Skip to content

Commit

Permalink
WAGE: First stub for rounded rectangles
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Dec 27, 2015
1 parent 7e23caa commit 0d6b726
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
67 changes: 62 additions & 5 deletions engines/wage/design.cpp
Expand Up @@ -89,11 +89,9 @@ void Design::paint(Graphics::Surface *canvas, Patterns &patterns, bool mask) {
case 4:
drawRect(canvas, in, mask, patterns, fillType, borderThickness, borderFillType);
break;
/*
case 8:
drawRoundRect(canvas, in, mask, patterns, fillType, borderThickness, borderFillType);
break;
*/
case 12:
drawOval(canvas, in, mask, patterns, fillType, borderThickness, borderFillType);
break;
Expand Down Expand Up @@ -123,13 +121,15 @@ void Design::paint(Graphics::Surface *canvas, Patterns &patterns, bool mask) {
void drawPixel(int x, int y, int color, void *data) {
plotData *p = (plotData *)data;

if (p->fillType > (*p->patterns).size())
if (p->fillType > p->patterns->size())
return;

if (x >= 0 && x < p->surface->w && y >= 0 && y < p->surface->h)
if (x >= 0 && x < p->surface->w && y >= 0 && y < p->surface->h) {
byte *pat = p->patterns->operator[](p->fillType - 1);
*((byte *)p->surface->getBasePtr(x, y)) =
((*p->patterns)[p->fillType - 1][(y - p->y0) % 8] & (1 << (7 - (x - p->x0) % 8))) ?
(pat[(y - p->y0) % 8] & (1 << (7 - (x - p->x0) % 8))) ?
color : kColorWhite;
}
}

void drawPixelPlain(int x, int y, int color, void *data) {
Expand Down Expand Up @@ -162,6 +162,36 @@ void Design::drawRect(Graphics::Surface *surface, Common::ReadStream &in, bool m
drawFilledRect(inner, kColorBlack, drawPixel, &pd);
}

void Design::drawRoundRect(Graphics::Surface *surface, Common::ReadStream &in, bool mask,
Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
int16 y1 = in.readSint16BE();
int16 x1 = in.readSint16BE();
int16 y2 = in.readSint16BE();
int16 x2 = in.readSint16BE();
int16 arc = in.readSint16BE();
Common::Rect outer(x1, y1, x2, y2);

plotData pd(surface, &patterns, borderFillType, x1, y1);

if (mask) {
drawFilledRoundRect(outer, arc, kColorBlack, drawPixelPlain, &pd);
return;
}
Common::Rect inner(x1 + borderThickness, y1 + borderThickness, x2 - borderThickness, y2 - borderThickness);

//drawFilledRoundRect(outer, arc, kColorBlack, drawPixel, &pd);

pd.fillType = fillType;

//drawFilledRoundRect(inner, arc, kColorBlack, drawPixel, &pd);


Common::Rect inn(50, 50, 400, 400);
pd.fillType = 8;
drawFilledRect(inn, kColorBlack, drawPixel, &pd);
//drawFilledRoundRect(inn, arc, kColorBlack, drawPixel, &pd);
}

void Design::drawPolygon(Graphics::Surface *surface, Common::ReadStream &in, bool mask,
Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {

Expand Down Expand Up @@ -323,6 +353,33 @@ void Design::drawFilledRect(Common::Rect &rect, int color, void (*plotProc)(int,
drawHLine(rect.left, rect.right, y, color, plotProc, data);
}

// http://members.chello.at/easyfilter/bresenham.html
void Design::drawFilledRoundRect(Common::Rect &rect, int arc, int color, void (*plotProc)(int, int, int, void *), void *data) {
//drawFilledRect(rect, color, plotProc, data);
//return;
int x = -arc, y = 0, err = 2-2*arc; /* II. Quadrant */
int dx = rect.width() - arc * 2;
int dy = rect.height() - arc * 2;

do {
//drawHLine(rect.left, rect.right, y, color, plotProc, data);

//drawPixelPlain(rect.left-x, rect.top-y, color, data); /* I. Quadrant */
//drawPixelPlain(rect.left+x, rect.top-y, color, data); /* II. Quadrant */
drawHLine(rect.left+x, rect.right-x, rect.top-y, color, drawPixelPlain, data);
drawHLine(rect.left+x, rect.right-x, rect.top+y+dy, color, drawPixelPlain, data);
//drawPixelPlain(rect.left-y, rect.top-x, color, data); /* II. Quadrant */
//drawPixelPlain(rect.left+x, rect.top-y, color, data); /* III. Quadrant */
//drawPixelPlain(rect.left+y, rect.top+x, color, data); /* IV. Quadrant */
arc = err;
if (arc <= y) err += ++y*2+1; /* e_xy+e_y < 0 */
if (arc > x || err > y) err += ++x*2+1; /* e_xy+e_x > 0 or no 2nd y-step */
} while (x < 0);


for (int i = 0; i < dy; i++)
drawHLine(rect.left, rect.right, rect.top + arc + i, color, drawPixelPlain, data);
}

// Based on public-domain code by Darel Rex Finley, 2007
// http://alienryderflex.com/polygon_fill/
Expand Down
3 changes: 3 additions & 0 deletions engines/wage/design.h
Expand Up @@ -82,6 +82,8 @@ class Design {

private:
void drawRect(Graphics::Surface *surface, Common::ReadStream &in, bool mask,
Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
void drawRoundRect(Graphics::Surface *surface, Common::ReadStream &in, bool mask,
Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
void drawPolygon(Graphics::Surface *surface, Common::ReadStream &in, bool mask,
Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
Expand All @@ -90,6 +92,7 @@ class Design {
void drawBitmap(Graphics::Surface *surface, Common::ReadStream &in, bool mask);

void drawFilledRect(Common::Rect &rect, int color, void (*plotProc)(int, int, int, void *), void *data);
void drawFilledRoundRect(Common::Rect &rect, int arc, int color, void (*plotProc)(int, int, int, void *), void *data);
void drawPolygonScan(int *polyX, int *polyY, int npoints, Common::Rect &bbox, int color,
void (*plotProc)(int, int, int, void *), void *data);
void drawFilledEllipse(int x0, int y0, int x1, int y1, void (*plotProc)(int, int, int, void *), void *data);
Expand Down
8 changes: 6 additions & 2 deletions engines/wage/wage.cpp
Expand Up @@ -108,8 +108,12 @@ Common::Error WageEngine::run() {
Graphics::Surface screen;
screen.create(640, 480, Graphics::PixelFormat::createFormatCLUT8());
Common::Rect r(0, 0, screen.w, screen.h);
_world->_scenes["entry"]->_design->setBounds(&r);
_world->_scenes["entry"]->_design->paint(&screen, _world->_patterns, false);
//_world->_objs["frank.1"]->_design->setBounds(&r);
//_world->_objs["frank.1"]->_design->paint(&screen, _world->_patterns, false);
//_world->_scenes["temple of the holy mackeral"]->_design->setBounds(&r);
//_world->_scenes["temple of the holy mackeral"]->_design->paint(&screen, _world->_patterns, false);
_world->_scenes["tower level 3"]->_design->setBounds(&r);
_world->_scenes["tower level 3"]->_design->paint(&screen, _world->_patterns, false);

return Common::kNoError;
}
Expand Down

0 comments on commit 0d6b726

Please sign in to comment.