[Scummvm-cvs-logs] CVS: scummvm/gui console.cpp,1.63,1.64 console.h,1.32,1.33

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Wed Jul 13 07:40:32 CEST 2005


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7989

Modified Files:
	console.cpp console.h 
Log Message:
Cache the blended background in a surface, so that the blending only needs
to be made once, instead of whenever the console is redrawn. (This is the
same trick as the About dialog uses.)

It should speed up the drawing quite a bit, though it's not particularly
noticeable on the computer I'm using at the moment, so I can't say for
sure.


Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- console.cpp	24 Jun 2005 15:22:41 -0000	1.63
+++ console.cpp	13 Jul 2005 14:38:26 -0000	1.64
@@ -117,10 +117,16 @@
 }
 
 void ConsoleDialog::open() {
+	// This dialog will be redrawn a lot, so we store a copy of the blended
+	// background in a separate "canvas", just like in the About dialog.
+	_canvas.pixels = NULL;
+
+
 	// Initiate sliding the console down. We do a very simple trick to achieve
 	// this effect: we simply move the console dialog just above (outside) the
 	// visible screen area, then shift it down in handleTickle() over a
 	// certain period of time.
+
 	_y = -_h;
 	_slideTime = g_system->getMillis();
 	_slideMode = kDownSlideMode;
@@ -132,9 +138,19 @@
 	}
 }
 
+void ConsoleDialog::close() {
+	free(_canvas.pixels);
+	Dialog::close();
+}
+
 void ConsoleDialog::drawDialog() {
-	// Blend over the background
-	g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor, 2);
+	if (!_canvas.pixels) {
+		// Blend over the background
+		g_gui.blendRect(0, 0, _w, _h, g_gui._bgcolor, 2);
+		g_gui.copyToSurface(&_canvas, 0, 0, _w, _h);
+	}
+
+	g_gui.drawSurface(_canvas, 0, 0);
 
 	// Draw a border
 	g_gui.hLine(_x, _y + _h - 1, _x + _w - 1, g_gui._color);
@@ -165,7 +181,16 @@
 	g_gui.addDirtyRect(_x, _y, _w, _h);
 }
 
+void ConsoleDialog::handleScreenChanged() {
+	free(_canvas.pixels);
+	_canvas.pixels = NULL;
+	draw();
+}
+
 void ConsoleDialog::handleTickle() {
+	if (!_canvas.pixels)
+		return;
+
 	uint32 time = g_system->getMillis();
 	if (_caretTime < time) {
 		_caretTime = time + kCaretBlinkTime;

Index: console.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- console.h	2 Jun 2005 12:29:01 -0000	1.32
+++ console.h	13 Jul 2005 14:38:26 -0000	1.33
@@ -43,6 +43,7 @@
 	typedef bool (*CompletionCallbackProc)(ConsoleDialog* console, const char *input, char*& completion, void *refCon);
 
 protected:
+	Graphics::Surface	_canvas;
 	char	_buffer[kBufferSize];
 	int		_linesInBuffer;
 
@@ -92,9 +93,11 @@
 	ConsoleDialog(float widthPercent, float heightPercent);
 
 	void open();
+	void close();
 	void drawDialog();
 
 	void handleTickle();
+	void handleScreenChanged();
 	void handleMouseWheel(int x, int y, int direction);
 	void handleKeyDown(uint16 ascii, int keycode, int modifiers);
 	void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);





More information about the Scummvm-git-logs mailing list