aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2002-12-14 20:04:46 +0000
committerMax Horn2002-12-14 20:04:46 +0000
commit534b4c4be4aa3c07f6e991ef25f36551aff0ff96 (patch)
treefd2c97f7ddbf0efdcb57fd00de93ddca4740e68e
parentc5294a352865810dad2f1116216b782d854df7fd (diff)
downloadscummvm-rg350-534b4c4be4aa3c07f6e991ef25f36551aff0ff96.tar.gz
scummvm-rg350-534b4c4be4aa3c07f6e991ef25f36551aff0ff96.tar.bz2
scummvm-rg350-534b4c4be4aa3c07f6e991ef25f36551aff0ff96.zip
added a scrollbar to console
svn-id: r5964
-rw-r--r--gui/console.cpp72
-rw-r--r--gui/console.h8
2 files changed, 75 insertions, 5 deletions
diff --git a/gui/console.cpp b/gui/console.cpp
index 0a7c249e08..2c79de0739 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -21,6 +21,7 @@
#include "stdafx.h"
#include "console.h"
#include "newgui.h"
+#include "ScrollBarWidget.h"
#include "common/engine.h"
@@ -50,7 +51,7 @@ This code is not finished, so please don't complain :-)
ConsoleDialog::ConsoleDialog(NewGui *gui)
: Dialog(gui, 0, 0, 320, 6*kLineHeight+2)
{
- _lineWidth = (_w - 2) / kCharWidth;
+ _lineWidth = (_w - kScrollBarWidth - 2) / kCharWidth;
_linesPerPage = (_h - 2) / kLineHeight;
memset(_buffer, ' ', kBufferSize);
@@ -60,15 +61,20 @@ ConsoleDialog::ConsoleDialog(NewGui *gui)
_currentLine = 0;
_scrollLine = _linesPerPage - 1;
+ _caretVisible = false;
+ _caretTime = 0;
+
+ // Add scrollbar
+ _scrollBar = new ScrollBarWidget(this, _w - kScrollBarWidth - 1, 0, kScrollBarWidth, _h);
+ _scrollBar->setTarget(this);
+
+ // Display greetings & prompt
print("ScummVM "SCUMMVM_VERSION" (" SCUMMVM_CVS ")\n");
print("Console is ready\n");
print(PROMPT);
_promptLine = _currentLine;
-
- _caretVisible = false;
- _caretTime = 0;
}
void ConsoleDialog::drawDialog()
@@ -93,6 +99,9 @@ void ConsoleDialog::drawDialog()
y += kLineHeight;
}
+ // Draw the scrollbar
+ _scrollBar->draw();
+
// Finally blit it all to the screen
_gui->addDirtyRect(_x, _y, _w, _h);
}
@@ -110,6 +119,11 @@ void ConsoleDialog::handleTickle()
}
}
+void ConsoleDialog::handleMouseWheel(int x, int y, int direction)
+{
+ _scrollBar->handleMouseWheel(x, y, direction);
+}
+
void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
switch (keycode) {
@@ -140,6 +154,28 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
drawCaret(true);
draw(); // FIXME - not nice to redraw the full console just for one char!
break;
+/*
+ case 256+24: // pageup
+ _selectedItem -= _entriesPerPage - 1;
+ if (_selectedItem < 0)
+ _selectedItem = 0;
+ break;
+ case 256+25: // pagedown
+ _selectedItem += _entriesPerPage - 1;
+ if (_selectedItem >= _list.size() )
+ _selectedItem = _list.size() - 1;
+ break;
+*/
+ case 256+22: // home
+ _scrollLine = _linesPerPage - 1; // FIXME - this is not correct after a wrap around
+ updateScrollBar();
+ draw();
+ break;
+ case 256+23: // end
+ _scrollLine = _currentLine;
+ updateScrollBar();
+ draw();
+ break;
default:
if (ascii == '~' || ascii == '#') {
close();
@@ -149,12 +185,40 @@ void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
}
}
+void ConsoleDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
+{
+ switch (cmd) {
+ case kSetPositionCmd:
+ int newPos = (int)data + _linesPerPage - 1;
+ if (newPos != _scrollLine) {
+ _scrollLine = newPos;
+ draw();
+ }
+ break;
+ }
+}
+
void ConsoleDialog::nextLine()
{
_currentColumn = 0;
if (_currentLine == _scrollLine)
_scrollLine++;
_currentLine++;
+
+ updateScrollBar();
+}
+
+void ConsoleDialog::updateScrollBar()
+{
+ if (_currentLine < _linesInBuffer) {
+ _scrollBar->_numEntries = _currentLine + 1;
+ _scrollBar->_currentPos = _scrollLine - _linesPerPage + 1;
+ } else {
+ _scrollBar->_numEntries = _linesInBuffer;
+ _scrollBar->_currentPos = _scrollLine - _linesPerPage + 1 - (_currentLine - _linesInBuffer);
+ }
+ _scrollBar->_entriesPerPage = _linesPerPage;
+ _scrollBar->recalc();
}
int ConsoleDialog::printf(const char *format, ...)
diff --git a/gui/console.h b/gui/console.h
index ab8b748db6..01d0705661 100644
--- a/gui/console.h
+++ b/gui/console.h
@@ -33,6 +33,8 @@ enum {
kCharWidth = 8
};
+class ScrollBarWidget;
+
class ConsoleDialog : public Dialog {
typedef ScummVM::String String;
protected:
@@ -51,6 +53,8 @@ protected:
bool _caretVisible;
uint32 _caretTime;
+
+ ScrollBarWidget *_scrollBar;
public:
ConsoleDialog(NewGui *gui);
@@ -61,8 +65,9 @@ public:
void drawDialog();
void handleTickle();
+ void handleMouseWheel(int x, int y, int direction);
void handleKeyDown(uint16 ascii, int keycode, int modifiers);
-// void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+ void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
int printf(const char *format, ...);
int vprintf(const char *format, va_list argptr);
@@ -73,6 +78,7 @@ protected:
void drawCaret(bool erase);
void print(const char *str);
void nextLine();
+ void updateScrollBar();
};
#endif