Color.h
Color.h
CPP1/* Copyright Statement:2 *3 * (C) 2021-2024 Cubios Inc. All rights reserved.4 */56#ifndef WASMLIBS_CPP_COLOR_H_7#define WASMLIBS_CPP_COLOR_H_89#include "native.h"10#include "Vec2.h"1112namespace Cubios13{14namespace Math15{1617#define HEX_VALUE(R,G,B,A) this->_Value = B|(G<<8)|(R<<16)|(A<<24);1819class Color20{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 }3233 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;3839 this->_R = (v & 0x000000ff);40 this->_G = (v & 0x0000ff00) >> 8;41 this->_B = (v & 0x00ff0000) >> 16;42 this->_A = (v & 0xff000000) >> 24;43 }4445 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);}4849 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));}5253 inline uint8_t A() {return this->_A;}54 inline float Af() {return (float)this->_A/255.0f;}5556 inline uint8_t R() {return this->_R;}57 inline uint8_t G() {return this->_G;}58 inline uint8_t B() {return this->_B;}5960 inline uint32_t Value() {return this->_Value;}6162private:63 uint8_t _R;64 uint8_t _G;65 uint8_t _B;66 uint8_t _A;6768 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.