diff --git a/source/gui/CButton.cpp b/source/gui/CButton.cpp index 76b5fb0d57..50137be283 100644 --- a/source/gui/CButton.cpp +++ b/source/gui/CButton.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,6 +19,7 @@ #include "CButton.h" +#include "gui/CGUIColor.h" #include "lib/ogl.h" CButton::CButton() @@ -38,10 +39,10 @@ CButton::CButton() AddSetting(GUIST_CGUISpriteInstance, "sprite_disabled"); AddSetting(GUIST_EAlign, "text_align"); AddSetting(GUIST_EVAlign, "text_valign"); - AddSetting(GUIST_CColor, "textcolor"); - AddSetting(GUIST_CColor, "textcolor_over"); - AddSetting(GUIST_CColor, "textcolor_pressed"); - AddSetting(GUIST_CColor, "textcolor_disabled"); + AddSetting(GUIST_CGUIColor, "textcolor"); + AddSetting(GUIST_CGUIColor, "textcolor_over"); + AddSetting(GUIST_CGUIColor, "textcolor_pressed"); + AddSetting(GUIST_CGUIColor, "textcolor_disabled"); AddSetting(GUIST_CStrW, "tooltip"); AddSetting(GUIST_CStr, "tooltip_style"); @@ -115,6 +116,6 @@ void CButton::Draw() *sprite_disabled, cell_id); - CColor color = ChooseColor(); + CGUIColor color = ChooseColor(); DrawText(0, color, m_TextPos, bz+0.1f); } diff --git a/source/gui/CChart.cpp b/source/gui/CChart.cpp index 273e18fb53..7359a823d6 100644 --- a/source/gui/CChart.cpp +++ b/source/gui/CChart.cpp @@ -16,8 +16,10 @@ */ #include "precompiled.h" + #include "CChart.h" +#include "gui/CGUIColor.h" #include "graphics/ShaderManager.h" #include "i18n/L10n.h" #include "lib/ogl.h" @@ -29,7 +31,7 @@ CChart::CChart() { - AddSetting(GUIST_CColor, "axis_color"); + AddSetting(GUIST_CGUIColor, "axis_color"); AddSetting(GUIST_float, "axis_width"); AddSetting(GUIST_float, "buffer_zone"); AddSetting(GUIST_CStrW, "font"); @@ -65,7 +67,7 @@ void CChart::HandleMessage(SGUIMessage& Message) } } -void CChart::DrawLine(const CShaderProgramPtr& shader, const CColor& color, const std::vector& vertices) const +void CChart::DrawLine(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector& vertices) const { shader->Uniform(str_color, color); shader->VertexPointer(3, GL_FLOAT, 0, &vertices[0]); @@ -79,7 +81,7 @@ void CChart::DrawLine(const CShaderProgramPtr& shader, const CColor& color, cons glDisable(GL_LINE_SMOOTH); } -void CChart::DrawTriangleStrip(const CShaderProgramPtr& shader, const CColor& color, const std::vector& vertices) const +void CChart::DrawTriangleStrip(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector& vertices) const { shader->Uniform(str_color, color); shader->VertexPointer(3, GL_FLOAT, 0, &vertices[0]); @@ -103,8 +105,8 @@ void CChart::DrawAxes(const CShaderProgramPtr& shader) const ADD(m_CachedActualSize.left, m_CachedActualSize.top); ADD(rect.left, rect.top - m_AxisWidth); #undef ADD - CColor axis_color(0.5f, 0.5f, 0.5f, 1.f); - GUI::GetSetting(this, "axis_color", axis_color); + CGUIColor axis_color(0.5f, 0.5f, 0.5f, 1.f); + GUI::GetSetting(this, "axis_color", axis_color); DrawTriangleStrip(shader, axis_color, vertices); } @@ -169,7 +171,7 @@ void CChart::Draw() glDepthMask(1); for (size_t i = 0; i < m_TextPositions.size(); ++i) - DrawText(i, CColor(1.f, 1.f, 1.f, 1.f), m_TextPositions[i], bz + 0.5f); + DrawText(i, CGUIColor(1.f, 1.f, 1.f, 1.f), m_TextPositions[i], bz + 0.5f); } CRect CChart::GetChartRect() const diff --git a/source/gui/CChart.h b/source/gui/CChart.h index 234eca2b1c..d9f3ef6bc8 100644 --- a/source/gui/CChart.h +++ b/source/gui/CChart.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -18,16 +18,16 @@ #ifndef INCLUDED_CCHART #define INCLUDED_CCHART -#include "GUI.h" -#include "IGUITextOwner.h" -#include "graphics/Color.h" +#include "gui/GUI.h" +#include "gui/IGUITextOwner.h" #include "maths/Vector2D.h" + #include struct CChartData { - CColor m_Color; + CGUIColor m_Color; std::vector m_Points; }; @@ -77,11 +77,11 @@ private: /** * Helper functions */ - void DrawLine(const CShaderProgramPtr& shader, const CColor& color, const std::vector& vertices) const; + void DrawLine(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector& vertices) const; // Draws the triangle sequence so that the each next triangle has a common edge with the previous one. // If we need to draw n triangles, we need only n + 2 points. - void DrawTriangleStrip(const CShaderProgramPtr& shader, const CColor& color, const std::vector& vertices) const; + void DrawTriangleStrip(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector& vertices) const; // Represents axes as triangles and draws them with DrawTriangleStrip. void DrawAxes(const CShaderProgramPtr& shader) const; diff --git a/source/gui/CCheckBox.cpp b/source/gui/CCheckBox.cpp index d745e0280a..143af3ca19 100644 --- a/source/gui/CCheckBox.cpp +++ b/source/gui/CCheckBox.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,6 +19,7 @@ #include "CCheckBox.h" +#include "gui/CGUIColor.h" #include "graphics/FontMetrics.h" #include "ps/CLogger.h" #include "ps/CStrIntern.h" @@ -48,10 +49,10 @@ CCheckBox::CCheckBox() AddSetting(GUIST_CGUISpriteInstance, "sprite2_pressed"); AddSetting(GUIST_CGUISpriteInstance, "sprite2_disabled"); AddSetting(GUIST_float, "square_side"); - AddSetting(GUIST_CColor, "textcolor"); - AddSetting(GUIST_CColor, "textcolor_over"); - AddSetting(GUIST_CColor, "textcolor_pressed"); - AddSetting(GUIST_CColor, "textcolor_disabled"); + AddSetting(GUIST_CGUIColor, "textcolor"); + AddSetting(GUIST_CGUIColor, "textcolor_over"); + AddSetting(GUIST_CGUIColor, "textcolor_pressed"); + AddSetting(GUIST_CGUIColor, "textcolor_disabled"); AddSetting(GUIST_CStrW, "tooltip"); AddSetting(GUIST_CStr, "tooltip_style"); diff --git a/source/gui/CDropDown.cpp b/source/gui/CDropDown.cpp index e233160e5a..2027291bd3 100644 --- a/source/gui/CDropDown.cpp +++ b/source/gui/CDropDown.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,6 +19,7 @@ #include "CDropDown.h" +#include "gui/CGUIColor.h" #include "lib/external_libraries/libsdl.h" #include "lib/ogl.h" #include "lib/timer.h" @@ -48,10 +49,10 @@ CDropDown::CDropDown() AddSetting(GUIST_EVAlign, "text_valign"); // Add these in CList! And implement TODO - //AddSetting(GUIST_CColor, "textcolor_over"); - //AddSetting(GUIST_CColor, "textcolor_pressed"); - AddSetting(GUIST_CColor, "textcolor_selected"); - AddSetting(GUIST_CColor, "textcolor_disabled"); + //AddSetting(GUIST_CGUIColor, "textcolor_over"); + //AddSetting(GUIST_CGUIColor, "textcolor_pressed"); + AddSetting(GUIST_CGUIColor, "textcolor_selected"); + AddSetting(GUIST_CGUIColor, "textcolor_disabled"); // Scrollbar is forced to be true. GUI::SetSetting(this, "scrollbar", true); @@ -486,7 +487,7 @@ void CDropDown::Draw() CGUISpriteInstance* sprite2; CGUISpriteInstance* sprite2_second; int cell_id, selected = 0; - CColor color; + CGUIColor color; bool enabled; GUI::GetSetting(this, "enabled", enabled); @@ -494,7 +495,7 @@ void CDropDown::Draw() GUI::GetSettingPointer(this, "sprite2", sprite2); GUI::GetSetting(this, "cell_id", cell_id); GUI::GetSetting(this, "selected", selected); - GUI::GetSetting(this, enabled ? "textcolor_selected" : "textcolor_disabled", color); + GUI::GetSetting(this, enabled ? "textcolor_selected" : "textcolor_disabled", color); GUI::GetSettingPointer(this, enabled ? "sprite" : "sprite_disabled", sprite); GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 18cbc2590f..0ac29bfb5f 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -827,7 +827,7 @@ SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const return Text; } -void CGUI::DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping) +void CGUI::DrawText(SGUIText& Text, const CGUIColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping) { CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text); @@ -854,7 +854,7 @@ void CGUI::DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, if (tc.m_pSpriteCall) continue; - CColor color = tc.m_UseCustomColor ? tc.m_Color : DefaultColor; + CGUIColor color = tc.m_UseCustomColor ? tc.m_Color : DefaultColor; textRenderer.Color(color); textRenderer.Font(tc.m_Font); @@ -872,9 +872,9 @@ void CGUI::DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, tech->EndPass(); } -bool CGUI::GetPreDefinedColor(const CStr& name, CColor& Output) const +bool CGUI::GetPreDefinedColor(const CStr& name, CGUIColor& Output) const { - std::map::const_iterator cit = m_PreDefinedColors.find(name); + std::map::const_iterator cit = m_PreDefinedColors.find(name); if (cit == m_PreDefinedColors.end()) return false; @@ -1510,16 +1510,16 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite } else if (attr_name == "backcolor") { - CColor color; - if (!GUI::ParseString(attr_value, color)) + CGUIColor color; + if (!GUI::ParseString(attr_value, color)) LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); else Image->m_BackColor = color; } else if (attr_name == "bordercolor") { - CColor color; - if (!GUI::ParseString(attr_value, color)) + CGUIColor color; + if (!GUI::ParseString(attr_value, color)) LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); else Image->m_BorderColor = color; @@ -1566,7 +1566,7 @@ void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImag if (attr_name == "add_color") { - CColor color; + CGUIColor color; if (!GUI::ParseColor(attr_value, color, 0)) LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); else effects.m_AddColor = color; @@ -1742,7 +1742,7 @@ void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile) { XMBAttributeList attributes = Element.GetAttributes(); - CColor color; + CGUIColor color; CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name")); // Try parsing value diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index c83ac5ebde..1e25841565 100644 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -49,7 +49,7 @@ class JSObject; // The GUI stores a JSObject*, so needs to know that JSObject ex class IGUIObject; class CGUISpriteInstance; struct SGUIText; -struct CColor; +struct CGUIColor; struct SGUIText; struct SGUIIcon; class CGUIString; @@ -131,7 +131,7 @@ public: * @param z z value. * @param clipping */ - void DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping); + void DrawText(SGUIText& Text, const CGUIColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping); /** * Clean up, call this to clean up all memory allocated @@ -244,7 +244,7 @@ public: * Get pre-defined color (if it exists) * Returns false if it fails. */ - bool GetPreDefinedColor(const CStr& name, CColor& Output) const; + bool GetPreDefinedColor(const CStr& name, CGUIColor& Output) const; shared_ptr GetScriptInterface() { return m_ScriptInterface; }; JS::Value GetGlobalObject() { return m_ScriptInterface->GetGlobalObject(); }; @@ -573,7 +573,7 @@ private: * color. Of course the colors have to be declared in XML, there are * no hard-coded values. */ - std::map m_PreDefinedColors; + std::map m_PreDefinedColors; //@} //-------------------------------------------------------- diff --git a/source/gui/CGUIColor.h b/source/gui/CGUIColor.h new file mode 100644 index 0000000000..317c16850d --- /dev/null +++ b/source/gui/CGUIColor.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2019 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_GUICOLOR +#define INCLUDED_GUICOLOR + +#include "graphics/Color.h" +#include "gui/GUIManager.h" + +/** + * Same as the CColor class, but this one can also parse colors predefined in the GUI page (such as "yellow"). + */ +struct CGUIColor : public CColor +{ + using CColor::CColor; + + bool ParseString(const CStr& value, int defaultAlpha = 255) + { + return g_GUI->GetPreDefinedColor(value, *this) || CColor::ParseString(value, defaultAlpha); + } +}; +#endif // INCLUDED_GUICOLOR diff --git a/source/gui/CGUISprite.h b/source/gui/CGUISprite.h index af76776411..271fe507ea 100644 --- a/source/gui/CGUISprite.h +++ b/source/gui/CGUISprite.h @@ -44,8 +44,8 @@ A GUI Sprite struct SGUIImageEffects { SGUIImageEffects() : m_Greyscale(false) {} - CColor m_AddColor; - CColor m_SolidColor; + CGUIColor m_AddColor; + CGUIColor m_SolidColor; bool m_Greyscale; }; @@ -109,8 +109,8 @@ public: SGUIImageEffects* m_Effects; // Color - CColor m_BackColor; - CColor m_BorderColor; + CGUIColor m_BackColor; + CGUIColor m_BorderColor; // 0 or 1 pixel border is the only option bool m_Border; diff --git a/source/gui/CInput.cpp b/source/gui/CInput.cpp index 7528860974..5c34878079 100644 --- a/source/gui/CInput.cpp +++ b/source/gui/CInput.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,9 +19,8 @@ #include "CInput.h" -#include "CGUIScrollBarVertical.h" -#include "GUI.h" - +#include "gui/CGUIScrollBarVertical.h" +#include "gui/GUI.h" #include "graphics/FontMetrics.h" #include "graphics/ShaderManager.h" #include "graphics/TextRenderer.h" @@ -59,8 +58,8 @@ CInput::CInput() AddSetting(GUIST_CStr, "scrollbar_style"); AddSetting(GUIST_CGUISpriteInstance, "sprite"); AddSetting(GUIST_CGUISpriteInstance, "sprite_selectarea"); - AddSetting(GUIST_CColor, "textcolor"); - AddSetting(GUIST_CColor, "textcolor_selected"); + AddSetting(GUIST_CGUIColor, "textcolor"); + AddSetting(GUIST_CGUIColor, "textcolor_selected"); AddSetting(GUIST_CStrW, "tooltip"); AddSetting(GUIST_CStr, "tooltip_style"); @@ -1175,10 +1174,10 @@ void CInput::Draw() return; CStrW font_name_w; - CColor color, color_selected; + CGUIColor color, color_selected; GUI::GetSetting(this, "font", font_name_w); - GUI::GetSetting(this, "textcolor", color); - GUI::GetSetting(this, "textcolor_selected", color_selected); + GUI::GetSetting(this, "textcolor", color); + GUI::GetSetting(this, "textcolor_selected", color_selected); CStrIntern font_name(font_name_w.ToUTF8()); // Get pointer of caption, it might be very large, and we don't diff --git a/source/gui/CList.cpp b/source/gui/CList.cpp index 33730aca5b..d859999393 100644 --- a/source/gui/CList.cpp +++ b/source/gui/CList.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,8 +19,8 @@ #include "CList.h" -#include "CGUIScrollBarVertical.h" - +#include "gui/CGUIColor.h" +#include "gui/CGUIScrollBarVertical.h" #include "lib/external_libraries/libsdl.h" #include "ps/CLogger.h" #include "ps/Profile.h" @@ -42,8 +42,8 @@ CList::CList() AddSetting(GUIST_CGUISpriteInstance, "sprite_selectarea"); AddSetting(GUIST_int, "cell_id"); AddSetting(GUIST_EAlign, "text_align"); - AddSetting(GUIST_CColor, "textcolor"); - AddSetting(GUIST_CColor, "textcolor_selected"); + AddSetting(GUIST_CGUIColor, "textcolor"); + AddSetting(GUIST_CGUIColor, "textcolor_selected"); AddSetting(GUIST_int, "selected"); // Index selected. -1 is none. AddSetting(GUIST_bool, "auto_scroll"); AddSetting(GUIST_int, "hovered"); @@ -384,8 +384,8 @@ void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spri } } - CColor color; - GUI::GetSetting(this, _textcolor, color); + CGUIColor color; + GUI::GetSetting(this, _textcolor, color); for (size_t i = 0; i < pList->m_Items.size(); ++i) { diff --git a/source/gui/COList.cpp b/source/gui/COList.cpp index 2a086f7721..8f2ef117ae 100644 --- a/source/gui/COList.cpp +++ b/source/gui/COList.cpp @@ -19,6 +19,7 @@ #include "COList.h" +#include "gui/CGUIColor.h" #include "i18n/L10n.h" #include "ps/CLogger.h" #include "soundmanager/ISoundManager.h" @@ -231,8 +232,8 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile if (attr_name == "color") { - CColor color; - if (!GUI::ParseString(attr_value.FromUTF8(), color)) + CGUIColor color; + if (!GUI::ParseString(attr_value.FromUTF8(), color)) LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); else column.m_TextColor = color; @@ -393,8 +394,8 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr int selectedColumnOrder; GUI::GetSetting(this, "selected_column_order", selectedColumnOrder); - CColor color; - GUI::GetSetting(this, _textcolor, color); + CGUIColor color; + GUI::GetSetting(this, _textcolor, color); float xpos = 0; for (size_t col = 0; col < m_Columns.size(); ++col) diff --git a/source/gui/COList.h b/source/gui/COList.h index eba161c508..14e52a6521 100644 --- a/source/gui/COList.h +++ b/source/gui/COList.h @@ -25,7 +25,7 @@ */ struct COListColumn { - CColor m_TextColor; + CGUIColor m_TextColor; CStr m_Id; float m_Width; CStrW m_Heading; diff --git a/source/gui/CText.cpp b/source/gui/CText.cpp index 5a2d6be813..5777217fe3 100644 --- a/source/gui/CText.cpp +++ b/source/gui/CText.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,9 +19,8 @@ #include "CText.h" -#include "CGUIScrollBarVertical.h" -#include "GUI.h" - +#include "gui/CGUIScrollBarVertical.h" +#include "gui/GUI.h" #include "lib/ogl.h" CText::CText() @@ -38,8 +37,8 @@ CText::CText() AddSetting(GUIST_CGUISpriteInstance, "sprite"); AddSetting(GUIST_EAlign, "text_align"); AddSetting(GUIST_EVAlign, "text_valign"); - AddSetting(GUIST_CColor, "textcolor"); - AddSetting(GUIST_CColor, "textcolor_disabled"); + AddSetting(GUIST_CGUIColor, "textcolor"); + AddSetting(GUIST_CGUIColor, "textcolor_disabled"); AddSetting(GUIST_CStrW, "tooltip"); AddSetting(GUIST_CStr, "tooltip_style"); @@ -237,8 +236,8 @@ void CText::Draw() bool enabled; GUI::GetSetting(this, "enabled", enabled); - CColor color; - GUI::GetSetting(this, enabled ? "textcolor" : "textcolor_disabled", color); + CGUIColor color; + GUI::GetSetting(this, enabled ? "textcolor" : "textcolor_disabled", color); if (scrollbar) DrawText(0, color, m_CachedActualSize.TopLeft() - CPos(0.f, scroll), bz+0.1f, cliparea); diff --git a/source/gui/CTooltip.cpp b/source/gui/CTooltip.cpp index e43d33424f..e9eba5868c 100644 --- a/source/gui/CTooltip.cpp +++ b/source/gui/CTooltip.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -30,7 +30,7 @@ CTooltip::CTooltip() AddSetting(GUIST_CStrW, "font"); AddSetting(GUIST_CGUISpriteInstance, "sprite"); AddSetting(GUIST_int, "delay"); - AddSetting(GUIST_CColor, "textcolor"); + AddSetting(GUIST_CGUIColor, "textcolor"); AddSetting(GUIST_float, "maxwidth"); AddSetting(GUIST_CPos, "offset"); AddSetting(GUIST_EVAlign, "anchor"); @@ -167,8 +167,8 @@ void CTooltip::Draw() GetGUI()->DrawSprite(*sprite, 0, z, m_CachedActualSize); - CColor color; - GUI::GetSetting(this, "textcolor", color); + CGUIColor color; + GUI::GetSetting(this, "textcolor", color); DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f); } diff --git a/source/gui/GUIManager.cpp b/source/gui/GUIManager.cpp index 49852f0bdc..dddb8f370a 100644 --- a/source/gui/GUIManager.cpp +++ b/source/gui/GUIManager.cpp @@ -19,8 +19,7 @@ #include "GUIManager.h" -#include "CGUI.h" - +#include "gui/CGUI.h" #include "lib/timer.h" #include "ps/Filesystem.h" #include "ps/CLogger.h" @@ -347,7 +346,7 @@ InReaction CGUIManager::HandleEvent(const SDL_Event_* ev) } -bool CGUIManager::GetPreDefinedColor(const CStr& name, CColor& output) const +bool CGUIManager::GetPreDefinedColor(const CStr& name, CGUIColor& output) const { return top()->GetPreDefinedColor(name, output); } diff --git a/source/gui/GUIManager.h b/source/gui/GUIManager.h index 2ac4fcf79b..7c01a58a85 100644 --- a/source/gui/GUIManager.h +++ b/source/gui/GUIManager.h @@ -32,7 +32,7 @@ class CGUI; class JSObject; class IGUIObject; -struct CColor; +struct CGUIColor; struct SGUIIcon; /** @@ -105,7 +105,7 @@ public: /** * See CGUI::GetPreDefinedColor; applies to the currently active page. */ - bool GetPreDefinedColor(const CStr& name, CColor& output) const; + bool GetPreDefinedColor(const CStr& name, CGUIColor& output) const; /** * See CGUI::SendEventToAll; applies to the currently active page. diff --git a/source/gui/GUIRenderer.cpp b/source/gui/GUIRenderer.cpp index 4a58b95322..46a66f11c6 100644 --- a/source/gui/GUIRenderer.cpp +++ b/source/gui/GUIRenderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -21,6 +21,7 @@ #include "graphics/ShaderManager.h" #include "graphics/TextureManager.h" +#include "gui/CGUIColor.h" #include "gui/GUIutil.h" #include "i18n/L10n.h" #include "lib/ogl.h" @@ -139,10 +140,10 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, if (SpriteName.Find("color:") != -1) { CStrW value = wstring_from_utf8(SpriteName.AfterLast("color:").BeforeFirst(":")); - CColor color; + CGUIColor color; // Check color is valid - if (!GUI::ParseString(value, color)) + if (!GUI::ParseString(value, color)) { LOGERROR("GUI: Error parsing sprite 'color' (\"%s\")", utf8_from_wstring(value)); return; @@ -230,7 +231,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, } Call.m_BackColor = (*cit)->m_BackColor; - Call.m_BorderColor = (*cit)->m_Border ? (*cit)->m_BorderColor : CColor(); + Call.m_BorderColor = (*cit)->m_Border ? (*cit)->m_BorderColor : CGUIColor(); Call.m_DeltaZ = (*cit)->m_DeltaZ; if (!Call.m_HasTexture) @@ -239,7 +240,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, } else if ((*cit)->m_Effects) { - if ((*cit)->m_Effects->m_AddColor != CColor()) + if ((*cit)->m_Effects->m_AddColor != CGUIColor()) { Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_add); Call.m_ShaderColorParameter = (*cit)->m_Effects->m_AddColor; @@ -252,7 +253,7 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, { Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_grayscale); } - else if ((*cit)->m_Effects->m_SolidColor != CColor()) + else if ((*cit)->m_Effects->m_SolidColor != CGUIColor()) { Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid_mask); Call.m_ShaderColorParameter = (*cit)->m_Effects->m_SolidColor; @@ -437,7 +438,7 @@ void GUIRenderer::Draw(DrawCalls& Calls, float Z) shader->VertexPointer(3, GL_FLOAT, 3*sizeof(float), &data[0]); glDrawArrays(GL_TRIANGLES, 0, 6); - if (cit->m_BorderColor != CColor()) + if (cit->m_BorderColor != CGUIColor()) { shader->Uniform(str_color, cit->m_BorderColor); diff --git a/source/gui/GUIRenderer.h b/source/gui/GUIRenderer.h index e5dce45467..c9fc3f5631 100644 --- a/source/gui/GUIRenderer.h +++ b/source/gui/GUIRenderer.h @@ -18,9 +18,9 @@ #ifndef INCLUDED_GUIRENDERER #define INCLUDED_GUIRENDERER -#include "graphics/Color.h" #include "graphics/ShaderTechnique.h" #include "graphics/Texture.h" +#include "gui/CGUIColor.h" #include "lib/res/handle.h" #include "ps/CStr.h" #include "ps/Shapes.h" @@ -61,8 +61,8 @@ namespace GUIRenderer CRect m_Vertices; float m_DeltaZ; - CColor m_BorderColor; // == CColor() for no border - CColor m_BackColor; + CGUIColor m_BorderColor; // == CGUIColor() for no border + CGUIColor m_BackColor; }; class DrawCalls : public std::vector diff --git a/source/gui/GUIbase.h b/source/gui/GUIbase.h index 643467b249..be94ed5890 100644 --- a/source/gui/GUIbase.h +++ b/source/gui/GUIbase.h @@ -35,7 +35,7 @@ GUI Core, stuff that the whole GUI uses #include #include -#include "graphics/Color.h" +#include "gui/CGUIColor.h" #include "ps/CStr.h" #include "ps/Errors.h" // I would like to just forward declare CSize, but it doesn't diff --git a/source/gui/GUItext.cpp b/source/gui/GUItext.cpp index 4f89b9d861..eea5688ba8 100644 --- a/source/gui/GUItext.cpp +++ b/source/gui/GUItext.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,7 +19,7 @@ #include -#include "GUI.h" +#include "gui/GUI.h" #include "lib/utf8.h" #include "graphics/FontMetrics.h" #include "ps/CLogger.h" @@ -190,7 +190,7 @@ void CGUIString::GenerateTextCall(const CGUI* pGUI, SFeedback& Feedback, CStrInt case TextChunk::Tag::TAG_COLOR: TextCall.m_UseCustomColor = true; - if (!GUI::ParseString(tag.m_TagValue, TextCall.m_Color) && pObject) + if (!GUI::ParseString(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: diff --git a/source/gui/GUItext.h b/source/gui/GUItext.h index 784d459317..214e3b5ce7 100644 --- a/source/gui/GUItext.h +++ b/source/gui/GUItext.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -33,6 +33,7 @@ #include #include "CGUISprite.h" +#include "gui/CGUIColor.h" #include "ps/CStrIntern.h" class CGUI; @@ -118,7 +119,7 @@ struct SGUIText /** * Color setup */ - CColor m_Color; + CGUIColor m_Color; /** * Font name diff --git a/source/gui/GUItypes.h b/source/gui/GUItypes.h index 5eb5322e8f..a5d4f71e53 100644 --- a/source/gui/GUItypes.h +++ b/source/gui/GUItypes.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -29,7 +29,7 @@ TYPE(bool) TYPE(int) TYPE(uint) TYPE(float) -TYPE(CColor) +TYPE(CGUIColor) TYPE(CClientArea) TYPE(CGUIString) #ifndef GUITYPE_IGNORE_CGUISpriteInstance diff --git a/source/gui/GUIutil.cpp b/source/gui/GUIutil.cpp index 703298d0a7..437fa034de 100644 --- a/source/gui/GUIutil.cpp +++ b/source/gui/GUIutil.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -17,9 +17,10 @@ #include "precompiled.h" -#include "GUI.h" -#include "GUIManager.h" +#include "GUIutil.h" +#include "gui/GUI.h" +#include "gui/GUIManager.h" #include "maths/Matrix3D.h" #include "ps/CLogger.h" #include "ps/GameSetup/Config.h" @@ -102,26 +103,14 @@ bool __ParseString(const CStrW& Value, CClientArea& Output) } template <> -bool GUI::ParseColor(const CStrW& Value, CColor& Output, int DefaultAlpha) +bool GUI::ParseColor(const CStrW& Value, CGUIColor& Output, int DefaultAlpha) { - // First, check our database in g_GUI for pre-defined colors - // If we find anything, we'll ignore DefaultAlpha - // If it fails, it won't do anything with Output - if (g_GUI->GetPreDefinedColor(Value.ToUTF8(), Output)) - return true; - return Output.ParseString(Value.ToUTF8(), DefaultAlpha); } - template <> -bool __ParseString(const CStrW& Value, CColor& Output) +bool __ParseString(const CStrW& Value, CGUIColor& Output) { - // First, check our database in g_GUI for pre-defined colors - // If it fails, it won't do anything with Output - if (g_GUI->GetPreDefinedColor(Value.ToUTF8(), Output)) - return true; - return Output.ParseString(Value.ToUTF8()); } diff --git a/source/gui/GUIutil.h b/source/gui/GUIutil.h index ef3910eee9..13f5df6343 100644 --- a/source/gui/GUIutil.h +++ b/source/gui/GUIutil.h @@ -32,10 +32,10 @@ GUI util #ifndef INCLUDED_GUIUTIL #define INCLUDED_GUIUTIL -#include "CGUI.h" -#include "CGUISprite.h" -#include "GUIbase.h" -#include "IGUIObject.h" +#include "gui/CGUI.h" +#include "gui/CGUISprite.h" +#include "gui/GUIbase.h" +#include "gui/IGUIObject.h" class CClientArea; class CGUIString; @@ -190,10 +190,10 @@ public: * @return Resulting color * @see FallBackSprite */ - static CColor FallBackColor(const CColor& prim, const CColor& sec) + static CGUIColor FallBackColor(const CGUIColor& prim, const CGUIColor& sec) { - // CColor() == null. - return ((prim!=CColor())?(prim):(sec)); + // CGUIColor() == null. + return ((prim!=CGUIColor())?(prim):(sec)); } /** @@ -214,7 +214,7 @@ public: return __ParseString(Value, tOutput); } - static bool ParseColor(const CStrW& Value, CColor& tOutput, int DefaultAlpha); + static bool ParseColor(const CStrW& Value, CGUIColor& tOutput, int DefaultAlpha); private: diff --git a/source/gui/IGUIButtonBehavior.cpp b/source/gui/IGUIButtonBehavior.cpp index 7f658c8b8f..376781da27 100644 --- a/source/gui/IGUIButtonBehavior.cpp +++ b/source/gui/IGUIButtonBehavior.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -131,31 +131,31 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message) } } -CColor IGUIButtonBehavior::ChooseColor() +CGUIColor IGUIButtonBehavior::ChooseColor() { - CColor color, color2; + CGUIColor color, color2; // Yes, the object must possess these settings. They are standard - GUI::GetSetting(this, "textcolor", color); + GUI::GetSetting(this, "textcolor", color); bool enabled; GUI::GetSetting(this, "enabled", enabled); if (!enabled) { - GUI::GetSetting(this, "textcolor_disabled", color2); + GUI::GetSetting(this, "textcolor_disabled", color2); return GUI<>::FallBackColor(color2, color); } else if (m_MouseHovering) { if (m_Pressed) { - GUI::GetSetting(this, "textcolor_pressed", color2); + GUI::GetSetting(this, "textcolor_pressed", color2); return GUI<>::FallBackColor(color2, color); } else { - GUI::GetSetting(this, "textcolor_over", color2); + GUI::GetSetting(this, "textcolor_over", color2); return GUI<>::FallBackColor(color2, color); } } diff --git a/source/gui/IGUIButtonBehavior.h b/source/gui/IGUIButtonBehavior.h index b0502177d5..746d5337b1 100644 --- a/source/gui/IGUIButtonBehavior.h +++ b/source/gui/IGUIButtonBehavior.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -35,7 +35,7 @@ GUI Object Base - Button Behavior #ifndef INCLUDED_IGUIBUTTONBEHAVIOR #define INCLUDED_IGUIBUTTONBEHAVIOR -#include "GUI.h" +#include "gui/GUI.h" class CGUISpriteInstance; @@ -82,7 +82,7 @@ public: * textcolor_pressed -- pressed * textcolor_over -- hovered */ - CColor ChooseColor(); + CGUIColor ChooseColor(); protected: diff --git a/source/gui/IGUITextOwner.cpp b/source/gui/IGUITextOwner.cpp index 7f22d15387..90f64aa808 100644 --- a/source/gui/IGUITextOwner.cpp +++ b/source/gui/IGUITextOwner.cpp @@ -17,7 +17,7 @@ #include "precompiled.h" -#include "GUI.h" +#include "gui/GUI.h" IGUITextOwner::IGUITextOwner() : m_GeneratedTextsValid(false) { @@ -68,7 +68,7 @@ void IGUITextOwner::UpdateCachedSize() m_GeneratedTextsValid = false; } -void IGUITextOwner::DrawText(size_t index, const CColor& color, const CPos& pos, float z, const CRect& clipping) +void IGUITextOwner::DrawText(size_t index, const CGUIColor& color, const CPos& pos, float z, const CRect& clipping) { if (!m_GeneratedTextsValid) { diff --git a/source/gui/IGUITextOwner.h b/source/gui/IGUITextOwner.h index 2766a80fc9..d48787b9f2 100644 --- a/source/gui/IGUITextOwner.h +++ b/source/gui/IGUITextOwner.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -73,7 +73,7 @@ public: * @param clipping Clipping rectangle, don't even add a parameter * to get no clipping. */ - virtual void DrawText(size_t index, const CColor& color, const CPos& pos, float z, const CRect& clipping = CRect()); + virtual void DrawText(size_t index, const CGUIColor& color, const CPos& pos, float z, const CRect& clipping = CRect()); /** * Test if mouse position is over an icon diff --git a/source/gui/MiniMap.cpp b/source/gui/MiniMap.cpp index da81ad0c06..0683807917 100644 --- a/source/gui/MiniMap.cpp +++ b/source/gui/MiniMap.cpp @@ -67,7 +67,6 @@ CMiniMap::CMiniMap() : m_EntitiesDrawn(0), m_IndexArray(GL_STATIC_DRAW), m_VertexArray(GL_DYNAMIC_DRAW), m_NextBlinkTime(0.0), m_PingDuration(25.0), m_BlinkState(false), m_WaterHeight(0.0) { - AddSetting(GUIST_CColor, "fov_wedge_color"); AddSetting(GUIST_CStrW, "tooltip"); AddSetting(GUIST_CStr, "tooltip_style"); m_Clicking = false; diff --git a/source/gui/scripting/GuiScriptConversions.cpp b/source/gui/scripting/GuiScriptConversions.cpp index 0dd18fbb9a..24c5097745 100644 --- a/source/gui/scripting/GuiScriptConversions.cpp +++ b/source/gui/scripting/GuiScriptConversions.cpp @@ -17,6 +17,7 @@ #include "precompiled.h" +#include "gui/CGUIColor.h" #include "gui/CGUIList.h" #include "gui/CGUISeries.h" #include "gui/GUIbase.h" @@ -144,6 +145,31 @@ JSVAL_VECTOR(CVector2D) JSVAL_VECTOR(std::vector) JSVAL_VECTOR(CGUIString) +template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CGUIColor& val) +{ + ToJSVal(cx, ret, val); +} + +template<> bool ScriptInterface::FromJSVal(JSContext* cx, JS::HandleValue v, CGUIColor& out) +{ + if (v.isString()) + { + CStr name; + if (!FromJSVal(cx, v, name)) + return false; + + if (!out.ParseString(name)) + { + JS_ReportError(cx, "Invalid color '%s'", name); + return false; + } + return true; + } + + // Parse as object + return FromJSVal(cx, v, out); +} + template<> void ScriptInterface::ToJSVal(JSContext* cx, JS::MutableHandleValue ret, const CClientArea& val) { val.ToJSVal(cx, ret); diff --git a/source/gui/scripting/JSInterface_IGUIObject.cpp b/source/gui/scripting/JSInterface_IGUIObject.cpp index cde9174a9f..d91bbadd46 100644 --- a/source/gui/scripting/JSInterface_IGUIObject.cpp +++ b/source/gui/scripting/JSInterface_IGUIObject.cpp @@ -18,18 +18,17 @@ #include "precompiled.h" #include "JSInterface_IGUIObject.h" -#include "JSInterface_GUITypes.h" -#include "gui/IGUIObject.h" #include "gui/CGUI.h" -#include "gui/IGUIScrollBar.h" +#include "gui/CGUIColor.h" #include "gui/CList.h" #include "gui/GUIManager.h" - +#include "gui/IGUIObject.h" +#include "gui/IGUIScrollBar.h" +#include "gui/scripting/JSInterface_GUITypes.h" #include "ps/CLogger.h" - -#include "scriptinterface/ScriptInterface.h" #include "scriptinterface/ScriptExtraHeaders.h" +#include "scriptinterface/ScriptInterface.h" JSClass JSI_IGUIObject::JSI_class = { "GUIObject", JSCLASS_HAS_PRIVATE, @@ -160,11 +159,11 @@ bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::Handle break; } - case GUIST_CColor: + case GUIST_CGUIColor: { - CColor color; - GUI::GetSetting(e, propName, color); - ScriptInterface::ToJSVal(cx, vp, color); + CGUIColor value; + GUI::GetSetting(e, propName, value); + ScriptInterface::ToJSVal(cx, vp, value); break; } @@ -422,33 +421,12 @@ bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::Handle break; } - case GUIST_CColor: + case GUIST_CGUIColor: { - if (vp.isString()) - { - std::wstring value; - if (!ScriptInterface::FromJSVal(cx, vp, value)) - return false; - - if (e->SetSetting(propName, value) != PSRETURN_OK) - { - JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); - return false; - } - } - else if (vp.isObject()) - { - CColor color; - if (!ScriptInterface::FromJSVal(cx, vp, color)) - // Exception has been thrown already - return false; - GUI::SetSetting(e, propName, color); - } - else - { - JS_ReportError(cx, "Color only accepts strings or GUIColor objects"); + CGUIColor value; + if (!ScriptInterface::FromJSVal(cx, vp, value)) return false; - } + GUI::SetSetting(e, propName, value); break; }