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.

42 lines
957B

  1. #include "ui/ScrollBar.hpp"
  2. #include "ui/ScrollWidget.hpp"
  3. #include "app.hpp"
  4. #include "window.hpp"
  5. namespace rack {
  6. static const float SCROLLBAR_SENSITIVITY = 2.f;
  7. ScrollBar::ScrollBar() {
  8. box.size = math::Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT);
  9. }
  10. void ScrollBar::draw(const DrawContext &ctx) {
  11. bndScrollBar(ctx.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. }
  17. void ScrollBar::onDragMove(const event::DragMove &e) {
  18. ScrollWidget *scrollWidget = dynamic_cast<ScrollWidget*>(parent);
  19. assert(scrollWidget);
  20. if (orientation == HORIZONTAL)
  21. scrollWidget->offset.x += SCROLLBAR_SENSITIVITY * e.mouseDelta.x;
  22. else
  23. scrollWidget->offset.y += SCROLLBAR_SENSITIVITY * e.mouseDelta.y;
  24. }
  25. void ScrollBar::onDragEnd(const event::DragEnd &e) {
  26. state = BND_DEFAULT;
  27. app()->window->cursorUnlock();
  28. }
  29. } // namespace rack