cgv
Loading...
Searching...
No Matches
color_map_legend.h
1#pragma once
2
3#include <cgv/render/color_map.h>
4#include <cgv/render/texture.h>
6#include <cgv_app/themed_canvas_overlay.h>
7#include <cgv_g2d/generic_2d_renderer.h>
8#include <cgv_g2d/msdf_text_geometry.h>
9
10#include "lib_begin.h"
11
12namespace cgv {
13namespace app {
14
16public:
17 enum OrientationOption {
18 OO_HORIZONTAL,
19 OO_VERTICAL
20 };
21
22protected:
24 int padding = 0;
25 int label_space = 12;
26 int x_label_size = 0;
27 int title_space = 0;
28
29 ivec2 total_size;
30
31 OrientationOption orientation = OO_HORIZONTAL;
32 AlignmentOption label_alignment = AO_END;
33
34 // dependent members
35 cgv::g2d::irect color_map_rect;
36 ivec2 title_position = ivec2(0);
37 float title_angle = 90.0f;
38
39 void update(const ivec2& parent_size) {
40 ivec2 offset(0, 0);
41 ivec2 size(parent_size);
42
43 switch(label_alignment) {
44 case AO_START:
45 if(orientation == OO_HORIZONTAL) {
46 offset.x() = x_label_size / 2;
47 offset.y() = title_space;
48 size.x() -= x_label_size;
49 size.y() -= label_space + title_space;
50 } else {
51 offset.x() = x_label_size + 4;
52 offset.y() = 0;
53 size.x() -= x_label_size + 4 + title_space;
54 }
55 break;
56 case AO_END:
57 if(orientation == OO_HORIZONTAL) {
58 offset.x() = x_label_size / 2;
59 offset.y() = label_space;
60 size.x() -= x_label_size;
61 size.y() -= label_space + title_space;
62 } else {
63 offset.x() = title_space;
64 size.x() -= x_label_size + 4 + title_space;
65 }
66 break;
67 default: break;
68 }
69
70 color_map_rect.position = offset + padding;
71 color_map_rect.size = size - 2 * padding;
72 }
73 } layout;
74
75 bool invert_color = false;
76 bool flip_texture = false;
77
79
80 std::string title;
81 vec2 value_range = { 0.0f, 1.0f };
82 vec2 display_range = { 0.0f, 1.0f };
83 unsigned num_ticks = 3;
84
85 AlignmentOption title_align = AO_START;
86
87 struct {
88 unsigned precision = 0;
89 bool auto_precision = true;
90 bool trailing_zeros = false;
91 bool integers = false;
92 } label_format;
93
94 bool show_opacity = true;
95
96 // general appearance
97 cgv::g2d::shape2d_style border_style, color_map_style, tick_style;
98 cgv::g2d::grid2d_style background_style;
99
100 // text appearance
101 cgv::g2d::text2d_style text_style;
102 cgv::g2d::msdf_text_geometry labels;
103
104 cgv::g2d::generic_2d_renderer tick_renderer;
105 DEFINE_GENERIC_RENDER_DATA_CLASS(tick_geometry, 2, vec2, position, vec2, size);
106 tick_geometry ticks;
107
108 void init_styles() override;
109 void create_labels(const cgv::render::context& ctx);
110 void create_ticks();
111
112 void create_gui_impl() override;
113
114public:
115 color_map_legend();
116 std::string get_type_name() const override { return "color_map_legend"; }
117
118 void clear(cgv::render::context& ctx) override;
119
120 void handle_member_change(const cgv::utils::pointer_test& m) override;
121
122 bool init(cgv::render::context& ctx) override;
123 void init_frame(cgv::render::context& ctx) override;
124 void draw_content(cgv::render::context& ctx) override;
125
126 void set_color_map(cgv::render::context& ctx, const cgv::render::color_map& cm);
127
128 void set_width(size_t w);
129 void set_height(size_t h);
130
131 void set_title(const std::string& t);
132
133 OrientationOption get_orientation() const { return layout.orientation; }
134 void set_orientation(OrientationOption orientation);
135
136 AlignmentOption get_label_alignment() const { return layout.label_alignment; }
137 void set_label_alignment(AlignmentOption alignment);
138
139 vec2 get_range() const { return value_range; }
140 void set_range(vec2 r);
141
142 vec2 get_display_range() const { return display_range; }
143 void set_display_range(vec2 r);
144
145 void set_invert_color(bool flag);
146
147 unsigned get_num_ticks() { return num_ticks; }
148 void set_num_ticks(unsigned n);
149
150 void set_label_precision(unsigned p);
151 void set_label_auto_precision(bool enabled);
152 void set_label_prune_trailing_zeros(bool enabled);
153 void set_label_integer_mode(bool enabled);
154 void set_show_opacity(bool enabled);
155};
156
157typedef cgv::data::ref_ptr<color_map_legend> color_map_legend_ptr;
158
159}
160}
161
162#include <cgv/config/lib_end.h>
std::string get_type_name() const override
overload to return the type name of this object. By default the type interface is queried over get_ty...
reference counted pointer, which can work together with types that are derived from ref_counted,...
Definition ref_ptr.h:160
T & y()
second element
Definition fvec.h:159
T & x()
first element
Definition fvec.h:155
static cgv::type::uint32_type size()
return number of elements
Definition fvec.h:179
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
the texture class encapsulates all functionality independent of the rendering api.
Definition texture.h:15
Helper functions to convert numeric types into strings using std streams.
the cgv namespace
Definition print.h:11
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
Definition fvec.h:667