aboutsummaryrefslogtreecommitdiff
path: root/gui/console.cpp
diff options
context:
space:
mode:
authorMax Horn2002-12-14 21:57:30 +0000
committerMax Horn2002-12-14 21:57:30 +0000
commit09e8c84ca3eac4b4466f095b7b7d695712ab8eef (patch)
tree8e9cf2b78c37c17d26aafa5c3fa0654a9d589d11 /gui/console.cpp
parent3af37415625842a392d6372e294e3966752d1d90 (diff)
downloadscummvm-rg350-09e8c84ca3eac4b4466f095b7b7d695712ab8eef.tar.gz
scummvm-rg350-09e8c84ca3eac4b4466f095b7b7d695712ab8eef.tar.bz2
scummvm-rg350-09e8c84ca3eac4b4466f095b7b7d695712ab8eef.zip
improved caret
svn-id: r5966
Diffstat (limited to 'gui/console.cpp')
-rw-r--r--gui/console.cpp57
1 files changed, 36 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;