[Scummvm-cvs-logs] SF.net SVN: scummvm: [29635] scummvm/trunk/engines

sev at users.sourceforge.net sev at users.sourceforge.net
Sun Nov 25 11:27:50 CET 2007


Revision: 29635
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29635&view=rev
Author:   sev
Date:     2007-11-25 02:27:50 -0800 (Sun, 25 Nov 2007)

Log Message:
-----------
Switch to our common drawLine routine

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/he/wiz_he.cpp
    scummvm/trunk/engines/touche/graphics.cpp
    scummvm/trunk/engines/touche/graphics.h
    scummvm/trunk/engines/touche/menu.cpp

Modified: scummvm/trunk/engines/scumm/he/wiz_he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/wiz_he.cpp	2007-11-25 10:04:23 UTC (rev 29634)
+++ scummvm/trunk/engines/scumm/he/wiz_he.cpp	2007-11-25 10:27:50 UTC (rev 29635)
@@ -27,6 +27,7 @@
 
 #include "common/system.h"
 #include "graphics/cursorman.h"
+#include "graphics/primitives.h"
 #include "scumm/he/intern_he.h"
 #include "scumm/resource.h"
 #include "scumm/scumm.h"
@@ -1742,6 +1743,20 @@
 	_vm->_res->setModified(rtImage, params->img.resNum);
 }
 
+struct drawProcP {
+	Common::Rect *imageRect;
+	uint8 *wizd;
+	int width;
+};
+
+static void drawProc(int x, int y, int c, void *data) {
+	drawProcP *param = (drawProcP *)data;
+
+	if (param->imageRect->contains(x, y)) {
+		*(param->wizd + y * param->width + x) = c;
+	}
+}
+
 void Wiz::fillWizLine(const WizParameters *params) {
 	if (params->processFlags & kWPFClipBox2) {
 		int state = 0;
@@ -1777,61 +1792,13 @@
 			if (params->processFlags & kWPFThickLine) {
 				debug(0, "Unsupported ThickLine (%d, %d)", params->lineUnk1, params->lineUnk2);
 			} else {
-				int dx = x2 - x1;
-				int incx = 0;
-				if (dx > 0) {
-					incx = 1;
-				} else if (dx < 0) {
-					incx = -1;
-				}
-				int dy = y2 - y1;
-				int incy = 0;
-				if (dy > 0) {
-					incy = 1;
-				} else if (dy < 0) {
-					incy = -1;
-				}
+				drawProcP lineP;
 
-				dx = ABS(x2 - x1);
-				dy = ABS(y2 - y1);
+				lineP.imageRect = &imageRect;
+				lineP.wizd = wizd;
+				lineP.width = w;
 
-				if (imageRect.contains(x1, y1)) {
-					*(wizd + y1 * w + x1) = color;
-				}
-
-				if (dx >= dy) {
-					int step1_y = (dy - dx) * 2;
-					int step2_y = dy * 2;
-					int accum_y = dy * 2 - dx;
-					while (x1 != x2) {
-						if (accum_y <= 0) {
-							accum_y += step2_y;
-						} else {
-							accum_y += step1_y;
-							y1 += incy;
-						}
-						x1 += incx;
-						if (imageRect.contains(x1, y1)) {
-							*(wizd + y1 * w + x1) = color;
-						}
-					}
-				} else {
-					int step1_x = (dx - dy) * 2;
-					int step2_x = dx * 2;
-					int accum_x = dx * 2 - dy;
-					while (y1 != y2) {
-						if (accum_x <= 0) {
-							accum_x += step2_x;
-						} else {
-							accum_x += step1_x;
-							x1 += incx;
-						}
-						y1 += incy;
-						if (imageRect.contains(x1, y1)) {
-							*(wizd + y1 * w + x1) = color;
-						}
-					}
-				}
+				Graphics::drawLine(x1, y1, x2, y2, color, drawProc, &lineP);
 			}
 		}
 	}

Modified: scummvm/trunk/engines/touche/graphics.cpp
===================================================================
--- scummvm/trunk/engines/touche/graphics.cpp	2007-11-25 10:04:23 UTC (rev 29634)
+++ scummvm/trunk/engines/touche/graphics.cpp	2007-11-25 10:27:50 UTC (rev 29635)
@@ -24,6 +24,7 @@
  */
 
 #include "common/endian.h"
+#include "graphics/primitives.h"
 
 #include "touche/graphics.h"
 
@@ -128,56 +129,15 @@
 	const int y1 = y;
 	const int x2 = x + w - 1;
 	const int y2 = y + h - 1;
-	drawLine(dst, dstPitch, x1, y1, x2, y1, color1);
-	drawLine(dst, dstPitch, x1, y1, x1, y2, color1);
-	drawLine(dst, dstPitch, x2, y1 + 1, x2, y2, color2);
-	drawLine(dst, dstPitch, x1 + 1, y2, x2, y2, color2);
-}
+	drawProcP lineP;
 
