diff --git a/dgl/EventHandlers.hpp b/dgl/EventHandlers.hpp index f06406c4..643d875a 100644 --- a/dgl/EventHandlers.hpp +++ b/dgl/EventHandlers.hpp @@ -52,6 +52,7 @@ public: bool isCheckable() const noexcept; void setCheckable(bool checkable) noexcept; + Point getLastClickPosition() const noexcept; Point getLastMotionPosition() const noexcept; void setCallback(Callback* callback) noexcept; diff --git a/dgl/src/EventHandlers.cpp b/dgl/src/EventHandlers.cpp index aba66983..1009e509 100644 --- a/dgl/src/EventHandlers.cpp +++ b/dgl/src/EventHandlers.cpp @@ -32,7 +32,8 @@ struct ButtonEventHandler::PrivateData { bool checkable; bool checked; - Point oldMotionPos; + Point lastClickPos; + Point 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), static_cast(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), static_cast(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 ButtonEventHandler::getLastClickPosition() const noexcept +{ + return pData->lastClickPos; +} + Point ButtonEventHandler::getLastMotionPosition() const noexcept { - return pData->oldMotionPos; + return pData->lastMotionPos; } void ButtonEventHandler::setCallback(Callback* const callback) noexcept