diff options
author | chai <chaifix@163.com> | 2020-02-11 11:29:07 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-02-11 11:29:07 +0800 |
commit | 160e1299ef3d95f8e8c48706d7f61dd3dc6c6b60 (patch) | |
tree | abe5ae5242d9cc6caf6edf103e662c44e978fca0 /src/libjin/graphics/color.h | |
parent | e095043485d1d298571af6d9eca7f0db9009ea7a (diff) |
Diffstat (limited to 'src/libjin/graphics/color.h')
-rw-r--r-- | src/libjin/graphics/color.h | 198 |
1 files changed, 99 insertions, 99 deletions
diff --git a/src/libjin/graphics/color.h b/src/libjin/graphics/color.h index 0f7d6dd..f10d918 100644 --- a/src/libjin/graphics/color.h +++ b/src/libjin/graphics/color.h @@ -13,105 +13,105 @@ 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 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 |