void VirtualKeyboardGUI::mainLoop() { Common::EventManager *eventMan = _system->getEventManager(); while (_displaying) { if (_kbd->_keyQueue.hasStringChanged()) updateDisplay(); animateCaret(); animateCursor(); redraw(); _system->updateScreen(); Common::Event event; while (eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_LBUTTONDOWN: if (_kbdBound.contains(event.mouse)) { _kbd->handleMouseDown(event.mouse.x - _kbdBound.left, event.mouse.y - _kbdBound.top); } break; case Common::EVENT_LBUTTONUP: if (_kbdBound.contains(event.mouse)) { _kbd->handleMouseUp(event.mouse.x - _kbdBound.left, event.mouse.y - _kbdBound.top); } break; case Common::EVENT_MOUSEMOVE: if (_drag) move(event.mouse.x - _dragPoint.x, event.mouse.y - _dragPoint.y); break; case Common::EVENT_SCREEN_CHANGED: screenChanged(); break; case Common::EVENT_QUIT: _system->quit(); return; default: break; } } // Delay for a moment _system->delayMillis(10); } }
// dest: MUST already contain a string, even if empty. // maxLineLength: Must include room for terminating NUL. // Returns TRUE if the user pressed Enter, FALSE if Break. // byte getLineFromUser(char *dest, word maxLineLength, word initIndex) { saveCursorPosition(); word index = initIndex; // offset of cursor in 'dest' // Print the existing string, if any. // word curLen = strlen(dest); putstr(dest, curLen); // Put the cursor at 'initIndex'. // restoreCursorPosition(); advanceCursor(initIndex); char key; for (;;) { animateCursor(); key = (char) tolower(inkey()); if (!key) continue; if (key == '\r' || key == '\n' || key == BREAK_CHAR) // if Enter (CoCo or PC) or Break { dest[curLen] = 0; break; } removeCursor(); if (key == CLEAR_CHAR) // if backspace { if (index > 0) { word numCharsToMove = curLen - index; moveBackwardOneByte(dest + index, numCharsToMove); --index; --curLen; putchar('\b'); byte finalX = textPosX, finalY = textPosY; putstr(dest + index, numCharsToMove); putchar(' '); // erase last char from screen moveCursor(finalX, finalY); // place cursor at erased char } continue; } if (key == SHIFT_CLEAR_CHAR) // if delete { if (index < curLen) { word numCharsToMove = curLen - index - 1; moveBackwardOneByte(dest + index + 1, numCharsToMove); --curLen; byte finalX = textPosX, finalY = textPosY; putstr(dest + index, numCharsToMove); putchar(' '); // erase last char from screen moveCursor(finalX, finalY); // place cursor at erased char } continue; } if (key == LEFT_CHAR) // if move cursor left { if (index > 0) { --index; putchar('\b'); } continue; } if (key == RIGHT_CHAR) // if move cursor right { if (index < curLen) { ++index; advanceCursor(1); } continue; } if (key == KILL_LINE_CHAR) // if shift-backspace { for (word i = 0; i < index; ++i) // back up cursor to beginning putchar('\b'); byte finalX = textPosX, finalY = textPosY; for (word i = 0; i < curLen; ++i) // erase entire line putchar(' '); moveCursor(finalX, finalY); // put cursor at beginning index = 0; curLen = 0; continue; } if (key < ' ' || key >= 127) continue; // ignore invalid characters if (curLen < maxLineLength - 1) // if still room { moveForwardOneByte(dest + index, curLen + 1 - index); // include terminating NUL dest[index] = key; ++curLen; saveCursorPosition(); putstr(dest + index, curLen - index); restoreCursorPosition(); advanceCursor(1); ++index; } } removeCursor(); return key != BREAK_CHAR; }