~ubuntu-branches/ubuntu/trusty/manaplus/trusty-proposed

« back to all changes in this revision

Viewing changes to src/compoundsprite.h

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-09-17 10:35:51 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130917103551-az7p3nz9jgxwqjfn
Tags: 1.3.9.15-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  The ManaPlus Client
3
 
 *  Copyright (C) 2010  The Mana Developers
4
 
 *  Copyright (C) 2011-2013  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 COMPOUNDSPRITE_H
23
 
#define COMPOUNDSPRITE_H
24
 
 
25
 
#include "sprite.h"
26
 
 
27
 
#include <list>
28
 
#include <vector>
29
 
 
30
 
#include "localconsts.h"
31
 
 
32
 
class Image;
33
 
 
34
 
typedef std::list <void*> VectorPointers;
35
 
 
36
 
class CompoundItem final
37
 
{
38
 
    public:
39
 
        CompoundItem();
40
 
 
41
 
        A_DELETE_COPY(CompoundItem)
42
 
 
43
 
        ~CompoundItem();
44
 
 
45
 
        VectorPointers data;
46
 
        Image *image;
47
 
        Image *alphaImage;
48
 
};
49
 
 
50
 
class CompoundSprite : public Sprite
51
 
{
52
 
public:
53
 
    typedef std::vector<Sprite*>::iterator SpriteIterator;
54
 
    typedef std::vector<Sprite*>::const_iterator SpriteConstIterator;
55
 
 
56
 
    CompoundSprite();
57
 
 
58
 
    A_DELETE_COPY(CompoundSprite)
59
 
 
60
 
    ~CompoundSprite();
61
 
 
62
 
    virtual bool reset() override;
63
 
 
64
 
    virtual bool play(const std::string &action) override;
65
 
 
66
 
    virtual bool update(const int time) override;
67
 
 
68
 
    virtual bool draw(Graphics *const graphics,
69
 
                      const int posX, const int posY) const override;
70
 
 
71
 
    /**
72
 
     * Gets the width in pixels of the first sprite in the list.
73
 
     */
74
 
    virtual int getWidth() const override A_WARN_UNUSED;
75
 
 
76
 
    /**
77
 
     * Gets the height in pixels of the first sprite in the list.
78
 
     */
79
 
    virtual int getHeight() const override A_WARN_UNUSED;
80
 
 
81
 
    virtual const Image *getImage() const override A_WARN_UNUSED;
82
 
 
83
 
    virtual bool setSpriteDirection(const SpriteDirection direction) override;
84
 
 
85
 
    int getNumberOfLayers() const A_WARN_UNUSED;
86
 
 
87
 
    unsigned int getCurrentFrame() const override A_WARN_UNUSED;
88
 
 
89
 
    unsigned int getFrameCount() const override A_WARN_UNUSED;
90
 
 
91
 
    size_t size() const A_WARN_UNUSED
92
 
    { return mSprites.size(); }
93
 
 
94
 
    bool empty() const A_WARN_UNUSED
95
 
    { return mSprites.empty(); }
96
 
 
97
 
    void addSprite(Sprite *const sprite);
98
 
 
99
 
    void setSprite(const int layer, Sprite *const sprite);
100
 
 
101
 
    Sprite *getSprite(int layer) const A_WARN_UNUSED
102
 
    { return mSprites.at(layer); }
103
 
 
104
 
    void removeSprite(const int layer);
105
 
 
106
 
    void clear();
107
 
 
108
 
    void ensureSize(size_t layerCount);
109
 
 
110
 
    virtual void drawSprites(Graphics *const graphics,
111
 
                             int posX, int posY) const;
112
 
 
113
 
    virtual void drawSpritesSDL(Graphics *const graphics,
114
 
                                int posX, int posY) const;
115
 
 
116
 
    /**
117
 
     * Returns the curent frame in the current animation of the given layer.
118
 
     */
119
 
    virtual unsigned int getCurrentFrame(unsigned int layer)
120
 
                                         const A_WARN_UNUSED;
121
 
 
122
 
    /**
123
 
     * Returns the frame count in the current animation of the given layer.
124
 
     */
125
 
    virtual unsigned int getFrameCount(unsigned int layer) A_WARN_UNUSED;
126
 
 
127
 
    virtual void setAlpha(float alpha) override;
128
 
 
129
 
    bool updateNumber(const unsigned num) override;
130
 
 
131
 
    static void setEnableDelay(bool b)
132
 
    { mEnableDelay = b; }
133
 
 
134
 
private:
135
 
    void redraw() const;
136
 
 
137
 
    void updateImages() const;
138
 
 
139
 
    bool updateFromCache() const;
140
 
 
141
 
    void initCurrentCacheItem() const;
142
 
 
143
 
    typedef std::list<CompoundItem*> ImagesCache;
144
 
    mutable ImagesCache imagesCache;
145
 
    mutable CompoundItem *mCacheItem;
146
 
 
147
 
    mutable Image *mImage;
148
 
    mutable Image *mAlphaImage;
149
 
 
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;
159
 
};
160
 
 
161
 
#endif  // COMPOUNDSPRITE_H