summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-10-04 17:00:40 +0300
committerAndrei Karas <akaras@inbox.ru>2012-10-04 17:30:17 +0300
commit7a7f5905cf19f6a773dcf9bab762b54c16e325f2 (patch)
tree4c891cfaa2eadeecd0685782d8cf561c2a79dbf8 /src/gui/widgets
parent0c7a1466e8c2c2dd6e15779368c87b62b2da601f (diff)
downloadmanaverse-7a7f5905cf19f6a773dcf9bab762b54c16e325f2.tar.gz
manaverse-7a7f5905cf19f6a773dcf9bab762b54c16e325f2.tar.bz2
manaverse-7a7f5905cf19f6a773dcf9bab762b54c16e325f2.tar.xz
manaverse-7a7f5905cf19f6a773dcf9bab762b54c16e325f2.zip
Add support for padding in progress bars.
Also fixed progress bars size. New progress bar attributes: fillPadding - padding for will rectangle padding - normal padding for bar
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/progressbar.cpp113
-rw-r--r--src/gui/widgets/progressbar.h20
2 files changed, 51 insertions, 82 deletions
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
index c85eb6220..6dc6346b8 100644
--- a/src/gui/widgets/progressbar.cpp
+++ b/src/gui/widgets/progressbar.cpp
@@ -37,7 +37,6 @@
#include "debug.h"
-ImageRect ProgressBar::mBorder;
int ProgressBar::mInstances = 0;
float ProgressBar::mAlpha = 1.0;
@@ -52,7 +51,9 @@ ProgressBar::ProgressBar(float progress,
mProgressPalette(color),
mSmoothColorChange(true),
mVertexes(new GraphicsVertexes()),
- mRedraw(true)
+ mRedraw(true),
+ mPadding(2),
+ mFillPadding(3)
{
// The progress value is directly set at load time:
if (progress > 1.0f || progress < 0.0f)
@@ -63,13 +64,12 @@ ProgressBar::ProgressBar(float progress,
addWidgetListener(this);
setSize(width, height);
- if (mInstances == 0)
+ if (Theme::instance())
{
- for (int f = 0; f < 9; f ++)
- mBorder.grid[f] = nullptr;
-
- if (Theme::instance())
- Theme::instance()->loadRect(mBorder, "progressbar.xml", "");
+ mSkin = Theme::instance()->load("progressbar.xml", "");
+ setPadding(mSkin->getPadding());
+ mFillPadding = mSkin->getOption("fillPadding");
+ setHeight(2 * mPadding + getFont()->getHeight() + 2);
}
mInstances++;
@@ -78,9 +78,11 @@ ProgressBar::ProgressBar(float progress,
ProgressBar::~ProgressBar()
{
mInstances--;
- if (mInstances == 0 && Theme::instance())
+ if (mSkin)
{
- Theme::instance()->unloadRect(mBorder);
+ if (Theme::instance())
+ Theme::instance()->unload(mSkin);
+ mSkin = nullptr;
}
delete mVertexes;
mVertexes = nullptr;
@@ -123,11 +125,14 @@ void ProgressBar::updateAlpha()
if (mAlpha != alpha)
{
mAlpha = alpha;
+/*
+ ImageRect &rect = mSkin->getBorder();
for (int i = 0; i < 9; i++)
{
- if (mBorder.grid[i])
- mBorder.grid[i]->setAlpha(mAlpha);
+ if (rect.grid[i])
+ rect.grid[i]->setAlpha(mAlpha);
}
+*/
}
}
@@ -138,12 +143,7 @@ void ProgressBar::draw(gcn::Graphics *graphics)
mColor.a = static_cast<int>(mAlpha * 255);
- gcn::Rectangle rect = getDimension();
- rect.x = 0;
- rect.y = 0;
-
- render(static_cast<Graphics*>(graphics), rect, mColor,
- mProgress, mText, mVertexes, &mRedraw);
+ render(static_cast<Graphics*>(graphics));
}
void ProgressBar::setProgress(const float progress)
@@ -175,73 +175,46 @@ void ProgressBar::setColor(const gcn::Color &color)
mColor = color;
}
-void ProgressBar::render(Graphics *graphics, const gcn::Rectangle &area,
- const gcn::Color &color, const float progress,
- const std::string &text, GraphicsVertexes *const vert,
- bool *const redraw)
+void ProgressBar::render(Graphics *graphics)
{
+ if (!mSkin)
+ return;
+
gcn::Font *const oldFont = graphics->getFont();
const gcn::Color oldColor = graphics->getColor();
- if (*redraw || graphics->getRedraw())
+ if (mRedraw || graphics->getRedraw())
{
- *redraw = false;
- graphics->calcWindow(vert, area.x, area.y,
- area.width, area.height, mBorder);
+ mRedraw = false;
+ graphics->calcWindow(mVertexes, 0, 0,
+ mDimension.width, mDimension.height, mSkin->getBorder());
}
- graphics->drawImageRect2(vert, mBorder);
+ graphics->drawImageRect2(mVertexes, mSkin->getBorder());
// The bar
- if (progress > 0)
+ if (mProgress > 0)
{
- graphics->setColor(color);
- graphics->fillRectangle(gcn::Rectangle(area.x + 4, area.y + 4,
- static_cast<int>(progress * static_cast<float>(area.width - 8)),
- area.height - 8));
- }
-
- // The label
- if (!text.empty())
- {
- const int textX = area.x + area.width / 2;
- const int textY = area.y + (area.height - boldFont->getHeight()) / 2;
-
- TextRenderer::renderText(graphics, text, textX, textY,
- gcn::Graphics::CENTER,
- Theme::getThemeColor(Theme::PROGRESS_BAR),
- gui->getFont(), true, false);
- }
-
- graphics->setFont(oldFont);
- graphics->setColor(oldColor);
-}
-
-void ProgressBar::render(Graphics *graphics, const gcn::Rectangle &area,
- const gcn::Color &color, const float progress,
- const std::string &text)
-{
- gcn::Font *const oldFont = graphics->getFont();
- const gcn::Color oldColor = graphics->getColor();
-
- graphics->drawImageRect(area, mBorder);
-
- // The bar
- if (progress > 0)
- {
- graphics->setColor(color);
- graphics->fillRectangle(gcn::Rectangle(area.x + 4, area.y + 4,
- static_cast<int>(progress * static_cast<float>(area.width - 8)),
- area.height - 8));
+ graphics->setColor(mColor);
+ const unsigned int pad = 2 * mFillPadding;
+ const int maxWidth = mDimension.width - pad;
+ int width = static_cast<int>(mProgress * static_cast<float>(maxWidth));
+ if (width > 0)
+ {
+ if (width > maxWidth)
+ width = maxWidth;
+ graphics->fillRectangle(gcn::Rectangle(mFillPadding, mFillPadding,
+ width, mDimension.height - pad));
+ }
}
// The label
- if (!text.empty())
+ if (!mText.empty())
{
- const int textX = area.x + area.width / 2;
- const int textY = area.y + (area.height - boldFont->getHeight()) / 2;
+ const int textX = mDimension.width / 2;
+ const int textY = (mDimension.height - boldFont->getHeight()) / 2;
- TextRenderer::renderText(graphics, text, textX, textY,
+ TextRenderer::renderText(graphics, mText, textX, textY,
gcn::Graphics::CENTER,
Theme::getThemeColor(Theme::PROGRESS_BAR),
gui->getFont(), true, false);
diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h
index e163fe66c..3b8b976cf 100644
--- a/src/gui/widgets/progressbar.h
+++ b/src/gui/widgets/progressbar.h
@@ -32,6 +32,7 @@
class Graphics;
class GraphicsVertexes;
class ImageRect;
+class Skin;
/**
* A progress bar.
@@ -120,23 +121,17 @@ class ProgressBar final : public gcn::Widget, public gcn::WidgetListener
/**
* Renders a progressbar with the given properties.
*/
- static void render(Graphics *graphics, const gcn::Rectangle &area,
- const gcn::Color &color, const float progress,
- const std::string &text,
- GraphicsVertexes *const vert, bool *const redraw);
-
- /**
- * Renders a progressbar with the given properties.
- */
- static void render(Graphics *graphics, const gcn::Rectangle &area,
- const gcn::Color &color, const float progress,
- const std::string &text = "");
+ void render(Graphics *graphics);
void widgetResized(const gcn::Event &event) override;
void widgetMoved(const gcn::Event &event) override;
+ void setPadding(unsigned int padding)
+ { mPadding = padding; }
+
private:
+ Skin *mSkin;
float mProgress;
float mProgressToGo;
bool mSmoothProgress;
@@ -149,8 +144,9 @@ class ProgressBar final : public gcn::Widget, public gcn::WidgetListener
std::string mText;
GraphicsVertexes *mVertexes;
bool mRedraw;
+ unsigned int mPadding;
+ unsigned int mFillPadding;
- static ImageRect mBorder;
static int mInstances;
static float mAlpha;