summaryrefslogtreecommitdiffstats
path: root/src/Color.cpp
diff options
context:
space:
mode:
authorSamuel Barney <samjbarney@gmail.com>2015-07-14 02:15:37 +0200
committerSamuel Barney <samjbarney@gmail.com>2015-07-15 22:05:36 +0200
commit561296f2699bcfff93d22b8a67182308998cfb31 (patch)
tree7e0c13beb4b3933923d57c5755b82c76da1a9db9 /src/Color.cpp
parentMerge pull request #2347 from SamJBarney/ClampFix (diff)
downloadcuberite-561296f2699bcfff93d22b8a67182308998cfb31.tar
cuberite-561296f2699bcfff93d22b8a67182308998cfb31.tar.gz
cuberite-561296f2699bcfff93d22b8a67182308998cfb31.tar.bz2
cuberite-561296f2699bcfff93d22b8a67182308998cfb31.tar.lz
cuberite-561296f2699bcfff93d22b8a67182308998cfb31.tar.xz
cuberite-561296f2699bcfff93d22b8a67182308998cfb31.tar.zst
cuberite-561296f2699bcfff93d22b8a67182308998cfb31.zip
Diffstat (limited to 'src/Color.cpp')
-rw-r--r--src/Color.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/Color.cpp b/src/Color.cpp
new file mode 100644
index 000000000..f2180e2d9
--- /dev/null
+++ b/src/Color.cpp
@@ -0,0 +1,76 @@
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "Color.h"
+
+
+
+
+
+#define COLOR_RED_BITS 0x00FF0000
+#define COLOR_GREEN_BITS 0x0000FF00
+#define COLOR_BLUE_BITS 0x000000FF
+#define COLOR_RED_OFFSET 16
+#define COLOR_GREEN_OFFSET 8
+
+
+
+
+
+void cColor::SetColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue)
+{
+ m_Color = (static_cast<unsigned int>(a_Red) << COLOR_RED_OFFSET) + (static_cast<unsigned int>(a_Green) << COLOR_GREEN_OFFSET) + (static_cast<unsigned int>(a_Blue));
+}
+
+
+
+
+
+void cColor::SetRed(unsigned char a_Red)
+{
+ m_Color = (static_cast<unsigned int>(a_Red) << COLOR_RED_OFFSET) + ((COLOR_GREEN_BITS | COLOR_BLUE_BITS) & m_Color);
+}
+
+
+
+
+
+void cColor::SetGreen(unsigned char a_Green)
+{
+ m_Color = (static_cast<unsigned int>(a_Green) << COLOR_GREEN_OFFSET) + ((COLOR_RED_BITS | COLOR_BLUE_BITS) & m_Color);
+}
+
+
+
+
+
+void cColor::SetBlue(unsigned char a_Blue)
+{
+ m_Color = static_cast<unsigned int>(a_Blue) + ((COLOR_RED_BITS | COLOR_GREEN_BITS) & m_Color);
+}
+
+
+
+
+
+unsigned char cColor::GetRed() const
+{
+ return (m_Color & COLOR_RED_BITS) >> COLOR_RED_OFFSET;
+}
+
+
+
+
+
+unsigned char cColor::GetGreen() const
+{
+ return (m_Color & COLOR_GREEN_BITS) >> COLOR_GREEN_OFFSET;
+}
+
+
+
+
+
+unsigned char cColor::GetBlue() const
+{
+ return m_Color & COLOR_BLUE_BITS;
+}