summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-24 15:11:39 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-24 15:11:39 +0300
commit07cef0090ecb3f9b904afbaeaf7b2e2449f34794 (patch)
tree6847d35368baa2a279212ab1562e0e1d277c58df /src
parent2027da5f18f3ffa4808c8d686990512a9d14c1be (diff)
downloadplus-07cef0090ecb3f9b904afbaeaf7b2e2449f34794.tar.gz
plus-07cef0090ecb3f9b904afbaeaf7b2e2449f34794.tar.bz2
plus-07cef0090ecb3f9b904afbaeaf7b2e2449f34794.tar.xz
plus-07cef0090ecb3f9b904afbaeaf7b2e2449f34794.zip
Improve radiobutton draw speed.
Use local text image and improve a bit calculations in draw.
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/radiobutton.cpp51
-rw-r--r--src/gui/widgets/radiobutton.h17
2 files changed, 60 insertions, 8 deletions
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index 192427636..5b9ce7aca 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -92,14 +92,18 @@ RadioButton::RadioButton(const Widget2 *const widget,
Widget(widget),
MouseListener(),
KeyListener(),
+ WidgetListener(),
mSelected(false),
mCaption(),
mGroup(),
+ mTextChunk(),
mPadding(0),
mImagePadding(0),
mImageSize(9),
mSpacing(2),
- mHasMouse(false)
+ mTextX(0 + 9 + 2),
+ mHasMouse(false),
+ mTextChanged(true)
{
mAllowLogic = false;
setCaption(caption);
@@ -129,6 +133,7 @@ RadioButton::RadioButton(const Widget2 *const widget,
mImagePadding = mSkin->getOption("imagePadding");
mImageSize = mSkin->getOption("imageSize");
mSpacing = mSkin->getOption("spacing");
+ mTextX = mPadding + mImageSize + mSpacing;
}
adjustSize();
@@ -136,7 +141,10 @@ RadioButton::RadioButton(const Widget2 *const widget,
RadioButton::~RadioButton()
{
- setGroup("");
+ if (mWindow)
+ mWindow->removeWidgetListener(this);
+
+ setGroup(std::string());
if (gui)
gui->removeDragged(this);
@@ -222,9 +230,22 @@ void RadioButton::draw(Graphics* graphics)
drawBox(graphics);
Font *const font = getFont();
- graphics->setColorAll(mForegroundColor, mForegroundColor2);
- font->drawString(graphics, mCaption, mPadding + mImageSize + mSpacing,
- mPadding);
+
+ if (mTextChanged)
+ {
+ mTextChunk.textFont = font;
+ mTextChunk.deleteImage();
+ mTextChunk.text = mCaption;
+ mTextChunk.color = mForegroundColor;
+ mTextChunk.color2 = mForegroundColor2;
+ font->generate(mTextChunk);
+ mTextChanged = false;
+ }
+
+ const Image *const image = mTextChunk.img;
+ if (image)
+ graphics->drawImage(image, mTextX, mPadding);
+
BLOCK_END("RadioButton::draw")
}
@@ -311,3 +332,23 @@ void RadioButton::setGroup(const std::string &group)
mGroup = group;
}
+
+void RadioButton::setCaption(const std::string& caption)
+{
+ if (caption != mCaption)
+ mTextChanged = true;
+ mCaption = caption;
+}
+
+void RadioButton::setParent(Widget *widget)
+{
+ if (mWindow)
+ mWindow->addWidgetListener(this);
+ Widget::setParent(widget);
+}
+
+void RadioButton::widgetHidden(const Event &event A_UNUSED)
+{
+ mTextChanged = true;
+ mTextChunk.deleteImage();
+}
diff --git a/src/gui/widgets/radiobutton.h b/src/gui/widgets/radiobutton.h
index eebbae8bd..d33634546 100644
--- a/src/gui/widgets/radiobutton.h
+++ b/src/gui/widgets/radiobutton.h
@@ -68,6 +68,9 @@
#include "listeners/keylistener.h"
#include "listeners/mouselistener.h"
+#include "listeners/widgetlistener.h"
+
+#include "gui/fonts/textchunk.h"
#include "gui/widgets/widget.h"
@@ -80,7 +83,8 @@ class Skin;
*/
class RadioButton final : public Widget,
public MouseListener,
- public KeyListener
+ public KeyListener,
+ public WidgetListener
{
public:
@@ -161,8 +165,7 @@ class RadioButton final : public Widget,
* @param caption The caption of the radio button.
* @see getCaption, adjustSize
*/
- void setCaption(const std::string &caption)
- { mCaption = caption; }
+ void setCaption(const std::string &caption);
void mouseClicked(MouseEvent& event) override final;
@@ -187,6 +190,10 @@ class RadioButton final : public Widget,
const std::string &getGroup() const
{ return mGroup; }
+ void setParent(Widget *widget) override final;
+
+ void widgetHidden(const Event &event) override final;
+
private:
static int instances;
static Skin *mSkin;
@@ -207,6 +214,8 @@ class RadioButton final : public Widget,
*/
std::string mGroup;
+ TextChunk mTextChunk;
+
/**
* Typdef.
*/
@@ -226,7 +235,9 @@ class RadioButton final : public Widget,
int mImagePadding;
int mImageSize;
int mSpacing;
+ int mTextX;
bool mHasMouse;
+ bool mTextChanged;
};
#endif // GUI_WIDGETS_RADIOBUTTON_H