FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
animationicon.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
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 // Standard C++ library includes
23 #include <cassert>
24 
25 // 3rd party library includes
26 
27 // FIFE includes
28 // These includes are split up in two parts, separated by one empty line
29 // First block: files included from the FIFE root src directory
30 // Second block: files included from the same folder
32 #include "util/base/exception.h"
33 #include "util/time/timemanager.h"
34 
35 #include "animationicon.h"
36 
37 namespace fcn {
39  mTimemanager(FIFE::TimeManager::instance()),
40  mAnimation(FIFE::AnimationPtr()),
41  mCurrentImage(NULL),
42  mAnimtime(0),
43  mFrameIndex(-1),
44  mRepeat(true),
45  mPlay(true) {
46 
47  setScaling(false);
48  setTiling(false);
49  setOpaque(true);
50  adjustSize();
51  }
52 
54  mTimemanager(FIFE::TimeManager::instance()),
55  mAnimation(animation),
56  mCurrentImage(NULL),
57  mAnimtime(0),
58  mFrameIndex(-1),
59  mRepeat(true),
60  mPlay(true) {
61 
62  // set first frame as new image
63  if (mAnimation->getFrameCount() > 0) {
64  mFrameIndex = 0;
66  setImage(mCurrentImage);
67  }
68  setScaling(false);
69  setTiling(false);
70  setOpaque(true);
71  adjustSize();
72  }
73 
75  delete mCurrentImage;
76  }
77 
79  mAnimation = animation;
80  if (mPlay) {
82  } else {
83  mAnimtime = 0;
84  }
85  // set first frame as new image
86  if (mAnimation->getFrameCount() > 0) {
87  mFrameIndex = 0;
88  if (mCurrentImage) {
89  delete mCurrentImage;
90  mCurrentImage = 0;
91  }
93  setImage(mCurrentImage);
94  }
95  adjustSize();
96  }
97 
99  return mAnimation;
100  }
101 
102  void AnimationIcon::setRepeating(bool repeat) {
103  mRepeat = repeat;
104  }
105 
107  return mRepeat;
108  }
109 
111  mPlay = true;
113  }
114 
116  return mPlay;
117  }
118 
120  mPlay = false;
121  }
122 
124  mPlay = false;
125  // set first frame as new image
126  if (mAnimation->getFrameCount() > 0) {
127  mFrameIndex = 0;
129  setImage(mCurrentImage);
130  }
131  }
132 
134  if (isPlaying()) {
135  int32_t index = mFrameIndex;
136  if (isRepeating()) {
138  } else {
140  }
141  if (index != mFrameIndex) {
142  mFrameIndex = index;
143  if (mCurrentImage) {
144  delete mCurrentImage;
145  mCurrentImage = 0;
146  }
147  if (mFrameIndex >= 0) {
149  }
150  setImage(mCurrentImage);
151  }
152  }
153  }
154 }
virtual ~AnimationIcon()
Destructor.
bool isRepeating() const
Gets repeating of the animation.
uint32_t getTime() const
Get the time.
void setAnimation(FIFE::AnimationPtr animation)
Sets the animation to display.
void pause()
Stops the animation at the current frame.
const Image * mCurrentImage
Currently used image.
bool mPlay
True if the animation was started, otherwise false.
bool isPlaying() const
Gets if the animation is playing.
virtual void logic()
void setRepeating(bool repeat)
Sets repeating of the animation.
FIFE::AnimationPtr getAnimation() const
Gets the current animation.
FIFE::AnimationPtr mAnimation
The animation to display.
FIFE::TimeManager * mTimemanager
Holds pointer to Fifes TimeManager.
int32_t getFrameIndex(uint32_t timestamp)
Get the frame index that matches given timestamp.
Definition: animation.cpp:124
void stop()
Stops the animation and sets the current frame to the first frame.
void play()
Starts the animation from beginning.
int32_t mFrameIndex
The last used frame index from the animation.
ImagePtr getFrame(int32_t index)
Gets the frame iamge that matches the given index.
Definition: animation.cpp:139
AnimationIcon()
Default constructor.
SharedPtr< Animation > AnimationPtr
Definition: animation.h:168
uint32_t getFrameCount() const
Get the number of frames.
Definition: animation.cpp:178
bool mRepeat
True if the animation should be repeating, otherwise false.
uint32_t getDuration() const
Gets the total duration for the whole animation.
Definition: animation.h:138
uint32_t mAnimtime
The time as the animation was started.