Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move color types to math/Color.h #1741

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
670 changes: 1 addition & 669 deletions core/base/Types.cpp

Large diffs are not rendered by default.

235 changes: 0 additions & 235 deletions core/base/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,241 +43,6 @@ THE SOFTWARE.

NS_AX_BEGIN

struct Color4B;
struct Color4F;
struct HSV;

/**
* RGB color composed of bytes 3 bytes.
* @since v3.0
*/
struct AX_DLL Color3B
{
Color3B();
Color3B(uint8_t _r, uint8_t _g, uint8_t _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) const { return (*this == other); }

uint8_t r = 0;
uint8_t g = 0;
uint8_t b = 0;

static const Color3B WHITE;
static const Color3B YELLOW;
static const Color3B BLUE;
static const Color3B GREEN;
static const Color3B RED;
static const Color3B MAGENTA;
static const Color3B BLACK;
static const Color3B ORANGE;
static const Color3B GRAY;
};

/**
* RGBA color composed of 4 bytes.
* @since v3.0
*/
struct AX_DLL Color4B
{
Color4B();
Color4B(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a);
explicit Color4B(const Color3B& color, uint8_t _a = 255);
Color4B(const Color4F& color);

inline void set(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a)
{
r = _r;
g = _g;
b = _b;
a = _a;
}

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;

uint8_t r = 0;
uint8_t g = 0;
uint8_t b = 0;
uint8_t a = 0;

static const Color4B WHITE;
static const Color4B YELLOW;
static const Color4B BLUE;
static const Color4B GREEN;
static const Color4B RED;
static const Color4B MAGENTA;
static const Color4B BLACK;
static const Color4B ORANGE;
static const Color4B GRAY;
static const Color4B AX_TRANSPARENT; // TRANSPARENT is defined on wingdi.h /*Background Modes*/
};

/**
* RGBA color composed of 4 floats.
* @since v3.0
*/
struct AX_DLL Color4F
{
Color4F();
Color4F(float _r, float _g, float _b, float _a);
explicit Color4F(const Color3B& color, float _a = 1.0f);
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) const { return (*this == other); }

float r = 0.f;
float g = 0.f;
float b = 0.f;
float a = 0.f;

static const Color4F WHITE;
static const Color4F YELLOW;
static const Color4F BLUE;
static const Color4F GREEN;
static const Color4F RED;
static const Color4F MAGENTA;
static const Color4F BLACK;
static const Color4F ORANGE;
static const Color4F GRAY;
static const Color4F AX_TRANSPARENT; // TRANSPARENT is defined on wingdi.h /*Background Modes*/
};

Color4F& operator+=(Color4F& lhs, const Color4F& rhs);
Color4F operator+(Color4F lhs, const Color4F& rhs);

Color4F& operator-=(Color4F& lhs, const Color4F& rhs);
Color4F operator-(Color4F lhs, const Color4F& rhs);

Color4F& operator*=(Color4F& lhs, const Color4F& rhs);
Color4F operator*(Color4F lhs, const Color4F& rhs);
Color4F& operator*=(Color4F& lhs, float rhs);
Color4F operator*(Color4F lhs, float rhs);

Color4F& operator/=(Color4F& lhs, const Color4F& rhs);
Color4F operator/(Color4F lhs, const Color4F& rhs);
Color4F& operator/=(Color4F& lhs, float rhs);
Color4F operator/(Color4F lhs, float rhs);

/**
* Hue Saturation Value color space composed of 4 floats.
* @since axmol-1.0.0b7
*
* Implementation source: https://gist.github.com/fairlight1337/4935ae72bcbcc1ba5c72
*/
struct AX_DLL HSV
{
HSV();
HSV(float _h, float _s, float _v, float _a = 1.0F);

explicit HSV(const Color3B& c);
explicit HSV(const Color4B& c);
explicit HSV(const Color4F& c);

bool operator==(const HSV& right) const;
bool operator!=(const HSV& right) const;

bool equals(const HSV& other) const { return (*this == other); }

void fromRgba(const Color4F& rgba);
Color4F toRgba() const;

Color3B toColor3B() const;
Color4B toColor4B() const;
Color4F toColor4F() const;

float h = 0.f;
float s = 0.f;
float v = 0.f;
float a = 0.f;
};

HSV& operator+=(HSV& lhs, const HSV& rhs);
HSV operator+(HSV lhs, const HSV& rhs);

HSV& operator-=(HSV& lhs, const HSV& rhs);
HSV operator-(HSV lhs, const HSV& rhs);

HSV& operator*=(HSV& lhs, const HSV& rhs);
HSV operator*(HSV lhs, const HSV& rhs);
HSV& operator*=(HSV& lhs, float rhs);
HSV operator*(HSV lhs, float rhs);

HSV& operator/=(HSV& lhs, const HSV& rhs);
HSV operator/(HSV lhs, const HSV& rhs);
HSV& operator/=(HSV& lhs, float rhs);
HSV operator/(HSV lhs, float rhs);

/**
* Hue Saturation Luminance color space composed of 4 floats.
* @since axmol-1.0.0b7
*
* Implementation source: https://gist.github.com/ciembor/1494530
*/
struct AX_DLL HSL
{
HSL();
HSL(float _h, float _s, float _l, float _a = 1.0F);

explicit HSL(const Color3B& c);
explicit HSL(const Color4B& c);
explicit HSL(const Color4F& c);

bool operator==(const HSL& right) const;
bool operator!=(const HSL& right) const;

bool equals(const HSL& other) const { return (*this == other); }

void fromRgba(const Color4F& rgba);
Color4F toRgba() const;

static float hue2rgb(float p, float q, float t);

Color3B toColor3B() const;
Color4B toColor4B() const;
Color4F toColor4F() const;

float h = 0.f;
float s = 0.f;
float l = 0.f;
float a = 0.f;
};

HSL& operator+=(HSL& lhs, const HSL& rhs);
HSL operator+(HSL lhs, const HSL& rhs);

HSL& operator-=(HSL& lhs, const HSL& rhs);
HSL operator-(HSL lhs, const HSL& rhs);

HSL& operator*=(HSL& lhs, const HSL& rhs);
HSL operator*(HSL lhs, const HSL& rhs);
HSL& operator*=(HSL& lhs, float rhs);
HSL operator*(HSL lhs, float rhs);

HSL& operator/=(HSL& lhs, const HSL& rhs);
HSL operator/(HSL lhs, const HSL& rhs);
HSL& operator/=(HSL& lhs, float rhs);
HSL operator/(HSL lhs, float rhs);

/** @struct Tex2F
* A TEXCOORD composed of 2 floats: u, v
* @since v3.0
Expand Down
2 changes: 2 additions & 0 deletions core/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(_AX_MATH_HEADER
math/Math.h
math/Rect.h
math/FastRNG.h
math/Color.h
)

set(_AX_MATH_SRC
Expand All @@ -25,4 +26,5 @@ set(_AX_MATH_SRC
math/Vec3.cpp
math/Vec4.cpp
math/Rect.cpp
math/Color.cpp
)
Loading
Loading