2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-09-30 02:56:11 +02:00
|
|
|
#include "Base/Color3.hpp"
|
|
|
|
#include "Base/Color4.hpp"
|
|
|
|
#include "Base/Shared.hpp"
|
2016-02-20 23:25:00 +01:00
|
|
|
#include "Library/Random.hpp"
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const Color3 Color3::NIL = Color3();
|
2016-02-20 23:25:00 +01:00
|
|
|
const Color3 Color3::MIN = Color3(NumLimit< Color3::Value >::Min);
|
|
|
|
const Color3 Color3::MAX = Color3(NumLimit< Color3::Value >::Max);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQChar Color3::Delim = ',';
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3::Color3()
|
2015-09-30 02:56:11 +02:00
|
|
|
: r(0), g(0), b(0)
|
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Color3::Color3(Value sv)
|
|
|
|
: r(sv), g(sv), b(sv)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Color3::Color3(Value rv, Value gv, Value bv)
|
|
|
|
: r(rv), g(gv), b(bv)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Color3::Color3(const Color3 & o)
|
|
|
|
: r(o.r), g(o.g), b(o.b)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Color3::~Color3()
|
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
/* ... */
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Color3 & Color3::operator = (const Color3 & o)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
r = o.r;
|
|
|
|
g = o.g;
|
|
|
|
b = o.b;
|
2015-09-30 02:56:11 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator = (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r = s;
|
|
|
|
g = s;
|
|
|
|
b = s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
Color3 & Color3::operator = (CSStr name)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Set(GetColor(name));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator = (const Color4 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r = c.r;
|
|
|
|
g = c.g;
|
|
|
|
b = c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator += (const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r += c.r;
|
|
|
|
g += c.g;
|
|
|
|
b += c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator -= (const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r -= c.r;
|
|
|
|
g -= c.g;
|
|
|
|
b -= c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator *= (const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r *= c.r;
|
|
|
|
g *= c.g;
|
|
|
|
b *= c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator /= (const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r /= c.r;
|
|
|
|
g /= c.g;
|
|
|
|
b /= c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator %= (const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r %= c.r;
|
|
|
|
g %= c.g;
|
|
|
|
b %= c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator &= (const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r &= c.r;
|
|
|
|
g &= c.g;
|
|
|
|
b &= c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator |= (const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r |= c.r;
|
|
|
|
g |= c.g;
|
|
|
|
b |= c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator ^= (const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r ^= c.r;
|
|
|
|
g ^= c.g;
|
|
|
|
b ^= c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator <<= (const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r <<= c.r;
|
|
|
|
g <<= c.g;
|
|
|
|
b <<= c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator >>= (const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r >>= c.r;
|
|
|
|
g >>= c.g;
|
|
|
|
b >>= c.b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator += (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r += s;
|
|
|
|
g += s;
|
|
|
|
b += s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator -= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r -= s;
|
|
|
|
g -= s;
|
|
|
|
b -= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator *= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r *= s;
|
|
|
|
g *= s;
|
|
|
|
b *= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator /= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r /= s;
|
|
|
|
g /= s;
|
|
|
|
b /= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator %= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r %= s;
|
|
|
|
g %= s;
|
|
|
|
b %= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator &= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r &= s;
|
|
|
|
g &= s;
|
|
|
|
b &= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator |= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r |= s;
|
|
|
|
g |= s;
|
|
|
|
b |= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator ^= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r ^= s;
|
|
|
|
g ^= s;
|
|
|
|
b ^= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator <<= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r <<= s;
|
|
|
|
g <<= s;
|
|
|
|
b <<= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator >>= (Value s)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r >>= s;
|
|
|
|
g >>= s;
|
|
|
|
b >>= s;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator ++ ()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
++r;
|
|
|
|
++g;
|
|
|
|
++b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 & Color3::operator -- ()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
--r;
|
|
|
|
--g;
|
|
|
|
--b;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator ++ (int)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Color3 state(*this);
|
|
|
|
++r;
|
|
|
|
++g;
|
|
|
|
++b;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator -- (int)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Color3 state(*this);
|
|
|
|
--r;
|
|
|
|
--g;
|
|
|
|
--b;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator + (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r + c.r, g + c.g, b + c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator - (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r - c.r, g - c.g, b - c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator * (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r * c.r, g * c.g, b * c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator / (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r / c.r, g / c.g, b / c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator % (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r % c.r, g % c.g, b % c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator & (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r & c.r, g & c.g, b & c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator | (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r | c.r, g | c.g, b | c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator ^ (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r ^ c.r, g ^ c.g, b ^ c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator << (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r << c.r, g << c.g, b << c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator >> (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r >> c.r, g >> c.g, b >> c.b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator + (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r + s, g + s, b + s);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator - (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r - s, g - s, b - s);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator * (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r * s, g * s, b * s);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator / (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r / s, g / s, b / s);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator % (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r % s, g % s, b % s);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator & (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r & s, g & s, b & s);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator | (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r | s, g | s, b | s);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator ^ (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r ^ s, g ^ s, b ^ s);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator << (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r << s, g << s, b << s);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator >> (Value s) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r >> s, g >> s, b >> s);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator + () const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(r, g, b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator - () const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
Color3 Color3::operator ~ () const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return Color3(~r, ~g, ~b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Color3::operator == (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (r == c.r) && (g == c.g) && (b == c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Color3::operator != (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (r != c.r) && (g != c.g) && (b != c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Color3::operator < (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (r < c.r) && (g < c.g) && (b < c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Color3::operator > (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (r > c.r) && (g > c.g) && (b > c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Color3::operator <= (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (r <= c.r) && (g <= c.g) && (b <= c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
bool Color3::operator >= (const Color3 & c) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return (r >= c.r) && (g >= c.g) && (b >= c.b);
|
|
|
|
}
|
|
|
|
|
2015-11-09 00:35:39 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Color3::operator Color4 () const
|
|
|
|
{
|
|
|
|
return Color4(r, g, b);
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Int32 Color3::Cmp(const Color3 & o) const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
if (*this == o)
|
|
|
|
return 0;
|
|
|
|
else if (*this > o)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return -1;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
CSStr Color3::ToString() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return ToStringF("%u,%u,%u", r, g, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void Color3::Set(Value ns)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r = ns;
|
|
|
|
g = ns;
|
|
|
|
b = ns;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void Color3::Set(Value nr, Value ng, Value nb)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r = nr;
|
|
|
|
g = ng;
|
|
|
|
b = nb;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void Color3::Set(const Color3 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r = c.r;
|
|
|
|
g = c.g;
|
|
|
|
b = c.b;
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void Color3::Set(const Color4 & c)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
r = c.r;
|
|
|
|
g = c.g;
|
|
|
|
b = c.b;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void Color3::Set(CSStr str, SQChar delim)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Set(GetColor3(str, delim));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
void Color3::SetCol(CSStr name)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Set(GetColor(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Uint32 Color3::GetRGB() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return Uint32(r << 16 | g << 8 | b);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
void Color3::SetRGB(Uint32 p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
r = Value((p >> 16) & 0xFF);
|
|
|
|
g = Value((p >> 8) & 0xFF);
|
|
|
|
b = Value((p) & 0xFF);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Uint32 Color3::GetRGBA() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return Uint32(r << 24 | g << 16 | b << 8 | 0x00);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
void Color3::SetRGBA(Uint32 p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
r = Value((p >> 24) & 0xFF);
|
|
|
|
g = Value((p >> 16) & 0xFF);
|
|
|
|
b = Value((p >> 8) & 0xFF);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-20 23:25:00 +01:00
|
|
|
Uint32 Color3::GetARGB() const
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
return Uint32(0x00 << 24 | r << 16 | g << 8 | b);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
void Color3::SetARGB(Uint32 p)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
r = Value((p >> 16) & 0xFF);
|
|
|
|
g = Value((p >> 8) & 0xFF);
|
|
|
|
b = Value((p) & 0xFF);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void Color3::Generate()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
r = GetRandomUint8();
|
|
|
|
g = GetRandomUint8();
|
|
|
|
b = GetRandomUint8();
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void Color3::Generate(Value min, Value max)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
if (max < min)
|
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
SqThrow("max value is lower than min value");
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
r = GetRandomUint8(min, max);
|
|
|
|
g = GetRandomUint8(min, max);
|
|
|
|
b = GetRandomUint8(min, max);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-01 04:48:01 +01:00
|
|
|
void Color3::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
if (rmax < rmin || gmax < gmin || bmax < bmin)
|
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
SqThrow("max value is lower than min value");
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
r = GetRandomUint8(rmin, rmax);
|
|
|
|
g = GetRandomUint8(gmin, gmax);
|
|
|
|
b = GetRandomUint8(bmin, bmax);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void Color3::Random()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
Set(GetRandomColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-11-01 04:48:01 +01:00
|
|
|
void Color3::Inverse()
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2016-02-20 23:25:00 +01:00
|
|
|
r = Value(~r);
|
|
|
|
g = Value(~g);
|
|
|
|
b = Value(~b);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ================================================================================================
|
2016-02-20 23:25:00 +01:00
|
|
|
void Register_Color3(HSQUIRRELVM vm)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
typedef Color3::Value Val;
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
RootTable(vm).Bind(_SC("Color3"), Class< Color3 >(vm, _SC("Color3"))
|
|
|
|
/* Constructors */
|
2015-09-30 02:56:11 +02:00
|
|
|
.Ctor()
|
2016-02-20 23:25:00 +01:00
|
|
|
.Ctor< Val >()
|
|
|
|
.Ctor< Val, Val, Val >()
|
|
|
|
/* Static Members */
|
|
|
|
.SetStaticValue(_SC("Delim"), &Color3::Delim)
|
|
|
|
/* Member Variables */
|
2015-09-30 02:56:11 +02:00
|
|
|
.Var(_SC("r"), &Color3::r)
|
|
|
|
.Var(_SC("g"), &Color3::g)
|
|
|
|
.Var(_SC("b"), &Color3::b)
|
2016-02-20 23:25:00 +01:00
|
|
|
/* Properties */
|
2015-09-30 02:56:11 +02:00
|
|
|
.Prop(_SC("rgb"), &Color3::GetRGB, &Color3::SetRGB)
|
|
|
|
.Prop(_SC("rgba"), &Color3::GetRGBA, &Color3::SetRGBA)
|
|
|
|
.Prop(_SC("argb"), &Color3::GetARGB, &Color3::SetARGB)
|
|
|
|
.Prop(_SC("str"), &Color3::SetCol)
|
2016-02-20 23:25:00 +01:00
|
|
|
/* Core Metamethods */
|
2015-09-30 02:56:11 +02:00
|
|
|
.Func(_SC("_tostring"), &Color3::ToString)
|
|
|
|
.Func(_SC("_cmp"), &Color3::Cmp)
|
2016-02-20 23:25:00 +01:00
|
|
|
/* Metamethods */
|
2015-09-30 02:56:11 +02:00
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_add"), &Color3::operator +)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_sub"), &Color3::operator -)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_mul"), &Color3::operator *)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_div"), &Color3::operator /)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("_modulo"), &Color3::operator %)
|
|
|
|
.Func<Color3 (Color3::*)(void) const>(_SC("_unm"), &Color3::operator -)
|
2016-02-20 23:25:00 +01:00
|
|
|
/* Setters */
|
|
|
|
.Overload<void (Color3::*)(Val)>(_SC("Set"), &Color3::Set)
|
|
|
|
.Overload<void (Color3::*)(Val, Val, Val)>(_SC("Set"), &Color3::Set)
|
|
|
|
.Overload<void (Color3::*)(const Color3 &)>(_SC("SetCol3"), &Color3::Set)
|
|
|
|
.Overload<void (Color3::*)(const Color4 &)>(_SC("SetCol4"), &Color3::Set)
|
|
|
|
.Overload<void (Color3::*)(CSStr, SQChar)>(_SC("SetStr"), &Color3::Set)
|
|
|
|
/* Random Generators */
|
|
|
|
.Overload<void (Color3::*)(void)>(_SC("Generate"), &Color3::Generate)
|
|
|
|
.Overload<void (Color3::*)(Val, Val)>(_SC("Generate"), &Color3::Generate)
|
|
|
|
.Overload<void (Color3::*)(Val, Val, Val, Val, Val, Val)>(_SC("Generate"), &Color3::Generate)
|
|
|
|
/* Utility Methods */
|
|
|
|
.Func(_SC("Clear"), &Color3::Clear)
|
|
|
|
.Func(_SC("Random"), &Color3::Random)
|
|
|
|
.Func(_SC("Inverse"), &Color3::Inverse)
|
|
|
|
/* Operator Exposure */
|
2015-09-30 02:56:11 +02:00
|
|
|
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opAddAssign"), &Color3::operator +=)
|
|
|
|
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opSubAssign"), &Color3::operator -=)
|
|
|
|
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opMulAssign"), &Color3::operator *=)
|
|
|
|
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opDivAssign"), &Color3::operator /=)
|
|
|
|
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opModAssign"), &Color3::operator %=)
|
|
|
|
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opAndAssign"), &Color3::operator &=)
|
|
|
|
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opOrAssign"), &Color3::operator |=)
|
|
|
|
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opXorAssign"), &Color3::operator ^=)
|
|
|
|
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opShlAssign"), &Color3::operator <<=)
|
|
|
|
.Func<Color3 & (Color3::*)(const Color3 &)>(_SC("opShrAssign"), &Color3::operator >>=)
|
|
|
|
|
|
|
|
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opAddAssignS"), &Color3::operator +=)
|
|
|
|
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opSubAssignS"), &Color3::operator -=)
|
|
|
|
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opMulAssignS"), &Color3::operator *=)
|
|
|
|
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opDivAssignS"), &Color3::operator /=)
|
|
|
|
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opModAssignS"), &Color3::operator %=)
|
|
|
|
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opAndAssignS"), &Color3::operator &=)
|
|
|
|
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opOrAssignS"), &Color3::operator |=)
|
|
|
|
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opXorAssignS"), &Color3::operator ^=)
|
|
|
|
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opShlAssignS"), &Color3::operator <<=)
|
|
|
|
.Func<Color3 & (Color3::*)(Color3::Value)>(_SC("opShrAssignS"), &Color3::operator >>=)
|
|
|
|
|
|
|
|
.Func<Color3 & (Color3::*)(void)>(_SC("opPreInc"), &Color3::operator ++)
|
|
|
|
.Func<Color3 & (Color3::*)(void)>(_SC("opPreDec"), &Color3::operator --)
|
|
|
|
.Func<Color3 (Color3::*)(int)>(_SC("opPostInc"), &Color3::operator ++)
|
|
|
|
.Func<Color3 (Color3::*)(int)>(_SC("opPostDec"), &Color3::operator --)
|
|
|
|
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opAdd"), &Color3::operator +)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opSub"), &Color3::operator -)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opMul"), &Color3::operator *)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opDiv"), &Color3::operator /)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opMod"), &Color3::operator %)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opAnd"), &Color3::operator &)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opOr"), &Color3::operator |)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShl"), &Color3::operator ^)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShl"), &Color3::operator <<)
|
|
|
|
.Func<Color3 (Color3::*)(const Color3 &) const>(_SC("opShr"), &Color3::operator >>)
|
|
|
|
|
|
|
|
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opAddS"), &Color3::operator +)
|
|
|
|
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opSubS"), &Color3::operator -)
|
|
|
|
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opMulS"), &Color3::operator *)
|
|
|
|
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opDivS"), &Color3::operator /)
|
|
|
|
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opModS"), &Color3::operator %)
|
|
|
|
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opAndS"), &Color3::operator &)
|
|
|
|
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opOrS"), &Color3::operator |)
|
|
|
|
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShlS"), &Color3::operator ^)
|
|
|
|
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShlS"), &Color3::operator <<)
|
|
|
|
.Func<Color3 (Color3::*)(Color3::Value) const>(_SC("opShrS"), &Color3::operator >>)
|
|
|
|
|
|
|
|
.Func<Color3 (Color3::*)(void) const>(_SC("opUnPlus"), &Color3::operator +)
|
|
|
|
.Func<Color3 (Color3::*)(void) const>(_SC("opUnMinus"), &Color3::operator -)
|
|
|
|
.Func<Color3 (Color3::*)(void) const>(_SC("opCom"), &Color3::operator ~)
|
|
|
|
|
|
|
|
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opEqual"), &Color3::operator ==)
|
|
|
|
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opNotEqual"), &Color3::operator !=)
|
|
|
|
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opLessThan"), &Color3::operator <)
|
|
|
|
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterThan"), &Color3::operator >)
|
|
|
|
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opLessEqual"), &Color3::operator <=)
|
|
|
|
.Func<bool (Color3::*)(const Color3 &) const>(_SC("opGreaterEqual"), &Color3::operator >=)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|