2019-07-26 20:57:28 +02:00
|
|
|
/* 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"
|
Delete wrongful proxy CGUIManager::GetPreDefinedColor from f0d9806b3f.
It is wrong because the predefined colors should be loaded from the GUI
page that requests to have the color parsed, which may be different from
the topmost page.
Similar to FindObjectByName removed in f9b529f2fb.
Achieve this by implementing the CGUISetting<CGUIColor>::FromJSVal
specialization, moved from ScriptInterface::FromJSVal<CGUIColor>,
instead of adding a CGUI pointer to CGUIColor.
Mark ScriptInterface::FromJSVal<GUIColor> and inherited
CColor::ParseString explicitly as deleted, so that people get a compile
error if they forget to check for predefined colors when parsing a
color.
Refs #5387, D1746 > D1684 > this > f9b529f2fb, 9be8a560a9, 415939b59b,
2c47fbd66a, 85a622b13a.
Differential Revision: https://code.wildfiregames.com/D2108
Tested on: clang 8, VS2015
This was SVN commit r22663.
2019-08-13 20:00:41 +02:00
|
|
|
#include "ps/CStr.h"
|
|
|
|
|
|
|
|
class CGUI;
|
2019-07-26 20:57:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as the CColor class, but this one can also parse colors predefined in the GUI page (such as "yellow").
|
|
|
|
*/
|
2019-08-05 22:45:15 +02:00
|
|
|
struct CGUIColor : CColor
|
2019-07-26 20:57:28 +02:00
|
|
|
{
|
Stop copying color every draw call for every GUI object using colors.
Avoid color copies for rendering Draw calls in
GUIRenderer::UpdateDrawCallCache, CButton::Draw, CChart::DrawAxes,
CDropDown::Draw, CList::DrawList, COList::DrawList, refs #1984,
8f4f8e240f, 3028551b91, a905fbbc98.
Avoid color copies during XML loading in CGUI::Xeromyces_ReadImage,
CGUI::Xeromyces_ReadEffects, COList::HandleAdditionalChildren.
Add CGUI::HasPreDefinedColor and mark m_PreDefinedColors,
CGUI::GetPreDefinedColor, IGUIButtonBehavior::ChooseColor() as const for
consistency with the other "databases", refs 3028551b91.
Mark CGUIColor as NONCOPYABLE to add compiler errors if there is an
unexplicit copy, refs 3028551b91.
Explicit ugly copy in CGUI::Xeromyces_ReadColor and
CGUIColor::ParseString.
Deregister copying <CGUIColor>GetSetting functions, refs 8f4f8e240f.
Uses the const ref GetSetting from 3dfa23cd25.
This was SVN commit r22694.
2019-08-19 14:53:58 +02:00
|
|
|
// Take advantage of compiler warnings if unintentionally copying this
|
|
|
|
NONCOPYABLE(CGUIColor);
|
|
|
|
|
|
|
|
// Defines move semantics so that the structs using the class can use it.
|
|
|
|
MOVABLE(CGUIColor);
|
|
|
|
|
2019-08-09 16:54:14 +02:00
|
|
|
CGUIColor() : CColor() {}
|
2019-07-26 20:57:28 +02:00
|
|
|
|
2019-08-09 16:54:14 +02:00
|
|
|
CGUIColor(float r, float g, float b, float a) : CColor(r, g, b, a) {}
|
2019-08-05 22:45:15 +02:00
|
|
|
|
2019-08-18 17:17:49 +02:00
|
|
|
/**
|
|
|
|
* Returns this color if it has been set, otherwise the given fallback color.
|
|
|
|
*/
|
|
|
|
const CGUIColor& operator||(const CGUIColor& fallback) const
|
|
|
|
{
|
|
|
|
if (*this)
|
|
|
|
return *this;
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
|
Delete wrongful proxy CGUIManager::GetPreDefinedColor from f0d9806b3f.
It is wrong because the predefined colors should be loaded from the GUI
page that requests to have the color parsed, which may be different from
the topmost page.
Similar to FindObjectByName removed in f9b529f2fb.
Achieve this by implementing the CGUISetting<CGUIColor>::FromJSVal
specialization, moved from ScriptInterface::FromJSVal<CGUIColor>,
instead of adding a CGUI pointer to CGUIColor.
Mark ScriptInterface::FromJSVal<GUIColor> and inherited
CColor::ParseString explicitly as deleted, so that people get a compile
error if they forget to check for predefined colors when parsing a
color.
Refs #5387, D1746 > D1684 > this > f9b529f2fb, 9be8a560a9, 415939b59b,
2c47fbd66a, 85a622b13a.
Differential Revision: https://code.wildfiregames.com/D2108
Tested on: clang 8, VS2015
This was SVN commit r22663.
2019-08-13 20:00:41 +02:00
|
|
|
/**
|
|
|
|
* Load color depending on current GUI page.
|
|
|
|
*/
|
2019-08-21 12:12:33 +02:00
|
|
|
bool ParseString(const CGUI& pGUI, const CStr& value, int defaultAlpha = 255);
|
Delete wrongful proxy CGUIManager::GetPreDefinedColor from f0d9806b3f.
It is wrong because the predefined colors should be loaded from the GUI
page that requests to have the color parsed, which may be different from
the topmost page.
Similar to FindObjectByName removed in f9b529f2fb.
Achieve this by implementing the CGUISetting<CGUIColor>::FromJSVal
specialization, moved from ScriptInterface::FromJSVal<CGUIColor>,
instead of adding a CGUI pointer to CGUIColor.
Mark ScriptInterface::FromJSVal<GUIColor> and inherited
CColor::ParseString explicitly as deleted, so that people get a compile
error if they forget to check for predefined colors when parsing a
color.
Refs #5387, D1746 > D1684 > this > f9b529f2fb, 9be8a560a9, 415939b59b,
2c47fbd66a, 85a622b13a.
Differential Revision: https://code.wildfiregames.com/D2108
Tested on: clang 8, VS2015
This was SVN commit r22663.
2019-08-13 20:00:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that all users check for predefined colors.
|
|
|
|
*/
|
|
|
|
bool ParseString(const CStr& value, int defaultAlpha = 255) = delete;
|
2019-07-26 20:57:28 +02:00
|
|
|
};
|
|
|
|
#endif // INCLUDED_GUICOLOR
|