diff options
-rw-r--r-- | gui/console.cpp | 57 | ||||
-rw-r--r-- | gui/console.h | 3 |
2 files changed, 39 insertions, 21 deletions
diff --git a/gui/console.cpp b/gui/console.cpp index 662c2b8734..3c14ecc9a2 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -20,7 +20,6 @@ #include "stdafx.h" #include "console.h" -#include "newgui.h" #include "ScrollBarWidget.h" #include "common/engine.h" @@ -127,18 +126,22 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) switch (keycode) { case '\n': // enter/return case '\r': + if (_caretVisible) + drawCaret(true); + nextLine(); print(PROMPT); _promptStartPos = _promptEndPos = _currentPos; - if (_caretVisible) - drawCaret(true); draw(); break; case 27: // escape close(); break; case 8: // backspace + if (_caretVisible) + drawCaret(true); + if (_currentPos > _promptStartPos) { _currentPos--; for (int i = _currentPos; i < _promptEndPos; i++) @@ -146,8 +149,6 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) _buffer[_promptEndPos % kBufferSize] = ' '; _promptEndPos--; } - if (_caretVisible) - drawCaret(true); draw(); // FIXME - not nice to redraw the full console just for one char! break; /* @@ -186,19 +187,13 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) default: if (ascii == '~' || ascii == '#') { close(); - } else if (modifiers == OSystem::KBD_CTRL) { // CTRL + } else if (modifiers == OSystem::KBD_CTRL) { specialKeys(keycode); } else if (isprint((char)ascii)) { for (int i = _promptEndPos-1; i >= _currentPos; i--) _buffer[(i+1) % kBufferSize] = _buffer[i % kBufferSize]; - _buffer[_currentPos % kBufferSize] = (char)ascii; - _currentPos++; _promptEndPos++; - if ((_scrollLine + 1) * _lineWidth == _currentPos) { - _scrollLine++; - updateScrollBar(); - } - draw(); // FIXME - not nice to redraw the full console just for one char! + putchar((char)ascii); } } } @@ -298,6 +293,16 @@ int ConsoleDialog::vprintf(const char *format, va_list argptr) void ConsoleDialog::putchar(int c) { + if (_caretVisible) + drawCaret(true); + + putcharIntern(c); + + draw(); // FIXME - not nice to redraw the full console just for one char! +} + +void ConsoleDialog::putcharIntern(int c) +{ if (c == '\n') nextLine(); else { @@ -308,31 +313,41 @@ void ConsoleDialog::putchar(int c) updateScrollBar(); } } - draw(); // FIXME - not nice to redraw the full console just for one char! } void ConsoleDialog::print(const char *str) { + if (_caretVisible) + drawCaret(true); + while (*str) - putchar(*str++); + putcharIntern(*str++); + + draw(); } void ConsoleDialog::drawCaret(bool erase) { - // Only draw if item is visible - if (!isVisible()) - return; - int line = _currentPos / _lineWidth; int displayLine = line - _scrollLine + _linesPerPage - 1; - if (displayLine < 0 || displayLine >= _linesPerPage) + // Only draw caret if visible + if (!isVisible() || displayLine < 0 || displayLine >= _linesPerPage) { + _caretVisible = false; return; + } int x = _x + 1 + (_currentPos % _lineWidth) * kCharWidth; int y = _y + displayLine * kLineHeight; - _gui->fillRect(x, y, kCharWidth, kLineHeight, erase ? _gui->_bgcolor : _gui->_textcolor); + char c = _buffer[getBufferPos()]; + if (erase) { + _gui->fillRect(x, y, kCharWidth, kLineHeight, _gui->_bgcolor); + _gui->drawChar(c, x, y+2, _gui->_textcolor); + } else { + _gui->fillRect(x, y, kCharWidth, kLineHeight, _gui->_textcolor); + _gui->drawChar(c, x, y+2, _gui->_bgcolor); + } _gui->addDirtyRect(x, y, kCharWidth, kLineHeight); _caretVisible = !erase; diff --git a/gui/console.h b/gui/console.h index 289bdb8441..be9cb1c467 100644 --- a/gui/console.h +++ b/gui/console.h @@ -22,6 +22,7 @@ #define CONSOLE_DIALOG_H #include "dialog.h" +#include "newgui.h" #include "common/str.h" #include "common/list.h" @@ -52,6 +53,7 @@ protected: bool _caretVisible; uint32 _caretTime; + byte _caretBuf[kLineHeight * kCharWidth * 2]; ScrollBarWidget *_scrollBar; @@ -72,6 +74,7 @@ public: protected: void drawCaret(bool erase); + void putcharIntern(int c); void print(const char *str); void nextLine(); void updateScrollBar(); |