Index: source/gui/CButton.h =================================================================== --- source/gui/CButton.h +++ source/gui/CButton.h @@ -68,7 +68,7 @@ float m_BufferZone; i32 m_CellID; CGUIString m_Caption; - CStrW m_Font; + CStrIntern m_Font; CGUISpriteInstance m_Sprite; CGUISpriteInstance m_SpriteOver; CGUISpriteInstance m_SpritePressed; Index: source/gui/CChart.h =================================================================== --- source/gui/CChart.h +++ source/gui/CChart.h @@ -78,7 +78,7 @@ CGUIColor m_AxisColor; float m_AxisWidth; float m_BufferZone; - CStrW m_Font; + CStrIntern m_Font; CStrW m_FormatX; CStrW m_FormatY; CGUIList m_SeriesColor; @@ -98,7 +98,7 @@ // Represents axes as triangles and draws them with DrawTriangleStrip. void DrawAxes(const CShaderProgramPtr& shader) const; - CSize AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone); + CSize AddFormattedValue(const CStrW& format, const float value, const CStrIntern& font, const float buffer_zone); void UpdateBounds(); }; Index: source/gui/CChart.cpp =================================================================== --- source/gui/CChart.cpp +++ source/gui/CChart.cpp @@ -239,7 +239,7 @@ } } -CSize CChart::AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone) +CSize CChart::AddFormattedValue(const CStrW& format, const float value, const CStrIntern& font, const float buffer_zone) { // TODO: we need to catch cases with equal formatted values. CGUIString gui_str; Index: source/gui/CGUIText.h =================================================================== --- source/gui/CGUIText.h +++ source/gui/CGUIText.h @@ -164,7 +164,7 @@ * @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); + CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrIntern& Font, const float Width, const float BufferZone, const IGUIObject* pObject); /** * Draw this CGUIText object Index: source/gui/CGUIText.cpp =================================================================== --- source/gui/CGUIText.cpp +++ source/gui/CGUIText.cpp @@ -60,12 +60,11 @@ m_Indentation = Size.cx + BufferZone * 2; } -CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, const float Width, const float BufferZone, const IGUIObject* pObject) +CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrIntern& Font, 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; Index: source/gui/CInput.h =================================================================== --- source/gui/CInput.h +++ source/gui/CInput.h @@ -21,6 +21,7 @@ #include "gui/IGUIScrollBarOwner.h" #include "gui/CGUISprite.h" #include "lib/external_libraries/libsdl.h" +#include "ps/CStrIntern.h" #include @@ -195,7 +196,7 @@ float m_BufferZone; CStrW m_Caption; i32 m_CellID; - CStrW m_Font; + CStrIntern m_Font; CStrW m_MaskChar; bool m_Mask; i32 m_MaxLength; Index: source/gui/CInput.cpp =================================================================== --- source/gui/CInput.cpp +++ source/gui/CInput.cpp @@ -1154,8 +1154,6 @@ if (m_ScrollBar && m_MultiLine) IGUIScrollBarOwner::Draw(); - CStrIntern font_name(m_Font.ToUTF8()); - wchar_t mask_char = L'*'; if (m_Mask && m_MaskChar.length() > 0) mask_char = m_MaskChar[0]; @@ -1166,7 +1164,7 @@ if (m_ScrollBar && m_MultiLine) scroll = GetScrollBar(0).GetPos(); - CFontMetrics font(font_name); + CFontMetrics font(m_Font); // We'll have to setup clipping manually, since we're doing the rendering manually. CRect cliparea(m_CachedActualSize); @@ -1218,7 +1216,7 @@ CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text); CTextRenderer textRenderer(tech->GetShader()); - textRenderer.Font(font_name); + textRenderer.Font(m_Font); // Set the Z to somewhat more, so we can draw a selected area between the // the control and the text. @@ -1478,8 +1476,6 @@ void CInput::UpdateText(int from, int to_before, int to_after) { - CStrIntern font_name(m_Font.ToUTF8()); - wchar_t mask_char = L'*'; if (m_Mask && m_MaskChar.length() > 0) mask_char = m_MaskChar[0]; @@ -1489,7 +1485,7 @@ m_iBufferPos_Tail = std::min(m_iBufferPos_Tail, static_cast(m_Caption.size())); UpdateBufferPositionSetting(); - if (font_name.empty()) + if (m_Font.empty()) { // Destroy everything stored, there's no font, so there can be no data. m_CharacterPositions.clear(); @@ -1504,7 +1500,7 @@ if (to_before == -1) to = static_cast(m_Caption.length()); - CFontMetrics font(font_name); + CFontMetrics font(m_Font); std::list::iterator current_line; @@ -1843,7 +1839,7 @@ // Now get the height of the font. // TODO: Get the real font - CFontMetrics font(CStrIntern(m_Font.ToUTF8())); + CFontMetrics font(m_Font); float spacing = (float)font.GetLineSpacing(); // Change mouse position relative to text. @@ -1972,7 +1968,7 @@ // Now get the height of the font. // TODO: Get the real font - CFontMetrics font(CStrIntern(m_Font.ToUTF8())); + CFontMetrics font(m_Font); float spacing = (float)font.GetLineSpacing(); //float height = font.GetHeight(); Index: source/gui/CList.h =================================================================== --- source/gui/CList.h +++ source/gui/CList.h @@ -114,7 +114,7 @@ // Settings float m_BufferZone; - CStrW m_Font; + CStrIntern m_Font; bool m_ScrollBar; CStr m_ScrollBarStyle; CStrW m_SoundDisabled; Index: source/gui/CText.h =================================================================== --- source/gui/CText.h +++ source/gui/CText.h @@ -71,7 +71,7 @@ CGUIString m_Caption; i32 m_CellID; bool m_Clip; - CStrW m_Font; + CStrIntern m_Font; bool m_ScrollBar; CStr m_ScrollBarStyle; bool m_ScrollBottom; Index: source/gui/CTooltip.h =================================================================== --- source/gui/CTooltip.h +++ source/gui/CTooltip.h @@ -46,7 +46,7 @@ // Settings float m_BufferZone; CGUIString m_Caption; - CStrW m_Font; + CStrIntern m_Font; CGUISpriteInstance m_Sprite; i32 m_Delay; CGUIColor m_TextColor; Index: source/gui/GUIStringConversions.cpp =================================================================== --- source/gui/GUIStringConversions.cpp +++ source/gui/GUIStringConversions.cpp @@ -220,6 +220,13 @@ } template <> +bool CGUI::ParseString(const CGUI* UNUSED(pGUI), const CStrW& Value, CStrIntern& Output) +{ + Output = CStrIntern(Value.ToUTF8()); + return true; +} + +template <> bool CGUI::ParseString(const CGUI* UNUSED(pGUI), const CStrW& Value, CStrW& Output) { Output = Value; Index: source/gui/GUItypes.h =================================================================== --- source/gui/GUItypes.h +++ source/gui/GUItypes.h @@ -46,5 +46,6 @@ TYPE(CGUISpriteInstance) TYPE(CGUIString) TYPE(CStr) +TYPE(CStrIntern) TYPE(CStrW) #endif Index: source/gui/IGUITextOwner.h =================================================================== --- source/gui/IGUITextOwner.h +++ source/gui/IGUITextOwner.h @@ -32,6 +32,7 @@ #include "gui/IGUIObject.h" #include "gui/scripting/JSInterface_IGUITextOwner.h" +#include "ps/CStrIntern.h" #include @@ -58,7 +59,7 @@ /** * Adds a text generated by the given arguments. */ - CGUIText& AddText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone); + CGUIText& AddText(const CGUIString& Text, const CStrIntern& Font, const float& Width, const float& BufferZone); /** * Subscribe the custom JS methods. Index: source/gui/IGUITextOwner.cpp =================================================================== --- source/gui/IGUITextOwner.cpp +++ source/gui/IGUITextOwner.cpp @@ -48,7 +48,7 @@ return m_GeneratedTexts.back(); } -CGUIText& IGUITextOwner::AddText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone) +CGUIText& IGUITextOwner::AddText(const CGUIString& Text, const CStrIntern& Font, const float& Width, const float& BufferZone) { // Avoids a move constructor m_GeneratedTexts.emplace_back(m_pGUI, Text, Font, Width, BufferZone, this); Index: source/scriptinterface/ScriptConversions.cpp =================================================================== --- source/scriptinterface/ScriptConversions.cpp +++ source/scriptinterface/ScriptConversions.cpp @@ -21,8 +21,9 @@ #include "graphics/Entity.h" #include "maths/Vector2D.h" -#include "ps/utf16string.h" #include "ps/CStr.h" +#include "ps/CStrIntern.h" +#include "ps/utf16string.h" #define FAIL(msg) STMT(JS_ReportError(cx, msg); return false) @@ -181,6 +182,16 @@ return ScriptInterface::FromJSVal(cx, v, static_cast(out)); } +template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CStrIntern& out) +{ + CStrW value; + if (!FromJSVal(cx, v, value)) + return false; + + out = CStrIntern(value.ToUTF8()); + return true; +} + template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, Entity& out) { JSAutoRequest rq(cx); @@ -331,6 +342,11 @@ ToJSVal(cx, ret, static_cast(val)); } +template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CStrIntern& val) +{ + ToJSVal(cx, ret, val.string()); +} + //////////////////////////////////////////////////////////////// // Compound types // Instantiate various vector types: