diff options
-rw-r--r-- | engines/titanic/module.mk | 1 | ||||
-rw-r--r-- | engines/titanic/star_control/surface_fader.cpp | 62 | ||||
-rw-r--r-- | engines/titanic/star_control/surface_fader.h | 45 | ||||
-rw-r--r-- | engines/titanic/star_control/surface_fader_base.cpp | 78 | ||||
-rw-r--r-- | engines/titanic/star_control/surface_fader_base.h | 70 |
5 files changed, 100 insertions, 156 deletions
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk index cdb3a64b3c..3d6c66dbf2 100644 --- a/engines/titanic/module.mk +++ b/engines/titanic/module.mk @@ -460,7 +460,6 @@ MODULE_OBJS := \ star_control/star_ref.o \ star_control/star_view.o \ star_control/surface_area.o \ - star_control/surface_fader_base.o \ star_control/surface_fader.o \ support/avi_surface.o \ support/direct_draw.o \ diff --git a/engines/titanic/star_control/surface_fader.cpp b/engines/titanic/star_control/surface_fader.cpp index 694832311f..79129d9732 100644 --- a/engines/titanic/star_control/surface_fader.cpp +++ b/engines/titanic/star_control/surface_fader.cpp @@ -26,6 +26,38 @@ namespace Titanic { + +CSurfaceFaderBase::CSurfaceFaderBase() : _index(-1), _count(32), + _videoSurface(nullptr) { +} + +CSurfaceFaderBase::~CSurfaceFaderBase() { + delete _videoSurface; +} + +void CSurfaceFaderBase::reset() { + _index = 0; +} + +bool CSurfaceFaderBase::setupSurface(CScreenManager *screenManager, CVideoSurface *srcSurface) { + int width = srcSurface->getWidth(); + int height = srcSurface->getHeight(); + + if (_videoSurface) { + if (width == _videoSurface->getWidth() && _videoSurface->getHeight()) + // Allocated surface already matches new size + return true; + + // Different sizes, so delete old surface + delete _videoSurface; + } + + _videoSurface = screenManager->createSurface(width, height); + return true; +} + +/*------------------------------------------------------------------------*/ + CSurfaceFader::CSurfaceFader() : CSurfaceFaderBase() { _dataP = new byte[_count]; @@ -38,6 +70,32 @@ CSurfaceFader::~CSurfaceFader() { delete[] _dataP; } +void CSurfaceFader::setFadeIn(bool fadeIn) { + _fadeIn = fadeIn; +} + +CVideoSurface *CSurfaceFader::fade(CScreenManager *screenManager, CVideoSurface *srcSurface) { + if (_index == -1 || _index >= _count) + return srcSurface; + + if (!_count && !setupSurface(screenManager, srcSurface)) + return nullptr; + + srcSurface->lock(); + _videoSurface->lock(); + CSurfaceArea srCSurfaceArea(srcSurface); + CSurfaceArea destSurfaceObj(_videoSurface); + + // Copy the surface with fading + copySurface(srCSurfaceArea, destSurfaceObj); + + srcSurface->unlock(); + _videoSurface->unlock(); + + ++_index; + return _videoSurface; +} + void CSurfaceFader::copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurface) { const uint16 *srcPixelP = (const uint16 *)srcSurface._pixelsPtr; uint16 *destPixelP = (uint16 *)destSurface._pixelsPtr; @@ -66,8 +124,4 @@ void CSurfaceFader::copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurf } } -void CSurfaceFader::setFadeIn(bool fadeIn) { - _fadeIn = fadeIn; -} - } // End of namespace Titanic diff --git a/engines/titanic/star_control/surface_fader.h b/engines/titanic/star_control/surface_fader.h index 650cbbb19b..d861186dc5 100644 --- a/engines/titanic/star_control/surface_fader.h +++ b/engines/titanic/star_control/surface_fader.h @@ -23,24 +23,63 @@ #ifndef TITANIC_SURFACE_FADER_H #define TITANIC_SURFACE_FADER_H -#include "titanic/star_control/surface_fader_base.h" +#include "titanic/support/video_surface.h" +#include "titanic/support/screen_manager.h" +#include "titanic/star_control/surface_area.h" namespace Titanic { +class CSurfaceFaderBase { +protected: + /** + * Sets up an internal surface to match the size of the specified one + */ + bool setupSurface(CScreenManager *screenManager, CVideoSurface *srcSurface); +public: + int _index; + int _count; + CVideoSurface *_videoSurface; +public: + CSurfaceFaderBase(); + virtual ~CSurfaceFaderBase(); + + /** + * Reset fading back to the start + */ + virtual void reset(); + + /** + * Creates a faded version of the passed source surface, based on a percentage + * visibility specified by _index of _count + */ + virtual CVideoSurface *fade(CScreenManager *screenManager, CVideoSurface *srcSurface) = 0; + + /** + * Returns true if a fade is in progress + */ + bool isActive() const { return _index != -1 && _index < _count; } +}; + class CSurfaceFader: public CSurfaceFaderBase { private: byte *_dataP; bool _fadeIn; -protected: +private: /** * Create a faded version of the source surface at the given dest */ - virtual void copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurface); + void copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurface); public: CSurfaceFader(); virtual ~CSurfaceFader(); /** + * Creates a faded version of the passed source surface, based on a percentage + * visibility specified by _index of _count + */ + virtual CVideoSurface *fade(CScreenManager *screenManager, CVideoSurface *srcSurface); + + /** * Sets whether a fade in (versus a fade out) should be done */ void setFadeIn(bool fadeIn); diff --git a/engines/titanic/star_control/surface_fader_base.cpp b/engines/titanic/star_control/surface_fader_base.cpp deleted file mode 100644 index fb17fb1f31..0000000000 --- a/engines/titanic/star_control/surface_fader_base.cpp +++ /dev/null @@ -1,78 +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/star_control/surface_fader_base.h" - -namespace Titanic { - -CSurfaceFaderBase::CSurfaceFaderBase() : _index(-1), _count(32), - _videoSurface(nullptr) { -} - -CSurfaceFaderBase::~CSurfaceFaderBase() { - delete _videoSurface; -} - -void CSurfaceFaderBase::reset() { - _index = 0; -} - -bool CSurfaceFaderBase::setupSurface(CScreenManager *screenManager, CVideoSurface *srcSurface) { - int width = srcSurface->getWidth(); - int height = srcSurface->getHeight(); - - if (_videoSurface) { - if (width == _videoSurface->getWidth() && _videoSurface->getHeight()) - // Allocated surface already matches new size - return true; - - // Different sizes, so delete old surface - delete _videoSurface; - } - - _videoSurface = screenManager->createSurface(width, height); - return true; -} - -CVideoSurface *CSurfaceFaderBase::fade(CScreenManager *screenManager, CVideoSurface *srcSurface) { - if (_index == -1 || _index >= _count) - return srcSurface; - - if (!_count && !setupSurface(screenManager, srcSurface)) - return nullptr; - - srcSurface->lock(); - _videoSurface->lock(); - CSurfaceArea srCSurfaceArea(srcSurface); - CSurfaceArea destSurfaceObj(_videoSurface); - - // Copy the surface with fading - copySurface(srCSurfaceArea, destSurfaceObj); - - srcSurface->unlock(); - _videoSurface->unlock(); - - ++_index; - return _videoSurface; -} - -} // End of namespace Titanic diff --git a/engines/titanic/star_control/surface_fader_base.h b/engines/titanic/star_control/surface_fader_base.h deleted file mode 100644 index 463183537b..0000000000 --- a/engines/titanic/star_control/surface_fader_base.h +++ /dev/null @@ -1,70 +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_SURFACE_FADER_BASE_H -#define TITANIC_SURFACE_FADER_BASE_H - -#include "titanic/support/video_surface.h" -#include "titanic/support/screen_manager.h" -#include "titanic/star_control/surface_area.h" - -namespace Titanic { - -class CSurfaceFaderBase { -private: - /** - * Sets up an internal surface to match the size of the specified one - */ - bool setupSurface(CScreenManager *screenManager, CVideoSurface *srcSurface); -protected: - /** - * Create a faded version of the source surface at the given dest - */ - virtual void copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurface) = 0; -public: - int _index; - int _count; - CVideoSurface *_videoSurface; -public: - CSurfaceFaderBase(); - virtual ~CSurfaceFaderBase(); - - /** - * Reset fading back to the start - */ - virtual void reset(); - - /** - * Creates a faded version of the passed source surface, based on a percentage - * visibility specified by _index of _count - */ - virtual CVideoSurface *fade(CScreenManager *screenManager, CVideoSurface *srcSurface); - - /** - * Returns true if a fade is in progress - */ - bool isActive() const { return _index != -1 && _index < _count; } -}; - -} // End of namespace Titanic - -#endif /* TITANIC_SURFACE_FADER_BASE_H */ |