Implement mouse-capture attribute on ui system
This commit is contained in:
13
src/node.cpp
13
src/node.cpp
@@ -132,7 +132,7 @@ kEventResult Node::on_event(Event* e)
|
||||
case kEventType::MouseDownR:
|
||||
case kEventType::MouseUpL:
|
||||
case kEventType::MouseUpR:
|
||||
if ((inside || m_mouse_captured) && handle_event(e) == kEventResult::Consumed)
|
||||
if ((inside || m_mouse_captured) && (handle_event(e) == kEventResult::Consumed || m_force_mouse_capture))
|
||||
return kEventResult::Consumed;
|
||||
break;
|
||||
case kEventType::MouseMove:
|
||||
@@ -143,7 +143,11 @@ kEventResult Node::on_event(Event* e)
|
||||
handle_event(&e2);
|
||||
}
|
||||
if (inside || m_mouse_captured)
|
||||
{
|
||||
ret = handle_event(e);
|
||||
if (m_force_mouse_capture)
|
||||
ret = kEventResult::Consumed;
|
||||
}
|
||||
if (inside_old == true && inside == false)
|
||||
{
|
||||
MouseEvent e2 = *me;
|
||||
@@ -419,6 +423,7 @@ Node::Node(Node&& o)
|
||||
m_mvp = o.m_mvp;
|
||||
m_mouse_inside = o.m_mouse_inside;
|
||||
m_flood_events = o.m_flood_events;
|
||||
m_force_mouse_capture = o.m_force_mouse_capture;
|
||||
m_capture_children = o.m_capture_children;
|
||||
m_destroyed = o.m_destroyed;
|
||||
|
||||
@@ -855,7 +860,10 @@ void Node::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
|
||||
break;
|
||||
}
|
||||
case kAttribute::FloodEvents:
|
||||
m_flood_events = attr->IntValue() > 0;
|
||||
m_flood_events = attr->BoolValue();
|
||||
break;
|
||||
case kAttribute::MouseCapture:
|
||||
m_force_mouse_capture = attr->BoolValue();
|
||||
break;
|
||||
case kAttribute::AspectRatio:
|
||||
YGNodeStyleSetAspectRatio(y_node, attr->FloatValue());
|
||||
@@ -1003,6 +1011,7 @@ void Node::clone_copy(Node* dest) const
|
||||
dest->m_size = m_size;
|
||||
dest->m_clip = m_clip;
|
||||
dest->m_flood_events = m_flood_events;
|
||||
dest->m_force_mouse_capture = m_force_mouse_capture;
|
||||
|
||||
dest->m_manager = m_manager;
|
||||
dest->current_mouse_capture = current_mouse_capture;
|
||||
|
||||
@@ -45,6 +45,7 @@ enum class kAttribute : uint16_t
|
||||
Default = const_hash("default"),
|
||||
RTL = const_hash("rtl"),
|
||||
AutoSize = const_hash("autosize"),
|
||||
MouseCapture = const_hash("mouse-capture"),
|
||||
};
|
||||
|
||||
enum class kWidget : uint16_t
|
||||
@@ -107,6 +108,7 @@ public:
|
||||
glm::mat4 m_mvp;
|
||||
bool m_mouse_inside = false;
|
||||
bool m_flood_events = false;
|
||||
bool m_force_mouse_capture = false;
|
||||
bool m_capture_children = true; // wether to capture children events when xx_capture() is used
|
||||
bool m_destroyed = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user