1#ifndef RAYLIB_CPP_INCLUDE_COLOR_HPP_
2#define RAYLIB_CPP_INCLUDE_COLOR_HPP_
7#include "./Vector4.hpp"
8#include "./RadiansDegrees.hpp"
9#include "./raylib-cpp-utils.hpp"
10#include "./raylib.hpp"
18 Color(const ::Color& color) :
::Color{color.r, color.g, color.b, color.a} {}
20 Color(
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha = 255)
21 :
::Color{red, green, blue, alpha} {};
31 Color(::Vector3 hsv) { set(::ColorFromHSV(hsv.x, hsv.y, hsv.z)); }
36 static ::Color
FromHSV(
float hue,
float saturation,
float value) { return ::ColorFromHSV(hue, saturation, value); }
41 explicit Color(
unsigned int hexValue) : ::
Color(::GetColor(hexValue)) { }
43 Color(
void* srcPtr,
int format) : ::
Color(::GetPixelColor(srcPtr, format)) { }
48 [[nodiscard]]
int ToInt()
const { return ::ColorToInt(*
this); }
53 explicit operator int()
const { return ::ColorToInt(*
this); }
55 [[nodiscard]] std::string ToString()
const {
return TextFormat(
"Color(%d, %d, %d, %d)", r, g, b, a); }
57 explicit operator std::string()
const {
return ToString(); }
62 [[nodiscard]]
Color Fade(
float alpha)
const { return ::Fade(*
this, alpha); }
72 explicit Color(::Vector4 normalized) :
Color(::ColorFromNormalized(normalized)) { }
77 [[nodiscard]]
Vector3 ToHSV()
const { return ::ColorToHSV(*
this); }
79 GETTERSETTER(
unsigned char, R, r)
80 GETTERSETTER(
unsigned char, G, g)
81 GETTERSETTER(
unsigned char, B, b)
82 GETTERSETTER(
unsigned char, A, a)
97 void DrawPixel(
int x,
int y)
const { ::DrawPixel(x, y, *
this); }
102 void DrawPixel(::Vector2 pos)
const { ::DrawPixelV(pos, *
this); }
107 void DrawLine(
int startPosX,
int startPosY,
int endPosX,
int endPosY)
const {
108 ::DrawLine(startPosX, startPosY, endPosX, endPosY, *
this);
114 void DrawLine(::Vector2 startPos, ::Vector2 endPos)
const { ::DrawLineV(startPos, endPos, *
this); }
119 void DrawLine(::Vector2 startPos, ::Vector2 endPos,
float thick)
const {
120 ::DrawLineEx(startPos, endPos, thick, *
this);
123 void DrawLineBezier(::Vector2 startPos, ::Vector2 endPos,
float thick = 1.0f)
const {
124 ::DrawLineBezier(startPos, endPos, thick, *
this);
127 void DrawLineStrip(::Vector2* points,
int numPoints)
const { ::DrawLineStrip(points, numPoints, *
this); }
129 void DrawText(
const char* text,
int posX = 0,
int posY = 0,
int fontSize = 10.0f)
const {
130 ::DrawText(text, posX, posY, fontSize, *
this);
133 void DrawText(
const std::string_view text,
int posX = 0,
int posY = 0,
int fontSize = 10.0f)
const {
134 ::DrawText(text.data(), posX, posY, fontSize, *
this);
137 void DrawText(const ::Font& font,
const char* text, ::Vector2 position,
float fontSize,
float spacing)
const {
138 ::DrawTextEx(font, text, position, fontSize, spacing, *
this);
141 void DrawText(const ::Font& font,
const std::string_view text, ::Vector2 position,
142 float fontSize,
float spacing)
const {
143 ::DrawTextEx(font, text.data(), position, fontSize, spacing, *
this);
153 float spacing)
const {
154 ::DrawTextPro(font, text, position, origin, rotation, fontSize, spacing, *
this);
159 const std::string_view text,
164 float spacing)
const {
165 ::DrawTextPro(font, text.data(), position, origin, rotation, fontSize, spacing, *
this);
168 void DrawRectangle(
int posX,
int posY,
int width,
int height)
const {
169 ::DrawRectangle(posX, posY, width, height, *
this);
172 void DrawRectangle(::Vector2 position, ::Vector2 size)
const { ::DrawRectangleV(position, size, *
this); }
174 void DrawRectangle(::Rectangle rec)
const { ::DrawRectangleRec(rec, *
this); }
176 void DrawRectangle(::Rectangle rec, ::Vector2 origin, Degree rotation)
const {
177 ::DrawRectanglePro(rec, origin, rotation, *
this);
180 void DrawRectangleLines(
int posX,
int posY,
int width,
int height)
const {
181 ::DrawRectangleLines(posX, posY, width, height, *
this);
184 void DrawRectangleLines(::Rectangle rec,
float lineThick)
const { ::DrawRectangleLinesEx(rec, lineThick, *
this); }
187 return ::ColorIsEqual(*
this, color);
190 bool operator==(const ::Color& other)
const { return ::ColorIsEqual(*
this, other); }
191 bool operator!=(const ::Color& other)
const {
return !::ColorIsEqual(*
this, other); }
211 [[nodiscard]]
Color Alpha(
float alpha)
const { return ::ColorAlpha(*
this, alpha); }
214 return ::ColorLerp(*
this, color2, factor);
222 static Color LightGray() {
return LIGHTGRAY; }
223 static Color Gray() {
return GRAY; }
224 static Color DarkGray() {
return DARKGRAY; }
225 static Color Yellow() {
return YELLOW; }
226 static Color Gold() {
return GOLD; }
227 static Color Orange() {
return ORANGE; }
228 static Color Pink() {
return PINK; }
229 static Color Red() {
return RED; }
230 static Color Maroon() {
return MAROON; }
231 static Color Green() {
return GREEN; }
232 static Color Lime() {
return LIME; }
233 static Color DarkGreen() {
return DARKGREEN; }
234 static Color SkyBlue() {
return SKYBLUE; }
235 static Color Blue() {
return BLUE; }
236 static Color DarkBlue() {
return DARKBLUE; }
237 static Color Purple() {
return PURPLE; }
238 static Color Violet() {
return VIOLET; }
239 static Color DarkPurple() {
return DARKPURPLE; }
240 static Color Beige() {
return BEIGE; }
241 static Color Brown() {
return BROWN; }
242 static Color DarkBrown() {
return DARKBROWN; }
243 static Color White() {
return WHITE; }
244 static Color Black() {
return BLACK; }
245 static Color Blank() {
return BLANK; }
246 static Color Magenta() {
return MAGENTA; }
247 static Color RayWhite() {
return RAYWHITE; }
249 void set(const ::Color& color) {
Color AlphaBlend(::Color dst, ::Color tint) const
Returns src alpha-blended into dst color with tint.
Color(::Vector3 hsv)
Returns a Color from HSV values.
Color Contrast(float contrast)
Get color with contrast correction, contrast values between -1.0f and 1.0f.
Color Tint(::Color tint)
Get color multiplied with another color.
void DrawLine(::Vector2 startPos, ::Vector2 endPos) const
Draw a line using Vector points.
void DrawPixel(::Vector2 pos) const
Draw a pixel.
::Color FromHSV(float hue, float saturation, float value)
Returns a Color from HSV values.
Vector4 Normalize() const
Returns Color normalized as float [0..1].
Color Fade(float alpha) const
Returns color with alpha applied, alpha goes from 0.0f to 1.0f.
int ToInt() const
Returns hexadecimal value for a Color.
Color(::Vector4 normalized)
Returns Color from normalized values [0..1].
void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY) const
Draw a line.
Vector3 ToHSV() const
Returns HSV values for a Color.
void DrawLine(::Vector2 startPos, ::Vector2 endPos, float thick) const
Draw a line using Vector points, with a given thickness.
Color Alpha(float alpha) const
Returns color with alpha applied, alpha goes from 0.0f to 1.0f.
Color & ClearBackground()
Set background color (framebuffer clear color)
Color(unsigned int hexValue)
Get Color structure from hexadecimal value.
Color Brightness(float factor)
Get color with brightness correction, brightness factor goes from -1.0f to 1.0f.
All raylib-cpp classes and functions appear in the raylib namespace.
static void DrawTextPro(const Font &font, const char *text, Vector2 position, Vector2 origin, Degree rotation, float fontSize, float spacing, ::Color tint)
Draw text using Font and pro parameters (rotation)
static void DrawTextEx(const Font &font, char *text, Vector2 position, float fontSize, float spacing, ::Color tint)
Draw text using font and additional parameters.