3
* Copyright (C) 2010 The Mana Developers
4
* Copyright (C) 2011-2013 The ManaPlus Developers
6
* This file is part of The ManaPlus Client.
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#ifndef COMPOUNDSPRITE_H
23
#define COMPOUNDSPRITE_H
30
#include "localconsts.h"
34
typedef std::list <void*> VectorPointers;
36
class CompoundItem final
41
A_DELETE_COPY(CompoundItem)
50
class CompoundSprite : public Sprite
53
typedef std::vector<Sprite*>::iterator SpriteIterator;
54
typedef std::vector<Sprite*>::const_iterator SpriteConstIterator;
58
A_DELETE_COPY(CompoundSprite)
62
virtual bool reset() override;
64
virtual bool play(const std::string &action) override;
66
virtual bool update(const int time) override;
68
virtual bool draw(Graphics *const graphics,
69
const int posX, const int posY) const override;
72
* Gets the width in pixels of the first sprite in the list.
74
virtual int getWidth() const override A_WARN_UNUSED;
77
* Gets the height in pixels of the first sprite in the list.
79
virtual int getHeight() const override A_WARN_UNUSED;
81
virtual const Image *getImage() const override A_WARN_UNUSED;
83
virtual bool setSpriteDirection(const SpriteDirection direction) override;
85
int getNumberOfLayers() const A_WARN_UNUSED;
87
unsigned int getCurrentFrame() const override A_WARN_UNUSED;
89
unsigned int getFrameCount() const override A_WARN_UNUSED;
91
size_t size() const A_WARN_UNUSED
92
{ return mSprites.size(); }
94
bool empty() const A_WARN_UNUSED
95
{ return mSprites.empty(); }
97
void addSprite(Sprite *const sprite);
99
void setSprite(const int layer, Sprite *const sprite);
101
Sprite *getSprite(int layer) const A_WARN_UNUSED
102
{ return mSprites.at(layer); }
104
void removeSprite(const int layer);
108
void ensureSize(size_t layerCount);
110
virtual void drawSprites(Graphics *const graphics,
111
int posX, int posY) const;
113
virtual void drawSpritesSDL(Graphics *const graphics,
114
int posX, int posY) const;
117
* Returns the curent frame in the current animation of the given layer.
119
virtual unsigned int getCurrentFrame(unsigned int layer)
123
* Returns the frame count in the current animation of the given layer.
125
virtual unsigned int getFrameCount(unsigned int layer) A_WARN_UNUSED;
127
virtual void setAlpha(float alpha) override;
129
bool updateNumber(const unsigned num) override;
131
static void setEnableDelay(bool b)
132
{ mEnableDelay = b; }
137
void updateImages() const;
139
bool updateFromCache() const;
141
void initCurrentCacheItem() const;
143
typedef std::list<CompoundItem*> ImagesCache;
144
mutable ImagesCache imagesCache;
145
mutable CompoundItem *mCacheItem;
147
mutable Image *mImage;
148
mutable Image *mAlphaImage;
150
mutable int mOffsetX;
151
mutable int mOffsetY;
152
std::vector<Sprite*> mSprites;
153
mutable int mNextRedrawTime;
154
static bool mEnableDelay;
155
mutable bool mNeedsRedraw;
156
bool mEnableAlphaFix;
157
bool mDisableAdvBeingCaching;
158
bool mDisableBeingCaching;
161
#endif // COMPOUNDSPRITE_H