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.

47 lines
920B

  1. #pragma once
  2. #include "app/common.hpp"
  3. #include "app/ParamWidget.hpp"
  4. namespace rack {
  5. static const float KNOB_SENSITIVITY = 0.0015f;
  6. /** Implements vertical dragging behavior for ParamWidgets */
  7. struct Knob : ParamWidget {
  8. /** Multiplier for mouse movement to adjust knob value */
  9. float speed = 1.0;
  10. void onDragStart(event::DragStart &e) override {
  11. windowCursorLock();
  12. }
  13. void onDragEnd(event::DragEnd &e) override {
  14. windowCursorUnlock();
  15. }
  16. void onDragMove(event::DragMove &e) override {
  17. if (quantity) {
  18. float range;
  19. if (quantity->isBounded()) {
  20. range = quantity->getRange();
  21. }
  22. else {
  23. // Continuous encoders scale as if their limits are +/-1
  24. range = 2.f;
  25. }
  26. float delta = KNOB_SENSITIVITY * -e.mouseDelta.y * speed * range;
  27. // Drag slower if Mod is held
  28. if (windowIsModPressed())
  29. delta /= 16.f;
  30. quantity->moveValue(delta);
  31. }
  32. }
  33. };
  34. } // namespace rack