ManaPlus
Public Member Functions | Private Attributes | Static Private Attributes
ProgressBar Class Reference

#include <progressbar.h>

Inheritance diagram for ProgressBar:
Widget WidgetListener Widget2

Public Member Functions

 ProgressBar (const Widget2 *const widget, float progress, const int width, const int height, const ProgressColorIdT backColor, const std::string &skin, const std::string &skinFill)
 
 ~ProgressBar ()
 
void logic ()
 
void updateAlpha ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setProgress (const float progress)
 
float getProgress () const
 
void setProgressPalette (const ProgressColorIdT progressPalette)
 
void setBackgroundColor (const Color &color)
 
void setColor (const Color &color1, const Color &color2)
 
const ColorgetBackgroundColor () const
 
void setText (const std::string &str)
 
const std::string & text () const
 
void setSmoothProgress (bool smoothProgress)
 
void setSmoothColorChange (bool smoothColorChange)
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void widgetHidden (const Event &event)
 
void setPadding (unsigned int padding)
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
virtual void setFocusHandler (FocusHandler *const focusHandler)
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
virtual WidgetgetWidgetAt (int x, int y)
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual Rect getChildrenArea ()
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
virtual void moveToTop (Widget *widget)
 
virtual void moveToBottom (Widget *widget)
 
virtual void focusNext ()
 
virtual void focusPrevious ()
 
virtual void showWidgetPart (Widget *const widget, const Rect &area)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
virtual void postInit ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 

Private Attributes

ImageRect mFillRect
 
TextChunk mTextChunk
 
SkinmSkin
 
float mProgress
 
float mProgressToGo
 
Color mBackgroundColorToGo
 
std::string mText
 
ImageCollectionmVertexes
 
ProgressColorIdT mProgressPalette
 
unsigned int mPadding
 
unsigned int mFillPadding
 
bool mFillImage
 
bool mSmoothProgress
 
bool mSmoothColorChange
 
bool mTextChanged
 

Static Private Attributes

static int mInstances = 0
 
static float mAlpha = 1.0
 

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

A progress bar.

Definition at line 44 of file progressbar.h.

Constructor & Destructor Documentation

◆ ProgressBar()

ProgressBar::ProgressBar ( const Widget2 *const  widget,
float  progress,
const int  width,
const int  height,
const ProgressColorIdT  backColor,
const std::string &  skin,
const std::string &  skinFill 
)

Constructor, initializes the progress with the given value.

Definition at line 43 of file progressbar.cpp.

References Widget::addWidgetListener(), Widget::getFont(), Widget::getHeight(), Skin::getOption(), Skin::getPadding(), Theme::getProgressColor(), Widget2::getThemeColor(), Theme::getThemePath(), Theme::load(), Theme::loadRect(), Widget::mBackgroundColor, mBackgroundColorToGo, mFillImage, mFillPadding, mFillRect, Widget::mForegroundColor, Widget2::mForegroundColor2, mInstances, mPadding, mProgress, mSkin, ProgressColorId::PROG_HP, ThemeColorId::PROGRESS_BAR, ThemeColorId::PROGRESS_BAR_OUTLINE, Widget::setHeight(), setPadding(), Widget::setSize(), and theme.

