14 #define is_assert(cond) arb_assert(cond)
18 #if defined(UNIT_TESTS)
19 static void destroyAllItemShaders();
31 DummyPlugin() :
ShaderPlugin(
"dummy",
"test crash dummy") {}
33 static void reshade() {}
43 void TEST_shader_interface();
45 void TEST_shader_interface() {
50 const char *SHADY =
"lady";
73 destroyAllItemShaders();
103 #define AWAR_SELECTED_PLUGIN shader_awar("plugin")
104 #define AWAR_SHOW_DIMENSION tmp_shader_awar("dimension")
106 #define AWAR_GUI_RANGE tmp_shader_awar("range")
107 #define AWAR_GUI_OVERLAY_GROUPS tmp_shader_awar("groups")
108 #define AWAR_GUI_OVERLAY_MARKED tmp_shader_awar("marked")
109 #define AWAR_GUI_PHASE_FREQ tmp_shader_awar("phase")
110 #define AWAR_GUI_PHASE_ALTER tmp_shader_awar("alternate")
111 #define AWAR_GUI_PHASE_PRESHIFT tmp_shader_awar("preshift")
112 #define AWAR_GUI_PHASE_POSTSHIFT tmp_shader_awar("postshift")
114 #define AWAR_PLUGIN_RANGE plugin_awar("range")
115 #define AWAR_PLUGIN_OVERLAY_GROUPS plugin_awar("groups")
116 #define AWAR_PLUGIN_OVERLAY_MARKED plugin_awar("marked")
117 #define AWAR_PLUGIN_PHASE_FREQ plugin_awar("phase")
118 #define AWAR_PLUGIN_PHASE_ALTER plugin_awar("alternate")
119 #define AWAR_PLUGIN_PHASE_PRESHIFT plugin_awar("preshift")
120 #define AWAR_PLUGIN_PHASE_POSTSHIFT plugin_awar("postshift")
127 awar_prefix =
string(awar_prefix_) +
'/' + get_id();
139 init_specific_awars(awr);
153 #define SKIP_TMP_PREFIX 4
166 void setup_new_dimension();
176 range_option_menu(
NULp)
180 bool activate_plugin(
const string& plugin_id)
OVERRIDE;
181 bool activate_plugin_impl(
const string& plugin_id);
183 if (active_plugin.isSet())
return active_plugin->get_id();
195 void init() OVERRIDE;
197 void check_dimension_change() OVERRIDE;
199 void popup_config_window(
AW_root *awr) OVERRIDE;
201 static
void trigger_reshade_cb(
AW_root*,ItemShader_impl *shader) { shader->trigger_reshade_callback(
SIMPLE_RESHADE); }
204 if (active_plugin.isSet()) {
205 if (active_plugin->customizable()) active_plugin->customize(awr);
247 char *store_config_cb()
const;
248 void load_or_reset_config_cb(
const char *cfgstr);
250 static char *
store_config_cb(ItemShader_impl *shader) {
return shader->store_config_cb(); }
251 static void load_or_reset_config_cb(
const char *cfgstr, ItemShader_impl *shader) {
return shader->load_or_reset_config_cb(cfgstr); }
256 explicit has_id(
const char *id_) : id(id_) {}
257 explicit has_id(
const string& id_) : id(id_) {}
259 bool operator()(
const ItemShader_impl& shader) {
return shader.get_id() ==
id; }
267 ShaderPluginPtr ItemShader_impl::find_plugin(
const string& plugin_id)
const {
268 Plugins::const_iterator found = find_if(plugins.begin(), plugins.end(),
has_id(plugin_id));
273 is_assert(find_plugin(plugin->get_id()).isNull());
274 plugins.push_back(plugin);
276 plugin->announce_shader(
this);
280 bool ItemShader_impl::activate_plugin_impl(
const string& plugin_id) {
281 bool changed =
false;
284 if (active_plugin.isSet()) {
292 active_plugin = found;
297 if (prevActive.
isSet()) prevActive->activate(
false);
298 if (active_plugin.isSet()) active_plugin->activate(
true);
304 if (active_plugin.isSet()) {
313 check_dimension_change();
324 setup_new_dimension();
331 bool ItemShader_impl::activate_plugin(
const string& plugin_id) {
334 return activate_plugin_impl(plugin_id);
340 return strcmp(awar_plugin->
read_char_pntr(), plugin_id.c_str()) == 0;
346 void ItemShader_impl::setup_new_dimension() {
348 int dim = active_plugin.isSet() ? active_plugin->get_dimension() : 0;
360 bool seen_selected =
false;
362 if (aw_cfg) aw_cfg->clear_option_menu(range_option_menu);
363 for (
unsigned i = 0; i<ids.
size(); ++i) {
364 if (aw_cfg) aw_cfg->insert_option(names[i],
"", ids[i]);
365 if (!seen_selected && strcmp(selected_range_id, ids[i]) == 0) {
366 seen_selected =
true;
369 if (aw_cfg) aw_cfg->update_option_menu();
371 if (!seen_selected) selected_range_id = ids[0];
378 aw_cfg->clear_option_menu(range_option_menu);
379 aw_cfg->insert_option(
"<none>",
"",
"");
380 aw_cfg->update_option_menu();
387 void ItemShader_impl::check_dimension_change() {
390 int wanted_dim = active_plugin->get_dimension();
397 if (wanted_dim != range_dim || wanted_dim != awar_dim) {
398 setup_new_dimension();
406 void ItemShader_impl::init_config_definition(
AWT_config_definition& cdef,
bool add_selected_plugin)
const {
418 char *ItemShader_impl::store_config_cb()
const {
423 init_config_definition(cdef,
true);
426 error = cfg.parseError();
429 if (active_plugin.isSet()) {
430 char *plugin_setup = active_plugin->store_config();
432 cfg.set_entry(
"plugin_setup", plugin_setup);
436 cfgstr = cfg.config_string();
442 return cfgstr ? cfgstr : strdup(
"");
445 void ItemShader_impl::load_or_reset_config_cb(
const char *stored) {
449 init_config_definition(cdef, stored);
453 error = cfg.parseError();
456 char *plugin_setup = nulldup(cfg.get_entry(
"plugin_setup"));
457 cfg.delete_entry(
"plugin_setup");
459 const char *saved_pluginname = cfg.get_entry(
"plugin");
460 ShaderPluginPtr targetPlugin = saved_pluginname ? find_plugin(saved_pluginname) : active_plugin;
465 if (targetPlugin.
isSet()) {
467 targetPlugin->load_or_reset_config(plugin_setup);
470 error =
"Failed to restore plugin-specific settings (unknown plugin)";
476 if (targetPlugin.
isSet()) activate_plugin(targetPlugin->get_id());
486 if (active_plugin.isSet()) active_plugin->load_or_reset_config(
NULp);
509 void ItemShader_impl::init_awars(
AW_root *awr) {
510 RootCallback Reshade_cb = makeRootCallback(ItemShader_impl::trigger_reshade_cb,
this);
511 RootCallback PhaseChanged_cb = makeRootCallback(ItemShader_impl::phase_changed_cb,
this);
512 RootCallback PluginChanged_cb = makeRootCallback(ItemShader_impl::selected_plugin_changed_cb,
this);
513 RootCallback RangeChanged_cb = makeRootCallback(ItemShader_impl::selected_range_changed_cb,
this);
529 void ItemShader_impl::popup_config_window(
AW_root *awr) {
531 AW_window_simple *aws =
new AW_window_simple;
534 aws->init(awr, wid.c_str(), get_description().c_str());
536 aws->load_xfig(
"item_shader_cfg.fig");
538 aws->button_length(8);
542 aws->create_button(
"CLOSE",
"CLOSE",
"O");
546 aws->create_button(
"HELP",
"HELP");
551 for (Plugins::iterator p = plugins.begin(); p != plugins.end(); ++p) {
557 aws->at(
"plugin_cfg");
558 aws->callback(makeWindowCallback(ItemShader_impl::configure_active_plugin_cb,
this));
559 aws->create_autosize_button(
"configure",
"Configure");
563 aws->insert_option(
"<none>",
"",
"");
564 aws->update_option_menu();
566 aws->at(
"color_cfg");
567 aws->callback(makeWindowCallback(ItemShader_impl::configure_colors_cb,
this));
568 aws->create_autosize_button(
"color_cfg",
"Color setup");
576 aws->auto_space(5,5);
577 const int FIELDSIZE = 12;
578 const int SCALERLENGTH = 400;
587 aws->callback(makeWindowCallback(ItemShader_impl::reset_phasing_cb,
this));
588 aws->create_button(
"reset",
"RESET",
"R");
596 makeStoreConfigCallback(ItemShader_impl::store_config_cb,
this),
597 makeRestoreConfigCallback(ItemShader_impl::load_or_reset_config_cb,
this));
603 setup_new_dimension();
634 registered.push_back(ItemShader_impl(gcman, unique_id, description, help_id, reshade_cb, undef_gc));
635 ItemShader_impl& new_shader = registered.back();
636 if (awr) new_shader.init_awars(awr);
642 Shaders::iterator found = find_if(registered.begin(), registered.end(),
has_id(
id));
643 return found == registered.end() ?
NULp : &*found;
646 #if defined(UNIT_TESTS) // atm only used locally in unittest code
647 static void destroyAllItemShaders() {
#define AWAR_PLUGIN_RANGE
GBDATA * GB_open(const char *path, const char *opent)
ShaderPluginPtr makeItemFieldShader(BoundItemSel &itemtype)
void add(const char *awar_name, const char *config_name)
#define AWAR_PLUGIN_OVERLAY_GROUPS
has_id(const string &id_)
const char * tmp_shader_awar(const char *name) const
return string(buffer, length)
#define AWAR_PLUGIN_PHASE_POSTSHIFT
vector< ItemShader_impl > Shaders
void insert_default(const char *displayed, const AW_scalar &value)
void AW_popup_gc_color_range_window(AW_window *aww, AW_gc_manager *gcmgr)
virtual char * store_config() const =0
SmartPtr< ShaderPlugin > ShaderPluginPtr
void configure_active_plugin(AW_root *awr)
void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const StoreConfigCallback &store_cb, const RestoreConfigCallback &load_or_reset_cb, const char *macro_id, const AWT_predefined_config *predef)
static char * store_config_cb(ItemShader_impl *shader)
AW_awar * set_minmax(float min, float max)
const char * GBS_global_string(const char *templat,...)
void AW_POPDOWN(AW_window *window)
#define AWAR_GUI_OVERLAY_MARKED
void init_awars(AW_root *awr, const char *awar_prefix_)
const char * AW_getActiveColorRangeID(AW_gc_manager *gcman, int *dimension)
void AW_activateColorRange(AW_gc_manager *gcman, const char *id)
const char * shader_awar(const char *name) const
bool overlay_marked() const
void setNull()
set SmartPtr to NULp
static Shaders registered
AW_awar * add_callback(const RootCallback &cb)
void insert(const char *displayed, const AW_scalar &value)
virtual ShadedValue shade(GBDATA *gb_item) const =0
static void global_colorgroup_use_changed_cb(AW_root *awr, ItemShader_impl *shader)
#define TEST_PUBLISH(testfunction)
const char * read_char_pntr() const
virtual bool activate_plugin(const std::string &id)=0
static AW_root * SINGLETON
WindowCallback makeHelpCallback(const char *helpfile)
#define TEST_EXPECT(cond)
bool overlay_color_groups() const
const char * AW_get_color_groups_active_awarname()
#define AWAR_PLUGIN_PHASE_ALTER
bool isSet() const
test if SmartPtr is not NULp
bool operator()(const ShaderPluginPtr &plugin)
AW_awar * awar_float(const char *var_name, float default_value=0.0, AW_default default_file=AW_ROOT_DEFAULT)
#define AWAR_PLUGIN_PHASE_PRESHIFT
virtual bool customizable() const =0
std::string active_plugin_name() const OVERRIDE
virtual int get_dimension() const =0
#define TEST_REJECT(cond)
#define TEST_REJECT_NULL(n)
static void error(const char *msg)
#define AWAR_SHOW_DIMENSION
void configure_colors_cb(AW_window *aww)
#define NO_PLUGIN_SELECTED
GB_ERROR reset_to_default()
virtual void register_plugin(ShaderPluginPtr plugin)=0
const std::string & get_description() const
#define AWAR_GUI_OVERLAY_GROUPS
AW_awar * awar(const char *awar)
static void selected_plugin_changed_cb(AW_root *awr, ItemShader_impl *shader)
#define AWAR_GUI_PHASE_PRESHIFT
#define AWAR_GUI_PHASE_FREQ
static void phase_changed_cb(AW_root *awr, ItemShader_impl *shader)
bool operator()(const ItemShader_impl &shader)
void selected_plugin_changed_cb(AW_root *awr)
ItemShader * registerItemShader(AW_root *awr, AW_gc_manager *gcman, BoundItemSel &itemtype, const char *unique_id, const char *description, const char *help_id, ReshadeCallback reshade_cb, int undef_gc)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
void AW_getColorRangeNames(const AW_gc_manager *gcman, int dimension, ConstStrArray &ids, ConstStrArray &names)
#define TEST_EXPECT_NULL(n)
#define AWAR_GUI_PHASE_POSTSHIFT
static void configure_active_plugin_cb(AW_window *aww, ItemShader_impl *shader)
virtual void load_or_reset_config(const char *cfgstr)=0
ItemShader_impl(AW_gc_manager *gcman_, const string &id_, const string &description_, const string &help_id_, ReshadeCallback rcb, int undef_gc)
virtual std::string active_plugin_name() const =0
void(* ReshadeCallback)()
AW_awar * map(const char *awarn)
ItemSelector & SPECIES_get_selector()
static ARB_init_perl_interface init
static const ItemShader * findItemShader(const char *id)
void aw_message(const char *msg)
#define AWAR_PLUGIN_OVERLAY_MARKED
virtual void customize(AW_root *awr)=0
#define AWAR_PLUGIN_PHASE_FREQ
const ConfigMapping & get_mapping() const
static void configure_colors_cb(AW_window *aww, ItemShader_impl *shader)
void selected_range_changed_cb(AW_root *awr)
virtual void activate(bool on)=0
void phase_changed_cb(AW_root *awr)
const std::string & get_id() const
static void selected_range_changed_cb(AW_root *awr, ItemShader_impl *shader)
GB_ERROR write_string(const char *aw_string)
#define AWAR_GUI_PHASE_ALTER
#define AWAR_SELECTED_PLUGIN
void reset_phasing_cb(AW_root *awr) const
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
static void reset_phasing_cb(AW_window *aww, const ItemShader_impl *shader)
static void load_or_reset_config_cb(const char *cfgstr, ItemShader_impl *shader)
#define TEST_EXPECT_EQUAL(expr, want)
GB_ERROR write_int(long aw_int)
void aw_message_if(GB_ERROR error)
void GB_close(GBDATA *gbd)
vector< ShaderPluginPtr > Plugins
int AW_getFirstRangeGC(AW_gc_manager *gcman)