raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
Rectangle.hpp
1#ifndef RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
2#define RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
3
4#include "./raylib.hpp"
5#include "./raylib-cpp-utils.hpp"
6#include "./Vector2.hpp"
7#include "./Vector4.hpp"
8#include "./RadiansDegrees.hpp"
9
10namespace raylib {
14class Rectangle : public ::Rectangle {
15 public:
16 Rectangle(const ::Rectangle& rect) : ::Rectangle{rect.x, rect.y, rect.width, rect.height} {}
17
18 Rectangle(float x, float y, float width, float height) : ::Rectangle{x, y, width, height} {}
19 Rectangle(float x, float y, float width) : ::Rectangle{x, y, width, 0} {}
20 Rectangle(float x, float y) : ::Rectangle{x, y, 0, 0} {}
21 Rectangle(float x) : ::Rectangle{x, 0, 0, 0} {}
22 Rectangle() : ::Rectangle{0, 0, 0, 0} {}
23
24 Rectangle(::Vector2 position, ::Vector2 size)
25 : ::Rectangle{position.x, position.y, size.x, size.y} {}
26 Rectangle(::Vector2 size) : ::Rectangle{0, 0, size.x, size.y} {}
27 Rectangle(::Vector4 rect) : ::Rectangle{rect.x, rect.y, rect.z, rect.w} {}
28
29 GETTERSETTER(float, X, x)
30 GETTERSETTER(float, Y, y)
31 GETTERSETTER(float, Width, width)
32 GETTERSETTER(float, Height, height)
33
34 Rectangle& operator=(const ::Rectangle& rect) {
35 set(rect);
36 return *this;
37 }
38
39 Vector4 ToVector4() {
40 return {x, y, width, height};
41 }
42
43 operator Vector4() const {
44 return {x, y, width, height};
45 }
46
50 void Draw(::Color color) const {
51 ::DrawRectangleRec(*this, color);
52 }
53
54 void Draw(::Vector2 origin, Degree rotation, ::Color color) const {
55 ::DrawRectanglePro(*this, origin, rotation, color);
56 }
57
58 void DrawGradientV(::Color color1, ::Color color2) const {
59 ::DrawRectangleGradientV(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
60 static_cast<int>(height), color1, color2);
61 }
62
63 void DrawGradientH(::Color color1, ::Color color2) const {
64 ::DrawRectangleGradientH(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
65 static_cast<int>(height), color1, color2);
66 }
67
68 void DrawGradient(::Color col1, ::Color col2, ::Color col3, ::Color col4) const {
69 ::DrawRectangleGradientEx(*this, col1, col2, col3, col4);
70 }
71
72 void DrawLines(::Color color) const {
73 ::DrawRectangleLines(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
74 static_cast<int>(height), color);
75 }
76
77 void DrawLines(::Color color, float lineThick) const {
78 ::DrawRectangleLinesEx(*this, lineThick, color);
79 }
80
81 void DrawRounded(float roundness, int segments, ::Color color) const {
82 ::DrawRectangleRounded(*this, roundness, segments, color);
83 }
84
85 void DrawRoundedLines(float roundness, int segments, ::Color color) const {
86 #if RAYLIB_VERSION_MAJOR == 5 && RAYLIB_VERSION_MINOR == 0
87 ::DrawRectangleRoundedLines(*this, roundness, segments, 1.0f, color);
88 #else
89 ::DrawRectangleRoundedLines(*this, roundness, segments, color);
90 #endif
91 }
92
93 void DrawRoundedLines(float roundness, int segments,
94 float lineThick, ::Color color) const {
95 #if RAYLIB_VERSION_MAJOR == 5 && RAYLIB_VERSION_MINOR == 0
96 ::DrawRectangleRoundedLines(*this, roundness, segments, lineThick, color);
97 #else
98 DrawRectangleRoundedLinesEx(*this, roundness, segments, lineThick, color);
99 #endif
100 }
101
105 bool CheckCollision(::Rectangle rec2) const {
106 return ::CheckCollisionRecs(*this, rec2);
107 }
108
112 Rectangle GetCollision(::Rectangle rec2) const {
113 return ::GetCollisionRec(*this, rec2);
114 }
115
119 bool CheckCollision(::Vector2 point) const {
120 return ::CheckCollisionPointRec(point, *this);
121 }
122
126 bool CheckCollision(::Vector2 center, float radius) const {
127 return ::CheckCollisionCircleRec(center, radius, *this);
128 }
129
130 Vector2 GetSize() const {
131 return {width, height};
132 }
133
134 Rectangle& SetSize(float newWidth, float newHeight) {
135 width = newWidth;
136 height = newHeight;
137 return *this;
138 }
139
140 Rectangle& SetSize(const ::Vector2& size) {
141 return SetSize(size.x, size.y);
142 }
143
144 Rectangle& SetShapesTexture(const ::Texture2D& texture) {
145 ::SetShapesTexture(texture, *this);
146 return *this;
147 }
148
149 Vector2 GetPosition() const {
150 return {x, y};
151 }
152
153 Rectangle& SetPosition(float newX, float newY) {
154 x = newX;
155 y = newY;
156 return *this;
157 }
158
159 Rectangle& SetPosition(const ::Vector2& position) {
160 return SetPosition(position.x, position.y);
161 }
162
163 protected:
164 void set(const ::Rectangle& rect) {
165 x = rect.x;
166 y = rect.y;
167 width = rect.width;
168 height = rect.height;
169 }
170};
171} // namespace raylib
172
174
175#endif // RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
Degree type (allows automatic worry free conversion between radians and degrees)
Rectangle type.
Definition: Rectangle.hpp:14
Rectangle GetCollision(::Rectangle rec2) const
Get collision rectangle for two rectangles collision.
Definition: Rectangle.hpp:112
bool CheckCollision(::Rectangle rec2) const
Check collision between two rectangles.
Definition: Rectangle.hpp:105
void Draw(::Color color) const
Draw a color-filled rectangle.
Definition: Rectangle.hpp:50
bool CheckCollision(::Vector2 center, float radius) const
Check collision between circle and rectangle.
Definition: Rectangle.hpp:126
bool CheckCollision(::Vector2 point) const
Check if point is inside rectangle.
Definition: Rectangle.hpp:119
Vector2 type.
Definition: Vector2.hpp:19
Vector4 type.
Definition: Vector4.hpp:20