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.

48 lines
1015B

  1. #pragma once
  2. #include "ui/common.hpp"
  3. #include "ui/QuantityWidget.hpp"
  4. namespace rack {
  5. static const float SLIDER_SENSITIVITY = 0.001f;
  6. struct Slider : OpaqueWidget, QuantityWidget {
  7. BNDwidgetState state = BND_DEFAULT;
  8. Slider() {
  9. box.size.y = BND_WIDGET_HEIGHT;
  10. }
  11. void draw(NVGcontext *vg) override {
  12. float progress = rescale(value, minValue, maxValue, 0.0, 1.0);
  13. bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, getText().c_str(), NULL);
  14. }
  15. void onDragStart(event::DragStart &e) override {
  16. state = BND_ACTIVE;
  17. windowCursorLock();
  18. }
  19. void onDragMove(event::DragMove &e) override {
  20. setValue(value + SLIDER_SENSITIVITY * (maxValue - minValue) * e.mouseDelta.x);
  21. }
  22. void onDragEnd(event::DragEnd &e) override {
  23. state = BND_DEFAULT;
  24. windowCursorUnlock();
  25. }
  26. void onButton(event::Button &e) override {
  27. if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) {
  28. setValue(defaultValue);
  29. }
  30. e.target = this;
  31. }
  32. };
  33. } // namespace rack