[Scummvm-cvs-logs] CVS: scummvm/gui console.cpp,1.4,1.5 console.h,1.3,1.4

Max Horn fingolfin at users.sourceforge.net
Sat Dec 14 12:05:25 CET 2002


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv25394

Modified Files:
	console.cpp console.h 
Log Message:
added a scrollbar to console

Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- console.cpp	14 Dec 2002 18:57:15 -0000	1.4
+++ console.cpp	14 Dec 2002 20:04:46 -0000	1.5
@@ -21,6 +21,7 @@
 #include "stdafx.h"
 #include "console.h"
 #include "newgui.h"
+#include "ScrollBarWidget.h"
 
 #include "common/engine.h"
 
@@ -50,7 +51,7 @@
 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 @@
 	_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 @@
 		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::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 @@
 				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::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, ...)

Index: console.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- console.h	14 Dec 2002 18:57:15 -0000	1.3
+++ console.h	14 Dec 2002 20:04:46 -0000	1.4
@@ -33,6 +33,8 @@
 	kCharWidth = 8
 };
 
+class ScrollBarWidget;
+
 class ConsoleDialog : public Dialog {
 	typedef ScummVM::String String;
 protected:
@@ -51,6 +53,8 @@
 
 	bool	_caretVisible;
 	uint32	_caretTime;
+	
+	ScrollBarWidget	*_scrollBar;
 
 public:
 	ConsoleDialog(NewGui *gui);
@@ -61,8 +65,9 @@
 	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 @@
 	void drawCaret(bool erase);
 	void print(const char *str);
 	void nextLine();
+	void updateScrollBar();
 };
 
 #endif





More information about the Scummvm-git-logs mailing list