mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-09-09 07:18:45 -04:00
Add various Rect constructors
This commit is contained in:
parent
a5d558b1c1
commit
837772dac0
@ -39,6 +39,13 @@ Rect::Rect(const SDL_Rect& rect) {
|
||||
h = rect.h;
|
||||
}
|
||||
|
||||
Rect::Rect(const Point& corner, const Point& size) {
|
||||
x = corner.x;
|
||||
y = corner.y;
|
||||
w = size.x;
|
||||
h = size.y;
|
||||
}
|
||||
|
||||
Rect::Rect(int nx, int ny, int nw, int nh) {
|
||||
x = nx;
|
||||
y = ny;
|
||||
@ -71,6 +78,18 @@ Rect Rect::FromCenter(int cx, int cy, int w, int h) {
|
||||
return Rect(cx - w/2, cy - h/2, w, h);
|
||||
}
|
||||
|
||||
Rect Rect::FromCenter(const Point& center, const Point& size) {
|
||||
return Rect(center - size / 2, size);
|
||||
}
|
||||
|
||||
Rect Rect::FromCorners(int x1, int y1, int x2, int y2) {
|
||||
return Rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
|
||||
}
|
||||
|
||||
Rect Rect::FromCorners(const Point& p1, const Point& p2) {
|
||||
return Rect(p1, p2 - p1 + Point(1, 1));
|
||||
}
|
||||
|
||||
bool Rect::IsNull() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -66,6 +66,15 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect(const SDL_Rect& rect);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the rect from given corner coordinates, and size
|
||||
///
|
||||
/// \param corner Coordinates of the top left rectangle corner
|
||||
/// \param size Dimensions of the rectangle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect(const Point& corner, const Point& size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the rect from given corner coordinates, width and height
|
||||
///
|
||||
@ -90,6 +99,35 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
static Rect FromCenter(int cx, int cy, int w, int h);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the rect from given center coordinates and size
|
||||
///
|
||||
/// \param center Coordinates of the rectangle center
|
||||
/// \param size Dimensions of the rectangle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Rect FromCenter(const Point& center, const Point& size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the rect from given center coordinates, width and height
|
||||
///
|
||||
/// \param x1 X coordinate of the top left rectangle corner
|
||||
/// \param y1 Y coordinate of the top left rectangle corner
|
||||
/// \param x2 X coordinate of the bottom right rectangle corner
|
||||
/// \param y2 Y coordinate of the bottom right rectangle corner
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Rect FromCorners(int x1, int y1, int x2, int y2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the rect from given center coordinates and size
|
||||
///
|
||||
/// \param p1 Coordinates of the top left rectangle corner
|
||||
/// \param p2 Coordinates of the bottom right rectangle corner
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Rect FromCorners(const Point& p1, const Point& p2);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy constructor
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user