[Scummvm-cvs-logs] SF.net SVN: scummvm:[44969] scummvm/trunk/engines/sci/gui

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Mon Oct 12 10:25:38 CEST 2009


Revision: 44969
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44969&view=rev
Author:   thebluegr
Date:     2009-10-12 08:25:38 +0000 (Mon, 12 Oct 2009)

Log Message:
-----------
Move the line drawing code to SciGuiScreen()

Modified Paths:
--------------
    scummvm/trunk/engines/sci/gui/gui.cpp
    scummvm/trunk/engines/sci/gui/gui_gfx.cpp
    scummvm/trunk/engines/sci/gui/gui_gfx.h
    scummvm/trunk/engines/sci/gui/gui_picture.cpp
    scummvm/trunk/engines/sci/gui/gui_screen.cpp
    scummvm/trunk/engines/sci/gui/gui_screen.h

Modified: scummvm/trunk/engines/sci/gui/gui.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui.cpp	2009-10-12 07:30:55 UTC (rev 44968)
+++ scummvm/trunk/engines/sci/gui/gui.cpp	2009-10-12 08:25:38 UTC (rev 44969)
@@ -418,7 +418,8 @@
 }
 
 void SciGui::graphDrawLine(Common::Point startPoint, Common::Point endPoint, int16 color, int16 priority, int16 control) {
-	_gfx->drawLine(startPoint.x, startPoint.y, endPoint.x, endPoint.y, color, priority, control);
+	_gfx->OffsetLine(startPoint, endPoint);
+	_screen->drawLine(startPoint.x, startPoint.y, endPoint.x, endPoint.y, color, priority, control);
 }
 
 reg_t SciGui::graphSaveBox(Common::Rect rect, uint16 flags) {

Modified: scummvm/trunk/engines/sci/gui/gui_gfx.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_gfx.cpp	2009-10-12 07:30:55 UTC (rev 44968)
+++ scummvm/trunk/engines/sci/gui/gui_gfx.cpp	2009-10-12 08:25:38 UTC (rev 44969)
@@ -253,6 +253,13 @@
 	r.right += _curPort->left;
 }
 
+void SciGuiGfx::OffsetLine(Common::Point &start, Common::Point &end) {
+	start.x += _curPort->left;
+	start.y += _curPort->top;
+	end.x += _curPort->left;
+	end.y += _curPort->top;
+}
+
 byte SciGuiGfx::CharHeight(int16 ch) {
 #if 0
 	CResFont *res = getResFont();
@@ -631,71 +638,6 @@
 	}
 }
 
