diff options
Diffstat (limited to 'engines/adl')
-rw-r--r-- | engines/adl/display.cpp | 3 | ||||
-rw-r--r-- | engines/adl/graphics.cpp | 112 | ||||
-rw-r--r-- | engines/adl/graphics.h | 19 | ||||
-rw-r--r-- | engines/adl/hires5.cpp | 2 |
4 files changed, 96 insertions, 40 deletions
diff --git a/engines/adl/display.cpp b/engines/adl/display.cpp index feef8fb2a4..e18de6adae 100644 --- a/engines/adl/display.cpp +++ b/engines/adl/display.cpp @@ -330,6 +330,9 @@ void Display::showCursor(bool enable) { } void Display::writeFrameBuffer(const Common::Point &p, byte color, byte mask) { + if (p.x >= DISPLAY_WIDTH || p.y >= DISPLAY_HEIGHT) + return; + byte *b = _frameBuf + p.y * DISPLAY_PITCH + p.x / 7; color ^= *b; color &= mask; diff --git a/engines/adl/graphics.cpp b/engines/adl/graphics.cpp index f550f3a177..47ef5744fa 100644 --- a/engines/adl/graphics.cpp +++ b/engines/adl/graphics.cpp @@ -303,39 +303,57 @@ static byte getPatternColor(const Common::Point &p, byte pattern) { return fillPatterns[pattern][offset % PATTERN_LEN]; } -void Graphics_v2::fillRow(const Common::Point &p, bool stopBit, byte pattern) { - const byte color = getPatternColor(p, pattern); - _display.setPixelPalette(p, color); - _display.setPixelBit(p, color); +bool Graphics_v2::canFillAt(const Common::Point &p, const bool stopBit) { + return _display.getPixelBit(p) != stopBit && _display.getPixelBit(Common::Point(p.x + 1, p.y)) != stopBit; +} - Common::Point q(p); - byte c = color; +void Graphics_v2::fillRowLeft(Common::Point p, const byte pattern, const bool stopBit) { + byte color = getPatternColor(p, pattern); - while (++q.x < DISPLAY_WIDTH) { - if ((q.x % 7) == 0) { - c = getPatternColor(q, pattern); - // Palette is set before the first bit is tested - _display.setPixelPalette(q, c); + while (--p.x >= 0) { + if ((p.x % 7) == 6) { + color = getPatternColor(p, pattern); + _display.setPixelPalette(p, color); } - if (_display.getPixelBit(q) == stopBit) + if (_display.getPixelBit(p) == stopBit) break; - _display.setPixelBit(q, c); + _display.setPixelBit(p, color); } +} + +void Graphics_v2::fillRow(Common::Point p, const byte pattern, const bool stopBit) { + // Set pixel at p and palette + byte color = getPatternColor(p, pattern); + _display.setPixelPalette(p, color); + _display.setPixelBit(p, color); - q = p; - c = color; - while (--q.x >= 0) { - if ((q.x % 7) == 6) { - c = getPatternColor(q, pattern); - _display.setPixelPalette(q, c); + // Fill left of p + fillRowLeft(p, pattern, stopBit); + + // Fill right of p + while (++p.x < DISPLAY_WIDTH) { + if ((p.x % 7) == 0) { + color = getPatternColor(p, pattern); + // Palette is set before the first bit is tested + _display.setPixelPalette(p, color); } - if (_display.getPixelBit(q) == stopBit) + if (_display.getPixelBit(p) == stopBit) break; - _display.setPixelBit(q, c); + _display.setPixelBit(p, color); } } -// Basic flood fill +void Graphics_v2::fillAt(Common::Point p, const byte pattern) { + const bool stopBit = !_display.getPixelBit(p); + + // Move up into the open space above p + while (--p.y >= 0 && canFillAt(p, stopBit)); + + // Then fill by moving down + while (++p.y < DISPLAY_HEIGHT && canFillAt(p, stopBit)) + fillRow(p, pattern, stopBit); +} + void Graphics_v2::fill(Common::SeekableReadStream &pic) { byte pattern; READ_BYTE(pattern); @@ -344,22 +362,7 @@ void Graphics_v2::fill(Common::SeekableReadStream &pic) { Common::Point p; READ_POINT(p); - bool stopBit = !_display.getPixelBit(p); - - while (--p.y >= 0) { - if (_display.getPixelBit(p) == stopBit) - break; - if (_display.getPixelBit(Common::Point(p.x + 1, p.y)) == stopBit) - break; - } - - while (++p.y < DISPLAY_HEIGHT) { - if (_display.getPixelBit(p) == stopBit) - break; - if (_display.getPixelBit(Common::Point(p.x + 1, p.y)) == stopBit) - break; - fillRow(p, stopBit, pattern); - } + fillAt(p, pattern); } } @@ -424,4 +427,37 @@ void Graphics_v2::drawPic(Common::SeekableReadStream &pic, const Common::Point & } } +void Graphics_v3::fillRowLeft(Common::Point p, const byte pattern, const bool stopBit) { + byte color = getPatternColor(p, pattern); + + while (--p.x >= 0) { + // In this version, when moving left, it no longer sets the palette first + if (!_display.getPixelBit(p)) + return; + if ((p.x % 7) == 6) { + color = getPatternColor(p, pattern); + _display.setPixelPalette(p, color); + } + _display.setPixelBit(p, color); + } +} + +void Graphics_v3::fillAt(Common::Point p, const byte pattern) { + // If the row at p cannot be filled, we do nothing + if (!canFillAt(p)) + return; + + fillRow(p, pattern); + + Common::Point q(p); + + // Fill up from p + while (--q.y >= 0 && canFillAt(q)) + fillRow(q, pattern); + + // Fill down from p + while (++p.y < DISPLAY_HEIGHT && canFillAt(p)) + fillRow(p, pattern); +} + } // End of namespace Adl diff --git a/engines/adl/graphics.h b/engines/adl/graphics.h index aab807696c..af34e80113 100644 --- a/engines/adl/graphics.h +++ b/engines/adl/graphics.h @@ -44,6 +44,7 @@ protected: Display &_display; }; +// Used in hires1 class Graphics_v1 : public GraphicsMan { public: Graphics_v1(Display &display) : GraphicsMan(display) { } @@ -54,23 +55,39 @@ private: void drawCornerPixel(Common::Point &p, byte color, byte bits, byte quadrant) const; }; +// Used in hires0 and hires2-hires4 class Graphics_v2 : public GraphicsMan { public: Graphics_v2(Display &display) : GraphicsMan(display), _color(0) { } void drawPic(Common::SeekableReadStream &pic, const Common::Point &pos); +protected: + bool canFillAt(const Common::Point &p, const bool stopBit = false); + void fillRow(Common::Point p, const byte pattern, const bool stopBit = false); + private: void clear(); void drawCorners(Common::SeekableReadStream &pic, bool yFirst); void drawRelativeLines(Common::SeekableReadStream &pic); void drawAbsoluteLines(Common::SeekableReadStream &pic); - void fillRow(const Common::Point &p, bool fillBit, byte pattern); + virtual void fillRowLeft(Common::Point p, const byte pattern, const bool stopBit); + virtual void fillAt(Common::Point p, const byte pattern); void fill(Common::SeekableReadStream &pic); byte _color; Common::Point _offset; }; +// Used in hires5, hires6 and gelfling (possibly others as well) +class Graphics_v3 : public Graphics_v2 { +public: + Graphics_v3(Display &display) : Graphics_v2(display) { } + +private: + void fillRowLeft(Common::Point p, const byte pattern, const bool stopBit); + void fillAt(Common::Point p, const byte pattern); +}; + } // End of namespace Adl #endif diff --git a/engines/adl/hires5.cpp b/engines/adl/hires5.cpp index 4bf65ab822..a1af394b3a 100644 --- a/engines/adl/hires5.cpp +++ b/engines/adl/hires5.cpp @@ -325,7 +325,7 @@ void HiRes5Engine::runIntro() { } void HiRes5Engine::init() { - _graphics = new Graphics_v2(*_display); + _graphics = new Graphics_v3(*_display); insertDisk(2); |