diff options
Diffstat (limited to 'engines/access/asurface.cpp')
-rw-r--r-- | engines/access/asurface.cpp | 250 |
1 files changed, 89 insertions, 161 deletions
diff --git a/engines/access/asurface.cpp b/engines/access/asurface.cpp index 526690807a..37f4c7082e 100644 --- a/engines/access/asurface.cpp +++ b/engines/access/asurface.cpp @@ -28,6 +28,8 @@ namespace Access { +const int TRANSPARENCY = 0; + SpriteResource::SpriteResource(AccessEngine *vm, Resource *res) { Common::Array<uint32> offsets; int count = res->_stream->readUint16LE(); @@ -64,7 +66,7 @@ SpriteFrame::SpriteFrame(AccessEngine *vm, Common::SeekableReadStream *stream, i // Empty surface byte *data = (byte *)getPixels(); - Common::fill(data, data + w * h, 0); + Common::fill(data, data + w * h, TRANSPARENCY); // Decode the data for (int y = 0; y < h; ++y) { @@ -105,10 +107,11 @@ void ImageEntryList::addToList(ImageEntry &ie) { /*------------------------------------------------------------------------*/ -int ASurface::_clipWidth; -int ASurface::_clipHeight; +int BaseSurface::_clipWidth; +int BaseSurface::_clipHeight; -ASurface::ASurface(): Graphics::Surface() { +BaseSurface::BaseSurface(): Graphics::Screen(0, 0) { + free(); // Free the 0x0 surface allocated by Graphics::Screen _leftSkip = _rightSkip = 0; _topSkip = _bottomSkip = 0; _lastBoundsX = _lastBoundsY = 0; @@ -119,67 +122,16 @@ ASurface::ASurface(): Graphics::Surface() { _maxChars = 0; } -ASurface::~ASurface() { - free(); +BaseSurface::~BaseSurface() { _savedBlock.free(); } -void ASurface::create(uint16 width, uint16 height) { - Graphics::Surface::create(width, height, Graphics::PixelFormat::createFormatCLUT8()); -} - -void ASurface::clearBuffer() { +void BaseSurface::clearBuffer() { byte *pSrc = (byte *)getPixels(); Common::fill(pSrc, pSrc + w * h, 0); } -bool ASurface::clip(Common::Rect &r) { - int skip; - _leftSkip = _rightSkip = 0; - _topSkip = _bottomSkip = 0; - - if (r.left > _clipWidth || r.left < 0) { - if (r.left >= 0) - return true; - - skip = -r.left; - r.setWidth(r.width() - skip); - _leftSkip = skip; - r.moveTo(0, r.top); - } - - int right = r.right - 1; - if (right < 0) - return true; - else if (right > _clipWidth) { - skip = right - _clipWidth; - r.setWidth(r.width() - skip); - _rightSkip = skip; - } - - if (r.top > _clipHeight || r.top < 0) { - if (r.top >= 0) - return true; - - skip = -r.top; - r.setHeight(r.height() - skip); - _topSkip = skip; - r.moveTo(r.left, 0); - } - - int bottom = r.bottom - 1; - if (bottom < 0) - return true; - else if (bottom > _clipHeight) { - skip = bottom - _clipHeight; - _bottomSkip = skip; - r.setHeight(r.height() - skip); - } - - return false; -} - -void ASurface::plotImage(SpriteResource *sprite, int frameNum, const Common::Point &pt) { +void BaseSurface::plotImage(SpriteResource *sprite, int frameNum, const Common::Point &pt) { SpriteFrame *frame = sprite->getFrame(frameNum); Common::Rect r(pt.x, pt.y, pt.x + frame->w, pt.y + frame->h); @@ -193,108 +145,38 @@ void ASurface::plotImage(SpriteResource *sprite, int frameNum, const Common::Poi } } -void ASurface::transBlitFrom(ASurface *src, const Common::Point &destPos) { - if (getPixels() == nullptr) - create(w, h); - - for (int yp = 0; yp < src->h; ++yp) { - const byte *srcP = (const byte *)src->getBasePtr(0, yp); - byte *destP = (byte *)getBasePtr(destPos.x, destPos.y + yp); - - for (int xp = 0; xp < this->w; ++xp, ++srcP, ++destP) { - if (*srcP != 0) - *destP = *srcP; - } - } -} - -void ASurface::transBlitFrom(ASurface *src, const Common::Rect &bounds) { - const int SCALE_LIMIT = 0x100; - int scaleX = SCALE_LIMIT * bounds.width() / src->w; - int scaleY = SCALE_LIMIT * bounds.height() / src->h; - int scaleXCtr = 0, scaleYCtr = 0; - - for (int yCtr = 0, destY = bounds.top; yCtr < src->h; ++yCtr) { - // Handle skipping lines if Y scaling - scaleYCtr += scaleY; - if (scaleYCtr < SCALE_LIMIT) - continue; - scaleYCtr -= SCALE_LIMIT; - - // Handle off-screen lines - if (destY >= this->h) - break; - - if (destY >= 0) { - // Handle drawing the line - const byte *pSrc = (const byte *)src->getBasePtr(0, yCtr); - byte *pDest = (byte *)getBasePtr(bounds.left, destY); - scaleXCtr = 0; - int x = bounds.left; - - for (int xCtr = 0; xCtr < src->w; ++xCtr, ++pSrc) { - // Handle horizontal scaling - scaleXCtr += scaleX; - if (scaleXCtr < SCALE_LIMIT) - continue; - scaleXCtr -= SCALE_LIMIT; - - // Only handle on-screen pixels - if (x >= this->w) - break; - if (x >= 0 && *pSrc != 0) - *pDest = *pSrc; - - ++pDest; - ++x; - } - } - - ++destY; - } -} - -void ASurface::transBlitFrom(ASurface &src) { - blitFrom(src); -} - -void ASurface::blitFrom(Graphics::Surface &src) { - assert(w >= src.w && h >= src.h); - for (int y = 0; y < src.h; ++y) { - const byte *srcP = (const byte *)src.getBasePtr(0, y); - byte *destP = (byte *)getBasePtr(0, y); - Common::copy(srcP, srcP + src.w, destP); - } -} - -void ASurface::copyBuffer(Graphics::Surface *src) { +void BaseSurface::copyBuffer(Graphics::ManagedSurface *src) { blitFrom(*src); } -void ASurface::plotF(SpriteFrame *frame, const Common::Point &pt) { +void BaseSurface::plotF(SpriteFrame *frame, const Common::Point &pt) { sPlotF(frame, Common::Rect(pt.x, pt.y, pt.x + frame->w, pt.y + frame->h)); } -void ASurface::plotB(SpriteFrame *frame, const Common::Point &pt) { +void BaseSurface::plotB(SpriteFrame *frame, const Common::Point &pt) { sPlotB(frame, Common::Rect(pt.x, pt.y, pt.x + frame->w, pt.y + frame->h)); } -void ASurface::sPlotF(SpriteFrame *frame, const Common::Rect &bounds) { - transBlitFrom(frame, bounds); +void BaseSurface::sPlotF(SpriteFrame *frame, const Common::Rect &bounds) { + transBlitFrom(*frame, Common::Rect(0, 0, frame->w, frame->h), bounds, TRANSPARENCY, false); } -void ASurface::sPlotB(SpriteFrame *frame, const Common::Rect &bounds) { - ASurface flippedFrame; - frame->flipHorizontal(flippedFrame); - - transBlitFrom(&flippedFrame, bounds); +void BaseSurface::sPlotB(SpriteFrame *frame, const Common::Rect &bounds) { + transBlitFrom(*frame, Common::Rect(0, 0, frame->w, frame->h), bounds, TRANSPARENCY, true); } -void ASurface::copyBlock(ASurface *src, const Common::Rect &bounds) { +void BaseSurface::copyBlock(BaseSurface *src, const Common::Rect &bounds) { copyRectToSurface(*src, bounds.left, bounds.top, bounds); } -void ASurface::saveBlock(const Common::Rect &bounds) { +void BaseSurface::copyTo(BaseSurface *dest) { + if (dest->empty()) + dest->create(this->w, this->h); + + dest->blitFrom(*this); +} + +void BaseSurface::saveBlock(const Common::Rect &bounds) { _savedBounds = bounds; _savedBounds.clip(Common::Rect(0, 0, this->w, this->h)); @@ -304,7 +186,7 @@ void ASurface::saveBlock(const Common::Rect &bounds) { _savedBlock.copyRectToSurface(*this, 0, 0, _savedBounds); } -void ASurface::restoreBlock() { +void BaseSurface::restoreBlock() { if (!_savedBounds.isEmpty()) { copyRectToSurface(_savedBlock, _savedBounds.left, _savedBounds.top, Common::Rect(0, 0, _savedBlock.w, _savedBlock.h)); @@ -314,26 +196,26 @@ void ASurface::restoreBlock() { } } -void ASurface::drawRect() { - Graphics::Surface::fillRect(Common::Rect(_orgX1, _orgY1, _orgX2, _orgY2), _lColor); +void BaseSurface::drawRect() { + Graphics::ManagedSurface::fillRect(Common::Rect(_orgX1, _orgY1, _orgX2, _orgY2), _lColor); } -void ASurface::drawLine(int x1, int y1, int x2, int y2, int col) { - Graphics::Surface::drawLine(x1, y1, x2, y2, col); +void BaseSurface::drawLine(int x1, int y1, int x2, int y2, int col) { + Graphics::ManagedSurface::drawLine(x1, y1, x2, y2, col); } -void ASurface::drawLine() { - Graphics::Surface::drawLine(_orgX1, _orgY1, _orgX2, _orgY1, _lColor); +void BaseSurface::drawLine() { + Graphics::ManagedSurface::drawLine(_orgX1, _orgY1, _orgX2, _orgY1, _lColor); } -void ASurface::drawBox() { - Graphics::Surface::drawLine(_orgX1, _orgY1, _orgX2, _orgY1, _lColor); - Graphics::Surface::drawLine(_orgX1, _orgY2, _orgX2, _orgY2, _lColor); - Graphics::Surface::drawLine(_orgX2, _orgY1, _orgX2, _orgY1, _lColor); - Graphics::Surface::drawLine(_orgX2, _orgY2, _orgX2, _orgY2, _lColor); +void BaseSurface::drawBox() { + Graphics::ManagedSurface::drawLine(_orgX1, _orgY1, _orgX2, _orgY1, _lColor); + Graphics::ManagedSurface::drawLine(_orgX1, _orgY2, _orgX2, _orgY2, _lColor); + Graphics::ManagedSurface::drawLine(_orgX2, _orgY1, _orgX2, _orgY1, _lColor); + Graphics::ManagedSurface::drawLine(_orgX2, _orgY2, _orgX2, _orgY2, _lColor); } -void ASurface::flipHorizontal(ASurface &dest) { +void BaseSurface::flipHorizontal(BaseSurface &dest) { dest.create(this->w, this->h); for (int y = 0; y < h; ++y) { const byte *pSrc = (const byte *)getBasePtr(this->w - 1, y); @@ -344,24 +226,70 @@ void ASurface::flipHorizontal(ASurface &dest) { } } -void ASurface::moveBufferLeft() { +void BaseSurface::moveBufferLeft() { byte *p = (byte *)getPixels(); Common::copy(p + TILE_WIDTH, p + (w * h), p); } -void ASurface::moveBufferRight() { +void BaseSurface::moveBufferRight() { byte *p = (byte *)getPixels(); Common::copy_backward(p, p + (pitch * h) - TILE_WIDTH, p + (pitch * h)); } -void ASurface::moveBufferUp() { +void BaseSurface::moveBufferUp() { byte *p = (byte *)getPixels(); Common::copy(p + (pitch * TILE_HEIGHT), p + (pitch * h), p); } -void ASurface::moveBufferDown() { +void BaseSurface::moveBufferDown() { byte *p = (byte *)getPixels(); Common::copy_backward(p, p + (pitch * (h - TILE_HEIGHT)), p + (pitch * h)); } +bool BaseSurface::clip(Common::Rect &r) { + int skip; + _leftSkip = _rightSkip = 0; + _topSkip = _bottomSkip = 0; + + if (r.left > _clipWidth || r.left < 0) { + if (r.left >= 0) + return true; + + skip = -r.left; + r.setWidth(r.width() - skip); + _leftSkip = skip; + r.moveTo(0, r.top); + } + + int right = r.right - 1; + if (right < 0) + return true; + else if (right > _clipWidth) { + skip = right - _clipWidth; + r.setWidth(r.width() - skip); + _rightSkip = skip; + } + + if (r.top > _clipHeight || r.top < 0) { + if (r.top >= 0) + return true; + + skip = -r.top; + r.setHeight(r.height() - skip); + _topSkip = skip; + r.moveTo(r.left, 0); + } + + int bottom = r.bottom - 1; + if (bottom < 0) + return true; + else if (bottom > _clipHeight) { + skip = bottom - _clipHeight; + _bottomSkip = skip; + r.setHeight(r.height() - skip); + } + + return false; +} + } // End of namespace Access |