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.

50 lines
1.1KB

  1. #include "ui/ScrollBar.hpp"
  2. #include "ui/ScrollWidget.hpp"
  3. #include "app.hpp"
  4. #include "window.hpp"
  5. namespace rack {
  6. namespace ui {
  7. ScrollBar::ScrollBar() {
  8. box.size = math::Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT);
  9. }
  10. void ScrollBar::draw(const DrawArgs &args) {
  11. BNDwidgetState state = BND_DEFAULT;
  12. if (APP->event->hoveredWidget == this)
  13. state = BND_HOVER;
  14. if (APP->event->draggedWidget == this)
  15. state = BND_ACTIVE;
  16. bndScrollBar(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size);
  17. }
  18. void ScrollBar::onDragStart(const event::DragStart &e) {
  19. if (e.button != GLFW_MOUSE_BUTTON_LEFT)
  20. return;
  21. APP->window->cursorLock();
  22. }
  23. void ScrollBar::onDragMove(const event::DragMove &e) {
  24. const float sensitivity = 1.f;
  25. ScrollWidget *scrollWidget = dynamic_cast<ScrollWidget*>(parent);
  26. assert(scrollWidget);
  27. if (orientation == HORIZONTAL)
  28. scrollWidget->offset.x += sensitivity * e.mouseDelta.x;
  29. else
  30. scrollWidget->offset.y += sensitivity * e.mouseDelta.y;
  31. }
  32. void ScrollBar::onDragEnd(const event::DragEnd &e) {
  33. APP->window->cursorUnlock();
  34. }
  35. } // namespace ui
  36. } // namespace rack