aboutsummaryrefslogtreecommitdiff
path: root/core/color.h
diff options
context:
space:
mode:
authorRémi Verschelde2017-03-05 16:44:50 +0100
committerRémi Verschelde2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /core/color.h
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
downloadgodot-5dbf180.tar.gz
godot-5dbf180.tar.zst
godot-5dbf180.zip
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'core/color.h')
-rw-r--r--core/color.h87
1 files changed, 46 insertions, 41 deletions
diff --git a/core/color.h b/core/color.h
index 50a676134..2339cd6cd 100644
--- a/core/color.h
+++ b/core/color.h
@@ -29,8 +29,8 @@
#ifndef COLOR_H
#define COLOR_H
-#include "ustring.h"
#include "math_funcs.h"
+#include "ustring.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -47,8 +47,8 @@ struct Color {
float components[4];
};
- bool operator==(const Color &p_color) const { return (r==p_color.r && g==p_color.g && b==p_color.b && a==p_color.a ); }
- bool operator!=(const Color &p_color) const { return (r!=p_color.r || g!=p_color.g || b!=p_color.b || a!=p_color.a ); }
+ bool operator==(const Color &p_color) const { return (r == p_color.r && g == p_color.g && b == p_color.b && a == p_color.a); }
+ bool operator!=(const Color &p_color) const { return (r != p_color.r || g != p_color.g || b != p_color.b || a != p_color.a); }
uint32_t to_32() const;
uint32_t to_ARGB32() const;
@@ -56,12 +56,12 @@ struct Color {
float get_h() const;
float get_s() const;
float get_v() const;
- void set_hsv(float p_h, float p_s, float p_v, float p_alpha=1.0);
+ void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0);
- _FORCE_INLINE_ float& operator[](int idx) {
+ _FORCE_INLINE_ float &operator[](int idx) {
return components[idx];
}
- _FORCE_INLINE_ const float& operator[](int idx) const {
+ _FORCE_INLINE_ const float &operator[](int idx) const {
return components[idx];
}
@@ -70,30 +70,29 @@ struct Color {
Color inverted() const;
Color contrasted() const;
- _FORCE_INLINE_ Color linear_interpolate(const Color& p_b, float p_t) const {
+ _FORCE_INLINE_ Color linear_interpolate(const Color &p_b, float p_t) const {
- Color res=*this;
+ Color res = *this;
- res.r+= (p_t * (p_b.r-r));
- res.g+= (p_t * (p_b.g-g));
- res.b+= (p_t * (p_b.b-b));
- res.a+= (p_t * (p_b.a-a));
+ res.r += (p_t * (p_b.r - r));
+ res.g += (p_t * (p_b.g - g));
+ res.b += (p_t * (p_b.b - b));
+ res.a += (p_t * (p_b.a - a));
return res;
}
- _FORCE_INLINE_ Color blend(const Color& p_over) const {
-
+ _FORCE_INLINE_ Color blend(const Color &p_over) const {
Color res;
float sa = 1.0 - p_over.a;
- res.a = a*sa+p_over.a;
- if (res.a==0) {
- return Color(0,0,0,0);
+ res.a = a * sa + p_over.a;
+ if (res.a == 0) {
+ return Color(0, 0, 0, 0);
} else {
- res.r = (r*a*sa + p_over.r * p_over.a)/res.a;
- res.g = (g*a*sa + p_over.g * p_over.a)/res.a;
- res.b = (b*a*sa + p_over.b * p_over.a)/res.a;
+ res.r = (r * a * sa + p_over.r * p_over.a) / res.a;
+ res.g = (g * a * sa + p_over.g * p_over.a) / res.a;
+ res.b = (b * a * sa + p_over.b * p_over.a) / res.a;
}
return res;
}
@@ -101,48 +100,54 @@ struct Color {
_FORCE_INLINE_ Color to_linear() const {
return Color(
- r<0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
- g<0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
- b<0.04045 ? b * (1.0 / 12.92) : Math::pow((b + 0.055) * (1.0 / (1 + 0.055)), 2.4),
- a
- );
+ r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
+ g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
+ b < 0.04045 ? b * (1.0 / 12.92) : Math::pow((b + 0.055) * (1.0 / (1 + 0.055)), 2.4),
+ a);
}
static Color hex(uint32_t p_hex);
- static Color html(const String& p_color);
- static bool html_is_valid(const String& p_color);
- static Color named(const String& p_name);
- String to_html(bool p_alpha=true) const;
+ static Color html(const String &p_color);
+ static bool html_is_valid(const String &p_color);
+ static Color named(const String &p_name);
+ String to_html(bool p_alpha = true) const;
- _FORCE_INLINE_ bool operator<(const Color& p_color) const; //used in set keys
+ _FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys
operator String() const;
/**
* No construct parameters, r=0, g=0, b=0. a=255
*/
_FORCE_INLINE_ Color() {
- r=0; g=0; b=0; a=1.0;
+ r = 0;
+ g = 0;
+ b = 0;
+ a = 1.0;
}
/**
* RGB / RGBA construct parameters. Alpha is optional, but defaults to 1.0
*/
- _FORCE_INLINE_ Color(float p_r,float p_g,float p_b,float p_a=1.0) { r=p_r; g=p_g; b=p_b; a=p_a; }
+ _FORCE_INLINE_ Color(float p_r, float p_g, float p_b, float p_a = 1.0) {
+ r = p_r;
+ g = p_g;
+ b = p_b;
+ a = p_a;
+ }
};
-bool Color::operator<(const Color& p_color) const {
+bool Color::operator<(const Color &p_color) const {
- if (r==p_color.r) {
- if (g==p_color.g) {
- if(b==p_color.b) {
- return (a<p_color.a);
+ if (r == p_color.r) {
+ if (g == p_color.g) {
+ if (b == p_color.b) {
+ return (a < p_color.a);
} else
- return (b<p_color.b);
+ return (b < p_color.b);
} else
- return g<p_color.g;
+ return g < p_color.g;
} else
- return r<p_color.r;
-
+ return r < p_color.r;
}
#endif