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.

40 lines
958B

  1. #include "widgets.hpp"
  2. #include "gui.hpp"
  3. namespace rack {
  4. void ScrollBar::draw(NVGcontext *vg) {
  5. float boxSize = (orientation == VERTICAL ? box.size.y : box.size.x);
  6. float maxOffset = containerSize - boxSize;
  7. float offset = containerOffset / maxOffset;
  8. float size = boxSize / containerSize;
  9. size = clampf(size, 0.0, 1.0);
  10. bndScrollBar(vg, box.pos.x, box.pos.y, box.size.x, box.size.y, state, offset, size);
  11. }
  12. void ScrollBar::move(float delta) {
  13. float boxSize = (orientation == VERTICAL ? box.size.y : box.size.x);
  14. float maxOffset = containerSize - boxSize;
  15. containerOffset += delta;
  16. containerOffset = clampf(containerOffset, 0.0, maxOffset);
  17. }
  18. void ScrollBar::onDragStart() {
  19. state = BND_ACTIVE;
  20. guiCursorLock();
  21. }
  22. void ScrollBar::onDragMove(Vec mouseRel) {
  23. float delta = (orientation == VERTICAL ? mouseRel.y : mouseRel.x);
  24. move(delta);
  25. }
  26. void ScrollBar::onDragEnd() {
  27. state = BND_DEFAULT;
  28. guiCursorUnlock();
  29. }
  30. } // namespace rack