Mana
Loading...
Searching...
No Matches
progressbar.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana 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
23
24#include "graphics.h"
25
26#include "gui/gui.h"
27
28#include "resources/theme.h"
29
30#include <guichan/font.hpp>
31
33 int width, int height,
34 int color):
35 mProgressPalette(color)
36{
37 // The progress value is directly set at load time:
38 if (progress > 1.0f || progress < 0.0f)
39 progress = 1.0f;
40
41 mProgress = mProgressToGo = progress;
42
43 mColor = mColorToGo = Theme::getProgressColor(color >= 0 ? color : 0,
44 mProgress);
45
46 setSize(width, height);
47}
48
50{
52 {
53 // Smoothly changing the color for a nicer effect.
54 if (mColorToGo.r > mColor.r)
55 mColor.r++;
56 if (mColorToGo.g > mColor.g)
57 mColor.g++;
58 if (mColorToGo.b > mColor.b)
59 mColor.b++;
60 if (mColorToGo.r < mColor.r)
61 mColor.r--;
62 if (mColorToGo.g < mColor.g)
63 mColor.g--;
64 if (mColorToGo.b < mColor.b)
65 mColor.b--;
66 }
67
69 {
70 // Smoothly showing the progressbar changes.
72 mProgress = std::min(1.0f, mProgress + 0.005f);
74 mProgress = std::max(0.0f, mProgress - 0.005f);
75 }
76}
77
78void ProgressBar::draw(gcn::Graphics *graphics)
79{
81
82 gcn::Rectangle rect = getDimension();
83 rect.x = 0;
84 rect.y = 0;
85
87 if (mProgressPalette >= 0)
88 palette = static_cast<Theme::ProgressPalette>(mProgressPalette);
89
90 gui->getTheme()->drawProgressBar(static_cast<Graphics *>(graphics),
91 rect,
92 mColor,
94 mText,
95 palette);
96}
97
98void ProgressBar::setProgress(float progress)
99{
100 const float p = std::min(1.0f, std::max(0.0f, progress));
101 mProgressToGo = p;
102
103 if (!mSmoothProgress)
104 mProgress = p;
105
106 if (mProgressPalette >= 0)
108}
109
110void ProgressBar::setProgressPalette(int progressPalette)
111{
112 int oldPalette = mProgressPalette;
113 mProgressPalette = progressPalette;
114
115 if (mProgressPalette != oldPalette && mProgressPalette >= 0)
117}
118
119void ProgressBar::setColor(const gcn::Color &color)
120{
121 mColorToGo = color;
122
124 mColor = color;
125}
A central point of control for graphics.
Definition graphics.h:78
Theme * getTheme() const
The global GUI theme.
Definition gui.h:138
void setProgress(float progress)
Sets the current progress.
ProgressBar(float progress=0.0f, int width=40, int height=7, int color=-1)
Constructor, initializes the progress with the given value.
gcn::Color mColorToGo
float mProgress
std::string mText
float mProgressToGo
void setColor(const gcn::Color &color)
Change the color of the progress bar.
void draw(gcn::Graphics *graphics) override
Draws the progress bar.
void setProgressPalette(int progressPalette)
Change the ProgressPalette for this ProgressBar to follow or -1 to disable this and manage color manu...
void logic() override
Performs progress bar logic (fading colors)
int mProgressPalette
bool mSmoothProgress
bool mSmoothColorChange
gcn::Color mColor
< Entry in ProgressPalette or -1 for none.
int getGuiAlpha() const
Get the current GUI alpha value.
Definition theme.h:321
void drawProgressBar(Graphics *graphics, const gcn::Rectangle &area, const gcn::Color &color, float progress, const std::string &text=std::string(), ProgressPalette progressType=ProgressPalette::THEME_PROG_END) const
Definition theme.cpp:378
ProgressPalette
Definition theme.h:268
@ THEME_PROG_END
Definition theme.h:277
static gcn::Color getProgressColor(int type, float progress)
Definition theme.cpp:318
Graphics * graphics
Definition client.cpp:104
Gui * gui
The GUI system.
Definition gui.cpp:50