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.

59 lines
1.2KB

  1. #pragma once
  2. #include "widgets/OpaqueWidget.hpp"
  3. #include "ui/Quantity.hpp"
  4. #include "ui/common.hpp"
  5. namespace rack {
  6. static const float SLIDER_SENSITIVITY = 0.001f;
  7. struct Slider : OpaqueWidget {
  8. BNDwidgetState state = BND_DEFAULT;
  9. Quantity *quantity = NULL;
  10. Slider() {
  11. box.size.y = BND_WIDGET_HEIGHT;
  12. }
  13. ~Slider() {
  14. if (quantity)
  15. delete quantity;
  16. }
  17. void draw(NVGcontext *vg) override {
  18. float progress = quantity ? quantity->getScaledValue() : 0.f;
  19. std::string text = quantity ? quantity->getString() : "";
  20. bndSlider(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL);
  21. }
  22. void onDragStart(event::DragStart &e) override {
  23. state = BND_ACTIVE;
  24. windowCursorLock();
  25. }
  26. void onDragMove(event::DragMove &e) override {
  27. if (quantity) {
  28. quantity->moveScaledValue(SLIDER_SENSITIVITY * e.mouseDelta.x);
  29. }
  30. }
  31. void onDragEnd(event::DragEnd &e) override {
  32. state = BND_DEFAULT;
  33. windowCursorUnlock();
  34. }
  35. void onButton(event::Button &e) override {
  36. if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT) {
  37. if (quantity)
  38. quantity->reset();
  39. }
  40. e.target = this;
  41. }
  42. };
  43. } // namespace rack