diff options
Diffstat (limited to 'src/libjin/graphics/je_color.h')
-rw-r--r-- | src/libjin/graphics/je_color.h | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/libjin/graphics/je_color.h b/src/libjin/graphics/je_color.h new file mode 100644 index 0000000..06b8f61 --- /dev/null +++ b/src/libjin/graphics/je_color.h @@ -0,0 +1,119 @@ +/** +* Some color operating here. +*/ +#ifndef __JE_COLOR_H__ +#define __JE_COLOR_H__ +#include "../core/je_configuration.h" +#if defined(jin_graphics) + +#include "../math/je_math.h" + +#include "../common/je_types.h" +#include "../utils/je_endian.h" + +namespace JinEngine +{ + namespace Graphics + { + + typedef uint8 Channel; + + class Color + { + public: + // Built-in colors + static const Color WHITE; + static const Color BLACK; + static const Color RED; + static const Color GREEN; + static const Color BLUE; + static const Color MAGENTA; + static const Color YELLOW; + + static const uint32 RMASK; + static const uint32 GMASK; + static const uint32 BMASK; + static const uint32 AMASK; + + /// + /// Get lerp color with given factor. + /// + /// @param start Start color. + /// @param end End color. + /// @param t Factor of interplation. + /// @return Color after interplation. + /// + static Color lerp(Color start, Color end, float t) + { + t = Math::clamp<float>(t, 0, 1); + Color c; + c.r = Math::lerp(start.r, end.r, t); + c.g = Math::lerp(start.g, end.g, t); + c.b = Math::lerp(start.b, end.b, t); + c.a = Math::lerp(start.a, end.a, t); + return c; + } + + /// + /// + /// + Color() { r = g = b = a = 0; }; + + /// + /// + /// + Color(unsigned char _r + , unsigned char _g + , unsigned char _b + , unsigned char _a = 255) + { + r = _r; + g = _g; + b = _b; + a = _a; + } + + Color(const Color& c) + { + r = c.r; + g = c.g; + b = c.b; + a = c.a; + } + + void set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a) + { + r = _r; + g = _g; + b = _b; + a = _a; + } + + void operator = (const Color& c) + { + r = c.r; + g = c.g; + b = c.b; + a = c.a; + } + + bool operator == (const Color& c) + { + return r == c.r && g == c.g && b == c.b && a == c.a; + } + + bool operator != (const Color& c) + { + return !(r == c.r && g == c.g && b == c.b && a == c.a); + } + + Channel r, g, b, a; + + }; + + } // namespace Graphics +} // namespace JinEngine + +#endif // jin_graphics + +#endif // __JE_COLOR_H__
\ No newline at end of file |