2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CCOLOR
|
|
|
|
#define _CCOLOR
|
2022-08-11 18:20:15 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2022-08-13 12:57:38 +00:00
|
|
|
#include "Kyoto/Basics/CCast.hpp"
|
2022-10-18 23:13:51 +00:00
|
|
|
#include "Kyoto/Math/CMath.hpp"
|
2022-08-13 12:57:38 +00:00
|
|
|
|
2022-09-05 04:00:04 +00:00
|
|
|
#include <dolphin/gx/GXStruct.h>
|
|
|
|
|
2022-08-26 03:46:24 +00:00
|
|
|
#ifdef __MWERKS__
|
2022-08-11 18:35:12 +00:00
|
|
|
#pragma cpp_extensions on
|
2022-08-26 03:46:24 +00:00
|
|
|
#endif
|
2022-08-11 18:35:12 +00:00
|
|
|
|
2022-08-13 12:57:38 +00:00
|
|
|
class CInputStream;
|
2022-08-11 18:20:15 +00:00
|
|
|
class CColor {
|
|
|
|
public:
|
2022-10-18 23:13:51 +00:00
|
|
|
CColor() { Set(255, 0, 255); }
|
2023-10-19 17:39:17 +00:00
|
|
|
CColor(const uint col) { Set(col); }
|
2022-08-13 12:57:38 +00:00
|
|
|
CColor(CInputStream& in);
|
2023-10-19 17:39:17 +00:00
|
|
|
CColor(const float r, const float g, const float b, const float a = 1.f);
|
|
|
|
CColor(const uchar r, const uchar g, const uchar b, const uchar a = 255) {
|
2022-08-13 12:57:38 +00:00
|
|
|
mR = r;
|
|
|
|
mG = g;
|
|
|
|
mB = b;
|
|
|
|
mA = a;
|
|
|
|
}
|
|
|
|
|
2023-10-19 17:39:17 +00:00
|
|
|
void Set(const float r, const float g, const float b, const float a);
|
2022-10-18 23:13:51 +00:00
|
|
|
void Set(uchar r, uchar g, uchar b, uchar a = 255) {
|
|
|
|
mR = r;
|
|
|
|
mG = g;
|
|
|
|
mB = b;
|
|
|
|
mA = a;
|
|
|
|
}
|
2022-11-03 17:09:58 +00:00
|
|
|
void Set(uint col) { mRgba = col; }
|
2022-08-13 12:57:38 +00:00
|
|
|
void Get(float& r, float& g, float& b, float& a) const;
|
|
|
|
void Get(float& r, float& g, float& b) const;
|
2022-11-03 10:51:20 +00:00
|
|
|
// TODO check. Maybe this calls SetAlpha(uchar)?
|
2022-11-02 01:21:07 +00:00
|
|
|
void SetAlpha(float a) { mA = CCast::ToUint8(a * 255.f); }
|
|
|
|
void SetAlpha(uchar a) { mRgba = (mRgba & ~0xff) | a; }
|
2022-10-20 12:45:54 +00:00
|
|
|
|
2022-08-13 12:57:38 +00:00
|
|
|
static CColor Lerp(const CColor& a, const CColor& b, float t);
|
2022-09-05 04:01:13 +00:00
|
|
|
static uint Lerp(uint a, uint b, float t);
|
2022-08-13 12:57:38 +00:00
|
|
|
static CColor Modulate(const CColor& a, const CColor& b);
|
|
|
|
static CColor Add(const CColor& a, const CColor& b);
|
2022-10-18 02:05:27 +00:00
|
|
|
float GetRed() const { return CCast::ToReal32(mR) * (1.f / 255.f); }
|
|
|
|
float GetGreen() const { return CCast::ToReal32(mG) * (1.f / 255.f); }
|
|
|
|
float GetBlue() const { return CCast::ToReal32(mB) * (1.f / 255.f); }
|
|
|
|
float GetAlpha() const { return CCast::ToReal32(mA) * (1.f / 255.f); }
|
2022-10-09 05:44:19 +00:00
|
|
|
uchar GetRedu8() const { return mR; }
|
|
|
|
uchar GetGreenu8() const { return mG; }
|
|
|
|
uchar GetBlueu8() const { return mB; }
|
|
|
|
uchar GetAlphau8() const { return mA; }
|
2022-10-09 05:37:23 +00:00
|
|
|
ushort ToRGB5A3() const;
|
2022-11-03 17:09:58 +00:00
|
|
|
uint GetColor_u32() const { return mRgba; }
|
|
|
|
const GXColor& GetGXColor() const { return *reinterpret_cast< const GXColor* >(this); }
|
|
|
|
|
|
|
|
CColor WithAlphaOf(float a) const { return CColor((mRgba & ~0xff) | CCast::ToUint8(a * 255.f)); }
|
|
|
|
CColor WithAlphaModulatedBy(float a) const {
|
|
|
|
return CColor((mRgba & ~0xff) | CCast::ToUint8(a * static_cast< float >(mA)));
|
|
|
|
}
|
|
|
|
|
2022-11-04 05:39:14 +00:00
|
|
|
bool operator==(const CColor& other) const { return mRgba == other.mRgba; }
|
2022-11-04 05:25:39 +00:00
|
|
|
|
2022-11-02 01:21:07 +00:00
|
|
|
// TODO check
|
|
|
|
static GXColor ToGX(uint c) { return *reinterpret_cast< const GXColor* >(&c); }
|
2022-08-11 18:20:15 +00:00
|
|
|
|
|
|
|
static const CColor& Black();
|
|
|
|
static const CColor& White();
|
|
|
|
static const CColor& Grey();
|
|
|
|
static const CColor& Red();
|
2022-08-11 18:35:12 +00:00
|
|
|
static const CColor& Green();
|
2022-08-11 18:20:15 +00:00
|
|
|
static const CColor& Blue();
|
|
|
|
static const CColor& Yellow();
|
2022-08-11 18:35:12 +00:00
|
|
|
static const CColor& Purple();
|
2022-08-11 18:20:15 +00:00
|
|
|
static const CColor& Orange();
|
2022-08-11 18:35:12 +00:00
|
|
|
|
2022-08-11 18:20:15 +00:00
|
|
|
private:
|
|
|
|
union {
|
|
|
|
struct {
|
2022-10-09 05:37:23 +00:00
|
|
|
uchar mR;
|
|
|
|
uchar mG;
|
|
|
|
uchar mB;
|
|
|
|
uchar mA;
|
2022-08-11 18:20:15 +00:00
|
|
|
};
|
2022-09-05 04:01:13 +00:00
|
|
|
uint mRgba;
|
2022-08-11 18:20:15 +00:00
|
|
|
};
|
2022-08-11 18:35:12 +00:00
|
|
|
|
|
|
|
static const CColor sBlackColor;
|
|
|
|
static const CColor sWhiteColor;
|
|
|
|
static const CColor sGreyColor;
|
|
|
|
static const CColor sRedColor;
|
|
|
|
static const CColor sGreenColor;
|
|
|
|
static const CColor sBlueColor;
|
|
|
|
static const CColor sYellowColor;
|
|
|
|
static const CColor sPurpleColor;
|
|
|
|
static const CColor sOrangeColor;
|
2022-08-11 18:20:15 +00:00
|
|
|
};
|
2022-09-18 17:51:07 +00:00
|
|
|
CHECK_SIZEOF(CColor, 0x4)
|
2022-08-11 18:20:15 +00:00
|
|
|
|
2022-09-05 04:00:04 +00:00
|
|
|
#ifdef __MWERKS__
|
|
|
|
#pragma cpp_extensions off
|
|
|
|
#endif
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CCOLOR
|