Widgets: Rework event dispatching
This commit is contained in:
parent
05c78da22a
commit
0fcf24f336
|
|
@ -102,15 +102,14 @@ namespace Nz
|
||||||
void OnFocusLost() override;
|
void OnFocusLost() override;
|
||||||
void OnFocusReceived() override;
|
void OnFocusReceived() override;
|
||||||
bool OnKeyPressed(const WindowEvent::KeyEvent& key) override;
|
bool OnKeyPressed(const WindowEvent::KeyEvent& key) override;
|
||||||
void OnKeyReleased(const WindowEvent::KeyEvent& key) override;
|
bool OnMouseButtonDoublePress(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseButtonDoublePress(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonTriplePress(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseButtonTriplePress(int x, int y, Mouse::Button button) override;
|
|
||||||
void OnMouseEnter() override;
|
void OnMouseEnter() override;
|
||||||
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
bool OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
||||||
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
||||||
void OnTextEntered(char32_t character, bool repeated) override;
|
bool OnTextEntered(char32_t character, bool repeated) override;
|
||||||
|
|
||||||
virtual void PasteFromClipboard(const Vector2ui& targetPosition) = 0;
|
virtual void PasteFromClipboard(const Vector2ui& targetPosition) = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,19 +128,19 @@ namespace Nz
|
||||||
virtual void OnFocusLost();
|
virtual void OnFocusLost();
|
||||||
virtual void OnFocusReceived();
|
virtual void OnFocusReceived();
|
||||||
virtual bool OnKeyPressed(const WindowEvent::KeyEvent& key);
|
virtual bool OnKeyPressed(const WindowEvent::KeyEvent& key);
|
||||||
virtual void OnKeyReleased(const WindowEvent::KeyEvent& key);
|
virtual bool OnKeyReleased(const WindowEvent::KeyEvent& key);
|
||||||
virtual void OnMouseEnter();
|
virtual void OnMouseEnter();
|
||||||
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
|
virtual bool OnMouseMoved(int x, int y, int deltaX, int deltaY);
|
||||||
virtual void OnMouseButtonDoublePress(int x, int y, Mouse::Button button);
|
virtual bool OnMouseButtonDoublePress(int x, int y, Mouse::Button button);
|
||||||
virtual void OnMouseButtonPress(int x, int y, Mouse::Button button);
|
virtual bool OnMouseButtonPress(int x, int y, Mouse::Button button);
|
||||||
virtual void OnMouseButtonRelease(int x, int y, Mouse::Button button);
|
virtual bool OnMouseButtonRelease(int x, int y, Mouse::Button button);
|
||||||
virtual void OnMouseButtonTriplePress(int x, int y, Mouse::Button button);
|
virtual bool OnMouseButtonTriplePress(int x, int y, Mouse::Button button);
|
||||||
virtual void OnMouseWheelMoved(int x, int y, float delta);
|
virtual bool OnMouseWheelMoved(int x, int y, float delta);
|
||||||
virtual void OnMouseExit();
|
virtual void OnMouseExit();
|
||||||
virtual void OnRenderLayerUpdated(int baseRenderLayer);
|
virtual void OnRenderLayerUpdated(int baseRenderLayer);
|
||||||
virtual void OnParentResized(const Vector2f& newSize);
|
virtual void OnParentResized(const Vector2f& newSize);
|
||||||
virtual void OnTextEntered(char32_t character, bool repeated);
|
virtual bool OnTextEntered(char32_t character, bool repeated);
|
||||||
virtual void OnTextEdited(const std::array<char, 32>& characters, int length);
|
virtual bool OnTextEdited(const std::array<char, 32>& characters, int length);
|
||||||
|
|
||||||
inline void SetBaseRenderLayer(int baseRenderLayer);
|
inline void SetBaseRenderLayer(int baseRenderLayer);
|
||||||
inline void SetPreferredSize(const Vector2f& preferredSize);
|
inline void SetPreferredSize(const Vector2f& preferredSize);
|
||||||
|
|
@ -156,6 +156,7 @@ namespace Nz
|
||||||
inline bool IsRegisteredToCanvas() const;
|
inline bool IsRegisteredToCanvas() const;
|
||||||
inline void NotifyParentResized(const Vector2f& newSize);
|
inline void NotifyParentResized(const Vector2f& newSize);
|
||||||
void RegisterToCanvas();
|
void RegisterToCanvas();
|
||||||
|
void SetParent(BaseWidget* widget);
|
||||||
inline void UpdateCanvasIndex(std::size_t index);
|
inline void UpdateCanvasIndex(std::size_t index);
|
||||||
void UnregisterFromCanvas();
|
void UnregisterFromCanvas();
|
||||||
void UpdatePositionAndSize();
|
void UpdatePositionAndSize();
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ namespace Nz
|
||||||
void Layout() override;
|
void Layout() override;
|
||||||
|
|
||||||
void OnMouseEnter() override;
|
void OnMouseEnter() override;
|
||||||
void OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseExit() override;
|
void OnMouseExit() override;
|
||||||
|
|
||||||
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,8 @@ namespace Nz
|
||||||
void UnregisterWidget(std::size_t index);
|
void UnregisterWidget(std::size_t index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template<typename F> void DispatchEvent(std::size_t widgetIndex, F&& functor);
|
||||||
|
|
||||||
void OnEventMouseButtonPressed(const EventHandler* eventHandler, const WindowEvent::MouseButtonEvent& event);
|
void OnEventMouseButtonPressed(const EventHandler* eventHandler, const WindowEvent::MouseButtonEvent& event);
|
||||||
void OnEventMouseButtonRelease(const EventHandler* eventHandler, const WindowEvent::MouseButtonEvent& event);
|
void OnEventMouseButtonRelease(const EventHandler* eventHandler, const WindowEvent::MouseButtonEvent& event);
|
||||||
void OnEventMouseEntered(const EventHandler* eventHandler);
|
void OnEventMouseEntered(const EventHandler* eventHandler);
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ namespace Nz
|
||||||
void Layout() override;
|
void Layout() override;
|
||||||
|
|
||||||
void OnMouseEnter() override;
|
void OnMouseEnter() override;
|
||||||
void OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseExit() override;
|
void OnMouseExit() override;
|
||||||
|
|
||||||
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,8 @@ namespace Nz
|
||||||
void Layout() override;
|
void Layout() override;
|
||||||
|
|
||||||
void OnMouseEnter() override;
|
void OnMouseEnter() override;
|
||||||
void OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseExit() override;
|
void OnMouseExit() override;
|
||||||
|
|
||||||
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,10 @@ namespace Nz
|
||||||
void Layout() override;
|
void Layout() override;
|
||||||
|
|
||||||
void OnMouseEnter() override;
|
void OnMouseEnter() override;
|
||||||
void OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonPress(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
bool OnMouseButtonRelease(int x, int y, Mouse::Button button) override;
|
||||||
void OnMouseExit() override;
|
void OnMouseExit() override;
|
||||||
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
bool OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
||||||
|
|
||||||
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -394,11 +394,7 @@ namespace Nz
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTextAreaWidget::OnKeyReleased(const WindowEvent::KeyEvent& /*key*/)
|
bool AbstractTextAreaWidget::OnMouseButtonDoublePress(int x, int y, Mouse::Button button)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void AbstractTextAreaWidget::OnMouseButtonDoublePress(int x, int y, Mouse::Button button)
|
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
{
|
{
|
||||||
|
|
@ -412,10 +408,13 @@ namespace Nz
|
||||||
HandleWordSelection(hoveredGlyph);
|
HandleWordSelection(hoveredGlyph);
|
||||||
|
|
||||||
m_isMouseButtonDown = true;
|
m_isMouseButtonDown = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTextAreaWidget::OnMouseButtonPress(int x, int y, Mouse::Button button)
|
bool AbstractTextAreaWidget::OnMouseButtonPress(int x, int y, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
{
|
{
|
||||||
|
|
@ -433,16 +432,24 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
m_isMouseButtonDown = true;
|
m_isMouseButtonDown = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTextAreaWidget::OnMouseButtonRelease(int, int, Mouse::Button button)
|
bool AbstractTextAreaWidget::OnMouseButtonRelease(int, int, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
|
{
|
||||||
m_isMouseButtonDown = false;
|
m_isMouseButtonDown = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTextAreaWidget::OnMouseButtonTriplePress(int x, int y, Mouse::Button button)
|
bool AbstractTextAreaWidget::OnMouseButtonTriplePress(int x, int y, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
{
|
{
|
||||||
|
|
@ -456,7 +463,10 @@ namespace Nz
|
||||||
SetSelection(Vector2ui(0, hoveredGlyph.y), Vector2ui(std::numeric_limits<unsigned int>::max(), hoveredGlyph.y));
|
SetSelection(Vector2ui(0, hoveredGlyph.y), Vector2ui(std::numeric_limits<unsigned int>::max(), hoveredGlyph.y));
|
||||||
|
|
||||||
m_isMouseButtonDown = true;
|
m_isMouseButtonDown = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTextAreaWidget::OnMouseEnter()
|
void AbstractTextAreaWidget::OnMouseEnter()
|
||||||
|
|
@ -465,10 +475,15 @@ namespace Nz
|
||||||
m_isMouseButtonDown = false;
|
m_isMouseButtonDown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTextAreaWidget::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
|
bool AbstractTextAreaWidget::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
|
||||||
{
|
{
|
||||||
if (m_isMouseButtonDown)
|
if (m_isMouseButtonDown)
|
||||||
|
{
|
||||||
SetSelection(m_selectionCursor, GetHoveredGlyph(float(x), float(y)));
|
SetSelection(m_selectionCursor, GetHoveredGlyph(float(x), float(y)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTextAreaWidget::OnRenderLayerUpdated(int baseRenderLayer)
|
void AbstractTextAreaWidget::OnRenderLayerUpdated(int baseRenderLayer)
|
||||||
|
|
@ -478,18 +493,19 @@ namespace Nz
|
||||||
cursor.sprite->UpdateRenderLayer(baseRenderLayer + 1);
|
cursor.sprite->UpdateRenderLayer(baseRenderLayer + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTextAreaWidget::OnTextEntered(char32_t character, bool /*repeated*/)
|
bool AbstractTextAreaWidget::OnTextEntered(char32_t character, bool /*repeated*/)
|
||||||
{
|
{
|
||||||
if (m_readOnly)
|
if (m_readOnly)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (Unicode::GetCategory(character) == Unicode::Category_Other_Control || (m_characterFilter && !m_characterFilter(character)))
|
if (Unicode::GetCategory(character) == Unicode::Category_Other_Control || (m_characterFilter && !m_characterFilter(character)))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
if (HasSelection())
|
if (HasSelection())
|
||||||
EraseSelection();
|
EraseSelection();
|
||||||
|
|
||||||
Write(FromUtf32String(std::u32string_view(&character, 1)));
|
Write(FromUtf32String(std::u32string_view(&character, 1)));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractTextAreaWidget::RefreshCursor()
|
void AbstractTextAreaWidget::RefreshCursor()
|
||||||
|
|
|
||||||
|
|
@ -276,38 +276,43 @@ namespace Nz
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnKeyReleased(const WindowEvent::KeyEvent& /*key*/)
|
bool BaseWidget::OnKeyReleased(const WindowEvent::KeyEvent& /*key*/)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnMouseEnter()
|
void BaseWidget::OnMouseEnter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnMouseMoved(int /*x*/, int /*y*/, int /*deltaX*/, int /*deltaY*/)
|
bool BaseWidget::OnMouseMoved(int /*x*/, int /*y*/, int /*deltaX*/, int /*deltaY*/)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnMouseButtonDoublePress(int x, int y, Mouse::Button button)
|
bool BaseWidget::OnMouseButtonDoublePress(int x, int y, Mouse::Button button)
|
||||||
{
|
{
|
||||||
return OnMouseButtonPress(x, y, button);
|
return OnMouseButtonPress(x, y, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Mouse::Button /*button*/)
|
bool BaseWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Mouse::Button /*button*/)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnMouseButtonRelease(int /*x*/, int /*y*/, Mouse::Button /*button*/)
|
bool BaseWidget::OnMouseButtonRelease(int /*x*/, int /*y*/, Mouse::Button /*button*/)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnMouseButtonTriplePress(int x, int y, Mouse::Button button)
|
bool BaseWidget::OnMouseButtonTriplePress(int x, int y, Mouse::Button button)
|
||||||
{
|
{
|
||||||
return OnMouseButtonPress(x, y, button);
|
return OnMouseButtonPress(x, y, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnMouseWheelMoved(int /*x*/, int /*y*/, float /*delta*/)
|
bool BaseWidget::OnMouseWheelMoved(int /*x*/, int /*y*/, float /*delta*/)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnMouseExit()
|
void BaseWidget::OnMouseExit()
|
||||||
|
|
@ -322,12 +327,14 @@ namespace Nz
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnTextEntered(char32_t /*character*/, bool /*repeated*/)
|
bool BaseWidget::OnTextEntered(char32_t /*character*/, bool /*repeated*/)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::OnTextEdited(const std::array<char, 32>& /*characters*/, int /*length*/)
|
bool BaseWidget::OnTextEdited(const std::array<char, 32>& /*characters*/, int /*length*/)
|
||||||
{
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWidget::ShowChildren(bool show)
|
void BaseWidget::ShowChildren(bool show)
|
||||||
|
|
@ -360,6 +367,20 @@ namespace Nz
|
||||||
m_canvasIndex = m_canvas->RegisterWidget(this);
|
m_canvasIndex = m_canvas->RegisterWidget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseWidget::SetParent(BaseWidget* widget)
|
||||||
|
{
|
||||||
|
Canvas* oldCanvas = m_canvas;
|
||||||
|
Canvas* newCanvas = widget->GetCanvas();
|
||||||
|
|
||||||
|
// Changing a widget canvas is a problem because of the canvas entities
|
||||||
|
NazaraAssert(oldCanvas == newCanvas, "Transferring a widget between canvas is not yet supported");
|
||||||
|
|
||||||
|
Node::SetParent(widget);
|
||||||
|
m_widgetParent = widget;
|
||||||
|
|
||||||
|
Layout();
|
||||||
|
}
|
||||||
|
|
||||||
void BaseWidget::UnregisterFromCanvas()
|
void BaseWidget::UnregisterFromCanvas()
|
||||||
{
|
{
|
||||||
if (IsRegisteredToCanvas())
|
if (IsRegisteredToCanvas())
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,18 @@ namespace Nz
|
||||||
m_style->Layout(GetSize());
|
m_style->Layout(GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Mouse::Button button)
|
bool ButtonWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
|
{
|
||||||
m_style->OnPress();
|
m_style->OnPress();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonWidget::OnMouseButtonRelease(int x, int y, Mouse::Button button)
|
bool ButtonWidget::OnMouseButtonRelease(int x, int y, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
{
|
{
|
||||||
|
|
@ -50,7 +55,11 @@ namespace Nz
|
||||||
// we don't want this to trigger the button, so double-check
|
// we don't want this to trigger the button, so double-check
|
||||||
if (IsInside(float(x), float(y)))
|
if (IsInside(float(x), float(y)))
|
||||||
OnButtonTrigger(this);
|
OnButtonTrigger(this);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonWidget::OnMouseEnter()
|
void ButtonWidget::OnMouseEnter()
|
||||||
|
|
|
||||||
|
|
@ -90,23 +90,40 @@ namespace Nz
|
||||||
m_widgetEntries.pop_back();
|
m_widgetEntries.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename F>
|
||||||
|
void Canvas::DispatchEvent(std::size_t widgetIndex, F&& functor)
|
||||||
|
{
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
WidgetEntry& targetWidget = m_widgetEntries[widgetIndex];
|
||||||
|
if (functor(targetWidget))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!targetWidget.widget->m_widgetParent)
|
||||||
|
return;
|
||||||
|
|
||||||
|
widgetIndex = targetWidget.widget->m_widgetParent->m_canvasIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Canvas::OnEventMouseButtonPressed(const EventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& event)
|
void Canvas::OnEventMouseButtonPressed(const EventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& event)
|
||||||
{
|
{
|
||||||
UpdateHoveredWidget(event.x, event.y);
|
UpdateHoveredWidget(event.x, event.y);
|
||||||
|
|
||||||
if (std::size_t targetWidgetIndex = GetMouseEventTarget(); targetWidgetIndex != InvalidCanvasIndex)
|
if (std::size_t targetWidgetIndex = GetMouseEventTarget(); targetWidgetIndex != InvalidCanvasIndex)
|
||||||
{
|
{
|
||||||
WidgetEntry& targetWidget = m_widgetEntries[targetWidgetIndex];
|
DispatchEvent(targetWidgetIndex, [&](WidgetEntry& widgetEntry)
|
||||||
|
{
|
||||||
|
int x = static_cast<int>(std::round(event.x - widgetEntry.box.x));
|
||||||
|
int y = static_cast<int>(std::round(m_size.y - event.y - widgetEntry.box.y));
|
||||||
|
|
||||||
int x = static_cast<int>(std::round(event.x - targetWidget.box.x));
|
if (event.clickCount == 2)
|
||||||
int y = static_cast<int>(std::round(m_size.y - event.y - targetWidget.box.y));
|
return widgetEntry.widget->OnMouseButtonDoublePress(x, y, event.button);
|
||||||
|
else if (event.clickCount == 3)
|
||||||
if (event.clickCount == 2)
|
return widgetEntry.widget->OnMouseButtonTriplePress(x, y, event.button);
|
||||||
targetWidget.widget->OnMouseButtonDoublePress(x, y, event.button);
|
else
|
||||||
else if (event.clickCount == 3)
|
return widgetEntry.widget->OnMouseButtonPress(x, y, event.button);
|
||||||
targetWidget.widget->OnMouseButtonTriplePress(x, y, event.button);
|
});
|
||||||
else
|
|
||||||
targetWidget.widget->OnMouseButtonPress(x, y, event.button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetMouseOwner(m_hoveredWidget);
|
SetMouseOwner(m_hoveredWidget);
|
||||||
|
|
@ -117,12 +134,13 @@ namespace Nz
|
||||||
{
|
{
|
||||||
if (std::size_t targetWidgetIndex = GetMouseEventTarget(); targetWidgetIndex != InvalidCanvasIndex)
|
if (std::size_t targetWidgetIndex = GetMouseEventTarget(); targetWidgetIndex != InvalidCanvasIndex)
|
||||||
{
|
{
|
||||||
WidgetEntry& targetWidget = m_widgetEntries[targetWidgetIndex];
|
DispatchEvent(targetWidgetIndex, [&](WidgetEntry& widgetEntry)
|
||||||
|
{
|
||||||
|
int x = static_cast<int>(std::round(event.x - widgetEntry.box.x));
|
||||||
|
int y = static_cast<int>(std::round(m_size.y - event.y - widgetEntry.box.y));
|
||||||
|
|
||||||
int x = static_cast<int>(std::round(event.x - targetWidget.box.x));
|
return widgetEntry.widget->OnMouseButtonRelease(x, y, event.button);
|
||||||
int y = static_cast<int>(std::round(m_size.y - event.y - targetWidget.box.y));
|
});
|
||||||
|
|
||||||
targetWidget.widget->OnMouseButtonRelease(x, y, event.button);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_mouseOwnerButtons[event.button] = false;
|
m_mouseOwnerButtons[event.button] = false;
|
||||||
|
|
@ -187,12 +205,13 @@ namespace Nz
|
||||||
{
|
{
|
||||||
if (std::size_t targetWidgetIndex = GetMouseEventTarget(); targetWidgetIndex != InvalidCanvasIndex)
|
if (std::size_t targetWidgetIndex = GetMouseEventTarget(); targetWidgetIndex != InvalidCanvasIndex)
|
||||||
{
|
{
|
||||||
WidgetEntry& targetWidget = m_widgetEntries[targetWidgetIndex];
|
DispatchEvent(targetWidgetIndex, [&](WidgetEntry& widgetEntry)
|
||||||
|
{
|
||||||
|
int x = static_cast<int>(std::round(event.x - widgetEntry.box.x));
|
||||||
|
int y = static_cast<int>(std::round(m_size.y - event.y - widgetEntry.box.y));
|
||||||
|
|
||||||
int x = static_cast<int>(std::round(event.x - targetWidget.box.x));
|
return widgetEntry.widget->OnMouseWheelMoved(x, y, event.delta);
|
||||||
int y = static_cast<int>(std::round(m_size.y - event.y - targetWidget.box.y));
|
});
|
||||||
|
|
||||||
targetWidget.widget->OnMouseWheelMoved(x, y, event.delta);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -278,19 +297,22 @@ namespace Nz
|
||||||
{
|
{
|
||||||
std::size_t bestEntry = InvalidCanvasIndex;
|
std::size_t bestEntry = InvalidCanvasIndex;
|
||||||
float bestEntryArea = std::numeric_limits<float>::infinity();
|
float bestEntryArea = std::numeric_limits<float>::infinity();
|
||||||
|
int bestEntryLayer = std::numeric_limits<int>::min();
|
||||||
|
|
||||||
Vector3f mousePos(float(x), m_size.y - float(y), 0.f);
|
Vector3f mousePos(float(x), m_size.y - float(y), 0.f);
|
||||||
for (std::size_t i = 0; i < m_widgetEntries.size(); ++i)
|
for (std::size_t i = 0; i < m_widgetEntries.size(); ++i)
|
||||||
{
|
{
|
||||||
const Boxf& box = m_widgetEntries[i].box;
|
const Boxf& box = m_widgetEntries[i].box;
|
||||||
|
int layer = m_widgetEntries[i].widget->GetBaseRenderLayer();
|
||||||
|
|
||||||
if (box.Contains(mousePos))
|
if (box.Contains(mousePos))
|
||||||
{
|
{
|
||||||
float area = box.width * box.height;
|
float area = box.width * box.height;
|
||||||
if (area < bestEntryArea)
|
if (area < bestEntryArea && layer >= bestEntryLayer)
|
||||||
{
|
{
|
||||||
bestEntry = i;
|
bestEntry = i;
|
||||||
bestEntryArea = area;
|
bestEntryArea = area;
|
||||||
|
bestEntryLayer = layer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,13 +41,18 @@ namespace Nz
|
||||||
m_style->Layout(GetSize());
|
m_style->Layout(GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckboxWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Mouse::Button button)
|
bool CheckboxWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
|
{
|
||||||
m_style->OnPress();
|
m_style->OnPress();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckboxWidget::OnMouseButtonRelease(int x, int y, Mouse::Button button)
|
bool CheckboxWidget::OnMouseButtonRelease(int x, int y, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
{
|
{
|
||||||
|
|
@ -57,7 +62,11 @@ namespace Nz
|
||||||
// we don't want this to trigger the button, so double-check
|
// we don't want this to trigger the button, so double-check
|
||||||
if (IsInside(x, y))
|
if (IsInside(x, y))
|
||||||
SwitchToNextState();
|
SwitchToNextState();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckboxWidget::OnMouseEnter()
|
void CheckboxWidget::OnMouseEnter()
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,18 @@ namespace Nz
|
||||||
m_style->Layout(GetSize());
|
m_style->Layout(GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageButtonWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Mouse::Button button)
|
bool ImageButtonWidget::OnMouseButtonPress(int /*x*/, int /*y*/, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
|
{
|
||||||
m_style->OnPress();
|
m_style->OnPress();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageButtonWidget::OnMouseButtonRelease(int x, int y, Mouse::Button button)
|
bool ImageButtonWidget::OnMouseButtonRelease(int x, int y, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
{
|
{
|
||||||
|
|
@ -48,7 +53,11 @@ namespace Nz
|
||||||
// we don't want this to trigger the button, so double-check
|
// we don't want this to trigger the button, so double-check
|
||||||
if (IsInside(float(x), float(y)))
|
if (IsInside(float(x), float(y)))
|
||||||
OnButtonTrigger(this);
|
OnButtonTrigger(this);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageButtonWidget::OnMouseEnter()
|
void ImageButtonWidget::OnMouseEnter()
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Nz
|
||||||
m_style->Layout(GetSize());
|
m_style->Layout(GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollbarButtonWidget::OnMouseButtonPress(int x, int y, Mouse::Button button)
|
bool ScrollbarButtonWidget::OnMouseButtonPress(int x, int y, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
{
|
{
|
||||||
|
|
@ -31,10 +31,13 @@ namespace Nz
|
||||||
OnButtonGrabbed(this, x, y);
|
OnButtonGrabbed(this, x, y);
|
||||||
|
|
||||||
m_style->OnGrab();
|
m_style->OnGrab();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollbarButtonWidget::OnMouseButtonRelease(int x, int y, Mouse::Button button)
|
bool ScrollbarButtonWidget::OnMouseButtonRelease(int x, int y, Mouse::Button button)
|
||||||
{
|
{
|
||||||
if (button == Mouse::Left)
|
if (button == Mouse::Left)
|
||||||
{
|
{
|
||||||
|
|
@ -42,7 +45,10 @@ namespace Nz
|
||||||
OnButtonReleased(this);
|
OnButtonReleased(this);
|
||||||
|
|
||||||
m_style->OnRelease();
|
m_style->OnRelease();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollbarButtonWidget::OnMouseEnter()
|
void ScrollbarButtonWidget::OnMouseEnter()
|
||||||
|
|
@ -55,10 +61,15 @@ namespace Nz
|
||||||
m_style->OnHoverEnd();
|
m_style->OnHoverEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollbarButtonWidget::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
|
bool ScrollbarButtonWidget::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/)
|
||||||
{
|
{
|
||||||
if (m_isGrabbed)
|
if (m_isGrabbed)
|
||||||
|
{
|
||||||
OnButtonMoved(this, x, y);
|
OnButtonMoved(this, x, y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollbarButtonWidget::OnRenderLayerUpdated(int baseRenderLayer)
|
void ScrollbarButtonWidget::OnRenderLayerUpdated(int baseRenderLayer)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue