From f97c915c7b0f3ef3c34dfea78619d8c17446638b Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 4 Jan 2016 00:09:10 +0100 Subject: WAGE: Display text input --- engines/wage/gui.cpp | 33 ++++++++++++++++++++++++++++++++- engines/wage/gui.h | 2 ++ engines/wage/wage.cpp | 23 +++++++++++++++++++++++ engines/wage/wage.h | 3 ++- 4 files changed, 59 insertions(+), 2 deletions(-) (limited to 'engines/wage') diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index baf9445b39..2f36270cc5 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -133,7 +133,9 @@ static void cursor_timer_handler(void *refCon) { y += gui->_consoleTextArea.top; gui->_screen.vLine(x, y - kCursorHeight, y, gui->_cursorState ? kColorBlack : kColorWhite); - gui->_cursorState = !gui->_cursorState; + + if (!gui->_cursorOff) + gui->_cursorState = !gui->_cursorState; g_system->copyRectToScreen(gui->_screen.getBasePtr(x, y - kCursorHeight), gui->_screen.pitch, x, y - kCursorHeight, 1, kCursorHeight); g_system->updateScreen(); @@ -161,6 +163,7 @@ Gui::Gui(WageEngine *engine) { _cursorX = 0; _cursorY = 0; _cursorState = false; + _cursorOff = false; g_system->getPaletteManager()->setPalette(palette, 0, 4); @@ -500,6 +503,34 @@ void Gui::renderConsole(Graphics::Surface *g, Common::Rect &r) { g_system->copyRectToScreen(g->getBasePtr(r.left, r.top), g->pitch, r.left, r.top, r.width(), r.height()); } +void Gui::drawInput() { + if (!_screen.getPixels()) + return; + + const Graphics::Font *font = getConsoleFont(); + + int x = kConHPadding + _consoleTextArea.left; + int y = _cursorY + _consoleTextArea.top; + Common::String text(_engine->_inputText); + int textW = font->getStringWidth(text); + + // undraw cursor + _cursorOff = true; + _cursorState = false; + cursor_timer_handler(this); + _cursorOff = false; + + Common::Rect r(x, y, x + textW + 10, y + font->getFontHeight()); + + _screen.fillRect(r, kColorWhite); + + font->drawString(&_screen, text, x, y, _screen.w, kColorBlack); + + g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, textW + 10, font->getFontHeight()); + + _cursorX = font->getStringWidth(_engine->_inputText) + 1; +} + void Gui::loadFonts() { Common::Archive *dat; diff --git a/engines/wage/gui.h b/engines/wage/gui.h index 1a82c8f713..cd918f7bd3 100644 --- a/engines/wage/gui.h +++ b/engines/wage/gui.h @@ -71,6 +71,7 @@ public: void clearOutput(); void mouseMove(int x, int y); Designed *getClickTarget(int x, int y); + void drawInput(); private: void paintBorder(Graphics::Surface *g, Common::Rect &r, WindowType windowType); @@ -90,6 +91,7 @@ public: int _cursorX, _cursorY; bool _cursorState; Common::Rect _consoleTextArea; + bool _cursorOff; private: WageEngine *_engine; diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp index e8658101ef..e3addd1020 100644 --- a/engines/wage/wage.cpp +++ b/engines/wage/wage.cpp @@ -158,6 +158,29 @@ void WageEngine::processEvents() { if (obj != NULL) processTurn(NULL, obj); } + break; + case Common::EVENT_KEYDOWN: + switch (event.kbd.keycode) { + case Common::KEYCODE_BACKSPACE: + if (_inputText.size()) { + _inputText.deleteLastChar(); + _gui->drawInput(); + } + break; + + default: + if (event.kbd.flags) + break; + + if (Common::isAlpha(event.kbd.ascii)) { + _inputText += (char)event.kbd.ascii; + _gui->drawInput(); + } + + break; + } + break; + default: break; } diff --git a/engines/wage/wage.h b/engines/wage/wage.h index 0c6f2e03c8..91d940470b 100644 --- a/engines/wage/wage.h +++ b/engines/wage/wage.h @@ -132,7 +132,6 @@ public: World *_world; Scene *_lastScene; - //PrintStream out; int _loopCount; int _turn; Chr *_monster; @@ -142,6 +141,8 @@ public: bool _temporarilyHidden; bool _isGameOver; + Common::String _inputText; + void playSound(String soundName); void setMenu(String soundName); void appendText(String &str); -- cgit v1.2.3