2009-07-01 16:20:47 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-07-03 17:50:22 +00:00
|
|
|
#include "draci/draci.h"
|
|
|
|
#include "draci/animation.h"
|
|
|
|
|
2009-07-01 16:20:47 +00:00
|
|
|
namespace Draci {
|
|
|
|
|
2009-07-03 19:05:58 +00:00
|
|
|
void Animation::addAnimation(uint id, uint z, bool playing) {
|
2009-07-03 17:50:22 +00:00
|
|
|
|
|
|
|
AnimObj *obj = new AnimObj();
|
|
|
|
obj->_id = id;
|
|
|
|
obj->_z = z;
|
|
|
|
obj->_currentFrame = 0;
|
2009-07-03 19:05:58 +00:00
|
|
|
obj->_playing = playing;
|
2009-07-03 17:50:22 +00:00
|
|
|
|
|
|
|
insertAnimation(*obj);
|
|
|
|
}
|
|
|
|
|
2009-07-03 19:05:58 +00:00
|
|
|
void Animation::play(uint id) {
|
|
|
|
|
|
|
|
AnimObj &obj = *getAnimation(id);
|
|
|
|
|
|
|
|
obj._playing = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::stop(uint id) {
|
|
|
|
|
|
|
|
AnimObj &obj = *getAnimation(id);
|
|
|
|
|
|
|
|
obj._playing = false;
|
|
|
|
}
|
|
|
|
|
2009-07-03 17:50:22 +00:00
|
|
|
Common::List<AnimObj>::iterator Animation::getAnimation(uint id) {
|
|
|
|
|
|
|
|
Common::List<AnimObj>::iterator it;
|
|
|
|
|
|
|
|
for (it = _animObjects.begin(); it != _animObjects.end(); ++it) {
|
|
|
|
if (it->_id == id) {
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _animObjects.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::insertAnimation(AnimObj &animObj) {
|
|
|
|
|
|
|
|
Common::List<AnimObj>::iterator it;
|
|
|
|
|
|
|
|
for (it = _animObjects.begin(); it != _animObjects.end(); ++it) {
|
|
|
|
if (animObj._z < it->_z)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_animObjects.insert(it, animObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::addFrame(uint id, Drawable *frame) {
|
|
|
|
|
|
|
|
Common::List<AnimObj>::iterator it = getAnimation(id);
|
|
|
|
|
|
|
|
it->_frames.push_back(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::addOverlay(Drawable *overlay, uint z) {
|
|
|
|
AnimObj *obj = new AnimObj();
|
|
|
|
obj->_id = kOverlayImage;
|
|
|
|
obj->_z = z;
|
|
|
|
obj->_currentFrame = 0;
|
2009-07-03 19:05:58 +00:00
|
|
|
obj->_playing = true;
|
2009-07-03 17:50:22 +00:00
|
|
|
obj->_frames.push_back(overlay);
|
|
|
|
|
|
|
|
insertAnimation(*obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::drawScene(Surface *surf) {
|
|
|
|
|
|
|
|
Common::List<AnimObj>::iterator it;
|
|
|
|
|
|
|
|
for (it = _animObjects.begin(); it != _animObjects.end(); ++it) {
|
2009-07-03 19:05:58 +00:00
|
|
|
if (!it->_playing) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it->_id == kOverlayImage) {
|
2009-07-03 17:50:22 +00:00
|
|
|
it->_frames[it->_currentFrame]->draw(surf, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
it->_frames[it->_currentFrame]->draw(surf, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::deleteAnimation(uint id) {
|
|
|
|
|
|
|
|
Common::List<AnimObj>::iterator it = getAnimation(id);
|
|
|
|
|
2009-07-03 19:05:58 +00:00
|
|
|
for (uint i = 0; i < it->_frames.size(); ++i) {
|
2009-07-03 18:19:51 +00:00
|
|
|
delete it->_frames[i];
|
|
|
|
}
|
|
|
|
|
2009-07-03 17:50:22 +00:00
|
|
|
_animObjects.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::deleteAll() {
|
|
|
|
|
2009-07-03 18:19:51 +00:00
|
|
|
Common::List<AnimObj>::iterator it;
|
|
|
|
|
|
|
|
for (it = _animObjects.begin(); it != _animObjects.end(); ++it) {
|
2009-07-03 19:05:58 +00:00
|
|
|
for (uint i = 0; i < it->_frames.size(); ++i) {
|
2009-07-03 18:19:51 +00:00
|
|
|
delete it->_frames[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 17:50:22 +00:00
|
|
|
_animObjects.clear();
|
2009-07-01 16:20:47 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 17:50:22 +00:00
|
|
|
}
|