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

  1. #include "ui/Slider.hpp"
  2. namespace rack {
  3. namespace ui {
  4. static const float SENSITIVITY = 0.001f;
  5. Slider::Slider() {
  6. box.size.y = BND_WIDGET_HEIGHT;
  7. }
  8. Slider::~Slider() {
  9. if (quantity)
  10. delete quantity;
  11. }
  12. void Slider::draw(const widget::DrawContext &ctx) {
  13. float progress = quantity ? quantity->getScaledValue() : 0.f;
  14. std::string text = quantity ? quantity->getString() : "";
  15. bndSlider(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL);
  16. }
  17. void Slider::onDragStart(const event::DragStart &e) {
  18. state = BND_ACTIVE;
  19. APP->window->cursorLock();
  20. e.consume(this);
  21. }
  22. void Slider::onDragMove(const event::DragMove &e) {
  23. if (quantity) {
  24. quantity->moveScaledValue(SENSITIVITY * e.mouseDelta.x);
  25. }
  26. }
  27. void Slider::onDragEnd(const event::DragEnd &e) {
  28. state = BND_DEFAULT;
  29. APP->window->cursorUnlock();
  30. }
  31. void Slider::onDoubleClick(const event::DoubleClick &e) {
  32. if (quantity)
  33. quantity->reset();
  34. }
  35. } // namespace ui
  36. } // namespace rack