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-2019 The ManaPlus Developers
5  * Copyright (C) 2019-2021 Andrei Karas
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef BEING_COMPOUNDSPRITE_H
24 #define BEING_COMPOUNDSPRITE_H
25 
27 
28 #include "utils/vector.h"
29 
30 #include <list>
31 
32 #include "localconsts.h"
33 
34 class CompoundItem;
35 class Image;
36 
38 {
39  public:
40  typedef STD_VECTOR<Sprite*>::iterator SpriteIterator;
41  typedef STD_VECTOR<Sprite*>::const_iterator SpriteConstIterator;
42 
44 
46 
47  ~CompoundSprite() override;
48 
49  bool reset() override final;
50 
51  bool play(const std::string &action) override final;
52 
53  bool update(const int time) override final;
54 
55  void drawSimple(Graphics *const graphics,
56  const int posX,
57  const int posY) const A_NONNULL(2);
58 
62  int getWidth() const override A_WARN_UNUSED;
63 
67  int getHeight() const override A_WARN_UNUSED;
68 
69  const Image *getImage() const override final A_WARN_UNUSED;
70 
71  bool setSpriteDirection(const SpriteDirection::Type direction)
73 
74  int getNumberOfLayers() const A_WARN_UNUSED;
75 
76  unsigned int getCurrentFrame() const override final A_WARN_UNUSED;
77 
78  unsigned int getFrameCount() const override final A_WARN_UNUSED;
79 
80  void addSprite(Sprite *const sprite);
81 
82  void setSprite(const size_t layer, Sprite *const sprite);
83 
84  void removeSprite(const int layer);
85 
86  void clear();
87 
88  void ensureSize(const size_t layerCount);
89 
90  void drawSprites(Graphics *const graphics,
91  const int posX,
92  const int posY) const;
93 
94  virtual void drawSpritesSDL(Graphics *const graphics,
95  const int posX,
96  const int posY) const;
97 
98  void setAlpha(float alpha) override;
99 
100  bool updateNumber(const unsigned num) override final;
101 
102  constexpr2 static void setEnableDelay(bool b) noexcept2
103  { mEnableDelay = b; }
104 
106  { return mLastTime; }
107 
109  { return mStartTime; }
110 
111  STD_VECTOR<Sprite*> mSprites;
112 
113  protected:
114  void redraw() const;
115 
116  void updateImages() const;
117 
118  bool updateFromCache() const;
119 
120  void initCurrentCacheItem() const;
121 
122  typedef std::list<CompoundItem*> ImagesCache;
125 
126  mutable Image *mImage;
127  mutable Image *mAlphaImage;
128 
129  mutable int mOffsetX;
130  mutable int mOffsetY;
133 #ifndef USE_SDL2
134  mutable int mNextRedrawTime;
135 #endif // USE_SDL2
136 
137  static bool mEnableDelay;
138  mutable bool mNeedsRedraw;
142 };
143 
144 #endif // BEING_COMPOUNDSPRITE_H
int getStartTime() const
void updateImages() const
void ensureSize(const size_t layerCount)
std::list< CompoundItem * > ImagesCache
const Image * getImage() const
void redraw() const
int getHeight() const
std::vector< Sprite * >::iterator SpriteIterator
void drawSimple(Graphics *const graphics, const int posX, const int posY) const
bool setSpriteDirection(const SpriteDirection::Type direction)
std::vector< Sprite * > mSprites
virtual void drawSpritesSDL(Graphics *const graphics, const int posX, const int posY) const
int getNumberOfLayers() const
static bool mEnableDelay
bool update(const int time)
CompoundItem * mCacheItem
unsigned int getFrameCount() const
void setAlpha(float alpha)
int getLastTime() const
bool play(const std::string &action)
void drawSprites(Graphics *const graphics, const int posX, const int posY) const
ImagesCache imagesCache
bool updateFromCache() const
void addSprite(Sprite *const sprite)
static void setEnableDelay(bool b)
bool updateNumber(const unsigned num)
std::vector< Sprite * >::const_iterator SpriteConstIterator
unsigned int getCurrentFrame() const
void removeSprite(const int layer)
int getWidth() const
void initCurrentCacheItem() const
bool mDisableAdvBeingCaching
void setSprite(const size_t layer, Sprite *const sprite)
Definition: sprite.h:34
#define constexpr2
Definition: localconsts.h:49
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define A_NONNULL(...)
Definition: localconsts.h:168
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53