Skip to content

Commit

Permalink
Mouse event fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Apr 28, 2023
1 parent 7f3f508 commit 65353ef
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lib/tlUI/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace tl
{
int button = 0;
int modifiers = 0;
math::Vector2i pos;
bool accept = false;
};

Expand Down Expand Up @@ -183,6 +184,7 @@ namespace tl
struct KeyEvent
{
Key key = Key::Unknown;
math::Vector2i pos;
bool accept = false;
};
}
Expand Down
32 changes: 21 additions & 11 deletions lib/tlUI/EventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace tl
std::shared_ptr<imaging::FontSystem> fontSystem;
imaging::Size frameBufferSize;
float contentScale = 1.F;
std::list<std::weak_ptr<IWidget> > widgets;
std::list<std::weak_ptr<IWidget> > topLevelWidgets;
math::Vector2i cursorPos;
std::weak_ptr<IWidget> hover;
std::weak_ptr<IWidget> mousePress;
Expand Down Expand Up @@ -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;
}
Expand All @@ -92,6 +92,7 @@ namespace tl
TLRENDER_P();
KeyEvent event;
event.key = key;
event.pos = p.cursorPos;
}

void EventLoop::cursorEnter(bool enter)
Expand Down Expand Up @@ -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<std::shared_ptr<IWidget> > 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
Expand All @@ -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())
{
Expand Down Expand Up @@ -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())
{
Expand All @@ -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())
{
Expand Down Expand Up @@ -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())
{
Expand All @@ -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())
{
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -364,7 +374,7 @@ namespace tl
std::list<std::shared_ptr<IWidget> >& out)
{
TLRENDER_P();
for (const auto& i : p.widgets)
for (const auto& i : p.topLevelWidgets)
{
if (auto widget = i.lock())
{
Expand Down
1 change: 1 addition & 0 deletions lib/tlUI/ScrollArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace tl
p.scrollAreaType = scrollAreaType;
p.scrollSize = observer::Value<math::Vector2i>::create();
p.scrollPos = observer::Value<math::Vector2i>::create();
setBackgroundRole(ColorRole::Base);
}

ScrollArea::ScrollArea() :
Expand Down
8 changes: 4 additions & 4 deletions lib/tlUI/TimelineItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tlUI/TimelineWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ namespace tl
{
TLRENDER_P();
event.accept = true;
p.mousePressPos = p.mousePos;
p.mousePressPos = event.pos;
if (event.modifiers & static_cast<int>(KeyModifier::Control))
{
p.mouseMode = Private::MouseMode::Scroll;
Expand Down

0 comments on commit 65353ef

Please sign in to comment.