raylib-cpp
C++ object-oriented wrapper library for raylib.
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 
8 namespace raylib {
12 class Rectangle : public ::Rectangle {
13  public:
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)
23  : ::Rectangle{position.x, position.y, size.x, size.y} {}
24  Rectangle(::Vector2 size) : ::Rectangle{0, 0, size.x, size.y} {}
25  Rectangle(::Vector4 rect) : ::Rectangle{rect.x, rect.y, rect.z, rect.w} {}
26 
27  GETTERSETTER(float, X, x)
28  GETTERSETTER(float, Y, y)
29  GETTERSETTER(float, Width, width)
30  GETTERSETTER(float, Height, height)
31 
32  Rectangle& operator=(const ::Rectangle& rect) {
33  set(rect);
34  return *this;
35  }
36 
37  inline ::Vector4 ToVector4() {
38  return {x, y, width, height};
39  }
40 
41  operator ::Vector4() const {
42  return {x, y, width, height};
43  }
44 
48  inline void Draw(::Color color) const {
49  ::DrawRectangleRec(*this, color);
50  }
51 
52  inline void Draw(::Vector2 origin, float rotation, ::Color color) const {
53  ::DrawRectanglePro(*this, origin, rotation, color);
54  }
55 
56  inline void DrawGradientV(::Color color1, ::Color color2) const {
57  ::DrawRectangleGradientV(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
58  static_cast<int>(height), color1, color2);
59  }
60 
61  inline void DrawGradientH(::Color color1, ::Color color2) const {
62  ::DrawRectangleGradientH(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
63  static_cast<int>(height), color1, color2);
64  }
65 
66  inline void DrawGradient(::Color col1, ::Color col2, ::Color col3, ::Color col4) const {
67  ::DrawRectangleGradientEx(*this, col1, col2, col3, col4);
68  }
69 
70  inline void DrawLines(::Color color) const {
71  ::DrawRectangleLines(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
72  static_cast<int>(height), color);
73  }
74 
75  inline void DrawLines(::Color color, float lineThick) const {
76  ::DrawRectangleLinesEx(*this, lineThick, color);
77  }
78 
79  inline void DrawRounded(float roundness, int segments, ::Color color) const {
80  ::DrawRectangleRounded(*this, roundness, segments, color);
81  }
82 
83  inline void DrawRoundedLines(float roundness, int segments,
84  float lineThick, ::Color color) const {
85  ::DrawRectangleRoundedLines(*this, roundness, segments, lineThick, color);
86  }
87 
91  inline bool CheckCollision(::Rectangle rec2) const {
92  return ::CheckCollisionRecs(*this, rec2);
93  }
94 
98  inline ::Rectangle GetCollision(::Rectangle rec2) const {
99  return ::GetCollisionRec(*this, rec2);
100  }
101 
105  inline bool CheckCollision(::Vector2 point) const {
106  return ::CheckCollisionPointRec(point, *this);
107  }
108 
112  inline bool CheckCollision(::Vector2 center, float radius) {
113  return ::CheckCollisionCircleRec(center, radius, *this);
114  }
115 
116  inline Vector2 GetSize() {
117  return {width, height};
118  }
119 
120  inline Rectangle& SetSize(float newWidth, float newHeight) {
121  width = newWidth;
122  height = newHeight;
123  return *this;
124  }
125 
126  inline Rectangle& SetSize(const ::Vector2& size) {
127  return SetSize(size.x, size.y);
128  }
129 
130  inline Rectangle& SetShapesTexture(const ::Texture2D& texture) {
131  ::SetShapesTexture(texture, *this);
132  return *this;
133  }
134 
135  inline Vector2 GetPosition() {
136  return {x, y};
137  }
138 
139  inline Rectangle& SetPosition(float newX, float newY) {
140  x = newX;
141  y = newY;
142  return *this;
143  }
144 
145  inline Rectangle& SetPosition(const ::Vector2& position) {
146  return SetPosition(position.x, position.y);
147  }
148 
149  private:
150  void set(const ::Rectangle& rect) {
151  x = rect.x;
152  y = rect.y;
153  width = rect.width;
154  height = rect.height;
155  }
156 };
157 } // namespace raylib
158 
160 
161 #endif // RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
Color type, RGBA (32bit)
Definition: Color.hpp:14
Rectangle type.
Definition: Rectangle.hpp:12
bool CheckCollision(::Rectangle rec2) const
Check collision between two rectangles.
Definition: Rectangle.hpp:91
inline ::Rectangle GetCollision(::Rectangle rec2) const
Get collision rectangle for two rectangles collision.
Definition: Rectangle.hpp:98
void Draw(::Color color) const
Draw a color-filled rectangle.
Definition: Rectangle.hpp:48
bool CheckCollision(::Vector2 center, float radius)
Check collision between circle and rectangle.
Definition: Rectangle.hpp:112
bool CheckCollision(::Vector2 point) const
Check if point is inside rectangle.
Definition: Rectangle.hpp:105
Vector2 type.
Definition: Vector2.hpp:16
Vector4 type.
Definition: Vector4.hpp:17
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8