1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

Make buttons unpress when the cursor leaves the button rect.

Implement this functionality by adding global cursor tracking.
It's currently only possible for one GWidget per GWindow to track the cursor.
This commit is contained in:
Andreas Kling 2019-01-27 08:48:34 +01:00
parent 15fad649ea
commit 069d21ed7f
15 changed files with 105 additions and 7 deletions

View file

@ -72,6 +72,13 @@ void GWindow::set_rect(const Rect& a_rect)
void GWindow::event(GEvent& event)
{
if (event.is_mouse_event()) {
if (m_global_cursor_tracking_widget) {
// FIXME: This won't work for widgets-within-widgets.
auto& mouse_event = static_cast<GMouseEvent&>(event);
Point local_point { mouse_event.x() - m_global_cursor_tracking_widget->relative_rect().x(), mouse_event.y() - m_global_cursor_tracking_widget->relative_rect().y() };
auto local_event = make<GMouseEvent>(event.type(), local_point, mouse_event.buttons(), mouse_event.button());
m_global_cursor_tracking_widget->event(*local_event);
}
if (!m_main_widget)
return;
auto& mouse_event = static_cast<GMouseEvent&>(event);
@ -158,3 +165,11 @@ void GWindow::set_focused_widget(GWidget* widget)
m_focused_widget->update();
}
}
void GWindow::set_global_cursor_tracking_widget(GWidget* widget)
{
if (widget == m_global_cursor_tracking_widget.ptr())
return;
m_global_cursor_tracking_widget = widget ? widget->makeWeakPtr() : nullptr;
gui_set_global_cursor_tracking_enabled(m_window_id, widget != nullptr);
}