diff options
author | chai <chaifix@163.com> | 2019-01-12 21:48:33 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-01-12 21:48:33 +0800 |
commit | 8b00d67febf133e89f6a0bfabc41feed555dc4a9 (patch) | |
tree | fe48ef17c250afa40c2588300fcdb5920dba6951 /src/libjin/graphics/color.h | |
parent | a907c39756ef6b368d06643afa491c49a9044a8e (diff) |
*去掉文件前缀je_
Diffstat (limited to 'src/libjin/graphics/color.h')
-rw-r--r-- | src/libjin/graphics/color.h | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/libjin/graphics/color.h b/src/libjin/graphics/color.h new file mode 100644 index 0000000..0f7d6dd --- /dev/null +++ b/src/libjin/graphics/color.h @@ -0,0 +1,119 @@ +/** +* Some color operating here. +*/ +#ifndef __JE_COLOR_H__ +#define __JE_COLOR_H__ +#include "../core/configuration.h" +#if defined(jin_graphics) + +#include "../math/math.h" + +#include "../common/types.h" +#include "../utils/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 |