GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/sprite/sprite.h Lines: 2 10 20.0 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
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 RESOURCES_SPRITE_SPRITE_H
24
#define RESOURCES_SPRITE_SPRITE_H
25
26
#include "resources/sprite/spritedef.h"
27
28
#include "localconsts.h"
29
30
class Graphics;
31
class Image;
32
33
class Sprite notfinal
34
{
35
    public:
36
        A_DELETE_COPY(Sprite)
37
38
        virtual ~Sprite()
39
        { }
40
41
        /**
42
         * Resets the sprite.
43
         *
44
         * @returns true if the sprite changed, false otherwise
45
         */
46
        virtual bool reset() = 0;
47
48
        /**
49
         * Plays an action using the current direction.
50
         *
51
         * @returns true if the sprite changed, false otherwise
52
         */
53
        virtual bool play(const std::string &action) = 0;
54
55
        /**
56
         * Inform the animation of the passed time so that it can output the
57
         * correct animation frame.
58
         *
59
         * @returns true if the sprite changed, false otherwise
60
         */
61
        virtual bool update(const int time) = 0;
62
63
        /**
64
         * Draw the current animation frame at the coordinates given in screen
65
         * pixels.
66
         */
67
        virtual void draw(Graphics *const graphics,
68
                          const int posX, const int posY)
69
                          const A_NONNULL(2) = 0;
70
71
        /**
72
         * Gets the width in pixels of the image of the current frame
73
         */
74
        virtual int getWidth() const A_WARN_UNUSED = 0;
75
76
        /**
77
         * Gets the height in pixels of the image of the current frame
78
         */
79
        virtual int getHeight() const A_WARN_UNUSED = 0;
80
81
        /**
82
         * Returns a reference to the current image being drawn.
83
         */
84
        virtual const Image* getImage() const A_WARN_UNUSED = 0;
85
86
        /**
87
         * Sets the direction.
88
         *
89
         * @returns true if the sprite changed, false otherwise
90
         */
91
        virtual bool setSpriteDirection(const SpriteDirection::Type
92
                                        direction) = 0;
93
94
        /**
95
         * Sets the alpha value of the animated sprite
96
         */
97
        virtual void setAlpha(float alpha)
98
        { mAlpha = alpha; }
99
100
        /**
101
         * Returns the current alpha opacity of the animated sprite.
102
         */
103
        virtual float getAlpha() const A_WARN_UNUSED
104
        { return mAlpha; }
105
106
        /**
107
         * Returns the current frame number for the sprite.
108
         */
109
        virtual unsigned int getCurrentFrame() const A_WARN_UNUSED = 0;
110
111
        /**
112
         * Returns the frame count for the sprite.
113
         */
114
        virtual unsigned int getFrameCount() const A_WARN_UNUSED = 0;
115
116
        virtual const void *getHash() const A_WARN_UNUSED
117
        { return nullptr; }
118
119
        virtual const void *getHash2() const A_WARN_UNUSED
120
        { return this; }
121
122
        virtual bool updateNumber(const unsigned num) = 0;
123
124
    protected:
125
1330
        Sprite() :
126
103
            mAlpha()
127
        {
128
        }
129
130
        float mAlpha;                  /**< The alpha opacity used to draw */
131
};
132
133
#endif  // RESOURCES_SPRITE_SPRITE_H