34 #ifndef __ENKI_TYPES_H 35 #define __ENKI_TYPES_H 61 Color(
double r = 0.0,
double g = 0.0,
double b = 0.0,
double a = 1.0)
70 const double&
operator[](
size_t i)
const { assert((i >= 0) && (i < 4));
return components[i]; }
72 double&
operator[](
size_t i) { assert((i >= 0) && (i < 4));
return components[i]; }
76 void operator +=(
double d) {
for (
size_t i=0; i<3; i++) components[i] += d; }
81 void operator -=(
double d) {
for (
size_t i=0; i<3; i++) components[i] -= d; }
86 void operator *=(
double d) {
for (
size_t i=0; i<3; i++) components[i] *= d; }
91 void operator /=(
double d) {
for (
size_t i=0; i<3; i++) components[i] /= d; }
111 void threshold(
const Color &limit) {
for (
size_t i=0; i<3; i++) components[i] = components[i] > limit.
components[i] ? components[i] : 0; }
113 double toGray()
const {
return (components[0] + components[1] + components[2]) / 3; }
116 std::string
toString()
const { std::ostringstream oss; oss << *
this;
return oss.str(); }
119 double r()
const {
return components[0]; }
122 void setR(
double value) { components[0] = value; }
125 double g()
const {
return components[1]; }
128 void setG(
double value) { components[1] = value; }
131 double b()
const {
return components[2]; }
134 void setB(
double value) { components[2] = value; }
137 double a()
const {
return components[3]; }
140 void setA(
double value) { components[3] = value; }
162 friend std::ostream & operator<<(std::ostream &os,
const Color& c);
void setA(double value)
Set the value of alpha component.
Definition: Types.h:140
void setG(double value)
Set the value of green component.
Definition: Types.h:128
void operator-=(double d)
Substract d from each component.
Definition: Types.h:81
void setB(double value)
Set the value of blue component.
Definition: Types.h:134
std::vector< Color > Texture
A texture.
Definition: Types.h:166
const double & operator[](size_t i) const
access component i
Definition: Types.h:70
double & operator[](size_t i)
access component i
Definition: Types.h:72
std::string toString() const
Return a string describing this color.
Definition: Types.h:116
static const Color white
white (1, 1, 1)
Definition: Types.h:152
Color operator/(double d) const
Divide each component with d and return result in a new color. I'm left unchanged.
Definition: Types.h:93
double components[4]
RGBA values in range [0..1].
Definition: Types.h:58
static const Color black
black (0, 0, 0)
Definition: Types.h:150
static const Color gray
gray (0.5, 0.5, 0.5)
Definition: Types.h:154
static Color fromARGB(uint32_t color)
Build from an ARGB uint32_t (0xAARRGGBB in little endian)
Definition: Types.cpp:42
Color(double r=0.0, double g=0.0, double b=0.0, double a=1.0)
Constructor from separated components.
Definition: Types.h:61
static uint32_t toARGB(Color color)
Pack into ABGR uint32_t (0xAABBGGRR in little endian)
Definition: Types.cpp:60
Enki is the namespace of the Enki simulator. All Enki functions and classes excepted the math one are...
Definition: BluetoothBase.cpp:44
static const Color green
green (0, 1, 0)
Definition: Types.h:158
std::vector< Texture > Textures
Textures for all sides of an object.
Definition: Types.h:169
static Color fromABGR(uint32_t color)
Build from an ABGR uint32_t (0xAABBGGRR in little endian)
Definition: Types.cpp:51
void operator/=(double d)
Divide each component with d.
Definition: Types.h:91
double a() const
Alpha component value getter.
Definition: Types.h:137
bool operator!=(const Color &c) const
Compare all components and return false if they're the same.
Definition: Types.h:109
Color operator-(double d) const
Substract d from each component and return result in a new color. I'm left unchanged.
Definition: Types.h:83
void operator*=(double d)
Multiply each component with d.
Definition: Types.h:86
bool operator==(const Color &c) const
Compare all components and return true if they're the same.
Definition: Types.h:107
void operator+=(double d)
Add d to each component.
Definition: Types.h:76
Color operator+(double d) const
Add d to each component and return result in a new color. I'm left unchanged.
Definition: Types.h:78
static const Color blue
blue (0, 0, 1)
Definition: Types.h:160
A color in RGBA.
Definition: Types.h:55
double toGray() const
Return the grey level value.
Definition: Types.h:113
double b() const
Blue component value getter.
Definition: Types.h:131
Color operator*(double d) const
Multiply each component with d and return result in a new color. I'm left unchanged.
Definition: Types.h:88
double g() const
Green component value getter.
Definition: Types.h:125
void setR(double value)
Set the value of red component.
Definition: Types.h:122
double r() const
Red component value getter.
Definition: Types.h:119
static const Color red
red (1, 0, 0)
Definition: Types.h:156
void threshold(const Color &limit)
Threshold the color using limit. For each component, if value is below limit, set it to 0...
Definition: Types.h:111