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 "./Vector2.hpp"
5#include "./Vector4.hpp"
6#include "./RadiansDegrees.hpp"
7
8namespace raylib {
12class Rectangle : public ::Rectangle {
13public:
14 Rectangle(const ::Rectangle& rect) : ::Rectangle{rect.x, rect.y, rect.width, rect.height} {}
15
16 Rectangle(float x, float y, float width, float height) : ::Rectangle{x, y, width, height} {}
17 Rectangle(float x, float y, float width) : ::Rectangle{x, y, width, 0} {}
18 Rectangle(float x, float y) : ::Rectangle{x, y, 0, 0} {}
19 Rectangle(float x) : ::Rectangle{x, 0, 0, 0} {}
20 Rectangle() : ::Rectangle{0, 0, 0, 0} {}
21
22 Rectangle(::Vector2 position, ::Vector2 size) : ::Rectangle{position.x, position.y, size.x, size.y} {}
23 Rectangle(::Vector2 size) : ::Rectangle{0, 0, size.x, size.y} {}
24 Rectangle(::Vector4 rect) : ::Rectangle{rect.x, rect.y, rect.z, rect.w} {}
25
26 GETTERSETTER(float, X, x)
27 GETTERSETTER(float, Y, y)
28 GETTERSETTER(float, Width, width)
29 GETTERSETTER(float, Height, height)
30
31 Rectangle& operator=(const ::Rectangle& rect) {
32 set(rect);
33 return *this;
34 }
35
36 Vector4 ToVector4() {
37 return {x, y, width, height};
38 }
39
40 operator Vector4() const {
41 return {x, y, width, height};
42 }
43
47 void Draw(::Color color) const { ::DrawRectangleRec(*this, color); }
48
49 void Draw(::Vector2 origin, Degree rotation, ::Color color) const {
50 ::DrawRectanglePro(*this, origin, rotation, color);
51 }
52
53 void DrawGradientV(::Color color1, ::Color color2) const {
54 ::DrawRectangleGradientV(
55 static_cast<int>(x),
56 static_cast<int>(y),
57 static_cast<int>(width),
58 static_cast<int>(height),
59 color1,
60 color2);
61 }
62
63 void DrawGradientH(::Color color1, ::Color color2) const {
64 ::DrawRectangleGradientH(
65 static_cast<int>(x),
66 static_cast<int>(y),
67 static_cast<int>(width),
68 static_cast<int>(height),
69 color1,
70 color2);
71 }
72
73 void DrawGradient(::Color topLeft, ::Color bottomLeft, ::Color topRight, ::Color bottomRight) const {
74 ::DrawRectangleGradientEx(*this, topLeft, bottomLeft, topRight, bottomRight);
75 }
76
77 void DrawLines(::Color color) const {
78 ::DrawRectangleLines(
79 static_cast<int>(x),
80 static_cast<int>(y),
81 static_cast<int>(width),
82 static_cast<int>(height),
83 color);
84 }
85
86 void DrawLines(::Color color, float lineThick) const { ::DrawRectangleLinesEx(*this, lineThick, color); }
87
88 void DrawRounded(float roundness, int segments, ::Color color) const {
89 ::DrawRectangleRounded(*this, roundness, segments, color);
90 }
91
92 void DrawRoundedLines(float roundness, int segments, ::Color color) const {
93 ::DrawRectangleRoundedLines(*this, roundness, segments, color);
94 }
95
96 void DrawRoundedLines(float roundness, int segments, float lineThick, ::Color color) const {
97 DrawRectangleRoundedLinesEx(*this, roundness, segments, lineThick, color);
98 }
99
103 [[nodiscard]] bool CheckCollision(::Rectangle rec2) const { return ::CheckCollisionRecs(*this, rec2); }
104
108 Rectangle GetCollision(::Rectangle rec2) const {
109 return ::GetCollisionRec(*this, rec2);
110 }
111
115 [[nodiscard]] bool CheckCollision(::Vector2 point) const { return ::CheckCollisionPointRec(point, *this); }
116
120 [[nodiscard]] bool CheckCollision(::Vector2 center, float radius) const {
121 return ::CheckCollisionCircleRec(center, radius, *this);
122 }
123
124 [[nodiscard]] Vector2 GetSize() const { return {width, height}; }
125
126 Rectangle& SetSize(float newWidth, float newHeight) {
127 width = newWidth;
128 height = newHeight;
129 return *this;
130 }
131
132 Rectangle& SetSize(const ::Vector2& size) { return SetSize(size.x, size.y); }
133
134 Rectangle& SetShapesTexture(const ::Texture2D& texture) {
135 ::SetShapesTexture(texture, *this);
136 return *this;
137 }
138
139 [[nodiscard]] Vector2 GetPosition() const { return {x, y}; }
140
141 Rectangle& SetPosition(float newX, float newY) {
142 x = newX;
143 y = newY;
144 return *this;
145 }
146
147 Rectangle& SetPosition(const ::Vector2& position) { return SetPosition(position.x, position.y); }
148protected:
149 void set(const ::Rectangle& rect) {
150 x = rect.x;
151 y = rect.y;
152 width = rect.width;
153 height = rect.height;
154 }
155};
156} // namespace raylib
157
159
160#endif // RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
Degree type (allows automatic worry free conversion between radians and degrees)
Rectangle type.
Definition: Rectangle.hpp:12
Rectangle GetCollision(::Rectangle rec2) const
Get collision rectangle for two rectangles collision.
Definition: Rectangle.hpp:108
bool CheckCollision(::Rectangle rec2) const
Check collision between two rectangles.
Definition: Rectangle.hpp:103
void Draw(::Color color) const
Draw a color-filled rectangle.
Definition: Rectangle.hpp:47
bool CheckCollision(::Vector2 center, float radius) const
Check collision between circle and rectangle.
Definition: Rectangle.hpp:120
bool CheckCollision(::Vector2 point) const
Check if point is inside rectangle.
Definition: Rectangle.hpp:115
Vector2 type.
Definition: Vector2.hpp:20
Vector4 type.
Definition: Vector4.hpp:21
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8