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.

46 lines
958B

  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. void Slider::draw(const DrawArgs &args) {
  9. float progress = quantity ? quantity->getScaledValue() : 0.f;
  10. std::string text = quantity ? quantity->getString() : "";
  11. bndSlider(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, progress, text.c_str(), NULL);
  12. }
  13. void Slider::onDragStart(const widget::DragStartEvent &e) {
  14. state = BND_ACTIVE;
  15. APP->window->cursorLock();
  16. e.consume(this);
  17. }
  18. void Slider::onDragMove(const widget::DragMoveEvent &e) {
  19. if (quantity) {
  20. quantity->moveScaledValue(SENSITIVITY * e.mouseDelta.x);
  21. }
  22. }
  23. void Slider::onDragEnd(const widget::DragEndEvent &e) {
  24. state = BND_DEFAULT;
  25. APP->window->cursorUnlock();
  26. }
  27. void Slider::onDoubleClick(const widget::DoubleClickEvent &e) {
  28. if (quantity)
  29. quantity->reset();
  30. }
  31. } // namespace ui
  32. } // namespace rack