ScummVM API documentation
Common::Rect Struct Reference

#include <rect.h>

Inheritance diagram for Common::Rect:
Sherlock::Exit Sherlock::ScaleZone Supernova::GuiElement Titanic::Rect TsAGE::Rect Ultima::Shared::TextRect Ultima::Ultima4::SubImage Voyeur::RectEntry Voyeur::RectResource

Public Member Functions

constexpr Rect (int16 w, int16 h)
 
 Rect (const Point &topLeft, const Point &bottomRight)
 
constexpr Rect (const Point &topLeft, int16 w, int16 h)
 
 Rect (int16 x1, int16 y1, int16 x2, int16 y2)
 
bool operator== (const Rect &rhs) const
 
bool operator!= (const Rect &rhs) const
 
int16 width () const
 
int16 height () const
 
void setWidth (int16 aWidth)
 
void setHeight (int16 aHeight)
 
bool contains (int16 x, int16 y) const
 
bool contains (const Point &p) const
 
bool contains (const Rect &r) const
 
bool equals (const Rect &r) const
 
bool intersects (const Rect &r) const
 
Rect findIntersectingRect (const Rect &r) const
 
void extend (const Rect &r)
 
void grow (int16 offset)
 
void clip (const Rect &r)
 
void clip (int16 maxw, int16 maxh)
 
bool isEmpty () const
 
bool isValidRect () const
 
void moveTo (int16 x, int16 y)
 
void translate (int16 dx, int16 dy)
 
void moveTo (const Point &p)
 
void debugPrint (int debuglevel=0, const char *caption="Rect:") const
 

Static Public Member Functions

static Rect center (int16 cx, int16 cy, int16 w, int16 h)
 
static bool getBlitRect (Point &dst, Rect &rect, const Rect &clip)
 

Public Attributes

int16 top
 
int16 left
 
int16 bottom
 
int16 right
 

Detailed Description

Simple class for handling a rectangular zone.

Note: This implementation is built around the assumption that (top,left) is part of the rectangle, but (bottom,right) is not. This is reflected in various methods, including contains(), intersects(), and others.

Another very widespread approach to rectangle classes treats (bottom,right) also as a part of the rectangle.

