mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-09 03:58:19 +03:00
Make new colour class, RGBAColor8Byte (the name is a work-in-progress, I promise), and move some GameScriptColor stuff into it.
This commit is contained in:
parent
2a9175f5fb
commit
0834bf805f
6 changed files with 178 additions and 69 deletions
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#include "Specific/RGBAColor8Byte.h"
|
||||
|
||||
typedef DWORD D3DCOLOR;
|
||||
|
||||
|
@ -9,12 +10,8 @@ namespace sol {
|
|||
|
||||
class GameScriptColor {
|
||||
public:
|
||||
byte r{ 0 };
|
||||
byte g{ 0 };
|
||||
byte b{ 0 };
|
||||
byte a{ 255 };
|
||||
|
||||
GameScriptColor(byte r, byte g, byte b);
|
||||
GameScriptColor(RGBAColor8Byte col);
|
||||
GameScriptColor(byte r, byte g, byte b, byte a);
|
||||
GameScriptColor(Vector3 const &);
|
||||
GameScriptColor(Vector4 const &);
|
||||
|
@ -23,17 +20,20 @@ public:
|
|||
operator Vector3() const;
|
||||
operator Vector4() const;
|
||||
operator D3DCOLOR() const;
|
||||
operator RGBAColor8Byte() const;
|
||||
|
||||
byte GetR() const;
|
||||
void SetR(byte v);
|
||||
byte GetG() const;
|
||||
void SetG(byte v);
|
||||
byte GetB() const;
|
||||
void SetB(byte v);
|
||||
byte GetA() const;
|
||||
void SetA(byte v);
|
||||
byte GetR() const;
|
||||
void SetR(byte v);
|
||||
byte GetG() const;
|
||||
void SetG(byte v);
|
||||
byte GetB() const;
|
||||
void SetB(byte v);
|
||||
byte GetA() const;
|
||||
void SetA(byte v);
|
||||
|
||||
std::string ToString() const;
|
||||
|
||||
static void Register(sol::state* state);
|
||||
private:
|
||||
RGBAColor8Byte m_color;
|
||||
};
|
|
@ -10,23 +10,6 @@ Components are specified in bytes; all values are clamped to [0, 255].
|
|||
@pragma nostrip
|
||||
*/
|
||||
|
||||
static byte FloatComponentToByte(float v)
|
||||
{
|
||||
//todo look into what these actually do AND TEST THEM
|
||||
//todo like, see if these are actually not undefined or some shit
|
||||
auto lval = std::lroundf((v / 2.0f) * 255.0f);
|
||||
return static_cast<byte>(lval);
|
||||
}
|
||||
|
||||
static float ByteComponentToFloat(byte b)
|
||||
{
|
||||
//todo look into what these actually do AND TEST THEM
|
||||
//todo like, see if these are actually not undefined or some shit
|
||||
float f = b;
|
||||
f = (f / 255.0f) * 2.0f;
|
||||
return f;
|
||||
}
|
||||
|
||||
void GameScriptColor::Register(sol::state* state)
|
||||
{
|
||||
state->new_usertype<GameScriptColor>("Color",
|
||||
|
@ -58,11 +41,9 @@ void GameScriptColor::Register(sol::state* state)
|
|||
@return A Color object.
|
||||
@function Color.new
|
||||
*/
|
||||
GameScriptColor::GameScriptColor(byte r, byte g, byte b)
|
||||
GameScriptColor::GameScriptColor(byte r, byte g, byte b) :
|
||||
m_color(r, g, b)
|
||||
{
|
||||
SetR(r);
|
||||
SetG(g);
|
||||
SetB(b);
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -79,94 +60,75 @@ GameScriptColor::GameScriptColor(byte r, byte g, byte b, byte a) : GameScriptCol
|
|||
}
|
||||
|
||||
GameScriptColor::GameScriptColor(Vector3 const& col) :
|
||||
r(FloatComponentToByte(col.x)),
|
||||
g(FloatComponentToByte(col.y)),
|
||||
b(FloatComponentToByte(col.z))
|
||||
m_color(col)
|
||||
{
|
||||
}
|
||||
|
||||
GameScriptColor::GameScriptColor(Vector4 const& col) :
|
||||
r(FloatComponentToByte(col.x)),
|
||||
g(FloatComponentToByte(col.y)),
|
||||
b(FloatComponentToByte(col.z)),
|
||||
a(FloatComponentToByte(col.w))
|
||||
m_color(col)
|
||||
{
|
||||
}
|
||||
|
||||
GameScriptColor::GameScriptColor(D3DCOLOR col)
|
||||
GameScriptColor::GameScriptColor(D3DCOLOR col) :
|
||||
m_color(col)
|
||||
{
|
||||
b = col & 0xFF;
|
||||
col >>= 8;
|
||||
g = col & 0xFF;
|
||||
col >>= 8;
|
||||
r = col & 0xFF;
|
||||
col >>= 8;
|
||||
a = col & 0xFF;
|
||||
}
|
||||
|
||||
GameScriptColor::operator Vector3() const
|
||||
{
|
||||
return Vector3{ ByteComponentToFloat(r), ByteComponentToFloat(g), ByteComponentToFloat(b) };
|
||||
return m_color;
|
||||
}
|
||||
|
||||
GameScriptColor::operator Vector4() const
|
||||
{
|
||||
return Vector4{ ByteComponentToFloat(r), ByteComponentToFloat(g), ByteComponentToFloat(b), ByteComponentToFloat(a) };
|
||||
return m_color;
|
||||
}
|
||||
|
||||
// D3DCOLOR is 32 bits and is layed out as ARGB.
|
||||
GameScriptColor::operator D3DCOLOR() const
|
||||
{
|
||||
D3DCOLOR col = a;
|
||||
col <<= 8;
|
||||
col += r;
|
||||
col <<= 8;
|
||||
col += g;
|
||||
col <<= 8;
|
||||
col += b;
|
||||
|
||||
return col;
|
||||
return m_color;
|
||||
}
|
||||
|
||||
|
||||
byte GameScriptColor::GetR() const
|
||||
{
|
||||
return r;
|
||||
return m_color.GetR();
|
||||
}
|
||||
|
||||
void GameScriptColor::SetR(byte v)
|
||||
{
|
||||
r = std::clamp<byte>(v, 0, 255);
|
||||
m_color.SetR(v);
|
||||
}
|
||||
|
||||
byte GameScriptColor::GetG() const
|
||||
{
|
||||
return g;
|
||||
return m_color.GetG();
|
||||
}
|
||||
|
||||
void GameScriptColor::SetG(byte v)
|
||||
{
|
||||
g = std::clamp<byte>(v, 0, 255);
|
||||
m_color.SetG(v);
|
||||
}
|
||||
|
||||
byte GameScriptColor::GetB() const
|
||||
{
|
||||
return b;
|
||||
return m_color.GetB();
|
||||
}
|
||||
|
||||
void GameScriptColor::SetB(byte v)
|
||||
{
|
||||
b = std::clamp<byte>(v, 0, 255);
|
||||
m_color.SetB(v);
|
||||
}
|
||||
|
||||
byte GameScriptColor::GetA() const
|
||||
{
|
||||
return a;
|
||||
return m_color.GetA();
|
||||
}
|
||||
|
||||
void GameScriptColor::SetA(byte v)
|
||||
{
|
||||
a = std::clamp<byte>(v, 0, 255);
|
||||
m_color.SetA(v);
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -176,5 +138,5 @@ void GameScriptColor::SetA(byte v)
|
|||
*/
|
||||
std::string GameScriptColor::ToString() const
|
||||
{
|
||||
return "{" + std::to_string(r) + ", " + std::to_string(g) + ", " + std::to_string(b) + ", " + std::to_string(a) + "}";
|
||||
return "{" + std::to_string(GetR()) + ", " + std::to_string(GetG()) + ", " + std::to_string(GetB()) + ", " + std::to_string(GetA()) + "}";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue