#include #include #include "InputRadioButtonSet.h" #include "constant.h" extern FONT *joystix; int* InputRadioButtonSet::getX() { return x; } int* InputRadioButtonSet::getY() { return y; } void InputRadioButtonSet::previous() { value = (value + length - 1) % length; } void InputRadioButtonSet::next() { value = (value + 1) % length; } int InputRadioButtonSet::accelerate(int ascii) { for (int i = 0; i < length; i++) if (tolower(command[i][acceleratorKey[i]]) == tolower(ascii)) return i; return -1; } void InputRadioButtonSet::drawCommands() { char singleton[2]; singleton[1] = '\0'; for (int i = 0; i < length; i++) { circle(canvas, x[i] + radioButtonRadius, y[i] + radioButtonRadius, radioButtonRadius, active ? interactivityColor : 15); textout_ex(canvas, joystix, command[i], x[i] + radioButtonCaptionOffset, y[i], 15, 16); singleton[0] = command[i][acceleratorKey[i]]; textout_ex(canvas, joystix, singleton, x[i] + radioButtonCaptionOffset + acceleratorKey[i] * charWidth, y[i], interactivityColor, -1); } } void InputRadioButtonSet::drawSelect() { circlefill(canvas, x[value] + radioButtonRadius, y[value] + radioButtonRadius, radioButtonInnerRadius, 15); } void InputRadioButtonSet::drawUnselect() { circlefill(canvas, x[value] + radioButtonRadius, y[value] + radioButtonRadius, radioButtonInnerRadius, 0); } int InputRadioButtonSet::getValue() { return value; } void InputRadioButtonSet::setValue(int desiredValue) { value = desiredValue; } bool InputRadioButtonSet::acknowledgeKeyStroke(int keyStroke) { const int scanCode = keyStroke >> 8; const int accelerated = accelerate(scancode_to_ascii(scanCode)); switch (scanCode) { case KEY_2_PAD: case KEY_6_PAD: case KEY_RIGHT: case KEY_DOWN: next(); return true; case KEY_4_PAD: case KEY_8_PAD: case KEY_LEFT: case KEY_UP: previous(); return true; default: if (accelerated != -1) { value = accelerated; return true; } } return false; } bool InputRadioButtonSet::acknowledgeMouse() { bool mouseIndicatesCommand = false; const int mousePosition = mouse_pos; const int mouseButtons = mouse_b; if ((mouseButtons & 0x1) && !(oldMouseB & 0x1)) for (int i = 0; i < length; i++) if ((mousePosition >> 16) >= x[i] && (mousePosition >> 16) < x[i] + radioButtonCaptionOffset + strlen(command[i]) * charWidth && (mousePosition & 0xffff) >= y[i] && (mousePosition & 0xffff) < y[i] + charHeight) { value = i; mouseIndicatesCommand = true; } oldMouseB = mouseButtons; return mouseIndicatesCommand; } void InputRadioButtonSet::shift(int xOffset, int yOffset) { for (int i = 0; i < length; i++) x[i] += xOffset; for (int i = 0; i < length; i++) y[i] += yOffset; } bool InputRadioButtonSet::within(int xTarget, int yTarget) { for (int i = 0; i < length; i++) if (xTarget >= x[i] && xTarget < x[i] + radioButtonCaptionOffset + strlen(command[i]) * charWidth && yTarget >= y[i] && yTarget < y[i] + charHeight) return true; return false; } void InputRadioButtonSet::draw() { drawCommands(); drawSelect(); } void InputRadioButtonSet::erase() { for (int i = 0; i < length; i++) rectfill(canvas, x[i], y[i], x[i] + radioButtonCaptionOffset + strlen(command[i]) * charWidth - 1, y[i] + charHeight - 1, 0); }