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]
Collaboration diagram for SDL::Rect:
Collaboration graph
[legend]

Public Member Functions

constexpr Rect (const RectRaw &r={})
 Wraps Rect. More...
 
constexpr Rect (int x, int y, int w, int h)
 Constructs from its fields. More...
 
constexpr Rect (const PointRaw &corner, const PointRaw &size)
 Construct from offset and size. More...
 
constexpr bool operator== (const RectRaw &other) const
 Compares with the underlying type.
 
constexpr bool operator== (const Rect &other) const
 Compares with the underlying type.
 
constexpr operator bool () const
 
constexpr int GetX () const
 Get left x coordinate. More...
 
constexpr RectSetX (int newX)
 Set the left x coordinate. More...
 
constexpr int GetY () const
 Get top y coordinate. More...
 
constexpr RectSetY (int newY)
 Set the top y coordinate. More...
 
constexpr int GetW () const
 Get width of the rect. More...
 
constexpr RectSetW (int newW)
 Set the width of the rect. More...
 
constexpr int GetH () const
 Get height of the rect. More...
 
constexpr RectSetH (int newH)
 Set the height of the rect. More...
 
constexpr int GetX2 () const
 Get X coordinate of the rect second corner. More...
 
constexpr RectSetX2 (int x2)
 Set X coordinate of the rect second corner. More...
 
constexpr int GetY2 () const
 Get Y coordinate of the rect second corner. More...
 
constexpr RectSetY2 (int y2)
 Set Y coordinate of the rect second corner. More...
 
constexpr Point GetTopLeft () const
 Get top left corner of the rect. More...
 
constexpr Point GetTopRight () const
 Get top right corner of the rect. More...
 
constexpr Point GetBottomLeft () const
 Get bottom left corner of the rect. More...
 
constexpr Point GetBottomRight () const
 Get bottom right corner of the rect. More...
 
constexpr Point GetSize () const
 Get size of the rect. More...
 
constexpr Point GetCentroid () const
 Get centroid of the rect. More...
 
bool GetLineIntersection (PointRaw *p1, PointRaw *p2) const
 Calculate the intersection of a rectangle and line segment. More...
 
bool GetLineIntersection (int *X1, int *Y1, int *X2, int *Y2) const
 Calculate the intersection of a rectangle and line segment. More...
 
constexpr operator SDL_FRect () const
 Convert an SDL_Rect to SDL_FRect. More...
 
constexpr operator FRect () const
 
constexpr bool Empty () const
 Determine whether a rectangle has no area. More...
 
constexpr bool Equal (const RectRaw &other) const
 Determine whether two rectangles are equal. More...
 
constexpr bool Contains (const PointRaw &p) const
 Check whether the rect contains given point. More...
 
constexpr bool Contains (const RectRaw &other) const
 Check whether the rect contains given point. More...
 
constexpr bool HasIntersection (const RectRaw &other) const
 Determine whether two rectangles intersect. More...
 
constexpr std::optional< RectGetIntersection (const RectRaw &other) const
 Calculate the intersection of two rectangles. More...
 
constexpr Rect GetUnion (const RectRaw &other) const
 Calculate the union of two rectangles. More...
 
constexpr Rect GetExtension (unsigned int amount) const
 Get a rect extended by specified amount of pixels. More...
 
constexpr Rect GetExtension (unsigned int hAmount, unsigned int vAmount) const
 Get a rect extended by specified amount of pixels. More...
 
constexpr RectExtend (unsigned int amount)
 Extend a rect by specified amount of pixels. More...
 
constexpr RectExtend (unsigned int hAmount, unsigned int vAmount)
 Extend a rect by specified amount of pixels. More...
 
constexpr Rect operator+ (const Point &offset) const
 Get rectangle moved by a given offset. More...
 
constexpr Rect operator- (const Point &offset) const
 Get rectangle moved by an opposite of given offset. More...
 
constexpr Rectoperator+= (const Point &offset)
 Move by then given offset. More...
 
constexpr Rectoperator-= (const Point &offset)
 Move by an opposite of the given offset. More...
 

Static Public Member Functions

static Rect GetEnclosingPoints (SpanRef< const PointRaw > points, OptionalRef< const RectRaw > clip=std::nullopt)
 Calculate a minimal rectangle enclosing a set of points. More...
 
static constexpr Rect FromCenter (int cx, int cy, int w, int h)
 Construct the rect from given center coordinates, width and height. More...
 
static constexpr Rect FromCenter (Point center, Point size)
 Construct the rect from given center coordinates and size. More...
 
static constexpr Rect FromCorners (int x1, int y1, int x2, int y2)
 Construct the rect from given corners coordinates. More...
 
static constexpr Rect FromCorners (Point p1, Point p2)
 Construct the rect from given centers coordinates. More...
 

Detailed Description

Since
This struct is available since SDL 3.2.0.
Category:
Wrap extending struct
See also
Rect.Empty
Rect.Equal
Rect.HasIntersection
Rect.GetIntersection
Rect.GetLineIntersection
Rect.GetUnion
Rect.GetEnclosingPoints

Constructor & Destructor Documentation

◆ Rect() [1/3]

constexpr SDL::Rect::Rect ( const RectRaw 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 PointRaw corner,
const PointRaw size 
)
inlineconstexpr
Parameters
cornerthe top-left corner
sizethe size

Member Function Documentation

◆ Contains() [1/2]

constexpr bool SDL::Rect::Contains ( const PointRaw 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 RectRaw other) const
inlineconstexpr
Parameters
otherPoint to check
Returns
True if the point is contained in the rect

◆ 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 ( 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

◆ FromCenter() [2/2]

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

◆ FromCorners() [1/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

◆ FromCorners() [2/2]

static constexpr Rect SDL::Rect::FromCorners ( Point  p1,
Point  p2 
)
inlinestaticconstexpr
Parameters
[in]p1Coordinates of the top left rectangle corner
[in]p2Coordinates 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

◆ 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

◆ GetLineIntersection()

bool SDL::Rect::GetLineIntersection ( PointRaw p1,
PointRaw 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.

◆ 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

◆ 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

◆ operator bool()

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

◆ operator FRect()

constexpr SDL::Rect::operator FRect ( ) const
constexpr
See also
operator ToFRect()

◆ 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

◆ 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: