diff options
author | rachytski <siarhei.rachytski@gmail.com> | 2012-11-09 17:40:13 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:46:45 +0300 |
commit | bcc94857d7b9f092148dea4a2a9b90c592f43a75 (patch) | |
tree | 7bf4c63e9b28fd0b00dfdcffcada9bb2c637b935 /graphics/color.cpp | |
parent | 771f47410fa67f271cf425a2b1a9a0ed6119b4ea (diff) |
renamed yg into graphics.
Diffstat (limited to 'graphics/color.cpp')
-rw-r--r-- | graphics/color.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/graphics/color.cpp b/graphics/color.cpp new file mode 100644 index 0000000000..b5c543f379 --- /dev/null +++ b/graphics/color.cpp @@ -0,0 +1,88 @@ +#include "color.hpp" + + +namespace graphics +{ + Color::Color(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char a1) + : r(r1), g(g1), b(b1), a(a1) + {} + + Color::Color() : r(0), g(0), b(0), a(0) + {} + + Color::Color(Color const & c) + { + r = c.r; + g = c.g; + b = c.b; + a = c.a; + } + + Color const & Color::operator=(Color const & c) + { + if (&c != this) + { + r = c.r; + g = c.g; + b = c.b; + a = c.a; + } + return *this; + } + + Color const Color::fromXRGB(uint32_t _c, unsigned char _a) + { + return Color( + redFromARGB(_c), + greenFromARGB(_c), + blueFromARGB(_c), + _a); + } + + Color const Color::fromARGB(uint32_t _c) + { + return Color( + redFromARGB(_c), + greenFromARGB(_c), + blueFromARGB(_c), + alphaFromARGB(_c)); + } + + Color const & Color::operator /= (unsigned k) + { + r /= k; + g /= k; + b /= k; + a /= k; + + return *this; + } + + bool operator < (Color const & l, Color const & r) + { + if (l.r != r.r) return l.r < r.r; + if (l.g != r.g) return l.g < r.g; + if (l.b != r.b) return l.b < r.b; + if (l.a != r.a) return l.a < r.a; + return false; + } + + bool operator > (Color const & l, Color const & r) + { + if (l.r != r.r) return l.r > r.r; + if (l.g != r.g) return l.g > r.g; + if (l.b != r.b) return l.b > r.b; + if (l.a != r.a) return l.a > r.a; + return false; + } + + bool operator != (Color const & l, Color const & r) + { + return (l.r != r.r) || (l.g != r.g) || (l.b != r.b) || (l.a != r.a); + } + + bool operator == (Color const & l, Color const & r) + { + return !(l != r); + } +} |