ARB
NT_shadeTree.cxx
Go to the documentation of this file.
1 // ============================================================ //
2 // //
3 // File : NT_shadeTree.cxx //
4 // Purpose : //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in June 2016 //
7 // http://www.arb-home.de/ //
8 // //
9 // ============================================================ //
10 
11 #include "tree_position.h"
12 
13 #include <TreeDisplay.hxx>
14 #include <AP_TreeShader.hxx>
15 
16 #include <awt_canvas.hxx>
17 
18 #include <aw_root.hxx>
19 #include <aw_awar.hxx>
20 #include <aw_awar_defs.hxx>
21 
22 #define nt_assert(cond) arb_assert(cond)
23 
24 // ------------------------
25 // TopologyShader
26 
28 
31  mutable TreePositionLookupPtr pos;
32 
33  void init_specific_awars(AW_root*) OVERRIDE {}
34 
35  void update_pos_lookup() const {
36  pos = new TreePositionLookup(agt->get_logical_root());
37  }
38 
39 public:
41  ShaderPlugin("topology", "Topology shader"),
42  agt(agt_)
43  {}
44 
45  ShadedValue shade(GBDATA *gb_item) const OVERRIDE {
46  if (gb_item) {
47  if (pos.isNull()) update_pos_lookup();
48 
49  const char *name = GBT_get_name(gb_item);
50  if (name) {
51  TreeRelativePosition relpos = pos->relative(name);
52  if (relpos.is_known()) return ValueTuple::make(relpos.value());
53  }
54  }
55  return ValueTuple::undefined();
56  }
57 
58  int get_dimension() const OVERRIDE { return 1; }
59  bool customizable() const OVERRIDE { return true; }
60  void customize(AW_root *) OVERRIDE { AW_help_popup(NULp, "topology_shader.hlp"); }
61 
62  char *store_config() const OVERRIDE { return NULp; }
63  void load_or_reset_config(const char *) OVERRIDE {}
64 
65  void activate(bool on) OVERRIDE;
66 
67 #if defined(ASSERTION_USED)
68  bool is_linked_with(AWT_graphic_tree *linkedWith) { return linkedWith == agt; }
69 #endif
70 
71  void tree_changed_cb() {
72  pos.setNull();
73  trigger_reshade_if_active_cb(SIMPLE_RESHADE); // forces reshade of "other" tree-canvas
74  }
76  nt_assert(shader->is_linked_with(by));
77  shader->tree_changed_cb();
78  }
79 };
80 
81 void TopologyShader::activate(bool on) {
82  // called with true when plugin gets activated, with false when it gets deactivated
83 
84  if (on) {
85  pos.setNull(); // invalidate cached positions
86  GraphicTreeCallback gtcb = makeGraphicTreeCallback(TopologyShader::tree_changed_cb, this);
88  }
89  else {
91  }
92 }
93 
94 // -----------------------
95 // NT_TreeShader
96 
97 class NT_TreeShader: public AP_TreeShader, virtual Noncopyable {
98  ItemShader *shader; // (owned by registry in ITEM_SHADER)
99 
100  static void reshade() {
101 #if defined(DEBUG)
102  fprintf(stderr, "[NT_TreeShader::reshade] @ %zu\n", clock());
103 #endif
105  }
106 
107 public:
109  shader(registerItemShader(ntw->awr,
110  ntw->gc_manager,
112  "tree",
113  "Tree shading",
114  "tree_shading.hlp",
115  NT_TreeShader::reshade,
117  {
119  ShaderPluginPtr topo_shader = new TopologyShader(agt);
120  shader->register_plugin(topo_shader);
121  }
122  ~NT_TreeShader() OVERRIDE {}
123  void init() OVERRIDE { shader->init(); } // called by AP_tree::set_tree_shader when installed
124 
125  void update_settings() OVERRIDE {
126  colorize_marked = shader->overlay_marked();
128  shade_species = shader->active();
129  }
130 
131  ShadedValue calc_shaded_leaf_GC(GBDATA *gb_node) const OVERRIDE { return shader->shade(gb_node); }
132  ShadedValue calc_shaded_inner_GC(const ShadedValue& left, float left_ratio, const ShadedValue& right) const OVERRIDE {
133  return mix(left, left_ratio, right);
134  }
135  int to_GC(const ShadedValue& val) const OVERRIDE { return shader->to_GC(val); }
136 
137  void popup_config() const {
139  }
140 };
141 
142 // ----------------------------
143 // external interface
144 
146  AP_tree::set_tree_shader(new NT_TreeShader(ntw, gb_main));
147 }
148 
150  const AP_TreeShader *tshader = AP_tree::get_tree_shader();
151  nt_assert(tshader);
152  if (tshader) DOWNCAST(const NT_TreeShader*, tshader)->popup_config();
153 
154 }
155 
156 
157 
double value() const
Definition: tree_position.h:48
bool customizable() const OVERRIDE
void popup_config() const
AP_tree * get_logical_root()
TopologyShader(AWT_graphic_tree *agt_)
int get_dimension() const OVERRIDE
bool is_known() const
Definition: tree_position.h:47
bool active() const
Definition: item_shader.h:320
static ShadedValue make(float f)
Definition: ValueTuple.cxx:508
~NT_TreeShader() OVERRIDE
bool overlay_marked() const
Definition: item_shader.h:321
ShadedValue shade(GBDATA *gb_item) const
Definition: item_shader.h:324
void init() OVERRIDE
void customize(AW_root *) OVERRIDE
void tree_changed_cb()
#define AWAR_TREE_RECOMPUTE
bool isNull() const
test if SmartPtr is NULp
Definition: smartptr.h:248
void update_settings() OVERRIDE
void setNull()
set SmartPtr to NULp
Definition: smartptr.h:251
#define DOWNCAST(totype, expr)
Definition: downcast.h:141
NT_TreeShader(TREE_canvas *ntw, GBDATA *gb_main)
static AW_root * SINGLETON
Definition: aw_root.hxx:102
#define nt_assert(cond)
void touch()
Definition: AW_awar.cxx:207
int to_GC(const ShadedValue &val) const OVERRIDE
virtual void register_plugin(ShaderPluginPtr plugin)=0
void uninstall_tree_changed_callback()
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
void NT_install_treeShader(TREE_canvas *ntw, GBDATA *gb_main)
ShadedValue calc_shaded_leaf_GC(GBDATA *gb_node) const OVERRIDE
SmartPtr< TreePositionLookup > TreePositionLookupPtr
AWT_graphic * gfx
Definition: awt_canvas.hxx:339
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)
#define IF_ASSERTION_USED(x)
Definition: arb_assert.h:308
virtual void init()=0
ShadedValue shade(GBDATA *gb_item) const OVERRIDE
#define OVERRIDE
Definition: cxxforward.h:112
static ShadedValue undefined()
Definition: ValueTuple.cxx:505
ItemSelector & SPECIES_get_selector()
Definition: species.cxx:139
ShadedValue mix(const ShadedValue &val1, float val1_ratio, const ShadedValue &val2)
Definition: item_shader.h:174
void trigger_reshade_if_active_cb(ReshadeMode mode)
Definition: item_shader.h:361
bool is_linked_with(AWT_graphic_tree *linkedWith)
void NT_configure_treeShader()
#define NULp
Definition: cxxforward.h:116
void AW_help_popup(UNFIXED, const char *help_file)
Definition: AW_help.cxx:628
const char * GBT_get_name(GBDATA *gb_item)
Definition: aditem.cxx:468
char * store_config() const OVERRIDE
void load_or_reset_config(const char *) OVERRIDE
static const AP_TreeShader * get_tree_shader()
Definition: AP_Tree.hxx:372
void install_tree_changed_callback(const GraphicTreeCallback &gtcb)
ShadedValue calc_shaded_inner_GC(const ShadedValue &left, float left_ratio, const ShadedValue &right) const OVERRIDE
GBDATA * gb_main
Definition: adname.cxx:32
static void set_tree_shader(AP_TreeShader *new_shader)
Definition: AP_Tree.cxx:704
bool overlay_color_groups() const
Definition: item_shader.h:322
virtual void popup_config_window(AW_root *awr)=0
void activate(bool on) OVERRIDE
TreeRelativePosition relative(const char *name) const
Definition: tree_position.h:78
int to_GC(const ShadedValue &val) const
Definition: item_shader.h:328
static void tree_changed_cb(AWT_graphic_tree *by, TopologyShader *shader)