Browse Source

Dispatch Action event on Knob when clicking and releasing without moving beyond a threshold distance.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
84b98e9d96
2 changed files with 18 additions and 0 deletions
  1. +4
    -0
      include/app/Knob.hpp
  2. +14
    -0
      src/app/Knob.cpp

+ 4
- 0
include/app/Knob.hpp View File

@@ -38,6 +38,10 @@ struct Knob : ParamWidget {
void onDragLeave(const DragLeaveEvent& e) override;
void onHoverScroll(const HoverScrollEvent& e) override;
void onLeave(const LeaveEvent& e) override;
/** Called when user clicks the knob without moving it.
Useful for handling emulating push-knobs in hardware.
*/
void onAction(const ActionEvent& e) override {}
};




+ 14
- 0
src/app/Knob.cpp View File

@@ -24,6 +24,8 @@ struct Knob::Internal {
/** The mouse has once escaped from the knob while dragging. */
bool rotaryDragEnabled = false;
float dragAngle = NAN;

float distDragged = 0.f;
};


@@ -83,6 +85,9 @@ void Knob::onDragStart(const DragStartEvent& e) {
internal->rotaryDragEnabled = false;
internal->dragAngle = NAN;

// Reset distance dragged
internal->distDragged = 0.f;

ParamWidget::onDragStart(e);
}

@@ -113,6 +118,13 @@ void Knob::onDragEnd(const DragEndEvent& e) {
}
internal->oldValue = NAN;

// Dispatch Action event if mouse traveled less than a threshold distance
const float actionDistThreshold = 16.f;
if (internal->distDragged < actionDistThreshold) {
ActionEvent eAction;
onAction(eAction);
}

ParamWidget::onDragEnd(e);
}

@@ -213,6 +225,8 @@ void Knob::onDragMove(const DragMoveEvent& e) {
pq->setSmoothValue(value);
}

internal->distDragged += e.mouseDelta.norm();

ParamWidget::onDragMove(e);
}



Loading…
Cancel
Save