[Scummvm-cvs-logs] CVS: scummvm/gui console.cpp,1.46,1.47 console.h,1.25,1.26
Torbj?rn Andersson
eriktorbjorn at users.sourceforge.net
Sun May 23 07:08:01 CEST 2004
Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25393
Modified Files:
console.cpp console.h
Log Message:
Applied patch #956989 ("Varous console fixes"). Fingolfin said it looked
ok, and as far as I can tell it does fix bugs #941811 and #941814, just as
it promised.
Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- console.cpp 5 May 2004 23:08:30 -0000 1.46
+++ console.cpp 23 May 2004 14:06:52 -0000 1.47
@@ -52,6 +52,7 @@
_currentPos = 0;
_scrollLine = _linesPerPage - 1;
+ _firstLineInBuffer = 0;
_caretVisible = false;
_caretTime = 0;
@@ -71,11 +72,11 @@
for (int i = 0; i < kHistorySize; i++)
_history[i][0] = '\0';
+ _promptStartPos = _promptEndPos = -1;
+
// Display greetings & prompt
print(gScummVMFullVersion);
print("\nConsole is ready\n");
-
- _promptStartPos = _promptEndPos = -1;
}
void ConsoleDialog::reflowLayout() {
@@ -109,6 +110,7 @@
// Draw text
int start = _scrollLine - _linesPerPage + 1;
int y = _y + 2;
+
for (int line = 0; line < _linesPerPage; line++) {
int x = _x + 1;
for (int column = 0; column < _lineWidth; column++) {
@@ -232,26 +234,42 @@
killChar();
draw();
break;
-/*
case 256 + 24: // pageup
- _selectedItem -= _entriesPerPage - 1;
- if (_selectedItem < 0)
- _selectedItem = 0;
+ if (modifiers == OSystem::KBD_SHIFT) {
+ _scrollLine -= _linesPerPage - 1;
+ if (_scrollLine < _firstLineInBuffer + _linesPerPage - 1)
+ _scrollLine = _firstLineInBuffer + _linesPerPage - 1;
+ updateScrollBuffer();
+ draw();
+ }
break;
case 256 + 25: // pagedown
- _selectedItem += _entriesPerPage - 1;
- if (_selectedItem >= _list.size() )
- _selectedItem = _list.size() - 1;
+ if (modifiers == OSystem::KBD_SHIFT) {
+ _scrollLine += _linesPerPage - 1;
+ if (_scrollLine > _promptEndPos / _lineWidth)
+ _scrollLine = _promptEndPos / _lineWidth;
+ updateScrollBuffer();
+ draw();
+ }
break;
-*/
case 256 + 22: // home
- _scrollLine = _linesPerPage - 1; // FIXME - this is not correct after a wrap around
- updateScrollBar();
+ if (modifiers == OSystem::KBD_SHIFT) {
+ _scrollLine = _firstLineInBuffer + _linesPerPage - 1;
+ updateScrollBuffer();
+ } else {
+ _currentPos = _promptStartPos;
+ }
draw();
break;
case 256 + 23: // end
- _scrollLine = _currentPos / _lineWidth;
- updateScrollBar();
+ if (modifiers == OSystem::KBD_SHIFT) {
+ _scrollLine = _promptEndPos / _lineWidth;
+ if (_scrollLine < _linesPerPage - 1)
+ _scrollLine = _linesPerPage - 1;
+ updateScrollBuffer();
+ } else {
+ _currentPos = _promptEndPos;
+ }
draw();
break;
case 273: // cursor up
@@ -299,7 +317,7 @@
void ConsoleDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kSetPositionCmd:
- int newPos = (int)data + _linesPerPage - 1;
+ int newPos = (int)data + _linesPerPage - 1 + _firstLineInBuffer;
if (newPos != _scrollLine) {
_scrollLine = newPos;
draw();
@@ -425,12 +443,25 @@
_scrollLine++;
_currentPos = (line + 1) * _lineWidth;
- updateScrollBar();
+ updateScrollBuffer();
}
-void ConsoleDialog::updateScrollBar() {
- int line = _currentPos / _lineWidth;
- _scrollBar->_numEntries = (line < _linesInBuffer) ? line + 1 : _linesInBuffer;
+
+// Call this (at least) when the current line changes or when
+// a new line is added
+void ConsoleDialog::updateScrollBuffer() {
+ int lastchar = MAX(_promptEndPos, _currentPos);
+ int line = lastchar / _lineWidth;
+ int numlines = (line < _linesInBuffer) ? line + 1 : _linesInBuffer;
+ int firstline = line - numlines + 1;
+ if (firstline > _firstLineInBuffer) {
+ // clear old line from buffer
+ for (int i = lastchar; i < (line+1) * _lineWidth; ++i)
+ buffer(i) = ' ';
+ _firstLineInBuffer = firstline;
+ }
+
+ _scrollBar->_numEntries = numlines;
_scrollBar->_currentPos = _scrollBar->_numEntries - (line - _scrollLine + _linesPerPage);
_scrollBar->_entriesPerPage = _linesPerPage;
_scrollBar->recalc();
@@ -477,7 +508,7 @@
_currentPos++;
if ((_scrollLine + 1) * _lineWidth == _currentPos) {
_scrollLine++;
- updateScrollBar();
+ updateScrollBuffer();
}
}
}
@@ -519,13 +550,13 @@
}
void ConsoleDialog::scrollToCurrent() {
- int line = _currentPos / _lineWidth;
+ int line = _promptEndPos / _lineWidth;
if (line + _linesPerPage <= _scrollLine) {
// TODO - this should only occur for loong edit lines, though
} else if (line > _scrollLine) {
_scrollLine = line;
- updateScrollBar();
+ updateScrollBuffer();
}
}
Index: console.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- console.h 5 May 2004 23:06:44 -0000 1.25
+++ console.h 23 May 2004 14:06:52 -0000 1.26
@@ -51,6 +51,7 @@
int _currentPos;
int _scrollLine;
+ int _firstLineInBuffer;
int _promptStartPos;
int _promptEndPos;
@@ -112,7 +113,7 @@
void putcharIntern(int c);
void insertIntoPrompt(const char *str);
void print(const char *str);
- void updateScrollBar();
+ void updateScrollBuffer();
void scrollToCurrent();
// Line editing
More information about the Scummvm-git-logs
mailing list