diff options
author | Filippos Karapetis | 2009-10-12 08:25:38 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-10-12 08:25:38 +0000 |
commit | ebb188c415bac4dfc2bfbcd2b7f7236365e0247d (patch) | |
tree | 43b6686b17c8dcceac74f10e40e0494fcad35fa2 /engines/sci/gui | |
parent | 713f573735b483fffd5da9f7469be3f72faf97e7 (diff) | |
download | scummvm-rg350-ebb188c415bac4dfc2bfbcd2b7f7236365e0247d.tar.gz scummvm-rg350-ebb188c415bac4dfc2bfbcd2b7f7236365e0247d.tar.bz2 scummvm-rg350-ebb188c415bac4dfc2bfbcd2b7f7236365e0247d.zip |
Move the line drawing code to SciGuiScreen()
svn-id: r44969
Diffstat (limited to 'engines/sci/gui')
-rw-r--r-- | engines/sci/gui/gui.cpp | 3 | ||||
-rw-r--r-- | engines/sci/gui/gui_gfx.cpp | 72 | ||||
-rw-r--r-- | engines/sci/gui/gui_gfx.h | 2 | ||||
-rw-r--r-- | engines/sci/gui/gui_picture.cpp | 15 | ||||
-rw-r--r-- | engines/sci/gui/gui_screen.cpp | 64 | ||||
-rw-r--r-- | engines/sci/gui/gui_screen.h | 4 |
6 files changed, 90 insertions, 70 deletions
diff --git a/engines/sci/gui/gui.cpp b/engines/sci/gui/gui.cpp index 24a1ecb03d..915c52cc76 100644 --- a/engines/sci/gui/gui.cpp +++ b/engines/sci/gui/gui.cpp @@ -418,7 +418,8 @@ void SciGui::graphFillBox(Common::Rect rect, uint16 colorMask, int16 color, int1 } 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) { diff --git a/engines/sci/gui/gui_gfx.cpp b/engines/sci/gui/gui_gfx.cpp index e061e09eea..89f3ebed37 100644 --- a/engines/sci/gui/gui_gfx.cpp +++ b/engines/sci/gui/gui_gfx.cpp @@ -253,6 +253,13 @@ void SciGuiGfx::OffsetRect(Common::Rect &r) { 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 @@ void SciGuiGfx::BitsFree(GuiMemoryHandle memoryHandle) { } } -// 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; diff --git a/engines/sci/gui/gui_gfx.h b/engines/sci/gui/gui_gfx.h index 24e143128c..0290f46534 100644 --- a/engines/sci/gui/gui_gfx.h +++ b/engines/sci/gui/gui_gfx.h @@ -84,6 +84,7 @@ public: 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 @@ public: 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); diff --git a/engines/sci/gui/gui_picture.cpp b/engines/sci/gui/gui_picture.cpp index cc3dda3e69..6978c4c7c6 100644 --- a/engines/sci/gui/gui_picture.cpp +++ b/engines/sci/gui/gui_picture.cpp @@ -357,7 +357,10 @@ void SciGuiPicture::drawVectorData(byte *data, int dataSize) { 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 @@ void SciGuiPicture::drawVectorData(byte *data, int dataSize) { 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 @@ void SciGuiPicture::drawVectorData(byte *data, int dataSize) { 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; diff --git a/engines/sci/gui/gui_screen.cpp b/engines/sci/gui/gui_screen.cpp index 18d5793606..28f3cbc25f 100644 --- a/engines/sci/gui/gui_screen.cpp +++ b/engines/sci/gui/gui_screen.cpp @@ -102,6 +102,70 @@ void SciGuiScreen::putPixel(int x, int y, byte drawMask, byte color, byte priori *(_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]; } diff --git a/engines/sci/gui/gui_screen.h b/engines/sci/gui/gui_screen.h index 6b2a5b5ca7..6ab6b03288 100644 --- a/engines/sci/gui/gui_screen.h +++ b/engines/sci/gui/gui_screen.h @@ -50,6 +50,10 @@ public: 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); |