mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:58:11 +00:00
GWidget: Tidy up the hit-testing code somewhat.
This commit is contained in:
parent
c812d63ea6
commit
952f334de7
3 changed files with 11 additions and 13 deletions
|
@ -296,7 +296,7 @@ Rect GWidget::screen_relative_rect() const
|
|||
return window_relative_rect().translated(window()->position());
|
||||
}
|
||||
|
||||
GWidget* GWidget::child_at(const Point& point)
|
||||
GWidget* GWidget::child_at(const Point& point) const
|
||||
{
|
||||
for (int i = children().size() - 1; i >= 0; --i) {
|
||||
if (!children()[i]->is_widget())
|
||||
|
@ -310,13 +310,13 @@ GWidget* GWidget::child_at(const Point& point)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
GWidget::HitTestResult GWidget::hit_test(int x, int y)
|
||||
GWidget::HitTestResult GWidget::hit_test(const Point& position)
|
||||
{
|
||||
if (is_greedy_for_hits())
|
||||
return { this, x, y };
|
||||
if (auto* child = child_at({ x, y }))
|
||||
return child->hit_test(x - child->x(), y - child->y());
|
||||
return { this, x, y };
|
||||
return { this, position };
|
||||
if (auto* child = child_at(position))
|
||||
return child->hit_test(position - child->relative_position());
|
||||
return { this, position };
|
||||
}
|
||||
|
||||
void GWidget::set_window(GWindow* window)
|
||||
|
|
|
@ -92,12 +92,10 @@ public:
|
|||
|
||||
struct HitTestResult {
|
||||
GWidget* widget { nullptr };
|
||||
int localX { 0 };
|
||||
int localY { 0 };
|
||||
Point local_position;
|
||||
};
|
||||
HitTestResult hit_test(int x, int y);
|
||||
|
||||
GWidget* child_at(const Point&);
|
||||
HitTestResult hit_test(const Point&);
|
||||
GWidget* child_at(const Point&) const;
|
||||
|
||||
virtual const char* class_name() const override { return "GWidget"; }
|
||||
|
||||
|
|
|
@ -191,8 +191,8 @@ void GWindow::event(CEvent& event)
|
|||
if (!m_main_widget)
|
||||
return;
|
||||
if (m_main_widget) {
|
||||
auto result = m_main_widget->hit_test(mouse_event.x(), mouse_event.y());
|
||||
auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), Point { result.localX, result.localY }, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers());
|
||||
auto result = m_main_widget->hit_test(mouse_event.position());
|
||||
auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), result.local_position, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers());
|
||||
ASSERT(result.widget);
|
||||
set_hovered_widget(result.widget);
|
||||
if (mouse_event.buttons() != 0 && !m_automatic_cursor_tracking_widget)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue