WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelog
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.
Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Source
  4. Color.h
Mission NodeSDK 6.2C++math

Color.h

SDK Source File: Color.h

Source / SDK 6.2 / C++ / math

Color.h

Color.h
CPP
1/* Copyright Statement:
2 *
3 * (C) 2021-2024 Cubios Inc. All rights reserved.
4 */
5
6#ifndef WASMLIBS_CPP_COLOR_H_
7#define WASMLIBS_CPP_COLOR_H_
8
9#include "native.h"
10#include "Vec2.h"
11
12namespace Cubios
13{
14namespace Math
15{
16
17#define HEX_VALUE(R,G,B,A) this->_Value = B|(G<<8)|(R<<16)|(A<<24);
18
19class Color
20{
21public:
22 Color():_R(255),_G(255),_B(255),_A(255),_Value(0xFFFFFFFF){}
23 Color(uint8_t r, uint8_t g, uint32_t b):_R(r),_G(g),_B(b),_A(255){ HEX_VALUE(r,g,b,255) }
24 Color(uint8_t r, uint8_t g, uint32_t b, uint8_t a):_R(r),_G(g),_B(b),_A(a){ HEX_VALUE(r,g,b,a) }
25 Color(uint32_t v):_Value(v)
26 {
27 this->_R = (v & 0x000000ff);
28 this->_G = (v & 0x0000ff00) >> 8;
29 this->_B = (v & 0x00ff0000) >> 16;
30 this->_A = (v & 0xff000000) >> 24;
31 }
32
33 void Set(uint8_t r, uint8_t g, uint32_t b, uint8_t a) { this->_R = r; this->_G = g; this->_B = b; this->_A = a; HEX_VALUE(r,g,b,a) }
34 void Set(uint8_t r, uint8_t g, uint32_t b) { this->_R = r; this->_G = g; this->_B = b; HEX_VALUE(r,g,b,this->_A) }
35 void Set(uint32_t v)
36 {
37 this->_Value = v;
38
39 this->_R = (v & 0x000000ff);
40 this->_G = (v & 0x0000ff00) >> 8;
41 this->_B = (v & 0x00ff0000) >> 16;
42 this->_A = (v & 0xff000000) >> 24;
43 }
44
45 inline void SetA(uint8_t a) {this->_A = a; this->_Value = (uint32_t(this->_Value) & 0x00FFFFFF) | ((uint32_t(a) & 0xFF) << 24);}
46 inline void SetAf(float a) {this->_A = a*255; this->_Value = (uint32_t(this->_Value) & 0x00FFFFFF) | ((uint32_t(this->_A) & 0xFF) << 24);}
47 inline void SetAfSafe(float a) {if(a<0.0) a=0; if(a>1.0) a = 1.0; this->SetAf(a);}
48
49 inline void SetR(uint8_t r) {this->_R = r; this->_Value = (uint32_t(this->_Value) & 0xFF00FFFF) | ((uint32_t(r) & 0xFF) << 16);}
50 inline void SetG(uint8_t g) {this->_G = g; this->_Value = (uint32_t(this->_Value) & 0xFFFF00FF) | ((uint32_t(g) & 0xFF) << 8);}
51 inline void SetB(uint8_t b) {this->_B = b; this->_Value = (uint32_t(this->_Value) & 0xFFFFFF00) | ((uint32_t(b) & 0xFF));}
52
53 inline uint8_t A() {return this->_A;}
54 inline float Af() {return (float)this->_A/255.0f;}
55
56 inline uint8_t R() {return this->_R;}
57 inline uint8_t G() {return this->_G;}
58 inline uint8_t B() {return this->_B;}
59
60 inline uint32_t Value() {return this->_Value;}
61
62private:
63 uint8_t _R;
64 uint8_t _G;
65 uint8_t _B;
66 uint8_t _A;
67
68 uint32_t _Value;
69};
70}
71}
72#endif /* WASMLIBS_CPP_TRANSFORM_H_ */
73
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Related nodes

Math.h
Source / SDK 6.2 / C++ / math
Rect2.h
Source / SDK 6.2 / C++ / math
Transform.h
Source / SDK 6.2 / C++ / math
Vec2.h
Source / SDK 6.2 / C++ / math
Previous Node
Text.h
Source / SDK 6.2 / C++ / gfx
Next Node
Math.h
Source / SDK 6.2 / C++ / math