From 16b5831a6640bcd1f6f7f23c7b282544bea2b47d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 26 May 2015 13:12:21 +0300 Subject: Use local TextChunk in windows for draw caption text. --- src/gui/widgets/window.cpp | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'src/gui/widgets/window.cpp') diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index f45e93362..e781ec548 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -125,6 +125,7 @@ Window::Window(const std::string &caption, mCloseRect(), mStickyRect(), mGripRect(), + mTextChunk(), mWindowName("window"), mMinWinWidth(100), mMinWinHeight(40), @@ -151,7 +152,8 @@ Window::Window(const std::string &caption, mSticky(false), mStickyButtonLock(false), mPlayVisibleSound(false), - mInit(false) + mInit(false), + mTextChanged(true) { logger->log("Window::Window(\"%s\")", caption.c_str()); @@ -359,11 +361,20 @@ void Window::draw(Graphics *graphics) x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption); break; } - mCaptionFont->drawString(graphics, - mForegroundColor, - mForegroundColor2, - mCaption, - x, mCaptionOffsetY); + if (mTextChanged) + { + mTextChunk.textFont = mCaptionFont; + mTextChunk.deleteImage(); + mTextChunk.text = mCaption; + mTextChunk.color = mForegroundColor; + mTextChunk.color2 = mForegroundColor2; + mCaptionFont->generate(mTextChunk); + mTextChanged = false; + } + + const Image *const image = mTextChunk.img; + if (image) + graphics->drawImage(image, x, mCaptionOffsetY); } if (update) @@ -427,11 +438,20 @@ void Window::safeDraw(Graphics *graphics) x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption); break; } - mCaptionFont->drawString(graphics, - mForegroundColor, - mForegroundColor2, - mCaption, - x, mCaptionOffsetY); + if (mTextChanged) + { + mTextChunk.textFont = mCaptionFont; + mTextChunk.deleteImage(); + mTextChunk.text = mCaption; + mTextChunk.color = mForegroundColor; + mTextChunk.color2 = mForegroundColor2; + mCaptionFont->generate(mTextChunk); + mTextChanged = false; + } + + const Image *const image = mTextChunk.img; + if (image) + graphics->drawImage(image, x, mCaptionOffsetY); } safeDrawChildren(graphics); @@ -668,6 +688,9 @@ void Window::widgetMoved(const Event& event A_UNUSED) void Window::widgetHidden(const Event &event A_UNUSED) { + mTextChanged = true; + mTextChunk.deleteImage(); + if (gui) gui->setCursorType(Cursor::CURSOR_POINTER); -- cgit v1.2.3-60-g2f50