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.

44 lines
966B

  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. bndScrollBar(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size);
  12. }
  13. void ScrollBar::onDragStart(const event::DragStart &e) {
  14. state = BND_ACTIVE;
  15. APP->window->cursorLock();
  16. e.consume(this);
  17. }
  18. void ScrollBar::onDragMove(const event::DragMove &e) {
  19. const float sensitivity = 1.f;
  20. ScrollWidget *scrollWidget = dynamic_cast<ScrollWidget*>(parent);
  21. assert(scrollWidget);
  22. if (orientation == HORIZONTAL)
  23. scrollWidget->offset.x += sensitivity * e.mouseDelta.x;
  24. else
  25. scrollWidget->offset.y += sensitivity * e.mouseDelta.y;
  26. }
  27. void ScrollBar::onDragEnd(const event::DragEnd &e) {
  28. state = BND_DEFAULT;
  29. APP->window->cursorUnlock();
  30. }
  31. } // namespace ui
  32. } // namespace rack