diff --git a/engines/wage/design.cpp b/engines/wage/design.cpp index 4fbd2e366f0a..59cf80f15bdb 100644 --- a/engines/wage/design.cpp +++ b/engines/wage/design.cpp @@ -48,15 +48,14 @@ #include "wage/wage.h" #include "wage/design.h" -#include "common/stream.h" -#include "common/memstream.h" - namespace Wage { Design::Design(Common::SeekableReadStream *data) { _len = data->readUint16BE() - 2; _data = (byte *)malloc(_len); data->read(_data, _len); + + paint(0, 0, false); } Design::~Design() { @@ -68,7 +67,7 @@ void Design::paint(Graphics::Surface *canvas, TexturePaint *patterns, bool mask) if (mask) { //canvas.setColor(Color.WHITE); - canvas->fillRect(Common::Rect(0, 0, _bounds->width(), _bounds->height()), 0xff); + canvas->fillRect(Common::Rect(0, 0, _bounds->width(), _bounds->height()), kColorWhite); //canvas.setColor(Color.BLACK); } @@ -88,10 +87,12 @@ void Design::paint(Graphics::Surface *canvas, TexturePaint *patterns, bool mask) case 12: drawOval(canvas, in, mask, patterns, fillType, borderThickness, borderFillType); break; +*/ case 16: case 20: drawPolygon(canvas, in, mask, patterns, fillType, borderThickness, borderFillType); break; +/* case 24: drawBitmap(canvas, in, mask); break; @@ -103,5 +104,104 @@ void Design::paint(Graphics::Surface *canvas, TexturePaint *patterns, bool mask) } } +void Design::drawPolygon(Graphics::Surface *surface, Common::ReadStream &in, bool mask, + TexturePaint *patterns, byte fillType, byte borderThickness, byte borderFillType) { + //surface->setColor(Color.BLACK); + //in.readUint16BE(); + warning("ignored => %d", in.readSint16BE()); + int numBytes = in.readSint16BE(); // #bytes used by polygon data, including the numBytes + warning("Num bytes is %d", numBytes); + // Ignoring these values works!!! + //in.readUint16BE(); in.readUint16BE(); in.readUint16BE(); in.readUint16BE(); + warning("Ignoring: %d", in.readSint16BE()); + warning("Ignoring: %d", in.readSint16BE()); + warning("Ignoring: %d", in.readSint16BE()); + warning("Ignoring: %d", in.readSint16BE()); + + numBytes -= 8; + + int y1 = in.readSint16BE(); + int x1 = in.readSint16BE(); + + Common::Array xcoords; + Common::Array ycoords; + + warning("Start point is (%d,%d)", x1, y1); + numBytes -= 6; + + while (numBytes > 0) { + int y2 = y1; + int x2 = x1; + int b = in.readSByte(); + warning("YB = %x", b); + if (b == (byte)0x80) { + y2 = in.readSint16BE(); + numBytes -= 3; + } else { + warning("Y"); + y2 += b; + numBytes -= 1; + } + b = in.readSByte(); + warning("XB = %x", b); + if (b == (byte) 0x80) { + x2 = in.readSint16BE(); + numBytes -= 3; + } else { + warning("X"); + x2 += b; + numBytes -= 1; + } + //surface->setColor(colors[c++]); + //surface->setColor(Color.black); + xcoords.push_back(x1); + ycoords.push_back(y1); + warning("%d %d %d %d", x1, y1, x2, y2); + //surface->drawLine(x1, y1, x2, y2); + x1 = x2; + y1 = y2; + } + xcoords.push_back(x1); + ycoords.push_back(y1); + + int npoints = xcoords.size(); + int *xpoints = (int *)calloc(npoints, sizeof(int)); + int *ypoints = (int *)calloc(npoints, sizeof(int)); + for (int i = 0; i < npoints; i++) { + xpoints[i] = xcoords[i]; + ypoints[i] = ycoords[i]; + } + // warning(fillType); +/* + if (mask) { + surface->fillPolygon(xpoints, ypoints, npoints); + if (borderThickness > 0) { + Stroke oldStroke = surface->getStroke(); + surface->setStroke(new BasicStroke(borderThickness - 0.5f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)); + for (int i = 1; i < npoints; i++) + surface->drawLine(xpoints[i-1], ypoints[i-1], xpoints[i], ypoints[i]); + surface->setStroke(oldStroke); + } + return; + } + if (setPattern(g2d, patterns, fillType - 1)) { + surface->fillPolygon(xpoints, ypoints, npoints); + } + // warning(borderFillType); + //surface->setColor(Color.black); + //if (1==0) + if (borderThickness > 0 && setPattern(g2d, patterns, borderFillType - 1)) { + Stroke oldStroke = surface->getStroke(); + //if (borderThickness != 1) + surface->setStroke(new BasicStroke(borderThickness - 0.5f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)); + for (int i = 1; i < npoints; i++) + surface->drawLine(xpoints[i-1], ypoints[i-1], xpoints[i], ypoints[i]); + surface->setStroke(oldStroke); + } +*/ + free(xpoints); + free(ypoints); +} + } // End of namespace Wage diff --git a/engines/wage/design.h b/engines/wage/design.h index a0315b588019..beb5c894274b 100644 --- a/engines/wage/design.h +++ b/engines/wage/design.h @@ -49,12 +49,18 @@ #define WAGE_DESIGN_H #include "graphics/surface.h" +#include "common/memstream.h" #include "common/rect.h" namespace Wage { struct TexturePaint; +enum { + kColorWhite = 0xff, + kColorBlack = 0x0 +}; + class Design { public: Design(Common::SeekableReadStream *data); @@ -74,6 +80,11 @@ class Design { byte *_data; int _len; Common::Rect *_bounds; + +private: + void drawPolygon(Graphics::Surface *surface, Common::ReadStream &in, bool mask, + TexturePaint *patterns, byte fillType, byte borderThickness, byte borderFillType); + }; } // End of namespace Wage