49  :
50  Widget(widget),
52  mFillRect(),
53  mTextChunk(),
54  mSkin(nullptr),
55  mProgress(progress),
56  mProgressToGo(progress),
58  mText(),
60  mProgressPalette(backColor),
61  mPadding(2),
62  mFillPadding(3),
63  mFillImage(false),
64  mSmoothProgress(true),
65  mSmoothColorChange(true),
66  mTextChanged(true)
67 {
69  backColor >= ProgressColorId::PROG_HP
70  ? backColor : ProgressColorId::PROG_HP,
71  mProgress);
74  255U);
75 
76  // The progress value is directly set at load time:
77  if (mProgress > 1.0F || mProgress < 0.0F)
78  mProgress = 1.0F;
79 
81  addWidgetListener(this);
82  setSize(width, height);
83 
84  if (theme != nullptr)
85  {
86  mSkin = theme->load(skin,
87  "progressbar.xml",
88  true,
90  if (mSkin != nullptr)
91  {
93  mFillPadding = mSkin->getOption("fillPadding");
94  mFillImage = mSkin->getOption("fillImage") != 0;
95  if (mFillImage)
96  {
98  skinFill,
99  "progressbar_fill.xml",
100  0,
101  8);
102  }
103  }
104  setHeight(2 * mPadding + getFont()->getHeight() + 2);
105  }
106 
107  mInstances++;
108 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
Font * getFont() const
Definition: widget.cpp:330
unsigned int mFillPadding
Definition: progressbar.h:155
void loadRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:882
unsigned int mPadding
Definition: progressbar.h:154
ImageCollection * mVertexes
Definition: progressbar.h:152
float mProgress
Definition: progressbar.h:146
static int mInstances
Definition: progressbar.h:157
Color mBackgroundColorToGo
Definition: progressbar.h:149
Skin * mSkin
Definition: progressbar.h:145
bool mTextChanged
Definition: progressbar.h:163
static std::string getThemePath()
Definition: theme.h:66
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
TextChunk mTextChunk
Definition: progressbar.h:144
Color mForegroundColor
Definition: widget.h:1085
int getOption(const std::string &name) const
Definition: skin.h:105
int getPadding() const
Definition: skin.h:99
Color mBackgroundColor
Definition: widget.h:1090
float mProgressToGo
Definition: progressbar.h:147
bool mFillImage
Definition: progressbar.h:160
bool mSmoothColorChange
Definition: progressbar.h:162
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
std::string mText
Definition: progressbar.h:151
ImageRect mFillRect
Definition: progressbar.h:143
void setHeight(const int height)
Definition: widget.cpp:139
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:301
Theme * theme
Definition: theme.cpp:61
Color mForegroundColor2
Definition: widget2.h:112
bool mSmoothProgress
Definition: progressbar.h:161
void setPadding(unsigned int padding)
Definition: progressbar.h:139
ProgressColorIdT mProgressPalette
Definition: progressbar.h:153
int getHeight() const
Definition: widget.h:239
static Color getProgressColor(const ProgressColorIdT type, const float progress)
Definition: theme.cpp:154
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44

◆ ~ProgressBar()

ProgressBar::~ProgressBar ( )

Definition at line 110 of file progressbar.cpp.

References delete2, TextChunk::deleteImage(), gui, mFillRect, mInstances, mSkin, mTextChunk, mVertexes, Gui::removeDragged(), theme, Theme::unload(), and Theme::unloadRect().

111 {
112  if (gui != nullptr)
113  gui->removeDragged(this);
114 
115  mInstances--;
116  if (mSkin != nullptr)
117  {
118  if (theme != nullptr)
119  theme->unload(mSkin);
120  mSkin = nullptr;
121  }
125 }
ImageCollection * mVertexes
Definition: progressbar.h:152
void unload(Skin *const skin)
Definition: theme.cpp:249
Gui * gui
Definition: gui.cpp:110
static int mInstances
Definition: progressbar.h:157
Skin * mSkin
Definition: progressbar.h:145
#define delete2(var)
Definition: delete2.h:24
TextChunk mTextChunk
Definition: progressbar.h:144
ImageRect mFillRect
Definition: progressbar.h:143
Theme * theme
Definition: theme.cpp:61
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1161
void deleteImage()
Definition: textchunk.cpp:192
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:914

Member Function Documentation

◆ draw()

void ProgressBar::draw ( Graphics *const  graphics)
virtual

Draws the progress bar.

Implements Widget.

Definition at line 167 of file progressbar.cpp.

References Color::a, BLOCK_END, BLOCK_START, Graphics::calcWindow(), CAST_S32, CAST_U32, ImageCollection::clear(), TextChunk::color, TextChunk::color2, TextChunk::deleteImage(), Graphics::drawImage(), Graphics::drawTileCollection(), Graphics::fillRectangle(), Graphics::finalize(), ServerCommandType::font, Font::generate(), Skin::getBorder(), Gui::getFont(), Font::getHeight(), Graphics::getRedraw(), Font::getWidth(), gui, Rect::height, TextChunk::img, mAlpha, Widget::mBackgroundColor, Widget::mDimension, mFillImage, mFillPadding, mFillRect, Widget::mForegroundColor, Widget2::mForegroundColor2, mProgress, Widget::mRedraw, mSkin, mText, mTextChanged, mTextChunk, mVertexes, Graphics::setColor(), TextChunk::text, TextChunk::textFont, updateAlpha(), and Rect::width.

