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.

42 lines
857B

  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. }
  13. void Slider::onDragMove(EventDragMove &e) {
  14. setValue(value + SLIDER_SENSITIVITY * (maxValue - minValue) * e.mouseRel.x);
  15. }
  16. void Slider::onDragEnd(EventDragEnd &e) {
  17. state = BND_DEFAULT;
  18. windowCursorUnlock();
  19. EventAction eAction;
  20. onAction(eAction);
  21. }
  22. void Slider::onMouseDown(EventMouseDown &e) {
  23. if (e.button == 1) {
  24. setValue(defaultValue);
  25. EventAction eAction;
  26. onAction(eAction);
  27. }
  28. e.consumed = true;
  29. e.target = this;
  30. }
  31. } // namespace rack