summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/textpreview.cpp42
-rw-r--r--src/gui/widgets/textpreview.h9
2 files changed, 45 insertions, 6 deletions
diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp
index 47cd71dfa..f9f0269c0 100644
--- a/src/gui/widgets/textpreview.cpp
+++ b/src/gui/widgets/textpreview.cpp
@@ -31,7 +31,9 @@
#include "debug.h"
+int TextPreview::instances = 0;
float TextPreview::mAlpha = 1.0;
+Skin *TextPreview::mSkin = nullptr;
TextPreview::TextPreview(const Widget2 *const widget,
const std::string &text) :
@@ -45,8 +47,33 @@ TextPreview::TextPreview(const Widget2 *const widget,
mTextAlpha(false),
mOpaque(false),
mShadow(false),
- mOutline(false)
+ mOutline(false),
+ mPadding(0)
{
+ if (instances == 0)
+ {
+ if (Theme::instance())
+ mSkin = Theme::instance()->load("textpreview.xml", "");
+ }
+
+ instances++;
+
+ if (mSkin)
+ mPadding = mSkin->getOption("padding", 0);
+
+ adjustSize();
+}
+
+TextPreview::~TextPreview()
+{
+ instances--;
+
+ if (instances == 0)
+ {
+ Theme *const theme = Theme::instance();
+ if (theme)
+ theme->unload(mSkin);
+ }
}
void TextPreview::draw(gcn::Graphics* graphics)
@@ -78,11 +105,16 @@ void TextPreview::draw(gcn::Graphics* graphics)
static_cast<int>(mTextBGColor->g),
static_cast<int>(mTextBGColor->b),
static_cast<int>(mAlpha * 255.0f)));
- graphics->fillRectangle(gcn::Rectangle(1, 1, x, y));
+ graphics->fillRectangle(gcn::Rectangle(mPadding, mPadding, x, y));
}
}
- TextRenderer::renderText(graphics, mText, 2, 2, gcn::Graphics::LEFT,
- gcn::Color(mTextColor->r, mTextColor->g, mTextColor->b, alpha),
- mFont, mOutline, mShadow);
+ TextRenderer::renderText(graphics, mText, mPadding + 1, mPadding + 1,
+ gcn::Graphics::LEFT, gcn::Color(mTextColor->r, mTextColor->g,
+ mTextColor->b, alpha), mFont, mOutline, mShadow);
+}
+
+void TextPreview::adjustSize()
+{
+ setHeight(getFont()->getHeight() + 2 * mPadding);
}
diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h
index 5e84900ff..6af6cccf9 100644
--- a/src/gui/widgets/textpreview.h
+++ b/src/gui/widgets/textpreview.h
@@ -42,13 +42,15 @@ class TextPreview final : public gcn::Widget,
A_DELETE_COPY(TextPreview)
+ ~TextPreview();
+
/**
* Sets the color the text is printed in.
*
* @param color the color to set
*/
inline void setTextColor(const gcn::Color *color)
- { mTextColor = color; }
+ { mTextColor = color; adjustSize(); }
/**
* Sets the text to use the set alpha value.
@@ -122,6 +124,8 @@ class TextPreview final : public gcn::Widget,
bool isOpaque() const
{ return mOpaque; }
+ void adjustSize();
+
private:
gcn::Font *mFont;
std::string mText;
@@ -132,7 +136,10 @@ class TextPreview final : public gcn::Widget,
bool mOpaque;
bool mShadow;
bool mOutline;
+ int mPadding;
+ static int instances;
static float mAlpha;
+ static Skin *mSkin;
};
#endif