diff options
author | Max Horn | 2002-12-14 15:45:45 +0000 |
---|---|---|
committer | Max Horn | 2002-12-14 15:45:45 +0000 |
commit | d30e577416fc217a8b9ee6320d408a8757607b6c (patch) | |
tree | f26d573b596528a51a6c63f8ee02670b374a91e5 /gui | |
parent | 2c16f43c8a59fab05ebe758ca8d689b4d6dbe247 (diff) | |
download | scummvm-rg350-d30e577416fc217a8b9ee6320d408a8757607b6c.tar.gz scummvm-rg350-d30e577416fc217a8b9ee6320d408a8757607b6c.tar.bz2 scummvm-rg350-d30e577416fc217a8b9ee6320d408a8757607b6c.zip |
some more console code
svn-id: r5955
Diffstat (limited to 'gui')
-rw-r--r-- | gui/console.cpp | 77 | ||||
-rw-r--r-- | gui/console.h | 10 |
2 files changed, 70 insertions, 17 deletions
diff --git a/gui/console.cpp b/gui/console.cpp index 872496f269..50917777bf 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -56,6 +56,9 @@ ConsoleDialog::ConsoleDialog(NewGui *gui) _currentColumn = 0; _currentLine = 0; _scrollLine = 0; + + print("ScummVM "SCUMMVM_VERSION" (" SCUMMVM_CVS ")\n"); + print("Console is ready\n"); } void ConsoleDialog::drawDialog() @@ -70,10 +73,12 @@ void ConsoleDialog::drawDialog() // Draw text int start = _scrollLine - _linesPerPage + 1; int y = _y + 1; + if (start < 0) + start = 0; for (int line = 0; line < _linesPerPage; line++) { int x = _x + 1; for (int column = 0; column < _lineWidth; column++) { - int l = (start+line+_linesInBuffer) % _linesInBuffer; + int l = (start+line) % _linesInBuffer; byte c = _buffer[l * _lineWidth + column]; _gui->drawChar(c, x, y, _gui->_textcolor); x += kCharWidth; @@ -88,8 +93,60 @@ void ConsoleDialog::nextLine() { _currentColumn = 0; if (_currentLine == _scrollLine) - _scrollLine = (_scrollLine + 1) % _linesInBuffer; - _currentLine = (_currentLine + 1) % _linesInBuffer; + _scrollLine++; + _currentLine++; +} + +int ConsoleDialog::printf(const char *format, ...) +{ + va_list argptr; + + va_start(argptr, format); + int count = this->vprintf(format, argptr); + va_end (argptr); + return count; +} + +int ConsoleDialog::vprintf(const char *format, va_list argptr) +{ + char buf[2048]; + + int count = vsnprintf(buf, sizeof(buf), format, argptr); + print(buf); + return count; +} + +void ConsoleDialog::putchar(int c) +{ + if (c == '\n') + nextLine(); + else { + int pos = (_currentLine % _linesInBuffer) * _lineWidth + _currentColumn; + _buffer[pos] = (char)c; + _currentColumn++; + if (_currentColumn >= _lineWidth) + nextLine(); + } + draw(); // FIXME - not nice to redraw the full console just for one char! +} + +void ConsoleDialog::print(const char *str) +{ + int pos = (_currentLine % _linesInBuffer) * _lineWidth + _currentColumn; + while (*str) { + if (*str == '\n') { + nextLine(); + pos += _lineWidth - _currentColumn; + } else { + _buffer[pos++] = *str; + _currentColumn++; + if (_currentColumn >= _lineWidth) + nextLine(); + } + pos %= kBufferSize; + str++; + } + draw(); } void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) { @@ -101,20 +158,14 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) { } else if (keycode == 8) { // Backspace if (_currentColumn == 0) { _currentColumn = _lineWidth - 1; - _currentLine--; - if (_currentLine < 0) - _currentLine = _linesInBuffer - 1; + if (_currentLine > 0) + _currentLine--; } else _currentColumn--; - _buffer[_currentLine * _lineWidth + _currentColumn] = ' '; + _buffer[(_currentLine % _linesInBuffer) * _lineWidth + _currentColumn] = ' '; draw(); // FIXME - not nice to redraw the full console just for one char! } else if ((ascii >= 31) && (ascii <= 122)) { // Printable ASCII, add to string - _buffer[_currentLine * _lineWidth + _currentColumn] = (char)ascii; - _currentColumn++; - if (_currentColumn >= _lineWidth) { - nextLine(); - } - draw(); // FIXME - not nice to redraw the full console just for one char! + putchar(ascii); } else { debug(2, "Unhandled keycode from ConsoleDialog: %d\n", keycode); } diff --git a/gui/console.h b/gui/console.h index 1d06284dd8..3b2f920672 100644 --- a/gui/console.h +++ b/gui/console.h @@ -25,6 +25,7 @@ #include "common/str.h" #include "common/list.h" +#include <stdarg.h> enum { kBufferSize = 32768, @@ -55,12 +56,13 @@ public: virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers); // void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); - //printf(const char *format, ...) - //vprintf( -// void printString(const String &str); -// const String &readString(); + int printf(const char *format, ...); + int vprintf(const char *format, va_list argptr); +#undef putchar + void putchar(int c); protected: + void print(const char *str); void nextLine(); }; |