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.

52 lines
1.1KB

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