#include "Base/Color3.hpp" #include "Base/Color4.hpp" #include "Base/Shared.hpp" #include "Register.hpp" // ------------------------------------------------------------------------------------------------ namespace SqMod { // ------------------------------------------------------------------------------------------------ const Color3 Color3::NIL = Color3(); const Color3 Color3::MIN = Color3(std::numeric_limits::min()); const Color3 Color3::MAX = Color3(std::numeric_limits::max()); // ------------------------------------------------------------------------------------------------ SQChar Color3::Delim = ','; // ------------------------------------------------------------------------------------------------ Color3::Color3() noexcept : r(0), g(0), b(0) { } Color3::Color3(Value s) noexcept : r(s), g(s), b(s) { } Color3::Color3(Value rv, Value gv, Value bv) noexcept : r(rv), g(gv), b(bv) { } // ------------------------------------------------------------------------------------------------ Color3::Color3(const Color4 & c) noexcept : r(c.r), g(c.g), b(c.b) { } // ------------------------------------------------------------------------------------------------ Color3::Color3(const SQChar * name) noexcept : Color3(GetColor(name)) { } Color3::Color3(const SQChar * str, SQChar delim) noexcept : Color3(GetColor3(str, delim)) { } // ------------------------------------------------------------------------------------------------ Color3::Color3(const Color3 & c) noexcept : r(c.r), g(c.g), b(c.b) { } Color3::Color3(Color3 && c) noexcept : r(c.r), g(c.g), b(c.b) { } // ------------------------------------------------------------------------------------------------ Color3::~Color3() { } // ------------------------------------------------------------------------------------------------ Color3 & Color3::operator = (const Color3 & c) noexcept { r = c.r; g = c.g; b = c.b; return *this; } Color3 & Color3::operator = (Color3 && c) noexcept { r = c.r; g = c.g; b = c.b; return *this; } // ------------------------------------------------------------------------------------------------ Color3 & Color3::operator = (Value s) noexcept { r = s; g = s; b = s; return *this; } Color3 & Color3::operator = (const SQChar * name) noexcept { Set(GetColor(name)); return *this; } Color3 & Color3::operator = (const Color4 & c) noexcept { r = c.r; g = c.g; b = c.b; return *this; } // ------------------------------------------------------------------------------------------------ Color3 & Color3::operator += (const Color3 & c) noexcept { r += c.r; g += c.g; b += c.b; return *this; } Color3 & Color3::operator -= (const Color3 & c) noexcept { r -= c.r; g -= c.g; b -= c.b; return *this; } Color3 & Color3::operator *= (const Color3 & c) noexcept { r *= c.r; g *= c.g; b *= c.b; return *this; } Color3 & Color3::operator /= (const Color3 & c) noexcept { r /= c.r; g /= c.g; b /= c.b; return *this; } Color3 & Color3::operator %= (const Color3 & c) noexcept { r %= c.r; g %= c.g; b %= c.b; return *this; } Color3 & Color3::operator &= (const Color3 & c) noexcept { r &= c.r; g &= c.g; b &= c.b; return *this; } Color3 & Color3::operator |= (const Color3 & c) noexcept { r |= c.r; g |= c.g; b |= c.b; return *this; } Color3 & Color3::operator ^= (const Color3 & c) noexcept { r ^= c.r; g ^= c.g; b ^= c.b; return *this; } Color3 & Color3::operator <<= (const Color3 & c) noexcept { r <<= c.r; g <<= c.g; b <<= c.b; return *this; } Color3 & Color3::operator >>= (const Color3 & c) noexcept { r >>= c.r; g >>= c.g; b >>= c.b; return *this; } // ------------------------------------------------------------------------------------------------ Color3 & Color3::operator += (Value s) noexcept { r += s; g += s; b += s; return *this; } Color3 & Color3::operator -= (Value s) noexcept { r -= s; g -= s; b -= s; return *this; } Color3 & Color3::operator *= (Value s) noexcept { r *= s; g *= s; b *= s; return *this; } Color3 & Color3::operator /= (Value s) noexcept { r /= s; g /= s; b /= s; return *this; } Color3 & Color3::operator %= (Value s) noexcept { r %= s; g %= s; b %= s; return *this; } Color3 & Color3::operator &= (Value s) noexcept { r &= s; g &= s; b &= s; return *this; } Color3 & Color3::operator |= (Value s) noexcept { r |= s; g |= s; b |= s; return *this; } Color3 & Color3::operator ^= (Value s) noexcept { r ^= s; g ^= s; b ^= s; return *this; } Color3 & Color3::operator <<= (Value s) noexcept { r <<= s; g <<= s; b <<= s; return *this; } Color3 & Color3::operator >>= (Value s) noexcept { r >>= s; g >>= s; b >>= s; return *this; } // ------------------------------------------------------------------------------------------------ Color3 & Color3::operator ++ () noexcept { ++r; ++g; ++b; return *this; } Color3 & Color3::operator -- () noexcept { --r; --g; --b; return *this; } // ------------------------------------------------------------------------------------------------ Color3 Color3::operator ++ (int) noexcept { Color3 state(*this); ++r; ++g; ++b; return state; } Color3 Color3::operator -- (int) noexcept { Color3 state(*this); --r; --g; --b; return state; } // ------------------------------------------------------------------------------------------------ Color3 Color3::operator + (const Color3 & c) const noexcept { return Color3(r + c.r, g + c.g, b + c.b); } Color3 Color3::operator - (const Color3 & c) const noexcept { return Color3(r - c.r, g - c.g, b - c.b); } Color3 Color3::operator * (const Color3 & c) const noexcept { return Color3(r * c.r, g * c.g, b * c.b); } Color3 Color3::operator / (const Color3 & c) const noexcept { return Color3(r / c.r, g / c.g, b / c.b); } Color3 Color3::operator % (const Color3 & c) const noexcept { return Color3(r % c.r, g % c.g, b % c.b); } Color3 Color3::operator & (const Color3 & c) const noexcept { return Color3(r & c.r, g & c.g, b & c.b); } Color3 Color3::operator | (const Color3 & c) const noexcept { return Color3(r | c.r, g | c.g, b | c.b); } Color3 Color3::operator ^ (const Color3 & c) const noexcept { return Color3(r ^ c.r, g ^ c.g, b ^ c.b); } Color3 Color3::operator << (const Color3 & c) const noexcept { return Color3(r << c.r, g << c.g, b << c.b); } Color3 Color3::operator >> (const Color3 & c) const noexcept { return Color3(r >> c.r, g >> c.g, b >> c.b); } // ------------------------------------------------------------------------------------------------ Color3 Color3::operator + (Value s) const noexcept { return Color3(r + s, g + s, b + s); } Color3 Color3::operator - (Value s) const noexcept { return Color3(r - s, g - s, b - s); } Color3 Color3::operator * (Value s) const noexcept { return Color3(r * s, g * s, b * s); } Color3 Color3::operator / (Value s) const noexcept { return Color3(r / s, g / s, b / s); } Color3 Color3::operator % (Value s) const noexcept { return Color3(r % s, g % s, b % s); } Color3 Color3::operator & (Value s) const noexcept { return Color3(r & s, g & s, b & s); } Color3 Color3::operator | (Value s) const noexcept { return Color3(r | s, g | s, b | s); } Color3 Color3::operator ^ (Value s) const noexcept { return Color3(r ^ s, g ^ s, b ^ s); } Color3 Color3::operator << (Value s) const noexcept { return Color3(r << s, g << s, b << s); } Color3 Color3::operator >> (Value s) const noexcept { return Color3(r >> s, g >> s, b >> s); } // ------------------------------------------------------------------------------------------------ Color3 Color3::operator + () const noexcept { return Color3(r, g, b); } Color3 Color3::operator - () const noexcept { return Color3(0, 0, 0); } // ------------------------------------------------------------------------------------------------ Color3 Color3::operator ~ () const noexcept { return Color3(~r, ~g, ~b); } // ------------------------------------------------------------------------------------------------ bool Color3::operator == (const Color3 & c) const noexcept { return (r == c.r) && (g == c.g) && (b == c.b); } bool Color3::operator != (const Color3 & c) const noexcept { return (r != c.r) && (g != c.g) && (b != c.b); } bool Color3::operator < (const Color3 & c) const noexcept { return (r < c.r) && (g < c.g) && (b < c.b); } bool Color3::operator > (const Color3 & c) const noexcept { return (r > c.r) && (g > c.g) && (b > c.b); } bool Color3::operator <= (const Color3 & c) const noexcept { return (r <= c.r) && (g <= c.g) && (b <= c.b); } bool Color3::operator >= (const Color3 & c) const noexcept { return (r >= c.r) && (g >= c.g) && (b >= c.b); } // ------------------------------------------------------------------------------------------------ SQInteger Color3::Cmp(const Color3 & c) const noexcept { return *this == c ? 0 : (*this > c ? 1 : -1); } // ------------------------------------------------------------------------------------------------ const SQChar * Color3::ToString() const noexcept { return ToStringF("%u,%u,%u", r, g, b); } // ------------------------------------------------------------------------------------------------ void Color3::Set(Value ns) noexcept { r = ns; g = ns; b = ns; } void Color3::Set(Value nr, Value ng, Value nb) noexcept { r = nr; g = ng; b = nb; } // ------------------------------------------------------------------------------------------------ void Color3::Set(const Color3 & c) noexcept { r = c.r; g = c.g; b = c.b; } void Color3::Set(const Color4 & c) noexcept { r = c.r; g = c.g; b = c.b; } // ------------------------------------------------------------------------------------------------ void Color3::Set(const SQChar * str, SQChar delim) noexcept { Set(GetColor3(str, delim)); } // ------------------------------------------------------------------------------------------------ void Color3::SetCol(const SQChar * name) noexcept { Set(GetColor(name)); } // ------------------------------------------------------------------------------------------------ SQUint32 Color3::GetRGB() const noexcept { return static_cast(r << 16 | g << 8 | b); } void Color3::SetRGB(SQUint32 p) noexcept { r = static_cast((p >> 16) & 0xFF); g = static_cast((p >> 8) & 0xFF); b = static_cast((p) & 0xFF); } // ------------------------------------------------------------------------------------------------ SQUint32 Color3::GetRGBA() const noexcept { return static_cast(r << 24 | g << 16 | b << 8 | 0x00); } void Color3::SetRGBA(SQUint32 p) noexcept { r = static_cast((p >> 24) & 0xFF); g = static_cast((p >> 16) & 0xFF); b = static_cast((p >> 8) & 0xFF); } // ------------------------------------------------------------------------------------------------ SQUint32 Color3::GetARGB() const noexcept { return static_cast(0x00 << 24 | r << 16 | g << 8 | b); } void Color3::SetARGB(SQUint32 p) noexcept { r = static_cast((p >> 16) & 0xFF); g = static_cast((p >> 8) & 0xFF); b = static_cast((p) & 0xFF); } // ------------------------------------------------------------------------------------------------ void Color3::Generate() noexcept { r = RandomVal::Get(); g = RandomVal::Get(); b = RandomVal::Get(); } void Color3::Generate(Value min, Value max) noexcept { if (max < min) { LogErr("max value is lower than min value"); } else { r = RandomVal::Get(min, max); g = RandomVal::Get(min, max); b = RandomVal::Get(min, max); } } void Color3::Generate(Value rmin, Value rmax, Value gmin, Value gmax, Value bmin, Value bmax) noexcept { if (rmax < rmin || gmax < gmin || bmax < bmin) { LogErr("max value is lower than min value"); } else { r = RandomVal::Get(rmin, rmax); g = RandomVal::Get(gmin, gmax); b = RandomVal::Get(bmin, bmax); } } // ------------------------------------------------------------------------------------------------ void Color3::Random() noexcept { Set(GetRandomColor()); } // ------------------------------------------------------------------------------------------------ void Color3::Inverse() noexcept { r = static_cast(~r); g = static_cast(~g); b = static_cast(~b); } // ================================================================================================ bool Register_Color3(HSQUIRRELVM vm) { LogDbg("Beginning registration of type"); typedef Color3::Value Val; Sqrat::RootTable(vm).Bind(_SC("Color3"), Sqrat::Class(vm, _SC("Color3")) .Ctor() .Ctor() .Ctor() .Ctor() .SetStaticValue(_SC("delim"), &Color3::Delim) .Var(_SC("r"), &Color3::r) .Var(_SC("g"), &Color3::g) .Var(_SC("b"), &Color3::b) .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) .Func(_SC("_tostring"), &Color3::ToString) .Func(_SC("_cmp"), &Color3::Cmp) .Func(_SC("_add"), &Color3::operator +) .Func(_SC("_sub"), &Color3::operator -) .Func(_SC("_mul"), &Color3::operator *) .Func(_SC("_div"), &Color3::operator /) .Func(_SC("_modulo"), &Color3::operator %) .Func(_SC("_unm"), &Color3::operator -) .Overload(_SC("set"), &Color3::Set) .Overload(_SC("set"), &Color3::Set) .Overload(_SC("set_col3"), &Color3::Set) .Overload(_SC("set_col4"), &Color3::Set) .Overload(_SC("set_str"), &Color3::Set) .Overload(_SC("generate"), &Color3::Generate) .Overload(_SC("generate"), &Color3::Generate) .Overload(_SC("generate"), &Color3::Generate) .Func(_SC("clear"), &Color3::Clear) .Func(_SC("random"), &Color3::Random) .Func(_SC("inverse"), &Color3::Inverse) .Func(_SC("opAddAssign"), &Color3::operator +=) .Func(_SC("opSubAssign"), &Color3::operator -=) .Func(_SC("opMulAssign"), &Color3::operator *=) .Func(_SC("opDivAssign"), &Color3::operator /=) .Func(_SC("opModAssign"), &Color3::operator %=) .Func(_SC("opAndAssign"), &Color3::operator &=) .Func(_SC("opOrAssign"), &Color3::operator |=) .Func(_SC("opXorAssign"), &Color3::operator ^=) .Func(_SC("opShlAssign"), &Color3::operator <<=) .Func(_SC("opShrAssign"), &Color3::operator >>=) .Func(_SC("opAddAssignS"), &Color3::operator +=) .Func(_SC("opSubAssignS"), &Color3::operator -=) .Func(_SC("opMulAssignS"), &Color3::operator *=) .Func(_SC("opDivAssignS"), &Color3::operator /=) .Func(_SC("opModAssignS"), &Color3::operator %=) .Func(_SC("opAndAssignS"), &Color3::operator &=) .Func(_SC("opOrAssignS"), &Color3::operator |=) .Func(_SC("opXorAssignS"), &Color3::operator ^=) .Func(_SC("opShlAssignS"), &Color3::operator <<=) .Func(_SC("opShrAssignS"), &Color3::operator >>=) .Func(_SC("opPreInc"), &Color3::operator ++) .Func(_SC("opPreDec"), &Color3::operator --) .Func(_SC("opPostInc"), &Color3::operator ++) .Func(_SC("opPostDec"), &Color3::operator --) .Func(_SC("opAdd"), &Color3::operator +) .Func(_SC("opSub"), &Color3::operator -) .Func(_SC("opMul"), &Color3::operator *) .Func(_SC("opDiv"), &Color3::operator /) .Func(_SC("opMod"), &Color3::operator %) .Func(_SC("opAnd"), &Color3::operator &) .Func(_SC("opOr"), &Color3::operator |) .Func(_SC("opShl"), &Color3::operator ^) .Func(_SC("opShl"), &Color3::operator <<) .Func(_SC("opShr"), &Color3::operator >>) .Func(_SC("opAddS"), &Color3::operator +) .Func(_SC("opSubS"), &Color3::operator -) .Func(_SC("opMulS"), &Color3::operator *) .Func(_SC("opDivS"), &Color3::operator /) .Func(_SC("opModS"), &Color3::operator %) .Func(_SC("opAndS"), &Color3::operator &) .Func(_SC("opOrS"), &Color3::operator |) .Func(_SC("opShlS"), &Color3::operator ^) .Func(_SC("opShlS"), &Color3::operator <<) .Func(_SC("opShrS"), &Color3::operator >>) .Func(_SC("opUnPlus"), &Color3::operator +) .Func(_SC("opUnMinus"), &Color3::operator -) .Func(_SC("opCom"), &Color3::operator ~) .Func(_SC("opEqual"), &Color3::operator ==) .Func(_SC("opNotEqual"), &Color3::operator !=) .Func(_SC("opLessThan"), &Color3::operator <) .Func(_SC("opGreaterThan"), &Color3::operator >) .Func(_SC("opLessEqual"), &Color3::operator <=) .Func(_SC("opGreaterEqual"), &Color3::operator >=) ); LogDbg("Registration of type was successful"); return true; } } // Namespace:: SqMod