-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathRectangle.hpp
More file actions
158 lines (127 loc) · 4.32 KB
/
Rectangle.hpp
File metadata and controls
158 lines (127 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
#define RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
#include "./raylib.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./Vector2.hpp"
namespace raylib {
/**
* Rectangle type
*/
class Rectangle : public ::Rectangle {
public:
Rectangle(const ::Rectangle& rect) : ::Rectangle{rect.x, rect.y, rect.width, rect.height} {}
Rectangle(float x = 0, float y = 0, float width = 0, float height = 0)
: ::Rectangle{x, y, width, height} {}
Rectangle(::Vector2 position, ::Vector2 size)
: ::Rectangle{position.x, position.y, size.x, size.y} {}
Rectangle(::Vector2 size) : ::Rectangle{0, 0, size.x, size.y} {}
Rectangle(::Vector4 rect) : ::Rectangle{rect.x, rect.y, rect.z, rect.w} {}
GETTERSETTER(float, X, x)
GETTERSETTER(float, Y, y)
GETTERSETTER(float, Width, width)
GETTERSETTER(float, Height, height)
Rectangle& operator=(const ::Rectangle& rect) {
set(rect);
return *this;
}
::Vector4 ToVector4() {
return {x, y, width, height};
}
operator ::Vector4() const {
return {x, y, width, height};
}
/**
* Draw a color-filled rectangle
*/
void Draw(::Color color) const {
::DrawRectangleRec(*this, color);
}
void Draw(::Vector2 origin, float rotation, ::Color color) const {
::DrawRectanglePro(*this, origin, rotation, color);
}
void DrawGradientV(::Color color1, ::Color color2) const {
::DrawRectangleGradientV(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
static_cast<int>(height), color1, color2);
}
void DrawGradientH(::Color color1, ::Color color2) const {
::DrawRectangleGradientH(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
static_cast<int>(height), color1, color2);
}
void DrawGradient(::Color col1, ::Color col2, ::Color col3, ::Color col4) const {
::DrawRectangleGradientEx(*this, col1, col2, col3, col4);
}
void DrawLines(::Color color) const {
::DrawRectangleLines(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
static_cast<int>(height), color);
}
void DrawLines(::Color color, float lineThick) const {
::DrawRectangleLinesEx(*this, lineThick, color);
}
void DrawRounded(float roundness, int segments, ::Color color) const {
::DrawRectangleRounded(*this, roundness, segments, color);
}
void DrawRoundedLines(float roundness, int segments,
float lineThick, ::Color color) const {
::DrawRectangleRoundedLines(*this, roundness, segments, lineThick, color);
}
/**
* Check collision between two rectangles
*/
bool CheckCollision(::Rectangle rec2) const {
return ::CheckCollisionRecs(*this, rec2);
}
/**
* Get collision rectangle for two rectangles collision
*/
::Rectangle GetCollision(::Rectangle rec2) const {
return ::GetCollisionRec(*this, rec2);
}
/**
* Check if point is inside rectangle
*/
bool CheckCollision(::Vector2 point) const {
return ::CheckCollisionPointRec(point, *this);
}
/**
* Check collision between circle and rectangle
*/
bool CheckCollision(::Vector2 center, float radius) const {
return ::CheckCollisionCircleRec(center, radius, *this);
}
Vector2 GetSize() const {
return {width, height};
}
Rectangle& SetSize(float newWidth, float newHeight) {
width = newWidth;
height = newHeight;
return *this;
}
Rectangle& SetSize(const ::Vector2& size) {
return SetSize(size.x, size.y);
}
Rectangle& SetShapesTexture(const ::Texture2D& texture) {
::SetShapesTexture(texture, *this);
return *this;
}
Vector2 GetPosition() const {
return {x, y};
}
Rectangle& SetPosition(float newX, float newY) {
x = newX;
y = newY;
return *this;
}
Rectangle& SetPosition(const ::Vector2& position) {
return SetPosition(position.x, position.y);
}
protected:
void set(const ::Rectangle& rect) {
x = rect.x;
y = rect.y;
width = rect.width;
height = rect.height;
}
};
} // namespace raylib
using RRectangle = raylib::Rectangle;
#endif // RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_