ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

Animation.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 // Based on code by omergilad.
00024 
00025 #include "gui/animation/Animation.h"
00026 
00027 namespace GUI {
00028 
00029 Animation::Animation()
00030         : _startTime(0), _duration(0), _finished(false), _finishOnEnd(true) {
00031 }
00032 
00033 Animation::~Animation() {
00034 }
00035 
00036 void Animation::start(long currentTime) {
00037     _finished = false;
00038     _startTime = currentTime;
00039 }
00040 
00041 void Animation::setDuration(long duration) {
00042     _duration = duration;
00043 }
00044 
00045 void Animation::update(Drawable *drawable, long currentTime) {
00046     float interpolation;
00047 
00048     if (currentTime < _startTime) {
00049         // If the start time is in the future, nothing changes - the interpolated value is 0
00050         interpolation = 0;
00051     } else if (currentTime > _startTime + _duration) {
00052         // If the animation is finished, the interpolated value is 1 and the animation is marked as finished
00053         interpolation = 1;
00054         finishAnimation();
00055     } else {
00056         // Calculate the interpolated value
00057         interpolation = (currentTime - _startTime) / (float) (_duration);
00058     }
00059 
00060     // Activate the interpolator if present
00061     if (_interpolator.get() != NULL) {
00062         interpolation = _interpolator->interpolate(interpolation);
00063     }
00064 
00065     updateInternal(drawable, interpolation);
00066 }
00067 
00068 void Animation::finishAnimation() {
00069     if (_finishOnEnd) {
00070         _finished = true;
00071     }
00072 }
00073 
00074 void Animation::updateInternal(Drawable *drawable, float interpolation) {
00075     // Default implementation
00076 }
00077 
00078 bool Animation::isFinished() const {
00079     return _finished;
00080 }
00081 
00082 bool Animation::isFinishOnEnd() const {
00083     return _finishOnEnd;
00084 }
00085 
00086 void Animation::setFinishOnEnd(bool finishOnEnd) {
00087     _finishOnEnd = finishOnEnd;
00088 }
00089 
00090 InterpolatorPtr Animation::getInterpolator() const {
00091     return _interpolator;
00092 }
00093 
00094 void Animation::setInterpolator(InterpolatorPtr interpolator) {
00095     _interpolator = interpolator;
00096 }
00097 
00098 } // End of namespace GUI


Generated on Sat Feb 16 2019 05:00:44 for ResidualVM by doxygen 1.7.1
curved edge   curved edge