-// Sierra's Bresenham line drawing
-// WARNING: Do not just blindly replace this with Graphics::drawLine(), as it seems to create issues with flood fill
-void SciGuiGfx::drawLine(int16 left, int16 top, int16 right, int16 bottom, byte color, byte priority, byte control) {
-	//set_drawing_flag
-	byte drawMask = _screen->getDrawingMask(color, priority, control);
-
-	// offseting the line
-	left += _curPort->left;
-	right += _curPort->left;
-	top += _curPort->top;
-	bottom += _curPort->top;
-
-	// horizontal line
-	if (top == bottom) {
-		if (right < left)
-			SWAP(right, left);
-		for (int i = left; i <= right; i++)
-			_screen->putPixel(i, top, drawMask, color, priority, control);
-		return;
-	}
-	// vertical line
-	if (left == right) {
-		if (top > bottom)
-			SWAP(top, bottom);
-		for (int i = top; i <= bottom; i++)
-			_screen->putPixel(left, i, drawMask, color, priority, control);
-		return;
-	}
-	// sloped line - draw with Bresenham algorithm
-	int dy = bottom - top;
-	int dx = right - left;
-	int stepy = dy < 0 ? -1 : 1;
-	int stepx = dx < 0 ? -1 : 1;
-	dy = ABS(dy) << 1;
-	dx = ABS(dx) << 1;
-
-	// setting the 1st and last pixel
-	_screen->putPixel(left, top, drawMask, color, priority, control);
-	_screen->putPixel(right, bottom, drawMask, color, priority, control);
-	// drawing the line
-	if (dx > dy) { // going horizontal
-		int fraction = dy - (dx >> 1);
-		while (left != right) {
-			if (fraction >= 0) {
-				top += stepy;
-				fraction -= dx;
-			}
-			left += stepx;
-			fraction += dy;
-			_screen->putPixel(left, top, drawMask, color, priority, control);
-		}
-	} else { // going vertical
-		int fraction = dx - (dy >> 1);
-		while (top != bottom) {
-			if (fraction >= 0) {
-				left += stepx;
-				fraction -= dy;
-			}
-			top += stepy;
-			fraction += dx;
-			_screen->putPixel(left, top, drawMask, color, priority, control);
-		}
-	}
-}
-
 void SciGuiGfx::Draw_String(const char *text) {
 	GuiResourceId orgFontId = GetFontId();
 	int16 orgPenColor = _curPort->penClr;

Modified: scummvm/trunk/engines/sci/gui/gui_gfx.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_gfx.h	2009-10-12 07:30:55 UTC (rev 44968)
+++ scummvm/trunk/engines/sci/gui/gui_gfx.h	2009-10-12 08:25:38 UTC (rev 44969)
@@ -84,6 +84,7 @@
 	void FillRect(const Common::Rect &rect, int16 drawFlags, byte clrPen, byte clrBack = 0, byte bControl = 0);
 	void FrameRect(const Common::Rect &rect);
 	void OffsetRect(Common::Rect &r);
+	void OffsetLine(Common::Point &start, Common::Point &end);
 
 	byte CharHeight(int16 ch);
 	byte CharWidth(int16 ch);
@@ -106,7 +107,6 @@
 	void BitsRestore(GuiMemoryHandle memoryHandle);
 	void BitsFree(GuiMemoryHandle memoryHandle);
 
-	void drawLine(int16 left, int16 top, int16 right, int16 bottom, byte color, byte prio, byte control);
 	void Draw_String(const char *text);
 	
 	void drawPicture(GuiResourceId pictureId, int16 animationNr, bool mirroredFlag, bool addToFlag, GuiResourceId paletteId);

Modified: scummvm/trunk/engines/sci/gui/gui_picture.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_picture.cpp	2009-10-12 07:30:55 UTC (rev 44968)
+++ scummvm/trunk/engines/sci/gui/gui_picture.cpp	2009-10-12 08:25:38 UTC (rev 44969)
@@ -357,7 +357,10 @@
 			while (vectorIsNonOpcode(data[curPos])) {
 				oldx = x; oldy = y;
 				vectorGetRelCoords(data, curPos, x, y);
-				_gfx->drawLine(oldx, oldy, x, y, pic_color, pic_priority, pic_control);
+				Common::Point startPoint(oldx, oldy);
+				Common::Point endPoint(x, y);
+				_gfx->OffsetLine(startPoint, endPoint);
+				_screen->drawLine(startPoint, endPoint, pic_color, pic_priority, pic_control);
 			}
 			break;
 		case PIC_OP_MEDIUM_LINES: // medium line
@@ -365,7 +368,10 @@
 			while (vectorIsNonOpcode(data[curPos])) {
 				oldx = x; oldy = y;
 				vectorGetRelCoordsMed(data, curPos, x, y);
-				_gfx->drawLine(oldx, oldy, x, y, pic_color, pic_priority, pic_control);
+				Common::Point startPoint(oldx, oldy);
+				Common::Point endPoint(x, y);
+				_gfx->OffsetLine(startPoint, endPoint);
+				_screen->drawLine(startPoint, endPoint, pic_color, pic_priority, pic_control);
 			}
 			break;
 		case PIC_OP_LONG_LINES: // long line
@@ -373,7 +379,10 @@
 			while (vectorIsNonOpcode(data[curPos])) {
 				oldx = x; oldy = y;
 				vectorGetAbsCoords(data, curPos, x, y);
-				_gfx->drawLine(oldx, oldy, x, y, pic_color, pic_priority, pic_control);
+				Common::Point startPoint(oldx, oldy);
+				Common::Point endPoint(x, y);
+				_gfx->OffsetLine(startPoint, endPoint);
+				_screen->drawLine(startPoint, endPoint, pic_color, pic_priority, pic_control);
 			}
 			break;
 

Modified: scummvm/trunk/engines/sci/gui/gui_screen.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_screen.cpp	2009-10-12 07:30:55 UTC (rev 44968)
+++ scummvm/trunk/engines/sci/gui/gui_screen.cpp	2009-10-12 08:25:38 UTC (rev 44969)
@@ -102,6 +102,70 @@
 		*(_controlScreen + offset) = control;
 }
 
