Back to index

libsfml  1.6+dfsg2
Public Member Functions | Public Attributes
sf::Rect< T > Class Template Reference

Rect is an utility class for manipulating rectangles. Template parameter defines the type of coordinates (integer, float, ...) /////////////////////////////////////////////////////////. More...

#include <Rect.hpp>

Inheritance diagram for sf::Rect< T >:
Inheritance graph
[legend]
Collaboration diagram for sf::Rect< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Rect ()
 Default constructor.
 Rect (T LeftCoord, T TopCoord, T RightCoord, T BottomCoord)
 Construct the rectangle from its coordinates.
GetWidth () const
 Get the width of the rectangle.
GetHeight () const
 Get the height of the rectangle.
void Offset (T OffsetX, T OffsetY)
 Move the whole rectangle by the given offset.
bool Contains (T X, T Y) const
 Check if a point is inside the rectangle's area.
bool Intersects (const Rect< T > &Rectangle, Rect< T > *OverlappingRect=NULL) const
 Check intersection between two rectangles.

Public Attributes

Left
 Left coordinate of the rectangle.
Top
 Top coordinate of the rectangle.
Right
 Right coordinate of the rectangle.
Bottom
 Bottom coordinate of the rectangle.

Detailed Description

template<typename T>
class sf::Rect< T >

Rect is an utility class for manipulating rectangles. Template parameter defines the type of coordinates (integer, float, ...) /////////////////////////////////////////////////////////.

Definition at line 41 of file Rect.hpp.


Constructor & Destructor Documentation

template<typename T>
Rect::Rect ( )

Default constructor.

Default constructor /////////////////////////////////////////////////////////.

/////////////////////////////////////////////////////////

Definition at line 30 of file Rect.inl.

              :
Left  (0),
Top   (0),
Right (0),
Bottom(0)
{

}
template<typename T>
Rect::Rect ( LeftCoord,
TopCoord,
RightCoord,
BottomCoord 
)

Construct the rectangle from its coordinates.

Construct the color from its coordinates /////////////////////////////////////////////////////////.

Parameters:
LeftCoord: Left coordinate of the rectangle
TopCoord: Top coordinate of the rectangle
RightCoord: Right coordinate of the rectangle
BottomCoord: Bottom coordinate of the rectangle

/////////////////////////////////////////////////////////

Definition at line 44 of file Rect.inl.

                                                                  :
Left  (LeftCoord),
Top   (TopCoord),
Right (RightCoord),
Bottom(BottomCoord)
{

}

Member Function Documentation

template<typename T>
bool Rect::Contains ( X,
Y 
) const

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

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

Parameters:
X: X coordinate of the point to test
Y: Y coordinate of the point to test
Returns:
True if the point is inside

/////////////////////////////////////////////////////////

Definition at line 91 of file Rect.inl.

{
    return (X >= Left) && (X <= Right) && (Y >= Top) && (Y <= Bottom);
}
template<typename T>
T Rect::GetHeight ( ) const

Get the height of the rectangle.

Get the height of the rectangle /////////////////////////////////////////////////////////.

Returns:
Height of rectangle

/////////////////////////////////////////////////////////

Definition at line 68 of file Rect.inl.

{
    return Bottom - Top;
}
template<typename T>
T Rect::GetWidth ( ) const

Get the width of the rectangle.

Get the width of the rectangle /////////////////////////////////////////////////////////.

Returns:
Width of rectangle

/////////////////////////////////////////////////////////

Definition at line 58 of file Rect.inl.

{
    return Right - Left;
}
template<typename T>
bool Rect::Intersects ( const Rect< T > &  Rectangle,
Rect< T > *  OverlappingRect = NULL 
) const

Check intersection between two rectangles.

Check intersection between two rectangles /////////////////////////////////////////////////////////.

Parameters:
Rectangle: Rectangle to test
OverlappingRect: Rectangle to be filled with overlapping rect (NULL by default)
Returns:
True if rectangles overlap

/////////////////////////////////////////////////////////

Definition at line 101 of file Rect.inl.

{
    // Compute overlapping rect
    Rect Overlapping(std::max(Left,   Rectangle.Left),
                     std::max(Top,    Rectangle.Top),
                     std::min(Right,  Rectangle.Right),
                     std::min(Bottom, Rectangle.Bottom));

    // If overlapping rect is valid, then there is intersection
    if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overlapping.Bottom))
    {
        if (OverlappingRect)
            *OverlappingRect = Overlapping;
        return true;
    }
    else
    {
        if (OverlappingRect)
            *OverlappingRect = Rect(0, 0, 0, 0);
        return false;
    }
}
template<typename T>
void Rect::Offset ( OffsetX,
OffsetY 
)

Move the whole rectangle by the given offset.

Move the whole rectangle by the given offset /////////////////////////////////////////////////////////.

Parameters:
OffsetX: Horizontal offset
OffsetY: Vertical offset

/////////////////////////////////////////////////////////

Definition at line 78 of file Rect.inl.

{
    Left   += OffsetX;
    Right  += OffsetX;
    Top    += OffsetY;
    Bottom += OffsetY;
}

Member Data Documentation

template<typename T>
T sf::Rect< T >::Bottom

Bottom coordinate of the rectangle.

Definition at line 115 of file Rect.hpp.

template<typename T>
T sf::Rect< T >::Left

Left coordinate of the rectangle.

Definition at line 112 of file Rect.hpp.

template<typename T>
T sf::Rect< T >::Right

Right coordinate of the rectangle.

Definition at line 114 of file Rect.hpp.

template<typename T>
T sf::Rect< T >::Top

Top coordinate of the rectangle.

Definition at line 113 of file Rect.hpp.


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