raylib-cpp
C++ object-oriented wrapper library for raylib.
Color.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_COLOR_HPP_
2 #define RAYLIB_CPP_INCLUDE_COLOR_HPP_
3 
4 #include <string>
5 
6 #include "./raylib.hpp"
7 #include "./Vector4.hpp"
8 #include "./raylib-cpp-utils.hpp"
9 
10 namespace raylib {
14 class Color : public ::Color {
15  public:
16  Color(const ::Color& color) {
17  set(color);
18  }
19 
20  Color(
21  unsigned char red,
22  unsigned char green,
23  unsigned char blue,
24  unsigned char alpha = 255) : ::Color{red, green, blue, alpha} {};
25 
29  Color() : ::Color{0, 0, 0, 255} {};
30 
34  Color(::Vector3 hsv) {
35  set(::ColorFromHSV(hsv.x, hsv.y, hsv.z));
36  }
37 
41  static ::Color FromHSV(float hue, float saturation, float value) {
42  return ::ColorFromHSV(hue, saturation, value);
43  }
44 
48  Color(unsigned int hexValue) {
49  set(::GetColor(hexValue));
50  }
51 
55  Color(::Vector4 normalized) {
56  set(::ColorFromNormalized(normalized));
57  }
58 
62  int ToInt() const {
63  return ::ColorToInt(*this);
64  }
65 
69  operator int() const {
70  return ::ColorToInt(*this);
71  }
72 
76  Color Fade(float alpha) const {
77  return ::Fade(*this, alpha);
78  }
79 
83  Vector4 Normalize() const {
84  return ::ColorNormalize(*this);
85  }
86 
90  Vector3 ToHSV() const {
91  return ::ColorToHSV(*this);
92  }
93 
94  GETTERSETTER(unsigned char, R, r)
95  GETTERSETTER(unsigned char, G, g)
96  GETTERSETTER(unsigned char, B, b)
97  GETTERSETTER(unsigned char, A, a)
98 
99  Color& operator=(const ::Color& color) {
100  set(color);
101  return *this;
102  }
103 
107  inline Color& ClearBackground() {
108  ::ClearBackground(*this);
109  return *this;
110  }
111 
112  inline Color& DrawPixel(int x, int y) {
113  ::DrawPixel(x, y, *this);
114  return *this;
115  }
116 
120  inline Color& DrawPixel(::Vector2 pos) {
121  ::DrawPixelV(pos, *this);
122  return *this;
123  }
124 
128  inline Color& DrawLine(int startPosX, int startPosY, int endPosX, int endPosY) {
129  ::DrawLine(startPosX, startPosY, endPosX, endPosY, *this);
130  return *this;
131  }
132 
133  inline Color& DrawLine(::Vector2 startPos, ::Vector2 endPos) {
134  ::DrawLineV(startPos, endPos, *this);
135  return *this;
136  }
137 
138  inline Color& DrawLine(::Vector2 startPos, ::Vector2 endPos, float thick) {
139  ::DrawLineEx(startPos, endPos, thick, *this);
140  return *this;
141  }
142 
143  inline Color& DrawLineBezier(::Vector2 startPos, ::Vector2 endPos, float thick) {
144  ::DrawLineBezier(startPos, endPos, thick, *this);
145  return *this;
146  }
147 
148  inline Color& DrawLineStrip(::Vector2 *points, int numPoints) {
149  ::DrawLineStrip(points, numPoints, *this);
150  return *this;
151  }
152 
153  inline Color& DrawText(const std::string& text, int posX, int posY, int fontSize) {
154  ::DrawText(text.c_str(), posX, posY, fontSize, *this);
155  return *this;
156  }
157 
158  inline Color& DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
159  float fontSize, float spacing) {
160  ::DrawTextEx(font, text.c_str(), position, fontSize, spacing, *this);
161  return *this;
162  }
163 
164  inline Color& DrawText(
165  const ::Font& font,
166  const std::string& text,
167  ::Vector2 position,
168  ::Vector2 origin,
169  float rotation,
170  float fontSize,
171  float spacing) {
172  ::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, *this);
173  return *this;
174  }
175 
176  inline Color& DrawRectangle(int posX, int posY, int width, int height) {
177  ::DrawRectangle(posX, posY, width, height, *this);
178  return *this;
179  }
180 
181  inline Color& DrawRectangle(::Vector2 position, ::Vector2 size) {
182  ::DrawRectangleV(position, size, *this);
183  return *this;
184  }
185 
186  inline Color& DrawRectangle(::Rectangle rec) {
187  ::DrawRectangleRec(rec, *this);
188  return *this;
189  }
190 
191  inline Color& DrawRectangle(::Rectangle rec, ::Vector2 origin, float rotation) {
192  ::DrawRectanglePro(rec, origin, rotation, *this);
193  return *this;
194  }
195 
196  inline Color& DrawRectangleLines(int posX, int posY, int width, int height) {
197  ::DrawRectangleLines(posX, posY, width, height, *this);
198  return *this;
199  }
200 
201  inline Color& DrawRectangleLines(::Rectangle rec, float lineThick) {
202  ::DrawRectangleLinesEx(rec, lineThick, *this);
203  return *this;
204  }
205 
209  Color Alpha(float alpha) const {
210  return ::ColorAlpha(*this, alpha);
211  }
212 
216  Color AlphaBlend(::Color dst, ::Color tint) const {
217  return ::ColorAlphaBlend(dst, *this, tint);
218  }
219 
220  inline static Color LightGray() { return LIGHTGRAY; }
221  inline static Color Gray() { return GRAY; }
222  inline static Color DarkGray() { return DARKGRAY; }
223  inline static Color Yellow() { return YELLOW; }
224  inline static Color Gold() { return GOLD; }
225  inline static Color Orange() { return ORANGE; }
226  inline static Color Pink() { return PINK; }
227  inline static Color Red() { return RED; }
228  inline static Color Maroon() { return MAROON; }
229  inline static Color Green() { return GREEN; }
230  inline static Color Lime() { return LIME; }
231  inline static Color DarkGreen() { return DARKGREEN; }
232  inline static Color SkyBlue() { return SKYBLUE; }
233  inline static Color Blue() { return BLUE; }
234  inline static Color DarkBlue() { return DARKBLUE; }
235  inline static Color Purple() { return PURPLE; }
236  inline static Color Violet() { return VIOLET; }
237  inline static Color DarkPurple() { return DARKPURPLE; }
238  inline static Color Beige() { return BEIGE; }
239  inline static Color Brown() { return BROWN; }
240  inline static Color DarkBrown() { return DARKBROWN; }
241  inline static Color White() { return WHITE; }
242  inline static Color Black() { return BLACK; }
243  inline static Color Blank() { return BLANK; }
244  inline static Color Magenta() { return MAGENTA; }
245  inline static Color RayWhite() { return RAYWHITE; }
246 
247  private:
248  inline void set(const ::Color& color) {
249  r = color.r;
250  g = color.g;
251  b = color.b;
252  a = color.a;
253  }
254 };
255 
256 } // namespace raylib
257 
258 #endif // RAYLIB_CPP_INCLUDE_COLOR_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8
raylib::Vector4
Vector4 type.
Definition: Vector4.hpp:17
raylib::Color::ClearBackground
Color & ClearBackground()
Set background color (framebuffer clear color)
Definition: Color.hpp:107
raylib::Color::Color
Color(unsigned int hexValue)
Get Color structure from hexadecimal value.
Definition: Color.hpp:48
raylib::Vector3
Vector3 type.
Definition: Vector3.hpp:16
raylib::Color::ToInt
int ToInt() const
Returns hexadecimal value for a Color.
Definition: Color.hpp:62
raylib::Color::ToHSV
Vector3 ToHSV() const
Returns HSV values for a Color.
Definition: Color.hpp:90
raylib::DrawTextPro
static void DrawTextPro(const Font &font, const std::string &text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, ::Color tint)
Draw text using Font and pro parameters (rotation)
Definition: Functions.hpp:271
raylib::Color::Color
Color(::Vector3 hsv)
Returns a Color from HSV values.
Definition: Color.hpp:34
raylib::Vector2
Vector2 type.
Definition: Vector2.hpp:16
raylib::Color::DrawPixel
Color & DrawPixel(::Vector2 pos)
Draw a pixel.
Definition: Color.hpp:120
raylib::Color::Color
Color(::Vector4 normalized)
Returns Color from normalized values [0..1].
Definition: Color.hpp:55
raylib::Color
Color type, RGBA (32bit)
Definition: Color.hpp:14
raylib::Color::Color
Color()
Black.
Definition: Color.hpp:29
raylib::Color::FromHSV
::Color FromHSV(float hue, float saturation, float value)
Returns a Color from HSV values.
Definition: Color.hpp:41
raylib::Color::Alpha
Color Alpha(float alpha) const
Returns color with alpha applied, alpha goes from 0.0f to 1.0f.
Definition: Color.hpp:209
raylib::Color::AlphaBlend
Color AlphaBlend(::Color dst, ::Color tint) const
Returns src alpha-blended into dst color with tint.
Definition: Color.hpp:216
raylib::Color::Normalize
Vector4 Normalize() const
Returns Color normalized as float [0..1].
Definition: Color.hpp:83
raylib::Color::DrawLine
Color & DrawLine(int startPosX, int startPosY, int endPosX, int endPosY)
Draw a line.
Definition: Color.hpp:128
raylib::Color::Fade
Color Fade(float alpha) const
Returns color with alpha applied, alpha goes from 0.0f to 1.0f.
Definition: Color.hpp:76
raylib::DrawTextEx
static void DrawTextEx(const Font &font, const std::string &text, Vector2 position, float fontSize, float spacing, ::Color tint)
Draw text using font and additional parameters.
Definition: Functions.hpp:263