Skip to content

Commit 29962ea

Browse files
committed
Add start frame = end frame argument to OnMouseUp
1 parent 15309bc commit 29962ea

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

include/lxgui/gui_frame.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ using script_list_view = script_signal::slot_list_view;
200200
* last call to `OnMouseMove` (or since the last position before the mouse
201201
* entered this frame), and the mouse X and Y position.
202202
* - `OnMouseUp`: Similar to `OnMouseDown`, but triggered when the mouse button
203-
* is released. This event provides one extra argument compared to `OnMouseDown`:
203+
* is released. This event provides two extra argument compared to `OnMouseDown`:
204204
* a boolean flag indicating whether the mouse was released after a drag
205-
* operation (true) or not (false).
205+
* operation (true) or not (false), and another boolean flag indicating whether
206+
* the mouse button was initially pressed on this frame (true) or not (false).
206207
* - `OnMouseWheel`: Triggered when the mouse wheel is moved and this frame is
207208
* the topmost mouse-wheel-enabled frame under the mouse pointer. Will not
208209
* trigger if the frame is hidden. This event provides three arguments to the
@@ -557,7 +558,6 @@ class frame : public region {
557558

558559
/**
559560
* \brief Marks this frame as unable to receive keyboard input from any key.
560-
* \param key_name The key to capture
561561
* \see enable_key_capture()
562562
* \see is_key_capture_enabled()
563563
* \see set_keyboard_enabled()

include/lxgui/gui_root.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ class root :
4949
~root() override;
5050

5151
// Non-copiable, non-movable
52-
root(const root&) = delete;
53-
root(root&&) = delete;
52+
root(const root&) = delete;
53+
root(root&&) = delete;
5454
root& operator=(const root&) = delete;
55-
root& operator=(root&&) = delete;
55+
root& operator=(root&&) = delete;
5656

5757
/**
5858
* \brief Returns the width and height of this renderer's main render target (e.g., screen).
@@ -327,8 +327,9 @@ class root :
327327
std::vector<utils::scoped_connection> connections_;
328328

329329
// Mouse IO
330-
utils::observer_ptr<frame> hovered_frame_ = nullptr;
331-
utils::observer_ptr<frame> dragged_frame_ = nullptr;
330+
utils::observer_ptr<frame> hovered_frame_ = nullptr;
331+
utils::observer_ptr<frame> dragged_frame_ = nullptr;
332+
utils::observer_ptr<frame> start_click_frame_ = nullptr;
332333

333334
utils::observer_ptr<region> moved_object_ = nullptr;
334335
utils::observer_ptr<region> sized_object_ = nullptr;

src/gui_frame_glues.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@
159159
* last call to `OnMouseMove` (or since the last position before the mouse
160160
* entered this frame), and the mouse X and Y position.
161161
* - `OnMouseUp`: Similar to `OnMouseDown`, but triggered when the mouse button
162-
* is released. This event provides one extra argument compared to `OnMouseDown`:
162+
* is released. This event provides two extra argument compared to `OnMouseDown`:
163163
* a boolean flag indicating whether the mouse was released after a drag
164-
* operation (true) or not (false).
164+
* operation (true) or not (false), and another boolean flag indicating whether
165+
* the mouse button was initially pressed on this frame (true) or not (false).
165166
* - `OnMouseWheel`: Triggered when the mouse wheel is moved and this frame is
166167
* the topmost mouse-wheel-enabled frame under the mouse pointer. This event
167168
* provides three arguments to the registered callback. The first is a number

src/gui_root.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ bool root::on_mouse_button_state_changed_(
789789
bool is_double_click,
790790
bool was_dragged,
791791
const vector2f& mouse_pos) {
792+
792793
utils::observer_ptr<frame> hovered_frame = find_topmost_frame([&](const frame& frame) {
793794
return frame.is_in_region(mouse_pos) && frame.is_mouse_click_enabled();
794795
});
@@ -798,6 +799,10 @@ bool root::on_mouse_button_state_changed_(
798799
clear_focus();
799800
}
800801

802+
if (is_down) {
803+
start_click_frame_ = hovered_frame;
804+
}
805+
801806
if (!hovered_frame) {
802807
// Forward to the world
803808
return false;
@@ -818,7 +823,9 @@ bool root::on_mouse_button_state_changed_(
818823
hovered_frame->fire_script("OnMouseDown", data);
819824
} else {
820825
data.add(was_dragged);
826+
data.add(start_click_frame_ == hovered_frame);
821827
hovered_frame->fire_script("OnMouseUp", data);
828+
start_click_frame_ = nullptr;
822829
}
823830

824831
return true;

0 commit comments

Comments
 (0)