From 65353ef1f872002f3f9ad2dc58be976fdb3c69d2 Mon Sep 17 00:00:00 2001 From: Darby Johnston Date: Fri, 28 Apr 2023 11:53:40 -0700 Subject: [PATCH] Mouse event fixes --- lib/tlUI/Event.h | 2 ++ lib/tlUI/EventLoop.cpp | 32 +++++++++++++++++++++----------- lib/tlUI/ScrollArea.cpp | 1 + lib/tlUI/TimelineItem.cpp | 8 ++++---- lib/tlUI/TimelineWidget.cpp | 2 +- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lib/tlUI/Event.h b/lib/tlUI/Event.h index 83b4ace81..425f49dd3 100644 --- a/lib/tlUI/Event.h +++ b/lib/tlUI/Event.h @@ -83,6 +83,7 @@ namespace tl { int button = 0; int modifiers = 0; + math::Vector2i pos; bool accept = false; }; @@ -183,6 +184,7 @@ namespace tl struct KeyEvent { Key key = Key::Unknown; + math::Vector2i pos; bool accept = false; }; } diff --git a/lib/tlUI/EventLoop.cpp b/lib/tlUI/EventLoop.cpp index d857740f7..a4b0415af 100644 --- a/lib/tlUI/EventLoop.cpp +++ b/lib/tlUI/EventLoop.cpp @@ -18,7 +18,7 @@ namespace tl std::shared_ptr fontSystem; imaging::Size frameBufferSize; float contentScale = 1.F; - std::list > widgets; + std::list > topLevelWidgets; math::Vector2i cursorPos; std::weak_ptr hover; std::weak_ptr mousePress; @@ -82,7 +82,7 @@ namespace tl { TLRENDER_P(); widget->setEventLoop(shared_from_this()); - p.widgets.push_back(widget); + p.topLevelWidgets.push_back(widget); p.updates |= Update::Size; p.updates |= Update::Draw; } @@ -92,6 +92,7 @@ namespace tl TLRENDER_P(); KeyEvent event; event.key = key; + event.pos = p.cursorPos; } void EventLoop::cursorEnter(bool enter) @@ -125,12 +126,21 @@ namespace tl MouseClickEvent event; event.button = button; event.modifiers = modifiers; + event.pos = p.cursorPos; if (press) { - if (auto widget = p.hover.lock()) + std::list > widgets; + _underCursor(p.cursorPos, widgets); + while (!widgets.empty()) { + auto widget = widgets.back(); + widgets.pop_back(); widget->mousePressEvent(event); - p.mousePress = widget; + if (event.accept) + { + p.mousePress = widget; + break; + } } } else @@ -157,7 +167,7 @@ namespace tl if (_getSizeUpdate()) { _sizeEvent(); - for (const auto& i : p.widgets) + for (const auto& i : p.topLevelWidgets) { if (auto widget = i.lock()) { @@ -196,7 +206,7 @@ namespace tl event.iconLibrary = p.iconLibrary; event.fontSystem = p.fontSystem; event.contentScale = p.contentScale; - for (const auto& i : p.widgets) + for (const auto& i : p.topLevelWidgets) { if (auto widget = i.lock()) { @@ -220,7 +230,7 @@ namespace tl { TLRENDER_P(); bool out = p.updates & Update::Size; - for (const auto& i : p.widgets) + for (const auto& i : p.topLevelWidgets) { if (auto widget = i.lock()) { @@ -258,7 +268,7 @@ namespace tl event.fontInfo[i].size *= p.contentScale; event.fontMetrics[i] = p.fontSystem->getMetrics(event.fontInfo[i]); } - for (const auto& i : p.widgets) + for (const auto& i : p.topLevelWidgets) { if (auto widget = i.lock()) { @@ -282,7 +292,7 @@ namespace tl { TLRENDER_P(); bool out = p.updates & Update::Draw; - for (const auto& i : p.widgets) + for (const auto& i : p.topLevelWidgets) { if (auto widget = i.lock()) { @@ -326,7 +336,7 @@ namespace tl event.fontMetrics[i] = p.fontSystem->getMetrics(event.fontInfo[i]); } event.render->setClipRectEnabled(true); - for (const auto& i : p.widgets) + for (const auto& i : p.topLevelWidgets) { if (auto widget = i.lock()) { @@ -364,7 +374,7 @@ namespace tl std::list >& out) { TLRENDER_P(); - for (const auto& i : p.widgets) + for (const auto& i : p.topLevelWidgets) { if (auto widget = i.lock()) { diff --git a/lib/tlUI/ScrollArea.cpp b/lib/tlUI/ScrollArea.cpp index 4f4e1d258..f90a86847 100644 --- a/lib/tlUI/ScrollArea.cpp +++ b/lib/tlUI/ScrollArea.cpp @@ -34,6 +34,7 @@ namespace tl p.scrollAreaType = scrollAreaType; p.scrollSize = observer::Value::create(); p.scrollPos = observer::Value::create(); + setBackgroundRole(ColorRole::Base); } ScrollArea::ScrollArea() : diff --git a/lib/tlUI/TimelineItem.cpp b/lib/tlUI/TimelineItem.cpp index 87b0f5294..8f2163e41 100644 --- a/lib/tlUI/TimelineItem.cpp +++ b/lib/tlUI/TimelineItem.cpp @@ -183,7 +183,7 @@ namespace tl void TimelineItem::mouseMoveEvent(ui::MouseMoveEvent& event) { TLRENDER_P(); - //event.accept = true; + event.accept = true; p.mousePos = event.pos; if (p.currentTimeDrag) { @@ -198,16 +198,16 @@ namespace tl { event.accept = true; p.mousePress = true; - p.mousePressPos = p.mousePos; + p.mousePressPos = event.pos; if (p.stopOnScrub) { p.timelinePlayer->setPlayback(timeline::Playback::Stop); } const math::BBox2i bbox = _getCurrentTimeBBox(); - if (bbox.contains(p.mousePos)) + if (bbox.contains(event.pos)) { p.currentTimeDrag = true; - p.timelinePlayer->seek(_posToTime(p.mousePos.x)); + p.timelinePlayer->seek(_posToTime(event.pos.x)); } } } diff --git a/lib/tlUI/TimelineWidget.cpp b/lib/tlUI/TimelineWidget.cpp index cfb6f8b2e..ac04f77c4 100644 --- a/lib/tlUI/TimelineWidget.cpp +++ b/lib/tlUI/TimelineWidget.cpp @@ -254,7 +254,7 @@ namespace tl { TLRENDER_P(); event.accept = true; - p.mousePressPos = p.mousePos; + p.mousePressPos = event.pos; if (event.modifiers & static_cast(KeyModifier::Control)) { p.mouseMode = Private::MouseMode::Scroll;