You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
2.3 KiB
124 lines
2.3 KiB
//========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
|
|
//
|
|
// Purpose:
|
|
//
|
|
// $NoKeywords: $
|
|
//=============================================================================//
|
|
|
|
#ifndef COLOR_H
|
|
#define COLOR_H
|
|
|
|
#ifdef _WIN32
|
|
#pragma once
|
|
#endif
|
|
|
|
#include "tier0/basetypes.h"
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// 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;
|
|
}
|
|
|
|
Color &operator=( const color32 &rhs )
|
|
{
|
|
_color[0] = rhs.r;
|
|
_color[1] = rhs.g;
|
|
_color[2] = rhs.b;
|
|
_color[3] = rhs.a;
|
|
return *this;
|
|
}
|
|
|
|
color32 ToColor32() const
|
|
{
|
|
color32 newColor;
|
|
newColor.r = _color[0];
|
|
newColor.g = _color[1];
|
|
newColor.b = _color[2];
|
|
newColor.a = _color[3];
|
|
return newColor;
|
|
}
|
|
|
|
private:
|
|
unsigned char _color[4];
|
|
};
|
|
|
|
|
|
#endif // COLOR_H
|