#include #include "InputButton.h" #include "constant.h" extern FONT *joystix; int InputButton::getW() { return w; } int InputButton::getH() { return h; } bool InputButton::acknowledgeKeyStroke(int keyStroke) { const int scanCode = keyStroke >> 8; const bool pressIt = scanCode == KEY_ENTER || scanCode == KEY_SPACE || scanCode == KEY_ENTER_PAD; if (pressIt) press(); return pressIt; } bool InputButton::acknowledgeMouse() { const int mousePosition = mouse_pos; const int mouseButtons = mouse_b; const bool pressIt = (oldMouseB & 0x1) && !(mouseButtons & 0x1) && within(mousePosition >> 16, mousePosition & 0xffff); if (pressIt) press(); oldMouseB = mouseButtons; return pressIt; } void InputButton::shift(int xOffset, int yOffset) { x += xOffset; y += yOffset; } bool InputButton::within(int xTarget, int yTarget) { return xTarget >= x && xTarget < x + w && yTarget >= y && yTarget < y + h; } void InputButton::draw() { rect(canvas, x, y, x + w - 1, y + h - 1, 15); rectfill(canvas, x + 1, y + 1, x + w - 2, y + h - 2, active ? interactivityColor : 16); textout_centre_ex(canvas, joystix, caption, x + w / 2, y + h / 2 - charHeight / 2, 15, -1); } void InputButton::erase() { rectfill(canvas, x, y, x + w - 1, y + h - 1, 0); }