168 {
169  BLOCK_START("ProgressBar::draw")
170  if (mSkin == nullptr)
171  {
172  BLOCK_END("ProgressBar::draw")
173  return;
174  }
175 
176  updateAlpha();
177  mBackgroundColor.a = CAST_U32(mAlpha * 255);
178 
179  if (mRedraw || graphics->getRedraw())
180  {
181  mRedraw = false;
182  mVertexes->clear();
183  graphics->calcWindow(mVertexes, 0, 0,
185  if (mFillImage)
186  {
187  const unsigned int pad = 2 * mFillPadding;
188  const int maxWidth = mDimension.width - pad;
189  int width = CAST_S32(mProgress
190  * static_cast<float>(maxWidth));
191  if (width > 0)
192  {
193  if (width > maxWidth)
194  width = maxWidth;
196  width, mDimension.height - pad, mFillRect);
197  }
198  }
199  graphics->finalize(mVertexes);
200  }
201 
202  graphics->drawTileCollection(mVertexes);
203 
204  // The bar
205  if (!mFillImage && mProgress > 0)
206  {
207  graphics->setColor(mBackgroundColor);
208  const unsigned int pad = 2 * mFillPadding;
209  const int maxWidth = mDimension.width - pad;
210  int width = CAST_S32(mProgress * static_cast<float>(maxWidth));
211  if (width > 0)
212  {
213  if (width > maxWidth)
214  width = maxWidth;
216  width, mDimension.height - pad));
217  }
218  }
219 
220  // The label
221  if (!mText.empty())
222  {
223  Font *const font = gui->getFont();
224  if (mTextChanged)
225  {
231  font->generate(mTextChunk);
232  mTextChanged = false;
233  }
234 
235  const Image *const image = mTextChunk.img;
236  if (image != nullptr)
237  {
238  const int textX = (mDimension.width - font->getWidth(mText)) / 2;
239  const int textY = (mDimension.height - font->getHeight()) / 2;
240  graphics->drawImage(image, textX, textY);
241  }
242  }
243  BLOCK_END("ProgressBar::draw")
244 }
#define CAST_U32
Definition: cast.h:30
unsigned int mFillPadding
Definition: progressbar.h:155
int width
Definition: rect.h:218
std::string text
Definition: textchunk.h:64
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
ImageCollection * mVertexes
Definition: progressbar.h:152
float mProgress
Definition: progressbar.h:146
Gui * gui
Definition: gui.cpp:110
Definition: font.h:88
Definition: rect.h:72
Skin * mSkin
Definition: progressbar.h:145
#define BLOCK_START(name)
Definition: perfomance.h:78
bool mTextChanged
Definition: progressbar.h:163
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Font * getFont() const
Definition: gui.h:159
TextChunk mTextChunk
Definition: progressbar.h:144
Color mForegroundColor
Definition: widget.h:1085
Font * textFont
Definition: textchunk.h:63
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:464
Color mBackgroundColor
Definition: widget.h:1090
virtual void setColor(const Color &color)
Definition: graphics.h:319
#define CAST_S32
Definition: cast.h:29
const ImageRect & getBorder() const
Definition: skin.h:67
bool mFillImage
Definition: progressbar.h:160
int height
Definition: rect.h:223
std::string mText
Definition: progressbar.h:151
ImageRect mFillRect
Definition: progressbar.h:143
virtual void fillRectangle(const Rect &rectangle)=0
Color mForegroundColor2
Definition: widget2.h:112
Image * img
Definition: textchunk.h:62
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
int getWidth(const std::string &text) const
Definition: font.cpp:333
bool mRedraw
Definition: widget.h:1163
Definition: image.h:61
Color color
Definition: textchunk.h:65
int getHeight() const
Definition: font.cpp:361
void deleteImage()
Definition: textchunk.cpp:192
Color color2
Definition: textchunk.h:66
Rect mDimension
Definition: widget.h:1100
static float mAlpha
Definition: progressbar.h:158
void updateAlpha()
virtual void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
void generate(TextChunk &chunk)
Definition: font.cpp:429

◆ getBackgroundColor()

const Color& ProgressBar::getBackgroundColor ( ) const
inline

Returns the color of the progress bar.

Definition at line 107 of file progressbar.h.

References Widget::mBackgroundColor, setText(), and ServerCommandType::str.