-void Graphics::drawLine(uint8 *dst, int dstPitch, int x1, int y1, int x2, int y2, uint8 color) {
-	assert(x1 >= 0 && y1 >= 0 && x2 >= 0 && y2 >= 0);
+	lineP.dst = dst;
+	lineP.width = dstPitch;
 
-	dst += y1 * dstPitch + x1;
-
-	int yInc, dy = y2 - y1;
-	if (dy < 0) {
-		dy = -dy;
-		yInc = -dstPitch;
-	} else {
-		yInc = dstPitch;
-	}
-
-	int xInc, dx = x2 - x1;
-	if (dx < 0) {
-		dx = -dx;
-		xInc = -1;
-	} else {
-		xInc = 1;
-	}
-
-	int step = 0;
-
-	if (dx > dy) {
-		for (int i = 0; i < dx + 1; ++i) {
-			*dst = color;
-			dst += xInc;
-			step += dy;
-			if (step > dx) {
-				step -= dx;
-				dst += yInc;
-			}
-		}
-	} else {
-		for (int i = 0; i < dy + 1; ++i) {
-			*dst = color;
-			dst += yInc;
-			step += dx;
-			if (step > 0) {
-				step -= dy;
-				dst += xInc;
-			}
-		}
-	}
+	::Graphics::drawLine(x1, y1, x2, y1, color1, drawProc, &lineP);
+	::Graphics::drawLine(x1, y1, x1, y2, color1, drawProc, &lineP);
+	::Graphics::drawLine(x2, y1 + 1, x2, y2, color2, drawProc, &lineP);
+	::Graphics::drawLine(x1 + 1, y2, x2, y2, color2, drawProc, &lineP);
 }
 
 void Graphics::copyRect(uint8 *dst, int dstPitch, int dstX, int dstY, const uint8 *src, int srcPitch, int srcX, int srcY, int w, int h, int flags) {

Modified: scummvm/trunk/engines/touche/graphics.h
===================================================================
--- scummvm/trunk/engines/touche/graphics.h	2007-11-25 10:04:23 UTC (rev 29634)
+++ scummvm/trunk/engines/touche/graphics.h	2007-11-25 10:27:50 UTC (rev 29635)
@@ -30,6 +30,11 @@
 
 namespace Touche {
 
+struct drawProcP {
+	uint8 *dst;
+	int width;
+};
+
 class Graphics {
 public:
 
@@ -44,10 +49,15 @@
 	static int drawChar16(uint8 *dst, int dstPitch, uint8 chr, int x, int y, uint16 color);
 	static void fillRect(uint8 *dst, int dstPitch, int x, int y, int w, int h, uint8 color);
 	static void drawRect(uint8 *dst, int dstPitch, int x, int y, int w, int h, uint8 color1, uint8 color2);
-	static void drawLine(uint8 *dst, int dstPitch, int x1, int y1, int x2, int y2, uint8 color);
 	static void copyRect(uint8 *dst, int dstPitch, int dstX, int dstY, const uint8 *src, int srcPitch, int srcX, int srcY, int w, int h, int flags = 0);
 	static void copyMask(uint8 *dst, int dstPitch, int dstX, int dstY, const uint8 *src, int srcPitch, int srcX, int srcY, int w, int h, uint8 fillColor);
 
+	static void drawProc(int x, int y, int c, void *data) {
+		drawProcP *param = (drawProcP *)data;
+
+		*(param->dst + y * param->width + x) = c;
+	}
+
 private:
 
 	/* font data for english version */

Modified: scummvm/trunk/engines/touche/menu.cpp
===================================================================
--- scummvm/trunk/engines/touche/menu.cpp	2007-11-25 10:04:23 UTC (rev 29634)
+++ scummvm/trunk/engines/touche/menu.cpp	2007-11-25 10:27:50 UTC (rev 29635)
@@ -28,6 +28,8 @@
 #include "common/system.h"
 #include "common/savefile.h"
 
+#include "graphics/primitives.h"
+
 #include "touche/graphics.h"
 #include "touche/midi.h"
 #include "touche/touche.h"
@@ -134,12 +136,17 @@
 		{ -9,  0,  0, -9 },
 		{  0, -9,  9,  0 }
 	};
+	drawProcP lineP;
+
+	lineP.dst = dst;
+	lineP.width = dstPitch;
+
 	for (uint i = 0; i < 7; ++i) {
 		const int x1 = x + arrowCoordsTable[i][0];
 		const int y1 = y + arrowCoordsTable[i][1] * delta;
 		const int x2 = x + arrowCoordsTable[i][2];
 		const int y2 = y + arrowCoordsTable[i][3] * delta;
-		Graphics::drawLine(dst, dstPitch, x1, y1, x2, y2, color);
+		::Graphics::drawLine(x1, y1, x2, y2, color, Graphics::drawProc, &lineP);
 	}
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list