Introduce CGUIColor type inheriting Color type and switch the GUI to exclusively use that.

The type differs from the Color type, because contrary to Color, it can
be created from a color predefined in the GUI page (such as "yellow").
Move this predefined color check to the new class instead of hardcoding
it in FromJSVal / ToJSVal, GUIUtil, JSInterface_IGUIObject and to
straighten the latter.

Delete fov_wedge_color from Minimap, unused since introduction in
5275dc862b.

This was SVN commit r22558.
This commit is contained in:
elexis 2019-07-26 18:57:28 +00:00
parent b9f3c8557b
commit 415939b59b
32 changed files with 213 additions and 180 deletions

View file

@ -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);
}

View file

@ -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<float>& vertices) const
void CChart::DrawLine(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector<float>& 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<float>& vertices) const
void CChart::DrawTriangleStrip(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector<float>& 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<CColor>::GetSetting(this, "axis_color", axis_color);
CGUIColor axis_color(0.5f, 0.5f, 0.5f, 1.f);
GUI<CGUIColor>::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

View file

@ -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 <vector>
struct CChartData
{
CColor m_Color;
CGUIColor m_Color;
std::vector<CVector2D> m_Points;
};
@ -77,11 +77,11 @@ private:
/**
* Helper functions
*/
void DrawLine(const CShaderProgramPtr& shader, const CColor& color, const std::vector<float>& vertices) const;
void DrawLine(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector<float>& 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<float>& vertices) const;
void DrawTriangleStrip(const CShaderProgramPtr& shader, const CGUIColor& color, const std::vector<float>& vertices) const;
// Represents axes as triangles and draws them with DrawTriangleStrip.
void DrawAxes(const CShaderProgramPtr& shader) const;

View file

@ -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");

View file

@ -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<bool>::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<bool>::GetSetting(this, "enabled", enabled);
@ -494,7 +495,7 @@ void CDropDown::Draw()
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2", sprite2);
GUI<int>::GetSetting(this, "cell_id", cell_id);
GUI<int>::GetSetting(this, "selected", selected);
GUI<CColor>::GetSetting(this, enabled ? "textcolor_selected" : "textcolor_disabled", color);
GUI<CGUIColor>::GetSetting(this, enabled ? "textcolor_selected" : "textcolor_disabled", color);
GUI<CGUISpriteInstance>::GetSettingPointer(this, enabled ? "sprite" : "sprite_disabled", sprite);
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);

View file

@ -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<CStr, CColor>::const_iterator cit = m_PreDefinedColors.find(name);
std::map<CStr, CGUIColor>::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<CColor>::ParseString(attr_value, color))
CGUIColor color;
if (!GUI<CGUIColor>::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<CColor>::ParseString(attr_value, color))
CGUIColor color;
if (!GUI<CGUIColor>::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<int>::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

View file

@ -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<ScriptInterface> 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<CStr, CColor> m_PreDefinedColors;
std::map<CStr, CGUIColor> m_PreDefinedColors;
//@}
//--------------------------------------------------------

36
source/gui/CGUIColor.h Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#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

View file

@ -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;

View file

@ -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<CStrW>::GetSetting(this, "font", font_name_w);
GUI<CColor>::GetSetting(this, "textcolor", color);
GUI<CColor>::GetSetting(this, "textcolor_selected", color_selected);
GUI<CGUIColor>::GetSetting(this, "textcolor", color);
GUI<CGUIColor>::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

View file

@ -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<CColor>::GetSetting(this, _textcolor, color);
CGUIColor color;
GUI<CGUIColor>::GetSetting(this, _textcolor, color);
for (size_t i = 0; i < pList->m_Items.size(); ++i)
{

View file

@ -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<CColor>::ParseString(attr_value.FromUTF8(), color))
CGUIColor color;
if (!GUI<CGUIColor>::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<int>::GetSetting(this, "selected_column_order", selectedColumnOrder);
CColor color;
GUI<CColor>::GetSetting(this, _textcolor, color);
CGUIColor color;
GUI<CGUIColor>::GetSetting(this, _textcolor, color);
float xpos = 0;
for (size_t col = 0; col < m_Columns.size(); ++col)

View file

@ -25,7 +25,7 @@
*/
struct COListColumn
{
CColor m_TextColor;
CGUIColor m_TextColor;
CStr m_Id;
float m_Width;
CStrW m_Heading;

View file

@ -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<bool>::GetSetting(this, "enabled", enabled);
CColor color;
GUI<CColor>::GetSetting(this, enabled ? "textcolor" : "textcolor_disabled", color);
CGUIColor color;
GUI<CGUIColor>::GetSetting(this, enabled ? "textcolor" : "textcolor_disabled", color);
if (scrollbar)
DrawText(0, color, m_CachedActualSize.TopLeft() - CPos(0.f, scroll), bz+0.1f, cliparea);

View file

@ -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<CColor>::GetSetting(this, "textcolor", color);
CGUIColor color;
GUI<CGUIColor>::GetSetting(this, "textcolor", color);
DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f);
}

View file

@ -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);
}

