SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
SDL::Rect Struct Reference

A rectangle, with the origin at the upper left (using integers). More...

Inheritance diagram for SDL::Rect:
Inheritance graph
[legend]

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 RectSetX (int newX)
 Set the left x coordinate.
 
constexpr int GetY () const
 Get top y coordinate.
 
constexpr RectSetY (int newY)
 Set the top y coordinate.
 
constexpr int GetW () const
 Get width of the rect.
 
constexpr RectSetW (int newW)
 Set the width of the rect.
 
constexpr int GetH () const
 Get height of the rect.
 
constexpr RectSetH (int newH)
 Set the height of the rect.
 
constexpr int GetX2 () const
 Get X coordinate of the rect second corner.
 
constexpr RectSetX2 (int x2)
 Set X coordinate of the rect second corner.
 
constexpr int GetY2 () const
 Get Y coordinate of the rect second corner.
 
constexpr RectSetY2 (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< RectGetIntersection (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 RectExtend (unsigned int amount)
 Extend a rect by specified amount of pixels.
 
constexpr RectExtend (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 Rectoperator+= (const Point &offset)
 Move by then given offset.
 
constexpr Rectoperator-= (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 &center, 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.
 

Detailed Description

Category:
Wrap extending struct
See also
wrap-extending-struct

Constructor & Destructor Documentation

◆ Rect() [1/3]

constexpr SDL::Rect::Rect ( const SDL_Rect &  r = {})
inlineconstexpr
Parameters
rthe value to be wrapped

◆ Rect() [2/3]

constexpr SDL::Rect::Rect ( int  x,
int  y,
int  w,
int  h 
)
inlineconstexpr
Parameters
xthe left x.
ythe top y.
wthe width.
hthe height.

◆ Rect() [3/3]

constexpr SDL::Rect::Rect ( const SDL_Point &  corner,
const SDL_Point &  size 
)
inlineconstexpr
Parameters
cornerthe top-left corner
sizethe size

Member Function Documentation

◆ Contains() [1/2]

constexpr bool SDL::Rect::Contains ( const Point p) const
inlineconstexpr
Parameters
pPoint to check
Returns
True if the point is contained in the rect

◆ Contains() [2/2]

constexpr bool SDL::Rect::Contains ( const Rect other) const
inlineconstexpr
Parameters
otherPoint to check
Returns
True if the point is contained in the rect

◆ Empty()

constexpr bool SDL::Rect::Empty ( ) const
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).

Returns
true if the rectangle is "empty", false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ Equal()

constexpr bool SDL::Rect::Equal ( const Rect other) const
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).

Parameters
otherthe second rectangle to test.
Returns
true if the rectangles are equal, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ Extend() [1/2]

constexpr Rect & SDL::Rect::Extend ( unsigned int  amount)
inlineconstexpr
Parameters
[in]amountNumber of pixels to extend by
Returns
Reference to self

◆ Extend() [2/2]

constexpr Rect & SDL::Rect::Extend ( unsigned int  hAmount,
unsigned int  vAmount 
)
inlineconstexpr
Parameters
[in]hAmountNumber of pixels to extend by in horizontal direction
[in]vAmountNumber of pixels to extend by in vertical direction
Returns
Reference to self

◆ FromCenter() [1/2]

static constexpr Rect SDL::Rect::FromCenter ( const Point center,
const Point size 
)
inlinestaticconstexpr
Parameters
[in]centerCoordinates of the rectangle center
[in]sizeDimensions of the rectangle

◆ FromCenter() [2/2]

static constexpr Rect SDL::Rect::FromCenter ( int  cx,
int  cy,
int  w,
int  h 
)
inlinestaticconstexpr
Parameters
[in]cxX coordinate of the rectangle center
[in]cyY coordinate of the rectangle center
[in]wWidth of the rectangle
[in]hHeight of the rectangle

◆ FromCorners() [1/2]

static constexpr Rect SDL::Rect::FromCorners ( const Point p1,
const Point p2 
)
inlinestaticconstexpr
Parameters
[in]p1Coordinates of the top left rectangle corner
[in]p2Coordinates of the bottom right rectangle corner

◆ FromCorners() [2/2]

static constexpr Rect SDL::Rect::FromCorners ( int  x1,
int  y1,
int  x2,
int  y2 
)
inlinestaticconstexpr
Parameters
[in]x1X coordinate of the top left rectangle corner
[in]y1Y coordinate of the top left rectangle corner
[in]x2X coordinate of the bottom right rectangle corner
[in]y2Y coordinate of the bottom right rectangle corner

◆ GetBottomLeft()

constexpr Point SDL::Rect::GetBottomLeft ( ) const
inlineconstexpr
Returns
bottom left corner of the rect

◆ GetBottomRight()

constexpr Point SDL::Rect::GetBottomRight ( ) const
inlineconstexpr
Returns
Bottom right corner of the rect

◆ GetCentroid()

constexpr Point SDL::Rect::GetCentroid ( ) const
inlineconstexpr
Returns
Centroid of the rect

◆ GetEnclosingPoints()

static Rect SDL::Rect::GetEnclosingPoints ( SpanRef< const SDL_Point >  points,
OptionalRef< const SDL_Rect >  clip = std::nullopt 
)
inlinestatic

If clip is not nullptr then only points inside of the clipping rectangle are considered.

Parameters
pointsa span of SDL_Point structures representing points to be enclosed.
clipan SDL_Rect used for clipping or std::nullopt to enclose all points.
Returns
a SDL_Rect structure filled in with the minimal enclosing rectangle or an empty rect if all the points were outside of the clipping rectangle.
Since
This function is available since SDL 3.2.0.

◆ GetExtension() [1/2]

constexpr Rect SDL::Rect::GetExtension ( unsigned int  amount) const
inlineconstexpr
Parameters
[in]amountNumber of pixels to extend by
Returns
Extended rect

◆ GetExtension() [2/2]

constexpr Rect SDL::Rect::GetExtension ( unsigned int  hAmount,
unsigned int  vAmount 
) const
inlineconstexpr
Parameters
[in]hAmountNumber of pixels to extend by in horizontal direction
[in]vAmountNumber of pixels to extend by in vertical direction
Returns
Extended rect

◆ GetH()

constexpr int SDL::Rect::GetH ( ) const
inlineconstexpr
Returns
Height of the rect

◆ GetIntersection()

constexpr std::optional< Rect > SDL::Rect::GetIntersection ( const Rect other) const
inlineconstexpr

If result is NULL then this function will return false.

Parameters
otheran SDL_Rect structure representing the second rectangle.
Returns
an SDL_Rect structure filled in with the intersection of if there is intersection, std::nullopt otherwise.
Since
This function is available since SDL 3.2.0.
See also
HasIntersection()

◆ GetSize()

constexpr Point SDL::Rect::GetSize ( ) const
inlineconstexpr
Returns
Size of the rect

◆ GetTopLeft()

constexpr Point SDL::Rect::GetTopLeft ( ) const
inlineconstexpr
Returns
Top left corner of the rect

◆ GetTopRight()

constexpr Point SDL::Rect::GetTopRight ( ) const
inlineconstexpr
Returns
Top right corner of the rect

◆ GetUnion()

constexpr Rect SDL::Rect::GetUnion ( const Rect other) const
inlineconstexpr
Parameters
otheran SDL_Rect structure representing the second rectangle.
Returns
Rect representing union of two rectangles
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.

◆ GetW()

constexpr int SDL::Rect::GetW ( ) const
inlineconstexpr
Returns
Width of the rect

◆ GetX()

constexpr int SDL::Rect::GetX ( ) const
inlineconstexpr
Returns
coordinate of the left x

◆ GetX2()

constexpr int SDL::Rect::GetX2 ( ) const
inlineconstexpr
Returns
X coordinate of the rect second corner

◆ GetY()

constexpr int SDL::Rect::GetY ( ) const
inlineconstexpr
Returns
coordinate of the top y.

◆ GetY2()

constexpr int SDL::Rect::GetY2 ( ) const
inlineconstexpr
Returns
Y coordinate of the rect second corner

◆ HasIntersection()

bool SDL::Rect::HasIntersection ( const Rect other) const
inline
Parameters
otheran SDL_Rect structure representing the second rectangle.
Returns
true if there is an intersection, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
GetIntersection()

◆ IntersectLine() [1/2]

bool SDL::Rect::IntersectLine ( int *  X1,
int *  Y1,
int *  X2,
int *  Y2 
) const
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.

Parameters
X1a pointer to the starting X-coordinate of the line.
Y1a pointer to the starting Y-coordinate of the line.
X2a pointer to the ending X-coordinate of the line.
Y2a pointer to the ending Y-coordinate of the line.
Returns
true if there is an intersection, false otherwise.
Since
This function is available since SDL 3.2.0.

◆ IntersectLine() [2/2]

bool SDL::Rect::IntersectLine ( Point p1,
Point p2 
) const
inline
Parameters
[in,out]p1Starting coordinates of the line
[in,out]p2Ending coordinates of the line
Returns
True if there is an intersection, false otherwise

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.

◆ operator bool()

constexpr SDL::Rect::operator bool ( ) const
inlineconstexpr
See also
Empty()

◆ operator FRect()

constexpr SDL::Rect::operator FRect ( ) const
constexpr
Returns
A FRect filled in with the floating point representation of rect.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ operator SDL_FRect()

constexpr SDL::Rect::operator SDL_FRect ( ) const
inlineconstexpr
See also
operator FRect()

◆ operator+()

constexpr Rect SDL::Rect::operator+ ( const Point offset) const
inlineconstexpr
Parameters
[in]offsetPoint specifying an offset
Returns
Moved rectangle

◆ operator+=()

constexpr Rect & SDL::Rect::operator+= ( const Point offset)
inlineconstexpr
Parameters
[in]offsetPoint specifying an offset
Returns
Reference to self

◆ operator-()

constexpr Rect SDL::Rect::operator- ( const Point offset) const
inlineconstexpr
Parameters
[in]offsetPoint specifying an offset
Returns
Moved rectangle

◆ operator-=()

constexpr Rect & SDL::Rect::operator-= ( const Point offset)
inlineconstexpr
Parameters
[in]offsetPoint specifying an offset
Returns
Reference to self

◆ operator==()

constexpr bool SDL::Rect::operator== ( const Rect other) const
inlineconstexpr
See also
Equal()

◆ SetH()

constexpr Rect & SDL::Rect::SetH ( int  newH)
inlineconstexpr
Parameters
newHthe new height.
Returns
Reference to self.

◆ SetW()

constexpr Rect & SDL::Rect::SetW ( int  newW)
inlineconstexpr
Parameters
newWthe new width.
Returns
Reference to self.

◆ SetX()

constexpr Rect & SDL::Rect::SetX ( int  newX)
inlineconstexpr
Parameters
newXthe new left x.
Returns
Reference to self.

◆ SetX2()

constexpr Rect & SDL::Rect::SetX2 ( int  x2)
inlineconstexpr
Parameters
[in]x2New X coordinate value

This modifies rectangle width internally

Returns
Reference to self

◆ SetY()

constexpr Rect & SDL::Rect::SetY ( int  newY)
inlineconstexpr
Parameters
newYthe new top y.
Returns
Reference to self.

◆ SetY2()

constexpr Rect & SDL::Rect::SetY2 ( int  y2)
inlineconstexpr
Parameters
[in]y2New Y coordinate value

This modifies rectangle height internally

Returns
Reference to self

The documentation for this struct was generated from the following file: