[Scummvm-cvs-logs] SF.net SVN: scummvm:[44720] scummvm/trunk/engines/sci/gui
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Tue Oct 6 23:23:24 CEST 2009
Revision: 44720
http://scummvm.svn.sourceforge.net/scummvm/?rev=44720&view=rev
Author: thebluegr
Date: 2009-10-06 21:23:24 +0000 (Tue, 06 Oct 2009)
Log Message:
-----------
Reverted #44697 (line drawing in the new GUI), with some function renaming. Apparently, Sierra's implementation of the Bresenham line drawing algorithm was a bit different than ours, which resulted in problems with flood fill
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
Modified: scummvm/trunk/engines/sci/gui/gui.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui.cpp 2009-10-06 21:20:32 UTC (rev 44719)
+++ scummvm/trunk/engines/sci/gui/gui.cpp 2009-10-06 21:23:24 UTC (rev 44720)
@@ -335,7 +335,7 @@
}
void SciGui::graphDrawLine(Common::Point startPoint, Common::Point endPoint, int16 color, int16 priority, int16 control) {
- _gfx->Draw_Line(startPoint.x, startPoint.y, endPoint.x, endPoint.y, color, priority, control);
+ _gfx->drawLine(startPoint.x, startPoint.y, endPoint.x, endPoint.y, color, priority, control);
_screen->copyToScreen();
}
Modified: scummvm/trunk/engines/sci/gui/gui_gfx.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_gfx.cpp 2009-10-06 21:20:32 UTC (rev 44719)
+++ scummvm/trunk/engines/sci/gui/gui_gfx.cpp 2009-10-06 21:23:24 UTC (rev 44720)
@@ -616,20 +616,9 @@
}
}
-// Data passed to drawProc()
-struct LineData {
- byte drawMask;
- byte prio;
- byte control;
- SciGuiScreen *screen;
-};
-
-static void drawProc(int x, int y, int c, void *data) {
- LineData *lineData = (LineData *)data;
- lineData->screen->putPixel(x, y, lineData->drawMask, (byte)c, lineData->prio, lineData->control);
-}
-
-void SciGuiGfx::Draw_Line(int16 left, int16 top, int16 right, int16 bottom, byte color, byte priority, byte 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 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);
@@ -639,13 +628,59 @@
top += _curPort->top;
bottom += _curPort->top;
- LineData lineData;
- lineData.drawMask = drawMask;
- lineData.prio = priority;
- lineData.control = control;
- lineData.screen = _screen;
+ // 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;
- Graphics::drawLine(left, top, right, bottom, color, drawProc, &lineData);
+ // 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);
+ }
+ }
+ //g_sci->eventMgr->waitUntil(5);
+ //ShowBits(&_rThePort->rect,6);
}
// Bitmap for drawing sierra circles
Modified: scummvm/trunk/engines/sci/gui/gui_gfx.h
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_gfx.h 2009-10-06 21:20:32 UTC (rev 44719)
+++ scummvm/trunk/engines/sci/gui/gui_gfx.h 2009-10-06 21:23:24 UTC (rev 44720)
@@ -92,7 +92,7 @@
GuiMemoryHandle SaveBits(const Common::Rect &rect, byte screenFlags);
void RestoreBits(GuiMemoryHandle memoryHandle);
- void Draw_Line(int16 left, int16 top, int16 right, int16 bottom, byte color, byte prio, byte control);
+ void drawLine(int16 left, int16 top, int16 right, int16 bottom, byte color, byte prio, byte control);
void Draw_Box(Common::Rect box, byte color, byte prio, byte control);
void Draw_TexturedBox(Common::Rect box, byte color, byte prio, byte control, byte texture);
void Draw_Circle(Common::Rect box, byte size, byte color, byte prio, byte control);
Modified: scummvm/trunk/engines/sci/gui/gui_picture.cpp
===================================================================
--- scummvm/trunk/engines/sci/gui/gui_picture.cpp 2009-10-06 21:20:32 UTC (rev 44719)
+++ scummvm/trunk/engines/sci/gui/gui_picture.cpp 2009-10-06 21:23:24 UTC (rev 44720)
@@ -352,7 +352,7 @@
while (vectorIsNonOpcode(data[curPos])) {
oldx = x; oldy = y;
vectorGetRelCoords(data, curPos, x, y);
- _gfx->Draw_Line(oldx, oldy, x, y, pic_color, pic_priority, pic_control);
+ _gfx->drawLine(oldx, oldy, x, y, pic_color, pic_priority, pic_control);
}
break;
case PIC_OP_MEDIUM_LINES: // medium line
@@ -360,7 +360,7 @@
while (vectorIsNonOpcode(data[curPos])) {
oldx = x; oldy = y;
vectorGetRelCoordsMed(data, curPos, x, y);
- _gfx->Draw_Line(oldx, oldy, x, y, pic_color, pic_priority, pic_control);
+ _gfx->drawLine(oldx, oldy, x, y, pic_color, pic_priority, pic_control);
}
break;
case PIC_OP_LONG_LINES: // long line
@@ -368,7 +368,7 @@
while (vectorIsNonOpcode(data[curPos])) {
oldx = x; oldy = y;
vectorGetAbsCoords(data, curPos, x, y);
- _gfx->Draw_Line(oldx, oldy, x, y, pic_color, pic_priority, pic_control);
+ _gfx->drawLine(oldx, oldy, x, y, pic_color, pic_priority, pic_control);
}
break;
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