View file

@ -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.

View file

@ -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<CColor>::ParseString(value, color))
if (!GUI<CGUIColor>::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);

View file

@ -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<SDrawCall>

View file

@ -35,7 +35,7 @@ GUI Core, stuff that the whole GUI uses
#include <map>
#include <vector>
#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

View file

@ -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 <algorithm>
#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<CColor>::ParseString(tag.m_TagValue, TextCall.m_Color) && pObject)
if (!GUI<CGUIColor>::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:

View file

@ -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 <list>
#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

View file

@ -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

View file

@ -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<CClientArea>(const CStrW& Value, CClientArea& Output)
}
template <>
bool GUI<int>::ParseColor(const CStrW& Value, CColor& Output, int DefaultAlpha)
bool GUI<int>::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<CColor>(const CStrW& Value, CColor& Output)
bool __ParseString<CGUIColor>(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());
}

View file

@ -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<T>(Value, tOutput);
}
static bool ParseColor(const CStrW& Value, CColor& tOutput, int DefaultAlpha);
static bool ParseColor(const CStrW& Value, CGUIColor& tOutput, int DefaultAlpha);
private:

View file

@ -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<CColor>::GetSetting(this, "textcolor", color);
GUI<CGUIColor>::GetSetting(this, "textcolor", color);
bool enabled;
GUI<bool>::GetSetting(this, "enabled", enabled);
if (!enabled)
{
GUI<CColor>::GetSetting(this, "textcolor_disabled", color2);
GUI<CGUIColor>::GetSetting(this, "textcolor_disabled", color2);
return GUI<>::FallBackColor(color2, color);
}
else if (m_MouseHovering)
{
if (m_Pressed)
{
GUI<CColor>::GetSetting(this, "textcolor_pressed", color2);
GUI<CGUIColor>::GetSetting(this, "textcolor_pressed", color2);
return GUI<>::FallBackColor(color2, color);
}
else
{
GUI<CColor>::GetSetting(this, "textcolor_over", color2);
GUI<CGUIColor>::GetSetting(this, "textcolor_over", color2);
return GUI<>::FallBackColor(color2, color);
}
}

View file

@ -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:

View file

@ -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)
{

View file

@ -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

View file

@ -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;

View file

@ -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<CVector2D>)
JSVAL_VECTOR(CGUIString)
template<> void ScriptInterface::ToJSVal<CGUIColor>(JSContext* cx, JS::MutableHandleValue ret, const CGUIColor& val)
{
ToJSVal<CColor>(cx, ret, val);
}
template<> bool ScriptInterface::FromJSVal<CGUIColor>(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<CColor>(cx, v, out);
}
template<> void ScriptInterface::ToJSVal<CClientArea>(JSContext* cx, JS::MutableHandleValue ret, const CClientArea& val)
{
val.ToJSVal(cx, ret);

View file

@ -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<CColor>::GetSetting(e, propName, color);
ScriptInterface::ToJSVal(cx, vp, color);
CGUIColor value;
GUI<CGUIColor>::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<CColor>::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<CGUIColor>::SetSetting(e, propName, value);
break;
}