1 | // ============================================================ // |
---|
2 | // // |
---|
3 | // File : AP_TreeShader.hxx // |
---|
4 | // Purpose : separate GC calculation from AP_TREE library // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in June 2016 // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // ============================================================ // |
---|
10 | |
---|
11 | #ifndef AP_TREESHADER_HXX |
---|
12 | #define AP_TREESHADER_HXX |
---|
13 | |
---|
14 | #ifndef AP_TREECOLORS_HXX |
---|
15 | #include <AP_TreeColors.hxx> |
---|
16 | #endif |
---|
17 | #ifndef AD_COLORSET_H |
---|
18 | #include <ad_colorset.h> |
---|
19 | #endif |
---|
20 | #ifndef ITEM_SHADER_H |
---|
21 | #include <item_shader.h> |
---|
22 | #endif |
---|
23 | |
---|
24 | #define ap_assert(cond) arb_assert(cond) |
---|
25 | |
---|
26 | class GBDATA; |
---|
27 | |
---|
28 | class AP_TreeShader { |
---|
29 | protected: |
---|
30 | bool colorize_marked; |
---|
31 | bool colorize_groups; |
---|
32 | bool shade_species; |
---|
33 | public: |
---|
34 | AP_TreeShader() : |
---|
35 | colorize_marked(false), |
---|
36 | colorize_groups(false), |
---|
37 | shade_species(false) |
---|
38 | {} |
---|
39 | virtual ~AP_TreeShader() {} |
---|
40 | virtual void init() = 0; // called by AP_tree::set_tree_shader when installed |
---|
41 | |
---|
42 | bool does_shade() const { return shade_species; } |
---|
43 | |
---|
44 | virtual void update_settings() = 0; |
---|
45 | virtual ShadedValue calc_shaded_leaf_GC(GBDATA *gb_node) const = 0; |
---|
46 | virtual ShadedValue calc_shaded_inner_GC(const ShadedValue& left, float left_ratio, const ShadedValue& right) const = 0; |
---|
47 | virtual int to_GC(const ShadedValue& val) const = 0; |
---|
48 | |
---|
49 | int calc_leaf_GC(GBDATA *gb_node, bool is_marked) const { |
---|
50 | int gc = AWT_GC_NONE_MARKED; |
---|
51 | if (gb_node) { |
---|
52 | if (is_marked && colorize_marked) { |
---|
53 | gc = AWT_GC_ALL_MARKED; |
---|
54 | } |
---|
55 | else if (colorize_groups) { // check for user color |
---|
56 | int color_group = GBT_get_color_group(gb_node); |
---|
57 | if (color_group) { |
---|
58 | ap_assert(color_group>0 && color_group<=AW_COLOR_GROUPS); // color_group has to be in range [1..AW_COLOR_GROUPS] |
---|
59 | gc = AWT_GC_FIRST_COLOR_GROUP+color_group-1; |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | else { |
---|
64 | gc = AWT_GC_ONLY_ZOMBIES; |
---|
65 | } |
---|
66 | ap_assert(gc>=0 && gc<AWT_GC_FIRST_RANGE_COLOR); // when violated -> leads to crash in PARSIMONY. |
---|
67 | return gc; |
---|
68 | } |
---|
69 | |
---|
70 | int calc_inner_GC(int left_gc, int right_gc) const { |
---|
71 | int gc; |
---|
72 | |
---|
73 | if (left_gc == right_gc) gc = left_gc; |
---|
74 | |
---|
75 | else if (left_gc == AWT_GC_ALL_MARKED || right_gc == AWT_GC_ALL_MARKED) gc = AWT_GC_SOME_MARKED; |
---|
76 | |
---|
77 | else if (left_gc == AWT_GC_ONLY_ZOMBIES) gc = right_gc; |
---|
78 | else if (right_gc == AWT_GC_ONLY_ZOMBIES) gc = left_gc; |
---|
79 | |
---|
80 | else if (left_gc == AWT_GC_SOME_MARKED || right_gc == AWT_GC_SOME_MARKED) gc = AWT_GC_SOME_MARKED; |
---|
81 | |
---|
82 | else { |
---|
83 | ap_assert(left_gc != AWT_GC_ALL_MARKED && right_gc != AWT_GC_ALL_MARKED); |
---|
84 | ap_assert(left_gc != AWT_GC_SOME_MARKED && right_gc != AWT_GC_SOME_MARKED); |
---|
85 | gc = AWT_GC_NONE_MARKED; |
---|
86 | } |
---|
87 | |
---|
88 | return gc; |
---|
89 | } |
---|
90 | }; |
---|
91 | |
---|
92 | |
---|
93 | #else |
---|
94 | #error AP_TreeShader.hxx included twice |
---|
95 | #endif // AP_TREESHADER_HXX |
---|