raylib-cpp
C++ object-oriented wrapper library for raylib.
Rectangle.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_RECTANGLE_HPP_
26 #define RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
27 
28 #include "./raylib.hpp"
29 #include "./raylib-cpp-utils.hpp"
30 #include "./Vector2.hpp"
31 
32 namespace raylib {
33 class Rectangle : public ::Rectangle {
34  public:
36  set(vec);
37  }
38 
39  Rectangle(float x, float y, float width, float height) : ::Rectangle{x, y, width, height} {}
40  Rectangle(float x, float y, float width) : ::Rectangle{x, y, width, height} {}
41  Rectangle(float x, float y) : ::Rectangle{x, y, 0, 0} {}
42  Rectangle(float x) : ::Rectangle{x, 0, 0, 0} {}
43  Rectangle() : ::Rectangle{0, 0, 0, 0} {}
44 
45  GETTERSETTER(float, X, x)
46  GETTERSETTER(float, Y, y)
47  GETTERSETTER(float, Width, width)
48  GETTERSETTER(float, Height, height)
49 
50  Rectangle& operator=(const ::Rectangle& rect) {
51  set(rect);
52  return *this;
53  }
54 
55  Rectangle& operator=(const Rectangle& rect) {
56  set(rect);
57  return *this;
58  }
59 
63  inline Rectangle& Draw(::Color color) {
64  ::DrawRectangle(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
65  static_cast<int>(height), color);
66  return *this;
67  }
68 
69  inline Rectangle& Draw(::Vector2 origin, float rotation, ::Color color) {
70  ::DrawRectanglePro(*this, origin, rotation, color);
71  return *this;
72  }
73 
74  inline Rectangle& DrawGradientV(::Color color1, ::Color color2) {
75  ::DrawRectangleGradientV(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
76  static_cast<int>(height), color1, color2);
77  return *this;
78  }
79 
80  inline Rectangle& DrawGradientH(::Color color1, ::Color color2) {
81  ::DrawRectangleGradientH(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
82  static_cast<int>(height), color1, color2);
83  return *this;
84  }
85 
86  inline Rectangle& DrawGradient(::Color col1, ::Color col2, ::Color col3, ::Color col4) {
87  ::DrawRectangleGradientEx(*this, col1, col2, col3, col4);
88  return *this;
89  }
90 
91  inline Rectangle& DrawLines(::Color color) {
92  ::DrawRectangleLines(static_cast<int>(x), static_cast<int>(y), static_cast<int>(width),
93  static_cast<int>(height), color);
94  return *this;
95  }
96 
97  inline Rectangle& DrawLinesEx(int lineThick, ::Color color) {
98  ::DrawRectangleLinesEx(*this, lineThick, color);
99  return *this;
100  }
101 
102  inline Rectangle& DrawRounded(float roundness, int segments, ::Color color) {
103  ::DrawRectangleRounded(*this, roundness, segments, color);
104  return *this;
105  }
106 
107  inline Rectangle& DrawRoundedLines(float roundness, int segments, int lineThick,
108  ::Color color) {
109  ::DrawRectangleRoundedLines(*this, roundness, segments, lineThick, color);
110  return *this;
111  }
112 
116  inline bool CheckCollision(::Rectangle rec2) const {
117  return ::CheckCollisionRecs(*this, rec2);
118  }
119 
123  inline ::Rectangle GetCollision(::Rectangle rec2) const {
124  return ::GetCollisionRec(*this, rec2);
125  }
126 
130  inline bool CheckCollision(::Vector2 point) const {
131  return ::CheckCollisionPointRec(point, *this);
132  }
133 
137  inline bool CheckCollision(::Vector2 center, float radius) {
138  return ::CheckCollisionCircleRec(center, radius, *this);
139  }
140 
141  protected:
142  inline void set(::Rectangle rect) {
143  x = rect.x;
144  y = rect.y;
145  width = rect.width;
146  height = rect.height;
147  }
148 };
149 } // namespace raylib
150 
151 #endif // RAYLIB_CPP_INCLUDE_RECTANGLE_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Rectangle::Rectangle
Rectangle(float x)
Definition: Rectangle.hpp:42
raylib::Rectangle::DrawRounded
Rectangle & DrawRounded(float roundness, int segments, ::Color color)
Definition: Rectangle.hpp:102
raylib::Rectangle::set
void set(::Rectangle rect)
Definition: Rectangle.hpp:142
raylib::Rectangle::DrawGradientH
Rectangle & DrawGradientH(::Color color1, ::Color color2)
Definition: Rectangle.hpp:80
raylib::Rectangle::Draw
Rectangle & Draw(::Vector2 origin, float rotation, ::Color color)
Definition: Rectangle.hpp:69
raylib::Rectangle::DrawLinesEx
Rectangle & DrawLinesEx(int lineThick, ::Color color)
Definition: Rectangle.hpp:97
raylib::Rectangle::DrawGradientV
Rectangle & DrawGradientV(::Color color1, ::Color color2)
Definition: Rectangle.hpp:74
raylib::Rectangle::DrawLines
Rectangle & DrawLines(::Color color)
Definition: Rectangle.hpp:91
raylib::Rectangle::CheckCollision
bool CheckCollision(::Vector2 point) const
Check if point is inside rectangle.
Definition: Rectangle.hpp:130
raylib::Rectangle::CheckCollision
bool CheckCollision(::Vector2 center, float radius)
Check collision between circle and rectangle.
Definition: Rectangle.hpp:137
raylib::Rectangle
Definition: Rectangle.hpp:33
raylib::Vector2
Definition: Vector2.hpp:37
raylib::Rectangle::Rectangle
Rectangle(::Rectangle vec)
Definition: Rectangle.hpp:35
raylib::Color
Definition: Color.hpp:35
raylib::Rectangle::Rectangle
Rectangle(float x, float y, float width)
Definition: Rectangle.hpp:40
raylib::Rectangle::GetCollision
inline ::Rectangle GetCollision(::Rectangle rec2) const
Get collision rectangle for two rectangles collision.
Definition: Rectangle.hpp:123
raylib::Rectangle::Rectangle
Rectangle(float x, float y)
Definition: Rectangle.hpp:41
raylib::Rectangle::Rectangle
Rectangle(float x, float y, float width, float height)
Definition: Rectangle.hpp:39
raylib::Rectangle::DrawGradient
Rectangle & DrawGradient(::Color col1, ::Color col2, ::Color col3, ::Color col4)
Definition: Rectangle.hpp:86
raylib::Rectangle::CheckCollision
bool CheckCollision(::Rectangle rec2) const
Check collision between two rectangles.
Definition: Rectangle.hpp:116
raylib::Rectangle::Rectangle
Rectangle()
Definition: Rectangle.hpp:43
raylib::Rectangle::Draw
Rectangle & Draw(::Color color)
Draw a color-filled rectangle.
Definition: Rectangle.hpp:63
raylib::Rectangle::DrawRoundedLines
Rectangle & DrawRoundedLines(float roundness, int segments, int lineThick, ::Color color)
Definition: Rectangle.hpp:107
raylib::Rectangle::operator=
Rectangle & operator=(const Rectangle &rect)
Definition: Rectangle.hpp:55