summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/button.cpp20
-rw-r--r--src/gui/button.h7
-rw-r--r--src/gui/ministatus.cpp22
-rw-r--r--src/gui/ministatus.h13
-rw-r--r--src/gui/progressbar.cpp23
-rw-r--r--src/gui/progressbar.h51
6 files changed, 72 insertions, 64 deletions
diff --git a/src/gui/button.cpp b/src/gui/button.cpp
index f49ae364..caf93b94 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 5230f10e..d01147e6 100644
--- a/src/gui/button.h
+++ b/src/gui/button.h
@@ -33,7 +33,8 @@ class ImageRect;
*
* \ingroup GUI
*/
-class Button : public gcn::Button {
+class Button : public gcn::Button
+{
public:
/**
* Default constructor.
@@ -44,7 +45,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);
/**
@@ -55,7 +56,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 f49022b6..e613a745 100644
--- a/src/gui/ministatus.cpp
+++ b/src/gui/ministatus.cpp
@@ -21,8 +21,6 @@
#include "ministatus.h"
-#include <guichan/widgets/label.hpp>
-
#include "gui.h"
#include "progressbar.h"
@@ -43,28 +41,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("");
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());
@@ -117,8 +101,8 @@ void MiniStatusWindow::update()
(float) player_node->getXp() / player_node->mXpForNextLevel);
// 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 << (int) (
@@ -138,7 +122,7 @@ void MiniStatusWindow::update()
}
*/
- mXpLabel->setCaption(updatedText.str());
+ mXpBar->setText(updatedText.str());
for (unsigned int i = 0; i < mIcons.size(); i++)
if (mIcons[i])
diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h
index b191dbf8..c6a36a98 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>
#include <vector>
@@ -46,12 +46,12 @@ class MiniStatusWindow : public Window
MiniStatusWindow();
/**
- * Draw this window
+ * Draw this window.
*/
void draw(gcn::Graphics *graphics);
/**
- * Sets one of the icons
+ * Sets one of the icons.
*/
void setIcon(int index, AnimatedSprite *sprite);
@@ -61,7 +61,7 @@ class MiniStatusWindow : public Window
private:
/**
- * Updates this dialog with values from player_node
+ * Updates this dialog with values from player_node.
*/
void update();
@@ -71,9 +71,6 @@ class MiniStatusWindow : public Window
ProgressBar *mHpBar;
ProgressBar *mMpBar;
ProgressBar *mXpBar;
- gcn::Label *mHpLabel;
- gcn::Label *mMpLabel;
- gcn::Label *mXpLabel;
std::vector<AnimatedSprite *> mIcons;
};
diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp
index 5ce01b35..d877bfbc 100644
--- a/src/gui/progressbar.cpp
+++ b/src/gui/progressbar.cpp
@@ -26,6 +26,8 @@
#include "../resources/image.h"
#include "../resources/resourcemanager.h"
+#include <guichan/font.hpp>
+
ImageRect ProgressBar::mBorder;
int ProgressBar::mInstances = 0;
@@ -94,13 +96,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 = getFont();
+ 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 1707b464..3b68fa40 100644
--- a/src/gui/progressbar.h
+++ b/src/gui/progressbar.h
@@ -26,15 +26,17 @@
#include <SDL_types.h>
-class ImageRect;
+#include <string>
+class ImageRect;
/**
* A progress bar.
*
* \ingroup GUI
*/
-class ProgressBar : public gcn::Widget {
+class ProgressBar : public gcn::Widget
+{
public:
/**
* Constructor, initializes the progress with the given value.
@@ -51,55 +53,60 @@ class ProgressBar : public gcn::Widget {
/**
* Performs progress bar logic (fading colors)
*/
- void
- logic();
+ void logic();
/**
* Draws the progress bar.
*/
- void
- draw(gcn::Graphics *graphics);
+ void draw(gcn::Graphics *graphics);
/**
* Sets the current progress.
*/
- void
- setProgress(float progress);
+ void setProgress(float progress);
/**
* Returns the current progress.
*/
- float
- getProgress() { return mProgress; }
+ float getProgress() const { return mProgress; }
/**
* Change the filling of the progress bar.
*/
- void
- setColor(Uint8, Uint8 green, Uint8 blue);
+ void setColor(Uint8, Uint8 green, Uint8 blue);
+
+ /**
+ * Returns the red value of color.
+ */
+ Uint8 getRed() const { return mRed; }
/**
- * Get The red value of color
+ * Returns the red value of color.
*/
- Uint8
- getRed() { return mRed; }
+ Uint8 getGreen() const { return mGreen; }
- /**
- * Get The red value of color
+ /**
+ * Returns the red 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;