aboutsummaryrefslogtreecommitdiff
path: root/engines/draci/animation.cpp
blob: c074deb867333649e1a35df2de6a0117f005e1db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* 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$
 *
 */

#include "draci/draci.h"
#include "draci/animation.h"

namespace Draci {

void Animation::addAnimation(uint id, uint z) {
	
	AnimObj *obj = new AnimObj();
	obj->_id = id;
	obj->_z = z;
	obj->_currentFrame = 0;

	insertAnimation(*obj);
}

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;
	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) {
		if(it->_id == kOverlayImage) {			
			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);

	_animObjects.erase(it);
}
	
void Animation::deleteAll() {
	
	_animObjects.clear();
}

}