ManaPlus
compoundsprite.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2010 The Mana Developers
4  * Copyright (C) 2011-2018 The ManaPlus Developers
5  *
6  * This file is part of The ManaPlus Client.
7  *
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
11  * any later version.
12  *
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.
17  *
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/>.
20  */
21 
22 #ifndef BEING_COMPOUNDSPRITE_H
23 #define BEING_COMPOUNDSPRITE_H
24 
26 
27 #include "utils/vector.h"
28 
29 #include <list>
30 
31 #include "localconsts.h"
32 
33 class CompoundItem;
34 class Image;
35 
37 {
38  public:
39  typedef STD_VECTOR<Sprite*>::iterator SpriteIterator;
40  typedef STD_VECTOR<Sprite*>::const_iterator SpriteConstIterator;
41 
43 
45 
46  ~CompoundSprite() override;
47 
48  bool reset() override final;
49 
50  bool play(const std::string &action) override final;
51 
52  bool update(const int time) override final;
53 
54  void drawSimple(Graphics *const graphics,
55  const int posX,
56  const int posY) const A_NONNULL(2);
57 
61  int getWidth() const override A_WARN_UNUSED;
62 
66  int getHeight() const override A_WARN_UNUSED;
67 
68  const Image *getImage() const override final A_WARN_UNUSED;
69 
70  bool setSpriteDirection(const SpriteDirection::Type direction)
71  override final;
72 
73  int getNumberOfLayers() const A_WARN_UNUSED;
74 
75  unsigned int getCurrentFrame() const override final A_WARN_UNUSED;
76 
77  unsigned int getFrameCount() const override final A_WARN_UNUSED;
78 
79  void addSprite(Sprite *const sprite);
80 
81  void setSprite(const size_t layer, Sprite *const sprite);
82 
83  void removeSprite(const int layer);
84 
85  void clear();
86 
87  void ensureSize(const size_t layerCount);
88 
89  void drawSprites(Graphics *const graphics,
90  const int posX,
91  const int posY) const;
92 
93  virtual void drawSpritesSDL(Graphics *const graphics,
94  const int posX,
95  const int posY) const;
96 
97  void setAlpha(float alpha) override;
98 
99  bool updateNumber(const unsigned num) override final;
100 
101  constexpr2 static void setEnableDelay(bool b) noexcept2
102  { mEnableDelay = b; }
103 
105  { return mLastTime; }
106 
108  { return mStartTime; }
109 
110  STD_VECTOR<Sprite*> mSprites;
111 
112  protected:
113  void redraw() const;
114 
115  void updateImages() const;
116 
117  bool updateFromCache() const;
118 
119  void initCurrentCacheItem() const;
120 
121  typedef std::list<CompoundItem*> ImagesCache;
122  mutable ImagesCache imagesCache;
124 
125  mutable Image *mImage;
126  mutable Image *mAlphaImage;
127 
128  mutable int mOffsetX;
129  mutable int mOffsetY;
132 #ifndef USE_SDL2
133  mutable int mNextRedrawTime;
134 #endif // USE_SDL2
135 
136  static bool mEnableDelay;
137  mutable bool mNeedsRedraw;
141 };
142 
143 #endif // BEING_COMPOUNDSPRITE_H
int getHeight() const
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
bool setSpriteDirection(const SpriteDirection::Type direction)
bool update(const int time)
int getStartTime() const
CompoundItem * mCacheItem
bool updateNumber(const unsigned num)
unsigned int getCurrentFrame() const
#define constexpr2
Definition: localconsts.h:48
const Image * getImage() const
Definition: sprite.h:32
void addSprite(Sprite *const sprite)
#define A_WARN_UNUSED
Definition: localconsts.h:152
#define final
Definition: localconsts.h:45
void drawSimple(Graphics *const graphics, const int posX, const int posY) const
void initCurrentCacheItem() const
int getLastTime() const
std::list< CompoundItem * > ImagesCache
int getNumberOfLayers() const
#define A_NONNULL(...)
Definition: localconsts.h:159
static void setEnableDelay(bool b)
ImagesCache imagesCache
void drawSprites(Graphics *const graphics, const int posX, const int posY) const
std::vector< Sprite * >::iterator SpriteIterator
int getWidth() const
std::vector< Sprite * >::const_iterator SpriteConstIterator
std::vector< Sprite * > mSprites
#define notfinal
Definition: localconsts.h:252
void removeSprite(const int layer)
static bool mEnableDelay
bool updateFromCache() const
virtual void drawSpritesSDL(Graphics *const graphics, const int posX, const int posY) const
unsigned int getFrameCount() const
bool play(const std::string &action)
bool mDisableAdvBeingCaching
void ensureSize(const size_t layerCount)
Definition: image.h:61
void updateImages() const
#define override
Definition: localconsts.h:46
void setAlpha(float alpha)
void setSprite(const size_t layer, Sprite *const sprite)
#define noexcept2
Definition: localconsts.h:49
void redraw() const