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-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#ifndef GUI_WIDGETS_PROGRESSBAR_H |
25 |
|
|
#define GUI_WIDGETS_PROGRESSBAR_H |
26 |
|
|
|
27 |
|
|
#include "gui/fonts/textchunk.h" |
28 |
|
|
|
29 |
|
|
#include "gui/widgets/widget.h" |
30 |
|
|
|
31 |
|
|
#include "listeners/widgetlistener.h" |
32 |
|
|
|
33 |
|
|
#include "resources/imagerect.h" |
34 |
|
|
|
35 |
|
|
#include "localconsts.h" |
36 |
|
|
|
37 |
|
|
class ImageCollection; |
38 |
|
|
class Skin; |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* A progress bar. |
42 |
|
|
* |
43 |
|
|
* \ingroup GUI |
44 |
|
|
*/ |
45 |
|
|
class ProgressBar final : public Widget, |
46 |
|
|
public WidgetListener |
47 |
|
|
{ |
48 |
|
|
public: |
49 |
|
|
/** |
50 |
|
|
* Constructor, initializes the progress with the given value. |
51 |
|
|
*/ |
52 |
|
|
ProgressBar(const Widget2 *const widget, |
53 |
|
|
float progress, |
54 |
|
|
const int width, |
55 |
|
|
const int height, |
56 |
|
|
const ProgressColorIdT backColor, |
57 |
|
|
const std::string &skin, |
58 |
|
|
const std::string &skinFill); |
59 |
|
|
|
60 |
|
|
A_DELETE_COPY(ProgressBar) |
61 |
|
|
|
62 |
|
|
~ProgressBar() override final; |
63 |
|
|
|
64 |
|
|
/** |
65 |
|
|
* Performs progress bar logic (fading colors) |
66 |
|
|
*/ |
67 |
|
|
void logic() override final; |
68 |
|
|
|
69 |
|
|
/** |
70 |
|
|
* Update the alpha value to the graphic components. |
71 |
|
|
*/ |
72 |
|
|
void updateAlpha(); |
73 |
|
|
|
74 |
|
|
/** |
75 |
|
|
* Draws the progress bar. |
76 |
|
|
*/ |
77 |
|
|
void draw(Graphics *const graphics) override final A_NONNULL(2); |
78 |
|
|
|
79 |
|
|
void safeDraw(Graphics *const graphics) override final A_NONNULL(2); |
80 |
|
|
|
81 |
|
|
/** |
82 |
|
|
* Sets the current progress. |
83 |
|
|
*/ |
84 |
|
|
void setProgress(const float progress); |
85 |
|
|
|
86 |
|
|
/** |
87 |
|
|
* Returns the current progress. |
88 |
|
|
*/ |
89 |
|
|
float getProgress() const noexcept2 A_WARN_UNUSED |
90 |
|
|
{ return mProgress; } |
91 |
|
|
|
92 |
|
|
/** |
93 |
|
|
* Change the ProgressPalette for this ProgressBar to follow or -1 to |
94 |
|
|
* disable this and manage color manually. |
95 |
|
|
*/ |
96 |
|
|
void setProgressPalette(const ProgressColorIdT progressPalette); |
97 |
|
|
|
98 |
|
|
/** |
99 |
|
|
* Change the color of the progress bar. |
100 |
|
|
*/ |
101 |
|
|
void setBackgroundColor(const Color &color); |
102 |
|
|
|
103 |
|
|
void setColor(const Color &color1, const Color &color2); |
104 |
|
|
|
105 |
|
|
/** |
106 |
|
|
* Returns the color of the progress bar. |
107 |
|
|
*/ |
108 |
|
|
const Color &getBackgroundColor() const noexcept2 A_WARN_UNUSED |
109 |
|
|
{ return mBackgroundColor; } |
110 |
|
|
|
111 |
|
|
/** |
112 |
|
|
* Sets the text shown on the progress bar. |
113 |
|
|
*/ |
114 |
|
|
void setText(const std::string &str); |
115 |
|
|
|
116 |
|
|
/** |
117 |
|
|
* Returns the text shown on the progress bar. |
118 |
|
|
*/ |
119 |
|
|
const std::string &text() const noexcept2 A_WARN_UNUSED |
120 |
|
|
{ return mText; } |
121 |
|
|
|
122 |
|
|
/** |
123 |
|
|
* Set whether the progress is moved smoothly. |
124 |
|
|
*/ |
125 |
|
|
void setSmoothProgress(bool smoothProgress) noexcept2 |
126 |
|
1 |
{ mSmoothProgress = smoothProgress; } |
127 |
|
|
|
128 |
|
|
/** |
129 |
|
|
* Set whether the color changing is made smoothly. |
130 |
|
|
*/ |
131 |
|
|
void setSmoothColorChange(bool smoothColorChange) noexcept2 |
132 |
|
|
{ mSmoothColorChange = smoothColorChange; } |
133 |
|
|
|
134 |
|
|
void widgetResized(const Event &event) override final; |
135 |
|
|
|
136 |
|
|
void widgetMoved(const Event &event) override final; |
137 |
|
|
|
138 |
|
|
void widgetHidden(const Event &event) override final; |
139 |
|
|
|
140 |
|
|
void setPadding(unsigned int padding) noexcept2 |
141 |
|
16 |
{ mPadding = padding; } |
142 |
|
|
|
143 |
|
|
private: |
144 |
|
|
ImageRect mFillRect; |
145 |
|
|
TextChunk mTextChunk; |
146 |
|
|
Skin *mSkin; |
147 |
|
|
float mProgress; |
148 |
|
|
float mProgressToGo; |
149 |
|
|
|
150 |
|
|
Color mBackgroundColorToGo; |
151 |
|
|
|
152 |
|
|
std::string mText; |
153 |
|
|
ImageCollection *mVertexes A_NONNULLPOINTER; |
154 |
|
|
ProgressColorIdT mProgressPalette; |
155 |
|
|
unsigned int mPadding; |
156 |
|
|
unsigned int mFillPadding; |
157 |
|
|
|
158 |
|
|
static int mInstances; |
159 |
|
|
static float mAlpha; |
160 |
|
|
|
161 |
|
|
bool mFillImage; |
162 |
|
|
bool mSmoothProgress; |
163 |
|
|
bool mSmoothColorChange; |
164 |
|
|
bool mTextChanged; |
165 |
|
|
}; |
166 |
|
|
|
167 |
|
|
#endif // GUI_WIDGETS_PROGRESSBAR_H |