DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 45eb87d01c660e44cc7cd17dcdba121ce0d6d8f7
parent accb8c96daf69708bd81f93b7c057637be49aec9
Author: falkTX <falktx@falktx.com>
Date:   Sat, 26 Jun 2021 23:33:19 +0100

Add ButtonEventHandler::getLastClickPosition()

Diffstat:
Mdgl/EventHandlers.hpp | 1+
Mdgl/src/EventHandlers.cpp | 23++++++++++++++++-------
2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/dgl/EventHandlers.hpp b/dgl/EventHandlers.hpp @@ -52,6 +52,7 @@ public: bool isCheckable() const noexcept; void setCheckable(bool checkable) noexcept; + Point<double> getLastClickPosition() const noexcept; Point<double> getLastMotionPosition() const noexcept; void setCallback(Callback* callback) noexcept; diff --git a/dgl/src/EventHandlers.cpp b/dgl/src/EventHandlers.cpp @@ -32,7 +32,8 @@ struct ButtonEventHandler::PrivateData { bool checkable; bool checked; - Point<double> oldMotionPos; + Point<double> lastClickPos; + Point<double> lastMotionPos; PrivateData(ButtonEventHandler* const s, SubWidget* const w) : self(s), @@ -43,10 +44,13 @@ struct ButtonEventHandler::PrivateData { state(kButtonStateDefault), checkable(false), checked(false), - oldMotionPos(0, 0) {} + lastClickPos(0, 0), + lastMotionPos(0, 0) {} bool mouseEvent(const Widget::MouseEvent& ev) { + lastClickPos = ev.pos; + // button was released, handle it now if (button != -1 && ! ev.press) { @@ -97,7 +101,7 @@ struct ButtonEventHandler::PrivateData { // keep pressed if (button != -1) { - oldMotionPos = ev.pos; + lastMotionPos = ev.pos; return true; } @@ -110,7 +114,7 @@ struct ButtonEventHandler::PrivateData { { const int state2 = state; state |= kButtonStateHover; - ret = widget->contains(oldMotionPos); + ret = widget->contains(lastMotionPos); self->stateChanged(static_cast<State>(state), static_cast<State>(state2)); widget->repaint(); } @@ -122,13 +126,13 @@ struct ButtonEventHandler::PrivateData { { const int state2 = state; state &= ~kButtonStateHover; - ret = widget->contains(oldMotionPos); + ret = widget->contains(lastMotionPos); self->stateChanged(static_cast<State>(state), static_cast<State>(state2)); widget->repaint(); } } - oldMotionPos = ev.pos; + lastMotionPos = ev.pos; return ret; } @@ -213,9 +217,14 @@ void ButtonEventHandler::setCheckable(const bool checkable) noexcept pData->checkable = checkable; } +Point<double> ButtonEventHandler::getLastClickPosition() const noexcept +{ + return pData->lastClickPos; +} + Point<double> ButtonEventHandler::getLastMotionPosition() const noexcept { - return pData->oldMotionPos; + return pData->lastMotionPos; } void ButtonEventHandler::setCallback(Callback* const callback) noexcept