+// Sierra's Bresenham line drawing
+// WARNING: Do not just blindly replace this with Graphics::drawLine(), as it seems to create issues with flood fill
+void SciGuiScreen::drawLine(Common::Point startPoint, Common::Point endPoint, byte color, byte priority, byte control) {
+	int16 left = startPoint.x;
+	int16 top = startPoint.y;
+	int16 right = endPoint.x;
+	int16 bottom = endPoint.y;
+
+	//set_drawing_flag
+	byte drawMask = getDrawingMask(color, priority, control);
+
+	// horizontal line
+	if (top == bottom) {
+		if (right < left)
+			SWAP(right, left);
+		for (int i = left; i <= right; i++)
+			putPixel(i, top, drawMask, color, priority, control);
+		return;
+	}
+	// vertical line
+	if (left == right) {
+		if (top > bottom)
+			SWAP(top, bottom);
+		for (int i = top; i <= bottom; i++)
+			putPixel(left, i, drawMask, color, priority, control);
+		return;
+	}
+	// sloped line - draw with Bresenham algorithm
+	int dy = bottom - top;
+	int dx = right - left;
+	int stepy = dy < 0 ? -1 : 1;
+	int stepx = dx < 0 ? -1 : 1;
+	dy = ABS(dy) << 1;
+	dx = ABS(dx) << 1;
+
+	// setting the 1st and last pixel
+	putPixel(left, top, drawMask, color, priority, control);
+	putPixel(right, bottom, drawMask, color, priority, control);
+	// drawing the line
+	if (dx > dy) { // going horizontal
+		int fraction = dy - (dx >> 1);
+		while (left != right) {
+			if (fraction >= 0) {
+				top += stepy;
+				fraction -= dx;
+			}
+			left += stepx;
+			fraction += dy;
+			putPixel(left, top, drawMask, color, priority, control);
+		}
+	} else { // going vertical
+		int fraction = dx - (dy >> 1);
+		while (top != bottom) {
+			if (fraction >= 0) {
+				left += stepx;
+				fraction -= dy;
+			}
+			top += stepy;
+			fraction += dx;
+			putPixel(left, top, drawMask, color, priority, control);
+		}
+	}
+}
+
 byte SciGuiScreen::getVisual(int x, int y) {
 	return _visualScreen[_baseTable[y] + x];
 }

Modified: scummvm/trunk/engines/sci/gui/gui_screen.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_screen.h	2009-10-12 07:30:55 UTC (rev 44968)
+++ scummvm/trunk/engines/sci/gui/gui_screen.h	2009-10-12 08:25:38 UTC (rev 44969)
@@ -50,6 +50,10 @@
 
 	byte getDrawingMask(byte color, byte prio, byte control);
 	void putPixel(int x, int y, byte drawMask, byte color, byte prio, byte control);
+	void drawLine(Common::Point startPoint, Common::Point endPoint, byte color, byte prio, byte control);
+	void drawLine(int16 left, int16 top, int16 right, int16 bottom, byte color, byte prio, byte control) {
+		drawLine(Common::Point(left, top), Common::Point(right, bottom), color, prio, control);
+	}
 	byte getVisual(int x, int y);
 	byte getPriority(int x, int y);
 	byte getControl(int x, int y);


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