108  { return mBackgroundColor; }
Color mBackgroundColor
Definition: widget.h:1090

◆ getProgress()

float ProgressBar::getProgress ( ) const
inline

Returns the current progress.

Definition at line 88 of file progressbar.h.

References mProgress, setBackgroundColor(), setColor(), and setProgressPalette().

89  { return mProgress; }
float mProgress
Definition: progressbar.h:146

◆ logic()

void ProgressBar::logic ( )
virtual

Performs progress bar logic (fading colors)

Reimplemented from Widget.

Definition at line 127 of file progressbar.cpp.

References Color::b, BLOCK_END, BLOCK_START, Color::g, Widget::mBackgroundColor, mBackgroundColorToGo, mProgress, mProgressToGo, Widget::mRedraw, mSmoothColorChange, mSmoothProgress, and Color::r.

128 {
129  BLOCK_START("ProgressBar::logic")
131  {
132  // Smoothly changing the color for a nicer effect.
133  if (mBackgroundColorToGo.r > mBackgroundColor.r)
134  mBackgroundColor.r++;
135  if (mBackgroundColorToGo.g > mBackgroundColor.g)
136  mBackgroundColor.g++;
137  if (mBackgroundColorToGo.b > mBackgroundColor.b)
138  mBackgroundColor.b++;
139  if (mBackgroundColorToGo.r < mBackgroundColor.r)
140  mBackgroundColor.r--;
141  if (mBackgroundColorToGo.g < mBackgroundColor.g)
142  mBackgroundColor.g--;
143  if (mBackgroundColorToGo.b < mBackgroundColor.b)
144  mBackgroundColor.b--;
145  mRedraw = true;
146  }
147 
149  {
150  // Smoothly showing the progressbar changes.
151  if (mProgressToGo > mProgress)
152  mProgress = std::min(1.0F, mProgress + 0.005F);
153  if (mProgressToGo < mProgress)
154  mProgress = std::max(0.0F, mProgress - 0.005F);
155  mRedraw = true;
156  }
157  BLOCK_END("ProgressBar::logic")
158 }
float mProgress
Definition: progressbar.h:146
Color mBackgroundColorToGo
Definition: progressbar.h:149
unsigned int g
Definition: color.h:239
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Color mBackgroundColor
Definition: widget.h:1090
unsigned int b
Definition: color.h:244
float mProgressToGo
Definition: progressbar.h:147
bool mSmoothColorChange
Definition: progressbar.h:162
bool mSmoothProgress
Definition: progressbar.h:161
bool mRedraw
Definition: widget.h:1163
unsigned int r
Definition: color.h:234

◆ safeDraw()

void ProgressBar::safeDraw ( Graphics *const  graphics)
virtual

Implements Widget.

Definition at line 246 of file progressbar.cpp.

References Color::a, BLOCK_END, BLOCK_START, CAST_S32, CAST_U32, TextChunk::color, TextChunk::color2, TextChunk::deleteImage(), Graphics::drawImage(), Graphics::drawImageRect(), Graphics::fillRectangle(), ServerCommandType::font, Font::generate(), Skin::getBorder(), Gui::getFont(), Font::getHeight(), Font::getWidth(), gui, Rect::height, TextChunk::img, mAlpha, Widget::mBackgroundColor, Widget::mDimension, mFillImage, mFillPadding, mFillRect, Widget::mForegroundColor, Widget2::mForegroundColor2, mProgress, mSkin, mText, mTextChanged, mTextChunk, Graphics::setColor(), TextChunk::text, TextChunk::textFont, updateAlpha(), and Rect::width.

