diff options
| author | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
|---|---|---|
| committer | Joe Ludwig <[email protected]> | 2013-06-26 15:22:04 -0700 |
| commit | 39ed87570bdb2f86969d4be821c94b722dc71179 (patch) | |
| tree | abc53757f75f40c80278e87650ea92808274aa59 /mp/src/public/Color.h | |
| download | source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip | |
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/public/Color.h')
| -rw-r--r-- | mp/src/public/Color.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/mp/src/public/Color.h b/mp/src/public/Color.h new file mode 100644 index 00000000..e15725d5 --- /dev/null +++ b/mp/src/public/Color.h @@ -0,0 +1,103 @@ +//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef COLOR_H
+#define COLOR_H
+
+#ifdef _WIN32
+#pragma once
+#endif
+
+//-----------------------------------------------------------------------------
+// Purpose: Basic handler for an rgb set of colors
+// This class is fully inline
+//-----------------------------------------------------------------------------
+class Color
+{
+public:
+ // constructors
+ Color()
+ {
+ *((int *)this) = 0;
+ }
+ Color(int _r,int _g,int _b)
+ {
+ SetColor(_r, _g, _b, 0);
+ }
+ Color(int _r,int _g,int _b,int _a)
+ {
+ SetColor(_r, _g, _b, _a);
+ }
+
+ // set the color
+ // r - red component (0-255)
+ // g - green component (0-255)
+ // b - blue component (0-255)
+ // a - alpha component, controls transparency (0 - transparent, 255 - opaque);
+ void SetColor(int _r, int _g, int _b, int _a = 0)
+ {
+ _color[0] = (unsigned char)_r;
+ _color[1] = (unsigned char)_g;
+ _color[2] = (unsigned char)_b;
+ _color[3] = (unsigned char)_a;
+ }
+
+ void GetColor(int &_r, int &_g, int &_b, int &_a) const
+ {
+ _r = _color[0];
+ _g = _color[1];
+ _b = _color[2];
+ _a = _color[3];
+ }
+
+ void SetRawColor( int color32 )
+ {
+ *((int *)this) = color32;
+ }
+
+ int GetRawColor() const
+ {
+ return *((int *)this);
+ }
+
+ inline int r() const { return _color[0]; }
+ inline int g() const { return _color[1]; }
+ inline int b() const { return _color[2]; }
+ inline int a() const { return _color[3]; }
+
+ unsigned char &operator[](int index)
+ {
+ return _color[index];
+ }
+
+ const unsigned char &operator[](int index) const
+ {
+ return _color[index];
+ }
+
+ bool operator == (const Color &rhs) const
+ {
+ return ( *((int *)this) == *((int *)&rhs) );
+ }
+
+ bool operator != (const Color &rhs) const
+ {
+ return !(operator==(rhs));
+ }
+
+ Color &operator=( const Color &rhs )
+ {
+ SetRawColor( rhs.GetRawColor() );
+ return *this;
+ }
+
+private:
+ unsigned char _color[4];
+};
+
+
+#endif // COLOR_H
|