Implement mouse-capture attribute on ui system

This commit is contained in:
2019-01-08 14:52:20 +01:00
parent c5a0b4e6b0
commit 1c8ace73c9
3 changed files with 29 additions and 18 deletions

View File

@@ -307,7 +307,7 @@
</layout> </layout>
<layout id="message-box"> <layout id="message-box">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3"> <border thickness="1" border-color=".2" pad="3">
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text id="title" text="Just a test message" font-face="arial" font-size="11"></text> <text id="title" text="Just a test message" font-face="arial" font-size="11"></text>
@@ -324,7 +324,7 @@
</layout> </layout>
<layout id="progress-bar"> <layout id="progress-bar">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3"> <border thickness="1" border-color=".2" pad="3">
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text id="title" text="Just a test message" font-face="arial" font-size="11"></text> <text id="title" text="Just a test message" font-face="arial" font-size="11"></text>
@@ -391,7 +391,7 @@
<!-- Dialog Rename Layer --> <!-- Dialog Rename Layer -->
<layout id="dialog-layer-rename"> <layout id="dialog-layer-rename">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3"> <border thickness="1" border-color=".2" pad="3">
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="Rename Layer" font-face="arial" font-size="11"></text> <text text="Rename Layer" font-face="arial" font-size="11"></text>
@@ -412,7 +412,7 @@
<!-- Dialog Resize --> <!-- Dialog Resize -->
<layout id="dialog-resize"> <layout id="dialog-resize">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3"> <border thickness="1" border-color=".2" pad="3">
<border width="500" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="500" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="Resize Document Resolution" font-face="arial" font-size="11"></text> <text text="Resize Document Resolution" font-face="arial" font-size="11"></text>
@@ -442,7 +442,7 @@
</border> </border>
</layout> </layout>
<layout id="dialog-browse"> <layout id="dialog-browse">
<border id="background" positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border id="background" positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border id="form" thickness="1" border-color=".2" pad="3" width="90%" height="90%" dir="col"> <border id="form" thickness="1" border-color=".2" pad="3" width="90%" height="90%" dir="col">
<border id="title-bar" width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border id="title-bar" width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="Browse PanoPainter Projects" font-face="arial" font-size="11"></text> <text text="Browse PanoPainter Projects" font-face="arial" font-size="11"></text>
@@ -474,7 +474,7 @@
</layout> </layout>
<layout id="dialog-cloud"> <layout id="dialog-cloud">
<border id="background" positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border id="background" positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border id="form" thickness="1" border-color=".2" pad="3" width="90%" height="90%" dir="col"> <border id="form" thickness="1" border-color=".2" pad="3" width="90%" height="90%" dir="col">
<border id="title-bar" width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border id="title-bar" width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="Browse PanoPainter Projects" font-face="arial" font-size="11"></text> <text text="Browse PanoPainter Projects" font-face="arial" font-size="11"></text>
@@ -501,7 +501,7 @@
</border> </border>
</layout> </layout>
<layout id="dialog-open"> <layout id="dialog-open">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3"> <border thickness="1" border-color=".2" pad="3">
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="Open PanoPainter Project" font-face="arial" font-size="11"></text> <text text="Open PanoPainter Project" font-face="arial" font-size="11"></text>
@@ -530,7 +530,7 @@
<!-- Save Dialog Popup --> <!-- Save Dialog Popup -->
<layout id="dialog-save"> <layout id="dialog-save">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3"> <border thickness="1" border-color=".2" pad="3">
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="Save Pano Project" font-face="arial" font-size="11"></text> <text text="Save Pano Project" font-face="arial" font-size="11"></text>
@@ -553,7 +553,7 @@
<!-- NewDoc Dialog Popup --> <!-- NewDoc Dialog Popup -->
<layout id="dialog-newdoc"> <layout id="dialog-newdoc">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3"> <border thickness="1" border-color=".2" pad="3">
<border width="500" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="500" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="Create New Pano Project" font-face="arial" font-size="11"></text> <text text="Create New Pano Project" font-face="arial" font-size="11"></text>
@@ -578,7 +578,7 @@
<!--settings window--> <!--settings window-->
<layout id="settings"> <layout id="settings">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3" width="80%" min-width="400"> <border thickness="1" border-color=".2" pad="3" width="80%" min-width="400">
<border width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="Global Settings" font-face="arial" font-size="11"></text> <text text="Global Settings" font-face="arial" font-size="11"></text>
@@ -616,7 +616,7 @@
<!--About window--> <!--About window-->
<layout id="about"> <layout id="about">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="1">
<border thickness="1" border-color=".2" pad="3" max-width="650"> <border thickness="1" border-color=".2" pad="3" max-width="650">
<border width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="About PanoPainter" font-face="arial" font-size="11"></text> <text text="About PanoPainter" font-face="arial" font-size="11"></text>
@@ -677,7 +677,7 @@ Roboto Font License:
<!--Changelog window--> <!--Changelog window-->
<layout id="changelog"> <layout id="changelog">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3" max-width="650"> <border thickness="1" border-color=".2" pad="3" max-width="650">
<border width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="What's new in PanoPainter" font-face="arial" font-size="11"></text> <text text="What's new in PanoPainter" font-face="arial" font-size="11"></text>
@@ -753,7 +753,7 @@ Here's a list of what's available in this release.
<!--UserManual window--> <!--UserManual window-->
<layout id="usermanual"> <layout id="usermanual">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true">
<border thickness="1" border-color=".2" pad="3" max-width="650"> <border thickness="1" border-color=".2" pad="3" max-width="650">
<border width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="100%" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="PanoPainter User Manual" font-face="arial" font-size="11"></text> <text text="PanoPainter User Manual" font-face="arial" font-size="11"></text>
@@ -996,7 +996,7 @@ Here's a list of what's available in this release.
<node dir="col" wrap="0" width="100%" height="100%" pad="0"> <node dir="col" wrap="0" width="100%" height="100%" pad="0">
<!-- content panel --> <!-- content panel -->
<!-- menu bar --> <!-- menu bar -->
<border flood-events="1" margin="0 0 0 0" pad="0 0 0 0" color=".1" width="100%" height="30" dir="row" align="center"> <border flood-events="1" margin="0 0 0 0" pad="0 0 0 0" color=".1" width="100%" height="30" dir="row" align="center" mouse-capture="true">
<!-- <!--
<button-custom id="menu-file" height="100%" margin="0 0 0 0" justify="center" align="center" pad="8" color=".1"> <button-custom id="menu-file" height="100%" margin="0 0 0 0" justify="center" align="center" pad="8" color=".1">
<text text="File" font-face="arial" font-size="11"/> <text text="File" font-face="arial" font-size="11"/>
@@ -1019,7 +1019,7 @@ Here's a list of what's available in this release.
</node> </node>
</border> </border>
<!-- toolbar --> <!-- toolbar -->
<border id="toolbar" height="60" width="100%" pad="5" dir="row" color=".2 .2 .2 .6"> <border id="toolbar" height="60" width="100%" pad="5" dir="row" color=".2 .2 .2 .6" mouse-capture="true">
<!-- <!--
<button id="btn-open" width="50" height="100%" margin="0 5 0 0" text="Open"/> <button id="btn-open" width="50" height="100%" margin="0 5 0 0" text="Open"/>
<button id="btn-save" width="50" height="100%" margin="0 5 0 0" text="Save"/> <button id="btn-save" width="50" height="100%" margin="0 5 0 0" text="Save"/>
@@ -1093,7 +1093,7 @@ Here's a list of what's available in this release.
</border> </border>
<!-- central row --> <!-- central row -->
<node grow="1" dir="row" wrap="1" height="0" id="central-row"> <node grow="1" dir="row" wrap="1" height="0" id="central-row">
<border width="60" color=".2 .2 .2 .6" margin="0 0 0 0" dir="col" pad="4" flood-events="1" justify="center"> <border width="60" color=".2 .2 .2 .6" margin="0 0 0 0" dir="col" pad="4" flood-events="1" justify="center" mouse-capture="true">
<!--panel togglers--> <!--panel togglers-->
<button-custom id="btn-stroke" width="50" height="50" margin="0 0 5 0" thickness="1" border-color=".1" pad="2"> <button-custom id="btn-stroke" width="50" height="50" margin="0 0 5 0" thickness="1" border-color=".1" pad="2">
<image path="data/ui/stroke.png" width="100%" height="100%" align="center" justify="flex-end"/> <image path="data/ui/stroke.png" width="100%" height="100%" align="center" justify="flex-end"/>

