#include #include "InputWindow.h" #include "constant.h" extern FONT *joystix; void InputWindow::next() { const int originalActiveIndex = activeIndex; control[activeIndex]->blur(); while (!control[activeIndex]->getActive()) { activeIndex = (activeIndex + 1) % controlCount; control[activeIndex]->focus(); if (activeIndex == originalActiveIndex) break; } } void InputWindow::previous() { const int originalActiveIndex = activeIndex; control[activeIndex]->blur(); while (!control[activeIndex]->getActive()) { activeIndex = (activeIndex + controlCount - 1) % controlCount; control[activeIndex]->focus(); if (activeIndex == originalActiveIndex) break; } } int InputWindow::getValue() { if (getCommitted()) return getCommitment(); else return -2; } bool InputWindow::acknowledgeKeyStroke(int keyStroke) { if (keyStroke >> 8 == KEY_TAB) if (key_shifts & KB_SHIFT_FLAG) { previous(); return true; } else { next(); return true; } else if (control[activeIndex]->getActive()) return control[activeIndex]->acknowledgeKeyStroke(keyStroke); else return false; } bool InputWindow::acknowledgeKeyArray() { if (control[activeIndex]->getActive()) return control[activeIndex]->acknowledgeKeyArray(); else return false; } bool InputWindow::acknowledgeMouse() { const int mousePosition = mouse_pos; const int mouseButtons = mouse_b; const int mouseX = mousePosition >> 16; const int mouseY = mousePosition & 0xffff; bool result = false; if ((mouseButtons & 0x1) && !(oldMouseB & 0x1) && mouseX > x && mouseX < x + w - 1 && mouseY > y && mouseY <= y + titleBarHeight) { bool through = true; for (int i = 0; i < controlCount; i++) through = through && !(control[i]->within(mouseX, mouseY)); if (through) dragging = true; } else if (!(mouseButtons & 0x1)) dragging = false; else if (dragging && mousePosition != oldMousePos) { shift(mouseX - (oldMousePos >> 16), mouseY - (oldMousePos & 0xffff)); result = true; } for (int i = 0; i < controlCount; i++) if (control[i]->acknowledgeMouse()) result = true; oldMousePos = mousePosition; oldMouseB = mouseButtons; return result; } void InputWindow::acknowledgeHeartBeat() { for (int i = 0; i < controlCount; i++) control[i]->acknowledgeHeartBeat(); } void InputWindow::shift(int xOffset, int yOffset) { erase(); x += xOffset; y += yOffset; for (int i = 0; i < controlCount; i++) control[i]->shift(xOffset, yOffset); } bool InputWindow::within(int xTarget, int yTarget) { return xTarget >= x && xTarget < x + w, yTarget >= y && yTarget < y + h; } void InputWindow::draw() { if (!getCommitted()) { rect(canvas, x, y, x + w - 1, y + h - 1, active ? interactivityColor : 15); rectfill(canvas, x + 1, y + 1, x + w - 1, y + titleBarHeight, active ? interactivityColor : 16); hline(canvas, x + 1, y + titleBarHeight + 1, x + w - 2, active ? interactivityColor : 15); rectfill(canvas, x + 1, y + titleBarHeight + 2, x + w - 2, y + h - 2, 16); textout_ex(canvas, joystix, title, x + titleBarOffset, y + titleBarHeight / 2 - charHeight / 2, 15, -1); for (int i = 0; i < controlCount; i++) control[i]->draw(); } } void InputWindow::erase() { rectfill(canvas, x, y, x + w - 1, y + h - 1, 0); }