SDL3pp
A slim C++ wrapper for SDL3
|
A rectangle, with the origin at the upper left (using integers). More...
Public Member Functions | |
constexpr | Rect (const SDL_Rect &r={}) |
Wraps Rect. | |
constexpr | Rect (int x, int y, int w, int h) |
Constructs from its fields. | |
constexpr | Rect (const SDL_Point &corner, const SDL_Point &size) |
Construct from offset and size. | |
constexpr bool | operator== (const Rect &other) const |
constexpr bool | operator== (const SDL_Rect &r) const |
Compares with the underlying type. | |
constexpr | operator bool () const |
constexpr int | GetX () const |
Get left x coordinate. | |
constexpr Rect & | SetX (int newX) |
Set the left x coordinate. | |
constexpr int | GetY () const |
Get top y coordinate. | |
constexpr Rect & | SetY (int newY) |
Set the top y coordinate. | |
constexpr int | GetW () const |
Get width of the rect. | |
constexpr Rect & | SetW (int newW) |
Set the width of the rect. | |
constexpr int | GetH () const |
Get height of the rect. | |
constexpr Rect & | SetH (int newH) |
Set the height of the rect. | |
constexpr int | GetX2 () const |
Get X coordinate of the rect second corner. | |
constexpr Rect & | SetX2 (int x2) |
Set X coordinate of the rect second corner. | |
constexpr int | GetY2 () const |
Get Y coordinate of the rect second corner. | |
constexpr Rect & | SetY2 (int y2) |
Set Y coordinate of the rect second corner. | |
constexpr Point | GetTopLeft () const |
Get top left corner of the rect. | |
constexpr Point | GetTopRight () const |
Get top right corner of the rect. | |
constexpr Point | GetBottomLeft () const |
Get bottom left corner of the rect. | |
constexpr Point | GetBottomRight () const |
Get bottom right corner of the rect. | |
constexpr Point | GetSize () const |
Get size of the rect. | |
constexpr Point | GetCentroid () const |
Get centroid of the rect. | |
bool | IntersectLine (int *X1, int *Y1, int *X2, int *Y2) const |
Calculate the intersection of a rectangle and line segment. | |
bool | IntersectLine (Point *p1, Point *p2) const |
Calculate the intersection of a rectangle and line segment. | |
constexpr | operator FRect () const |
Convert an SDL_Rect to SDL_FRect. | |
constexpr | operator SDL_FRect () const |
constexpr bool | Empty () const |
Determine whether a rectangle has no area. | |
constexpr bool | Equal (const Rect &other) const |
Determine whether two rectangles are equal. | |
constexpr bool | Contains (const Point &p) const |
Check whether the rect contains given point. | |
constexpr bool | Contains (const Rect &other) const |
Check whether the rect contains given point. | |
bool | HasIntersection (const Rect &other) const |
Determine whether two rectangles intersect. | |
constexpr std::optional< Rect > | GetIntersection (const Rect &other) const |
Calculate the intersection of two rectangles. | |
constexpr Rect | GetUnion (const Rect &other) const |
Calculate the union of two rectangles. | |
constexpr Rect | GetExtension (unsigned int amount) const |
Get a rect extended by specified amount of pixels. | |
constexpr Rect | GetExtension (unsigned int hAmount, unsigned int vAmount) const |
Get a rect extended by specified amount of pixels. | |
constexpr Rect & | Extend (unsigned int amount) |
Extend a rect by specified amount of pixels. | |
constexpr Rect & | Extend (unsigned int hAmount, unsigned int vAmount) |
Extend a rect by specified amount of pixels. | |
constexpr Rect | operator+ (const Point &offset) const |
Get rectangle moved by a given offset. | |
constexpr Rect | operator- (const Point &offset) const |
Get rectangle moved by an opposite of given offset. | |
constexpr Rect & | operator+= (const Point &offset) |
Move by then given offset. | |
constexpr Rect & | operator-= (const Point &offset) |
Move by an opposite of the given offset. | |
Static Public Member Functions | |
static Rect | GetEnclosingPoints (SpanRef< const SDL_Point > points, OptionalRef< const SDL_Rect > clip=std::nullopt) |
Calculate a minimal rectangle enclosing a set of points. | |
static constexpr Rect | FromCenter (int cx, int cy, int w, int h) |
Construct the rect from given center coordinates, width and height. | |
static constexpr Rect | FromCenter (const Point ¢er, const Point &size) |
Construct the rect from given center coordinates and size. | |
static constexpr Rect | FromCorners (int x1, int y1, int x2, int y2) |
Construct the rect from given corners coordinates. | |
static constexpr Rect | FromCorners (const Point &p1, const Point &p2) |
Construct the rect from given centers coordinates. | |
|
inlineconstexpr |
r | the value to be wrapped |
|
inlineconstexpr |
x | the left x. |
y | the top y. |
w | the width. |
h | the height. |
|
inlineconstexpr |
corner | the top-left corner |
size | the size |
|
inlineconstexpr |
p | Point to check |
|
inlineconstexpr |
other | Point to check |
|
inlineconstexpr |
A rectangle is considered "empty" for this function if r
is NULL, or if r
's width and/or height are <= 0.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
|
inlineconstexpr |
Rectangles are considered equal if both are not NULL and each of their x, y, width and height match.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
other | the second rectangle to test. |
|
inlineconstexpr |
[in] | amount | Number of pixels to extend by |
|
inlineconstexpr |
[in] | hAmount | Number of pixels to extend by in horizontal direction |
[in] | vAmount | Number of pixels to extend by in vertical direction |
|
inlinestaticconstexpr |
[in] | center | Coordinates of the rectangle center |
[in] | size | Dimensions of the rectangle |
|
inlinestaticconstexpr |
[in] | cx | X coordinate of the rectangle center |
[in] | cy | Y coordinate of the rectangle center |
[in] | w | Width of the rectangle |
[in] | h | Height of the rectangle |
|
inlinestaticconstexpr |
[in] | p1 | Coordinates of the top left rectangle corner |
[in] | p2 | Coordinates of the bottom right rectangle corner |
|
inlinestaticconstexpr |
[in] | x1 | X coordinate of the top left rectangle corner |
[in] | y1 | Y coordinate of the top left rectangle corner |
[in] | x2 | X coordinate of the bottom right rectangle corner |
[in] | y2 | Y coordinate of the bottom right rectangle corner |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlinestatic |
If clip
is not nullptr then only points inside of the clipping rectangle are considered.
points | a span of SDL_Point structures representing points to be enclosed. |
clip | an SDL_Rect used for clipping or std::nullopt to enclose all points. |
|
inlineconstexpr |
[in] | amount | Number of pixels to extend by |
|
inlineconstexpr |
[in] | hAmount | Number of pixels to extend by in horizontal direction |
[in] | vAmount | Number of pixels to extend by in vertical direction |
|
inlineconstexpr |
|
inlineconstexpr |
If result
is NULL then this function will return false.
other | an SDL_Rect structure representing the second rectangle. |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inline |
other | an SDL_Rect structure representing the second rectangle. |
|
inline |
This function is used to clip a line segment to a rectangle. A line segment contained entirely within the rectangle or that does not intersect will remain unchanged. A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates saved in X1
, Y1
, X2
, and/or Y2
as necessary.
X1 | a pointer to the starting X-coordinate of the line. |
Y1 | a pointer to the starting Y-coordinate of the line. |
X2 | a pointer to the ending X-coordinate of the line. |
Y2 | a pointer to the ending Y-coordinate of the line. |
[in,out] | p1 | Starting coordinates of the line |
[in,out] | p2 | Ending coordinates of the line |
This function is used to clip a line segment to a rectangle. A line segment contained entirely within the rectangle or that does not intersect will remain unchanged. A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates saved in p1 and/or p2 as necessary.
|
inlineconstexpr |
|
constexpr |
|
inlineconstexpr |
[in] | offset | Point specifying an offset |
[in] | offset | Point specifying an offset |
[in] | offset | Point specifying an offset |
[in] | offset | Point specifying an offset |
|
inlineconstexpr |
newH | the new height. |
|
inlineconstexpr |
newW | the new width. |
|
inlineconstexpr |
newX | the new left x. |
|
inlineconstexpr |
[in] | x2 | New X coordinate value |
This modifies rectangle width internally
|
inlineconstexpr |
newY | the new top y. |
|
inlineconstexpr |
[in] | y2 | New Y coordinate value |
This modifies rectangle height internally