11#pragma once
22
3- // combine rgba bytes into single unsigned int value
4- #define MAKE_RGBA (r,g,b,a ) (((unsigned int )(r)) | (((unsigned int )(g)) << 8 ) | (((unsigned int )(b)) << 16 ) | (((unsigned int )(a)) << 24 ))
5- #define MAKE_RGB_SET_ALPHA (rgb, a ) ((((unsigned int )(rgb) & 0x00FFFFFFU )) | (((unsigned int )(a)) << 24 ))
6-
7- // predefined rgba colors
8-
9- #define COLOR_RED MAKE_RGBA (0xFF ,0x00 ,0x00 ,0xFF )
10- #define COLOR_GREEN MAKE_RGBA (0x00 ,0xFF ,0x00 ,0xFF )
11- #define COLOR_DARK_GREEN MAKE_RGBA (0x00 ,0x80 ,0x00 ,0xFF )
12- #define COLOR_ORANGE MAKE_RGBA (0xFF ,0xA5 ,0x00 ,0xFF )
13- #define COLOR_BLUE MAKE_RGBA (0x00 ,0x00 ,0xFF ,0xFF )
14- #define COLOR_SKYBLUE MAKE_RGBA (0x87 ,0xCE ,0xEB ,0xFF )
15- #define COLOR_DARK_BLUE MAKE_RGBA (0x00 ,0x00 ,0xA0 ,0xFF )
16- #define COLOR_WHITE MAKE_RGBA (0xFF ,0xFF ,0xFF ,0xFF )
17- #define COLOR_BLACK MAKE_RGBA (0x00 ,0x00 ,0x00 ,0xFF )
18- #define COLOR_CYAN MAKE_RGBA (0x00 ,0xFF ,0xFF ,0xFF )
19- #define COLOR_YELLOW MAKE_RGBA (0xFF ,0xFF ,0x00 ,0xFF )
20-
213// defines rgba color
224struct Color32
235{
@@ -31,33 +13,50 @@ struct Color32
3113 , mA (ca)
3214 {
3315 }
34- // @param rgba: Source rgba color
35- inline Color32& operator = (const Color32& rgba)
16+ // @param rgba: Source 32bits color
17+ inline Color32& operator = (Color32 rgba)
3618 {
3719 mRGBA = rgba.mRGBA ;
3820 return *this ;
3921 }
40- // Set color components
41- // @param theR, theG, theB, theA: Color components
42- inline void SetComponents (unsigned char theR, unsigned char theG, unsigned char theB, unsigned char theA)
22+ // set color components
23+ // @param cr, cg, cb, ca: Color components
24+ inline void SetComponents (unsigned char cr, unsigned char cg, unsigned char cb, unsigned char ca)
25+ {
26+ mA = cr;
27+ mR = cg;
28+ mG = cg;
29+ mB = cb;
30+ }
31+
32+ // combine rgba channels into single unsigned int value
33+ static unsigned int MakeRGBA (unsigned char cr, unsigned char cg, unsigned char cb, unsigned char ca)
34+ {
35+ return ((unsigned int )(cr)) | (((unsigned int )(cg)) << 8U ) | (((unsigned int )(cb)) << 16U ) | (((unsigned int )(ca)) << 24U );
36+ }
37+
38+ // implicit conversion to int
39+ inline operator unsigned int () const { return mRGBA ; }
40+
41+ inline unsigned char operator [] (int index) const
4342 {
44- mA = theA;
45- mR = theR;
46- mG = theG;
47- mB = theB;
43+ debug_assert (index > -1 && index < 4 );
44+ return mChannels [index];
4845 }
49- // Set color components
50- // @param theR, theG, theB, theA: Normalized color components in range [0, 1]
51- inline void SetComponentsF (float theR, float theG, float theB, float theA)
46+
47+ inline unsigned char & operator [] (int index)
5248 {
53- mA = (unsigned char ) (theA * 255 );
54- mR = (unsigned char ) (theR * 255 );
55- mG = (unsigned char ) (theG * 255 );
56- mB = (unsigned char ) (theB * 255 );
49+ debug_assert (index > -1 && index < 4 );
50+ return mChannels [index];
5751 }
52+
5853public:
5954 union
6055 {
56+ struct
57+ {
58+ unsigned char mChannels [4 ];
59+ };
6160 struct
6261 {
6362 unsigned char mR ;
@@ -69,47 +68,113 @@ struct Color32
6968 };
7069};
7170
71+ const unsigned int Sizeof_Color32 = sizeof (Color32);
72+
7273inline bool operator == (const Color32& LHS, const Color32& RHS) { return LHS.mRGBA == RHS.mRGBA ; }
7374inline bool operator != (const Color32& LHS, const Color32& RHS) { return LHS.mRGBA != RHS.mRGBA ; }
7475
75- // defines point in 2d space
76- using Point2D = glm::ivec2;
77-
78- // defines size in 2d space
79- using Size2D = glm::ivec2;
76+ // predefined rgba colors
77+
78+ // standard colors
79+ extern const Color32 Color32_Red;
80+ extern const Color32 Color32_Green;
81+ extern const Color32 Color32_DarkGreen;
82+ extern const Color32 Color32_Orange;
83+ extern const Color32 Color32_Blue;
84+ extern const Color32 Color32_Brown;
85+ extern const Color32 Color32_SkyBlue;
86+ extern const Color32 Color32_DarkBlue;
87+ extern const Color32 Color32_White;
88+ extern const Color32 Color32_DarkGray;
89+ extern const Color32 Color32_GrimGray;
90+ extern const Color32 Color32_Gray;
91+ extern const Color32 Color32_Black;
92+ extern const Color32 Color32_Cyan;
93+ extern const Color32 Color32_Yellow;
94+ extern const Color32 Color32_NULL;
95+
96+ // defines coordinate or size in 2d
97+ using Point = glm::ivec2;
8098
8199// defines rectangle in 2d space
82- struct Rect2D
100+ struct Rectangle
83101{
84102public:
85- Rect2D () = default ;
86- Rect2D (int posx, int posy, int sizex, int sizey)
103+ Rectangle () = default ;
104+ Rectangle (int posx, int posy, int sizex, int sizey)
87105 : x(posx)
88106 , y(posy)
89107 , w(sizex)
90108 , h(sizey)
91109 {
92110 }
111+ inline void Set (int posx, int posy, int sizex, int sizey)
112+ {
113+ x = posx;
114+ y = posy;
115+ w = sizex;
116+ h = sizey;
117+ }
93118 inline void SetNull ()
94119 {
95- x = 0 ; y = 0 ;
96- w = 0 ; h = 0 ;
120+ x = 0 ;
121+ y = 0 ;
122+ w = 0 ;
123+ h = 0 ;
124+ }
125+ // test whether point is within rect
126+ inline bool PointWithin (const Point& point) const
127+ {
128+ return point.x >= x && point.y >= y &&
129+ point.x < (x + w - 1 ) &&
130+ point.y < (y + h - 1 );
131+ }
132+ // get union area of two rectangles
133+ inline Rectangle GetUnion (const Rectangle& rc) const
134+ {
135+ Rectangle rcOutput;
136+
137+ int maxx = glm::max (x + w, rc.x + rc.w );
138+ int maxy = glm::max (y + h, rc.y + rc.h );
139+
140+ rcOutput.x = glm::min (x, rc.x );
141+ rcOutput.y = glm::min (y, rc.y );
142+ rcOutput.w = glm::max (maxx - rcOutput.x , 0 );
143+ rcOutput.h = glm::max (maxy - rcOutput.y , 0 );
144+
145+ return rcOutput;
146+ }
147+ // get intersection area of two rectangles
148+ inline Rectangle GetIntersection (const Rectangle& rc) const
149+ {
150+ Rectangle rcOutput;
151+
152+ int minx = glm::min (x + w, rc.x + rc.w );
153+ int miny = glm::min (y + h, rc.y + rc.h );
154+
155+ rcOutput.x = glm::max (x, rc.x );
156+ rcOutput.y = glm::max (y, rc.y );
157+ rcOutput.w = glm::max (minx - rcOutput.x , 0 );
158+ rcOutput.h = glm::max (miny - rcOutput.y , 0 );
159+
160+ return rcOutput;
97161 }
98162public:
99163 int x, y;
100164 int w, h;
101165};
102166
103- inline bool operator == (const Rect2D& theL , const Rect2D& theR )
167+ inline bool operator == (const Rectangle& lhs , const Rectangle& rhs )
104168{
105- return (theL .x == theR .x ) && (theL .y == theR .y ) && (theL .w == theR .w ) && (theL .h == theR .h );
169+ return (lhs .x == rhs .x ) && (lhs .y == rhs .y ) && (lhs .w == rhs .w ) && (lhs .h == rhs .h );
106170}
107171
108- inline bool operator != (const Rect2D& theL , const Rect2D& theR )
172+ inline bool operator != (const Rectangle& lhs , const Rectangle& rhs )
109173{
110- return (theL .x != theR .x ) || (theL .y != theR .y ) || (theL .w != theR .w ) || (theL .h != theR .h );
174+ return (lhs .x != rhs .x ) || (lhs .y != rhs .y ) || (lhs .w != rhs .w ) || (lhs .h != rhs .h );
111175}
112176
177+ // console log message category
113178enum eLogMessage
114179{
115180 eLogMessage_Debug,
@@ -142,12 +207,10 @@ struct ConsoleLine
142207 std::string mString ;
143208};
144209
145- namespace SceneAxes
146- {
147- static const glm::vec3 X {1 .0f , 0 .0f , 0 .0f };
148- static const glm::vec3 Y {0 .0f , 1 .0f , 0 .0f };
149- static const glm::vec3 Z {0 .0f , 0 .0f , 1 .0f };
150- };
210+ // global constants
211+ extern const glm::vec3 SceneAxisX;
212+ extern const glm::vec3 SceneAxisY;
213+ extern const glm::vec3 SceneAxisZ;
151214
152215enum eSceneCameraMode
153216{
0 commit comments