From c094e72ede9e3234618444d09c77efd2902bf18c Mon Sep 17 00:00:00 2001 From: historic_bruno Date: Fri, 17 Jan 2014 02:54:57 +0000 Subject: [PATCH] Fixes scoping for icons in GUI text, instead of using only the top page on the stack, which caused errors when dialog boxes popped up over text containing icons This was SVN commit r14591. --- source/gui/CGUI.cpp | 8 ++++---- source/gui/GUIManager.cpp | 12 +----------- source/gui/GUIManager.h | 12 +----------- source/gui/GUItext.cpp | 16 ++++++++-------- source/gui/GUItext.h | 8 ++++++-- 5 files changed, 20 insertions(+), 36 deletions(-) diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 0ec22c5589..e9f529a1a8 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -601,7 +601,7 @@ SGUIText CGUI::GenerateText(const CGUIString &string, float prelim_line_height=0.f; // Width and height of all text calls generated. - string.GenerateTextCall(Feedback, Font, + string.GenerateTextCall(this, Feedback, Font, string.m_Words[i], string.m_Words[i+1], FirstLine); @@ -719,7 +719,7 @@ SGUIText CGUI::GenerateText(const CGUIString &string, // 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(Feedback2, Font, + string.GenerateTextCall(this, Feedback2, Font, string.m_Words[j], string.m_Words[j+1], FirstLine); @@ -772,7 +772,7 @@ SGUIText CGUI::GenerateText(const CGUIString &string, CGUIString::SFeedback Feedback2; // Defaults - string.GenerateTextCall(Feedback2, Font, + string.GenerateTextCall(this, Feedback2, Font, string.m_Words[j], string.m_Words[j+1], FirstLine, pObject); diff --git a/source/gui/GUIManager.cpp b/source/gui/GUIManager.cpp index a9739f02cb..fc57c3461d 100644 --- a/source/gui/GUIManager.cpp +++ b/source/gui/GUIManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -353,16 +353,6 @@ bool CGUIManager::GetPreDefinedColor(const CStr& name, CColor& output) return top()->GetPreDefinedColor(name, output); } -bool CGUIManager::IconExists(const CStr& str) const -{ - return top()->IconExists(str); -} - -SGUIIcon CGUIManager::GetIcon(const CStr& str) const -{ - return top()->GetIcon(str); -} - IGUIObject* CGUIManager::FindObjectByName(const CStr& name) const { // This can be called from scripts run by TickObjects, diff --git a/source/gui/GUIManager.h b/source/gui/GUIManager.h index 2cae269302..24906f8d65 100644 --- a/source/gui/GUIManager.h +++ b/source/gui/GUIManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -102,16 +102,6 @@ public: */ bool GetPreDefinedColor(const CStr& name, CColor& output); - /** - * See CGUI::IconExists; applies to the currently active page. - */ - bool IconExists(const CStr& str) const; - - /** - * See CGUI::GetIcon; applies to the currently active page. - */ - SGUIIcon GetIcon(const CStr& str) const; - /** * See CGUI::FindObjectByName; applies to the currently active page. */ diff --git a/source/gui/GUItext.cpp b/source/gui/GUItext.cpp index 770c8ea003..d832884354 100644 --- a/source/gui/GUItext.cpp +++ b/source/gui/GUItext.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -22,7 +22,6 @@ GUI text #include "precompiled.h" #include "GUI.h" -#include "GUIManager.h" #include "graphics/FontMetrics.h" #include "ps/CLogger.h" #include "ps/Parser.h" @@ -42,7 +41,8 @@ void CGUIString::SFeedback::Reset() m_NewLine=false; } -void CGUIString::GenerateTextCall(SFeedback &Feedback, +void CGUIString::GenerateTextCall(const CGUI *pGUI, + SFeedback &Feedback, CStrIntern DefaultFont, const int &from, const int &to, const bool FirstLine, @@ -98,7 +98,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback, if (itTextChunk->m_Tags[0].m_TagType == CGUIString::TextChunk::Tag::TAG_IMGLEFT) { // Only add the image if the icon exists. - if (g_GUI->IconExists(itTextChunk->m_Tags[0].m_TagValue)) + if (pGUI->IconExists(itTextChunk->m_Tags[0].m_TagValue)) { Feedback.m_Images[SFeedback::Left].push_back(itTextChunk->m_Tags[0].m_TagValue); } @@ -111,7 +111,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback, if (itTextChunk->m_Tags[0].m_TagType == CGUIString::TextChunk::Tag::TAG_IMGRIGHT) { // Only add the image if the icon exists. - if (g_GUI->IconExists(itTextChunk->m_Tags[0].m_TagValue)) + if (pGUI->IconExists(itTextChunk->m_Tags[0].m_TagValue)) { Feedback.m_Images[SFeedback::Right].push_back(itTextChunk->m_Tags[0].m_TagValue); } @@ -124,7 +124,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback, if (itTextChunk->m_Tags[0].m_TagType == CGUIString::TextChunk::Tag::TAG_ICON) { // Only add the image if the icon exists. - if (g_GUI->IconExists(itTextChunk->m_Tags[0].m_TagValue)) + if (pGUI->IconExists(itTextChunk->m_Tags[0].m_TagValue)) { // We'll need to setup a text-call that will point // to the icon, this is to be able to iterate @@ -135,8 +135,8 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback, // Also add it to the sprites being rendered. SGUIText::SSpriteCall SpriteCall; - // Get Icon from icon database in g_GUI - SGUIIcon icon = g_GUI->GetIcon(itTextChunk->m_Tags[0].m_TagValue); + // Get Icon from icon database in pGUI + SGUIIcon icon = pGUI->GetIcon(itTextChunk->m_Tags[0].m_TagValue); CSize size = icon.m_Size; diff --git a/source/gui/GUItext.h b/source/gui/GUItext.h index 2e12df891d..a4b2354c6a 100644 --- a/source/gui/GUItext.h +++ b/source/gui/GUItext.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -41,6 +41,8 @@ GUI text, handles text stuff #include "CGUISprite.h" #include "ps/CStrIntern.h" +class CGUI; + //-------------------------------------------------------- // Declarations //-------------------------------------------------------- @@ -308,6 +310,7 @@ public: * 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, @@ -318,7 +321,8 @@ public: * to make several GenerateTextCall in different phases, * it avoids duplicates. */ - void GenerateTextCall(SFeedback &Feedback, + void GenerateTextCall(const CGUI *pGUI, + SFeedback &Feedback, CStrIntern DefaultFont, const int &from, const int &to, const bool FirstLine,