Skip to content

Commit

Permalink
WAGE: Made ellipse drawing generic
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Dec 27, 2015
1 parent b054e82 commit f483bc0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
31 changes: 19 additions & 12 deletions engines/wage/design.cpp
Expand Up @@ -321,7 +321,6 @@ void Design::drawBitmap(Graphics::Surface *surface, Common::ReadStream &in, bool

}
}

}
}

Expand Down Expand Up @@ -393,14 +392,22 @@ void Design::drawOval(Graphics::Surface *surface, Common::ReadStream &in, bool m
int16 y2 = in.readSint16BE();
int16 x2 = in.readSint16BE();

plotEllipseRect(surface, patterns, x1, y1, x2, y2, borderFillType);
plotEllipseRect(surface, patterns, x1+borderThickness, y1+borderThickness, x2-2*borderThickness, y2-2*borderThickness, fillType);
plotData pd;

pd.surface = surface;
pd.patterns = &patterns;
pd.fillType = borderFillType;
pd.x0 = x1;
pd.y0 = y1;

drawFilledEllipse(x1, y1, x2, y2, drawPixel, &pd);

pd.fillType = fillType;
drawFilledEllipse(x1+borderThickness, y1+borderThickness, x2-2*borderThickness, y2-2*borderThickness, drawPixel, &pd);
}


void Design::plotEllipseRect(Graphics::Surface *surface, Patterns &patterns,
int x0, int y0, int x1, int y1, byte fillType) {
int xO = x0, yO = y0;
void Design::drawFilledEllipse(int x0, int y0, int x1, int y1, void (*plotProc)(int, int, int, void *), void *data) {
int a = abs(x1-x0), b = abs(y1-y0), b1 = b&1; /* values of diameter */
long dx = 4*(1-a)*b*b, dy = 4*(b1+1)*a*a; /* error increment */
long err = dx+dy+b1*a*a, e2; /* error of 1.step */
Expand All @@ -411,19 +418,19 @@ void Design::plotEllipseRect(Graphics::Surface *surface, Patterns &patterns,
a *= 8*a; b1 = 8*b*b;

do {
patternHLine(surface, patterns, fillType, x0, x1 + 1, y0, xO, yO);
patternHLine(surface, patterns, fillType, x0, x1 + 1, y1, xO, yO);
drawHLine(x0, x1 + 1, y0, kColorBlack, plotProc, data);
drawHLine(x0, x1 + 1, y1, kColorBlack, plotProc, data);
e2 = 2*err;
if (e2 <= dy) { y0++; y1--; err += dy += a; } /* y step */
if (e2 >= dx || 2*err > dy) { x0++; x1--; err += dx += b1; } /* x step */
} while (x0 <= x1);

while (y0-y1 < b) { /* too early stop of flat ellipses a=1 */
patternHLine(surface, patterns, fillType, x0-1, x0-1, y0, xO, yO); /* -> finish tip of ellipse */
patternHLine(surface, patterns, fillType, x1+1, x1+1, y0, xO, yO);
drawHLine(x0-1, x0-1, y0, kColorBlack, plotProc, data); /* -> finish tip of ellipse */
drawHLine(x1+1, x1+1, y0, kColorBlack, plotProc, data);
y0++;
patternHLine(surface, patterns, fillType, x0-1, x0-1, y1, xO, yO);
patternHLine(surface, patterns, fillType, x1+1, x1+1, y1, xO, yO);
drawHLine(x0-1, x0-1, y1, kColorBlack, plotProc, data);
drawHLine(x1+1, x1+1, y1, kColorBlack, plotProc, data);
y1--;
}
}
Expand Down
3 changes: 1 addition & 2 deletions engines/wage/design.h
Expand Up @@ -96,8 +96,7 @@ class Design {
void patternRect(Graphics::Surface *surface, Patterns &patterns, Common::Rect &rect, byte fillType);
void drawPolygonScan(int *polyX, int *polyY, int npoints, Common::Rect &bbox, int color,
void (*plotProc)(int, int, int, void *), void *data);
void plotEllipseRect(Graphics::Surface *surface, Patterns &patterns,
int x0, int y0, int x1, int y1, byte fillType);
void drawFilledEllipse(int x0, int y0, int x1, int y1, void (*plotProc)(int, int, int, void *), void *data);
void drawHLine(int x1, int x2, int y, int color, void (*plotProc)(int, int, int, void *), void *data);
void patternHLine(Graphics::Surface *surface, Patterns &patterns, byte fillType, int x1, int x2, int y, int x0, int y0);
void patternVLine(Graphics::Surface *surface, Patterns &patterns, byte fillType, int x, int y1, int y2, int x0, int y0);
Expand Down

0 comments on commit f483bc0

Please sign in to comment.