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.

51 lines
1.0KB

  1. #include "ui.hpp"
  2. #include "window.hpp"
  3. namespace rack {
  4. #define SLIDER_SENSITIVITY 0.001
  5. void Slider::draw(NVGcontext *vg) {
  6. float progress = rescale(value, minValue, maxValue, 0.0, 1.0);
  7. bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, getText().c_str(), NULL);
  8. }
  9. void Slider::onDragStart(EventDragStart &e) {
  10. state = BND_ACTIVE;
  11. windowCursorLock();
  12. revert_val = value;
  13. }
  14. void Slider::onDragMove(EventDragMove &e) {
  15. setValue(value + SLIDER_SENSITIVITY * (maxValue - minValue) * e.mouseRel.x);
  16. }
  17. void Slider::onDragEnd(EventDragEnd &e) {
  18. state = BND_DEFAULT;
  19. windowCursorUnlock();
  20. EventAction eAction;
  21. onAction(eAction);
  22. }
  23. void Slider::onMouseDown(EventMouseDown &e) {
  24. if (e.button == 1) {
  25. if(INVALID_REVERT_VAL != revert_val) // during mouse drag
  26. {
  27. setValue(revert_val);
  28. revert_val = INVALID_REVERT_VAL;
  29. }
  30. else
  31. {
  32. setValue(defaultValue);
  33. }
  34. EventAction eAction;
  35. onAction(eAction);
  36. }
  37. e.consumed = true;
  38. e.target = this;
  39. }
  40. } // namespace rack