RCS file: /cvsroot/scummvm/scummvm/gui/console.h,v
retrieving revision 1.25
diff -u -r1.25 console.h
|
|
|
51 | 51 | |
52 | 52 | int _currentPos; |
53 | 53 | int _scrollLine; |
| 54 | int _firstLineInBuffer; |
54 | 55 | |
55 | 56 | int _promptStartPos; |
56 | 57 | int _promptEndPos; |
… |
… |
|
112 | 113 | void putcharIntern(int c); |
113 | 114 | void insertIntoPrompt(const char *str); |
114 | 115 | void print(const char *str); |
115 | | void updateScrollBar(); |
| 116 | void updateScrollBuffer(); |
116 | 117 | void scrollToCurrent(); |
117 | 118 | |
118 | 119 | // Line editing |
RCS file: /cvsroot/scummvm/scummvm/gui/console.cpp,v
retrieving revision 1.46
diff -u -r1.46 console.cpp
|
|
|
52 | 52 | |
53 | 53 | _currentPos = 0; |
54 | 54 | _scrollLine = _linesPerPage - 1; |
| 55 | _firstLineInBuffer = 0; |
55 | 56 | |
56 | 57 | _caretVisible = false; |
57 | 58 | _caretTime = 0; |
… |
… |
|
71 | 72 | for (int i = 0; i < kHistorySize; i++) |
72 | 73 | _history[i][0] = '\0'; |
73 | 74 | |
| 75 | _promptStartPos = _promptEndPos = -1; |
| 76 | |
74 | 77 | // Display greetings & prompt |
75 | 78 | print(gScummVMFullVersion); |
76 | 79 | print("\nConsole is ready\n"); |
77 | | |
78 | | _promptStartPos = _promptEndPos = -1; |
79 | 80 | } |
80 | 81 | |
81 | 82 | void ConsoleDialog::reflowLayout() { |
… |
… |
|
109 | 110 | // Draw text |
110 | 111 | int start = _scrollLine - _linesPerPage + 1; |
111 | 112 | int y = _y + 2; |
| 113 | |
112 | 114 | for (int line = 0; line < _linesPerPage; line++) { |
113 | 115 | int x = _x + 1; |
114 | 116 | for (int column = 0; column < _lineWidth; column++) { |
… |
… |
|
232 | 234 | killChar(); |
233 | 235 | draw(); |
234 | 236 | break; |
235 | | /* |
236 | 237 | case 256 + 24: // pageup |
237 | | _selectedItem -= _entriesPerPage - 1; |
238 | | if (_selectedItem < 0) |
239 | | _selectedItem = 0; |
| 238 | if (modifiers == OSystem::KBD_SHIFT) { |
| 239 | _scrollLine -= _linesPerPage - 1; |
| 240 | if (_scrollLine < _firstLineInBuffer + _linesPerPage - 1) |
| 241 | _scrollLine = _firstLineInBuffer + _linesPerPage - 1; |
| 242 | updateScrollBuffer(); |
| 243 | draw(); |
| 244 | } |
240 | 245 | break; |
241 | 246 | case 256 + 25: // pagedown |
242 | | _selectedItem += _entriesPerPage - 1; |
243 | | if (_selectedItem >= _list.size() ) |
244 | | _selectedItem = _list.size() - 1; |
| 247 | if (modifiers == OSystem::KBD_SHIFT) { |
| 248 | _scrollLine += _linesPerPage - 1; |
| 249 | if (_scrollLine > _promptEndPos / _lineWidth) |
| 250 | _scrollLine = _promptEndPos / _lineWidth; |
| 251 | updateScrollBuffer(); |
| 252 | draw(); |
| 253 | } |
245 | 254 | break; |
246 | | */ |
247 | 255 | case 256 + 22: // home |
248 | | _scrollLine = _linesPerPage - 1; // FIXME - this is not correct after a wrap around |
249 | | updateScrollBar(); |
| 256 | if (modifiers == OSystem::KBD_SHIFT) { |
| 257 | _scrollLine = _firstLineInBuffer + _linesPerPage - 1; |
| 258 | updateScrollBuffer(); |
| 259 | } else { |
| 260 | _currentPos = _promptStartPos; |
| 261 | } |
250 | 262 | draw(); |
251 | 263 | break; |
252 | 264 | case 256 + 23: // end |
253 | | _scrollLine = _currentPos / _lineWidth; |
254 | | updateScrollBar(); |
| 265 | if (modifiers == OSystem::KBD_SHIFT) { |
| 266 | _scrollLine = _promptEndPos / _lineWidth; |
| 267 | if (_scrollLine < _linesPerPage - 1) |
| 268 | _scrollLine = _linesPerPage - 1; |
| 269 | updateScrollBuffer(); |
| 270 | } else { |
| 271 | _currentPos = _promptEndPos; |
| 272 | } |
255 | 273 | draw(); |
256 | 274 | break; |
257 | 275 | case 273: // cursor up |
… |
… |
|
299 | 317 | void ConsoleDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { |
300 | 318 | switch (cmd) { |
301 | 319 | case kSetPositionCmd: |
302 | | int newPos = (int)data + _linesPerPage - 1; |
| 320 | int newPos = (int)data + _linesPerPage - 1 + _firstLineInBuffer; |
303 | 321 | if (newPos != _scrollLine) { |
304 | 322 | _scrollLine = newPos; |
305 | 323 | draw(); |
… |
… |
|
425 | 443 | _scrollLine++; |
426 | 444 | _currentPos = (line + 1) * _lineWidth; |
427 | 445 | |
428 | | updateScrollBar(); |
| 446 | updateScrollBuffer(); |
429 | 447 | } |
430 | 448 | |
431 | | void ConsoleDialog::updateScrollBar() { |
432 | | int line = _currentPos / _lineWidth; |
433 | | _scrollBar->_numEntries = (line < _linesInBuffer) ? line + 1 : _linesInBuffer; |
| 449 | |
| 450 | // Call this (at least) when the current line changes or when |
| 451 | // a new line is added |
| 452 | void ConsoleDialog::updateScrollBuffer() { |
| 453 | int lastchar = MAX(_promptEndPos, _currentPos); |
| 454 | int line = lastchar / _lineWidth; |
| 455 | int numlines = (line < _linesInBuffer) ? line + 1 : _linesInBuffer; |
| 456 | int firstline = line - numlines + 1; |
| 457 | if (firstline > _firstLineInBuffer) { |
| 458 | // clear old line from buffer |
| 459 | for (int i = lastchar; i < (line+1) * _lineWidth; ++i) |
| 460 | buffer(i) = ' '; |
| 461 | _firstLineInBuffer = firstline; |
| 462 | } |
| 463 | |
| 464 | _scrollBar->_numEntries = numlines; |
434 | 465 | _scrollBar->_currentPos = _scrollBar->_numEntries - (line - _scrollLine + _linesPerPage); |
435 | 466 | _scrollBar->_entriesPerPage = _linesPerPage; |
436 | 467 | _scrollBar->recalc(); |
… |
… |
|
477 | 508 | _currentPos++; |
478 | 509 | if ((_scrollLine + 1) * _lineWidth == _currentPos) { |
479 | 510 | _scrollLine++; |
480 | | updateScrollBar(); |
| 511 | updateScrollBuffer(); |
481 | 512 | } |
482 | 513 | } |
483 | 514 | } |
… |
… |
|
519 | 550 | } |
520 | 551 | |
521 | 552 | void ConsoleDialog::scrollToCurrent() { |
522 | | int line = _currentPos / _lineWidth; |
| 553 | int line = _promptEndPos / _lineWidth; |
523 | 554 | |
524 | 555 | if (line + _linesPerPage <= _scrollLine) { |
525 | 556 | // TODO - this should only occur for loong edit lines, though |
526 | 557 | } else if (line > _scrollLine) { |
527 | 558 | _scrollLine = line; |
528 | | updateScrollBar(); |
| 559 | updateScrollBuffer(); |
529 | 560 | } |
530 | 561 | } |
531 | 562 | |