diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-05-24 15:11:39 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-05-24 15:11:39 +0300 |
commit | 07cef0090ecb3f9b904afbaeaf7b2e2449f34794 (patch) | |
tree | 6847d35368baa2a279212ab1562e0e1d277c58df /src/gui/widgets/radiobutton.cpp | |
parent | 2027da5f18f3ffa4808c8d686990512a9d14c1be (diff) | |
download | ManaVerse-07cef0090ecb3f9b904afbaeaf7b2e2449f34794.tar.gz ManaVerse-07cef0090ecb3f9b904afbaeaf7b2e2449f34794.tar.bz2 ManaVerse-07cef0090ecb3f9b904afbaeaf7b2e2449f34794.tar.xz ManaVerse-07cef0090ecb3f9b904afbaeaf7b2e2449f34794.zip |
Improve radiobutton draw speed.
Use local text image and improve a bit calculations in draw.
Diffstat (limited to 'src/gui/widgets/radiobutton.cpp')
-rw-r--r-- | src/gui/widgets/radiobutton.cpp | 51 |
1 files changed, 46 insertions, 5 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(); +} |