View File

@@ -132,7 +132,7 @@ kEventResult Node::on_event(Event* e)
case kEventType::MouseDownR: case kEventType::MouseDownR:
case kEventType::MouseUpL: case kEventType::MouseUpL:
case kEventType::MouseUpR: 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; return kEventResult::Consumed;
break; break;
case kEventType::MouseMove: case kEventType::MouseMove:
@@ -143,7 +143,11 @@ kEventResult Node::on_event(Event* e)
handle_event(&e2); handle_event(&e2);
} }
if (inside || m_mouse_captured) if (inside || m_mouse_captured)
{
ret = handle_event(e); ret = handle_event(e);
if (m_force_mouse_capture)
ret = kEventResult::Consumed;
}
if (inside_old == true && inside == false) if (inside_old == true && inside == false)
{ {
MouseEvent e2 = *me; MouseEvent e2 = *me;
@@ -419,6 +423,7 @@ Node::Node(Node&& o)
m_mvp = o.m_mvp; m_mvp = o.m_mvp;
m_mouse_inside = o.m_mouse_inside; m_mouse_inside = o.m_mouse_inside;
m_flood_events = o.m_flood_events; m_flood_events = o.m_flood_events;
m_force_mouse_capture = o.m_force_mouse_capture;
m_capture_children = o.m_capture_children; m_capture_children = o.m_capture_children;
m_destroyed = o.m_destroyed; m_destroyed = o.m_destroyed;
@@ -855,7 +860,10 @@ void Node::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
break; break;
} }
case kAttribute::FloodEvents: 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; break;
case kAttribute::AspectRatio: case kAttribute::AspectRatio:
YGNodeStyleSetAspectRatio(y_node, attr->FloatValue()); YGNodeStyleSetAspectRatio(y_node, attr->FloatValue());
@@ -1003,6 +1011,7 @@ void Node::clone_copy(Node* dest) const
dest->m_size = m_size; dest->m_size = m_size;
dest->m_clip = m_clip; dest->m_clip = m_clip;
dest->m_flood_events = m_flood_events; dest->m_flood_events = m_flood_events;
dest->m_force_mouse_capture = m_force_mouse_capture;
dest->m_manager = m_manager; dest->m_manager = m_manager;
dest->current_mouse_capture = current_mouse_capture; dest->current_mouse_capture = current_mouse_capture;

View File

@@ -45,6 +45,7 @@ enum class kAttribute : uint16_t
Default = const_hash("default"), Default = const_hash("default"),
RTL = const_hash("rtl"), RTL = const_hash("rtl"),
AutoSize = const_hash("autosize"), AutoSize = const_hash("autosize"),
MouseCapture = const_hash("mouse-capture"),
}; };
enum class kWidget : uint16_t enum class kWidget : uint16_t
@@ -107,6 +108,7 @@ public:
glm::mat4 m_mvp; glm::mat4 m_mvp;
bool m_mouse_inside = false; bool m_mouse_inside = false;
bool m_flood_events = 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_capture_children = true; // wether to capture children events when xx_capture() is used
bool m_destroyed = false; bool m_destroyed = false;