Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cColorf.h
Go to the documentation of this file.
1 //
6 //
7 
8 #ifndef _INC_cColorf_H
9 #define _INC_cColorf_H
10 #ifndef NO_PRAGMA_ONCE
11 #pragma once
12 #endif
13 
14 #include "cColorRef.h"
15 #include "../Math/cVecT.h"
16 #include "../Math/MathDX.h"
18 
19 namespace GrayLib
20 {
22 
23  class GRAYLIB_LINK cColorf : public cVecT4<float>
24  {
29 
30  typedef cVecT4<float> SUPER_t;
31 
32  public:
33  cColorf() noexcept
34  {}
35  cColorf(D3DCOLOR c) noexcept // assume D3DCOLOR format
36  : cVecT4<float>(cColorDX::GetR(c) / 255.0f, cColorDX::GetG(c) / 255.0f, cColorDX::GetB(c) / 255.0f, cColorDX::GetA(c) / 255.0f)
37  {}
38  cColorf(D3DCOLOR_TYPE_ c) noexcept
39  : cVecT4<float>(cColorDX::GetR(c) / 255.0f, cColorDX::GetG(c) / 255.0f, cColorDX::GetB(c) / 255.0f, cColorDX::GetA(c) / 255.0f)
40  {}
41  cColorf(const SUPER_t& v) noexcept
42  : cVecT4<float>(v)
43  {}
44  explicit cColorf(const float* f) noexcept
45  : cVecT4<float>(f)
46  {}
47  explicit cColorf(const cVecT3<float>& v, float a) noexcept
48  : cVecT4<float>(v, a)
49  {}
50  explicit cColorf(float r, float g, float b, float a = 1.0f) noexcept
51  : cVecT4<float>(r, g, b, a)
52  {}
53 
54 #ifdef D3DCOLORVALUE_DEFINED
55  explicit cColorf(const D3DCOLORVALUE& v ) noexcept
56  : cVecT4<float>(v.r, v.g, v.b, v.a)
57  {}
58 #endif
59 
60 #if defined(USE_DX) || defined(USE_DXM)
61  // Cast directly to the DirectX equiv type D3DXCOLOR.
62  cColorf( const XMFLOAT4& v ) noexcept
63  : cVecT4<float>( *(const SUPER_t*) &v )
64  {}
65  inline operator XMFLOAT4*() noexcept
66  { return (XMFLOAT4*) this; }
67  inline operator const XMFLOAT4*() const noexcept
68  { return (const XMFLOAT4*) this; }
69 #endif
70 
71 #ifdef USE_DXM
72  inline void Set(const XMVECTOR& v) noexcept
73  {
74  ::XMStoreFloat4((XMFLOAT4*)this, v);
75  }
76  inline operator XMVECTOR () const noexcept
77  {
78  return ::XMLoadFloat4((const XMFLOAT4*)this);
79  }
80 #endif
81 
82  COLORREF get_ColorRef() const noexcept
83  {
85  return RGB((BYTE)(r * 255), (BYTE)(g * 255), (BYTE)(b * 255));
86  }
87  D3DCOLOR get_ColorDX() const noexcept
88  {
90  return D3DCOLOR_ARGB((BYTE)(a * 255), (BYTE)(r * 255), (BYTE)(g * 255), (BYTE)(b * 255));
91  }
92  operator D3DCOLOR() const noexcept
93  {
95  return get_ColorDX();
96  }
97 
98  float get_R() const noexcept
99  {
100  return r;
101  }
102  float get_G() const noexcept
103  {
104  return g;
105  }
106  float get_B() const noexcept
107  {
108  return b;
109  }
110  float get_A() const noexcept
111  {
112  return a;
113  }
114 
115  inline void SetModulate(const cColorf& rColor)
116  {
118 #ifdef USE_DXM
119  ::XMColorModulate( (D3DXCOLOR*) this, (D3DXCOLOR*) this, (D3DXCOLOR*) &rColor);
120 #else
121  DoMul(rColor);
122 #endif
123  }
124 
126  };
127 }
128 #endif // _INC_cColorf_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
Using X files without the sources and the makefile How to use you just create a debug directory e g
Definition: Readme.txt:21
#define D3DCOLOR_ARGB(a, r, g, b)
Definition: cColorRef.h:28
DWORD D3DCOLOR
Stuff normally defined in windows.h or DirectX headers.
Definition: cColorRef.h:24
UINT32 COLORREF
ABGR (high to low bits)
Definition: cVariantData.h:21
static COLOR_ELEM_t GetR(D3DCOLOR color) noexcept
Definition: cColorRef.h:184
static COLOR_ELEM_t GetA(D3DCOLOR color) noexcept
Definition: cColorRef.h:179
static COLOR_ELEM_t GetB(D3DCOLOR color) noexcept
Definition: cColorRef.h:194
static COLOR_ELEM_t GetG(D3DCOLOR color) noexcept
Definition: cColorRef.h:189
Definition: cColorf.h:24
UNITTEST_FRIEND(cColorf)
D3DCOLOR get_ColorDX() const noexcept
Definition: cColorf.h:87
cColorf(float r, float g, float b, float a=1.0f) noexcept
Definition: cColorf.h:50
float get_R() const noexcept
Definition: cColorf.h:98
cColorf(const SUPER_t &v) noexcept
Definition: cColorf.h:41
void SetModulate(const cColorf &rColor)
Definition: cColorf.h:115
cColorf() noexcept
Definition: cColorf.h:33
cColorf(D3DCOLOR c) noexcept
Definition: cColorf.h:35
cColorf(const float *f) noexcept
Definition: cColorf.h:44
COLORREF get_ColorRef() const noexcept
Definition: cColorf.h:82
cColorf(D3DCOLOR_TYPE_ c) noexcept
Definition: cColorf.h:38
float get_A() const noexcept
Definition: cColorf.h:110
float get_B() const noexcept
Definition: cColorf.h:106
float get_G() const noexcept
Definition: cColorf.h:102
cColorf(const cVecT3< float > &v, float a) noexcept
Definition: cColorf.h:47
Definition: cVecT.h:663
Definition: cMesh.h:22
UNITTEST2_PREDEF(cQuadtree)
D3DCOLOR_TYPE_
Definition: cColorRef.h:471
Definition: MathDX.h:106