summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/graphics/gui/CMakeLists.txt1
-rw-r--r--data/graphics/gui/Makefile.am1
-rw-r--r--data/graphics/gui/textpreview.xml5
-rw-r--r--src/gui/widgets/textpreview.cpp42
-rw-r--r--src/gui/widgets/textpreview.h9
5 files changed, 52 insertions, 6 deletions
diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt
index 1f665cebb..4cb568721 100644
--- a/data/graphics/gui/CMakeLists.txt
+++ b/data/graphics/gui/CMakeLists.txt
@@ -62,6 +62,7 @@ SET (FILES
target-cursor-normal-m.png
target-cursor-normal-s.png
textfield.xml
+ textpreview.xml
unknown-item.png
window.png
window.xml
diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am
index 9a3e17f37..f6d9eb9df 100644
--- a/data/graphics/gui/Makefile.am
+++ b/data/graphics/gui/Makefile.am
@@ -65,6 +65,7 @@ gui_DATA = \
target-cursor-normal-m.png \
target-cursor-normal-s.png \
textfield.xml \
+ textpreview.xml \
unknown-item.png \
window.png \
window.xml \
diff --git a/data/graphics/gui/textpreview.xml b/data/graphics/gui/textpreview.xml
new file mode 100644
index 000000000..406213a2a
--- /dev/null
+++ b/data/graphics/gui/textpreview.xml
@@ -0,0 +1,5 @@
+<skinset name="Default" image="window.png">
+ <widget type="Window">
+ <option name="padding" value="1" />
+ </widget>
+</skinset>
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