Move the line drawing code to SciGuiScreen()

svn-id: r44969
This commit is contained in:
Filippos Karapetis 2009-10-12 08:25:38 +00:00
parent 713f573735
commit ebb188c415
6 changed files with 90 additions and 70 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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];
}

View File

@ -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);