raylib-cpp
C++ object-oriented wrapper library for raylib.
Color.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_COLOR_HPP_
26 #define RAYLIB_CPP_INCLUDE_COLOR_HPP_
27 
28 #include <string>
29 
30 #include "./raylib.hpp"
31 #include "./Vector4.hpp"
32 #include "./raylib-cpp-utils.hpp"
33 
34 namespace raylib {
35 class Color : public ::Color {
36  public:
37  Color(const ::Color& color) {
38  set(color);
39  }
40 
41  Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) :
42  ::Color{red, green, blue, alpha} {};
43 
44  Color(unsigned char red, unsigned char green, unsigned char blue) :
45  ::Color{red, green, blue, 255} {};
46 
50  Color() : ::Color{0, 0, 0, 255} {};
51 
55  Color(::Vector3 hsv) {
56  set(::ColorFromHSV(hsv.x, hsv.y, hsv.z));
57  }
58 
62  static ::Color FromHSV(float hue, float saturation, float value) {
63  return ::ColorFromHSV(hue, saturation, value);
64  }
65 
69  Color(int hexValue) {
70  set(::GetColor(hexValue));
71  }
72 
76  Color(::Vector4 normalized) {
77  set(::ColorFromNormalized(normalized));
78  }
79 
83  int ToInt() const {
84  return ::ColorToInt(*this);
85  }
86 
90  operator int() const {
91  return ::ColorToInt(*this);
92  }
93 
97  Color Fade(float alpha) const {
98  return ::Fade(*this, alpha);
99  }
100 
104  Vector4 Normalize() const {
105  return ::ColorNormalize(*this);
106  }
107 
111  Vector3 ToHSV() const {
112  return ::ColorToHSV(*this);
113  }
114 
115  GETTERSETTER(unsigned char, R, r)
116  GETTERSETTER(unsigned char, G, g)
117  GETTERSETTER(unsigned char, B, b)
118  GETTERSETTER(unsigned char, A, a)
119 
120  Color& operator=(const ::Color& color) {
121  set(color);
122  return *this;
123  }
124 
128  inline Color& ClearBackground() {
129  ::ClearBackground(*this);
130  return *this;
131  }
132 
133  inline Color& DrawPixel(int x, int y) {
134  ::DrawPixel(x, y, *this);
135  return *this;
136  }
137 
141  inline Color& DrawPixel(::Vector2 pos) {
142  ::DrawPixelV(pos, *this);
143  return *this;
144  }
145 
149  inline Color& DrawLine(int startPosX, int startPosY, int endPosX, int endPosY) {
150  ::DrawLine(startPosX, startPosY, endPosX, endPosY, *this);
151  return *this;
152  }
153 
154  inline Color& DrawLine(::Vector2 startPos, ::Vector2 endPos) {
155  ::DrawLineV(startPos, endPos, *this);
156  return *this;
157  }
158 
159  inline Color& DrawLine(::Vector2 startPos, ::Vector2 endPos, float thick) {
160  ::DrawLineEx(startPos, endPos, thick, *this);
161  return *this;
162  }
163 
164  inline Color& DrawLineBezier(::Vector2 startPos, ::Vector2 endPos, float thick) {
165  ::DrawLineBezier(startPos, endPos, thick, *this);
166  return *this;
167  }
168 
169  inline Color& DrawLineStrip(::Vector2 *points, int numPoints) {
170  ::DrawLineStrip(points, numPoints, *this);
171  return *this;
172  }
173 
174  inline Color& DrawText(const std::string& text, int posX, int posY, int fontSize) {
175  ::DrawText(text.c_str(), posX, posY, fontSize, *this);
176  return *this;
177  }
178 
179  inline Color& DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
180  float fontSize, float spacing) {
181  ::DrawTextEx(font, text.c_str(), position, fontSize, spacing, *this);
182  return *this;
183  }
184 
185  inline Color& DrawText(
186  const ::Font& font,
187  const std::string& text,
188  ::Rectangle rec,
189  float fontSize,
190  float spacing,
191  bool wordWrap = false) {
192  ::DrawTextRec(font, text.c_str(), rec, fontSize, spacing, wordWrap, *this);
193  return *this;
194  }
195 
196  inline Color& DrawRectangle(int posX, int posY, int width, int height) {
197  ::DrawRectangle(posX, posY, width, height, *this);
198  return *this;
199  }
200 
201  inline Color& DrawRectangle(::Vector2 position, ::Vector2 size) {
202  ::DrawRectangleV(position, size, *this);
203  return *this;
204  }
205 
206  inline Color& DrawRectangle(::Rectangle rec) {
207  ::DrawRectangleRec(rec, *this);
208  return *this;
209  }
210 
211  inline Color& DrawRectangle(::Rectangle rec, ::Vector2 origin, float rotation) {
212  ::DrawRectanglePro(rec, origin, rotation, *this);
213  return *this;
214  }
215 
216  inline Color& DrawRectangleLines(int posX, int posY, int width, int height) {
217  ::DrawRectangleLines(posX, posY, width, height, *this);
218  return *this;
219  }
220 
221  inline Color& DrawRectangleLines(::Rectangle rec, int lineThick) {
222  ::DrawRectangleLinesEx(rec, lineThick, *this);
223  return *this;
224  }
225 
229  Color Alpha(float alpha) const {
230  return ::ColorAlpha(*this, alpha);
231  }
232 
236  Color AlphaBlend(::Color dst, ::Color tint) const {
237  return ::ColorAlphaBlend(dst, *this, tint);
238  }
239 
240  inline static Color LightGray() { return LIGHTGRAY; }
241  inline static Color Gray() { return GRAY; }
242  inline static Color DarkGray() { return DARKGRAY; }
243  inline static Color Yellow() { return YELLOW; }
244  inline static Color Gold() { return GOLD; }
245  inline static Color Orange() { return ORANGE; }
246  inline static Color Pink() { return PINK; }
247  inline static Color Red() { return RED; }
248  inline static Color Maroon() { return MAROON; }
249  inline static Color Green() { return GREEN; }
250  inline static Color Lime() { return LIME; }
251  inline static Color DarkGreen() { return DARKGREEN; }
252  inline static Color SkyBlue() { return SKYBLUE; }
253  inline static Color Blue() { return BLUE; }
254  inline static Color DarkBlue() { return DARKBLUE; }
255  inline static Color Purple() { return PURPLE; }
256  inline static Color Violet() { return VIOLET; }
257  inline static Color DarkPurple() { return DARKPURPLE; }
258  inline static Color Beige() { return BEIGE; }
259  inline static Color Brown() { return BROWN; }
260  inline static Color DarkBrown() { return DARKBROWN; }
261  inline static Color White() { return WHITE; }
262  inline static Color Black() { return BLACK; }
263  inline static Color Blank() { return BLANK; }
264  inline static Color Magenta() { return MAGENTA; }
265  inline static Color RayWhite() { return RAYWHITE; }
266 
267  protected:
268  inline void set(const ::Color& color) {
269  r = color.r;
270  g = color.g;
271  b = color.b;
272  a = color.a;
273  }
274 };
275 
276 } // namespace raylib
277 
278 #endif // RAYLIB_CPP_INCLUDE_COLOR_HPP_
raylib::Color::Violet
static Color Violet()
Definition: Color.hpp:256
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Color::DrawRectangleLines
Color & DrawRectangleLines(int posX, int posY, int width, int height)
Definition: Color.hpp:216
RenderTexture
raylib::Color::Green
static Color Green()
Definition: Color.hpp:249
raylib::Color::DrawLineStrip
Color & DrawLineStrip(::Vector2 *points, int numPoints)
Definition: Color.hpp:169
raylib::Color::White
static Color White()
Definition: Color.hpp:261
Color
raylib::Color::Purple
static Color Purple()
Definition: Color.hpp:255
raylib::Color::DrawRectangle
Color & DrawRectangle(::Vector2 position, ::Vector2 size)
Definition: Color.hpp:201
raylib::Color::DrawText
Color & DrawText(const ::Font &font, const std::string &text, ::Rectangle rec, float fontSize, float spacing, bool wordWrap=false)
Definition: Color.hpp:185
raylib::Color::DrawRectangleLines
Color & DrawRectangleLines(::Rectangle rec, int lineThick)
Definition: Color.hpp:221
raylib::Vector4
Definition: Vector4.hpp:38
Texture
Vector3
raylib::Color::set
void set(const ::Color &color)
Definition: Color.hpp:268
raylib::Color::ClearBackground
Color & ClearBackground()
Set background color (framebuffer clear color)
Definition: Color.hpp:128
raylib::Color::DrawLine
Color & DrawLine(::Vector2 startPos, ::Vector2 endPos)
Definition: Color.hpp:154
raylib::Color::DarkPurple
static Color DarkPurple()
Definition: Color.hpp:257
raylib::Color::DarkBlue
static Color DarkBlue()
Definition: Color.hpp:254
Sound
raylib::Color::SkyBlue
static Color SkyBlue()
Definition: Color.hpp:252
Camera2D
raylib::Color::DrawRectangle
Color & DrawRectangle(::Rectangle rec, ::Vector2 origin, float rotation)
Definition: Color.hpp:211
Camera3D
raylib::Color::Brown
static Color Brown()
Definition: Color.hpp:259
raylib::Color::Beige
static Color Beige()
Definition: Color.hpp:258
raylib::Color::Pink
static Color Pink()
Definition: Color.hpp:246
Mesh
raylib::Vector3
Definition: Vector3.hpp:37
raylib::Color::DrawPixel
Color & DrawPixel(int x, int y)
Definition: Color.hpp:133
Image
raylib::Color::ToInt
int ToInt() const
Returns hexadecimal value for a Color.
Definition: Color.hpp:83
raylib::Color::ToHSV
Vector3 ToHSV() const
Returns HSV values for a Color.
Definition: Color.hpp:111
raylib::Color::DrawLine
Color & DrawLine(::Vector2 startPos, ::Vector2 endPos, float thick)
Definition: Color.hpp:159
raylib::Color::Blue
static Color Blue()
Definition: Color.hpp:253
Font
raylib::Color::Blank
static Color Blank()
Definition: Color.hpp:263
raylib::Color::Maroon
static Color Maroon()
Definition: Color.hpp:248
raylib::Color::LightGray
static Color LightGray()
Definition: Color.hpp:240
ModelAnimation
raylib::Color::Orange
static Color Orange()
Definition: Color.hpp:245
raylib::Color::Black
static Color Black()
Definition: Color.hpp:262
raylib::Color::Color
Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
Definition: Color.hpp:41
raylib::Color::RayWhite
static Color RayWhite()
Definition: Color.hpp:265
Ray
raylib::Color::Yellow
static Color Yellow()
Definition: Color.hpp:243
Material
raylib::Color::DrawText
Color & DrawText(const ::Font &font, const std::string &text, ::Vector2 position, float fontSize, float spacing)
Definition: Color.hpp:179
raylib::Rectangle
Definition: Rectangle.hpp:33
raylib::Color::Gray
static Color Gray()
Definition: Color.hpp:241
Model
Wave
raylib::Color::Color
Color(::Vector3 hsv)
Returns a Color from HSV values.
Definition: Color.hpp:55
AudioStream
raylib::Vector2
Definition: Vector2.hpp:37
raylib::Color::DarkGreen
static Color DarkGreen()
Definition: Color.hpp:251
raylib::Color::DrawRectangle
Color & DrawRectangle(::Rectangle rec)
Definition: Color.hpp:206
raylib::Color::Color
Color(unsigned char red, unsigned char green, unsigned char blue)
Definition: Color.hpp:44
raylib::Color::Red
static Color Red()
Definition: Color.hpp:247
raylib::Color::DrawPixel
Color & DrawPixel(::Vector2 pos)
Draw a pixel.
Definition: Color.hpp:141
Rectangle
raylib::Color::Color
Color(::Vector4 normalized)
Returns Color from normalized values [0..1].
Definition: Color.hpp:76
BoundingBox
raylib::Color
Definition: Color.hpp:35
raylib::Color::DrawText
Color & DrawText(const std::string &text, int posX, int posY, int fontSize)
Definition: Color.hpp:174
raylib::Color::Color
Color()
Black.
Definition: Color.hpp:50
raylib::Color::FromHSV
::Color FromHSV(float hue, float saturation, float value)
Returns a Color from HSV values.
Definition: Color.hpp:62
raylib::Color::Alpha
Color Alpha(float alpha) const
Returns color with alpha applied, alpha goes from 0.0f to 1.0f.
Definition: Color.hpp:229
raylib::Color::AlphaBlend
Color AlphaBlend(::Color dst, ::Color tint) const
Returns src alpha-blended into dst color with tint.
Definition: Color.hpp:236
Shader
raylib::Color::Normalize
Vector4 Normalize() const
Returns Color normalized as float [0..1].
Definition: Color.hpp:104
Music
raylib::Color::Gold
static Color Gold()
Definition: Color.hpp:244
Matrix
raylib::Color::DarkGray
static Color DarkGray()
Definition: Color.hpp:242
raylib::Color::DrawLine
Color & DrawLine(int startPosX, int startPosY, int endPosX, int endPosY)
Draw a line.
Definition: Color.hpp:149
raylib::Color::Fade
Color Fade(float alpha) const
Returns color with alpha applied, alpha goes from 0.0f to 1.0f.
Definition: Color.hpp:97
raylib::Color::DarkBrown
static Color DarkBrown()
Definition: Color.hpp:260
raylib::Color::Lime
static Color Lime()
Definition: Color.hpp:250
raylib::Color::Color
Color(const ::Color &color)
Definition: Color.hpp:37
raylib::Color::DrawLineBezier
Color & DrawLineBezier(::Vector2 startPos, ::Vector2 endPos, float thick)
Definition: Color.hpp:164
raylib::Color::DrawRectangle
Color & DrawRectangle(int posX, int posY, int width, int height)
Definition: Color.hpp:196
raylib::Color::Magenta
static Color Magenta()
Definition: Color.hpp:264
Vector4
RayHitInfo
Vector2
raylib::Color::Color
Color(int hexValue)
Get Color structure from hexadecimal value.
Definition: Color.hpp:69