Renamed kLineWidth to kCharsPerLine, and moved some enum constants into class ConsoleDialog (to avoid name clashes with other code)

svn-id: r23889
This commit is contained in:
Max Horn 2006-09-16 15:19:23 +00:00
parent a2dc897fe5
commit 1add07beca
2 changed files with 25 additions and 25 deletions

View file

@ -123,7 +123,7 @@ void ConsoleDialog::init() {
_pageWidth = (_w - scrollBarWidth - 2 - _leftPadding - _topPadding - scrollBarWidth) / kConsoleCharWidth; _pageWidth = (_w - scrollBarWidth - 2 - _leftPadding - _topPadding - scrollBarWidth) / kConsoleCharWidth;
_linesPerPage = (_h - 2 - _topPadding - _bottomPadding) / kConsoleLineHeight; _linesPerPage = (_h - 2 - _topPadding - _bottomPadding) / kConsoleLineHeight;
_linesInBuffer = kBufferSize / kLineWidth; _linesInBuffer = kBufferSize / kCharsPerLine;
} }
void ConsoleDialog::slideUpAndClose() { void ConsoleDialog::slideUpAndClose() {
@ -185,7 +185,7 @@ void ConsoleDialog::drawLine(int line, bool restoreBg) {
int x = _x + 1 + _leftPadding; int x = _x + 1 + _leftPadding;
int start = _scrollLine - _linesPerPage + 1; int start = _scrollLine - _linesPerPage + 1;
int y = _y + 2 + _topPadding; int y = _y + 2 + _topPadding;
int limit = MIN(_pageWidth, (int)kLineWidth); int limit = MIN(_pageWidth, (int)kCharsPerLine);
y += line * kConsoleLineHeight; y += line * kConsoleLineHeight;
@ -198,9 +198,9 @@ void ConsoleDialog::drawLine(int line, bool restoreBg) {
for (int column = 0; column < limit; column++) { for (int column = 0; column < limit; column++) {
#if 0 #if 0
int l = (start + line) % _linesInBuffer; int l = (start + line) % _linesInBuffer;
byte c = buffer(l * kLineWidth + column); byte c = buffer(l * kCharsPerLine + column);
#else #else
byte c = buffer((start + line) * kLineWidth + column); byte c = buffer((start + line) * kCharsPerLine + column);
#endif #endif
g_gui.theme()->drawChar(Common::Rect(x, y, x+kConsoleCharWidth, y+kConsoleLineHeight), c, _font); g_gui.theme()->drawChar(Common::Rect(x, y, x+kConsoleCharWidth, y+kConsoleLineHeight), c, _font);
x += kConsoleCharWidth; x += kConsoleCharWidth;
@ -210,7 +210,7 @@ void ConsoleDialog::drawLine(int line, bool restoreBg) {
void ConsoleDialog::reflowLayout() { void ConsoleDialog::reflowLayout() {
init(); init();
_scrollLine = _promptEndPos / kLineWidth; _scrollLine = _promptEndPos / kCharsPerLine;
if (_scrollLine < _linesPerPage - 1) if (_scrollLine < _linesPerPage - 1)
_scrollLine = _linesPerPage - 1; _scrollLine = _linesPerPage - 1;
updateScrollBuffer(); updateScrollBuffer();
@ -358,8 +358,8 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
case 256 + 25: // pagedown case 256 + 25: // pagedown
if (modifiers == OSystem::KBD_SHIFT) { if (modifiers == OSystem::KBD_SHIFT) {
_scrollLine += _linesPerPage - 1; _scrollLine += _linesPerPage - 1;
if (_scrollLine > _promptEndPos / kLineWidth) { if (_scrollLine > _promptEndPos / kCharsPerLine) {
_scrollLine = _promptEndPos / kLineWidth; _scrollLine = _promptEndPos / kCharsPerLine;
if (_scrollLine < _firstLineInBuffer + _linesPerPage - 1) if (_scrollLine < _firstLineInBuffer + _linesPerPage - 1)
_scrollLine = _firstLineInBuffer + _linesPerPage - 1; _scrollLine = _firstLineInBuffer + _linesPerPage - 1;
} }
@ -378,7 +378,7 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
break; break;
case 256 + 23: // end case 256 + 23: // end
if (modifiers == OSystem::KBD_SHIFT) { if (modifiers == OSystem::KBD_SHIFT) {
_scrollLine = _promptEndPos / kLineWidth; _scrollLine = _promptEndPos / kCharsPerLine;
if (_scrollLine < _linesPerPage - 1) if (_scrollLine < _linesPerPage - 1)
_scrollLine = _linesPerPage - 1; _scrollLine = _linesPerPage - 1;
updateScrollBuffer(); updateScrollBuffer();
@ -552,10 +552,10 @@ void ConsoleDialog::historyScroll(int direction) {
} }
void ConsoleDialog::nextLine() { void ConsoleDialog::nextLine() {
int line = _currentPos / kLineWidth; int line = _currentPos / kCharsPerLine;
if (line == _scrollLine) if (line == _scrollLine)
_scrollLine++; _scrollLine++;
_currentPos = (line + 1) * kLineWidth; _currentPos = (line + 1) * kCharsPerLine;
updateScrollBuffer(); updateScrollBuffer();
} }
@ -565,12 +565,12 @@ void ConsoleDialog::nextLine() {
// a new line is added // a new line is added
void ConsoleDialog::updateScrollBuffer() { void ConsoleDialog::updateScrollBuffer() {
int lastchar = MAX(_promptEndPos, _currentPos); int lastchar = MAX(_promptEndPos, _currentPos);
int line = lastchar / kLineWidth; int line = lastchar / kCharsPerLine;
int numlines = (line < _linesInBuffer) ? line + 1 : _linesInBuffer; int numlines = (line < _linesInBuffer) ? line + 1 : _linesInBuffer;
int firstline = line - numlines + 1; int firstline = line - numlines + 1;
if (firstline > _firstLineInBuffer) { if (firstline > _firstLineInBuffer) {
// clear old line from buffer // clear old line from buffer
for (int i = lastchar; i < (line+1) * kLineWidth; ++i) for (int i = lastchar; i < (line+1) * kCharsPerLine; ++i)
buffer(i) = ' '; buffer(i) = ' ';
_firstLineInBuffer = firstline; _firstLineInBuffer = firstline;
} }
@ -622,7 +622,7 @@ void ConsoleDialog::putcharIntern(int c) {
else { else {
buffer(_currentPos) = (char)c; buffer(_currentPos) = (char)c;
_currentPos++; _currentPos++;
if ((_scrollLine + 1) * kLineWidth == _currentPos) { if ((_scrollLine + 1) * kCharsPerLine == _currentPos) {
_scrollLine++; _scrollLine++;
updateScrollBuffer(); updateScrollBuffer();
} }
@ -641,7 +641,7 @@ void ConsoleDialog::print(const char *str) {
void ConsoleDialog::drawCaret(bool erase) { void ConsoleDialog::drawCaret(bool erase) {
// TODO: use code from EditableWidget::drawCaret here // TODO: use code from EditableWidget::drawCaret here
int line = _currentPos / kLineWidth; int line = _currentPos / kCharsPerLine;
int displayLine = line - _scrollLine + _linesPerPage - 1; int displayLine = line - _scrollLine + _linesPerPage - 1;
// Only draw caret if visible // Only draw caret if visible
@ -650,7 +650,7 @@ void ConsoleDialog::drawCaret(bool erase) {
return; return;
} }
int x = _x + 1 + _leftPadding + (_currentPos % kLineWidth) * kConsoleCharWidth; int x = _x + 1 + _leftPadding + (_currentPos % kCharsPerLine) * kConsoleCharWidth;
int y = _y + _topPadding + displayLine * kConsoleLineHeight; int y = _y + _topPadding + displayLine * kConsoleLineHeight;
_caretVisible = !erase; _caretVisible = !erase;
@ -658,7 +658,7 @@ void ConsoleDialog::drawCaret(bool erase) {
} }
void ConsoleDialog::scrollToCurrent() { void ConsoleDialog::scrollToCurrent() {
int line = _promptEndPos / kLineWidth; int line = _promptEndPos / kCharsPerLine;
if (line + _linesPerPage <= _scrollLine) { if (line + _linesPerPage <= _scrollLine) {
// TODO - this should only occur for loong edit lines, though // TODO - this should only occur for loong edit lines, though

View file

@ -29,14 +29,6 @@
namespace GUI { namespace GUI {
enum {
kBufferSize = 32768,
kLineWidth = 128,
kLineBufferSize = 256,
kHistorySize = 20
};
class ScrollBarWidget; class ScrollBarWidget;
class ConsoleDialog : public Dialog { class ConsoleDialog : public Dialog {
@ -45,6 +37,14 @@ public:
typedef bool (*CompletionCallbackProc)(ConsoleDialog* console, const char *input, char*& completion, void *refCon); typedef bool (*CompletionCallbackProc)(ConsoleDialog* console, const char *input, char*& completion, void *refCon);
protected: protected:
enum {
kBufferSize = 32768,
kCharsPerLine = 128,
kLineBufferSize = 256,
kHistorySize = 20
};
const Graphics::Font *_font; const Graphics::Font *_font;
char _buffer[kBufferSize]; char _buffer[kBufferSize];
@ -131,7 +131,7 @@ protected:
void init(); void init();
int pos2line(int pos) { return (pos - (_scrollLine - _linesPerPage + 1) * kLineWidth) / kLineWidth; } int pos2line(int pos) { return (pos - (_scrollLine - _linesPerPage + 1) * kCharsPerLine) / kCharsPerLine; }
void drawLine(int line, bool restoreBg = true); void drawLine(int line, bool restoreBg = true);
void drawCaret(bool erase); void drawCaret(bool erase);