1.1.0
color.hpp
1 #ifndef FONT_CHEF_COLOR_HPP
2 #define FONT_CHEF_COLOR_HPP
3 
9 #include "font-chef/font-chef-export.h"
10 #include "font-chef/color.h"
11 
12 namespace fc {
18  struct FONT_CHEF_EXPORT color {
23 
25  color() : data() { }
26 
33  color(fc_color const & c) : data(c) { } //NOLINT
34 
39  color(color const & other) = default;
40 
49  color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) : data{r, g, b, a} { }
50 
55  uint8_t r() const { return data.r; }
56 
61  uint8_t g() const { return data.g; }
62 
67  uint8_t b() const { return data.b; }
68 
73  uint8_t a() const { return data.a; }
74 
79  color & r(uint8_t v) { data.r = v; return *this; }
80 
85  color & g(uint8_t v) { data.g = v; return *this; }
86 
91  color & b(uint8_t v) { data.b = v; return *this; }
92 
97  color & a(uint8_t v) { data.a = v; return *this; }
98  };
99 
107  FONT_CHEF_EXPORT inline color rgba(uint32_t c) {
108  fc_color r = fc_0xrgba(c);
109  return color(r);
110  }
111 
122  FONT_CHEF_EXPORT inline color rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
123  return color(r, g, b, a);
124  }
125 
135  FONT_CHEF_EXPORT inline color rgb(uint8_t r, uint8_t g, uint8_t b) {
136  return color(r, g, b);
137  }
138 
146  FONT_CHEF_EXPORT inline color rgb(uint32_t c) {
147  fc_color r = fc_0xrgb(c);
148  return color(r);
149  }
150 }
151 
152 #endif //FONT_CHEF_COLOR_HPP
fc_color::r
uint8_t r
Definition: color.h:27
fc::rgba
color rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Constructs a fc::color instance from red, green, blue and alpha values.
Definition: color.hpp:122
fc::color::a
color & a(uint8_t v)
Sets the alpha component for this color.
Definition: color.hpp:97
fc::color
A wrapper class for fc_color.
Definition: color.hpp:18
fc::rgb
color rgb(uint32_t c)
Constructs a fc::color instance from an integer with red, green and blue components,...
Definition: color.hpp:146
fc::color::b
color & b(uint8_t v)
Sets the blue component for this color.
Definition: color.hpp:91
fc::color::color
color(fc_color const &c)
Creates a fc::color instance from a fc_color value.
Definition: color.hpp:33
fc::color::g
color & g(uint8_t v)
Sets the green component for this color.
Definition: color.hpp:85
fc::color::g
uint8_t g() const
Gets the green component for this color.
Definition: color.hpp:61
fc::color::b
uint8_t b() const
Gets the blue component for this color.
Definition: color.hpp:67
fc::color::r
color & r(uint8_t v)
Sets the red component for this color.
Definition: color.hpp:79
fc_color::g
uint8_t g
Definition: color.h:30
fc::color::r
uint8_t r() const
Gets the red component for this color.
Definition: color.hpp:55
fc_color::a
uint8_t a
Definition: color.h:36
fc::color::a
uint8_t a() const
Gets the alpha component for this color.
Definition: color.hpp:73
fc_color
Represents a 4-byte-per-pixel color with red, green, blue and alpha components.
Definition: color.h:25
fc::color::color
color(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Constructs a fc::color instance from red, green, blue and alpha components.
Definition: color.hpp:49
fc::color::color
color()
Definition: color.hpp:25
fc::color::data
fc_color data
The internal fc_color value.
Definition: color.hpp:22
fc_0xrgba
struct fc_color fc_0xrgba(uint32_t color)
Constructs and return a fc_color value with red, green and blue components extracted from an unsigned...
fc_color::b
uint8_t b
Definition: color.h:33
fc_0xrgb
struct fc_color fc_0xrgb(uint32_t color)
Constructs and return a fc_color value with red, green and blue components extracted from an unsigned...