[Scummvm-cvs-logs] CVS: scummvm/gui about.cpp,1.26,1.27 about.h,1.8,1.9 newgui.cpp,1.106,1.107 newgui.h,1.54,1.55

Max Horn fingolfin at users.sourceforge.net
Sat Apr 16 04:41:43 CEST 2005


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

Modified Files:
	about.cpp about.h newgui.cpp newgui.h 
Log Message:
Patch #1183808 (GUI: Less CPU-intensive credits scroll), with some tweaks by me

Index: about.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/about.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- about.cpp	10 Jan 2005 22:35:40 -0000	1.26
+++ about.cpp	16 Apr 2005 11:40:07 -0000	1.27
@@ -120,16 +120,33 @@
 	_scrollPos = 0;
 	_modifiers = 0;
 	_willClose = false;
+	_canvas.pixels = NULL;
 
 	Dialog::open();
 }
 
+void AboutDialog::close() {
+	free(_canvas.pixels);
+	Dialog::close();
+}
+
 void AboutDialog::drawDialog() {
-	// Blend over the background
-	g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor);
+	if (!_canvas.pixels) {
+		// Blend over the background. Since we can't afford to do that
+		// every time the text is updated (it's horribly CPU intensive)
+		// we do it just once and then use a copy of the result as our
+		// static background for the remainder of the credits.
+		g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor);
+		g_gui.copyToSurface(&_canvas, _x, _y, _w, _h);
+	}
+
+	g_gui.drawSurface(_canvas, _x, _y);
 
 	// Draw text
 	// TODO: Add a "fade" effect for the top/bottom text lines
+	// TODO: Maybe prerender all of the text into another surface,
+	//       and then simply compose that over the screen surface
+	//       in the right way. Should be even faster...
 	const int firstLine = _scrollPos / _lineHeight;
 	const int lastLine = MIN((_scrollPos + _h) / _lineHeight + 1, (uint32)_lines.size());
 	int y = _y + kYOff - (_scrollPos % _lineHeight);
@@ -212,13 +229,18 @@
 		} else if ((uint32)_scrollPos > _lines.size() * _lineHeight) {
 			_scrollPos = 0;
 			_scrollTime += kScrollStartDelay;
-		} else {
-			g_gui.addDirtyRect(_x, _y, _w, _h);
 		}
-		draw();	// Issue a full redraw
+		drawDialog();
 	}
 }
 
+void AboutDialog::handleScreenChanged() {
+	// The screen has changed. Reset the canvas, to ensure it gets
+	// refreshed next time a redraw takes place.
+	free(_canvas.pixels);
+	_canvas.pixels = NULL;
+}
+
 void AboutDialog::handleMouseUp(int x, int y, int button, int clickCount) {
 	// Close upon any mouse click
 	close();

Index: about.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/about.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- about.h	1 Jan 2005 16:09:06 -0000	1.8
+++ about.h	16 Apr 2005 11:40:09 -0000	1.9
@@ -23,6 +23,7 @@
 
 #include "gui/dialog.h"
 #include "common/str.h"
+#include "graphics/surface.h"
 
 namespace GUI {
 
@@ -35,13 +36,16 @@
 	uint32		_lineHeight;
 	byte		_modifiers;
 	bool		_willClose;
+	Graphics::Surface	_canvas;
 
 public:
 	AboutDialog();
 
 	void open();
+	void close();
 	void drawDialog();
 	void handleTickle();
+	void handleScreenChanged();
 	void handleMouseUp(int x, int y, int button, int clickCount);
 	void handleKeyDown(uint16 ascii, int keycode, int modifiers);
 	void handleKeyUp(uint16 ascii, int keycode, int modifiers);

Index: newgui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.cpp,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -d -r1.106 -r1.107
--- newgui.cpp	3 Apr 2005 19:41:20 -0000	1.106
+++ newgui.cpp	16 Apr 2005 11:40:09 -0000	1.107
@@ -301,6 +301,54 @@
 	_screen.vLine(x * _scaleFactor, y * _scaleFactor, y2 * _scaleFactor, color);
 }
 
+void NewGui::copyToSurface(Graphics::Surface *s, int x, int y, int w, int h) {
+	Common::Rect rect(x * _scaleFactor, y * _scaleFactor, (x + w) * _scaleFactor, (y + h) * _scaleFactor);
+	rect.clip(_screen.w, _screen.h);
+
+	if (!rect.isValidRect())
+		return;
+
+	s->w = rect.width();
+	s->h = rect.height();
+	s->bytesPerPixel = sizeof(OverlayColor);
+	s->pitch = s->w * s->bytesPerPixel;
+	s->pixels = (OverlayColor *)malloc(s->pitch * s->h);
+
+	w = s->w;
+	h = s->h;
+
+	OverlayColor *dst = (OverlayColor *)s->pixels;
+	OverlayColor *src = getBasePtr(rect.left, rect.top);
+
+	while (h--) {
+		memcpy(dst, src, s->pitch);
+		src += _screenPitch;
+		dst += s->w;
+	}
+}
+
+void NewGui::drawSurface(const Graphics::Surface &s, int x, int y) {
+	Common::Rect rect(x * _scaleFactor, y * _scaleFactor, x * _scaleFactor + s.w, y * _scaleFactor + s.h);
+	rect.clip(_screen.w, _screen.h);
+
+	if (!rect.isValidRect())
+		return;
+	
+	assert(s.bytesPerPixel == sizeof(OverlayColor));
+
+	OverlayColor *src = (OverlayColor *)s.pixels;
+	OverlayColor *dst = getBasePtr(rect.left, rect.top);
+
+	int w = rect.width();
+	int h = rect.height();
+
+	while (h--) {
+		memcpy(dst, src, s.pitch);
+		src += w;
+		dst += _screenPitch;
+	}
+}
+
 void NewGui::blendRect(int x, int y, int w, int h, OverlayColor color, int level) {
 #ifdef NEWGUI_256
 	fillRect(x, y, w, h, color);

Index: newgui.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- newgui.h	10 Jan 2005 22:05:38 -0000	1.54
+++ newgui.h	16 Apr 2005 11:40:15 -0000	1.55
@@ -134,6 +134,19 @@
 	void box(int x, int y, int width, int height, OverlayColor colorA, OverlayColor colorB);
 	void hLine(int x, int y, int x2, OverlayColor color);
 	void vLine(int x, int y, int y2, OverlayColor color);
+
+	/**
+	 * Copy the specified screen rectangle into a new graphics surfaces.
+	 * New memory for the GFX data is allocated via malloc; it is the
+	 * callers responsibilty to free that data.
+	 */
+	void copyToSurface(Graphics::Surface *s, int x, int y, int w, int h);
+	
+	/**
+	 * Draw the graphics contained in the given surface at the specified coordinates.
+	 */
+	void drawSurface(const Graphics::Surface &s, int x, int y);
+
 	void blendRect(int x, int y, int w, int h, OverlayColor color, int level = 3);
 	void fillRect(int x, int y, int w, int h, OverlayColor color);
 	void frameRect(int x, int y, int w, int h, OverlayColor color);





More information about the Scummvm-git-logs mailing list