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
982B

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