FIFE  2008.0
animation.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_VIDEO_ANIMATION_H
23 #define FIFE_VIDEO_ANIMATION_H
24 
25 // Standard C++ library includes
26 #include <cassert>
27 #include <map>
28 #include <vector>
29 
30 // Platform specific includes
31 #include "util/base/fife_stdint.h"
32 #include "util/base/fifeclass.h"
33 #include "util/base/sharedptr.h"
34 
35 #include "image.h"
36 
37 // 3rd party library includes
38 
39 // FIFE includes
40 // These includes are split up in two parts, separated by one empty line
41 // First block: files included from the FIFE root src directory
42 // Second block: files included from the same folder
43 
44 namespace FIFE {
45 
46  class Image;
47 
56  class Animation : public FifeClass {
57  public:
60  explicit Animation();
61 
64  ~Animation();
65 
72  void addFrame(ImagePtr image, uint32_t duration);
73 
80  int32_t getFrameIndex(uint32_t timestamp);
81 
84  ImagePtr getFrame(int32_t index);
85 
88  ImagePtr getFrameByTimestamp(uint32_t timestamp);
89 
93  int32_t getFrameDuration(int32_t index) const;
94 
97  uint32_t getFrameCount() const;
98 
105  void setActionFrame(int32_t num) { m_action_frame = num; }
106 
110  int32_t getActionFrame() const { return m_action_frame; }
111 
119  void setDirection(uint32_t direction);
120 
125  uint32_t getDirection() const { return m_direction; }
126 
129  uint32_t getDuration() const { return m_animation_endtime; }
130 
131  private:
134  struct FrameInfo {
135  uint32_t index;
136  uint32_t duration;
137  ImagePtr image;
138  };
139 
142  bool isValidIndex(int32_t index) const;
143 
144  // Map of timestamp + associated frame
145  std::map<uint32_t, FrameInfo> m_framemap;
146  // vector of frames for fast indexed access
147  std::vector<FrameInfo> m_frames;
148  // Action frame of the Animation.
149  int32_t m_action_frame;
150  // time when animation ends (zero based)
151  int32_t m_animation_endtime;
152  // Direction for this animation
153  uint32_t m_direction;
154 
155  };
156 
157  typedef SharedPtr<Animation> AnimationPtr;
158 
159 }
160 
161 #endif
162 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */
int32_t getFrameDuration(int32_t index) const
Definition: animation.cpp:112
void setDirection(uint32_t direction)
Definition: animation.cpp:124
uint32_t getDuration() const
Definition: animation.h:129
void setActionFrame(int32_t num)
Definition: animation.h:105
int32_t getActionFrame() const
Definition: animation.h:110
ImagePtr getFrameByTimestamp(uint32_t timestamp)
Definition: animation.cpp:99
uint32_t getFrameCount() const
Definition: animation.cpp:120
int32_t getFrameIndex(uint32_t timestamp)
Definition: animation.cpp:72
ImagePtr getFrame(int32_t index)
Definition: animation.cpp:87
void addFrame(ImagePtr image, uint32_t duration)
Definition: animation.cpp:52
uint32_t getDirection() const
Definition: animation.h:125
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...
Definition: soundclip.cpp:39