summaryrefslogtreecommitdiff
path: root/src
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
parent0c7a1466e8c2c2dd6e15779368c87b62b2da601f (diff)
downloadmanaplus-7a7f5905cf19f6a773dcf9bab762b54c16e325f2.tar.gz
manaplus-7a7f5905cf19f6a773dcf9bab762b54c16e325f2.tar.bz2
manaplus-7a7f5905cf19f6a773dcf9bab762b54c16e325f2.tar.xz
manaplus-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')
-rw-r--r--src/gui/inventorywindow.cpp4
-rw-r--r--src/gui/ministatuswindow.cpp18
-rw-r--r--src/gui/skilldialog.cpp7
-rw-r--r--src/gui/specialswindow.cpp2
-rw-r--r--src/gui/statuswindow.cpp8
-rw-r--r--src/gui/updaterwindow.cpp2
-rw-r--r--src/gui/widgets/progressbar.cpp113
-rw-r--r--src/gui/widgets/progressbar.h20
8 files changed, 68 insertions, 106 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index ffa1f29d8..fd85b0d85 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -106,7 +106,7 @@ InventoryWindow::InventoryWindow(Inventory *const inventory):
mRetrieveButton(nullptr),
mCloseButton(nullptr),
mWeightBar(nullptr),
- mSlotsBar(new ProgressBar(0.0f, 100, 20, Theme::PROG_INVY_SLOTS)),
+ mSlotsBar(new ProgressBar(0.0f, 100, 0, Theme::PROG_INVY_SLOTS)),
mFilter(nullptr),
mSortModel(new SortListModel()),
mSortDropDown(new DropDown(mSortModel, this, "sort")),
@@ -183,7 +183,7 @@ InventoryWindow::InventoryWindow(Inventory *const inventory):
mOutfitButton = new Button(_("Outfits"), "outfit", this);
mShopButton = new Button(_("Shop"), "shop", this);
mEquipmentButton = new Button(_("Equipment"), "equipment", this);
- mWeightBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_WEIGHT);
+ mWeightBar = new ProgressBar(0.0f, 100, 0, Theme::PROG_WEIGHT);
place(0, 0, mWeightBar, 4);
mSlotsBarCell = &place(4, 0, mSlotsBar, 5);
diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp
index b219d23c7..5aa22800b 100644
--- a/src/gui/ministatuswindow.cpp
+++ b/src/gui/ministatuswindow.cpp
@@ -53,22 +53,22 @@ extern volatile int tick_time;
MiniStatusWindow::MiniStatusWindow() :
Popup("MiniStatus", "ministatus.xml"),
InventoryListener(),
- mHpBar(createBar(0, 100, 20, Theme::PROG_HP, "hp bar", _("health bar"))),
+ mHpBar(createBar(0, 100, 0, Theme::PROG_HP, "hp bar", _("health bar"))),
mMpBar(Net::getGameHandler()->canUseMagicBar()
- ? createBar(0, 100, 20, Net::getPlayerHandler()->canUseMagic()
+ ? createBar(0, 100, 0, Net::getPlayerHandler()->canUseMagic()
? Theme::PROG_MP : Theme::PROG_NO_MP, "mp bar", _("mana bar"))
: nullptr),
- mXpBar(createBar(0, 100, 20, Theme::PROG_EXP,
+ mXpBar(createBar(0, 100, 0, Theme::PROG_EXP,
"xp bar", _("experience bar"))),
- mWeightBar(createBar(0, 140, 20, Theme::PROG_WEIGHT,
+ mWeightBar(createBar(0, 140, 0, Theme::PROG_WEIGHT,
"weight bar", _("weight bar"))),
- mInvSlotsBar(createBar(0, 45, 20, Theme::PROG_INVY_SLOTS,
+ mInvSlotsBar(createBar(0, 45, 0, Theme::PROG_INVY_SLOTS,
"inventory slots bar", _("inventory slots bar"))),
- mMoneyBar(createBar(0, 130, 20, Theme::PROG_INVY_SLOTS,
+ mMoneyBar(createBar(0, 130, 0, Theme::PROG_INVY_SLOTS,
"money bar", _("money bar"))),
- mArrowsBar(createBar(0, 50, 20, Theme::PROG_INVY_SLOTS,
+ mArrowsBar(createBar(0, 50, 0, Theme::PROG_INVY_SLOTS,
"arrows bar", _("arrows bar"))),
- mStatusBar(createBar(100, 165, 20, Theme::PROG_EXP,
+ mStatusBar(createBar(100, 165, 0, Theme::PROG_EXP,
"status bar", _("status bar"))),
mTextPopup(new TextPopup),
mStatusPopup(new StatusPopup)
@@ -87,7 +87,7 @@ MiniStatusWindow::MiniStatusWindow() :
if (job)
{
- mJobBar = createBar(0, 100, 20, Theme::PROG_JOB, "job bar",
+ mJobBar = createBar(0, 100, 0, Theme::PROG_JOB, "job bar",
_("job bar"));
StatusWindow::updateJobBar(mJobBar);
}
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index e3316486f..78282ec46 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -629,13 +629,6 @@ void SkillInfo::draw(Graphics *const graphics, const int y, const int width)
}
graphics->drawText(skillLevel, width - skillLevelWidth, y);
-
- if (!skillExp.empty())
- {
- gcn::Rectangle rect(33, y + 15, width - 33, 17);
-
- ProgressBar::render(graphics, rect, color, progress, skillExp);
- }
}
SkillInfo* SkillDialog::getSkill(int id)
diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp
index eaeefcf78..0fed5da50 100644
--- a/src/gui/specialswindow.cpp
+++ b/src/gui/specialswindow.cpp
@@ -237,7 +237,7 @@ SpecialEntry::SpecialEntry(SpecialInfo *info) :
progress = static_cast<float>(info->rechargeCurrent)
/ static_cast<float>(info->rechargeNeeded);
}
- mRechargeBar = new ProgressBar(progress, 100, 10, Theme::PROG_MP);
+ mRechargeBar = new ProgressBar(progress, 100, 0, Theme::PROG_MP);
mRechargeBar->setSmoothProgress(false);
mRechargeBar->setPosition(0, 13);
add(mRechargeBar);
diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp
index 2a8c39240..08efc3efa 100644
--- a/src/gui/statuswindow.cpp
+++ b/src/gui/statuswindow.cpp
@@ -165,13 +165,13 @@ StatusWindow::StatusWindow() :
mHpBar = new ProgressBar(max ?
static_cast<float>(PlayerInfo::getAttribute(PlayerInfo::HP))
/ static_cast<float>(max):
- static_cast<float>(0), 80, 15, Theme::PROG_HP);
+ static_cast<float>(0), 80, 0, Theme::PROG_HP);
max = PlayerInfo::getAttribute(PlayerInfo::EXP_NEEDED);
mXpBar = new ProgressBar(max ?
static_cast<float>(PlayerInfo::getAttribute(PlayerInfo::EXP))
/ static_cast<float>(max):
- static_cast<float>(0), 80, 15, Theme::PROG_EXP);
+ static_cast<float>(0), 80, 0, Theme::PROG_EXP);
const bool magicBar = Net::getGameHandler()->canUseMagicBar();
const int job = Net::getPlayerHandler()->getJobLocation()
@@ -184,7 +184,7 @@ StatusWindow::StatusWindow() :
mMpBar = new ProgressBar(max ? static_cast<float>(
PlayerInfo::getAttribute(PlayerInfo::MAX_MP))
/ static_cast<float>(max) : static_cast<float>(0),
- 80, 15, Net::getPlayerHandler()->canUseMagic() ?
+ 80, 0, Net::getPlayerHandler()->canUseMagic() ?
Theme::PROG_MP : Theme::PROG_NO_MP);
}
else
@@ -214,7 +214,7 @@ StatusWindow::StatusWindow() :
{
mJobLvlLabel = new Label(strprintf(_("Job: %d"), 0));
mJobLabel = new Label(_("Job:"));
- mJobBar = new ProgressBar(0.0f, 80, 15, Theme::PROG_JOB);
+ mJobBar = new ProgressBar(0.0f, 80, 0, Theme::PROG_JOB);
place(5, 0, mJobLvlLabel, 3);
place(5, 2, mJobLabel).setPadding(3);
diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp
index 83b0756c9..23c51c109 100644
--- a/src/gui/updaterwindow.cpp
+++ b/src/gui/updaterwindow.cpp
@@ -159,7 +159,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost,
mLabel(new Label(_("Connecting..."))),
mCancelButton(new Button(_("Cancel"), "cancel", this)),
mPlayButton(new Button(_("Play"), "play", this)),
- mProgressBar(new ProgressBar(0.0, 310, 20)),
+ mProgressBar(new ProgressBar(0.0, 310, 0)),
mBrowserBox(new BrowserBox),
mScrollArea(new ScrollArea(mBrowserBox, true, "update_background.xml")),
mUpdateServerPath(mUpdateHost)
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;