3#include <cgv/render/texture.h>
4#include <cgv_g2d/draggable_collection.h>
5#include <cgv_g2d/msdf_text_geometry.h>
6#include <cgv_g2d/shape2d_styles.h>
7#include <cgv_overlay/themed_canvas_overlay.h>
21 cgv::g2d::irect border_rect;
22 cgv::g2d::irect color_rect;
23 cgv::g2d::irect hue_rect;
24 cgv::g2d::irect opacity_rect;
25 cgv::g2d::irect preview_rect;
27 cgv::g2d::irect hue_constraint;
28 cgv::g2d::irect opacity_constraint;
31 struct selector_handle :
public cgv::g2d::draggable {
33 bool is_rectangular =
false;
37 position_is_center =
true;
38 constraint_reference = cgv::g2d::ConstraintReference::kCenter;
43 const cgv::g2d::irect& c = *constraint;
44 vec2 p = position -
static_cast<vec2>(c.position);
46 val = p /
static_cast<vec2>(size);
47 if(size.x() == 0) val.x() = 0.0f;
48 if(size.y() == 0) val.y() = 0.0f;
49 val = cgv::math::clamp(val, 0.0f, 1.0f);
55 const cgv::g2d::irect& c = *constraint;
56 val = cgv::math::clamp(val, 0.0f, 1.0f);
57 position =
static_cast<vec2>(c.position) + val * c.size;
61 bool contains(
const vec2& mp)
const override {
63 return draggable::contains(mp);
65 const auto dist = length(mp - center());
66 return dist <= 0.5f*size.x();
71 bool has_opacity =
false;
72 bool auto_show =
true;
74 cgv::g2d::msdf_text_geometry text_geometry;
76 cgv::g2d::shape2d_style border_style, color_texture_style, hue_texture_style, opacity_color_style, color_handle_style, hue_handle_style;
77 cgv::g2d::text2d_style text_style;
78 cgv::g2d::grid2d_style opacity_bg_style;
80 cgv::g2d::draggable_collection<selector_handle> selector_handles;
82 cgv::render::texture color_tex = {
"uint8[R,G,B]", cgv::render::TF_LINEAR, cgv::render::TF_LINEAR };
83 cgv::render::texture hue_tex = {
"uint8[R,G,B]", cgv::render::TF_LINEAR, cgv::render::TF_LINEAR };
88 void update_layout(
const ivec2& parent_size);
90 void init_styles()
override;
96 void handle_selector_drag(cgv::g2d::DragAction action);
98 void set_color(
rgba color,
bool opacity,
bool init =
false);
100 std::function<void(
rgb)> on_change_rgb_callback;
101 std::function<void(
rgba)> on_change_rgba_callback;
103 void create_gui_impl()
override;
121 void set_rgb_color(
rgb color);
122 void set_rgba_color(
rgba color);
123 rgb get_rgb_color()
const {
return rgb_color; }
124 rgba get_rgba_color()
const {
return rgba_color; }
126 void set_on_change_rgb_callback(std::function<
void(rgb)> cb) { on_change_rgb_callback = cb; }
127 void set_on_change_rgba_callback(std::function<
void(rgba)> cb) { on_change_rgba_callback = cb; }
130typedef cgv::data::ref_ptr<color_selector> color_selector_ptr;
135#include <cgv/config/lib_end.h>
class to represent all possible mouse events with the EID_MOUSE
std::string get_type_name() const override
overload to return the type name of this object
void set_auto_show(bool enabled)
whether to automatically make the overlay visible if a color is set
themed_canvas_overlay()
creates an overlay in the bottom left corner with zero size using a canvas for 2d drawing
base class for all drawables, which is independent of the used rendering API.
the texture class encapsulates all functionality independent of the rendering api.
this header is dependency free
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > rgba
declare rgba color type with 32 bit components
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components
cgv::math::fvec< int32_t, 2 > ivec2
declare type of 2d 32 bit integer vectors
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors