2022-08-11 18:20:15 +00:00
|
|
|
#ifndef __CCOLOR_HPP__
|
|
|
|
#define __CCOLOR_HPP__
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2022-08-13 12:57:38 +00:00
|
|
|
#include "Kyoto/Basics/CCast.hpp"
|
|
|
|
|
2022-08-11 18:35:12 +00:00
|
|
|
#pragma cpp_extensions on
|
|
|
|
|
2022-08-13 12:57:38 +00:00
|
|
|
class CInputStream;
|
2022-08-11 18:20:15 +00:00
|
|
|
class CColor {
|
|
|
|
public:
|
2022-08-13 12:57:38 +00:00
|
|
|
CColor() {}
|
2022-08-11 18:20:15 +00:00
|
|
|
CColor(u32 col) : mRgba(col) {}
|
2022-08-13 12:57:38 +00:00
|
|
|
CColor(CInputStream& in);
|
|
|
|
CColor(f32 r, f32 g, f32 b, f32 a = 1.f);
|
|
|
|
CColor(u8 r, u8 g, u8 b, u8 a = 255) {
|
|
|
|
mR = r;
|
|
|
|
mG = g;
|
|
|
|
mB = b;
|
|
|
|
mA = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(float r, float g, float b, float a);
|
|
|
|
void Get(float& r, float& g, float& b, float& a) const;
|
|
|
|
void Get(float& r, float& g, float& b) const;
|
|
|
|
static CColor Lerp(const CColor& a, const CColor& b, float t);
|
|
|
|
static u32 Lerp(u32 a, u32 b, float t);
|
|
|
|
static CColor Modulate(const CColor& a, const CColor& b);
|
|
|
|
static CColor Add(const CColor& a, const CColor& b);
|
|
|
|
f32 GetRed() const { return CCast::ToReal32(mR) * (1/255.f); }
|
|
|
|
f32 GetGreen() const { return CCast::ToReal32(mG) * (1/255.f); }
|
|
|
|
f32 GetBlue() const { return CCast::ToReal32(mB) * (1/255.f); }
|
|
|
|
f32 GetAlpha() const { return CCast::ToReal32(mA) * (1/255.f); }
|
|
|
|
u8 GetRedu8() const { return mR; }
|
|
|
|
u8 GetGreenu8() const { return mG; }
|
|
|
|
u8 GetBlueu8() const { return mB; }
|
|
|
|
u8 GetAlphau8() const { return mA; }
|
|
|
|
u16 ToRGB5A3() const;
|
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 {
|
|
|
|
u8 mR;
|
|
|
|
u8 mG;
|
|
|
|
u8 mB;
|
|
|
|
u8 mA;
|
|
|
|
};
|
|
|
|
u32 mRgba;
|
|
|
|
};
|
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
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __CCOLOR_HPP__
|