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.

43 lines
1.2KB

  1. #include "widgets.hpp"
  2. #include "gui.hpp"
  3. namespace rack {
  4. void ScrollBar::draw(NVGcontext *vg) {
  5. ScrollWidget *scrollWidget = dynamic_cast<ScrollWidget*>(parent);
  6. assert(scrollWidget);
  7. Vec viewportCorner = scrollWidget->container->getChildrenBoundingBox().getBottomRight();
  8. float viewportSize = (orientation == HORIZONTAL) ? viewportCorner.x : viewportCorner.y;
  9. float containerSize = (orientation == HORIZONTAL) ? scrollWidget->box.size.x : scrollWidget->box.size.y;
  10. float viewportOffset = (orientation == HORIZONTAL) ? scrollWidget->offset.x : scrollWidget->offset.y;
  11. float offset = viewportOffset / (viewportSize - containerSize);
  12. float size = containerSize / viewportSize;
  13. size = clampf(size, 0.0, 1.0);
  14. bndScrollBar(vg, 0.0, 0.0, box.size.x, box.size.y, state, offset, size);
  15. }
  16. void ScrollBar::onDragStart(EventDragStart &e) {
  17. state = BND_ACTIVE;
  18. guiCursorLock();
  19. }
  20. void ScrollBar::onDragMove(EventDragMove &e) {
  21. ScrollWidget *scrollWidget = dynamic_cast<ScrollWidget*>(parent);
  22. assert(scrollWidget);
  23. if (orientation == HORIZONTAL)
  24. scrollWidget->offset.x += e.mouseRel.x;
  25. else
  26. scrollWidget->offset.y += e.mouseRel.y;
  27. }
  28. void ScrollBar::onDragEnd(EventDragEnd &e) {
  29. state = BND_DEFAULT;
  30. guiCursorUnlock();
  31. }
  32. } // namespace rack