summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-27 14:42:15 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-27 23:15:05 +0300
commit60add2c149c9c61bfbede5ae92cfe216927aca8a (patch)
tree9ded097faa108eb07b9ca1c8ce4490882e238a44 /src/gui/widgets
parent2babe1d6491f5231b0e97349ccb198b92bb90ba9 (diff)
downloadmanaplus-60add2c149c9c61bfbede5ae92cfe216927aca8a.tar.gz
manaplus-60add2c149c9c61bfbede5ae92cfe216927aca8a.tar.bz2
manaplus-60add2c149c9c61bfbede5ae92cfe216927aca8a.tar.xz
manaplus-60add2c149c9c61bfbede5ae92cfe216927aca8a.zip
Improve a bit draw speed in other controls.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/button.cpp38
-rw-r--r--src/gui/widgets/checkbox.cpp5
-rw-r--r--src/gui/widgets/dropdown.cpp5
-rw-r--r--src/gui/widgets/label.cpp11
-rw-r--r--src/gui/widgets/radiobutton.cpp5
-rw-r--r--src/gui/widgets/textbox.cpp29
-rw-r--r--src/gui/widgets/textbox.h2
-rw-r--r--src/gui/widgets/textfield.cpp5
-rw-r--r--src/gui/widgets/window.cpp18
9 files changed, 89 insertions, 29 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")
}
diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp
index 786c77fd2..75c3960db 100644
--- a/src/gui/widgets/checkbox.cpp
+++ b/src/gui/widgets/checkbox.cpp
@@ -94,10 +94,11 @@ void CheckBox::draw(gcn::Graphics* graphics)
BLOCK_START("CheckBox::draw")
drawBox(graphics);
- graphics->setFont(getFont());
+ gcn::Font *const font = getFont();
+ graphics->setFont(font);
graphics->setColor(mForegroundColor);
- graphics->drawText(getCaption(), mPadding + mImageSize + mSpacing,
+ font->drawString(graphics, mCaption, mPadding + mImageSize + mSpacing,
mPadding);
BLOCK_END("CheckBox::draw")
}
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index 8c8f6843f..ec564146e 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -227,9 +227,10 @@ void DropDown::draw(gcn::Graphics* graphics)
if (mPopup->getListModel() && mPopup->getSelected() >= 0)
{
- graphics->setFont(getFont());
+ gcn::Font *const font = getFont();
+ graphics->setFont(font);
graphics->setColor(mForegroundColor);
- graphics->drawText(mPopup->getListModel()->getElementAt(
+ font->drawString(graphics, mPopup->getListModel()->getElementAt(
mPopup->getSelected()), mPadding, mPadding);
}
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index 2d565a571..9efa375d7 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -72,27 +72,28 @@ void Label::draw(gcn::Graphics* graphics)
BLOCK_START("Label::draw")
int textX;
const int textY = getHeight() / 2 - getFont()->getHeight() / 2;
+ gcn::Font *const font = getFont();
+ graphics->setFont(font);
- switch (getAlignment())
+ switch (mAlignment)
{
case Graphics::LEFT:
default:
textX = mPadding;
break;
case Graphics::CENTER:
- textX = getWidth() / 2;
+ textX = (getWidth() - font->getWidth(mCaption)) / 2;
break;
case Graphics::RIGHT:
if (getWidth() > mPadding)
- textX = getWidth() - mPadding;
+ textX = getWidth() - mPadding - font->getWidth(mCaption);
else
textX = 0;
break;
}
- graphics->setFont(getFont());
graphics->setColor(mForegroundColor);
- graphics->drawText(getCaption(), textX, textY, getAlignment());
+ font->drawString(graphics, mCaption, textX, textY);
BLOCK_END("Label::draw")
}
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index 1c56f787e..b2f38db4a 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -152,10 +152,11 @@ void RadioButton::draw(gcn::Graphics* graphics)
BLOCK_START("RadioButton::draw")
drawBox(graphics);
- graphics->setFont(getFont());
+ gcn::Font *const font = getFont();
+ graphics->setFont(font);
graphics->setColor(mForegroundColor);
- graphics->drawText(getCaption(), mPadding + mImageSize + mSpacing,
+ font->drawString(graphics, mCaption, mPadding + mImageSize + mSpacing,
mPadding);
BLOCK_END("RadioButton::draw")
}
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index 51933708b..976d7f772 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -338,3 +338,32 @@ void TextBox::keyPressed(gcn::KeyEvent& keyEvent)
keyEvent.consume();
}
+
+void TextBox::draw(gcn::Graphics* graphics)
+{
+ BLOCK_START("TextBox::draw")
+ if (mOpaque)
+ {
+ graphics->setColor(mBackgroundColor);
+ graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
+ }
+
+ if (isFocused() && isEditable())
+ {
+ drawCaret(graphics, getFont()->getWidth(
+ mTextRows[mCaretRow].substr(0, mCaretColumn)),
+ mCaretRow * getFont()->getHeight());
+ }
+
+ graphics->setColor(mForegroundColor);
+ gcn::Font *const font = getFont();
+ graphics->setFont(font);
+ const int fontHeight = font->getHeight();
+
+ for (size_t i = 0, sz = mTextRows.size(); i < sz; i++)
+ {
+ // Move the text one pixel so we can have a caret before a letter.
+ font->drawString(graphics, mTextRows[i], 1, i * fontHeight);
+ }
+ BLOCK_END("TextBox::draw")
+}
diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h
index 51402fad7..5271f742e 100644
--- a/src/gui/widgets/textbox.h
+++ b/src/gui/widgets/textbox.h
@@ -60,6 +60,8 @@ class TextBox final : public gcn::TextBox,
void keyPressed(gcn::KeyEvent& keyEvent) override;
+ void draw(gcn::Graphics* graphics);
+
private:
int mMinWidth;
};
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index fc9c73a68..02ad7699e 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -130,8 +130,9 @@ void TextField::draw(gcn::Graphics *graphics)
}
graphics->setColor(mForegroundColor);
- graphics->setFont(getFont());
- graphics->drawText(mText, mPadding - mXScroll, mPadding);
+ gcn::Font *const font = getFont();
+ graphics->setFont(font);
+ font->drawString(graphics, mText, mPadding - mXScroll, mPadding);
BLOCK_END("TextField::draw")
}
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 52042f019..ffeac0cb1 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -36,6 +36,7 @@
#include <guichan/exception.hpp>
#include <guichan/focushandler.hpp>
+#include <guichan/font.hpp>
#include "debug.h"
@@ -267,8 +268,21 @@ void Window::draw(gcn::Graphics *graphics)
{
g->setColor(mForegroundColor);
g->setFont(mCaptionFont);
- g->drawText(getCaption(), mCaptionOffsetX, mCaptionOffsetY,
- static_cast<gcn::Graphics::Alignment>(mCaptionAlign));
+ int x;
+ switch (static_cast<gcn::Graphics::Alignment>(mCaptionAlign))
+ {
+ case Graphics::LEFT:
+ default:
+ x = mCaptionOffsetX;
+ break;
+ case Graphics::CENTER:
+ x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption) / 2;
+ break;
+ case Graphics::RIGHT:
+ x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption);
+ break;
+ }
+ mCaptionFont->drawString(g, mCaption, x, mCaptionOffsetY);
}
if (update)