Skip to content

Commit

Permalink
WAGE: Display text input
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Jan 3, 2016
1 parent e95122b commit f97c915
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
33 changes: 32 additions & 1 deletion engines/wage/gui.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -161,6 +163,7 @@ Gui::Gui(WageEngine *engine) {
_cursorX = 0;
_cursorY = 0;
_cursorState = false;
_cursorOff = false;

g_system->getPaletteManager()->setPalette(palette, 0, 4);

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions engines/wage/gui.h
Expand Up @@ -71,6 +71,7 @@ class Gui {
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);
Expand All @@ -90,6 +91,7 @@ class Gui {
int _cursorX, _cursorY;
bool _cursorState;
Common::Rect _consoleTextArea;
bool _cursorOff;

private:
WageEngine *_engine;
Expand Down
23 changes: 23 additions & 0 deletions engines/wage/wage.cpp
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion engines/wage/wage.h
Expand Up @@ -132,7 +132,6 @@ class WageEngine : public Engine {
World *_world;

Scene *_lastScene;
//PrintStream out;
int _loopCount;
int _turn;
Chr *_monster;
Expand All @@ -142,6 +141,8 @@ class WageEngine : public Engine {
bool _temporarilyHidden;
bool _isGameOver;

Common::String _inputText;

void playSound(String soundName);
void setMenu(String soundName);
void appendText(String &str);
Expand Down

0 comments on commit f97c915

Please sign in to comment.