summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-10-14 18:50:27 +0300
committerAndrei Karas <akaras@inbox.ru>2012-10-14 18:50:27 +0300
commit066488a6f4d086b57f4fe32e8799c207552cccb7 (patch)
tree2c73d80030ff0da73fc5f5b4b664a34030a51633 /src/gui/widgets
parent0b3aafe2859d9ea1c4009eed8a87f69c41cbc14b (diff)
downloadManaVerse-066488a6f4d086b57f4fe32e8799c207552cccb7.tar.gz
ManaVerse-066488a6f4d086b57f4fe32e8799c207552cccb7.tar.bz2
ManaVerse-066488a6f4d086b57f4fe32e8799c207552cccb7.tar.xz
ManaVerse-066488a6f4d086b57f4fe32e8799c207552cccb7.zip
Add theming to labels.
New theme file: label.xml Parameters: padding
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/desktop.h8
-rw-r--r--src/gui/widgets/label.cpp69
-rw-r--r--src/gui/widgets/label.h15
3 files changed, 81 insertions, 11 deletions
diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h
index 0a9759835..2e5eeea24 100644
--- a/src/gui/widgets/desktop.h
+++ b/src/gui/widgets/desktop.h
@@ -27,11 +27,7 @@
#include <guichan/widgetlistener.hpp>
class Image;
-
-namespace gcn
-{
- class Label;
-}
+class Label;
/**
* Desktop widget, for drawing a background image and color.
@@ -68,7 +64,7 @@ class Desktop final : public Container, private gcn::WidgetListener
void setBestFittingWallpaper();
Image *mWallpaper;
- gcn::Label *mVersionLabel;
+ Label *mVersionLabel;
gcn::Color mBackgroundColor;
gcn::Color mBackgroundGrayColor;
};
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index e6f603fb2..188da1bf4 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -23,21 +23,80 @@
#include "gui/theme.h"
+#include <guichan/font.hpp>
+
#include "debug.h"
+Skin *Label::mSkin = nullptr;
+int Label::mInstances = 0;
+
Label::Label() :
- gcn::Label()
+ gcn::Label(),
+ mPadding(0)
{
- mForegroundColor = Theme::getThemeColor(Theme::LABEL);
+ init();
}
Label::Label(const std::string &caption) :
- gcn::Label(caption)
+ gcn::Label(caption),
+ mPadding(0)
+{
+ init();
+}
+
+Label::~Label()
+{
+ mInstances --;
+ if (mInstances == 0 && Theme::instance())
+ {
+ Theme::instance()->unload(mSkin);
+ }
+}
+
+void Label::init()
{
mForegroundColor = Theme::getThemeColor(Theme::LABEL);
+ if (mInstances == 0)
+ {
+ if (Theme::instance())
+ mSkin = Theme::instance()->load("label.xml", "");
+ mInstances ++;
+ }
+ if (mSkin)
+ mPadding = mSkin->getPadding();
+ else
+ mPadding = 0;
+}
+
+void Label::draw(gcn::Graphics* graphics)
+{
+ int textX;
+ const int textY = getHeight() / 2 - getFont()->getHeight() / 2;
+
+ switch (getAlignment())
+ {
+ case Graphics::LEFT:
+ default:
+ textX = mPadding;
+ break;
+ case Graphics::CENTER:
+ textX = getWidth() / 2;
+ break;
+ case Graphics::RIGHT:
+ if (getWidth() > mPadding)
+ textX = getWidth() - mPadding;
+ else
+ textX = 0;
+ break;
+ }
+
+ graphics->setFont(getFont());
+ graphics->setColor(mForegroundColor);
+ graphics->drawText(getCaption(), textX, textY, getAlignment());
}
-void Label::draw(gcn::Graphics *graphics)
+void Label::adjustSize()
{
- gcn::Label::draw(graphics);
+ setWidth(getFont()->getWidth(getCaption()) + 2 * mPadding);
+ setHeight(getFont()->getHeight() + 2 * mPadding);
}
diff --git a/src/gui/widgets/label.h b/src/gui/widgets/label.h
index 046f2ca00..40632109d 100644
--- a/src/gui/widgets/label.h
+++ b/src/gui/widgets/label.h
@@ -24,6 +24,8 @@
#include <guichan/widgets/label.hpp>
+class Skin;
+
/**
* Label widget. Same as the Guichan label but modified to use the palette
* system.
@@ -46,10 +48,23 @@ class Label final : public gcn::Label
A_DELETE_COPY(Label);
+ ~Label();
+
+ void init();
+
/**
* Draws the label.
*/
void draw(gcn::Graphics *graphics) override;
+
+ void adjustSize();
+
+ static Skin *mSkin;
+
+ static int mInstances;
+
+ private:
+ int mPadding;
};
#endif