summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/widgets/window.cpp45
-rw-r--r--src/gui/widgets/window.h6
-rw-r--r--src/gui/windows/shortcutwindow.cpp1
3 files changed, 40 insertions, 12 deletions
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);
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index 2c174aeae..102aedf73 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -71,6 +71,8 @@
#include "listeners/mouselistener.h"
#include "listeners/widgetlistener.h"
+#include "gui/fonts/textchunk.h"
+
#include "gui/widgets/basiccontainer2.h"
#include "resources/imagerect.h"
@@ -511,7 +513,7 @@ class Window notfinal : public BasicContainer2,
* @see getCaption
*/
void setCaption(const std::string& caption)
- { mCaption = caption; }
+ { mCaption = caption; mTextChanged = true; }
/**
* Gets the caption of the window.
@@ -669,6 +671,7 @@ class Window notfinal : public BasicContainer2,
Rect mCloseRect; /**< Close button rectangle */
Rect mStickyRect; /**< Sticky button rectangle */
Rect mGripRect; /**< Resize grip rectangle */
+ TextChunk mTextChunk;
std::string mWindowName; /**< Name of the window */
int mMinWinWidth; /**< Minimum window width */
int mMinWinHeight; /**< Minimum window height */
@@ -707,6 +710,7 @@ class Window notfinal : public BasicContainer2,
bool mStickyButtonLock; /**< Window locked if sticky enabled*/
bool mPlayVisibleSound;
bool mInit;
+ bool mTextChanged;
};
#endif // GUI_WIDGETS_WINDOW_H
diff --git a/src/gui/windows/shortcutwindow.cpp b/src/gui/windows/shortcutwindow.cpp
index 85fb2e2ff..baf8b68d7 100644
--- a/src/gui/windows/shortcutwindow.cpp
+++ b/src/gui/windows/shortcutwindow.cpp
@@ -179,6 +179,7 @@ int ShortcutWindow::getTabIndex() const
void ShortcutWindow::widgetHidden(const Event &event)
{
+ Window::widgetHidden(event);
if (mItems)
mItems->widgetHidden(event);
if (mTabs)