247 {
248  BLOCK_START("ProgressBar::safeDraw")
249  if (mSkin == nullptr)
250  {
251  BLOCK_END("ProgressBar::safeDraw")
252  return;
253  }
254 
255  updateAlpha();
256  mBackgroundColor.a = CAST_U32(mAlpha * 255);
257 
258  graphics->drawImageRect(0, 0, mDimension.width, mDimension.height,
259  mSkin->getBorder());
260  if (mFillImage)
261  {
262  const unsigned int pad = 2 * mFillPadding;
263  const int maxWidth = mDimension.width - pad;
264  int width = CAST_S32(mProgress
265  * static_cast<float>(maxWidth));
266  if (width > 0)
267  {
268  if (width > maxWidth)
269  width = maxWidth;
271  width, mDimension.height - pad, mFillRect);
272  }
273  }
274 
275  // The bar
276  if (!mFillImage && mProgress > 0)
277  {
278  graphics->setColor(mBackgroundColor);
279  const unsigned int pad = 2 * mFillPadding;
280  const int maxWidth = mDimension.width - pad;
281  int width = CAST_S32(mProgress * static_cast<float>(maxWidth));
282  if (width > 0)
283  {
284  if (width > maxWidth)
285  width = maxWidth;
287  width, mDimension.height - pad));
288  }
289  }
290 
291  // The label
292  if (!mText.empty())
293  {
294  Font *const font = gui->getFont();
295  if (mTextChanged)
296  {
302  font->generate(mTextChunk);
303  mTextChanged = false;
304  }
305 
306  const Image *const image = mTextChunk.img;
307  if (image != nullptr)
308  {
309  const int textX = (mDimension.width - font->getWidth(mText)) / 2;
310  const int textY = (mDimension.height - font->getHeight()) / 2;
311  graphics->drawImage(image, textX, textY);
312  }
313  }
314  BLOCK_END("ProgressBar::safeDraw")
315 }
#define CAST_U32
Definition: cast.h:30
unsigned int mFillPadding
Definition: progressbar.h:155
int width
Definition: rect.h:218
std::string text
Definition: textchunk.h:64
float mProgress
Definition: progressbar.h:146
Gui * gui
Definition: gui.cpp:110
Definition: font.h:88
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
Definition: rect.h:72
Skin * mSkin
Definition: progressbar.h:145
#define BLOCK_START(name)
Definition: perfomance.h:78
bool mTextChanged
Definition: progressbar.h:163
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
Font * getFont() const
Definition: gui.h:159
TextChunk mTextChunk
Definition: progressbar.h:144
Color mForegroundColor
Definition: widget.h:1085
Font * textFont
Definition: textchunk.h:63
Color mBackgroundColor
Definition: widget.h:1090
virtual void setColor(const Color &color)
Definition: graphics.h:319
#define CAST_S32
Definition: cast.h:29
bool mFillImage
Definition: progressbar.h:160
int height
Definition: rect.h:223
std::string mText
Definition: progressbar.h:151
void drawImageRect(int x, int y, int w, int h, const ImageRect &restrict imgRect) restrict2 override final
ImageRect mFillRect
Definition: progressbar.h:143
virtual void fillRectangle(const Rect &rectangle)=0
Color mForegroundColor2
Definition: widget2.h:112
Image * img
Definition: textchunk.h:62
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
int getWidth(const std::string &text) const
Definition: font.cpp:333
Definition: image.h:61
Color color
Definition: textchunk.h:65
int getHeight() const
Definition: font.cpp:361
void deleteImage()
Definition: textchunk.cpp:192
Color color2
Definition: textchunk.h:66
Rect mDimension
Definition: widget.h:1100
static float mAlpha
Definition: progressbar.h:158
void updateAlpha()
void generate(TextChunk &chunk)
Definition: font.cpp:429

◆ setBackgroundColor()

void ProgressBar::setBackgroundColor ( const Color color)

Change the color of the progress bar.

Definition at line 347 of file progressbar.cpp.

References Widget::mBackgroundColor, mBackgroundColorToGo, Widget::mRedraw, and mSmoothColorChange.

Referenced by getProgress(), and StatusWindow::updateStatusBar().

348 {
349  mRedraw = true;
350  mBackgroundColorToGo = color;
351 
352  if (!mSmoothColorChange)
353  mBackgroundColor = color;
354 }
Color mBackgroundColorToGo
Definition: progressbar.h:149
Color mBackgroundColor
Definition: widget.h:1090
bool mSmoothColorChange
Definition: progressbar.h:162
bool mRedraw
Definition: widget.h:1163

◆ setColor()

void ProgressBar::setColor ( const Color color1,
const Color color2 
)

◆ setPadding()

void ProgressBar::setPadding ( unsigned int  padding)
inline

Definition at line 139 of file progressbar.h.

References mPadding.

Referenced by ProgressBar().

140  { mPadding = padding; }
unsigned int mPadding
Definition: progressbar.h:154

◆ setProgress()

void ProgressBar::setProgress ( const float  progress)

Sets the current progress.

Definition at line 317 of file progressbar.cpp.

