You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4KB

  1. #pragma once
  2. #include <app/common.hpp>
  3. #include <app/ParamWidget.hpp>
  4. #include <context.hpp>
  5. namespace rack {
  6. namespace app {
  7. /** Implements vertical dragging behavior for ParamWidgets */
  8. struct Knob : ParamWidget {
  9. struct Internal;
  10. Internal* internal;
  11. /** Drag horizontally instead of vertically. */
  12. bool horizontal = false;
  13. /** Enables per-sample value smoothing while dragging. */
  14. bool smooth = true;
  15. /** Enables value snapping to the nearest integer. */
  16. bool snap = false;
  17. /** Multiplier for mouse movement to adjust knob value */
  18. float speed = 1.f;
  19. /** Force dragging to linear, e.g. for sliders. */
  20. bool forceLinear = false;
  21. /** Angles in radians. */
  22. float minAngle = -M_PI;
  23. float maxAngle = M_PI;
  24. Knob();
  25. ~Knob();
  26. void initParamQuantity() override;
  27. void onHover(const HoverEvent& e) override;
  28. void onButton(const ButtonEvent& e) override;
  29. void onDragStart(const DragStartEvent& e) override;
  30. void onDragEnd(const DragEndEvent& e) override;
  31. void onDragMove(const DragMoveEvent& e) override;
  32. void onDragLeave(const DragLeaveEvent& e) override;
  33. void onHoverScroll(const HoverScrollEvent& e) override;
  34. void onLeave(const LeaveEvent& e) override;
  35. /** Called when user clicks the knob without moving it.
  36. Useful for handling emulating push-knobs in hardware.
  37. */
  38. void onAction(const ActionEvent& e) override {}
  39. };
  40. } // namespace app
  41. } // namespace rack