summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-01-25 21:30:47 +0100
committerIra Rice <irarice@gmail.com>2009-01-25 17:35:59 -0700
commit537d390ae65e9b8a2701c04baa22962f7db0f093 (patch)
tree10a14a57ca6d61e4660cf68c15ea68652d81bc41
parentedd500dd27bb648840abfe1cecb0767d7b2ba3ae (diff)
downloadMana-537d390ae65e9b8a2701c04baa22962f7db0f093.tar.gz
Mana-537d390ae65e9b8a2701c04baa22962f7db0f093.tar.bz2
Mana-537d390ae65e9b8a2701c04baa22962f7db0f093.tar.xz
Mana-537d390ae65e9b8a2701c04baa22962f7db0f093.zip
Made the labels on the progress bars more readable
-rw-r--r--src/gui/button.cpp20
-rw-r--r--src/gui/button.h7
-rw-r--r--src/gui/ministatus.cpp30
-rw-r--r--src/gui/ministatus.h11
-rw-r--r--src/gui/progressbar.cpp24
-rw-r--r--src/gui/progressbar.h33
6 files changed, 67 insertions, 58 deletions
diff --git a/src/gui/button.cpp b/src/gui/button.cpp
index 04b96810..9b624015 100644
--- a/src/gui/button.cpp
+++ b/src/gui/button.cpp
@@ -19,12 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <algorithm>
-
-#include <guichan/exception.hpp>
-#include <guichan/graphics.hpp>
-#include <guichan/imagefont.hpp>
-
#include "button.h"
#include "../graphics.h"
@@ -34,6 +28,12 @@
#include "../utils/dtor.h"
+#include <guichan/exception.hpp>
+#include <guichan/graphics.hpp>
+#include <guichan/font.hpp>
+
+#include <algorithm>
+
int Button::mInstances = 0;
enum{
@@ -52,10 +52,10 @@ struct ButtonData
};
static ButtonData const data[BUTTON_COUNT] = {
- {"graphics/gui/button.png", 0, 0},
- {"graphics/gui/buttonhi.png", 9, 4},
- {"graphics/gui/buttonpress.png", 16, 19},
- {"graphics/gui/button_disabled.png", 25, 23}
+ { "graphics/gui/button.png", 0, 0 },
+ { "graphics/gui/buttonhi.png", 9, 4 },
+ { "graphics/gui/buttonpress.png", 16, 19 },
+ { "graphics/gui/button_disabled.png", 25, 23 }
};
ImageRect Button::button[BUTTON_COUNT];
diff --git a/src/gui/button.h b/src/gui/button.h
index 2999a737..51f6cffc 100644
--- a/src/gui/button.h
+++ b/src/gui/button.h
@@ -35,7 +35,8 @@ class ImageRect;
*
* \ingroup GUI
*/
-class Button : public gcn::Button {
+class Button : public gcn::Button
+{
public:
/**
* Default constructor.
@@ -46,7 +47,7 @@ class Button : public gcn::Button {
* Constructor, sets the caption of the button to the given string and
* adds the given action listener.
*/
- Button(const std::string& caption, const std::string &actionEventId,
+ Button(const std::string &caption, const std::string &actionEventId,
gcn::ActionListener *listener);
/**
@@ -57,7 +58,7 @@ class Button : public gcn::Button {
/**
* Draws the button.
*/
- void draw(gcn::Graphics* graphics);
+ void draw(gcn::Graphics *graphics);
/**
* Enable/Disable highlighting
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp
index 6e162141..4c22e63d 100644
--- a/src/gui/ministatus.cpp
+++ b/src/gui/ministatus.cpp
@@ -19,8 +19,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <guichan/widgets/label.hpp>
-
#include "gui.h"
#include "ministatus.h"
#include "progressbar.h"
@@ -42,36 +40,14 @@ MiniStatusWindow::MiniStatusWindow():
mHpBar = new ProgressBar(1.0f, 100, 20, 0, 171, 34);
mMpBar = new ProgressBar(1.0f, 100, 20, 26, 102, 230);
mXpBar = new ProgressBar(1.0f, 100, 20, 143, 192, 211);
- mHpLabel = new gcn::Label("");
- mMpLabel = new gcn::Label("");
- mXpLabel = new gcn::Label("");
-
- mHpLabel->setForegroundColor(gcn::Color(50, 50, 50));
- mMpLabel->setForegroundColor(gcn::Color(50, 50, 50));
- mXpLabel->setForegroundColor(gcn::Color(50, 50, 50));
-
- mHpLabel->setFont(boldFont);
- mMpLabel->setFont(boldFont);
- mXpLabel->setFont(boldFont);
mHpBar->setPosition(0, 3);
mMpBar->setPosition(mHpBar->getWidth() + 3, 3);
mXpBar->setPosition(mMpBar->getX() + mMpBar->getWidth() + 3, 3);
- mHpLabel->setDimension(mHpBar->getDimension());
- mMpLabel->setDimension(mMpBar->getDimension());
- mXpLabel->setDimension(mXpBar->getDimension());
-
- mHpLabel->setAlignment(gcn::Graphics::CENTER);
- mMpLabel->setAlignment(gcn::Graphics::CENTER);
- mXpLabel->setAlignment(gcn::Graphics::CENTER);
-
add(mHpBar);
add(mMpBar);
add(mXpBar);
- add(mHpLabel);
- add(mMpLabel);
- add(mXpLabel);
setContentSize(mXpBar->getX() + mXpBar->getWidth(),
mXpBar->getY() + mXpBar->getHeight());
@@ -106,8 +82,8 @@ void MiniStatusWindow::update()
mXpBar->setProgress(xp);
// Update labels
- mHpLabel->setCaption(toString(player_node->mHp));
- mMpLabel->setCaption(toString(player_node->mMp));
+ mHpBar->setText(toString(player_node->mHp));
+ mMpBar->setText(toString(player_node->mMp));
std::stringstream updatedText;
updatedText << (float) ((int) (xp * 10000.0f)) / 100.0f << "%";
@@ -125,7 +101,7 @@ void MiniStatusWindow::update()
}
*/
- mXpLabel->setCaption(updatedText.str());
+ mXpBar->setText(updatedText.str());
}
void MiniStatusWindow::draw(gcn::Graphics *graphics)
diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h
index d4804bef..d2bcef1c 100644
--- a/src/gui/ministatus.h
+++ b/src/gui/ministatus.h
@@ -19,8 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _TMW_MINISTATUS_H
-#define _TMW_MINISTATUS_H
+#ifndef MINISTATUS_H
+#define MINISTATUS_H
#include <iosfwd>
@@ -44,13 +44,13 @@ class MiniStatusWindow : public Window
MiniStatusWindow();
/**
- * Draw this window
+ * Draw this window.
*/
void draw(gcn::Graphics *graphics);
private:
/**
- * Updates this dialog with values from player_node
+ * Updates this dialog with values from player_node.
*/
void update();
@@ -60,9 +60,6 @@ class MiniStatusWindow : public Window
ProgressBar *mHpBar;
ProgressBar *mMpBar;
ProgressBar *mXpBar;
- gcn::Label *mHpLabel;
- gcn::Label *mMpLabel;
- gcn::Label *mXpLabel;
};
#endif
diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp
index 5ce01b35..ecc0017d 100644
--- a/src/gui/progressbar.cpp
+++ b/src/gui/progressbar.cpp
@@ -19,6 +19,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "gui.h"
#include "progressbar.h"
#include "../graphics.h"
@@ -26,6 +27,8 @@
#include "../resources/image.h"
#include "../resources/resourcemanager.h"
+#include <guichan/font.hpp>
+
ImageRect ProgressBar::mBorder;
int ProgressBar::mInstances = 0;
@@ -94,13 +97,30 @@ void ProgressBar::draw(gcn::Graphics *graphics)
drawImageRect(0, 0, getWidth(), getHeight(), mBorder);
// The bar
- if (mProgress > 0)
- {
+ if (mProgress > 0) {
graphics->setColor(gcn::Color(mRed, mGreen, mBlue, 200));
graphics->fillRectangle(gcn::Rectangle(4, 4,
(int) (mProgress * (getWidth() - 8)),
getHeight() - 8));
}
+
+ // The label
+ if (!mText.empty()) {
+ gcn::Font *f = boldFont;
+ const int textX = getWidth() / 2;
+ const int textY = (getHeight() - f->getHeight()) / 2;
+
+ graphics->setFont(f);
+
+ graphics->setColor(gcn::Color(0, 0, 0));
+ graphics->drawText(mText, textX + 1, textY, gcn::Graphics::CENTER);
+ graphics->drawText(mText, textX, textY - 1, gcn::Graphics::CENTER);
+ graphics->drawText(mText, textX, textY + 1, gcn::Graphics::CENTER);
+ graphics->drawText(mText, textX - 1, textY, gcn::Graphics::CENTER);
+
+ graphics->setColor(gcn::Color(255, 255, 255));
+ graphics->drawText(mText, textX, textY, gcn::Graphics::CENTER);
+ }
}
void ProgressBar::setProgress(float progress)
diff --git a/src/gui/progressbar.h b/src/gui/progressbar.h
index 670b4ab4..e874b56d 100644
--- a/src/gui/progressbar.h
+++ b/src/gui/progressbar.h
@@ -25,6 +25,7 @@
#include <guichan/widget.hpp>
#include <SDL_types.h>
+#include <string>
#include "../guichanfwd.h"
@@ -35,7 +36,8 @@ class ImageRect;
*
* \ingroup GUI
*/
-class ProgressBar : public gcn::Widget {
+class ProgressBar : public gcn::Widget
+{
public:
/**
* Constructor, initializes the progress with the given value.
@@ -67,7 +69,7 @@ class ProgressBar : public gcn::Widget {
/**
* Returns the current progress.
*/
- float getProgress() { return mProgress; }
+ float getProgress() const { return mProgress; }
/**
* Change the filling of the progress bar.
@@ -75,24 +77,37 @@ class ProgressBar : public gcn::Widget {
void setColor(Uint8, Uint8 green, Uint8 blue);
/**
- * Get The red value of color
+ * Returns the red value of color.
*/
- Uint8 getRed() { return mRed; }
+ Uint8 getRed() const { return mRed; }
- /**
- * Get The red value of color
+ /**
+ * Returns the green value of color.
+ */
+ Uint8 getGreen() const { return mGreen; }
+
+ /**
+ * Returns the blue value of color.
+ */
+ Uint8 getBlue() const { return mBlue; }
+
+ /**
+ * Sets the text shown on the progress bar.
*/
- Uint8 getGreen() { return mGreen; }
+ void setText(const std::string &text)
+ { mText = text; }
/**
- * Get The red value of color
+ * Returns the text shown on the progress bar.
*/
- Uint8 getBlue() { return mBlue; }
+ const std::string &text() const
+ { return mText; }
private:
float mProgress;
Uint8 mRed, mGreen, mBlue;
Uint8 mRedToGo, mGreenToGo, mBlueToGo;
+ std::string mText;
static ImageRect mBorder;
static int mInstances;