26 bool mouse_is_over_overlay = local_rect.contains(local_mouse_pos);
31 bool mouse_was_over_overlay = local_rect.contains(last_local_mouse_pos_);
33 last_local_mouse_pos_ = local_mouse_pos;
35 if(!mouse_was_over_overlay && mouse_is_over_overlay)
37 else if(mouse_was_over_overlay && !mouse_is_over_overlay)
46 captured_mouse_ = mouse_is_over_overlay;
49 captured_mouse_ =
false;
52 return mouse_is_over_overlay;
57 if((mouse_is_over_overlay || captured_mouse_) &&
handle_mouse_event(me, local_mouse_pos))
60 if(captured_mouse_ && blocks_events_)
77 return cgv::g2d::apply_origin_setting(mouse_pos, last_viewport_size_, cgv::g2d::OriginSetting::kUpperLeft, cgv::g2d::OriginSetting::kLowerLeft) - container_.position;
81 horizontal_alignment_ = horizontal;
82 vertical_alignment_ = vertical;
84 for(
int i = 0; i < 2; ++i) {
85 if(percentual_offset[i] != -1.0f)
86 percentual_offset_[i] = percentual_offset[i];
95 for(
int i = 0; i < 2; ++i) {
96 if(percentual_size[i] != -1.0f)
97 percentual_size_[i] = percentual_size[i];
109 container_.size = size;
127 if(last_viewport_size_ != viewport_size) {
128 last_viewport_size_ = viewport_size;
138 if(last_size_ != container_.size) {
139 last_size_ = container_.size;
147 ivec2 test_pos = cgv::g2d::apply_origin_setting(mouse_pos, last_viewport_size_, cgv::g2d::OriginSetting::kUpperLeft, cgv::g2d::OriginSetting::kLowerLeft);
148 return container_.contains(test_pos);
154 add_layout_member_control(
"Show", cgv::render::drawable::active,
"toggle",
"w=40");
182 add_decorator(
"Horizontal",
"heading",
"level=4;font_style=regular;w=94",
" ");
183 add_decorator(
"Vertical",
"heading",
"level=4;font_style=regular;w=94");
185 add_layout_member_control(
"", horizontal_alignment_,
"dropdown",
"enums='Free,Left,Center,Right';w=94",
" ");
186 add_layout_member_control(
"", vertical_alignment_,
"dropdown",
"enums='Free=0,Top=3,Center=2,Bottom=1';w=94");
190 add_layout_member_control(
"Stretch", stretch_,
"dropdown",
"enums='None,Horizontal,Vertical,Both'");
193 add_layout_member_control(
"Margin", margin_[0],
"value",
"w=94;min=-10000;max=10000;step=1;",
" ");
194 add_layout_member_control(
"", margin_[1],
"value",
"w=94;min=-10000;max=10000;step=1;");
216 container_.position = margin_;
217 ivec2 max_size = last_viewport_size_ - 2 * margin_;
221 container_.w() = max_size.
x();
224 container_.h() = max_size.
y();
227 container_.size = max_size;
230 container_.size = percentual_size_ * max_size;
236 const auto compute_aligned_position = [
this, &max_size](AlignmentOption alignment,
int axis) {
238 case AO_CENTER:
return (last_viewport_size_[axis] - container_.size[axis]) / 2;
239 case AO_END:
return last_viewport_size_[axis] - container_.size[axis] - margin_[axis];
240 case AO_PERCENTUAL:
return static_cast<int32_t
>(margin_[axis] + percentual_offset_[axis] * max_size[axis]);
243 default:
return margin_[axis];
247 container_.x() = compute_aligned_position(horizontal_alignment_, 0);
248 container_.y() = compute_aligned_position(vertical_alignment_, 1);
void create_layout_gui()
provides a default gui implementation for private overlay layout members
void end_overlay_gui()
ends the tree node of the overlay gui
void create_gui()
Creates a tree node containing the overlay layout options and the gui as specified by the derived ove...
virtual void handle_member_change(const cgv::utils::pointer_test &m)
implement to handle member changes
void set_visibility(bool visible)
set the visibility of the overlay
void set_stretch(StretchOption stretch, vec2 percentual_size=vec2(-1.0f))
set the stretch option
void update_layout()
update the layout of the overlay container
bool ensure_viewport(cgv::render::context &ctx)
Check whether the viewport size has changed since the last call to this method.
void set_alignment(AlignmentOption horizontal, AlignmentOption vertical, vec2 percentual_offset=vec2(-1.0f))
set the alignment options
bool begin_overlay_gui()
begins a tree node if create default tree node is set in the gui options; automatically creates the l...
virtual void on_visibility_change()
called when the overlay visibility is changed through the default gui
virtual void on_set(void *member_ptr)
default implementation of that calls handle_member_change and afterwards updates the member in the gu...
void toggle_visibility()
toggle the visibility of the overlay
virtual bool handle_key_event(cgv::gui::key_event &e)
overload this method to handle key events
void set_margin(const ivec2 &margin)
set the overlay margin
cgv::g2d::irect get_local_rectangle() const
return the current rectangle area of the overlay in local space, i.e. with position set to zero
gui_options_t gui_options
options for the GUI creation of this overlay (must be set before GUI creation)
virtual ivec2 get_local_mouse_pos(ivec2 mouse_pos) const
return the mouse position local to the container of this overlay
virtual bool handle_mouse_event(cgv::gui::mouse_event &e, cgv::ivec2 local_mouse_pos)
overload this method to handle mouse events; local_mouse_pos is the mouse position in the local coord...
virtual bool is_hit(const ivec2 &mouse_pos) const
Test if the mouse pointer is hovering over this overlay and returns true if this is the case.
virtual bool handle(cgv::gui::event &e)
handle incomming events; calls handle_key_events or handle_mouse_events depending on the event type; ...
virtual void on_layout_change()
called when the overlay layout parameters are changed through the default gui
void set_size(const ivec2 &size)
set the default size of the overlay before stretch gets applied
virtual void create_gui_impl()
virtual method to implement the derived class gui creation
std::string name
store the name as a string
unsigned get_kind() const
return, what kind of event this is, typically a value from the EventId enum
class to represent all possible keyboard events with the EID_KEY
class to represent all possible mouse events with the EID_MOUSE
short get_y() const
current mouse y position (origin is top-left of window)
MouseAction get_action() const
return the mouse action
void set_action(MouseAction _action)
return the mouse action
short get_x() const
current mouse x position (origin is top-left of window)
cgv::base::base_ptr add_decorator(const std::string &label, const std::string &decorator_type, const std::string &options="", const std::string &align="\n")
add a newly created decorator to the group
bool begin_tree_node_void(const std::string &label, const void *value_ptr, int index=-1, bool initial_visibility=false, const std::string &options="", gui_group_ptr ggp=gui_group_ptr())
void version of the templated functions
void align(const std::string &_align)
send pure alignment information
bool begin_tree_node(const std::string &label, const T &value, bool initial_visibility=false, const std::string &options="", gui_group_ptr ggp=gui_group_ptr())
Begin a sub tree of a tree structured gui.
virtual void update_member(void *member_ptr)
call this to update all views and controls of a member
void end_tree_node(const T &value)
template specialization that allows to specify value reference plus node_instance by using the result...
base class for all drawables, which is independent of the used rendering API.
virtual unsigned int get_width() const =0
return the width of the window
virtual unsigned int get_height() const =0
return the height of the window
void hide()
hide the drawable
void show()
show the drawable
void post_redraw()
posts a redraw event to the current context if one is available
bool is_visible() const
check whether the drawable is visible
MouseAction
different actions that a mouse can perform
@ MA_PRESS
mouse button pressed
@ MA_LEAVE
mouse leave window action
@ MA_MOVE
mouse pointer moved
@ MA_ENTER
mouse enter window action
@ MA_WHEEL
mouse wheel moved
@ MA_RELEASE
mouse button released
@ EID_KEY
id for key event
@ EID_MOUSE
id for mouse event
bool create_default_tree_node
if true the overlay GUI will be placed inside a collapsible tree node
bool allow_stretch
whether to show the stretch options (show_layout_options must be enabled)
bool allow_alignment
whether to show the alignment options (show_layout_options must be enabled)
bool allow_margin
whether to show the margin options (show_layout_options must be enabled)
bool show_layout_options
whether to show the layout options