TGUI  0.9.5
Loading...
Searching...
No Matches
tgui::Rect< T > Class Template Reference

Public Member Functions

TGUI_CONSTEXPR Rect ()=default
 Default constructor.
 
template<typename U >
TGUI_CONSTEXPR Rect (const Rect< U > &rect)
 Constructs the rectangle from an another Rect with a different type.
 
TGUI_CONSTEXPR Rect (sf::Rect< T > rect)
 Constructs the rectangle from an sf::Rect.
 
TGUI_CONSTEXPR Rect (T rectLeft, T rectTop, T rectWidth, T rectHeight)
 Constructs the rectangle from its position and size.
 
TGUI_CONSTEXPR Rect (Vector2< T > position, Vector2< T > size)
 Constructs the rectangle from its position and size.
 
TGUI_CONSTEXPR void setPosition (Vector2< T > position)
 Sets the position of the rectangle.
 
TGUI_CONSTEXPR Vector2< T > getPosition () const
 Returns the position of the rectangle.
 
TGUI_CONSTEXPR void setSize (Vector2< T > size)
 Sets the size of the rectangle.
 
TGUI_CONSTEXPR Vector2< T > getSize () const
 Returns the size of the rectangle.
 
 operator sf::Rect< T > () const
 Converts the Rect to an sf::Rect.
 
TGUI_CONSTEXPR bool contains (const Vector2< T > &pos) const
 Check if a point is inside the rectangle's area.
 
TGUI_CONSTEXPR bool intersects (const Rect< T > &rect) const
 Check the intersection between two rectangles.
 

Public Attributes

left = 0
 Left coordinate of the rectangle.
 
top = 0
 Top coordinate of the rectangle.
 
width = 0
 Width of the rectangle.
 
height = 0
 Height of the rectangle.
 

Constructor & Destructor Documentation

◆ Rect() [1/5]

template<typename T >
TGUI_CONSTEXPR tgui::Rect< T >::Rect ( )
default

Default constructor.

Creates an empty rectangle (it is equivalent to calling Rect{0, 0, 0, 0}).

◆ Rect() [2/5]

template<typename T >
template<typename U >
TGUI_CONSTEXPR tgui::Rect< T >::Rect ( const Rect< U > &  rect)
inlineexplicit

Constructs the rectangle from an another Rect with a different type.

Parameters
rectRectangle to copy

◆ Rect() [3/5]

template<typename T >
TGUI_CONSTEXPR tgui::Rect< T >::Rect ( sf::Rect< T >  rect)
inlineexplicit

Constructs the rectangle from an sf::Rect.

Parameters
rectRectangle to initialize

◆ Rect() [4/5]

template<typename T >
TGUI_CONSTEXPR tgui::Rect< T >::Rect ( rectLeft,
rectTop,
rectWidth,
rectHeight 
)
inline

Constructs the rectangle from its position and size.

Parameters
rectLeftLeft coordinate of the rectangle
rectTopTop coordinate of the rectangle
rectWidthWidth of the rectangle
rectHeightHeight of the rectangle

◆ Rect() [5/5]

template<typename T >
TGUI_CONSTEXPR tgui::Rect< T >::Rect ( Vector2< T >  position,
Vector2< T >  size 
)
inline

Constructs the rectangle from its position and size.

Parameters
positionPosition of the top-left corner of the rectangle
sizeSize of the rectangle

Member Function Documentation

◆ contains()

template<typename T >
TGUI_CONSTEXPR bool tgui::Rect< T >::contains ( const Vector2< T > &  pos) const
inline

Check if a point is inside the rectangle's area.

This check is non-inclusive. If the point lies on the edge of the rectangle, this function will return false.

Parameters
posCoordinate to test
Returns
True if the point is inside, false otherwise
Warning
This code assumes the width and height are positive.

◆ getPosition()

template<typename T >
TGUI_CONSTEXPR Vector2< T > tgui::Rect< T >::getPosition ( ) const
inline

Returns the position of the rectangle.

Returns
Rectangle position

◆ getSize()

template<typename T >
TGUI_CONSTEXPR Vector2< T > tgui::Rect< T >::getSize ( ) const
inline

Returns the size of the rectangle.

Returns
Rectangle size

◆ intersects()

template<typename T >
TGUI_CONSTEXPR bool tgui::Rect< T >::intersects ( const Rect< T > &  rect) const
inline

Check the intersection between two rectangles.

Parameters
rectRectangle to test
Returns
True if rectangles overlap, false otherwise
Warning
This code assumes the width and height of both rectangles are positive.

◆ setPosition()

template<typename T >
TGUI_CONSTEXPR void tgui::Rect< T >::setPosition ( Vector2< T >  position)
inline

Sets the position of the rectangle.

Parameters
positionNew position for the rectangle

◆ setSize()

template<typename T >
TGUI_CONSTEXPR void tgui::Rect< T >::setSize ( Vector2< T >  size)
inline

Sets the size of the rectangle.

Parameters
sizeNew size for the rectangle

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