From dd2ee74cc099e1cf7b6a179886581188b5dfbca3 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 2 Oct 2016 15:39:45 -0400 Subject: TITANIC: Change mouse cursor to use transparency --- engines/titanic/support/mouse_cursor.cpp | 35 ++++-- engines/titanic/support/mouse_cursor.h | 4 +- engines/titanic/support/movie.cpp | 2 +- engines/titanic/support/movie.h | 10 +- engines/titanic/support/raw_surface.cpp | 134 ----------------------- engines/titanic/support/raw_surface.h | 67 ------------ engines/titanic/support/transparency_surface.cpp | 79 +++++++++++++ engines/titanic/support/transparency_surface.h | 63 +++++++++++ engines/titanic/support/video_surface.cpp | 45 +++----- engines/titanic/support/video_surface.h | 11 +- 10 files changed, 194 insertions(+), 256 deletions(-) delete mode 100644 engines/titanic/support/raw_surface.cpp delete mode 100644 engines/titanic/support/raw_surface.h create mode 100644 engines/titanic/support/transparency_surface.cpp create mode 100644 engines/titanic/support/transparency_surface.h (limited to 'engines/titanic/support') diff --git a/engines/titanic/support/mouse_cursor.cpp b/engines/titanic/support/mouse_cursor.cpp index 0cefc368fa..66c28d705e 100644 --- a/engines/titanic/support/mouse_cursor.cpp +++ b/engines/titanic/support/mouse_cursor.cpp @@ -32,6 +32,8 @@ namespace Titanic { +#define CURSOR_SIZE 64 + static const int CURSOR_DATA[NUM_CURSORS][4] = { { 1, 136, 19, 18 }, { 2, 139, 1, 1 }, @@ -52,7 +54,7 @@ static const int CURSOR_DATA[NUM_CURSORS][4] = { CMouseCursor::CursorEntry::~CursorEntry() { delete _videoSurface; - delete _frameSurface; + delete _transSurface; } CMouseCursor::CMouseCursor(CScreenManager *screenManager) : @@ -75,16 +77,16 @@ void CMouseCursor::loadCursorImages() { CURSOR_DATA[idx][3]); // Create the surface - CVideoSurface *surface = _screenManager->createSurface(64, 64); + CVideoSurface *surface = _screenManager->createSurface(CURSOR_SIZE, CURSOR_SIZE); _cursors[idx]._videoSurface = surface; // Open the cursors video and move to the given frame OSMovie movie(key, surface); movie.setFrame(idx); - Graphics::ManagedSurface *frameSurface = movie.duplicateFrame(); - _cursors[idx]._frameSurface = frameSurface; - surface->setTransparencySurface(frameSurface); + Graphics::ManagedSurface *transSurface = movie.duplicateTransparency(); + _cursors[idx]._transSurface = transSurface; + surface->setTransparencySurface(transSurface); } } @@ -101,12 +103,23 @@ void CMouseCursor::setCursor(CursorId cursorId) { if (cursorId != _cursorId) { CursorEntry &ce = _cursors[cursorId - 1]; - CVideoSurface &surface = *ce._videoSurface; - surface.lock(); - - CursorMan.replaceCursor(surface.getPixels(), surface.getWidth(), surface.getHeight(), - ce._centroid.x, ce._centroid.y, 0, false, &g_vm->_screen->format); - surface.unlock(); + CVideoSurface &srcSurface = *ce._videoSurface; + srcSurface.lock(); + + CVideoSurface *surface = CScreenManager::_currentScreenManagerPtr->createSurface( + CURSOR_SIZE, CURSOR_SIZE); + Rect srcRect(0, 0, CURSOR_SIZE, CURSOR_SIZE); + surface->lock(); + surface->getRawSurface()->fillRect(srcRect, srcSurface.getTransparencyColor()); + surface->blitFrom(Point(0, 0), &srcSurface, &srcRect); + + CursorMan.replaceCursor(surface->getPixels(), CURSOR_SIZE, CURSOR_SIZE, + ce._centroid.x, ce._centroid.y, surface->getTransparencyColor(), + false, &g_vm->_screen->format); + + srcSurface.unlock(); + surface->unlock(); + delete surface; _cursorId = cursorId; } diff --git a/engines/titanic/support/mouse_cursor.h b/engines/titanic/support/mouse_cursor.h index 74fb1f6113..5bf6895a67 100644 --- a/engines/titanic/support/mouse_cursor.h +++ b/engines/titanic/support/mouse_cursor.h @@ -55,10 +55,10 @@ class CVideoSurface; class CMouseCursor { struct CursorEntry { CVideoSurface *_videoSurface; - Graphics::ManagedSurface *_frameSurface; + Graphics::ManagedSurface *_transSurface; Common::Point _centroid; - CursorEntry() : _videoSurface(nullptr), _frameSurface(nullptr) {} + CursorEntry() : _videoSurface(nullptr), _transSurface(nullptr) {} ~CursorEntry(); }; private: diff --git a/engines/titanic/support/movie.cpp b/engines/titanic/support/movie.cpp index a605cc3465..eff0e0c754 100644 --- a/engines/titanic/support/movie.cpp +++ b/engines/titanic/support/movie.cpp @@ -203,7 +203,7 @@ void OSMovie::setFrameRate(double rate) { _aviSurface.setFrameRate(rate); } -Graphics::ManagedSurface *OSMovie::duplicateFrame() const { +Graphics::ManagedSurface *OSMovie::duplicateTransparency() const { return _aviSurface.duplicateTransparency(); } diff --git a/engines/titanic/support/movie.h b/engines/titanic/support/movie.h index 8c89f9e6dd..be34244d96 100644 --- a/engines/titanic/support/movie.h +++ b/engines/titanic/support/movie.h @@ -130,9 +130,9 @@ public: virtual void setFrameRate(double rate) = 0; /** - * Creates a duplicate of the movie's frame - */ - virtual Graphics::ManagedSurface *duplicateFrame() const = 0; + * Creates a duplicate of the transparency surface + */ + virtual Graphics::ManagedSurface *duplicateTransparency() const = 0; /** * Removes the movie from the list of currently playing movies @@ -229,9 +229,9 @@ public: virtual void setFrameRate(double rate); /** - * Creates a duplicate of the frame info + * Creates a duplicate of the transparency surface */ - virtual Graphics::ManagedSurface *duplicateFrame() const; + virtual Graphics::ManagedSurface *duplicateTransparency() const; }; } // End of namespace Titanic diff --git a/engines/titanic/support/raw_surface.cpp b/engines/titanic/support/raw_surface.cpp deleted file mode 100644 index 4123b86e68..0000000000 --- a/engines/titanic/support/raw_surface.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "titanic/support/raw_surface.h" -#include "common/algorithm.h" - -namespace Titanic { - -CRawSurface::CRawSurface(const Graphics::Surface *surface, TransparencyMode transMode) { - _width = surface->w; - _pixelsBaseP = (byte *)surface->getPixels(); - _pixelsP = nullptr; - _pitch = 0; - _runLength = 0; - _flag = false; - _flag1 = false; - _flag2 = true; - - switch (transMode) { - case TRANS_MASK0: - case TRANS_ALPHA0: - _flag2 = false; - _flag1 = true; - break; - case TRANS_MASK255: - case TRANS_ALPHA255: - _flag2 = true; - _flag1 = false; - break; - case TRANS_DEFAULT: - if ((_pixelsBaseP[0] == 0 && _pixelsBaseP[2] < 0x80) || - (_pixelsBaseP[0] != 0 && _pixelsBaseP[1] < 0x80)) { - _flag1 = true; - _flag2 = false; - } - break; - default: - break; - } -} - -void CRawSurface::setRow(int yp) { - for (int y = 0; y < yp; ++yp) { - resetPitch(); - skipPitch(); - } -} - -void CRawSurface::setCol(int xp) { - while (xp > 0) - xp -= moveX(xp); -} - -void CRawSurface::skipPitch() { - setCol(_pitch); -} - -int CRawSurface::moveX(int xp) { - if (_runLength) { - if (!_flag) { - --_runLength; - --_pitch; - ++_pixelsP; - return 1; - } - } else { - while (!*_pixelsBaseP) { - _runLength = *++_pixelsBaseP; - ++_pixelsBaseP; - - if (_runLength) { - _pixelsP = _pixelsBaseP; - _pixelsBaseP += _runLength; - if (_runLength & 1) - ++_pixelsBaseP; - - _flag = false; - --_pitch; - --_runLength; - return 1; - } - } - - _runLength = *_pixelsBaseP; - _pixelsP = _pixelsBaseP + 1; - _pixelsBaseP += 2; - _flag = true; - } - - if (xp < 0 || xp > _pitch) - xp = _pitch; - - int len = MIN(_runLength, xp); - _pitch -= len; - _runLength -= len; - return len; -} - -uint CRawSurface::getPixel() const { - return _flag1 ? 0xFF - *_pixelsP : *_pixelsP; -} - -bool CRawSurface::isPixelTransparent1() const { - return _flag1 ? *_pixelsP == 0xF0 : *_pixelsP == 0x10; -} - -bool CRawSurface::isPixelTransparent2() const { - return _flag2 ? *_pixelsP == 0xF0 : *_pixelsP == 0x10; -} - -void CRawSurface::resetPitch() { - _pitch = _width; -} - -} // End of namespace Titanic diff --git a/engines/titanic/support/raw_surface.h b/engines/titanic/support/raw_surface.h deleted file mode 100644 index 69efc1e3db..0000000000 --- a/engines/titanic/support/raw_surface.h +++ /dev/null @@ -1,67 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef TITANIC_RAW_SURFACE_H -#define TITANIC_RAW_SURFACE_H - -#include "graphics/surface.h" - -namespace Titanic { - -enum TransparencyMode { - TRANS_MASK0 = 0, TRANS_MASK255 = 1, TRANS_ALPHA0 = 2, - TRANS_ALPHA255 = 3, TRANS_DEFAULT = 4 -}; - -class CRawSurface { -private: - const byte *_pixelsBaseP; - const byte *_pixelsP; - int _pitch; - int _runLength; - bool _flag; - int _width; - bool _flag1; - bool _flag2; -public: - CRawSurface(const Graphics::Surface *surface, TransparencyMode transMode); - - void setRow(int yp); - - void setCol(int xp); - - void skipPitch(); - - uint getPixel() const; - - bool isPixelTransparent1() const; - - bool isPixelTransparent2() const; - - void resetPitch(); - - int moveX(int xp); -}; - -} // End of namespace Titanic - -#endif /* TITANIC_RAW_SURFACE_H */ diff --git a/engines/titanic/support/transparency_surface.cpp b/engines/titanic/support/transparency_surface.cpp new file mode 100644 index 0000000000..d956c77a58 --- /dev/null +++ b/engines/titanic/support/transparency_surface.cpp @@ -0,0 +1,79 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "titanic/support/transparency_surface.h" +#include "common/algorithm.h" +#include "common/textconsole.h" + +namespace Titanic { + +CTransparencySurface::CTransparencySurface(const Graphics::Surface *surface, + TransparencyMode transMode) : _surface(surface) { + _pitch = 0; + _runLength = 0; + _flag = false; + _flag1 = false; + _flag2 = true; + + switch (transMode) { + case TRANS_MASK0: + case TRANS_ALPHA0: + _flag2 = false; + _flag1 = true; + break; + case TRANS_MASK255: + case TRANS_ALPHA255: + _flag2 = true; + _flag1 = false; + break; + case TRANS_DEFAULT: + error("TRANS_DEFAULT not supported in transparency surface"); + default: + break; + } +} + +int CTransparencySurface::moveX() { + if (++_pos.x >= _surface->w) { + _pos.x = 0; + ++_pos.y; + } + + return 1; +} + +uint CTransparencySurface::getPixel() const { + const byte *pixelP = (const byte *)_surface->getBasePtr(_pos.x, _pos.y); + return _flag1 ? 0xFF - *pixelP : *pixelP; +} + +bool CTransparencySurface::isPixelTransparent1() const { + const byte *pixelP = (const byte *)_surface->getBasePtr(_pos.x, _pos.y); + return _flag1 ? *pixelP == 0xF0 : *pixelP == 0x10; +} + +bool CTransparencySurface::isPixelTransparent2() const { + const byte *pixelP = (const byte *)_surface->getBasePtr(_pos.x, _pos.y); + return _flag2 ? *pixelP == 0xF0 : *pixelP == 0x10; +} + +} // End of namespace Titanic diff --git a/engines/titanic/support/transparency_surface.h b/engines/titanic/support/transparency_surface.h new file mode 100644 index 0000000000..5593dfa66d --- /dev/null +++ b/engines/titanic/support/transparency_surface.h @@ -0,0 +1,63 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef TITANIC_TRANSPARENCY_SURFACE_H +#define TITANIC_TRANSPARENCY_SURFACE_H + +#include "common/rect.h" +#include "graphics/surface.h" + +namespace Titanic { + +enum TransparencyMode { + TRANS_MASK0 = 0, TRANS_MASK255 = 1, TRANS_ALPHA0 = 2, + TRANS_ALPHA255 = 3, TRANS_DEFAULT = 4 +}; + +class CTransparencySurface { +private: + const Graphics::Surface *_surface; + Common::Point _pos; + int _pitch; + int _runLength; + bool _flag; + bool _flag1; + bool _flag2; +public: + CTransparencySurface(const Graphics::Surface *surface, TransparencyMode transMode); + + void setRow(int yp) { _pos.y = yp; } + + void setCol(int xp) { _pos.x = xp; } + + uint getPixel() const; + + bool isPixelTransparent1() const; + + bool isPixelTransparent2() const; + + int moveX(); +}; + +} // End of namespace Titanic + +#endif /* TITANIC_TRANSPARENCY_SURFACE_H */ diff --git a/engines/titanic/support/video_surface.cpp b/engines/titanic/support/video_surface.cpp index fa87e6df0c..8e2fb40a27 100644 --- a/engines/titanic/support/video_surface.cpp +++ b/engines/titanic/support/video_surface.cpp @@ -22,8 +22,8 @@ #include "titanic/support/video_surface.h" #include "titanic/support/image_decoders.h" -#include "titanic/support/raw_surface.h" #include "titanic/support/screen_manager.h" +#include "titanic/support/transparency_surface.h" #include "titanic/titanic.h" namespace Titanic { @@ -198,40 +198,28 @@ void CVideoSurface::transBlitRect(const Rect &srcRect, const Rect &destRect, CVi bool isAlpha = src->_transparencyMode == TRANS_ALPHA0 || src->_transparencyMode == TRANS_ALPHA255; - CRawSurface rawSurface(src->getTransparencySurface(), src->_transparencyMode); + CTransparencySurface transSurface(src->getTransparencySurface(), src->_transparencyMode); if (flipFlag) - rawSurface.setRow(srcRect.top); + transSurface.setRow(srcRect.top); else - rawSurface.setRow(src->getHeight() - srcRect.bottom); + transSurface.setRow(src->getHeight() - srcRect.bottom); for (int srcY = srcRect.top; srcY < srcRect.bottom; ++srcY) { // Prepare for copying the line const uint16 *lineSrcP = srcPtr; uint16 *lineDestP = destPtr; - rawSurface.resetPitch(); - rawSurface.setCol(srcRect.left); + transSurface.setRow(srcY); + transSurface.setCol(srcRect.left); int srcWidth = srcRect.width(); while (srcWidth > 0) { - int move = rawSurface.moveX(0); + int move = transSurface.moveX(); if (move <= 1) { - if (!rawSurface.isPixelTransparent2()) { - copyPixel(lineDestP, lineSrcP, rawSurface.getPixel() >> 3, + if (!transSurface.isPixelTransparent2()) { + copyPixel(lineDestP, lineSrcP, transSurface.getPixel() >> 3, is16Bit, isAlpha); } - } else { - if (move > srcWidth) - move = srcWidth; - - if (rawSurface.isPixelTransparent1()) { - Common::copy(lineSrcP, lineSrcP + move, lineDestP); - } else if (!rawSurface.isPixelTransparent2()) { - byte transVal = rawSurface.getPixel() >> 3; - for (int idx = 0; idx < move; ++idx) { - copyPixel(lineDestP + idx, lineSrcP + idx, transVal, is16Bit, isAlpha); - } - } } lineSrcP += move; @@ -240,7 +228,6 @@ void CVideoSurface::transBlitRect(const Rect &srcRect, const Rect &destRect, CVi } // Move to next line - rawSurface.skipPitch(); srcPtr = flipFlag ? srcPtr + getWidth() : srcPtr - getWidth(); destPtr -= destArea.w; } @@ -487,13 +474,11 @@ uint16 OSVideoSurface::getPixel(const Common::Point &pt) { if (pt.x >= 0 && pt.y >= 0 && pt.x < getWidth() && pt.y < getHeight()) { if (_transparencySurface) { - CRawSurface rawSurface(&_transparencySurface->rawSurface(), _transparencyMode); - rawSurface.setRow(_transBlitFlag ? pt.y : getHeight() - pt.y - 1); - rawSurface.resetPitch(); - rawSurface.setCol(pt.x); - rawSurface.moveX(0); + CTransparencySurface transSurface(&_transparencySurface->rawSurface(), _transparencyMode); + transSurface.setRow(_transBlitFlag ? pt.y : getHeight() - pt.y - 1); + transSurface.setCol(pt.x); - if (rawSurface.isPixelTransparent2()) + if (transSurface.isPixelTransparent2()) return getTransparencyColor(); } @@ -637,8 +622,8 @@ void OSVideoSurface::transPixelate() { unlock(); } -Graphics::ManagedSurface *OSVideoSurface::dupMovieFrame() const { - return _movie ? _movie->duplicateFrame() : nullptr; +Graphics::ManagedSurface *OSVideoSurface::dupMovieTransparency() const { + return _movie ? _movie->duplicateTransparency() : nullptr; } int OSVideoSurface::freeSurface() { diff --git a/engines/titanic/support/video_surface.h b/engines/titanic/support/video_surface.h index 37ff7917dc..3625a3555c 100644 --- a/engines/titanic/support/video_surface.h +++ b/engines/titanic/support/video_surface.h @@ -30,8 +30,8 @@ #include "titanic/support/direct_draw.h" #include "titanic/support/movie.h" #include "titanic/support/movie_range_info.h" -#include "titanic/support/raw_surface.h" #include "titanic/support/rect.h" +#include "titanic/support/transparency_surface.h" #include "titanic/core/list.h" #include "titanic/core/resource_key.h" @@ -277,9 +277,9 @@ public: virtual bool hasFrame(); /** - * Duplicates movie frame surface + * Duplicates movie transparency surface */ - virtual Graphics::ManagedSurface *dupMovieFrame() const = 0; + virtual Graphics::ManagedSurface *dupMovieTransparency() const = 0; /** * Frees the underlying surface @@ -509,10 +509,9 @@ public: virtual void transPixelate(); /** - * Duplicates movie frame surface + * Duplicates movie transparency surface */ - virtual Graphics::ManagedSurface *dupMovieFrame() const; - + virtual Graphics::ManagedSurface *dupMovieTransparency() const; /** * Frees the underlying surface -- cgit v1.2.3