GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/progressbar.h Lines: 2 3 66.7 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
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 GUI_WIDGETS_PROGRESSBAR_H
24
#define GUI_WIDGETS_PROGRESSBAR_H
25
26
#include "gui/fonts/textchunk.h"
27
28
#include "gui/widgets/widget.h"
29
30
#include "listeners/widgetlistener.h"
31
32
#include "resources/imagerect.h"
33
34
#include "localconsts.h"
35
36
class ImageCollection;
37
class Skin;
38
39
/**
40
 * A progress bar.
41
 *
42
 * \ingroup GUI
43
 */
44
class ProgressBar final : public Widget,
45
                          public WidgetListener
46
{
47
    public:
48
        /**
49
         * Constructor, initializes the progress with the given value.
50
         */
51
        ProgressBar(const Widget2 *const widget,
52
                    float progress,
53
                    const int width,
54
                    const int height,
55
                    const ProgressColorIdT backColor,
56
                    const std::string &skin,
57
                    const std::string &skinFill);
58
59
        A_DELETE_COPY(ProgressBar)
60
61
        ~ProgressBar();
62
63
        /**
64
         * Performs progress bar logic (fading colors)
65
         */
66
        void logic() override final;
67
68
        /**
69
         * Update the alpha value to the graphic components.
70
         */
71
        void updateAlpha();
72
73
        /**
74
         * Draws the progress bar.
75
         */
76
        void draw(Graphics *const graphics) override final A_NONNULL(2);
77
78
        void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
79
80
        /**
81
         * Sets the current progress.
82
         */
83
        void setProgress(const float progress);
84
85
        /**
86
         * Returns the current progress.
87
         */
88
        float getProgress() const noexcept2 A_WARN_UNUSED
89
        { return mProgress; }
90
91
        /**
92
         * Change the ProgressPalette for this ProgressBar to follow or -1 to
93
         * disable this and manage color manually.
94
         */
95
        void setProgressPalette(const ProgressColorIdT progressPalette);
96
97
        /**
98
         * Change the color of the progress bar.
99
         */
100
        void setBackgroundColor(const Color &color);
101
102
        void setColor(const Color &color1, const Color &color2);
103
104
        /**
105
         * Returns the color of the progress bar.
106
         */
107
        const Color &getBackgroundColor() const noexcept2 A_WARN_UNUSED
108
        { return mBackgroundColor; }
109
110
        /**
111
         * Sets the text shown on the progress bar.
112
         */
113
        void setText(const std::string &str);
114
115
        /**
116
         * Returns the text shown on the progress bar.
117
         */
118
        const std::string &text() const noexcept2 A_WARN_UNUSED
119
        { return mText; }
120
121
        /**
122
         * Set whether the progress is moved smoothly.
123
         */
124
        void setSmoothProgress(bool smoothProgress) noexcept2
125
2
        { mSmoothProgress = smoothProgress; }
126
127
        /**
128
         * Set whether the color changing is made smoothly.
129
         */
130
        void setSmoothColorChange(bool smoothColorChange) noexcept2
131
        { mSmoothColorChange = smoothColorChange; }
132
133
        void widgetResized(const Event &event) override final;
134
135
        void widgetMoved(const Event &event) override final;
136
137
        void widgetHidden(const Event &event) override final;
138
139
        void setPadding(unsigned int padding) noexcept2
140
32
        { mPadding = padding; }
141
142
    private:
143
        ImageRect mFillRect;
144
        TextChunk mTextChunk;
145
        Skin *mSkin;
146
        float mProgress;
147
        float mProgressToGo;
148
149
        Color mBackgroundColorToGo;
150
151
        std::string mText;
152
        ImageCollection *mVertexes A_NONNULLPOINTER;
153
        ProgressColorIdT mProgressPalette;
154
        unsigned int mPadding;
155
        unsigned int mFillPadding;
156
157
        static int mInstances;
158
        static float mAlpha;
159
160
        bool mFillImage;
161
        bool mSmoothProgress;
162
        bool mSmoothColorChange;
163
        bool mTextChanged;
164
};
165
166
#endif  // GUI_WIDGETS_PROGRESSBAR_H