diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-12-27 14:42:15 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-12-27 23:15:05 +0300 |
commit | 60add2c149c9c61bfbede5ae92cfe216927aca8a (patch) | |
tree | 9ded097faa108eb07b9ca1c8ce4490882e238a44 /src/gui/widgets/button.cpp | |
parent | 2babe1d6491f5231b0e97349ccb198b92bb90ba9 (diff) | |
download | manaverse-60add2c149c9c61bfbede5ae92cfe216927aca8a.tar.gz manaverse-60add2c149c9c61bfbede5ae92cfe216927aca8a.tar.bz2 manaverse-60add2c149c9c61bfbede5ae92cfe216927aca8a.tar.xz manaverse-60add2c149c9c61bfbede5ae92cfe216927aca8a.zip |
Improve a bit draw speed in other controls.
Diffstat (limited to 'src/gui/widgets/button.cpp')
-rw-r--r-- | src/gui/widgets/button.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index a6ecfa7db..4606cca57 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -345,19 +345,23 @@ void Button::draw(gcn::Graphics *graphics) break; } - int textX = 0; - const int textY = getHeight() / 2 - getFont()->getHeight() / 2; int imageX = 0; int imageY = 0; + int textX = 0; + int textY = getHeight() / 2 - getFont()->getHeight() / 2; if (mImages) imageY = getHeight() / 2 - mImageHeight / 2; // need move calculation from draw!!! - switch (getAlignment()) + gcn::Font *const font = getFont(); + graphics->setFont(font); + + switch (mAlignment) { default: case gcn::Graphics::LEFT: + { if (mImages) { imageX = padding; @@ -368,27 +372,31 @@ void Button::draw(gcn::Graphics *graphics) textX = padding; } break; + } case gcn::Graphics::CENTER: + { + const int width = font->getWidth(mCaption); if (mImages) { - const int width = getFont()->getWidth(mCaption) - + mImageWidth + spacing; + const int width = width + mImageWidth + spacing; imageX = getWidth() / 2 - width / 2; - textX = imageX + mImageWidth + spacing; + textX = imageX + mImageWidth + spacing - width / 2; } else { - textX = getWidth() / 2; + textX = (getWidth() - width) / 2; } break; + } case gcn::Graphics::RIGHT: - textX = getWidth() - padding; - imageX = textX - getFont()->getWidth(mCaption) - spacing; + { + const int width = font->getWidth(mCaption); + textX = getWidth() - width - padding; + imageX = textX - width - spacing; break; + } } - graphics->setFont(getFont()); - if (openGLMode != 2) { if (recalc) @@ -427,9 +435,11 @@ void Button::draw(gcn::Graphics *graphics) } if (isPressed()) - g2->drawText(getCaption(), textX + 1, textY + 1, getAlignment()); - else - g2->drawText(getCaption(), textX, textY, getAlignment()); + { + textX ++; + textY ++; + } + font->drawString(g2, mCaption, textX, textY); BLOCK_END("Button::draw") } |