Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthew Hoops
committed
Sep 17, 2011
1 parent
3b9ab4f
commit 544224b
Showing
4 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* 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. | ||
* | ||
* Additional copyright for this file: | ||
* Copyright (C) 1995-1997 Presto Studios, Inc. | ||
* | ||
* 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 "common/system.h" | ||
|
||
#include "pegasus/transition.h" | ||
|
||
namespace Pegasus { | ||
|
||
ScreenFader::ScreenFader() { | ||
_fadeTarget = getBlack(); | ||
// Initially, assume screens are on at full brightness. | ||
Fader::setFaderValue(100); | ||
} | ||
|
||
void ScreenFader::doFadeOutSync(const TimeValue duration, const TimeValue scale, const uint32 fadeTarget) { | ||
_fadeTarget = fadeTarget; | ||
|
||
FaderMoveSpec spec; | ||
spec.makeTwoKnotFaderSpec(scale, 0, getFaderValue(), duration, 0); | ||
startFaderSync(spec); | ||
} | ||
|
||
void ScreenFader::doFadeInSync(const TimeValue duration, const TimeValue scale, const uint32 fadeTarget) { | ||
_fadeTarget = fadeTarget; | ||
|
||
FaderMoveSpec spec; | ||
spec.makeTwoKnotFaderSpec(scale, 0, getFaderValue(), duration, 100); | ||
startFaderSync(spec); | ||
} | ||
|
||
void ScreenFader::setFaderValue(const uint32 value) { | ||
if (value != getFaderValue()) { | ||
Fader::setFaderValue(value); | ||
|
||
// TODO: Gamma fading | ||
} | ||
} | ||
|
||
uint32 ScreenFader::getBlack() { | ||
return g_system->getScreenFormat().RGBToColor(0, 0, 0); | ||
} | ||
|
||
Transition::Transition(const tDisplayElementID id) : FaderAnimation(id) { | ||
_outPicture = 0; | ||
_inPicture = 0; | ||
} | ||
|
||
void Transition::setBounds(const Common::Rect &r) { | ||
FaderAnimation::setBounds(r); | ||
_boundsWidth = _bounds.width(); | ||
_boundsHeight = _bounds.height(); | ||
} | ||
|
||
void Transition::setInAndOutElements(DisplayElement *inElement, DisplayElement *outElement) { | ||
_inPicture = inElement; | ||
_outPicture = outElement; | ||
|
||
Common::Rect r; | ||
|
||
if (_outPicture) | ||
_outPicture->getBounds(r); | ||
else if (_inPicture) | ||
_inPicture->getBounds(r); | ||
|
||
setBounds(r); | ||
} | ||
|
||
void Slide::draw(const Common::Rect &r) { | ||
Common::Rect oldBounds, newBounds; | ||
|
||
adjustSlideRects(oldBounds, newBounds); | ||
drawElements(r, oldBounds, newBounds); | ||
} | ||
|
||
void Slide::adjustSlideRects(Common::Rect &oldBounds, Common::Rect &newBounds) { | ||
oldBounds = _bounds; | ||
newBounds = _bounds; | ||
} | ||
|
||
void Slide::drawElements(const Common::Rect &drawRect, const Common::Rect &oldBounds, const Common::Rect &newBounds) { | ||
drawSlideElement(drawRect, oldBounds, _outPicture); | ||
drawSlideElement(drawRect, newBounds, _inPicture); | ||
} | ||
|
||
void Slide::drawSlideElement(const Common::Rect &drawRect, const Common::Rect &oldBounds, DisplayElement *picture) { | ||
if (picture && drawRect.intersects(oldBounds)) { | ||
picture->moveElementTo(oldBounds.left, oldBounds.top); | ||
picture->draw(drawRect.findIntersectingRect(oldBounds)); | ||
} | ||
} | ||
|
||
void Push::adjustSlideRects(Common::Rect &oldBounds, Common::Rect &newBounds) { | ||
switch (_direction & kSlideHorizMask) { | ||
case kSlideLeftMask: | ||
newBounds.left = oldBounds.right = _bounds.right - pegasusRound(getFaderValue() * _boundsWidth, kTransitionRange); | ||
newBounds.right = newBounds.left + _boundsWidth; | ||
oldBounds.left = oldBounds.right - _boundsWidth; | ||
break; | ||
case kSlideRightMask: | ||
oldBounds.left = newBounds.right = _bounds.left + pegasusRound(getFaderValue() * _boundsWidth, kTransitionRange); | ||
oldBounds.right = oldBounds.left + _boundsWidth; | ||
newBounds.left = newBounds.right - _boundsWidth; | ||
break; | ||
default: | ||
newBounds.left = oldBounds.left = _bounds.left; | ||
newBounds.right = oldBounds.right = _bounds.right; | ||
break; | ||
} | ||
switch (_direction & kSlideVertMask) { | ||
case kSlideDownMask: | ||
oldBounds.top = newBounds.bottom = _bounds.top + pegasusRound(getFaderValue() * _boundsHeight, kTransitionRange); | ||
oldBounds.bottom = oldBounds.top + _boundsHeight; | ||
newBounds.top = newBounds.bottom - _boundsHeight; | ||
break; | ||
case kSlideUpMask: | ||
newBounds.top = oldBounds.bottom = _bounds.bottom - pegasusRound(getFaderValue() * _boundsHeight, kTransitionRange); | ||
newBounds.bottom = newBounds.top + _boundsHeight; | ||
oldBounds.top = oldBounds.bottom - _boundsHeight; | ||
break; | ||
default: | ||
newBounds.top = oldBounds.top = _bounds.top; | ||
newBounds.bottom = oldBounds.bottom = _bounds.bottom; | ||
break; | ||
} | ||
} | ||
|
||
} // End of namespace Pegasus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* 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. | ||
* | ||
* Additional copyright for this file: | ||
* Copyright (C) 1995-1997 Presto Studios, Inc. | ||
* | ||
* 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 PEGASUS_TRANSITION_H | ||
#define PEGASUS_TRANSITION_H | ||
|
||
#include "pegasus/fader.h" | ||
|
||
namespace Pegasus { | ||
|
||
class ScreenFader : public Fader { | ||
public: | ||
ScreenFader(); | ||
virtual ~ScreenFader() {} | ||
|
||
void doFadeOutSync(const TimeValue = kOneSecondPerThirtyTicks, const TimeScale = kThirtyTicksPerSecond, const uint32 = getBlack()); | ||
void doFadeInSync(const TimeValue = kHalfSecondPerThirtyTicks, const TimeScale = kThirtyTicksPerSecond, const uint32 = getBlack()); | ||
|
||
void setFaderValue(const uint32); | ||
|
||
protected: | ||
uint32 _fadeTarget; | ||
|
||
private: | ||
static uint32 getBlack(); | ||
}; | ||
|
||
// Transitions are faders that range over [0,1000], which makes their | ||
// "resolution" one tenth of a percent | ||
|
||
const long kTransitionBottom = 0; | ||
const long kTransitionTop = 1000; | ||
|
||
const long kTransitionRange = kTransitionTop - kTransitionBottom; | ||
|
||
class Transition : public FaderAnimation { | ||
public: | ||
Transition(const tDisplayElementID id); | ||
virtual ~Transition() {} | ||
|
||
virtual void setBounds(const Common::Rect &); | ||
|
||
virtual void setInAndOutElements(DisplayElement *, DisplayElement *); | ||
DisplayElement *getInElement() { return _inPicture; } | ||
DisplayElement *getOutElement() { return _outPicture; } | ||
|
||
protected: | ||
DisplayElement *_outPicture; | ||
DisplayElement *_inPicture; | ||
|
||
tCoordType _boundsWidth, _boundsHeight; | ||
}; | ||
|
||
class Slide : public Transition { | ||
public: | ||
Slide(const tDisplayElementID id) : Transition(id) {} | ||
virtual ~Slide() {} | ||
|
||
virtual void setSlideDirection(tSlideDirection dir) { _direction = dir; } | ||
virtual void draw(const Common::Rect &); | ||
|
||
virtual void setDirection(const tSlideDirection dir) { _direction = dir; } | ||
|
||
protected: | ||
virtual void adjustSlideRects(Common::Rect &, Common::Rect &); | ||
virtual void drawElements(const Common::Rect &, const Common::Rect &, const Common::Rect &); | ||
virtual void drawSlideElement(const Common::Rect &, const Common::Rect &, DisplayElement *); | ||
|
||
tSlideDirection _direction; | ||
}; | ||
|
||
class Push : public Slide { | ||
public: | ||
Push(const tDisplayElementID id) : Slide(id) {} | ||
virtual ~Push() {} | ||
|
||
protected: | ||
virtual void adjustSlideRects(Common::Rect &, Common::Rect &); | ||
}; | ||
|
||
} // End of namespace Pegasus | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters