From 8d228219c9121b0152fbf1f1fcab6a477574e9a2 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 25 Nov 2007 10:27:50 +0000 Subject: Switch to our common drawLine routine svn-id: r29635 --- engines/scumm/he/wiz_he.cpp | 73 +++++++++++++-------------------------------- engines/touche/graphics.cpp | 56 +++++----------------------------- engines/touche/graphics.h | 12 +++++++- engines/touche/menu.cpp | 9 +++++- 4 files changed, 47 insertions(+), 103 deletions(-) diff --git a/engines/scumm/he/wiz_he.cpp b/engines/scumm/he/wiz_he.cpp index e4e93232dc..164cfef7f8 100644 --- a/engines/scumm/he/wiz_he.cpp +++ b/engines/scumm/he/wiz_he.cpp @@ -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 @@ void Wiz::fillWizRect(const WizParameters *params) { _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 @@ void Wiz::fillWizLine(const WizParameters *params) { 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; - } - - dx = ABS(x2 - x1); - dy = ABS(y2 - y1); + drawProcP lineP; - if (imageRect.contains(x1, y1)) { - *(wizd + y1 * w + x1) = color; - } + lineP.imageRect = &imageRect; + lineP.wizd = wizd; + lineP.width = w; - 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); } } } diff --git a/engines/touche/graphics.cpp b/engines/touche/graphics.cpp index cb5f60a4c9..13619eebd1 100644 --- a/engines/touche/graphics.cpp +++ b/engines/touche/graphics.cpp @@ -24,6 +24,7 @@ */ #include "common/endian.h" +#include "graphics/primitives.h" #include "touche/graphics.h" @@ -128,56 +129,15 @@ void Graphics::drawRect(uint8 *dst, int dstPitch, int x, int y, int w, int h, ui 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); -} - -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); - - 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; - } + drawProcP lineP; - int step = 0; + lineP.dst = dst; + lineP.width = dstPitch; - 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) { diff --git a/engines/touche/graphics.h b/engines/touche/graphics.h index 6b4072d896..74928cefcf 100644 --- a/engines/touche/graphics.h +++ b/engines/touche/graphics.h @@ -30,6 +30,11 @@ namespace Touche { +struct drawProcP { + uint8 *dst; + int width; +}; + class Graphics { public: @@ -44,10 +49,15 @@ public: 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 */ diff --git a/engines/touche/menu.cpp b/engines/touche/menu.cpp index 2dacab4132..1c3dfe87ee 100644 --- a/engines/touche/menu.cpp +++ b/engines/touche/menu.cpp @@ -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 @@ static void drawArrow(uint8 *dst, int dstPitch, int x, int y, int delta, uint8 c { -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); } } -- cgit v1.2.3