2019-01-13 16:38:41 +01:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_COLOR
|
|
|
|
#define INCLUDED_COLOR
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2019-01-13 16:38:41 +01:00
|
|
|
#include "graphics/SColor.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "maths/Vector3D.h"
|
|
|
|
#include "maths/Vector4D.h"
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2019-01-13 16:38:41 +01:00
|
|
|
// Simple defines for 3 and 4 component floating point colors - just map to
|
|
|
|
// corresponding vector types.
|
2004-05-29 22:56:24 +02:00
|
|
|
typedef CVector3D RGBColor;
|
|
|
|
typedef CVector4D RGBAColor;
|
|
|
|
|
2019-01-13 16:38:41 +01:00
|
|
|
// Convert float RGB(A) colors to unsigned byte.
|
|
|
|
// Exposed as function pointer because it is set at init-time to
|
2006-04-14 08:32:05 +02:00
|
|
|
// one of several implementations depending on CPU caps.
|
2008-06-30 21:08:29 +02:00
|
|
|
extern SColor4ub (*ConvertRGBColorTo4ub)(const RGBColor& src);
|
2005-10-03 05:41:42 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
// call once ia32_Init has run; detects CPU caps and activates the best
|
2006-04-14 08:32:05 +02:00
|
|
|
// possible codepath.
|
|
|
|
extern void ColorActivateFastImpl();
|
|
|
|
|
2019-01-13 16:38:41 +01:00
|
|
|
class CStr8;
|
|
|
|
|
|
|
|
struct CColor
|
|
|
|
{
|
|
|
|
CColor() : r(-1.f), g(-1.f), b(-1.f), a(1.f) {}
|
|
|
|
CColor(float cr, float cg, float cb, float ca) : r(cr), g(cg), b(cb), a(ca) {}
|
|
|
|
|
2019-08-18 17:17:49 +02:00
|
|
|
/**
|
|
|
|
* Returns whether this has been set to a valid color.
|
|
|
|
*/
|
|
|
|
operator bool() const
|
|
|
|
{
|
|
|
|
return r >= 0 && g >= 0 && b >= 0 && a >= 0;
|
|
|
|
}
|
|
|
|
|
2019-01-13 16:38:41 +01:00
|
|
|
/**
|
|
|
|
* Try to parse @p Value as a color. Returns true on success, false otherwise.
|
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
|
|
|
* Leaves the color unchanged if it failed.
|
2019-01-13 16:38:41 +01:00
|
|
|
* @param value Should be "r g b" or "r g b a" where each value is an integer in [0,255].
|
|
|
|
* @param defaultAlpha The alpha value that is used if the format of @p Value is "r g b".
|
|
|
|
*/
|
|
|
|
bool ParseString(const CStr8& value, int defaultAlpha = 255);
|
|
|
|
|
|
|
|
bool operator==(const CColor& color) const;
|
|
|
|
bool operator!=(const CColor& color) const
|
|
|
|
{
|
|
|
|
return !(*this == color);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For passing to glColor[34]fv:
|
|
|
|
const float* FloatArray() const { return &r; }
|
|
|
|
|
|
|
|
// For passing to CRenderer:
|
|
|
|
SColor4ub AsSColor4ub() const
|
|
|
|
{
|
|
|
|
return SColor4ub(
|
|
|
|
static_cast<u8>(r * 255.f),
|
|
|
|
static_cast<u8>(g * 255.f),
|
|
|
|
static_cast<u8>(b * 255.f),
|
|
|
|
static_cast<u8>(a * 255.f)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
float r, g, b, a;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDED_COLOR
|