mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-21 03:31:40 +00:00
TITANIC: Merge CSurfaceFader and base into a single file
This commit is contained in:
parent
2454290366
commit
33bcc9d058
@ -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 \
|
||||
|
@ -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
|
||||
|
@ -23,23 +23,62 @@
|
||||
#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
|
||||
*/
|
||||
|
@ -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
|
@ -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 */
|
Loading…
x
Reference in New Issue
Block a user