Skip to content

Commit 2096f7d

Browse files
falbrechtskirchingerFlow86
authored andcommitted
Enable WindowManager to update tooltips
Add a parameter (bool updateCurrent) to the WindowManager::SetToolTip() function, to update the text of the currently displayed tooltip.
1 parent bdf4110 commit 2096f7d

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

libs/s25main/WindowManager.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -798,12 +798,21 @@ class WindowManager::Tooltip
798798
const glFont* font;
799799
std::vector<std::string> lines;
800800
unsigned width = 0, height = 0;
801+
unsigned short maxWidth;
801802

802803
public:
803804
Tooltip(const ctrlBaseTooltip* showingCtrl, const std::string& text, unsigned short maxWidth)
804-
: showingCtrl(showingCtrl), font(NormalFont),
805-
lines(font->GetWrapInfo(text, maxWidth, maxWidth).CreateSingleStrings(text))
805+
: showingCtrl(showingCtrl), font(NormalFont), maxWidth(maxWidth)
806806
{
807+
setText(text);
808+
}
809+
810+
auto getShowingCtrl() const { return showingCtrl; }
811+
auto getWidth() const { return width; }
812+
813+
void setText(const std::string& text)
814+
{
815+
lines = font->GetWrapInfo(text, maxWidth, maxWidth).CreateSingleStrings(text);
807816
if(lines.empty())
808817
return;
809818
width = 0;
@@ -813,9 +822,6 @@ class WindowManager::Tooltip
813822
height = lines.size() * font->getHeight() + BORDER_SIZE * 2;
814823
}
815824

816-
auto getShowingCtrl() const { return showingCtrl; }
817-
auto getWidth() const { return width; }
818-
819825
void draw(DrawPoint pos) const
820826
{
821827
Window::DrawRectangle(Rect(pos, width, height), 0x9F000000);
@@ -829,7 +835,7 @@ class WindowManager::Tooltip
829835
}
830836
};
831837

832-
void WindowManager::SetToolTip(const ctrlBaseTooltip* ttw, const std::string& tooltip)
838+
void WindowManager::SetToolTip(const ctrlBaseTooltip* ttw, const std::string& tooltip, bool updateCurrent)
833839
{
834840
// Max width of tooltip
835841
constexpr unsigned short MAX_TOOLTIP_WIDTH = 260;
@@ -838,6 +844,10 @@ void WindowManager::SetToolTip(const ctrlBaseTooltip* ttw, const std::string& to
838844
{
839845
if(curTooltip && (!ttw || curTooltip->getShowingCtrl() == ttw))
840846
curTooltip.reset();
847+
} else if(updateCurrent)
848+
{
849+
if(curTooltip && curTooltip->getShowingCtrl() == ttw)
850+
curTooltip->setText(tooltip);
841851
} else
842852
curTooltip = std::make_unique<Tooltip>(ttw, tooltip, MAX_TOOLTIP_WIDTH);
843853
}

libs/s25main/WindowManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class WindowManager : public Singleton<WindowManager>, public VideoDriverLoaderI
102102
/// Verarbeitung Keyboard-Event
103103
void Msg_KeyDown(const KeyEvent& ke) override;
104104
// setzt den Tooltip
105-
void SetToolTip(const ctrlBaseTooltip* ttw, const std::string& tooltip);
105+
void SetToolTip(const ctrlBaseTooltip* ttw, const std::string& tooltip, bool updateCurrent = false);
106106

107107
/// Verarbeitung Spielfenstergröße verändert (vom Betriebssystem aus)
108108
void WindowResized() override;

0 commit comments

Comments
 (0)