Conceptually, both are sound, but the approach we use saves many intermediate computations (like computing the height in our case is done by doing this: height = bottom - top; while in the alternate system, it would be height = bottom - top + 1;

When writing code using our Rect class, always keep this principle in mind!

Constructor & Destructor Documentation

◆ Rect() [1/4]

constexpr Common::Rect::Rect ( int16  w,
int16  h 
)
inline

Create a rectangle with the top-left corner at position (0, 0) and the given width w and height h.

◆ Rect() [2/4]

Common::Rect::Rect ( const Point topLeft,
const Point bottomRight 
)
inline

Create a rectangle with the top-left corner at the position topLeft and the bottom-right corner at the position bottomRight.

The topLeft x value must be greater or equal bottomRight x and topLeft y must be greater or equal bottomRight y.

◆ Rect() [3/4]

constexpr Common::Rect::Rect ( const Point topLeft,
int16  w,
int16  h 
)
inline

Create a rectangle with the top-left corner at the position topLeft and the given width w and height h.

◆ Rect() [4/4]

Common::Rect::Rect ( int16  x1,
int16  y1,
int16  x2,
int16  y2 
)
inline

Create a rectangle with the top-left corner at the given position (x1, y1) and the bottom-right corner at the position (x2, y2).

The x2 value must be greater or equal x1 and y2 must be greater or equal y1.

Member Function Documentation

◆ operator==()

bool Common::Rect::operator== ( const Rect rhs) const
inline

Check if two rectangles are identical.

Returns
True if the rectangles are identical, false otherwise.

◆ operator!=()

bool Common::Rect::operator!= ( const Rect rhs) const
inline

Check if two rectangles are different.

Returns
True if the rectangles are different, false otherwise.

◆ width()

int16 Common::Rect::width ( ) const
inline

Return the width of a rectangle.

◆ height()

int16 Common::Rect::height ( ) const
inline

Return the height of a rectangle.

◆ setWidth()

void Common::Rect::setWidth ( int16  aWidth)
inline

< Set the width to aWidth value.

◆ setHeight()

void Common::Rect::setHeight ( int16  aHeight)
inline

< Set the height to aHeight value.

◆ contains() [1/3]

bool Common::Rect::contains ( int16  x,
int16  y 
) const
inline

Check if the given position is inside this rectangle.

Parameters
xThe horizontal position to check.
yThe vertical position to check.
Returns
True if the given position is inside this rectangle, false otherwise.

◆ contains() [2/3]

bool Common::Rect::contains ( const Point p) const
inline

Check if the given point is inside this rectangle.

Parameters
pThe point to check.
Returns
True if the given point is inside this rectangle, false otherwise.

◆ contains() [3/3]

bool Common::Rect::contains ( const Rect r) const
inline

Check if the given Rect is contained inside this rectangle.

Parameters
rThe rectangle to check.
Returns
True if the given Rect is inside, false otherwise.

◆ equals()

bool Common::Rect::equals ( const Rect r) const
inline

Check if the given Rect is equal to this one.

Parameters
rThe rectangle to check.
Returns
true If the given Rect is equal, false otherwise.

◆ intersects()

bool Common::Rect::intersects ( const Rect r) const
inline

Check if the given rectangle intersects with this rectangle.

Parameters
rThe rectangle to check.
Returns
True if the given rectangle has a non-empty intersection with this rectangle, false otherwise.

◆ findIntersectingRect()

Rect Common::Rect::findIntersectingRect ( const Rect r) const
inline

Find the intersecting rectangle between this rectangle and the given rectangle.

Parameters
rThe intersecting rectangle.
Returns
The intersection of the rectangles or an empty rectangle if not intersecting.

◆ extend()

void Common::Rect::extend ( const Rect r)
inline

Extend this rectangle so that it contains r.

Parameters
rThe rectangle to extend by.

◆ grow()

void Common::Rect::grow ( int16  offset)
inline

Extend this rectangle in all four directions by the given number of pixels.

Parameters
offsetThe size to grow by.

◆ clip() [1/2]

void Common::Rect::clip ( const Rect r)
inline

Clip this rectangle with another rectangle r.

◆ clip() [2/2]

void Common::Rect::clip ( int16  maxw,
int16  maxh 
)
inline

Reduce the dimensions of this rectangle by setting max width and max height.

◆ isEmpty()

bool Common::Rect::isEmpty ( ) const
inline

Check if the rectangle is empty (its width or length is 0) or invalid (its width or length are negative).

Return values
trueThe rectangle is empty or invalid.
falseThe rectangle is valid and not empty.

◆ isValidRect()

bool Common::Rect::isValidRect ( ) const
inline

Check if this is a valid rectangle.

◆ moveTo() [1/2]

void Common::Rect::moveTo ( int16  x,
int16  y 
)
inline

Move this rectangle to the position defined by x, y.

◆ translate()

void Common::Rect::translate ( int16  dx,
int16  dy 
)
inline

Move the rectangle by the given delta x and y values.

◆ moveTo() [2/2]

void Common::Rect::moveTo ( const Point p)
inline

Move this rectangle to the position of the point p.

◆ debugPrint()

void Common::Rect::debugPrint ( int  debuglevel = 0,
const char *  caption = "Rect:" 
) const
inline

Print debug messages related to this class.

◆ center()

static Rect Common::Rect::center ( int16  cx,
int16  cy,
int16  w,
int16  h 
)
inlinestatic

Create a rectangle around the given center.

Note
The center point is rounded up and left when given an odd width and height.

◆ getBlitRect()

static bool Common::Rect::getBlitRect ( Point dst,
Rect rect,
const Rect clip 
)
inlinestatic

Given target surface with size clip, this function ensures that blit arguments dst and rect are within the clip rectangle.

Parameters
dstBlit destination coordinates.
rectBlit source rectangle.
clipClip rectangle (size of destination surface).

Member Data Documentation

◆ left

int16 Common::Rect::left

The point at the top left of the rectangle (part of the Rect).

◆ right

int16 Common::Rect::right

The point at the bottom right of the rectangle (not part of the Rect).


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