References Theme::getProgressColor(), mBackgroundColorToGo, mProgress, mProgressPalette, mProgressToGo, Widget::mRedraw, mSmoothProgress, and ProgressColorId::PROG_HP.

Referenced by UpdaterWindow::logic(), InventoryWindow::slotsChanged(), StatusWindow::updateHPBar(), StatusWindow::updateInvSlotsBar(), StatusWindow::updateMoneyBar(), StatusWindow::updateMPBar(), StatusWindow::updateProgressBar(), StatusWindow::updateStatusBar(), InventoryWindow::updateWeight(), and StatusWindow::updateWeightBar().

318 {
319  const float p = std::min(1.0F, std::max(0.0F, progress));
320  mProgressToGo = p;
321  mRedraw = true;
322 
323  if (!mSmoothProgress)
324  mProgress = p;
325 
327  {
329  mProgressPalette, progress);
330  }
331 }
float mProgress
Definition: progressbar.h:146
Color mBackgroundColorToGo
Definition: progressbar.h:149
float mProgressToGo
Definition: progressbar.h:147
bool mSmoothProgress
Definition: progressbar.h:161
bool mRedraw
Definition: widget.h:1163
ProgressColorIdT mProgressPalette
Definition: progressbar.h:153
static Color getProgressColor(const ProgressColorIdT type, const float progress)
Definition: theme.cpp:154

◆ setProgressPalette()

void ProgressBar::setProgressPalette ( const ProgressColorIdT  progressPalette)

Change the ProgressPalette for this ProgressBar to follow or -1 to disable this and manage color manually.

Definition at line 333 of file progressbar.cpp.

References Theme::getProgressColor(), mBackgroundColorToGo, mProgressPalette, mProgressToGo, Widget::mRedraw, and ProgressColorId::PROG_HP.

Referenced by getProgress(), and StatusWindow::updateMPBar().

