Browse Source

Add ButtonEventHandler::getLastMotionPosition(), fix whitespace

pull/295/head
falkTX 4 years ago
parent
commit
accb8c96da
2 changed files with 13 additions and 10 deletions
  1. +5
    -3
      dgl/EventHandlers.hpp
  2. +8
    -7
      dgl/src/EventHandlers.cpp

+ 5
- 3
dgl/EventHandlers.hpp View File

@@ -52,16 +52,18 @@ public:
bool isCheckable() const noexcept; bool isCheckable() const noexcept;
void setCheckable(bool checkable) noexcept; void setCheckable(bool checkable) noexcept;


Point<double> getLastMotionPosition() const noexcept;

void setCallback(Callback* callback) noexcept; void setCallback(Callback* callback) noexcept;


bool mouseEvent(const Widget::MouseEvent& ev); bool mouseEvent(const Widget::MouseEvent& ev);
bool motionEvent(const Widget::MotionEvent& ev); bool motionEvent(const Widget::MotionEvent& ev);


protected: protected:
State getState() const noexcept;
void clearState() noexcept;
State getState() const noexcept;
void clearState() noexcept;


virtual void stateChanged(State state, State oldState);
virtual void stateChanged(State state, State oldState);


void setInternalCallback(Callback* callback) noexcept; void setInternalCallback(Callback* callback) noexcept;
void triggerUserCallback(SubWidget* widget, int button); void triggerUserCallback(SubWidget* widget, int button);


+ 8
- 7
dgl/src/EventHandlers.cpp View File

@@ -59,18 +59,14 @@ struct ButtonEventHandler::PrivateData {
const int state2 = state; const int state2 = state;
state &= ~kButtonStateActive; state &= ~kButtonStateActive;


self->stateChanged(static_cast<State>(state), static_cast<State>(state2));
widget->repaint();

// cursor was moved outside the button bounds, ignore click // cursor was moved outside the button bounds, ignore click
if (! widget->contains(ev.pos)) if (! widget->contains(ev.pos))
{
self->stateChanged(static_cast<State>(state), static_cast<State>(state2));
widget->repaint();
return true; return true;
}


// still on bounds, register click // still on bounds, register click
self->stateChanged(static_cast<State>(state), static_cast<State>(state2));
widget->repaint();

if (checkable) if (checkable)
checked = !checked; checked = !checked;


@@ -217,6 +213,11 @@ void ButtonEventHandler::setCheckable(const bool checkable) noexcept
pData->checkable = checkable; pData->checkable = checkable;
} }


Point<double> ButtonEventHandler::getLastMotionPosition() const noexcept
{
return pData->oldMotionPos;
}

void ButtonEventHandler::setCallback(Callback* const callback) noexcept void ButtonEventHandler::setCallback(Callback* const callback) noexcept
{ {
pData->userCallback = callback; pData->userCallback = callback;


Loading…
Cancel
Save