mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-30 08:47:58 +03:00
Fix GameScriptColor's D3DCOLOR operator and __tostring, and add a converting constructor.
This commit is contained in:
parent
d946f4c118
commit
e834d38522
2 changed files with 16 additions and 3 deletions
|
@ -13,6 +13,7 @@ void GameScriptColor::Register(sol::state* state)
|
||||||
{
|
{
|
||||||
state->new_usertype<GameScriptColor>("Color",
|
state->new_usertype<GameScriptColor>("Color",
|
||||||
sol::constructors<GameScriptColor(byte, byte, byte), GameScriptColor(byte, byte, byte, byte)>(),
|
sol::constructors<GameScriptColor(byte, byte, byte), GameScriptColor(byte, byte, byte, byte)>(),
|
||||||
|
sol::meta_function::to_string, &GameScriptColor::ToString,
|
||||||
|
|
||||||
/// (int) red component
|
/// (int) red component
|
||||||
//@mem r
|
//@mem r
|
||||||
|
@ -63,6 +64,17 @@ GameScriptColor::GameScriptColor(Vector3 const& col) : GameScriptColor{ col.x, c
|
||||||
|
|
||||||
GameScriptColor::GameScriptColor(Vector4 const& col) : GameScriptColor{ col.x, col.y, col.z, col.w } {}
|
GameScriptColor::GameScriptColor(Vector4 const& col) : GameScriptColor{ col.x, col.y, col.z, col.w } {}
|
||||||
|
|
||||||
|
GameScriptColor::GameScriptColor(D3DCOLOR col)
|
||||||
|
{
|
||||||
|
b = col & 0xFF;
|
||||||
|
col >>= 8;
|
||||||
|
g = col & 0xFF;
|
||||||
|
col >>= 8;
|
||||||
|
r = col & 0xFF;
|
||||||
|
col >>= 8;
|
||||||
|
a = col & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
GameScriptColor::operator Vector3() const
|
GameScriptColor::operator Vector3() const
|
||||||
{
|
{
|
||||||
return Vector3{ float(r), float(g), float(b) };
|
return Vector3{ float(r), float(g), float(b) };
|
||||||
|
@ -73,16 +85,16 @@ GameScriptColor::operator Vector4() const
|
||||||
return Vector4{ float(r), float(g), float(b), float(a) };
|
return Vector4{ float(r), float(g), float(b), float(a) };
|
||||||
}
|
}
|
||||||
|
|
||||||
// D3DCOLOR is 32 bits and is layed out as RGBA.
|
// D3DCOLOR is 32 bits and is layed out as ARGB.
|
||||||
GameScriptColor::operator D3DCOLOR() const
|
GameScriptColor::operator D3DCOLOR() const
|
||||||
{
|
{
|
||||||
D3DCOLOR col = a;
|
D3DCOLOR col = a;
|
||||||
col <<= 8;
|
col <<= 8;
|
||||||
col += b;
|
col += r;
|
||||||
col <<= 8;
|
col <<= 8;
|
||||||
col += g;
|
col += g;
|
||||||
col <<= 8;
|
col <<= 8;
|
||||||
col += r;
|
col += b;
|
||||||
|
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
GameScriptColor(byte r, byte g, byte b, byte a);
|
GameScriptColor(byte r, byte g, byte b, byte a);
|
||||||
GameScriptColor(Vector3 const &);
|
GameScriptColor(Vector3 const &);
|
||||||
GameScriptColor(Vector4 const &);
|
GameScriptColor(Vector4 const &);
|
||||||
|
GameScriptColor(D3DCOLOR);
|
||||||
|
|
||||||
operator Vector3() const;
|
operator Vector3() const;
|
||||||
operator Vector4() const;
|
operator Vector4() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue