#include #include #include "InputCheckBox.h" #include "constant.h" using namespace std; extern FONT *joystix; bool InputCheckBox::getValue() { return value; } void InputCheckBox::setValue(bool desiredValue) { value = desiredValue; } bool InputCheckBox::acknowledgeKeyStroke(int keyStroke) { const bool toggle = (keyStroke >> 8) == KEY_SPACE; if (toggle) value = !value; return toggle; } bool InputCheckBox::acknowledgeMouse() { const int mousePosition = mouse_pos; const int mouseButtons = mouse_b; const bool toggle = (mouseButtons & 0x1) && !(oldMouseB & 0x1) && within(mousePosition >> 16, mousePosition & 0xffff); if (toggle) value = !value; oldMouseB = mouseButtons; return toggle; } void InputCheckBox::shift(int xOffset, int yOffset) { x += xOffset; y += yOffset; } bool InputCheckBox::within(int xTarget, int yTarget) { return xTarget >= x && xTarget < x + checkBoxCaptionOffset + strlen(caption) * charWidth && yTarget >= y && yTarget < y + charHeight; } void InputCheckBox::draw() { rect(canvas, x, y, x + checkBoxSize - 1, y + checkBoxSize - 1, active ? interactivityColor : 15); if (value) { line(canvas, x + 1, y + 1, x + checkBoxSize - 2, y + checkBoxSize - 2, 15); line(canvas, x + checkBoxSize - 2, y + 1, x + 1, y + checkBoxSize - 2, 15); } textout_ex(canvas, joystix, caption, x + checkBoxCaptionOffset, y, 15, -1); } void InputCheckBox::erase() { rectfill(canvas, x, y, x + checkBoxCaptionOffset + strlen(caption) * charWidth - 1, y + charHeight - 1, 0); }