Skip to content

Commit

Permalink
WAGE: Improve text entry
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Feb 14, 2016
1 parent 5e002c4 commit ab20b96
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
41 changes: 24 additions & 17 deletions engines/wage/gui.cpp
Expand Up @@ -159,6 +159,8 @@ Gui::Gui(WageEngine *engine) {
_selectionStartX = _selectionStartY = -1;
_selectionEndX = _selectionEndY = -1;

_inputTextLineNum = 0;

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

CursorMan.replaceCursorPalette(palette, 0, 4);
Expand Down Expand Up @@ -432,14 +434,14 @@ void Gui::flowText(Common::String &str) {
_lines.push_back(*j);

uint pos = _scrollPos;
_scrollPos = MAX<int>(0, (_lines.size() - _consoleNumLines) * _consoleLineHeight);
_scrollPos = MAX<int>(0, (_lines.size() - 1 - _consoleNumLines) * _consoleLineHeight);

_cursorX = kConWPadding;

if (_scrollPos)
_cursorY = (_consoleNumLines) * _consoleLineHeight + kConHPadding;
else
_cursorY = (_lines.size()) * _consoleLineHeight + kConHPadding;
_cursorY = (_lines.size() - 1) * _consoleLineHeight + kConHPadding;

if (pos != _scrollPos)
_consoleFullRedraw = true;
Expand Down Expand Up @@ -576,28 +578,33 @@ void Gui::drawInput() {
_bordersDirty = true;
}

const Graphics::Font *font = getConsoleFont();
_lines.pop_back();
appendText(_engine->_inputText.c_str());
_inputTextLineNum = _lines.size() - 1;

int x = kConWPadding + _consoleTextArea.left;
int y = _cursorY + _consoleTextArea.top;
Common::String text(_engine->_inputText);
int textW = font->getStringWidth(text);
const Graphics::Font *font = getConsoleFont();

// undraw cursor
_cursorOff = true;
_cursorState = false;
cursorTimerHandler(this);
_cursorOff = false;
if (_engine->_inputText.contains('\n')) {
_consoleDirty = true;
} else {
int x = kConWPadding + _consoleTextArea.left;
int y = _cursorY + _consoleTextArea.top;

Common::Rect r(x, y, x + textW + 10, y + font->getFontHeight());
Common::Rect r(x, y, x + _consoleTextArea.width(), y + font->getFontHeight());
_screen.fillRect(r, kColorWhite);

_screen.fillRect(r, kColorWhite);
// undraw cursor
_cursorOff = true;
_cursorState = false;
cursorTimerHandler(this);
_cursorOff = false;

font->drawString(&_screen, text, x, y, _screen.w, kColorBlack);
font->drawString(&_screen, _lines[_inputTextLineNum], x, y, _screen.w, kColorBlack);

g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, textW + 10, font->getFontHeight());
g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, _consoleTextArea.width(), font->getFontHeight());
}

_cursorX = font->getStringWidth(_engine->_inputText) + kConHPadding;
_cursorX = font->getStringWidth(_lines[_inputTextLineNum]) + kConHPadding;
}

void Gui::loadFonts() {
Expand Down
2 changes: 2 additions & 0 deletions engines/wage/gui.h
Expand Up @@ -162,6 +162,8 @@ class Gui {

Common::String _clipboard;
Common::String _undobuffer;

int _inputTextLineNum;
};

} // End of namespace Wage
Expand Down
8 changes: 5 additions & 3 deletions engines/wage/wage.cpp
Expand Up @@ -209,10 +209,12 @@ void WageEngine::setMenu(Common::String menu) {
}

void WageEngine::appendText(const char *str) {
if (_inputText.size())
_gui->appendText(_inputText.c_str());
if (_inputText.size()) {
_inputText += '\n';
_gui->drawInput();

_inputText = "";
_inputText = "";
}

_gui->appendText(str);
}
Expand Down

0 comments on commit ab20b96

Please sign in to comment.