Mana
Loading...
Searching...
No Matches
compoundsprite.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2010-2012 The Mana Developers
4 *
5 * This file is part of The Mana Client.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include "sprite.h"
24
25#include <vector>
26
28{
29public:
30 CompoundSprite() = default;
32
33 bool reset();
34 bool play(const std::string &action);
35 bool update(int time);
36 bool draw(Graphics *graphics, int posX, int posY) const;
37
41 int getWidth() const { doRedraw(); return mWidth; }
42
46 int getHeight() const { doRedraw(); return mHeight; }
47
48 float getAlpha() const { return mAlpha; }
49 void setAlpha(float alpha) { mAlpha = alpha; }
50
51 bool setDirection(SpriteDirection direction);
52
53 int getNumberOfLayers() const;
54
55 int getMaxDuration() const;
56
57 size_t size() const { return mSprites.size(); }
58
59 void add(Sprite *sprite);
60 void set(int layer, Sprite *sprite);
61 void clear();
62 void ensureSize(size_t layerCount);
63
64 void doRedraw() const;
65
66private:
67 void redraw() const;
68
69 mutable Image *mImage = nullptr;
70 mutable Image *mAlphaImage = nullptr;
71
72 mutable int mWidth = 0, mHeight = 0;
73 mutable int mOffsetX = 0, mOffsetY = 0;
74
75 mutable bool mNeedsRedraw = false;
76
77 float mAlpha = 1.0f;
78 std::vector<Sprite*> mSprites;
79};
80
81inline void CompoundSprite::doRedraw() const
82{
83 if (mNeedsRedraw)
84 redraw();
85}
void add(Sprite *sprite)
void redraw() const
int getHeight() const
Gets the height in pixels of the first sprite in the list.
CompoundSprite()=default
std::vector< Sprite * > mSprites
bool draw(Graphics *graphics, int posX, int posY) const
void doRedraw() const
size_t size() const
int getNumberOfLayers() const
void setAlpha(float alpha)
bool play(const std::string &action)
void ensureSize(size_t layerCount)
void set(int layer, Sprite *sprite)
float getAlpha() const
int getWidth() const
Gets the width in pixels of the first sprite in the list.
bool setDirection(SpriteDirection direction)
bool update(int time)
int getMaxDuration() const
A central point of control for graphics.
Definition graphics.h:78
Defines a class for loading and storing images.
Definition image.h:45
Animates a sprite by adding playback state.
Definition sprite.h:37
Graphics * graphics
Definition client.cpp:104
SpriteDirection
Definition spritedef.h:74