Index: ps/trunk/source/gui/CGUIText.cpp =================================================================== --- ps/trunk/source/gui/CGUIText.cpp (revision 25352) +++ ps/trunk/source/gui/CGUIText.cpp (revision 25353) @@ -1,470 +1,478 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #include "precompiled.h" #include "CGUIText.h" #include "graphics/FontMetrics.h" #include "graphics/ShaderManager.h" #include "graphics/TextRenderer.h" #include "gui/CGUI.h" #include "gui/ObjectBases/IGUIObject.h" #include "gui/SettingTypes/CGUIString.h" #include "renderer/Renderer.h" #include extern int g_xres, g_yres; extern float g_GuiScale; // TODO Gee: CRect => CPoint ? void SGenerateTextImage::SetupSpriteCall( const bool Left, CGUIText::SSpriteCall& SpriteCall, const float width, const float y, const CSize2D& Size, const CStr& TextureName, const float BufferZone) { // TODO Gee: Temp hardcoded values SpriteCall.m_Area.top = y + BufferZone; SpriteCall.m_Area.bottom = y + BufferZone + Size.Height; if (Left) { SpriteCall.m_Area.left = BufferZone; SpriteCall.m_Area.right = Size.Width + BufferZone; } else { SpriteCall.m_Area.left = width-BufferZone - Size.Width; SpriteCall.m_Area.right = width-BufferZone; } SpriteCall.m_Sprite = TextureName; m_YFrom = SpriteCall.m_Area.top - BufferZone; m_YTo = SpriteCall.m_Area.bottom + BufferZone; m_Indentation = Size.Width + BufferZone * 2; } CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, const float Width, const float BufferZone, const IGUIObject* pObject) { if (string.m_Words.empty()) return; CStrIntern Font(FontW.ToUTF8()); float x = BufferZone, y = BufferZone; // drawing pointer int from = 0; bool FirstLine = true; // Necessary because text in the first line is shorter // (it doesn't count the line spacing) // Images on the left or the right side. SGenerateTextImages Images; int pos_last_img = -1; // Position in the string where last img (either left or right) were encountered. // in order to avoid duplicate processing. // get the alignment type for the control we are computing the text for since // we are computing the horizontal alignment in this method in order to not have // to run through the TextCalls a second time in the CalculateTextPosition method again EAlign align = EAlign::LEFT; if (pObject->SettingExists("text_align")) align = pObject->GetSetting("text_align"); // Go through string word by word for (int i = 0; i < static_cast(string.m_Words.size()) - 1; ++i) { // Pre-process each line one time, so we know which floating images // will be added for that line. // Generated stuff is stored in Feedback. CGUIString::SFeedback Feedback; // Preliminary line height, used for word-wrapping with floating images. float prelim_line_height = 0.f; // Width and height of all text calls generated. string.GenerateTextCall(pGUI, Feedback, Font, string.m_Words[i], string.m_Words[i+1], FirstLine); SetupSpriteCalls(pGUI, Feedback.m_Images, y, Width, BufferZone, i, pos_last_img, Images); pos_last_img = std::max(pos_last_img, i); x += Feedback.m_Size.Width; prelim_line_height = std::max(prelim_line_height, Feedback.m_Size.Height); // If Width is 0, then there's no word-wrapping, disable NewLine. if (((Width != 0 && (x > Width - BufferZone || Feedback.m_NewLine)) || i == static_cast(string.m_Words.size()) - 2) && ProcessLine(pGUI, string, Font, pObject, Images, align, prelim_line_height, Width, BufferZone, FirstLine, x, y, i, from)) return; } } // Loop through our images queues, to see if images have been added. void CGUIText::SetupSpriteCalls( const CGUI& pGUI, const std::array, 2>& FeedbackImages, const float y, const float Width, const float BufferZone, const int i, const int pos_last_img, SGenerateTextImages& Images) { // Check if this has already been processed. // Also, floating images are only applicable if Word-Wrapping is on if (Width == 0 || i <= pos_last_img) return; // Loop left/right for (int j = 0; j < 2; ++j) for (const CStr& imgname : FeedbackImages[j]) { SSpriteCall SpriteCall; SGenerateTextImage Image; // Y is if no other floating images is above, y. Else it is placed // after the last image, like a stack downwards. float _y; if (!Images[j].empty()) _y = std::max(y, Images[j].back().m_YTo); else _y = y; const SGUIIcon& icon = pGUI.GetIcon(imgname); Image.SetupSpriteCall(j == CGUIString::SFeedback::Left, SpriteCall, Width, _y, icon.m_Size, icon.m_SpriteName, BufferZone); // Check if image is the lowest thing. m_Size.Height = std::max(m_Size.Height, Image.m_YTo); Images[j].emplace_back(Image); m_SpriteCalls.emplace_back(std::move(SpriteCall)); } } // Now we'll do another loop to figure out the height and width of // the line (the height of the largest character and the width is // the sum of all of the individual widths). This // couldn't be determined in the first loop (main loop) // because it didn't regard images, so we don't know // if all characters processed, will actually be involved // in that line. void CGUIText::ComputeLineSize( const CGUI& pGUI, const CGUIString& string, const CStrIntern& Font, const bool FirstLine, const float Width, const float width_range_to, const int i, const int temp_from, float& x, CSize2D& line_size) const { for (int j = temp_from; j <= i; ++j) { // We don't want to use Feedback now, so we'll have to use another one. CGUIString::SFeedback Feedback2; // Don't attach object, it'll suppress the errors // we want them to be reported in the final GenerateTextCall() // so that we don't get duplicates. string.GenerateTextCall(pGUI, Feedback2, Font, string.m_Words[j], string.m_Words[j+1], FirstLine); // Append X value. x += Feedback2.m_Size.Width; if (Width != 0 && x > width_range_to && j != temp_from && !Feedback2.m_NewLine) { // The calculated width of each word includes the space between the current // word and the next. When we're wrapping, we need subtract the width of the // space after the last word on the line before the wrap. CFontMetrics currentFont(Font); line_size.Width -= currentFont.GetCharacterWidth(*L" "); break; } // Let line_size.cy be the maximum m_Height we encounter. line_size.Height = std::max(line_size.Height, Feedback2.m_Size.Height); // If the current word is an explicit new line ("\n"), // break now before adding the width of this character. // ("\n" doesn't have a glyph, thus is given the same width as // the "missing glyph" character by CFont::GetCharacterWidth().) if (Width != 0 && Feedback2.m_NewLine) break; line_size.Width += Feedback2.m_Size.Width; } } bool CGUIText::ProcessLine( const CGUI& pGUI, const CGUIString& string, const CStrIntern& Font, const IGUIObject* pObject, const SGenerateTextImages& Images, const EAlign align, const float prelim_line_height, const float Width, const float BufferZone, bool& FirstLine, float& x, float& y, int& i, int& from) { // Change 'from' to 'i', but first keep a copy of its value. int temp_from = from; from = i; float width_range_from = BufferZone; float width_range_to = Width - BufferZone; ComputeLineRange(Images, y, Width, prelim_line_height, width_range_from, width_range_to); // Reset X for the next loop x = width_range_from; CSize2D line_size; ComputeLineSize(pGUI, string, Font, FirstLine, Width, width_range_to, i, temp_from, x, line_size); // Reset x once more x = width_range_from; // Move down, because font drawing starts from the baseline y += line_size.Height; const float dx = GetLineOffset(align, width_range_from, width_range_to, line_size); // Do the real processing now const bool done = AssembleCalls(pGUI, string, Font, pObject, FirstLine, Width, width_range_to, dx, y, temp_from, i, x, from); // Reset X x = BufferZone; // Update dimensions m_Size.Width = std::max(m_Size.Width, line_size.Width + BufferZone * 2); m_Size.Height = std::max(m_Size.Height, y + BufferZone); FirstLine = false; // Now if we entered as from = i, then we want // i being one minus that, so that it will become // the same i in the next loop. The difference is that // we're on a new line now. i = from - 1; return done; } // Decide width of the line. We need to iterate our floating images. // this won't be exact because we're assuming the line_size.cy // will be as our preliminary calculation said. But that may change, // although we'd have to add a couple of more loops to try straightening // this problem out, and it is very unlikely to happen noticeably if one // structures his text in a stylistically pure fashion. Even if not, it // is still quite unlikely it will happen. // Loop through left and right side, from and to. void CGUIText::ComputeLineRange( const SGenerateTextImages& Images, const float y, const float Width, const float prelim_line_height, float& width_range_from, float& width_range_to) const { // Floating images are only applicable if word-wrapping is enabled. if (Width == 0) return; for (int j = 0; j < 2; ++j) for (const SGenerateTextImage& img : Images[j]) { // We're working with two intervals here, the image's and the line height's. // let's find the union of these two. float union_from, union_to; union_from = std::max(y, img.m_YFrom); union_to = std::min(y + prelim_line_height, img.m_YTo); // The union is not empty if (union_to > union_from) { if (j == 0) width_range_from = std::max(width_range_from, img.m_Indentation); else width_range_to = std::min(width_range_to, Width - img.m_Indentation); } } } // compute offset based on what kind of alignment float CGUIText::GetLineOffset( const EAlign align, const float width_range_from, const float width_range_to, const CSize2D& line_size) const { switch (align) { case EAlign::LEFT: // don't add an offset return 0.f; case EAlign::CENTER: return ((width_range_to - width_range_from) - line_size.Width) / 2; case EAlign::RIGHT: return width_range_to - line_size.Width; default: debug_warn(L"Broken EAlign in CGUIText()"); return 0.f; } } bool CGUIText::AssembleCalls( const CGUI& pGUI, const CGUIString& string, const CStrIntern& Font, const IGUIObject* pObject, const bool FirstLine, const float Width, const float width_range_to, const float dx, const float y, const int temp_from, const int i, float& x, int& from) { bool done = false; for (int j = temp_from; j <= i; ++j) { // We don't want to use Feedback now, so we'll have to use another one. CGUIString::SFeedback Feedback2; // Defaults string.GenerateTextCall(pGUI, Feedback2, Font, string.m_Words[j], string.m_Words[j+1], FirstLine, pObject); // Iterate all and set X/Y values // Since X values are not set, we need to make an internal // iteration with an increment that will append the internal // x, that is what x_pointer is for. float x_pointer = 0.f; for (STextCall& tc : Feedback2.m_TextCalls) { tc.m_Pos = CVector2D(dx + x + x_pointer, y); x_pointer += tc.m_Size.Width; if (tc.m_pSpriteCall) tc.m_pSpriteCall->m_Area += tc.m_Pos - CSize2D(0, tc.m_pSpriteCall->m_Area.GetHeight()); } // Append X value. x += Feedback2.m_Size.Width; // The first word overrides the width limit, what we // do, in those cases, are just drawing that word even // though it'll extend the object. if (Width != 0) // only if word-wrapping is applicable { if (Feedback2.m_NewLine) { from = j + 1; // Sprite call can exist within only a newline segment, // therefore we need this. - m_SpriteCalls.insert( - m_SpriteCalls.end(), - std::make_move_iterator(Feedback2.m_SpriteCalls.begin()), - std::make_move_iterator(Feedback2.m_SpriteCalls.end())); + if (!Feedback2.m_SpriteCalls.empty()) + { + auto newEnd = std::remove_if(Feedback2.m_TextCalls.begin(), Feedback2.m_TextCalls.end(), [](const STextCall& call) { return !call.m_pSpriteCall; }); + m_TextCalls.insert( + m_TextCalls.end(), + std::make_move_iterator(Feedback2.m_TextCalls.begin()), + std::make_move_iterator(newEnd)); + m_SpriteCalls.insert( + m_SpriteCalls.end(), + std::make_move_iterator(Feedback2.m_SpriteCalls.begin()), + std::make_move_iterator(Feedback2.m_SpriteCalls.end())); + } break; } else if (x > width_range_to && j == temp_from) { from = j+1; // do not break, since we want it to be added to m_TextCalls } else if (x > width_range_to) { from = j; break; } } // Add the whole Feedback2.m_TextCalls to our m_TextCalls. m_TextCalls.insert( m_TextCalls.end(), std::make_move_iterator(Feedback2.m_TextCalls.begin()), std::make_move_iterator(Feedback2.m_TextCalls.end())); m_SpriteCalls.insert( m_SpriteCalls.end(), std::make_move_iterator(Feedback2.m_SpriteCalls.begin()), std::make_move_iterator(Feedback2.m_SpriteCalls.end())); if (j == static_cast(string.m_Words.size()) - 2) done = true; } return done; } void CGUIText::Draw(CGUI& pGUI, const CGUIColor& DefaultColor, const CVector2D& pos, const float z, const CRect& clipping) const { CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text); tech->BeginPass(); bool isClipped = clipping != CRect(); if (isClipped) { glEnable(GL_SCISSOR_TEST); glScissor( clipping.left * g_GuiScale, g_yres - clipping.bottom * g_GuiScale, clipping.GetWidth() * g_GuiScale, clipping.GetHeight() * g_GuiScale); } CTextRenderer textRenderer(tech->GetShader()); textRenderer.SetClippingRect(clipping); textRenderer.Translate(0.0f, 0.0f, z); for (const STextCall& tc : m_TextCalls) { // If this is just a placeholder for a sprite call, continue if (tc.m_pSpriteCall) continue; textRenderer.Color(tc.m_UseCustomColor ? tc.m_Color : DefaultColor); textRenderer.Font(tc.m_Font); textRenderer.Put(floorf(pos.X + tc.m_Pos.X), floorf(pos.Y + tc.m_Pos.Y), &tc.m_String); } textRenderer.Render(); for (const SSpriteCall& sc : m_SpriteCalls) pGUI.DrawSprite(sc.m_Sprite, z, sc.m_Area + pos); if (isClipped) glDisable(GL_SCISSOR_TEST); tech->EndPass(); } Index: ps/trunk/source/gui/CGUIText.h =================================================================== --- ps/trunk/source/gui/CGUIText.h (revision 25352) +++ ps/trunk/source/gui/CGUIText.h (revision 25353) @@ -1,285 +1,280 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #ifndef INCLUDED_GUITEXT #define INCLUDED_GUITEXT #include "gui/CGUISprite.h" #include "gui/SettingTypes/CGUIColor.h" #include "gui/SettingTypes/EAlign.h" #include "maths/Rect.h" #include "maths/Size2D.h" #include "maths/Vector2D.h" #include "ps/CStrIntern.h" #include #include #include class CGUI; class CGUIString; class IGUIObject; struct SGenerateTextImage; using SGenerateTextImages = std::array, 2>; /** * An CGUIText object is a parsed string, divided into * text-rendering components. Each component, being a * call to the Renderer. For instance, if you by tags * change the color, then the GUI will have to make * individual calls saying it want that color on the * text. * * For instance: * "Hello [b]there[/b] bunny!" * * That without word-wrapping would mean 3 components. * i.e. 3 calls to CRenderer. One drawing "Hello", * one drawing "there" in bold, and one drawing "bunny!". */ class CGUIText { public: /** * A sprite call to the CRenderer */ struct SSpriteCall { // The CGUISpriteInstance makes this uncopyable to avoid invalidating its draw cache NONCOPYABLE(SSpriteCall); MOVABLE(SSpriteCall); SSpriteCall() {} /** * Size and position of sprite */ CRect m_Area; /** * Sprite from global GUI sprite database. */ CGUISpriteInstance m_Sprite; - - /** - * Tooltip text - */ - CStrW m_Tooltip; - - /** - * Tooltip style - */ - CStrW m_TooltipStyle; }; /** * A text call to the CRenderer */ struct STextCall { NONCOPYABLE(STextCall); MOVABLE(STextCall); STextCall() : m_UseCustomColor(false), m_Bold(false), m_Italic(false), m_Underlined(false), m_pSpriteCall(nullptr) {} /** * Position */ CVector2D m_Pos; /** * Size */ CSize2D m_Size; /** * The string that is suppose to be rendered. */ CStrW m_String; /** * Use custom color? If true then m_Color is used, * else the color inputted will be used. */ bool m_UseCustomColor; /** * Color setup */ CGUIColor m_Color; /** * Font name */ CStrIntern m_Font; /** * Settings */ bool m_Bold, m_Italic, m_Underlined; /** + * Tooltip text + */ + CStrW m_Tooltip; + + /** * *IF* an icon, then this is not nullptr. */ std::list::pointer m_pSpriteCall; }; // The SSpriteCall CGUISpriteInstance makes this uncopyable to avoid invalidating its draw cache. // Also take advantage of exchanging the containers directly with move semantics. NONCOPYABLE(CGUIText); MOVABLE(CGUIText); /** * Generates empty text. */ CGUIText() = default; /** * Generate a CGUIText object from the inputted string. * The function will break down the string and its * tags to calculate exactly which rendering queries * will be sent to the Renderer. Also, horizontal alignment * is taken into acount in this method but NOT vertical alignment. * * @param Text Text to generate CGUIText object from * @param Font Default font, notice both Default color and default font * can be changed by tags. * @param Width Width, 0 if no word-wrapping. * @param BufferZone space between text and edge, and space between text and images. * @param pObject Optional parameter for error output. Used *only* if error parsing fails, * and we need to be able to output which object the error occurred in to aid the user. */ CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, const float Width, const float BufferZone, const IGUIObject* pObject); /** * Draw this CGUIText object */ void Draw(CGUI& pGUI, const CGUIColor& DefaultColor, const CVector2D& pos, const float z, const CRect& clipping) const; const CSize2D& GetSize() const { return m_Size; } const std::list& GetSpriteCalls() const { return m_SpriteCalls; } const std::vector& GetTextCalls() const { return m_TextCalls; } // Helper functions of the constructor bool ProcessLine( const CGUI& pGUI, const CGUIString& string, const CStrIntern& Font, const IGUIObject* pObject, const SGenerateTextImages& Images, const EAlign align, const float prelim_line_height, const float Width, const float BufferZone, bool& FirstLine, float& x, float& y, int& i, int& from); void SetupSpriteCalls( const CGUI& pGUI, const std::array, 2>& FeedbackImages, const float y, const float Width, const float BufferZone, const int i, const int pos_last_img, SGenerateTextImages& Images); float GetLineOffset( const EAlign align, const float width_range_from, const float width_range_to, const CSize2D& line_size) const; void ComputeLineRange( const SGenerateTextImages& Images, const float y, const float Width, const float prelim_line_height, float& width_range_from, float& width_range_to) const; void ComputeLineSize( const CGUI& pGUI, const CGUIString& string, const CStrIntern& Font, const bool FirstLine, const float Width, const float width_range_to, const int i, const int temp_from, float& x, CSize2D& line_size) const; bool AssembleCalls( const CGUI& pGUI, const CGUIString& string, const CStrIntern& Font, const IGUIObject* pObject, const bool FirstLine, const float Width, const float width_range_to, const float dx, const float y, const int temp_from, const int i, float& x, int& from); /** * List of TextCalls, for instance "Hello", "there!" */ std::vector m_TextCalls; /** * List of sprites, or "icons" that should be rendered * along with the text. */ std::list m_SpriteCalls; // list for consistent mem addresses // so that we can point to elements. /** * Width and height of the whole output, used when setting up * scrollbars and such. */ CSize2D m_Size; }; struct SGenerateTextImage { // The image's starting location in Y float m_YFrom; // The image's end location in Y float m_YTo; // The image width in other words float m_Indentation; void SetupSpriteCall( const bool Left, CGUIText::SSpriteCall& SpriteCall, const float width, const float y, const CSize2D& Size, const CStr& TextureName, const float BufferZone); }; #endif // INCLUDED_GUITEXT Index: ps/trunk/source/gui/GUITooltip.cpp =================================================================== --- ps/trunk/source/gui/GUITooltip.cpp (revision 25352) +++ ps/trunk/source/gui/GUITooltip.cpp (revision 25353) @@ -1,344 +1,331 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #include "precompiled.h" #include "GUITooltip.h" #include "gui/CGUI.h" #include "gui/ObjectBases/IGUIObject.h" #include "lib/timer.h" #include "ps/CLogger.h" /* Tooltips: When holding the mouse stationary over an object for some amount of time, the tooltip is displayed. If the mouse moves off that object, the tooltip disappears. If the mouse re-enters an object within a short time, the new tooltip is displayed immediately. (This lets you run the mouse across a series of buttons, without waiting ages for the text to pop up every time.) See Visual Studio's toolbar buttons for an example. Implemented as a state machine: (where "*" lines are checked constantly, and "<" lines are handled on entry to that state) IN MOTION * If the mouse stops, check whether it should have a tooltip and move to 'STATIONARY, NO TOOLTIP' or 'STATIONARY, TOOLIP' * If the mouse enters an object with a tooltip delay of 0, switch to 'SHOWING' STATIONARY, NO TOOLTIP * If the mouse moves, switch to 'IN MOTION' STATIONARY, TOOLTIP < Set target time = now + tooltip time * If the mouse moves, switch to 'IN MOTION' * If now > target time, switch to 'SHOWING' SHOWING < Start displaying the tooltip * If the mouse leaves the object, check whether the new object has a tooltip and switch to 'SHOWING' or 'COOLING' COOLING (since I can't think of a better name) < Stop displaying the tooltip < Set target time = now + cooldown time * If the mouse has moved and is over a tooltipped object, switch to 'SHOWING' * If now > target time, switch to 'STATIONARY, NO TOOLTIP' */ enum { ST_IN_MOTION, ST_STATIONARY_NO_TOOLTIP, ST_STATIONARY_TOOLTIP, ST_SHOWING, ST_COOLING }; GUITooltip::GUITooltip() : m_State(ST_IN_MOTION), m_PreviousObject(nullptr), m_PreviousTooltipName() { } const double CooldownTime = 0.25; // TODO: Don't hard-code this value bool GUITooltip::GetTooltip(IGUIObject* obj, CStr& style) { - if (obj && obj->SettingExists("_icon_tooltip_style") && obj->MouseOverIcon()) - { - style = obj->GetSetting("_icon_tooltip_style"); - if (!obj->GetSetting("_icon_tooltip").empty()) - { - if (style.empty()) - style = "default"; - m_IsIconTooltip = true; - return true; - } - } + if (!obj) + return false; - if (obj && obj->SettingExists("tooltip_style")) - { - style = obj->GetSetting("tooltip_style"); - if (!obj->GetSetting("tooltip").empty()) - { - if (style.empty()) - style = "default"; - m_IsIconTooltip = false; - return true; - } - } + if (obj->GetTooltipText().empty()) + return false; - return false; + style = obj->GetTooltipStyle(); + if (style.empty()) + style = "default"; + return true; } void GUITooltip::ShowTooltip(IGUIObject* obj, const CVector2D& pos, const CStr& style, CGUI& pGUI) { ENSURE(obj); if (style.empty()) return; // Must be a CTooltip* IGUIObject* tooltipobj = pGUI.FindObjectByName("__tooltip_" + style); if (!tooltipobj || !tooltipobj->SettingExists("use_object")) { LOGERROR("Cannot find tooltip named '%s'", style.c_str()); return; } IGUIObject* usedobj; // object actually used to display the tooltip in const CStr& usedObjectName = tooltipobj->GetSetting("use_object"); if (usedObjectName.empty()) { usedobj = tooltipobj; if (usedobj->SettingExists("_mousepos")) { usedobj->SetSetting("_mousepos", pos, true); } else { LOGERROR("Object '%s' used by tooltip '%s' isn't a tooltip object!", usedObjectName.c_str(), style.c_str()); return; } } else { usedobj = pGUI.FindObjectByName(usedObjectName); if (!usedobj) { LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str()); return; } } if (usedobj->SettingExists("caption")) { - const CStrW& text = obj->GetSetting(m_IsIconTooltip ? "_icon_tooltip" : "tooltip"); + const CStrW& text = obj->GetTooltipText(); usedobj->SetSettingFromString("caption", text, true); } else { LOGERROR("Object '%s' used by tooltip '%s' must have a caption setting!", usedobj->GetPresentableName().c_str(), style.c_str()); return; } // Every IGUIObject has a "hidden" setting usedobj->SetSetting("hidden", false, true); } void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI) { if (style.empty()) return; // Must be a CTooltip* IGUIObject* tooltipobj = pGUI.FindObjectByName("__tooltip_" + style); if (!tooltipobj || !tooltipobj->SettingExists("use_object") || !tooltipobj->SettingExists("hide_object")) { LOGERROR("Cannot find tooltip named '%s' or it is not a tooltip", style.c_str()); return; } const CStr& usedObjectName = tooltipobj->GetSetting("use_object"); if (!usedObjectName.empty()) { IGUIObject* usedobj = pGUI.FindObjectByName(usedObjectName); if (usedobj && usedobj->SettingExists("caption")) { usedobj->SetSettingFromString("caption", L"", true); } else { LOGERROR("Object named '%s' used by tooltip '%s' does not exist or does not have a caption setting!", usedObjectName.c_str(), style.c_str()); return; } if (tooltipobj->GetSetting("hide_object")) // Every IGUIObject has a "hidden" setting usedobj->SetSetting("hidden", true, true); } else tooltipobj->SetSetting("hidden", true, true); } static i32 GetTooltipDelay(const CStr& style, CGUI& pGUI) { // Must be a CTooltip* IGUIObject* tooltipobj = pGUI.FindObjectByName("__tooltip_" + style); if (!tooltipobj) { LOGERROR("Cannot find tooltip object named '%s'", style.c_str()); return 500; } return tooltipobj->GetSetting("delay"); } void GUITooltip::Update(IGUIObject* Nearest, const CVector2D& MousePos, CGUI& GUI) { // Called once per frame, so efficiency isn't vital double now = timer_Time(); CStr style; int nextstate = -1; switch (m_State) { case ST_IN_MOTION: if (MousePos == m_PreviousMousePos) { if (GetTooltip(Nearest, style)) nextstate = ST_STATIONARY_TOOLTIP; else nextstate = ST_STATIONARY_NO_TOOLTIP; } else { // Check for movement onto a zero-delayed tooltip if (GetTooltip(Nearest, style) && GetTooltipDelay(style, GUI)==0) { // Reset any previous tooltips completely //m_Time = now + (double)GetTooltipDelay(style, GUI) / 1000.; HideTooltip(m_PreviousTooltipName, GUI); nextstate = ST_SHOWING; } } break; case ST_STATIONARY_NO_TOOLTIP: if (MousePos != m_PreviousMousePos) nextstate = ST_IN_MOTION; break; case ST_STATIONARY_TOOLTIP: if (MousePos != m_PreviousMousePos) nextstate = ST_IN_MOTION; else if (now >= m_Time) { // Make sure the tooltip still exists if (GetTooltip(Nearest, style)) nextstate = ST_SHOWING; else { // Failed to retrieve style - the object has probably been // altered, so just restart the process nextstate = ST_IN_MOTION; } } break; case ST_SHOWING: - // Handle special case of icon tooltips - if (Nearest == m_PreviousObject && (!m_IsIconTooltip || Nearest->MouseOverIcon())) + // Handle sub-object tooltips. + if (Nearest == m_PreviousObject) { // Still showing the same object's tooltip, but the text might have changed if (GetTooltip(Nearest, style)) ShowTooltip(Nearest, MousePos, style, GUI); + else + nextstate = ST_COOLING; } else { // Mouse moved onto a new object if (GetTooltip(Nearest, style)) { CStr style_old; // If we're displaying a tooltip with no delay, then we want to // reset so that other object that should have delay can't // "ride this tail", it have to wait. // Notice that this doesn't apply to when you go from one delay=0 // to another delay=0 if (GetTooltip(m_PreviousObject, style_old) && GetTooltipDelay(style_old, GUI) == 0 && GetTooltipDelay(style, GUI) != 0) { HideTooltip(m_PreviousTooltipName, GUI); nextstate = ST_IN_MOTION; } else { // Hide old scrollbar HideTooltip(m_PreviousTooltipName, GUI); nextstate = ST_SHOWING; } } else nextstate = ST_COOLING; } break; case ST_COOLING: if (GetTooltip(Nearest, style)) nextstate = ST_SHOWING; else if (now >= m_Time) nextstate = ST_IN_MOTION; break; } // Handle state-entry code: if (nextstate != -1) { switch (nextstate) { case ST_STATIONARY_TOOLTIP: m_Time = now + (double)GetTooltipDelay(style, GUI) / 1000.; break; case ST_SHOWING: ShowTooltip(Nearest, MousePos, style, GUI); m_PreviousTooltipName = style; break; case ST_COOLING: HideTooltip(m_PreviousTooltipName, GUI); m_Time = now + CooldownTime; break; } m_State = nextstate; } m_PreviousMousePos = MousePos; m_PreviousObject = Nearest; } Index: ps/trunk/source/gui/GUITooltip.h =================================================================== --- ps/trunk/source/gui/GUITooltip.h (revision 25352) +++ ps/trunk/source/gui/GUITooltip.h (revision 25353) @@ -1,50 +1,49 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #ifndef INCLUDED_GUITOOLTIP #define INCLUDED_GUITOOLTIP class IGUIObject; class CGUI; #include "maths/Vector2D.h" #include "ps/CStr.h" class GUITooltip { public: NONCOPYABLE(GUITooltip); GUITooltip(); void Update(IGUIObject* Nearest, const CVector2D& MousePos, CGUI& GUI); private: void ShowTooltip(IGUIObject* obj, const CVector2D& pos, const CStr& style, CGUI& pGUI); void HideTooltip(const CStr& style, CGUI& pGUI); bool GetTooltip(IGUIObject* obj, CStr& style); int m_State; IGUIObject* m_PreviousObject; CStr m_PreviousTooltipName; CVector2D m_PreviousMousePos; double m_Time; - bool m_IsIconTooltip; }; #endif // INCLUDED_GUITOOLTIP Index: ps/trunk/source/gui/ObjectBases/IGUIObject.cpp =================================================================== --- ps/trunk/source/gui/ObjectBases/IGUIObject.cpp (revision 25352) +++ ps/trunk/source/gui/ObjectBases/IGUIObject.cpp (revision 25353) @@ -1,565 +1,560 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #include "precompiled.h" #include "IGUIObject.h" #include "gui/CGUI.h" #include "gui/CGUISetting.h" #include "gui/Scripting/JSInterface_GUIProxy.h" #include "js/Conversions.h" #include "ps/CLogger.h" #include "ps/GameSetup/Config.h" #include "ps/Profile.h" #include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptExtraHeaders.h" #include "scriptinterface/ScriptInterface.h" #include "soundmanager/ISoundManager.h" #include #include const CStr IGUIObject::EventNameMouseEnter = "MouseEnter"; const CStr IGUIObject::EventNameMouseMove = "MouseMove"; const CStr IGUIObject::EventNameMouseLeave = "MouseLeave"; IGUIObject::IGUIObject(CGUI& pGUI) : m_pGUI(pGUI), m_pParent(), m_MouseHovering(), m_LastClickTime(), m_Enabled(), m_Hidden(), m_Size(), m_Style(), m_Hotkey(), m_Z(), m_Absolute(), m_Ghost(), m_AspectRatio(), m_Tooltip(), m_TooltipStyle() { RegisterSetting("enabled", m_Enabled); RegisterSetting("hidden", m_Hidden); RegisterSetting("size", m_Size); RegisterSetting("style", m_Style); RegisterSetting("hotkey", m_Hotkey); RegisterSetting("z", m_Z); RegisterSetting("absolute", m_Absolute); RegisterSetting("ghost", m_Ghost); RegisterSetting("aspectratio", m_AspectRatio); RegisterSetting("tooltip", m_Tooltip); RegisterSetting("tooltip_style", m_TooltipStyle); // Setup important defaults // TODO: Should be in the default style? SetSetting("hidden", false, true); SetSetting("ghost", false, true); SetSetting("enabled", true, true); SetSetting("absolute", true, true); } IGUIObject::~IGUIObject() { for (const std::pair& p : m_Settings) delete p.second; if (!m_ScriptHandlers.empty()) JS_RemoveExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetGeneralJSContext(), Trace, this); // m_Children is deleted along all other GUI Objects in the CGUI destructor } void IGUIObject::AddChild(IGUIObject& pChild) { pChild.SetParent(this); m_Children.push_back(&pChild); } template void IGUIObject::RegisterSetting(const CStr& Name, T& Value) { if (SettingExists(Name)) LOGERROR("The setting '%s' already exists on the object '%s'!", Name.c_str(), GetPresentableName().c_str()); else m_Settings.emplace(Name, new CGUISetting(*this, Name, Value)); } bool IGUIObject::SettingExists(const CStr& Setting) const { return m_Settings.find(Setting) != m_Settings.end(); } template T& IGUIObject::GetSetting(const CStr& Setting) { return static_cast* >(m_Settings.at(Setting))->m_pSetting; } template const T& IGUIObject::GetSetting(const CStr& Setting) const { return static_cast* >(m_Settings.at(Setting))->m_pSetting; } bool IGUIObject::SetSettingFromString(const CStr& Setting, const CStrW& Value, const bool SendMessage) { const std::map::iterator it = m_Settings.find(Setting); if (it == m_Settings.end()) { LOGERROR("GUI object '%s' has no property called '%s', can't set parse and set value '%s'", GetPresentableName().c_str(), Setting.c_str(), Value.ToUTF8().c_str()); return false; } return it->second->FromString(Value, SendMessage); } template void IGUIObject::SetSetting(const CStr& Setting, T& Value, const bool SendMessage) { PreSettingChange(Setting); static_cast* >(m_Settings.at(Setting))->m_pSetting = std::move(Value); SettingChanged(Setting, SendMessage); } template void IGUIObject::SetSetting(const CStr& Setting, const T& Value, const bool SendMessage) { PreSettingChange(Setting); static_cast* >(m_Settings.at(Setting))->m_pSetting = Value; SettingChanged(Setting, SendMessage); } void IGUIObject::PreSettingChange(const CStr& Setting) { if (Setting == "hotkey") m_pGUI.UnsetObjectHotkey(this, GetSetting(Setting)); } void IGUIObject::SettingChanged(const CStr& Setting, const bool SendMessage) { if (Setting == "size") { // If setting was "size", we need to re-cache itself and all children RecurseObject(nullptr, &IGUIObject::UpdateCachedSize); } else if (Setting == "hidden") { // Hiding an object requires us to reset it and all children if (m_Hidden) RecurseObject(nullptr, &IGUIObject::ResetStates); } else if (Setting == "hotkey") m_pGUI.SetObjectHotkey(this, GetSetting(Setting)); else if (Setting == "style") m_pGUI.SetObjectStyle(this, GetSetting(Setting)); if (SendMessage) { SGUIMessage msg(GUIM_SETTINGS_UPDATED, Setting); HandleMessage(msg); } } bool IGUIObject::IsMouseOver() const { return m_CachedActualSize.PointInside(m_pGUI.GetMousePos()); } -bool IGUIObject::MouseOverIcon() -{ - return false; -} - void IGUIObject::UpdateMouseOver(IGUIObject* const& pMouseOver) { if (pMouseOver == this) { if (!m_MouseHovering) SendMouseEvent(GUIM_MOUSE_ENTER,EventNameMouseEnter); m_MouseHovering = true; SendMouseEvent(GUIM_MOUSE_OVER, EventNameMouseMove); } else { if (m_MouseHovering) { m_MouseHovering = false; SendMouseEvent(GUIM_MOUSE_LEAVE, EventNameMouseLeave); } } } void IGUIObject::ChooseMouseOverAndClosest(IGUIObject*& pObject) { if (!IsMouseOver()) return; // Check if we've got competition at all if (pObject == nullptr) { pObject = this; return; } // Or if it's closer if (GetBufferedZ() >= pObject->GetBufferedZ()) { pObject = this; return; } } IGUIObject* IGUIObject::GetParent() const { // Important, we're not using GetParent() for these // checks, that could screw it up if (m_pParent && m_pParent->m_pParent == nullptr) return nullptr; return m_pParent; } void IGUIObject::ResetStates() { // Notify the gui that we aren't hovered anymore UpdateMouseOver(nullptr); } void IGUIObject::UpdateCachedSize() { // If absolute="false" and the object has got a parent, // use its cached size instead of the screen. Notice // it must have just been cached for it to work. if (!m_Absolute && m_pParent && !IsRootObject()) m_CachedActualSize = m_Size.GetSize(m_pParent->m_CachedActualSize); else m_CachedActualSize = m_Size.GetSize(CRect(0.f, 0.f, g_xres / g_GuiScale, g_yres / g_GuiScale)); // In a few cases, GUI objects have to resize to fill the screen // but maintain a constant aspect ratio. // Adjust the size to be the max possible, centered in the original size: if (m_AspectRatio) { if (m_CachedActualSize.GetWidth() > m_CachedActualSize.GetHeight() * m_AspectRatio) { float delta = m_CachedActualSize.GetWidth() - m_CachedActualSize.GetHeight() * m_AspectRatio; m_CachedActualSize.left += delta/2.f; m_CachedActualSize.right -= delta/2.f; } else { float delta = m_CachedActualSize.GetHeight() - m_CachedActualSize.GetWidth() / m_AspectRatio; m_CachedActualSize.bottom -= delta/2.f; m_CachedActualSize.top += delta/2.f; } } } CRect IGUIObject::GetComputedSize() { UpdateCachedSize(); return m_CachedActualSize; } bool IGUIObject::ApplyStyle(const CStr& StyleName) { if (!m_pGUI.HasStyle(StyleName)) { LOGERROR("IGUIObject: Trying to use style '%s' that doesn't exist.", StyleName.c_str()); return false; } // The default style may specify settings for any GUI object. // Other styles are reported if they specify a Setting that does not exist, // so that the XML author is informed and can correct the style. for (const std::pair& p : m_pGUI.GetStyle(StyleName).m_SettingsDefaults) { if (SettingExists(p.first)) SetSettingFromString(p.first, p.second, true); else if (StyleName != "default") LOGWARNING("GUI object has no setting \"%s\", but the style \"%s\" defines it", p.first, StyleName.c_str()); } return true; } float IGUIObject::GetBufferedZ() const { if (m_Absolute) return m_Z; if (GetParent()) return GetParent()->GetBufferedZ() + m_Z; // In philosophy, a parentless object shouldn't be able to have a relative sizing, // but we'll accept it so that absolute can be used as default without a complaint. // Also, you could consider those objects children to the screen resolution. return m_Z; } void IGUIObject::RegisterScriptHandler(const CStr& eventName, const CStr& Code, CGUI& pGUI) { ScriptRequest rq(pGUI.GetScriptInterface()); const int paramCount = 1; const char* paramNames[paramCount] = { "mouse" }; // Location to report errors from CStr CodeName = GetName() + " " + eventName; // Generate a unique name static int x = 0; char buf[64]; sprintf_s(buf, ARRAY_SIZE(buf), "__eventhandler%d (%s)", x++, eventName.c_str()); // TODO: this is essentially the same code as ScriptInterface::LoadScript (with a tweak for the argument). JS::CompileOptions options(rq.cx); options.setFileAndLine(CodeName.c_str(), 0); options.setIsRunOnce(false); JS::SourceText src; ENSURE(src.init(rq.cx, Code.c_str(), Code.length(), JS::SourceOwnership::Borrowed)); JS::RootedObjectVector emptyScopeChain(rq.cx); JS::RootedFunction func(rq.cx, JS::CompileFunction(rq.cx, emptyScopeChain, options, buf, paramCount, paramNames, src)); if (func == nullptr) { LOGERROR("RegisterScriptHandler: Failed to compile the script for %s", eventName.c_str()); return; } JS::RootedObject funcObj(rq.cx, JS_GetFunctionObject(func)); SetScriptHandler(eventName, funcObj); } void IGUIObject::SetScriptHandler(const CStr& eventName, JS::HandleObject Function) { if (m_ScriptHandlers.empty()) JS_AddExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetGeneralJSContext(), Trace, this); m_ScriptHandlers[eventName] = JS::Heap(Function); if (std::find(m_pGUI.m_EventObjects[eventName].begin(), m_pGUI.m_EventObjects[eventName].end(), this) == m_pGUI.m_EventObjects[eventName].end()) m_pGUI.m_EventObjects[eventName].emplace_back(this); } void IGUIObject::UnsetScriptHandler(const CStr& eventName) { std::map >::iterator it = m_ScriptHandlers.find(eventName); if (it == m_ScriptHandlers.end()) return; m_ScriptHandlers.erase(it); if (m_ScriptHandlers.empty()) JS_RemoveExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetGeneralJSContext(), Trace, this); std::unordered_map>::iterator it2 = m_pGUI.m_EventObjects.find(eventName); if (it2 == m_pGUI.m_EventObjects.end()) return; std::vector& handlers = it2->second; handlers.erase(std::remove(handlers.begin(), handlers.end(), this), handlers.end()); if (handlers.empty()) m_pGUI.m_EventObjects.erase(it2); } InReaction IGUIObject::SendEvent(EGUIMessageType type, const CStr& eventName) { PROFILE2_EVENT("gui event"); PROFILE2_ATTR("type: %s", eventName.c_str()); PROFILE2_ATTR("object: %s", m_Name.c_str()); SGUIMessage msg(type); HandleMessage(msg); ScriptEvent(eventName); return msg.skipped ? IN_PASS : IN_HANDLED; } InReaction IGUIObject::SendMouseEvent(EGUIMessageType type, const CStr& eventName) { PROFILE2_EVENT("gui mouse event"); PROFILE2_ATTR("type: %s", eventName.c_str()); PROFILE2_ATTR("object: %s", m_Name.c_str()); SGUIMessage msg(type); HandleMessage(msg); ScriptRequest rq(m_pGUI.GetScriptInterface()); // Set up the 'mouse' parameter JS::RootedValue mouse(rq.cx); const CVector2D& mousePos = m_pGUI.GetMousePos(); ScriptInterface::CreateObject( rq, &mouse, "x", mousePos.X, "y", mousePos.Y, "buttons", m_pGUI.GetMouseButtons()); JS::RootedValueVector paramData(rq.cx); ignore_result(paramData.append(mouse)); ScriptEvent(eventName, paramData); return msg.skipped ? IN_PASS : IN_HANDLED; } void IGUIObject::ScriptEvent(const CStr& eventName) { ScriptEventWithReturn(eventName); } bool IGUIObject::ScriptEventWithReturn(const CStr& eventName) { if (m_ScriptHandlers.find(eventName) == m_ScriptHandlers.end()) return false; ScriptRequest rq(m_pGUI.GetScriptInterface()); JS::RootedValueVector paramData(rq.cx); return ScriptEventWithReturn(eventName, paramData); } void IGUIObject::ScriptEvent(const CStr& eventName, const JS::HandleValueArray& paramData) { ScriptEventWithReturn(eventName, paramData); } bool IGUIObject::ScriptEventWithReturn(const CStr& eventName, const JS::HandleValueArray& paramData) { std::map >::iterator it = m_ScriptHandlers.find(eventName); if (it == m_ScriptHandlers.end()) return false; ScriptRequest rq(m_pGUI.GetScriptInterface()); JS::RootedObject obj(rq.cx, GetJSObject()); JS::RootedValue handlerVal(rq.cx, JS::ObjectValue(*it->second)); JS::RootedValue result(rq.cx); if (!JS_CallFunctionValue(rq.cx, obj, handlerVal, paramData, &result)) { LOGERROR("Errors executing script event \"%s\"", eventName.c_str()); ScriptException::CatchPending(rq); return false; } return JS::ToBoolean(result); } JSObject* IGUIObject::GetJSObject() { // Cache the object when somebody first asks for it, because otherwise // we end up doing far too much object allocation. if (!m_JSObject) CreateJSObject(); return m_JSObject->Get(); } bool IGUIObject::IsEnabled() const { return m_Enabled; } bool IGUIObject::IsHidden() const { return m_Hidden; } bool IGUIObject::IsHiddenOrGhost() const { return m_Hidden || m_Ghost; } void IGUIObject::PlaySound(const CStrW& soundPath) const { if (g_SoundManager && !soundPath.empty()) g_SoundManager->PlayAsUI(soundPath.c_str(), false); } CStr IGUIObject::GetPresentableName() const { // __internal(), must be at least 13 letters to be able to be // an internal name if (m_Name.length() <= 12) return m_Name; if (m_Name.substr(0, 10) == "__internal") return CStr("[unnamed object]"); else return m_Name; } void IGUIObject::SetFocus() { m_pGUI.SetFocusedObject(this); } void IGUIObject::ReleaseFocus() { m_pGUI.SetFocusedObject(nullptr); } bool IGUIObject::IsFocused() const { return m_pGUI.GetFocusedObject() == this; } bool IGUIObject::IsBaseObject() const { return this == m_pGUI.GetBaseObject(); } bool IGUIObject::IsRootObject() const { return m_pParent == m_pGUI.GetBaseObject(); } void IGUIObject::TraceMember(JSTracer* trc) { // Please ensure to adapt the Tracer enabling and disabling in accordance with the GC things traced! for (std::pair>& handler : m_ScriptHandlers) JS::TraceEdge(trc, &handler.second, "IGUIObject::m_ScriptHandlers"); } // Instantiate templated functions: // These functions avoid copies by working with a reference and move semantics. #define TYPE(T) \ template void IGUIObject::RegisterSetting(const CStr& Name, T& Value); \ template T& IGUIObject::GetSetting(const CStr& Setting); \ template const T& IGUIObject::GetSetting(const CStr& Setting) const; \ template void IGUIObject::SetSetting(const CStr& Setting, T& Value, const bool SendMessage); \ #include "gui/GUISettingTypes.h" #undef TYPE // Copying functions - discouraged except for primitives. #define TYPE(T) \ template void IGUIObject::SetSetting(const CStr& Setting, const T& Value, const bool SendMessage); \ #define GUITYPE_IGNORE_NONCOPYABLE #include "gui/GUISettingTypes.h" #undef GUITYPE_IGNORE_NONCOPYABLE #undef TYPE Index: ps/trunk/source/gui/ObjectBases/IGUIObject.h =================================================================== --- ps/trunk/source/gui/ObjectBases/IGUIObject.h (revision 25352) +++ ps/trunk/source/gui/ObjectBases/IGUIObject.h (revision 25353) @@ -1,560 +1,558 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ /* * The base class of an object. * All objects are derived from this class. * It's an abstract data type, so it can't be used per se. * Also contains a Dummy object which is used for completely blank objects. */ #ifndef INCLUDED_IGUIOBJECT #define INCLUDED_IGUIOBJECT #include "gui/SettingTypes/CGUISize.h" #include "gui/SGUIMessage.h" #include "lib/input.h" // just for IN_PASS #include "ps/XML/Xeromyces.h" #include "scriptinterface/ScriptTypes.h" #include #include class CGUI; class IGUIObject; class IGUIProxyObject; class IGUISetting; template class JSI_GUIProxy; #define GUI_OBJECT(obj) \ public: \ static IGUIObject* ConstructObject(CGUI& pGUI) \ { return new obj(pGUI); } /** * GUI object such as a button or an input-box. * Abstract data type ! */ class IGUIObject { friend class CGUI; // Allow getProperty to access things like GetParent() template friend class JSI_GUIProxy; public: NONCOPYABLE(IGUIObject); IGUIObject(CGUI& pGUI); virtual ~IGUIObject(); /** * This function checks if the mouse is hovering the * rectangle that the base setting "size" makes. * Although it is virtual, so one could derive * an object from CButton, which changes only this * to checking the circle that "size" makes. * * This function also returns true if there is a different * GUI object shown on top of this one. */ virtual bool IsMouseOver() const; /** * This function returns true if the mouse is hovering * over this GUI object and if this GUI object is the * topmost object in that screen location. * For example when hovering dropdown list items, the * buttons beneath the list won't return true here. */ virtual bool IsMouseHovering() const { return m_MouseHovering; } - /** - * Test if mouse position is over an icon - */ - virtual bool MouseOverIcon(); - //-------------------------------------------------------- /** @name Leaf Functions */ //-------------------------------------------------------- //@{ /// Get object name, name is unique const CStr& GetName() const { return m_Name; } /// Get object name void SetName(const CStr& Name) { m_Name = Name; } // Get Presentable name. // Will change all internally set names to something like "" CStr GetPresentableName() const; /** * Builds the object hierarchy with references. */ void AddChild(IGUIObject& pChild); /** * Return all child objects of the current object. */ const std::vector& GetChildren() const { return m_Children; } //@} //-------------------------------------------------------- /** @name Settings Management */ //-------------------------------------------------------- //@{ /** * Registers the given setting variables with the GUI object. * Enable XML and JS to modify the given variable. * * @param Type Setting type * @param Name Setting reference name */ template void RegisterSetting(const CStr& Name, T& Value); /** * Returns whether there is a setting with the given name registered. * * @param Setting setting name * @return True if settings exist. */ bool SettingExists(const CStr& Setting) const; /** * Get a mutable reference to the setting. * If no such setting exists, an exception of type std::out_of_range is thrown. * If the value is modified, there is no GUIM_SETTINGS_UPDATED message sent. */ template T& GetSetting(const CStr& Setting); template const T& GetSetting(const CStr& Setting) const; /** * Set a setting by string, regardless of what type it is. * Used to parse setting values from XML files. * For example a CRect(10,10,20,20) is created from "10 10 20 20". * Returns false if the conversion fails, otherwise true. */ bool SetSettingFromString(const CStr& Setting, const CStrW& Value, const bool SendMessage); /** * Assigns the given value to the setting identified by the given name. * Uses move semantics, so do not read from Value after this call. * * @param SendMessage If true, a GUIM_SETTINGS_UPDATED message will be broadcasted to all GUI objects. */ template void SetSetting(const CStr& Setting, T& Value, const bool SendMessage); /** * This variant will copy the value. */ template void SetSetting(const CStr& Setting, const T& Value, const bool SendMessage); /** * Returns whether this object is set to be hidden or ghost. */ bool IsEnabled() const; /** * Returns whether this is object is set to be hidden. */ bool IsHidden() const; /** * Returns whether this object is set to be hidden or ghost. */ bool IsHiddenOrGhost() const; /** * Retrieves the configured sound filename from the given setting name and plays that once. */ void PlaySound(const CStrW& soundPath) const; /** * Send event to this GUI object (HandleMessage and ScriptEvent) * * @param type Type of GUI message to be handled * @param eventName String representation of event name * @return IN_HANDLED if event was handled, or IN_PASS if skipped */ InReaction SendEvent(EGUIMessageType type, const CStr& eventName); /** * Same as SendEvent, but passes mouse coordinates and button state as an argument. */ InReaction SendMouseEvent(EGUIMessageType type, const CStr& eventName); /** * All sizes are relative to resolution, and the calculation * is not wanted in real time, therefore it is cached, update * the cached size with this function. */ virtual void UpdateCachedSize(); /** * Updates and returns the size of the object. */ CRect GetComputedSize(); + virtual const CStrW& GetTooltipText() const { return m_Tooltip; } + virtual const CStr& GetTooltipStyle() const { return m_TooltipStyle; } + /** * Reset internal state of this object. */ virtual void ResetStates(); /** * Set the script handler for a particular object-specific action * * @param eventName Name of action * @param Code Javascript code to execute when the action occurs * @param pGUI GUI instance to associate the script with */ void RegisterScriptHandler(const CStr& eventName, const CStr& Code, CGUI& pGUI); /** * Retrieves the JSObject representing this GUI object. */ JSObject* GetJSObject(); //@} protected: //-------------------------------------------------------- /** @name Called by CGUI and friends * * Methods that the CGUI will call using * its friendship, these should not * be called by user. * These functions' security are a lot * what constitutes the GUI's */ //-------------------------------------------------------- //@{ public: /** * Called on every GUI tick unless the object or one of its parent is hidden/ghost. */ virtual void Tick() {}; /** * This function is called with different messages * for instance when the mouse enters the object. * * @param Message GUI Message */ virtual void HandleMessage(SGUIMessage& UNUSED(Message)) {} /** * Calls an IGUIObject member function recursively on this object and its children. * Aborts recursion at IGUIObjects that have the isRestricted function return true. * The arguments of the callback function must be references. */ template void RecurseObject(bool(IGUIObject::*isRestricted)() const, void(IGUIObject::*callbackFunction)(Args... args), Args&&... args) { if (!IsBaseObject()) { if (isRestricted && (this->*isRestricted)()) return; (this->*callbackFunction)(args...); } for (IGUIObject* const& obj : m_Children) obj->RecurseObject(isRestricted, callbackFunction, args...); } protected: /** * Draws the object. */ virtual void Draw() = 0; /** * Some objects need to be able to pre-emptively process SDL_Event_. * * Only the object with focus will have this function called. * * Returns either IN_PASS or IN_HANDLED. If IN_HANDLED, then * the event won't be passed on and processed by other handlers. */ virtual InReaction PreemptEvent(const SDL_Event_* UNUSED(ev)) { return IN_PASS; } /** * Some objects need to handle the text-related SDL_Event_ manually. * For instance the input box. * * Only the object with focus will have this function called. * * Returns either IN_PASS or IN_HANDLED. If IN_HANDLED, then * the key won't be passed on and processed by other handlers. * This is used for keys that the GUI uses. */ virtual InReaction ManuallyHandleKeys(const SDL_Event_* UNUSED(ev)) { return IN_PASS; } /** * Applies the given style to the object. * * Returns false if the style is not recognised (and thus has * not been applied). */ bool ApplyStyle(const CStr& StyleName); /** * Returns not the Z value, but the actual buffered Z value, i.e. if it's * defined relative, then it will check its parent's Z value and add * the relativity. * * @return Actual Z value on the screen. */ virtual float GetBufferedZ() const; /** * Set parent of this object */ void SetParent(IGUIObject* pParent) { m_pParent = pParent; } public: CGUI& GetGUI() { return m_pGUI; } const CGUI& GetGUI() const { return m_pGUI; } /** * Take focus! */ void SetFocus(); /** * Release focus. */ void ReleaseFocus(); protected: /** * Check if object is focused. */ bool IsFocused() const; /** * NOTE! This will not just return m_pParent, when that is * need use it! There is one exception to it, when the parent is * the top-node (the object that isn't a real object), this * will return nullptr, so that the top-node's children are * seemingly parentless. * * @return Pointer to parent */ IGUIObject* GetParent() const; /** * Handle additional children to the \-tag. In IGUIObject, this function does * nothing. In CList and CDropDown, it handles the \, used to build the data. * * Returning false means the object doesn't recognize the child. Should be reported. * Notice 'false' is default, because an object not using this function, should not * have any additional children (and this function should never be called). */ virtual bool HandleAdditionalChildren(const XMBElement& UNUSED(child), CXeromyces* UNUSED(pFile)) { return false; } /** * Allow the GUI object to process after all child items were handled. * Useful to avoid iterator invalidation with push_back calls. */ virtual void AdditionalChildrenHandled() {} /** * Cached size, real size m_Size is actually dependent on resolution * and can have different *real* outcomes, this is the real outcome * cached to avoid slow calculations in real time. */ CRect m_CachedActualSize; /** * Execute the script for a particular action. * Does nothing if no script has been registered for that action. * The mouse coordinates will be passed as the first argument. * * @param eventName Name of action */ void ScriptEvent(const CStr& eventName); /** * Execute the script for a particular action. * Does nothing if no script has been registered for that action. * The mouse coordinates will be passed as the first argument. * * @param eventName Name of action * * @return True if the script returned something truthy. */ bool ScriptEventWithReturn(const CStr& eventName); /** * Execute the script for a particular action. * Does nothing if no script has been registered for that action. * * @param eventName Name of action * @param paramData JS::HandleValueArray arguments to pass to the event. */ void ScriptEvent(const CStr& eventName, const JS::HandleValueArray& paramData); /** * Execute the script for a particular action. * Does nothing if no script has been registered for that action. * * @param eventName Name of action * @param paramData JS::HandleValueArray arguments to pass to the event. * * @return True if the script returned something truthy. */ bool ScriptEventWithReturn(const CStr& eventName, const JS::HandleValueArray& paramData); /** * Assigns a JS function to the event name. */ void SetScriptHandler(const CStr& eventName, JS::HandleObject Function); /** * Deletes an event handler assigned to the given name, if such a handler exists. */ void UnsetScriptHandler(const CStr& eventName); /** * Inputes the object that is currently hovered, this function * updates this object accordingly (i.e. if it's the object * being inputted one thing happens, and not, another). * * @param pMouseOver Object that is currently hovered, can be nullptr too! */ void UpdateMouseOver(IGUIObject* const& pMouseOver); //@} private: //-------------------------------------------------------- /** @name Internal functions */ //-------------------------------------------------------- //@{ /** * Creates the JS object representing this page upon first use. * This function (and its derived versions) are defined in the GUIProxy implementation file for convenience. */ virtual void CreateJSObject(); /** * Updates some internal data depending on the setting changed. */ void PreSettingChange(const CStr& Setting); void SettingChanged(const CStr& Setting, const bool SendMessage); /** * Inputs a reference pointer, checks if the new inputted object * if hovered, if so, then check if this's Z value is greater * than the inputted object... If so then the object is closer * and we'll replace the pointer with this. * Also Notice input can be nullptr, which means the Z value demand * is out. NOTICE you can't input nullptr as const so you'll have * to set an object to nullptr. * * @param pObject Object pointer, can be either the old one, or * the new one. */ void ChooseMouseOverAndClosest(IGUIObject*& pObject); /** * Returns whether this is the object all other objects are descendants of. */ bool IsBaseObject() const; /** * Returns whether this object is a child of the base object. */ bool IsRootObject() const; static void Trace(JSTracer* trc, void* data) { reinterpret_cast(data)->TraceMember(trc); } void TraceMember(JSTracer* trc); // Variables protected: static const CStr EventNameMouseEnter; static const CStr EventNameMouseMove; static const CStr EventNameMouseLeave; // Name of object CStr m_Name; // Constructed on the heap, will be destroyed along with the the CGUI std::vector m_Children; // Pointer to parent IGUIObject* m_pParent; //This represents the last click time for each mouse button double m_LastClickTime[6]; /** * This variable is true if the mouse is hovering this object and * this object is the topmost object shown in this location. */ bool m_MouseHovering; /** * Settings pool, all an object's settings are located here */ std::map m_Settings; // An object can't function stand alone CGUI& m_pGUI; // Internal storage for registered script handlers. std::map > m_ScriptHandlers; // Cached JSObject representing this GUI object. std::unique_ptr m_JSObject; // Cache references to settings for performance bool m_Enabled; bool m_Hidden; CGUISize m_Size; CStr m_Style; CStr m_Hotkey; float m_Z; bool m_Absolute; bool m_Ghost; float m_AspectRatio; CStrW m_Tooltip; CStr m_TooltipStyle; }; #endif // INCLUDED_IGUIOBJECT Index: ps/trunk/source/gui/ObjectBases/IGUITextOwner.cpp =================================================================== --- ps/trunk/source/gui/ObjectBases/IGUITextOwner.cpp (revision 25352) +++ ps/trunk/source/gui/ObjectBases/IGUITextOwner.cpp (revision 25353) @@ -1,129 +1,123 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #include "precompiled.h" #include "IGUITextOwner.h" #include "gui/CGUI.h" #include "gui/SGUIMessage.h" #include "gui/ObjectBases/IGUIObject.h" #include "gui/SettingTypes/CGUIString.h" #include "maths/Vector2D.h" #include IGUITextOwner::IGUITextOwner(IGUIObject& pObject) : m_pObject(pObject), m_GeneratedTextsValid() { } IGUITextOwner::~IGUITextOwner() { } CGUIText& IGUITextOwner::AddText() { m_GeneratedTexts.emplace_back(); return m_GeneratedTexts.back(); } CGUIText& IGUITextOwner::AddText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone) { // Avoids a move constructor m_GeneratedTexts.emplace_back(m_pObject.GetGUI(), Text, Font, Width, BufferZone, &m_pObject); return m_GeneratedTexts.back(); } void IGUITextOwner::HandleMessage(SGUIMessage& Message) { switch (Message.type) { case GUIM_SETTINGS_UPDATED: // Everything that can change the visual appearance. // it is assumed that the text of the object will be dependent on // these. Although that is not certain, but one will have to manually // change it and disregard this function. - // TODO Gee: (2004-09-07) Make sure this is all options that can affect the text. - if (Message.value == "size" || Message.value == "z" || + if (Message.value == "size" || Message.value == "tooltip" || Message.value == "absolute" || Message.value == "caption" || Message.value == "font" || Message.value == "textcolor" || Message.value == "text_align" || Message.value == "text_valign" || Message.value == "buffer_zone") { m_GeneratedTextsValid = false; } break; default: break; } } void IGUITextOwner::UpdateCachedSize() { // update our text positions m_GeneratedTextsValid = false; } void IGUITextOwner::UpdateText() { if (!m_GeneratedTextsValid) { SetupText(); m_GeneratedTextsValid = true; } } void IGUITextOwner::DrawText(size_t index, const CGUIColor& color, const CVector2D& pos, float z, const CRect& clipping) { UpdateText(); ENSURE(index < m_GeneratedTexts.size() && "Trying to draw a Text Index within a IGUITextOwner that doesn't exist"); m_GeneratedTexts.at(index).Draw(m_pObject.GetGUI(), color, pos, z, clipping); } void IGUITextOwner::CalculateTextPosition(CRect& ObjSize, CVector2D& TextPos, CGUIText& Text) { // The horizontal Alignment is now computed in GenerateText in order to not have to // loop through all of the TextCall objects again. TextPos.X = ObjSize.left; switch (m_pObject.GetSetting("text_valign")) { case EVAlign::TOP: TextPos.Y = ObjSize.top; break; case EVAlign::CENTER: // Round to integer pixel values, else the fonts look awful TextPos.Y = floorf(ObjSize.CenterPoint().Y - Text.GetSize().Height / 2.f); break; case EVAlign::BOTTOM: TextPos.Y = ObjSize.bottom - Text.GetSize().Height; break; default: debug_warn(L"Broken EVAlign in CButton::SetupText()"); break; } } - -bool IGUITextOwner::MouseOverIcon() -{ - return false; -} Index: ps/trunk/source/gui/ObjectBases/IGUITextOwner.h =================================================================== --- ps/trunk/source/gui/ObjectBases/IGUITextOwner.h (revision 25352) +++ ps/trunk/source/gui/ObjectBases/IGUITextOwner.h (revision 25353) @@ -1,128 +1,123 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ /* GUI Object Base - Text Owner --Overview-- Interface class that enhance the IGUIObject with cached CGUIStrings. This class is not at all needed, and many controls that will use CGUIStrings might not use this, but does help for regular usage such as a text-box, a button, a radio button etc. */ #ifndef INCLUDED_IGUITEXTOWNER #define INCLUDED_IGUITEXTOWNER #include "maths/Rect.h" #include struct CGUIColor; struct SGUIMessage; class CGUIText; class CGUIString; class IGUIObject; class CStrW; class CVector2D; /** * Framework for handling Output text. */ class IGUITextOwner { NONCOPYABLE(IGUITextOwner); public: IGUITextOwner(IGUIObject& pObject); virtual ~IGUITextOwner(); /** * Adds a text object. */ CGUIText& AddText(); /** * Adds a text generated by the given arguments. */ CGUIText& AddText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone); /** * @see IGUIObject#HandleMessage() */ virtual void HandleMessage(SGUIMessage& Message); /** * @see IGUIObject#UpdateCachedSize() */ virtual void UpdateCachedSize(); /** * Draws the Text. * * @param index Index value of text. Mostly this will be 0 * @param color * @param pos Position * @param z Z value * @param clipping Clipping rectangle, don't even add a parameter * to get no clipping. */ virtual void DrawText(size_t index, const CGUIColor& color, const CVector2D& pos, float z, const CRect& clipping = CRect()); - /** - * Test if mouse position is over an icon - */ - virtual bool MouseOverIcon(); - protected: /** * Setup texts. Functions that sets up all texts when changes have been made. */ virtual void SetupText() = 0; /** * Regenerate the text in case it is invalid. Should only be called when inevitable. */ virtual void UpdateText(); /** * Whether the cached text is currently valid (if not then SetupText will be called by Draw) */ bool m_GeneratedTextsValid; /** * Texts that are generated and ready to be rendered. */ std::vector m_GeneratedTexts; /** * Calculate the position for the text, based on the alignment. */ void CalculateTextPosition(CRect& ObjSize, CVector2D& TextPos, CGUIText& Text); private: /** * Reference to the IGUIObject. * Private, because we don't want to inherit it in multiple classes. */ IGUIObject& m_pObject; }; #endif // INCLUDED_IGUITEXTOWNER Index: ps/trunk/source/gui/ObjectTypes/CText.cpp =================================================================== --- ps/trunk/source/gui/ObjectTypes/CText.cpp (revision 25352) +++ ps/trunk/source/gui/ObjectTypes/CText.cpp (revision 25353) @@ -1,257 +1,244 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #include "precompiled.h" #include "CText.h" #include "gui/CGUI.h" #include "gui/CGUIScrollBarVertical.h" #include "gui/CGUIText.h" #include "scriptinterface/ScriptInterface.h" CText::CText(CGUI& pGUI) : IGUIObject(pGUI), IGUIScrollBarOwner(*static_cast(this)), IGUITextOwner(*static_cast(this)), m_BufferZone(), m_Caption(), m_Clip(), m_Font(), m_ScrollBar(), m_ScrollBarStyle(), m_ScrollBottom(), m_ScrollTop(), m_Sprite(), m_TextAlign(), m_TextVAlign(), m_TextColor(), - m_TextColorDisabled(), - m_IconTooltip(), - m_IconTooltipStyle() + m_TextColorDisabled() { RegisterSetting("buffer_zone", m_BufferZone); RegisterSetting("caption", m_Caption); RegisterSetting("clip", m_Clip); RegisterSetting("font", m_Font); RegisterSetting("scrollbar", m_ScrollBar); RegisterSetting("scrollbar_style", m_ScrollBarStyle); RegisterSetting("scroll_bottom", m_ScrollBottom); RegisterSetting("scroll_top", m_ScrollTop); RegisterSetting("sprite", m_Sprite); RegisterSetting("text_align", m_TextAlign); RegisterSetting("text_valign", m_TextVAlign); RegisterSetting("textcolor", m_TextColor); RegisterSetting("textcolor_disabled", m_TextColorDisabled); - // Private settings - RegisterSetting("_icon_tooltip", m_IconTooltip); - RegisterSetting("_icon_tooltip_style", m_IconTooltipStyle); //SetSetting("ghost", true, true); SetSetting("scrollbar", false, true); SetSetting("clip", true, true); // Add scroll-bar CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); bar->SetRightAligned(true); AddScrollBar(bar); // Add text AddText(); } CText::~CText() { } void CText::SetupText() { if (m_GeneratedTexts.empty()) return; float width = m_CachedActualSize.GetWidth(); // remove scrollbar if applicable if (m_ScrollBar && GetScrollBar(0).GetStyle()) width -= GetScrollBar(0).GetStyle()->m_Width; m_GeneratedTexts[0] = CGUIText(m_pGUI, m_Caption, m_Font, width, m_BufferZone, this); if (!m_ScrollBar) CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]); // Setup scrollbar if (m_ScrollBar) { // If we are currently scrolled to the bottom of the text, // then add more lines of text, update the scrollbar so we // stick to the bottom. // (Use 1.5px delta so this triggers the first time caption is set) bool bottom = false; if (m_ScrollBottom && GetScrollBar(0).GetPos() > GetScrollBar(0).GetMaxPos() - 1.5f) bottom = true; GetScrollBar(0).SetScrollRange(m_GeneratedTexts[0].GetSize().Height); GetScrollBar(0).SetScrollSpace(m_CachedActualSize.GetHeight()); GetScrollBar(0).SetX(m_CachedActualSize.right); GetScrollBar(0).SetY(m_CachedActualSize.top); GetScrollBar(0).SetZ(GetBufferedZ()); GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); if (bottom) GetScrollBar(0).SetPos(GetScrollBar(0).GetMaxPos()); if (m_ScrollTop) GetScrollBar(0).SetPos(0.0f); } } void CText::ResetStates() { IGUIObject::ResetStates(); IGUIScrollBarOwner::ResetStates(); } void CText::UpdateCachedSize() { IGUIObject::UpdateCachedSize(); IGUITextOwner::UpdateCachedSize(); } CSize2D CText::GetTextSize() { UpdateText(); return m_GeneratedTexts[0].GetSize(); } +const CStrW& CText::GetTooltipText() const +{ + for (const CGUIText& text : m_GeneratedTexts) + for (const CGUIText::STextCall& textChunk : text.GetTextCalls()) + { + if (textChunk.m_Tooltip.empty()) + continue; + CRect area(textChunk.m_Pos - CVector2D(0.f, textChunk.m_Size.Height), textChunk.m_Size); + if (area.PointInside(m_pGUI.GetMousePos() - m_CachedActualSize.TopLeft())) + return textChunk.m_Tooltip; + } + return m_Tooltip; +} + void CText::HandleMessage(SGUIMessage& Message) { IGUIObject::HandleMessage(Message); IGUIScrollBarOwner::HandleMessage(Message); //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead! switch (Message.type) { case GUIM_SETTINGS_UPDATED: if (Message.value == "scrollbar") SetupText(); // Update scrollbar if (Message.value == "scrollbar_style") { GetScrollBar(0).SetScrollBarStyle(m_ScrollBarStyle); SetupText(); } break; case GUIM_MOUSE_WHEEL_DOWN: { GetScrollBar(0).ScrollPlus(); // Since the scroll was changed, let's simulate a mouse movement // to check if scrollbar now is hovered SGUIMessage msg(GUIM_MOUSE_MOTION); HandleMessage(msg); break; } case GUIM_MOUSE_WHEEL_UP: { GetScrollBar(0).ScrollMinus(); // Since the scroll was changed, let's simulate a mouse movement // to check if scrollbar now is hovered SGUIMessage msg(GUIM_MOUSE_MOTION); HandleMessage(msg); break; } case GUIM_LOAD: { GetScrollBar(0).SetX(m_CachedActualSize.right); GetScrollBar(0).SetY(m_CachedActualSize.top); GetScrollBar(0).SetZ(GetBufferedZ()); GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); GetScrollBar(0).SetScrollBarStyle(m_ScrollBarStyle); break; } default: break; } IGUITextOwner::HandleMessage(Message); } void CText::Draw() { float bz = GetBufferedZ(); if (m_ScrollBar) IGUIScrollBarOwner::Draw(); m_pGUI.DrawSprite(m_Sprite, bz, m_CachedActualSize); float scroll = 0.f; if (m_ScrollBar) scroll = GetScrollBar(0).GetPos(); // Clipping area (we'll have to subtract the scrollbar) CRect cliparea; if (m_Clip) { cliparea = m_CachedActualSize; if (m_ScrollBar) { // subtract scrollbar from cliparea if (cliparea.right > GetScrollBar(0).GetOuterRect().left && cliparea.right <= GetScrollBar(0).GetOuterRect().right) cliparea.right = GetScrollBar(0).GetOuterRect().left; if (cliparea.left >= GetScrollBar(0).GetOuterRect().left && cliparea.left < GetScrollBar(0).GetOuterRect().right) cliparea.left = GetScrollBar(0).GetOuterRect().right; } } const CGUIColor& color = m_Enabled ? m_TextColor : m_TextColorDisabled; if (m_ScrollBar) DrawText(0, color, m_CachedActualSize.TopLeft() - CVector2D(0.f, scroll), bz + 0.1f, cliparea); else DrawText(0, color, m_TextPos, bz + 0.1f, cliparea); } - -bool CText::MouseOverIcon() -{ - for (const CGUIText& guitext : m_GeneratedTexts) - for (const CGUIText::SSpriteCall& spritecall : guitext.GetSpriteCalls()) - { - // Check mouse over sprite - if (!spritecall.m_Area.PointInside(m_pGUI.GetMousePos() - m_CachedActualSize.TopLeft())) - continue; - - // If tooltip exists, set the property - if (!spritecall.m_Tooltip.empty()) - { - SetSettingFromString("_icon_tooltip_style", spritecall.m_TooltipStyle, true); - SetSettingFromString("_icon_tooltip", spritecall.m_Tooltip, true); - } - - return true; - } - - return false; -} Index: ps/trunk/source/gui/ObjectTypes/CText.h =================================================================== --- ps/trunk/source/gui/ObjectTypes/CText.h (revision 25352) +++ ps/trunk/source/gui/ObjectTypes/CText.h (revision 25353) @@ -1,98 +1,93 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #ifndef INCLUDED_CTEXT #define INCLUDED_CTEXT #include "gui/CGUISprite.h" #include "gui/ObjectBases/IGUIObject.h" #include "gui/ObjectBases/IGUIScrollBarOwner.h" #include "gui/ObjectBases/IGUITextOwner.h" #include "gui/SettingTypes/CGUIString.h" /** * Text field that just displays static text. */ class CText : public IGUIObject, public IGUIScrollBarOwner, public IGUITextOwner { GUI_OBJECT(CText) public: CText(CGUI& pGUI); virtual ~CText(); /** * @see IGUIObject#ResetStates() */ virtual void ResetStates(); /** * @see IGUIObject#UpdateCachedSize() */ virtual void UpdateCachedSize(); /** * @return the object text size. */ CSize2D GetTextSize(); - /** - * Test if mouse position is over an icon - */ - virtual bool MouseOverIcon(); + virtual const CStrW& GetTooltipText() const; protected: /** * Sets up text, should be called every time changes has been * made that can change the visual. */ void SetupText(); /** * @see IGUIObject#HandleMessage() */ virtual void HandleMessage(SGUIMessage& Message); /** * Draws the Text */ virtual void Draw(); virtual void CreateJSObject(); /** * Placement of text. Ignored when scrollbars are active. */ CVector2D m_TextPos; // Settings float m_BufferZone; CGUIString m_Caption; bool m_Clip; CStrW m_Font; bool m_ScrollBar; CStr m_ScrollBarStyle; bool m_ScrollBottom; bool m_ScrollTop; CGUISpriteInstance m_Sprite; EAlign m_TextAlign; EVAlign m_TextVAlign; CGUIColor m_TextColor; CGUIColor m_TextColorDisabled; - CStrW m_IconTooltip; - CStr m_IconTooltipStyle; }; #endif // INCLUDED_CTEXT Index: ps/trunk/source/gui/SettingTypes/CGUIString.cpp =================================================================== --- ps/trunk/source/gui/SettingTypes/CGUIString.cpp (revision 25352) +++ ps/trunk/source/gui/SettingTypes/CGUIString.cpp (revision 25353) @@ -1,474 +1,480 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #include "precompiled.h" #include "CGUIString.h" #include "graphics/FontMetrics.h" #include "gui/CGUI.h" #include "gui/ObjectBases/IGUIObject.h" #include "lib/utf8.h" #include "ps/CLogger.h" #include #include // List of word delimiter bounds // The list contains ranges of word delimiters. The odd indexed chars are the start // of a range, the even are the end of a range. The list must be sorted in INCREASING ORDER static const int NUM_WORD_DELIMITERS = 4*2; static const u16 WordDelimiters[NUM_WORD_DELIMITERS] = { ' ' , ' ', // spaces '-' , '-', // hyphens 0x3000, 0x31FF, // ideographic symbols 0x3400, 0x9FFF // TODO add unicode blocks of other languages that don't use spaces }; void CGUIString::SFeedback::Reset() { m_Images[Left].clear(); m_Images[Right].clear(); m_TextCalls.clear(); m_SpriteCalls.clear(); m_Size = CSize2D(); m_NewLine = false; } void CGUIString::GenerateTextCall(const CGUI& pGUI, SFeedback& Feedback, CStrIntern DefaultFont, const int& from, const int& to, const bool FirstLine, const IGUIObject* pObject) const { // Reset width and height, because they will be determined with incrementation // or comparisons. Feedback.Reset(); // Check out which text chunk this is within. for (const TextChunk& textChunk : m_TextChunks) { // Get the area that is overlapped by both the TextChunk and // by the from/to inputted. int _from = std::max(from, textChunk.m_From); int _to = std::min(to, textChunk.m_To); // If from is larger than to, then they are not overlapping if (_to == _from && textChunk.m_From == textChunk.m_To) { // These should never be able to have more than one tag. ENSURE(textChunk.m_Tags.size() == 1); // Icons and images are placed on exactly one position // in the words-list, and they can be counted twice if placed // on an edge. But there is always only one logical preference // that we want. This check filters the unwanted. // it's in the end of one word, and the icon // should really belong to the beginning of the next one if (_to == to && to >= 1 && to < (int)m_RawString.length()) { if (m_RawString[to-1] == ' ' || m_RawString[to-1] == '-' || m_RawString[to-1] == '\n') continue; } // This std::string is just a break if (_from == from && from >= 1) { if (m_RawString[from] == '\n' && m_RawString[from-1] != '\n' && m_RawString[from-1] != ' ' && m_RawString[from-1] != '-') continue; } const TextChunk::Tag& tag = textChunk.m_Tags[0]; ENSURE(tag.m_TagType == TextChunk::Tag::TAG_IMGLEFT || tag.m_TagType == TextChunk::Tag::TAG_IMGRIGHT || tag.m_TagType == TextChunk::Tag::TAG_ICON); const std::string& path = utf8_from_wstring(tag.m_TagValue); if (!pGUI.HasIcon(path)) { if (pObject) LOGERROR("Trying to use an icon, imgleft or imgright-tag with an undefined icon (\"%s\").", path.c_str()); continue; } switch (tag.m_TagType) { case TextChunk::Tag::TAG_IMGLEFT: Feedback.m_Images[SFeedback::Left].push_back(path); break; case TextChunk::Tag::TAG_IMGRIGHT: Feedback.m_Images[SFeedback::Right].push_back(path); break; case TextChunk::Tag::TAG_ICON: { // We'll need to setup a text-call that will point // to the icon, this is to be able to iterate // through the text-calls without having to // complex the structure virtually for nothing more. CGUIText::STextCall TextCall; // Also add it to the sprites being rendered. CGUIText::SSpriteCall SpriteCall; // Get Icon from icon database in pGUI const SGUIIcon& icon = pGUI.GetIcon(path); const CSize2D& size = icon.m_Size; // append width, and make maximum height the height. Feedback.m_Size.Width += size.Width; Feedback.m_Size.Height = std::max(Feedback.m_Size.Height, size.Height); // These are also needed later TextCall.m_Size = size; SpriteCall.m_Area = size; // Handle additional attributes for (const TextChunk::Tag::TagAttribute& tagAttrib : tag.m_TagAttributes) { if (tagAttrib.attrib == L"displace" && !tagAttrib.value.empty()) { // Displace the sprite CSize2D displacement; // Parse the value if (!CGUI::ParseString(&pGUI, tagAttrib.value, displacement)) LOGERROR("Error parsing 'displace' value for tag [ICON]"); else SpriteCall.m_Area += displacement; } else if (tagAttrib.attrib == L"tooltip") - SpriteCall.m_Tooltip = tagAttrib.value; - else if (tagAttrib.attrib == L"tooltip_style") - SpriteCall.m_TooltipStyle = tagAttrib.value; + { + TextCall.m_Tooltip = tagAttrib.value; + LOGWARNING("setting tooltip to %s", TextCall.m_Tooltip.ToUTF8().c_str()); + } } SpriteCall.m_Sprite = icon.m_SpriteName; // Add sprite call Feedback.m_SpriteCalls.push_back(std::move(SpriteCall)); // Finalize text call TextCall.m_pSpriteCall = &Feedback.m_SpriteCalls.back(); // Add text call Feedback.m_TextCalls.emplace_back(std::move(TextCall)); break; } NODEFAULT; } } else if (_to > _from && !Feedback.m_NewLine) { CGUIText::STextCall TextCall; // Set defaults TextCall.m_Font = DefaultFont; TextCall.m_UseCustomColor = false; TextCall.m_String = m_RawString.substr(_from, _to-_from); // Go through tags and apply changes. for (const TextChunk::Tag& tag : textChunk.m_Tags) { switch (tag.m_TagType) { case TextChunk::Tag::TAG_COLOR: TextCall.m_UseCustomColor = true; if (!CGUI::ParseString(&pGUI, tag.m_TagValue, TextCall.m_Color) && pObject) LOGERROR("Error parsing the value of a [color]-tag in GUI text when reading object \"%s\".", pObject->GetPresentableName().c_str()); break; case TextChunk::Tag::TAG_FONT: // TODO Gee: (2004-08-15) Check if Font exists? TextCall.m_Font = CStrIntern(utf8_from_wstring(tag.m_TagValue)); break; + case TextChunk::Tag::TAG_TOOLTIP: + TextCall.m_Tooltip = tag.m_TagValue; + break; default: LOGERROR("Encountered unexpected tag applied to text"); break; } } // Calculate the size of the font CSize2D size; int cx, cy; CFontMetrics font (TextCall.m_Font); font.CalculateStringSize(TextCall.m_String.c_str(), cx, cy); // For anything other than the first line, the line spacing // needs to be considered rather than just the height of the text if (!FirstLine) cy = font.GetLineSpacing(); size.Width = (float)cx; size.Height = (float)cy; // Append width, and make maximum height the height. Feedback.m_Size.Width += size.Width; Feedback.m_Size.Height = std::max(Feedback.m_Size.Height, size.Height); // These are also needed later TextCall.m_Size = size; if (!TextCall.m_String.empty() && TextCall.m_String[0] == '\n') Feedback.m_NewLine = true; // Add text-chunk Feedback.m_TextCalls.emplace_back(std::move(TextCall)); } } } bool CGUIString::TextChunk::Tag::SetTagType(const CStrW& tagtype) { TagType t = GetTagType(tagtype); if (t == TAG_INVALID) return false; m_TagType = t; return true; } CGUIString::TextChunk::Tag::TagType CGUIString::TextChunk::Tag::GetTagType(const CStrW& tagtype) const { if (tagtype == L"color") return TAG_COLOR; if (tagtype == L"font") return TAG_FONT; if (tagtype == L"icon") return TAG_ICON; if (tagtype == L"imgleft") return TAG_IMGLEFT; if (tagtype == L"imgright") return TAG_IMGRIGHT; + if (tagtype == L"tooltip") + return TAG_TOOLTIP; return TAG_INVALID; } void CGUIString::SetValue(const CStrW& str) { m_OriginalString = str; m_TextChunks.clear(); m_Words.clear(); m_RawString.clear(); // Current Text Chunk CGUIString::TextChunk CurrentTextChunk; CurrentTextChunk.m_From = 0; int l = str.length(); int rawpos = 0; CStrW tag; std::vector tags; bool closing = false; for (int p = 0; p < l; ++p) { TextChunk::Tag tag_; switch (str[p]) { case L'[': CurrentTextChunk.m_To = rawpos; // Add the current chunks if it is not empty if (CurrentTextChunk.m_From != rawpos) m_TextChunks.push_back(CurrentTextChunk); CurrentTextChunk.m_From = rawpos; closing = false; if (++p == l) { LOGERROR("Partial tag at end of string '%s'", utf8_from_wstring(str)); break; } if (str[p] == L'/') { closing = true; if (tags.empty()) { LOGERROR("Encountered closing tag without having any open tags. At %d in '%s'", p, utf8_from_wstring(str)); break; } if (++p == l) { LOGERROR("Partial closing tag at end of string '%s'", utf8_from_wstring(str)); break; } } tag.clear(); // Parse tag for (; p < l && str[p] != L']'; ++p) { CStrW name, param; switch (str[p]) { case L' ': if (closing) // We still parse them to make error handling cleaner LOGERROR("Closing tags do not support parameters (at pos %d '%s')", p, utf8_from_wstring(str)); // parse something="something else" for (++p; p < l && str[p] != L'='; ++p) name.push_back(str[p]); if (p == l) { LOGERROR("Parameter without value at pos %d '%s'", p, utf8_from_wstring(str)); break; } FALLTHROUGH; case L'=': // parse a quoted parameter if (closing) // We still parse them to make error handling cleaner LOGERROR("Closing tags do not support parameters (at pos %d '%s')", p, utf8_from_wstring(str)); if (++p == l) { LOGERROR("Expected parameter, got end of string '%s'", utf8_from_wstring(str)); break; } if (str[p] != L'"') { LOGERROR("Unquoted parameters are not supported (at pos %d '%s')", p, utf8_from_wstring(str)); break; } for (++p; p < l && str[p] != L'"'; ++p) { switch (str[p]) { case L'\\': if (++p == l) { LOGERROR("Escape character at end of string '%s'", utf8_from_wstring(str)); break; } // NOTE: We do not support \n in tag parameters FALLTHROUGH; default: param.push_back(str[p]); } } if (!name.empty()) { TextChunk::Tag::TagAttribute a = {name, param}; tag_.m_TagAttributes.push_back(a); } else tag_.m_TagValue = param; break; default: tag.push_back(str[p]); break; } } if (!tag_.SetTagType(tag)) { LOGERROR("Invalid tag '%s' at %d in '%s'", utf8_from_wstring(tag), p, utf8_from_wstring(str)); break; } if (!closing) { if (tag_.m_TagType == TextChunk::Tag::TAG_IMGRIGHT || tag_.m_TagType == TextChunk::Tag::TAG_IMGLEFT || tag_.m_TagType == TextChunk::Tag::TAG_ICON) { TextChunk FreshTextChunk = { rawpos, rawpos }; FreshTextChunk.m_Tags.push_back(tag_); m_TextChunks.push_back(FreshTextChunk); } else { tags.push_back(tag); CurrentTextChunk.m_Tags.push_back(tag_); } } else { if (tag != tags.back()) { LOGERROR("Closing tag '%s' does not match last opened tag '%s' at %d in '%s'", utf8_from_wstring(tag), utf8_from_wstring(tags.back()), p, utf8_from_wstring(str)); break; } tags.pop_back(); CurrentTextChunk.m_Tags.pop_back(); } break; case L'\\': if (++p == l) { LOGERROR("Escape character at end of string '%s'", utf8_from_wstring(str)); break; } if (str[p] == L'n') { ++rawpos; m_RawString.push_back(L'\n'); break; } FALLTHROUGH; default: ++rawpos; m_RawString.push_back(str[p]); break; } } // Add the chunk after the last tag if (CurrentTextChunk.m_From != rawpos) { CurrentTextChunk.m_To = rawpos; m_TextChunks.push_back(CurrentTextChunk); } // Add a delimiter at start and at end, it helps when // processing later, because we don't have make exceptions for // those cases. m_Words.push_back(0); // Add word boundaries in increasing order for (u32 i = 0; i < m_RawString.length(); ++i) { wchar_t c = m_RawString[i]; if (c == '\n') { m_Words.push_back((int)i); m_Words.push_back((int)i+1); continue; } for (int n = 0; n < NUM_WORD_DELIMITERS; n += 2) { if (c <= WordDelimiters[n+1]) { if (c >= WordDelimiters[n]) m_Words.push_back((int)i+1); // assume the WordDelimiters list is stored in increasing order break; } } } m_Words.push_back((int)m_RawString.length()); // Remove duplicates (only if larger than 2) if (m_Words.size() <= 2) return; m_Words.erase(std::unique(m_Words.begin(), m_Words.end()), m_Words.end()); } Index: ps/trunk/source/gui/SettingTypes/CGUIString.h =================================================================== --- ps/trunk/source/gui/SettingTypes/CGUIString.h (revision 25352) +++ ps/trunk/source/gui/SettingTypes/CGUIString.h (revision 25353) @@ -1,219 +1,220 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #ifndef INCLUDED_CGUISTRING #define INCLUDED_CGUISTRING #include "gui/CGUIText.h" #include "ps/CStrIntern.h" #include #include #include class CGUI; /** * String class, substitute for CStr, but that parses * the tags and builds up a list of all text that will * be different when outputted. * * The difference between CGUIString and CGUIText is that * CGUIString is a string-class that parses the tags * when the value is set. The CGUIText is just a container * which stores the positions and settings of all text-calls * that will have to be made to the Renderer. */ class CGUIString { public: /** * A chunk of text that represents one call to the renderer. * In other words, all text in one chunk, will be drawn * exactly with the same settings. */ struct TextChunk { /** * A tag looks like this "Hello [b]there[/b] little" */ struct Tag { /** * Tag Type */ enum TagType { TAG_B, TAG_I, TAG_FONT, TAG_SIZE, TAG_COLOR, TAG_IMGLEFT, TAG_IMGRIGHT, TAG_ICON, + TAG_TOOLTIP, TAG_INVALID }; struct TagAttribute { std::wstring attrib; std::wstring value; }; /** * Set tag from string * * @param tagtype TagType by string, like 'img' for [img] * @return True if m_TagType was set. */ bool SetTagType(const CStrW& tagtype); TagType GetTagType(const CStrW& tagtype) const; /** * In [b="Hello"][/b] * m_TagType is TAG_B */ TagType m_TagType; /** * In [b="Hello"][/b] * m_TagValue is 'Hello' */ std::wstring m_TagValue; /** * Some tags need an additional attributes */ std::vector m_TagAttributes; }; /** * m_From and m_To is the range of the string */ int m_From, m_To; /** * Tags that are present. [a][b] */ std::vector m_Tags; }; /** * All data generated in GenerateTextCall() */ struct SFeedback { // Avoid copying the vector and list containers. NONCOPYABLE(SFeedback); MOVABLE(SFeedback); SFeedback() = default; // Constants static const int Left = 0; static const int Right = 1; /** * Reset all member data. */ void Reset(); /** * Image stacks, for left and right floating images. */ std::array, 2> m_Images; // left and right /** * Text and Sprite Calls. */ std::vector m_TextCalls; // list for consistent mem addresses so that we can point to elements. std::list m_SpriteCalls; /** * Width and Height *feedback* */ CSize2D m_Size; /** * If the word inputted was a new line. */ bool m_NewLine; }; /** * Set the value, the string will automatically * be parsed when set. */ void SetValue(const CStrW& str); /** * Get String, with tags */ const CStrW& GetOriginalString() const { return m_OriginalString; } /** * Get String, stripped of tags */ const CStrW& GetRawString() const { return m_RawString; } /** * Generate Text Call from specified range. The range * must span only within ONE TextChunk though. Otherwise * it can't be fit into a single Text Call * * Notice it won't make it complete, you will have to add * X/Y values and such. * * @param pGUI Pointer to CGUI object making this call, for e.g. icon retrieval. * @param Feedback contains all info that is generated. * @param DefaultFont Default Font * @param from From character n, * @param to to character n. * @param FirstLine Whether this is the first line of text, to calculate its height correctly * @param pObject Only for Error outputting, optional! If nullptr * then no Errors will be reported! Useful when you need * to make several GenerateTextCall in different phases, * it avoids duplicates. */ void GenerateTextCall(const CGUI& pGUI, SFeedback& Feedback, CStrIntern DefaultFont, const int& from, const int& to, const bool FirstLine, const IGUIObject* pObject = nullptr) const; /** * Words */ std::vector m_Words; private: /** * TextChunks */ std::vector m_TextChunks; /** * The full raw string. Stripped of tags. */ CStrW m_RawString; /** * The original string value passed to SetValue. */ CStrW m_OriginalString; }; #endif // INCLUDED_CGUISTRING