mirror of https://github.com/axmolengine/axmol.git
Colors are now compare- and explicit convertible
This commit is contained in:
parent
237f7a7839
commit
0160bec3ad
|
@ -26,42 +26,221 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Color4B::Color4B(const Color4F &color4F)
|
||||
: r((GLubyte)(color4F.r * 255.0f)),
|
||||
g((GLubyte)(color4F.g * 255.0f)),
|
||||
b((GLubyte)(color4F.b * 255.0f)),
|
||||
a((GLubyte)(color4F.a * 255.0f))
|
||||
/**
|
||||
* Color3B
|
||||
*/
|
||||
|
||||
Color3B::Color3B()
|
||||
: r(0)
|
||||
, g(0)
|
||||
, b(0)
|
||||
{}
|
||||
|
||||
const Color3B Color3B::WHITE(255,255,255);
|
||||
const Color3B Color3B::YELLOW(255,255,0);
|
||||
const Color3B Color3B::GREEN(0,255,0);
|
||||
const Color3B Color3B::BLUE(0,0,255);
|
||||
const Color3B Color3B::RED(255,0,0);
|
||||
const Color3B Color3B::MAGENTA(255,0,255);
|
||||
const Color3B Color3B::BLACK(0,0,0);
|
||||
const Color3B Color3B::ORANGE(255,127,0);
|
||||
const Color3B Color3B::GRAY(166,166,166);
|
||||
Color3B::Color3B(GLubyte _r, GLubyte _g, GLubyte _b)
|
||||
: r(_r)
|
||||
, g(_g)
|
||||
, b(_b)
|
||||
{}
|
||||
|
||||
const Color4B Color4B::WHITE(255,255,255,255);
|
||||
const Color4B Color4B::YELLOW(255,255,0,255);
|
||||
const Color4B Color4B::GREEN(0,255,0,255);
|
||||
const Color4B Color4B::BLUE(0,0,255,255);
|
||||
const Color4B Color4B::RED(255,0,0,255);
|
||||
const Color4B Color4B::MAGENTA(255,0,255,255);
|
||||
const Color4B Color4B::BLACK(0,0,0,255);
|
||||
const Color4B Color4B::ORANGE(255,127,0,255);
|
||||
const Color4B Color4B::GRAY(166,166,166,255);
|
||||
Color3B::Color3B(const Color4B& color)
|
||||
: r(color.r)
|
||||
, g(color.g)
|
||||
, b(color.b)
|
||||
{}
|
||||
|
||||
const Color4F Color4F::WHITE(1,1,1,1);
|
||||
const Color4F Color4F::YELLOW(1,1,0,1);
|
||||
const Color4F Color4F::GREEN(0,1,0,1);
|
||||
const Color4F Color4F::BLUE(0,0,1,1);
|
||||
const Color4F Color4F::RED(1,0,0,1);
|
||||
const Color4F Color4F::MAGENTA(1,0,1,1);
|
||||
const Color4F Color4F::BLACK(0,0,0,1);
|
||||
const Color4F Color4F::ORANGE(1,0.5f,0,1);
|
||||
const Color4F Color4F::GRAY(0.65f,0.65f,0.65f,1);
|
||||
Color3B::Color3B(const Color4F& color)
|
||||
: r(color.r * 255.0f)
|
||||
, g(color.g * 255.0f)
|
||||
, b(color.b * 255.0f)
|
||||
{}
|
||||
|
||||
bool Color3B::operator==(const Color3B& right) const
|
||||
{
|
||||
return (r == right.r && g == right.g && b == right.b);
|
||||
}
|
||||
|
||||
bool Color3B::operator==(const Color4B& right) const
|
||||
{
|
||||
return (r == right.r && g == right.g && b == right.b && 255 == right.a);
|
||||
}
|
||||
|
||||
bool Color3B::operator==(const Color4F& right) const
|
||||
{
|
||||
return (right.a == 1.0f && Color4F(*this) == right);
|
||||
}
|
||||
|
||||
bool Color3B::operator!=(const Color3B& right) const
|
||||
{
|
||||
return !(*this == right);
|
||||
}
|
||||
|
||||
bool Color3B::operator!=(const Color4B& right) const
|
||||
{
|
||||
return !(*this == right);
|
||||
}
|
||||
|
||||
bool Color3B::operator!=(const Color4F& right) const
|
||||
{
|
||||
return !(*this == right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Color4B
|
||||
*/
|
||||
|
||||
Color4B::Color4B()
|
||||
: r(0)
|
||||
, g(0)
|
||||
, b(0)
|
||||
, a(0)
|
||||
{}
|
||||
|
||||
Color4B::Color4B(GLubyte _r, GLubyte _g, GLubyte _b, GLubyte _a)
|
||||
: r(_r)
|
||||
, g(_g)
|
||||
, b(_b)
|
||||
, a(_a)
|
||||
{}
|
||||
|
||||
Color4B::Color4B(const Color3B& color)
|
||||
: r(color.r * 255)
|
||||
, g(color.g * 255)
|
||||
, b(color.b * 255)
|
||||
, a(255)
|
||||
{}
|
||||
|
||||
Color4B::Color4B(const Color4F& color)
|
||||
: r(color.r * 255)
|
||||
, g(color.g * 255)
|
||||
, b(color.b * 255)
|
||||
, a(color.a * 255)
|
||||
{}
|
||||
|
||||
bool Color4B::operator==(const Color4B& right) const
|
||||
{
|
||||
return (r == right.r && g == right.g && b == right.b && a == right.a);
|
||||
}
|
||||
|
||||
bool Color4B::operator==(const Color3B& right) const
|
||||
{
|
||||
return (r == right.r && g == right.g && b == right.b && a == 255);
|
||||
}
|
||||
|
||||
bool Color4B::operator==(const Color4F& right) const
|
||||
{
|
||||
return (*this == Color4B(right));
|
||||
}
|
||||
|
||||
bool Color4B::operator!=(const Color4B& right) const
|
||||
{
|
||||
return !(*this == right);
|
||||
}
|
||||
|
||||
bool Color4B::operator!=(const Color3B& right) const
|
||||
{
|
||||
return !(*this == right);
|
||||
}
|
||||
|
||||
bool Color4B::operator!=(const Color4F& right) const
|
||||
{
|
||||
return !(*this == right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Color4F
|
||||
*/
|
||||
|
||||
Color4F::Color4F()
|
||||
: r(0.0f)
|
||||
, g(0.0f)
|
||||
, b(0.0f)
|
||||
, a(0.0f)
|
||||
{}
|
||||
|
||||
Color4F::Color4F(float _r, float _g, float _b, float _a)
|
||||
: r(_r)
|
||||
, g(_g)
|
||||
, b(_b)
|
||||
, a(_a)
|
||||
{}
|
||||
|
||||
Color4F::Color4F(const Color3B& color)
|
||||
: r(color.r / 255.0f)
|
||||
, g(color.g / 255.0f)
|
||||
, b(color.b / 255.0f)
|
||||
, a(1.0f)
|
||||
{}
|
||||
|
||||
Color4F::Color4F(const Color4B& color)
|
||||
: r(color.r / 255.0f)
|
||||
, g(color.g / 255.0f)
|
||||
, b(color.b / 255.0f)
|
||||
, a(color.a / 255.0f)
|
||||
{}
|
||||
|
||||
bool Color4F::operator==(const Color4F& right) const
|
||||
{
|
||||
return (r == right.r && g == right.g && b == right.b && a == right.a);
|
||||
}
|
||||
|
||||
bool Color4F::operator==(const Color3B& right) const
|
||||
{
|
||||
return (a == 1.0f && Color3B(*this) == right);
|
||||
}
|
||||
|
||||
bool Color4F::operator==(const Color4B& right) const
|
||||
{
|
||||
return (*this == Color4F(right));
|
||||
}
|
||||
|
||||
bool Color4F::operator!=(const Color4F& right) const
|
||||
{
|
||||
return !(*this == right);
|
||||
}
|
||||
|
||||
bool Color4F::operator!=(const Color3B& right) const
|
||||
{
|
||||
return !(*this == right);
|
||||
}
|
||||
|
||||
bool Color4F::operator!=(const Color4B& right) const
|
||||
{
|
||||
return !(*this == right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Color constants
|
||||
*/
|
||||
|
||||
const Color3B Color3B::WHITE (255, 255, 255);
|
||||
const Color3B Color3B::YELLOW (255, 255, 0);
|
||||
const Color3B Color3B::GREEN ( 0, 255, 0);
|
||||
const Color3B Color3B::BLUE ( 0, 0, 255);
|
||||
const Color3B Color3B::RED (255, 0, 0);
|
||||
const Color3B Color3B::MAGENTA(255, 0, 255);
|
||||
const Color3B Color3B::BLACK ( 0, 0, 0);
|
||||
const Color3B Color3B::ORANGE (255, 127, 0);
|
||||
const Color3B Color3B::GRAY (166, 166, 166);
|
||||
|
||||
const Color4B Color4B::WHITE (255, 255, 255, 255);
|
||||
const Color4B Color4B::YELLOW (255, 255, 0, 255);
|
||||
const Color4B Color4B::GREEN ( 0, 255, 0, 255);
|
||||
const Color4B Color4B::BLUE ( 0, 0, 255, 255);
|
||||
const Color4B Color4B::RED (255, 0, 0, 255);
|
||||
const Color4B Color4B::MAGENTA(255, 0, 255, 255);
|
||||
const Color4B Color4B::BLACK ( 0, 0, 0, 255);
|
||||
const Color4B Color4B::ORANGE (255, 127, 0, 255);
|
||||
const Color4B Color4B::GRAY (166, 166, 166, 255);
|
||||
|
||||
const Color4F Color4F::WHITE ( 1, 1, 1, 1);
|
||||
const Color4F Color4F::YELLOW ( 1, 1, 0, 1);
|
||||
const Color4F Color4F::GREEN ( 0, 1, 0, 1);
|
||||
const Color4F Color4F::BLUE ( 0, 0, 1, 1);
|
||||
const Color4F Color4F::RED ( 1, 0, 0, 1);
|
||||
const Color4F Color4F::MAGENTA( 1, 0, 1, 1);
|
||||
const Color4F Color4F::BLACK ( 0, 0, 0, 1);
|
||||
const Color4F Color4F::ORANGE ( 1, 0.5f, 0, 1);
|
||||
const Color4F Color4F::GRAY (0.65f, 0.65f, 0.65f, 1);
|
||||
|
||||
const BlendFunc BlendFunc::DISABLE = {GL_ONE, GL_ZERO};
|
||||
const BlendFunc BlendFunc::ALPHA_PREMULTIPLIED = {GL_ONE, GL_ONE_MINUS_SRC_ALPHA};
|
||||
|
|
|
@ -31,29 +31,33 @@ THE SOFTWARE.
|
|||
#include "CCGeometry.h"
|
||||
#include "CCGL.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
struct Color4B;
|
||||
struct Color4F;
|
||||
|
||||
/** RGB color composed of bytes 3 bytes
|
||||
@since v3.0
|
||||
*/
|
||||
struct Color3B
|
||||
{
|
||||
Color3B(): r(0), g(0), b(0) {}
|
||||
|
||||
Color3B(GLubyte _r, GLubyte _g, GLubyte _b)
|
||||
: r(_r)
|
||||
, g(_g)
|
||||
, b(_b)
|
||||
{}
|
||||
|
||||
bool equals(const Color3B &other)
|
||||
Color3B();
|
||||
Color3B(GLubyte _r, GLubyte _g, GLubyte _b);
|
||||
explicit Color3B(const Color4B& color);
|
||||
explicit Color3B(const Color4F& color);
|
||||
|
||||
bool operator==(const Color3B& right) const;
|
||||
bool operator==(const Color4B& right) const;
|
||||
bool operator==(const Color4F& right) const;
|
||||
bool operator!=(const Color3B& right) const;
|
||||
bool operator!=(const Color4B& right) const;
|
||||
bool operator!=(const Color4F& right) const;
|
||||
|
||||
bool equals(const Color3B& other)
|
||||
{
|
||||
return (this->r == other.r &&
|
||||
this->g == other.g &&
|
||||
this->b == other.b);
|
||||
return (*this == other);
|
||||
}
|
||||
|
||||
|
||||
GLubyte r;
|
||||
GLubyte g;
|
||||
GLubyte b;
|
||||
|
@ -69,24 +73,22 @@ struct Color3B
|
|||
const static Color3B GRAY;
|
||||
};
|
||||
|
||||
struct Color4F;
|
||||
|
||||
/** RGBA color composed of 4 bytes
|
||||
@since v3.0
|
||||
*/
|
||||
struct Color4B
|
||||
{
|
||||
Color4B(GLubyte _r, GLubyte _g, GLubyte _b, GLubyte _a)
|
||||
: r(_r)
|
||||
, g(_g)
|
||||
, b(_b)
|
||||
, a(_a)
|
||||
{}
|
||||
|
||||
Color4B(): r(0), g(0), b(0), a(0) {}
|
||||
|
||||
// This function should use Color4F, so implement it in .cpp file.
|
||||
explicit Color4B(const Color4F &color4F);
|
||||
Color4B();
|
||||
Color4B(GLubyte _r, GLubyte _g, GLubyte _b, GLubyte _a);
|
||||
explicit Color4B(const Color3B& color);
|
||||
explicit Color4B(const Color4F& color);
|
||||
|
||||
bool operator==(const Color4B& right) const;
|
||||
bool operator==(const Color3B& right) const;
|
||||
bool operator==(const Color4F& right) const;
|
||||
bool operator!=(const Color4B& right) const;
|
||||
bool operator!=(const Color3B& right) const;
|
||||
bool operator!=(const Color4F& right) const;
|
||||
|
||||
GLubyte r;
|
||||
GLubyte g;
|
||||
|
@ -110,35 +112,21 @@ struct Color4B
|
|||
*/
|
||||
struct Color4F
|
||||
{
|
||||
Color4F(float _r, float _g, float _b, float _a)
|
||||
: r(_r)
|
||||
, g(_g)
|
||||
, b(_b)
|
||||
, a(_a)
|
||||
{}
|
||||
|
||||
explicit Color4F(const Color3B &color3B)
|
||||
: r(color3B.r / 255.0f)
|
||||
, g(color3B.g / 255.0f)
|
||||
, b(color3B.b / 255.0f)
|
||||
, a(1.f)
|
||||
{}
|
||||
|
||||
explicit Color4F(const Color4B &color4B)
|
||||
: r(color4B.r / 255.0f)
|
||||
, g(color4B.g / 255.0f)
|
||||
, b(color4B.b / 255.0f)
|
||||
, a(color4B.a / 255.0f)
|
||||
{}
|
||||
|
||||
Color4F(): r(0.f), g(0.f), b(0.f), a(0.f) {}
|
||||
|
||||
Color4F();
|
||||
Color4F(float _r, float _g, float _b, float _a);
|
||||
explicit Color4F(const Color3B& color);
|
||||
explicit Color4F(const Color4B& color);
|
||||
|
||||
bool operator==(const Color4F& right) const;
|
||||
bool operator==(const Color3B& right) const;
|
||||
bool operator==(const Color4B& right) const;
|
||||
bool operator!=(const Color4F& right) const;
|
||||
bool operator!=(const Color3B& right) const;
|
||||
bool operator!=(const Color4B& right) const;
|
||||
|
||||
bool equals(const Color4F &other)
|
||||
{
|
||||
return (this->r == other.r &&
|
||||
this->g == other.g &&
|
||||
this->b == other.b &&
|
||||
this->a == other.a);
|
||||
return (*this == other);
|
||||
}
|
||||
|
||||
GLfloat r;
|
||||
|
|
Loading…
Reference in New Issue