cgv
Loading...
Searching...
No Matches
color_scale_legend.h
1#pragma once
2
3#include <cgv/data/time_stamp.h>
4#include <cgv/media/color_scale.h>
5#include <cgv/render/texture.h>
7#include <cgv/utils/number_format.h>
8#include <cgv_g2d/generic_2d_renderer.h>
9#include <cgv_g2d/generic_2d_render_data.h>
10#include <cgv_g2d/msdf_text_geometry.h>
11#include <cgv_overlay/themed_canvas_overlay.h>
12
13#include "lib_begin.h"
14
15namespace cgv {
16namespace overlay {
17
19public:
20 enum class Orientation {
21 kHorizontal,
22 kVertical
23 };
24
25protected:
27 int padding = 0;
28 int label_space = 12;
29 int x_label_size = 0;
30 int title_space = 0;
31
32 ivec2 total_size;
33
34 Orientation orientation = Orientation::kHorizontal;
35 Alignment label_alignment = Alignment::kEnd;
36
37 // dependent members
38 cgv::g2d::irect color_ramp_rect;
39 } layout;
40
41 bool invert_color = false;
42 bool flip_texture = false;
43
44 cgv::render::texture tex = { "uint8[R,G,B,A]" };
45
46 std::string title;
47 Alignment title_alignment = Alignment::kStart;
48
49 unsigned num_ticks = 10;
50 bool nice_ticks = true;
51 bool auto_precision = true;
52 cgv::utils::number_format label_format;
53
54 bool show_opacity = true;
55
56 // general appearance
57 cgv::g2d::shape2d_style border_style, color_ramp_style, tick_style;
58 cgv::g2d::grid2d_style background_style;
59
60 // text appearance
61 cgv::g2d::text2d_style text_style;
62 cgv::g2d::msdf_text_geometry label_geometry;
63
64 cgv::g2d::generic_2d_renderer tick_renderer;
65 cgv::g2d::generic_render_data_vec2_vec2 tick_geometry;
66
67 cgv::data::time_stamp build_time;
68
69 std::shared_ptr<const cgv::media::color_scale> color_scale;
70
71 void init_styles() override;
72 void update_layout(const ivec2& parent_size);
73 void create_texture();
74 bool create_ticks(const cgv::render::context& ctx);
75
76 void create_gui_impl() override;
77
78public:
80 std::string get_type_name() const override { return "color_scale_legend"; }
81
82 void clear(cgv::render::context& ctx) override;
83
84 void handle_member_change(cgv::data::informed_ptr ptr) override;
85
86 bool init(cgv::render::context& ctx) override;
87 void init_frame(cgv::render::context& ctx) override;
88 void draw_content(cgv::render::context& ctx) override;
89
90 void set_color_scale(std::shared_ptr<const cgv::media::color_scale> color_scale);
91
92 void set_width(size_t w);
93 void set_height(size_t h);
94
95 void set_title(const std::string& t);
96
97 Orientation get_orientation() const { return layout.orientation; }
98 void set_orientation(Orientation orientation);
99
100 Alignment get_label_alignment() const { return layout.label_alignment; }
101 void set_label_alignment(Alignment alignment);
102
103 void set_invert_color(bool flag);
104
105 unsigned get_num_ticks() { return num_ticks; }
106 void set_num_ticks(unsigned n);
107
108 void set_label_precision(unsigned p);
109 void set_label_auto_precision(bool enabled);
110 void set_label_prune_trailing_zeros(bool enabled);
111 void set_label_integer_mode(bool enabled);
112 void set_show_opacity(bool enabled);
113};
114
115typedef cgv::data::ref_ptr<color_scale_legend> color_scale_legend_ptr;
116
117} // namespace overlay
118} // namespace cgv
119
120#include <cgv/config/lib_end.h>
This class provides methods to test if a stored pointer points to addresses of given variables or ins...
reference counted pointer, which can work together with types that are derived from ref_counted,...
Definition ref_ptr.h:160
Keep a time stamp to store modified time of objects.
Definition time_stamp.h:11
std::string get_type_name() const override
overload to return the type name of this object
base class for all drawables, which is independent of the used rendering API.
Definition context.h:668
the texture class encapsulates all functionality independent of the rendering api.
Definition texture.h:15
A class to store number formatting specification and allow converting numbers to strings.
Helper functions to convert numeric types into strings using std streams.
this header is dependency free
Definition print.h:11