improved caret
svn-id: r5966
This commit is contained in:
parent
3af3741562
commit
09e8c84ca3
2 changed files with 39 additions and 21 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -297,6 +292,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();
|
||||
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue