| 15 | } |
| 16 | |
| 17 | void UIButton::Listener::onBeginFrame() FL_NOEXCEPT { |
| 18 | bool clicked_this_frame = mOwner->clicked(); |
| 19 | bool pressed_this_frame = mOwner->isPressed(); |
| 20 | |
| 21 | // Check the real button if one is attached (via IButtonInput interface) |
| 22 | if (mOwner->mButtonInput) { |
| 23 | // Edge-detect rising transitions of mButtonInput->clicked() so |
| 24 | // clickedCount() reflects real-button presses on platforms where |
| 25 | // UIButtonImpl::clickedCount() is a no-op stub. |
| 26 | const bool real_clicked = mOwner->mButtonInput->clicked(); |
| 27 | if (real_clicked && !mRealButtonClickedLastFrame) { |
| 28 | ++mRealButtonClickCount; |
| 29 | } |
| 30 | mRealButtonClickedLastFrame = real_clicked; |
| 31 | |
| 32 | if (mOwner->mButtonInput->isPressed()) { |
| 33 | clicked_this_frame = true; |
| 34 | pressed_this_frame = true; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | // Detect press event (was not pressed, now is pressed) |
| 39 | if (pressed_this_frame && !mPressedLastFrame) { |
| 40 | mOwner->mPressCallbacks.invoke(); |
| 41 | } |
| 42 | |
| 43 | // Detect release event (was pressed, now is not pressed) |
| 44 | if (!pressed_this_frame && mPressedLastFrame) { |
| 45 | mOwner->mReleaseCallbacks.invoke(); |
| 46 | } |
| 47 | |
| 48 | mPressedLastFrame = pressed_this_frame; |
| 49 | |
| 50 | const bool clicked_changed = (clicked_this_frame != mClickedLastFrame); |
| 51 | mClickedLastFrame = clicked_this_frame; |
| 52 | if (clicked_changed) { |
| 53 | mOwner->mCallbacks.invoke(*mOwner); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | } // namespace fl |