diff options
Diffstat (limited to 'engines/sherlock/surface.cpp')
| -rw-r--r-- | engines/sherlock/surface.cpp | 103 |
1 files changed, 55 insertions, 48 deletions
diff --git a/engines/sherlock/surface.cpp b/engines/sherlock/surface.cpp index 36e625794c..80495a398c 100644 --- a/engines/sherlock/surface.cpp +++ b/engines/sherlock/surface.cpp @@ -22,12 +22,13 @@ #include "sherlock/surface.h" #include "sherlock/sherlock.h" +#include "sherlock/resources.h" #include "common/system.h" #include "graphics/palette.h" namespace Sherlock { -Surface::Surface(uint16 width, uint16 height): _freePixels(true) { +Surface::Surface(uint16 width, uint16 height) : _freePixels(true) { create(width, height); } @@ -36,61 +37,65 @@ Surface::Surface() : _freePixels(false) { Surface::~Surface() { if (_freePixels) - free(); + _surface.free(); } -/** - * Sets up an internal surface with the specified dimensions that will be automatically freed - * when the surface object is destroyed - */ void Surface::create(uint16 width, uint16 height) { if (_freePixels) - free(); + _surface.free(); - Graphics::Surface::create(width, height, Graphics::PixelFormat::createFormatCLUT8()); + _surface.create(width, height, Graphics::PixelFormat::createFormatCLUT8()); _freePixels = true; } -/** - * Copy a surface into this one - */ +void Surface::blitFrom(const Surface &src) { + blitFrom(src, Common::Point(0, 0)); +} + +void Surface::blitFrom(const ImageFrame &src) { + blitFrom(src._frame, Common::Point(0, 0)); +} + void Surface::blitFrom(const Graphics::Surface &src) { blitFrom(src, Common::Point(0, 0)); } -/** - * Draws a surface at a given position within this surface - */ +void Surface::blitFrom(const Surface &src, const Common::Point &pt) { + blitFrom(src, pt, Common::Rect(0, 0, src._surface.w, src._surface.h)); +} + +void Surface::blitFrom(const ImageFrame &src, const Common::Point &pt) { + blitFrom(src._frame, pt, Common::Rect(0, 0, src._frame.w, src._frame.h)); +} + void Surface::blitFrom(const Graphics::Surface &src, const Common::Point &pt) { blitFrom(src, pt, Common::Rect(0, 0, src.w, src.h)); } -/** - * Draws a sub-section of a surface at a given position within this surface - */ -void Surface::blitFrom(const Graphics::Surface &src, const Common::Point &pt, - const Common::Rect &srcBounds) { +void Surface::blitFrom(const Graphics::Surface &src, const Common::Point &pt, const Common::Rect &srcBounds) { Common::Rect srcRect = srcBounds; Common::Rect destRect(pt.x, pt.y, pt.x + srcRect.width(), pt.y + srcRect.height()); if (srcRect.isValidRect() && clip(srcRect, destRect)) { // Surface is at least partially or completely on-screen addDirtyRect(destRect); - copyRectToSurface(src, destRect.left, destRect.top, srcRect); + _surface.copyRectToSurface(src, destRect.left, destRect.top, srcRect); } } -/** -* Draws an image frame at a given position within this surface with transparency -*/ +void Surface::blitFrom(const ImageFrame &src, const Common::Point &pt, const Common::Rect &srcBounds) { + blitFrom(src._frame, pt, srcBounds); +} + +void Surface::blitFrom(const Surface &src, const Common::Point &pt, const Common::Rect &srcBounds) { + blitFrom(src._surface, pt, srcBounds); +} + void Surface::transBlitFrom(const ImageFrame &src, const Common::Point &pt, bool flipped, int overrideColor) { transBlitFrom(src._frame, pt + src._offset, flipped, overrideColor); } -/** -* Draws a surface at a given position within this surface with transparency -*/ void Surface::transBlitFrom(const Graphics::Surface &src, const Common::Point &pt, bool flipped, int overrideColor) { Common::Rect drawRect(0, 0, src.w, src.h); @@ -125,38 +130,29 @@ void Surface::transBlitFrom(const Graphics::Surface &src, const Common::Point &p } } -/** - * Fill a given area of the surface with a given color - */ void Surface::fillRect(int x1, int y1, int x2, int y2, byte color) { fillRect(Common::Rect(x1, y1, x2, y2), color); } -/** - * Fill a given area of the surface with a given color - */ void Surface::fillRect(const Common::Rect &r, byte color) { - Graphics::Surface::fillRect(r, color); + _surface.fillRect(r, color); addDirtyRect(r); } -/** - * Clips the given source bounds so the passed destBounds will be entirely on-screen - */ bool Surface::clip(Common::Rect &srcBounds, Common::Rect &destBounds) { - if (destBounds.left >= this->w || destBounds.top >= this->h || - destBounds.right <= 0 || destBounds.bottom <= 0) + if (destBounds.left >= _surface.w || destBounds.top >= _surface.h || + destBounds.right <= 0 || destBounds.bottom <= 0) return false; // Clip the bounds if necessary to fit on-screen - if (destBounds.right > this->w) { - srcBounds.right -= destBounds.right - this->w; - destBounds.right = this->w; + if (destBounds.right > _surface.w) { + srcBounds.right -= destBounds.right - _surface.w; + destBounds.right = _surface.w; } - if (destBounds.bottom > this->h) { - srcBounds.bottom -= destBounds.bottom - this->h; - destBounds.bottom = this->h; + if (destBounds.bottom > _surface.h) { + srcBounds.bottom -= destBounds.bottom - _surface.h; + destBounds.bottom = _surface.h; } if (destBounds.top < 0) { @@ -172,11 +168,22 @@ bool Surface::clip(Common::Rect &srcBounds, Common::Rect &destBounds) { return true; } -/** - * Clear the screen - */ void Surface::clear() { - fillRect(Common::Rect(0, 0, this->w, this->h), 0); + fillRect(Common::Rect(0, 0, _surface.w, _surface.h), 0); +} + +void Surface::free() { + if (_freePixels) { + _surface.free(); + _freePixels = false; + } +} + +void Surface::setPixels(byte *pixels, int width, int height) { + _surface.format = Graphics::PixelFormat::createFormatCLUT8(); + _surface.w = _surface.pitch = width; + _surface.h = height; + _surface.setPixels(pixels); } } // End of namespace Sherlock |
