WAGE: Improve text entry

This commit is contained in:
Eugene Sandulenko 2016-02-08 18:26:16 +01:00
parent 5e002c4fe2
commit ab20b96f60
3 changed files with 31 additions and 20 deletions

View File

@ -159,6 +159,8 @@ Gui::Gui(WageEngine *engine) {
_selectionStartX = _selectionStartY = -1; _selectionStartX = _selectionStartY = -1;
_selectionEndX = _selectionEndY = -1; _selectionEndX = _selectionEndY = -1;
_inputTextLineNum = 0;
g_system->getPaletteManager()->setPalette(palette, 0, 4); g_system->getPaletteManager()->setPalette(palette, 0, 4);
CursorMan.replaceCursorPalette(palette, 0, 4); CursorMan.replaceCursorPalette(palette, 0, 4);
@ -432,14 +434,14 @@ void Gui::flowText(Common::String &str) {
_lines.push_back(*j); _lines.push_back(*j);
uint pos = _scrollPos; uint pos = _scrollPos;
_scrollPos = MAX<int>(0, (_lines.size() - _consoleNumLines) * _consoleLineHeight); _scrollPos = MAX<int>(0, (_lines.size() - 1 - _consoleNumLines) * _consoleLineHeight);
_cursorX = kConWPadding; _cursorX = kConWPadding;
if (_scrollPos) if (_scrollPos)
_cursorY = (_consoleNumLines) * _consoleLineHeight + kConHPadding; _cursorY = (_consoleNumLines) * _consoleLineHeight + kConHPadding;
else else
_cursorY = (_lines.size()) * _consoleLineHeight + kConHPadding; _cursorY = (_lines.size() - 1) * _consoleLineHeight + kConHPadding;
if (pos != _scrollPos) if (pos != _scrollPos)
_consoleFullRedraw = true; _consoleFullRedraw = true;
@ -576,28 +578,33 @@ void Gui::drawInput() {
_bordersDirty = true; _bordersDirty = true;
} }
_lines.pop_back();
appendText(_engine->_inputText.c_str());
_inputTextLineNum = _lines.size() - 1;
const Graphics::Font *font = getConsoleFont(); const Graphics::Font *font = getConsoleFont();
int x = kConWPadding + _consoleTextArea.left; if (_engine->_inputText.contains('\n')) {
int y = _cursorY + _consoleTextArea.top; _consoleDirty = true;
Common::String text(_engine->_inputText); } else {
int textW = font->getStringWidth(text); int x = kConWPadding + _consoleTextArea.left;
int y = _cursorY + _consoleTextArea.top;
// undraw cursor Common::Rect r(x, y, x + _consoleTextArea.width(), y + font->getFontHeight());
_cursorOff = true; _screen.fillRect(r, kColorWhite);
_cursorState = false;
cursorTimerHandler(this);
_cursorOff = false;
Common::Rect r(x, y, x + textW + 10, y + font->getFontHeight()); // undraw cursor
_cursorOff = true;
_cursorState = false;
cursorTimerHandler(this);
_cursorOff = false;
_screen.fillRect(r, kColorWhite); font->drawString(&_screen, _lines[_inputTextLineNum], x, y, _screen.w, kColorBlack);
font->drawString(&_screen, text, x, y, _screen.w, kColorBlack); g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, _consoleTextArea.width(), font->getFontHeight());
}
g_system->copyRectToScreen(_screen.getBasePtr(x, y), _screen.pitch, x, y, textW + 10, font->getFontHeight()); _cursorX = font->getStringWidth(_lines[_inputTextLineNum]) + kConHPadding;
_cursorX = font->getStringWidth(_engine->_inputText) + kConHPadding;
} }
void Gui::loadFonts() { void Gui::loadFonts() {

View File

@ -162,6 +162,8 @@ private:
Common::String _clipboard; Common::String _clipboard;
Common::String _undobuffer; Common::String _undobuffer;
int _inputTextLineNum;
}; };
} // End of namespace Wage } // End of namespace Wage

View File

@ -209,10 +209,12 @@ void WageEngine::setMenu(Common::String menu) {
} }
void WageEngine::appendText(const char *str) { void WageEngine::appendText(const char *str) {
if (_inputText.size()) if (_inputText.size()) {
_gui->appendText(_inputText.c_str()); _inputText += '\n';
_gui->drawInput();
_inputText = ""; _inputText = "";
}
_gui->appendText(str); _gui->appendText(str);
} }