From 60add2c149c9c61bfbede5ae92cfe216927aca8a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 27 Dec 2012 14:42:15 +0300 Subject: Improve a bit draw speed in other controls. --- src/gui/widgets/button.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src/gui/widgets/button.cpp') 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") } -- cgit v1.2.3-70-g09d2