#include #include "InputScrollbar.h" void InputScrollbar::scrollUp() { setValue(value - 1); } void InputScrollbar::scrollDown() { setValue(value + 1); } int InputScrollbar::getValue() { return value; } void InputScrollbar::setValue(int desiredValue) { value = desiredValue; if (desiredValue > limit) desiredValue = limit; if (desiredValue < 0) desiredValue = 0; func(); } void InputScrollbar::setLimit(int desiredLimit) { limit = desiredLimit; setValue(0); } InputGuiElementCallback* InputScrollbar::getUpButtonPointer() { return &upButton; } InputGuiElementCallback* InputScrollbar::getDownButtonPointer() { return &downButton; } bool InputScrollbar::acknowledgeMouse() { const int mousePosition = mouse_pos; const int mouseButtons = mouse_b; if ((mouseButtons & 0x1) && (mousePosition >> 16) >= x && (mousePosition >> 16) < x + w && (mousePosition & 0xffff) >= y + upButton.getH() && (mousePosition & 0xffff) < y + h - downButton.getH()) { setValue(((mousePosition & 0xffff) - (y + upButton.getH())) * limit / (h - upButton.getH() - downButton.getH() - 1)); return true; } else return false; } void InputScrollbar::focus() {} void InputScrollbar::blur() {} void InputScrollbar::shift(int xOffset, int yOffset) { x += xOffset; y += yOffset; } bool InputScrollbar::within(int xTarget, int yTarget) { return xTarget >= x && xTarget < x + w && yTarget >= y && yTarget < y + h; } void InputScrollbar::draw() { upButton.draw(); downButton.draw(); vline(canvas, x, y + upButton.getH(), y + h - downButton.getH() - 1, 15); vline(canvas, x + w - 1, y + upButton.getH(), y + h - downButton.getH() - 1, 15); hline(canvas, x + 1, y + upButton.getH() + (limit == 0 ? 0 : value * (h - upButton.getH() - downButton.getH() - 1) / limit), x + w - 2, interactivityColor); } void InputScrollbar::erase() { rectfill(canvas, x, y, x + w - 1, y + h - 1, 0); }