raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
Color.hpp
1#ifndef RAYLIB_CPP_INCLUDE_COLOR_HPP_
2#define RAYLIB_CPP_INCLUDE_COLOR_HPP_
3
4#include <string>
5#include <string_view>
6
7#include "./raylib.hpp"
8#include "./Vector4.hpp"
9#include "./RadiansDegrees.hpp"
10#include "./raylib-cpp-utils.hpp"
11
12namespace raylib {
16class Color : public ::Color {
17 public:
18 Color(const ::Color& color) : ::Color{color.r, color.g, color.b, color.a} {}
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
52 Color(void *srcPtr, int format) {
53 set(::GetPixelColor(srcPtr, format));
54 }
55
59 int ToInt() const {
60 return ::ColorToInt(*this);
61 }
62
66 operator int() const {
67 return ::ColorToInt(*this);
68 }
69
70 std::string ToString() const {
71 return TextFormat("Color(%d, %d, %d, %d)", r, g, b, a);
72 }
73
74 operator std::string() const {
75 return ToString();
76 }
77
81 Color Fade(float alpha) const {
82 return ::Fade(*this, alpha);
83 }
84
89 return ::ColorNormalize(*this);
90 }
91
95 Color(::Vector4 normalized) {
96 set(::ColorFromNormalized(normalized));
97 }
98
102 Vector3 ToHSV() const {
103 return ::ColorToHSV(*this);
104 }
105
106 GETTERSETTER(unsigned char, R, r)
107 GETTERSETTER(unsigned char, G, g)
108 GETTERSETTER(unsigned char, B, b)
109 GETTERSETTER(unsigned char, A, a)
110
111 Color& operator=(const ::Color& color) {
112 set(color);
113 return *this;
114 }
115
120 ::ClearBackground(*this);
121 return *this;
122 }
123
124 void DrawPixel(int x, int y) const {
125 ::DrawPixel(x, y, *this);
126 }
127
131 void DrawPixel(::Vector2 pos) const {
132 ::DrawPixelV(pos, *this);
133 }
134
138 void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY) const {
139 ::DrawLine(startPosX, startPosY, endPosX, endPosY, *this);
140 }
141
145 void DrawLine(::Vector2 startPos, ::Vector2 endPos) const {
146 ::DrawLineV(startPos, endPos, *this);
147 }
148
152 void DrawLine(::Vector2 startPos, ::Vector2 endPos, float thick) const {
153 ::DrawLineEx(startPos, endPos, thick, *this);
154 }
155
156 void DrawLineBezier(::Vector2 startPos, ::Vector2 endPos, float thick = 1.0f) const {
157 ::DrawLineBezier(startPos, endPos, thick, *this);
158 }
159
160 void DrawLineStrip(::Vector2 *points, int numPoints) const {
161 ::DrawLineStrip(points, numPoints, *this);
162 }
163
164 void DrawText(const char* text, int posX = 0, int posY = 0, int fontSize = 10.0f) const {
165 ::DrawText(text, posX, posY, fontSize, *this);
166 }
167
168 void DrawText(const std::string_view text, int posX = 0, int posY = 0, int fontSize = 10.0f) const {
169 ::DrawText(text.data(), posX, posY, fontSize, *this);
170 }
171
172 void DrawText(const ::Font& font, const char* text, ::Vector2 position,
173 float fontSize, float spacing) const {
174 ::DrawTextEx(font, text, position, fontSize, spacing, *this);
175 }
176
177 void DrawText(const ::Font& font, const std::string_view text, ::Vector2 position,
178 float fontSize, float spacing) const {
179 ::DrawTextEx(font, text.data(), position, fontSize, spacing, *this);
180 }
181
182 void DrawText(
183 const ::Font& font,
184 const char* text,
185 ::Vector2 position,
186 ::Vector2 origin,
187 Degree rotation,
188 float fontSize,
189 float spacing) const {
190 ::DrawTextPro(font, text, position, origin, rotation, fontSize, spacing, *this);
191 }
192
193 void DrawText(
194 const ::Font& font,
195 const std::string_view text,
196 ::Vector2 position,
197 ::Vector2 origin,
198 Degree rotation,
199 float fontSize,
200 float spacing) const {
201 ::DrawTextPro(font, text.data(), position, origin, rotation, fontSize, spacing, *this);
202 }
203
204 void DrawRectangle(int posX, int posY, int width, int height) const {
205 ::DrawRectangle(posX, posY, width, height, *this);
206 }
207
208 void DrawRectangle(::Vector2 position, ::Vector2 size) const {
209 ::DrawRectangleV(position, size, *this);
210 }
211
212 void DrawRectangle(::Rectangle rec) const {
213 ::DrawRectangleRec(rec, *this);
214 }
215
216 void DrawRectangle(::Rectangle rec, ::Vector2 origin, Degree rotation) const {
217 ::DrawRectanglePro(rec, origin, rotation, *this);
218 }
219
220 void DrawRectangleLines(int posX, int posY, int width, int height) const {
221 ::DrawRectangleLines(posX, posY, width, height, *this);
222 }
223
224 void DrawRectangleLines(::Rectangle rec, float lineThick) const {
225 ::DrawRectangleLinesEx(rec, lineThick, *this);
226 }
227
232 return ::ColorTint(*this, tint);
233 }
234
238 Color Brightness(float factor) {
239 return ::ColorBrightness(*this, factor);
240 }
241
245 Color Contrast(float contrast) {
246 return ::ColorContrast(*this, contrast);
247 }
248
252 Color Alpha(float alpha) const {
253 return ::ColorAlpha(*this, alpha);
254 }
255
259 Color AlphaBlend(::Color dst, ::Color tint) const {
260 return ::ColorAlphaBlend(dst, *this, tint);
261 }
262
263 static Color LightGray() { return LIGHTGRAY; }
264 static Color Gray() { return GRAY; }
265 static Color DarkGray() { return DARKGRAY; }
266 static Color Yellow() { return YELLOW; }
267 static Color Gold() { return GOLD; }
268 static Color Orange() { return ORANGE; }
269 static Color Pink() { return PINK; }
270 static Color Red() { return RED; }
271 static Color Maroon() { return MAROON; }
272 static Color Green() { return GREEN; }
273 static Color Lime() { return LIME; }
274 static Color DarkGreen() { return DARKGREEN; }
275 static Color SkyBlue() { return SKYBLUE; }
276 static Color Blue() { return BLUE; }
277 static Color DarkBlue() { return DARKBLUE; }
278 static Color Purple() { return PURPLE; }
279 static Color Violet() { return VIOLET; }
280 static Color DarkPurple() { return DARKPURPLE; }
281 static Color Beige() { return BEIGE; }
282 static Color Brown() { return BROWN; }
283 static Color DarkBrown() { return DARKBROWN; }
284 static Color White() { return WHITE; }
285 static Color Black() { return BLACK; }
286 static Color Blank() { return BLANK; }
287 static Color Magenta() { return MAGENTA; }
288 static Color RayWhite() { return RAYWHITE; }
289
290 protected:
291 void set(const ::Color& color) {
292 r = color.r;
293 g = color.g;
294 b = color.b;
295 a = color.a;
296 }
297};
298
299} // namespace raylib
300
301using RColor = raylib::Color;
302
303#endif // RAYLIB_CPP_INCLUDE_COLOR_HPP_
Color type, RGBA (32bit)
Definition: Color.hpp:16
Color AlphaBlend(::Color dst, ::Color tint) const
Returns src alpha-blended into dst color with tint.
Definition: Color.hpp:259
Color(::Vector3 hsv)
Returns a Color from HSV values.
Definition: Color.hpp:34
Color Contrast(float contrast)
Get color with contrast correction, contrast values between -1.0f and 1.0f.
Definition: Color.hpp:245
Color Tint(::Color tint)
Get color multiplied with another color.
Definition: Color.hpp:231
void DrawLine(::Vector2 startPos, ::Vector2 endPos) const
Draw a line using Vector points.
Definition: Color.hpp:145
void DrawPixel(::Vector2 pos) const
Draw a pixel.
Definition: Color.hpp:131
::Color FromHSV(float hue, float saturation, float value)
Returns a Color from HSV values.
Definition: Color.hpp:41
Vector4 Normalize() const
Returns Color normalized as float [0..1].
Definition: Color.hpp:88
Color Fade(float alpha) const
Returns color with alpha applied, alpha goes from 0.0f to 1.0f.
Definition: Color.hpp:81
int ToInt() const
Returns hexadecimal value for a Color.
Definition: Color.hpp:59
Color(::Vector4 normalized)
Returns Color from normalized values [0..1].
Definition: Color.hpp:95
void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY) const
Draw a line.
Definition: Color.hpp:138
Vector3 ToHSV() const
Returns HSV values for a Color.
Definition: Color.hpp:102
Color()
Black.
Definition: Color.hpp:29
void DrawLine(::Vector2 startPos, ::Vector2 endPos, float thick) const
Draw a line using Vector points, with a given thickness.
Definition: Color.hpp:152
Color Alpha(float alpha) const
Returns color with alpha applied, alpha goes from 0.0f to 1.0f.
Definition: Color.hpp:252
Color & ClearBackground()
Set background color (framebuffer clear color)
Definition: Color.hpp:119
Color(unsigned int hexValue)
Get Color structure from hexadecimal value.
Definition: Color.hpp:48
Color Brightness(float factor)
Get color with brightness correction, brightness factor goes from -1.0f to 1.0f.
Definition: Color.hpp:238
Vector3 type.
Definition: Vector3.hpp:19
Vector4 type.
Definition: Vector4.hpp:20