334 {
335  const ProgressColorIdT oldPalette = mProgressPalette;
336  mProgressPalette = progressPalette;
337  mRedraw = true;
338 
339  if (mProgressPalette != oldPalette &&
341  {
344  }
345 }
ProgressColorId ::T ProgressColorIdT
Color mBackgroundColorToGo
Definition: progressbar.h:149
float mProgressToGo
Definition: progressbar.h:147
bool mRedraw
Definition: widget.h:1163
ProgressColorIdT mProgressPalette
Definition: progressbar.h:153
static Color getProgressColor(const ProgressColorIdT type, const float progress)
Definition: theme.cpp:154

◆ setSmoothColorChange()

void ProgressBar::setSmoothColorChange ( bool  smoothColorChange)
inline

Set whether the color changing is made smoothly.

Definition at line 130 of file progressbar.h.

References mSmoothColorChange, widgetHidden(), widgetMoved(), and widgetResized().

131  { mSmoothColorChange = smoothColorChange; }
bool mSmoothColorChange
Definition: progressbar.h:162

◆ setSmoothProgress()

void ProgressBar::setSmoothProgress ( bool  smoothProgress)
inline

Set whether the progress is moved smoothly.

Definition at line 124 of file progressbar.h.

References mSmoothProgress.

Referenced by UpdaterWindow::UpdaterWindow().

125  { mSmoothProgress = smoothProgress; }
bool mSmoothProgress
Definition: progressbar.h:161

◆ setText()

void ProgressBar::setText ( const std::string &  str)

◆ text()

const std::string& ProgressBar::text ( ) const
inline

Returns the text shown on the progress bar.

Definition at line 118 of file progressbar.h.

References mText.

Referenced by PopupMenu::showPopup().

119  { return mText; }
std::string mText
Definition: progressbar.h:151

◆ updateAlpha()

void ProgressBar::updateAlpha ( )

Update the alpha value to the graphic components.

Definition at line 160 of file progressbar.cpp.

References Theme::getMinimumOpacity(), Settings::guiAlpha, mAlpha, settings, and theme.

Referenced by draw(), and safeDraw().

161 {
162  const float alpha = std::max(settings.guiAlpha,
164  mAlpha = alpha;
165 }
float getMinimumOpacity() const
Definition: theme.h:123
Settings settings
Definition: settings.cpp:31
Theme * theme
Definition: theme.cpp:61
float guiAlpha
Definition: settings.h:129
static float mAlpha
Definition: progressbar.h:158

◆ widgetHidden()

void ProgressBar::widgetHidden ( const Event event)
virtual

Invoked when a widget is hidden, i.e it's set to be not visible.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 382 of file progressbar.cpp.

References TextChunk::deleteImage(), mTextChanged, and mTextChunk.

Referenced by setSmoothColorChange().

383 {
384  mTextChanged = true;
386 }
bool mTextChanged
Definition: progressbar.h:163
TextChunk mTextChunk
Definition: progressbar.h:144
void deleteImage()
Definition: textchunk.cpp:192

◆ widgetMoved()

void ProgressBar::widgetMoved ( const Event event)
virtual

Invoked when a widget is moved.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 368 of file progressbar.cpp.

References Widget::mRedraw.

Referenced by setSmoothColorChange().

369 {
370  mRedraw = true;
371 }
bool mRedraw
Definition: widget.h:1163

◆ widgetResized()

void ProgressBar::widgetResized ( const Event event)
virtual

Invoked when a widget changes its size.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 363 of file progressbar.cpp.

References Widget::mRedraw.

Referenced by setSmoothColorChange().

364 {
365  mRedraw = true;
366 }
bool mRedraw
Definition: widget.h:1163

Field Documentation

◆ mAlpha

float ProgressBar::mAlpha = 1.0
staticprivate

Definition at line 158 of file progressbar.h.

Referenced by draw(), safeDraw(), and updateAlpha().

◆ mBackgroundColorToGo

Color ProgressBar::mBackgroundColorToGo
private

◆ mFillImage

bool ProgressBar::mFillImage
private

Definition at line 160 of file progressbar.h.

Referenced by draw(), ProgressBar(), and safeDraw().

◆ mFillPadding

unsigned int ProgressBar::mFillPadding
private

Definition at line 155 of file progressbar.h.

Referenced by draw(), ProgressBar(), and safeDraw().

◆ mFillRect

ImageRect ProgressBar::mFillRect
private

Definition at line 143 of file progressbar.h.

Referenced by draw(), ProgressBar(), safeDraw(), and ~ProgressBar().

◆ mInstances

int ProgressBar::mInstances = 0
staticprivate

Definition at line 157 of file progressbar.h.

Referenced by ProgressBar(), and ~ProgressBar().

◆ mPadding

unsigned int ProgressBar::mPadding
private

Definition at line 154 of file progressbar.h.

Referenced by ProgressBar(), and setPadding().

◆ mProgress

float ProgressBar::mProgress
private

Definition at line 146 of file progressbar.h.

Referenced by draw(), getProgress(), logic(), ProgressBar(), safeDraw(), and setProgress().

◆ mProgressPalette

ProgressColorIdT ProgressBar::mProgressPalette
private

Definition at line 153 of file progressbar.h.

Referenced by setProgress(), and setProgressPalette().

◆ mProgressToGo

float ProgressBar::mProgressToGo
private

Definition at line 147 of file progressbar.h.

Referenced by logic(), setProgress(), and setProgressPalette().

◆ mSkin

Skin* ProgressBar::mSkin
private

Definition at line 145 of file progressbar.h.

Referenced by draw(), ProgressBar(), safeDraw(), and ~ProgressBar().

◆ mSmoothColorChange

bool ProgressBar::mSmoothColorChange
private

Definition at line 162 of file progressbar.h.

Referenced by logic(), setBackgroundColor(), and setSmoothColorChange().

◆ mSmoothProgress

bool ProgressBar::mSmoothProgress
private

Definition at line 161 of file progressbar.h.

Referenced by logic(), setProgress(), and setSmoothProgress().

◆ mText

std::string ProgressBar::mText
private

Definition at line 151 of file progressbar.h.

Referenced by draw(), safeDraw(), setText(), and text().

◆ mTextChanged

bool ProgressBar::mTextChanged
private

Definition at line 163 of file progressbar.h.

Referenced by draw(), safeDraw(), setColor(), setText(), and widgetHidden().

◆ mTextChunk

TextChunk ProgressBar::mTextChunk
private

Definition at line 144 of file progressbar.h.

Referenced by draw(), safeDraw(), widgetHidden(), and ~ProgressBar().

◆ mVertexes

ImageCollection* ProgressBar::mVertexes
private

Definition at line 152 of file progressbar.h.

Referenced by draw(), and ~ProgressBar().


The documentation for this class was generated from the following files: