All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Public Member Functions | Public Attributes | List of all members
BRect Class Reference

Defines a rectangular area aligned along pixel dimensions. More...

Public Member Functions

 BRect ()
 Creates an empty BRect object with dimensions (0, 0, -1, -1).
 
 BRect (BPoint leftTop, BPoint rightBottom)
 Creates a new BRect object with its dimensions defined by the leftTop and rightBottom points.
 
 BRect (BPoint leftTop, BSize size)
 Creates a new BRect object with its dimensions defined by the leftTop point and size.
 
 BRect (const BRect &other)
 Creates a new BRect object as a copy of other.
 
 BRect (float left, float top, float right, float bottom)
 Creates a new BRect object with the given dimensions.
 
 BRect (float side)
 Creates a new BRect object setting the left and top dimensions to 0 and setting the right and bottom dimensions to side - 1.
 
bool Contains (BPoint point) const
 Returns whether or not the BRect contains point.
 
bool Contains (BRect rect) const
 Returns whether or not the BRect wholly contains rect.
 
float Height () const
 Returns the height of the rectangle.
 
int32 IntegerHeight () const
 Returns The height of the rectangle rounded using ceil(bottom - top).
 
int32 IntegerWidth () const
 Returns The width of the rectangle rounded using ceil(right - left).
 
bool Intersects (BRect rect) const
 Returns whether or not the BRect and rect intersect.
 
bool IsValid () const
 Returns whether or not the BRect is valid.
 
BPoint LeftBottom () const
 Returns the left bottom point of the BRect.
 
BPoint LeftTop () const
 Returns the left top point of the BRect.
 
void PrintToStream () const
 Prints the BRect dimensions to standard output.
 
BPoint RightBottom () const
 Returns the right bottom point of the BRect.
 
BPoint RightTop () const
 Returns the right top point of the BRect.
 
void Set (float left, float top, float right, float bottom)
 Sets the dimensions of a BRect.
 
void SetLeftBottom (const BPoint point)
 Sets the left bottom point of the BRect.
 
void SetLeftTop (const BPoint point)
 Sets the left top point of the BRect.
 
void SetRightBottom (const BPoint point)
 Sets the right bottom point of the BRect.
 
void SetRightTop (const BPoint point)
 Sets the right top point of the BRect.
 
BSize Size () const
 Returns the dimensions of the BRect.
 
float Width () const
 Returns the width of the rectangle.
 
Operators
BRectoperator= (const BRect &other)
 Creates a new BRect object as a copy of other by overloading the = operator.
 
bool operator== (BRect other) const
 Returns whether or not two rectangles coincide exactly.
 
bool operator!= (BRect other) const
 Returns whether or not two rectangles do NOT coincide exactly.
 
BRect operator& (BRect other) const
 Creates and returns a new BRect that is the intersection of the BRect and other.
 
BRect operator| (BRect other) const
 Returns a new BRect that is the union of the BRect and other.
 
Transformation

Positive values make the rectangle smaller, negative values make it larger.

The …Self() versions also return the transformed BRect when they are done. The …Copy() versions transform a copy without changing the original.

void InsetBy (BPoint inset)
 Inset the BRect by the x and y coordinates of point.
 
void InsetBy (float dx, float dy)
 Inset the BRect by dx units in the horizontal direction and dy units in the vertical direction.
 
BRectInsetBySelf (BPoint inset)
 Like BRect::InsetBy() but returns the transformed BRect.
 
BRectInsetBySelf (float dx, float dy)
 Like BRect::InsetBy() but returns the transformed BRect.
 
BRect InsetByCopy (BPoint inset) const
 Like BRect::InsetBy() but returns a copy of the transformed BRect leaving the original unmodified.
 
BRect InsetByCopy (float dx, float dy) const
 Like BRect::InsetBy() but returns a copy of the transformed BRect leaving the original unmodified.
 
Translation

Positive values move the rectangle right and down, negative values move the rectangle left and up.

The …Self() versions also return the translated BRect when they are done. The …Copy() versions translate a copy without changing the original.

void OffsetBy (BPoint delta)
 Moves the BRect horizontally by the x value of point and vertically by y value of point without changing the size of the rectangle.
 
void OffsetBy (float dx, float dy)
 Moves the BRect horizontally by dx units and vertically by dy units point without changing the size of the rectangle.
 
void OffsetTo (BPoint offset)
 Move the BRect to the location specified by point.
 
void OffsetTo (float x, float y)
 Move the BRect to the point specified by the given x and y coordinates.
 
BRectOffsetBySelf (BPoint offset)
 Like BRect::OffsetBy() but returns the translated BRect.
 
BRectOffsetBySelf (float dx, float dy)
 Like BRect::OffsetBy() but returns the translated BRect.
 
BRect OffsetByCopy (BPoint offset) const
 Like BRect::OffsetBy() but returns a copy of the translated BRect leaving the original unmodified.
 
BRect OffsetByCopy (float dx, float dy) const
 Like BRect::OffsetBy() but returns a copy of the translated BRect leaving the original unmodified.
 
BRectOffsetToSelf (BPoint offset)
 Like BRect::OffsetTo() but returns the translated BRect.
 
BRectOffsetToSelf (float x, float y)
 Like BRect::OffsetTo() but returns the translated BRect.
 
BRect OffsetToCopy (BPoint offset) const
 Like BRect::OffsetTo() but returns a copy of the translated BRect leaving the original unmodified.
 
BRect OffsetToCopy (float x, float y) const
 Like BRect::OffsetTo() but returns a copy of the translated BRect leaving the original unmodified.
 

Public Attributes

float bottom
 The value of the rectangle's bottom edge.
 
float left
 The value of the rectangle's left edge.
 
float right
 The value of the rectangle's right edge.
 
float top
 The value of the rectangle's top edge.
 

Detailed Description

Defines a rectangular area aligned along pixel dimensions.

BRect's are used throughout the Interface Kit to define the frames of windows, views, and bitmaps. BRect's are always oriented with completely vertical and horizontal lines, they cannot be rotated.

A BRect must have a non-negative width and height to be valid, that is the left value must be greater than or equal to the right value and the bottom edge value be greater than or equal to the top value. You can test whether or not a BRect is valid by calling IsValid(). Nothing prevents you from creating an invalid BRect, but, using one to define an area can produce unpredictable results.

A gotcha of using BRect's is that the starting point is 0, not 1, so in order to create a BRect with a 32x32 pixel area you write:

BRect(0, 0, 31, 31);
BRect()
Creates an empty BRect object with dimensions (0, 0, -1, -1).
Definition: Rect.h:120

or if you have the width and height stored in a variable you subtract 1 like this:

BRect(0, 0, width - 1, height -1);
Since
BeOS R3

Constructor & Destructor Documentation

◆ BRect() [1/6]

BRect::BRect ( )
inline

Creates an empty BRect object with dimensions (0, 0, -1, -1).

These dimensions are invalid, use Set() to provide valid dimensions.

See also
BRect::Set()
BRect::IsValid()
Since
BeOS R3

◆ BRect() [2/6]

BRect::BRect ( const BRect other)
inline

Creates a new BRect object as a copy of other.

Parameters
otherThe BRect object to copy.
Since
BeOS R3

◆ BRect() [3/6]

BRect::BRect ( float  left,
float  top,
float  right,
float  bottom 
)
inline

Creates a new BRect object with the given dimensions.

Parameters
leftThe left dimension.
topThe top dimension.
rightThe right dimension.
bottomThe bottom dimension.
Since
BeOS R3

◆ BRect() [4/6]

BRect::BRect ( BPoint  leftTop,
BPoint  rightBottom 
)
inline

Creates a new BRect object with its dimensions defined by the leftTop and rightBottom points.

Parameters
leftTopThe position to set the left top corner to.
rightBottomThe position to set the bottom right corner to.
Since
BeOS R3

◆ BRect() [5/6]

BRect::BRect ( BPoint  leftTop,
BSize  size 
)
inline

Creates a new BRect object with its dimensions defined by the leftTop point and size.

Parameters
leftTopThe position of the left top corner.
sizeThe size of the rect defining its width and height.
Since
Haiku R1

◆ BRect() [6/6]

BRect::BRect ( float  side)
inline

Creates a new BRect object setting the left and top dimensions to 0 and setting the right and bottom dimensions to side - 1.

Parameters
sideThe dimension to set the right and bottom sides.
Since
Haiku R1

Member Function Documentation

◆ Contains() [1/2]

bool BRect::Contains ( BPoint  point) const

Returns whether or not the BRect contains point.

Parameters
pointThe point to test.
Returns
true if the BRect contains point, false otherwise.
Since
BeOS R3

◆ Contains() [2/2]

bool BRect::Contains ( BRect  rect) const

Returns whether or not the BRect wholly contains rect.

Parameters
rectThe rectangle to test.
Returns
true if the BRect contains rect, false otherwise.
Since
BeOS R3

◆ Height()

float BRect::Height ( ) const
inline

Returns the height of the rectangle.

Returns
The height of the rectangle as a float.
Since
BeOS R3

References bottom, and top.

◆ InsetBy() [1/2]

void BRect::InsetBy ( BPoint  point)

Inset the BRect by the x and y coordinates of point.

Parameters
pointThe point to use to inset the BRect.
Since
BeOS R3

◆ InsetBy() [2/2]

void BRect::InsetBy ( float  dx,
float  dy 
)

Inset the BRect by dx units in the horizontal direction and dy units in the vertical direction.

Parameters
dxThe horizontal distance to inset the BRect by.
dyThe vertical distance to inset the BRect by.
Since
BeOS R3

◆ InsetByCopy() [1/2]

BRect BRect::InsetByCopy ( BPoint  point) const

Like BRect::InsetBy() but returns a copy of the transformed BRect leaving the original unmodified.

Parameters
pointThe point to use to inset the BRect.
Returns
A copy of the BRect after it has been transformed.
See also
BRect::InsetBy(BPoint point)
Since
BeOS R5

◆ InsetByCopy() [2/2]

BRect BRect::InsetByCopy ( float  dx,
float  dy 
) const

Like BRect::InsetBy() but returns a copy of the transformed BRect leaving the original unmodified.

Parameters
dxThe horizontal distance to inset the BRect by.
dyThe vertical distance to inset the BRect by.
Returns
A copy of the BRect after it has been transformed.
See also
BRect::InsetBy(float dx, float dy)
Since
BeOS R5

◆ InsetBySelf() [1/2]

BRect & BRect::InsetBySelf ( BPoint  point)

Like BRect::InsetBy() but returns the transformed BRect.

Parameters
pointThe point to use to inset the BRect.
Returns
The transformed BRect.
See also
BRect::InsetBy(BPoint point)
Since
BeOS R5

◆ InsetBySelf() [2/2]

BRect & BRect::InsetBySelf ( float  dx,
float  dy 
)

Like BRect::InsetBy() but returns the transformed BRect.

Parameters
dxThe horizontal distance to inset the BRect by.
dyThe vertical distance to inset the BRect by.
Returns
The transformed BRect.
See also
BRect::InsetBy(float dx, float dy)
Since
BeOS R5

◆ IntegerHeight()

int32 BRect::IntegerHeight ( ) const
inline

Returns The height of the rectangle rounded using ceil(bottom - top).

Returns
The height of the rectangle as an int32.
Since
BeOS R3

References bottom, and top.

◆ IntegerWidth()

int32 BRect::IntegerWidth ( ) const
inline

Returns The width of the rectangle rounded using ceil(right - left).

Returns
The width of the rectangle as an int32.
Since
BeOS R3

References left, and right.

◆ Intersects()

bool BRect::Intersects ( BRect  rect) const

Returns whether or not the BRect and rect intersect.

Parameters
rectThe BRect to use to test for intersection.
Returns
true if the rectangles intersect, false otherwise.
Since
BeOS R3

◆ IsValid()

bool BRect::IsValid ( ) const
inline

Returns whether or not the BRect is valid.

A BRect is valid if its width and height are non-negative, that is its right value is greater than or equal to its left value and its bottom value is greater than or equal to its top value.

Returns
true if the BRect is valid, false if the BRect is invalid.
Since
BeOS R3

References bottom, left, right, and top.

◆ LeftBottom()

BPoint BRect::LeftBottom ( ) const
inline

Returns the left bottom point of the BRect.

Returns
The left bottom point as a BPoint.
Since
BeOS R3

References bottom, and left.

◆ LeftTop()

BPoint BRect::LeftTop ( ) const
inline

Returns the left top point of the BRect.

Returns
The left top point as a BPoint.
Since
BeOS R3

References left.

◆ OffsetBy() [1/2]

void BRect::OffsetBy ( BPoint  point)

Moves the BRect horizontally by the x value of point and vertically by y value of point without changing the size of the rectangle.

Parameters
pointThe point to use to move the rectangle.
Since
BeOS R3

◆ OffsetBy() [2/2]

void BRect::OffsetBy ( float  dx,
float  dy 
)

Moves the BRect horizontally by dx units and vertically by dy units point without changing the size of the rectangle.

Parameters
dxThe number of units the move the rectangle vertically.
dyThe number of units the move the rectangle horizontally.
Since
BeOS R3

◆ OffsetByCopy() [1/2]

BRect BRect::OffsetByCopy ( BPoint  point) const

Like BRect::OffsetBy() but returns a copy of the translated BRect leaving the original unmodified.

Parameters
pointThe point to use to move the rectangle.
Returns
A copy of the BRect after it has been translated.
See also
BRect::OffsetBy(BPoint point)
Since
BeOS R5

◆ OffsetByCopy() [2/2]

BRect BRect::OffsetByCopy ( float  dx,
float  dy 
) const

Like BRect::OffsetBy() but returns a copy of the translated BRect leaving the original unmodified.

Parameters
dxThe number of units the move the rectangle vertically.
dyThe number of units the move the rectangle horizontally.
Returns
A copy of the BRect after it has been translated.
See also
BRect::OffsetBy(float dx, float dy)
Since
BeOS R5

◆ OffsetBySelf() [1/2]

BRect & BRect::OffsetBySelf ( BPoint  point)

Like BRect::OffsetBy() but returns the translated BRect.

Parameters
pointThe point to use to move the rectangle.
See also
BRect::OffsetBy(BPoint point)
Since
BeOS R5

◆ OffsetBySelf() [2/2]

BRect & BRect::OffsetBySelf ( float  dx,
float  dy 
)

Like BRect::OffsetBy() but returns the translated BRect.

Parameters
dxThe number of units the move the rectangle vertically.
dyThe number of units the move the rectangle horizontally.
Returns
The translated BRect.
See also
BRect::OffsetBy(float dx, float dy)
Since
BeOS R5

◆ OffsetTo() [1/2]

void BRect::OffsetTo ( BPoint  point)

Move the BRect to the location specified by point.

Parameters
pointThe location to move the BRect to.
Since
BeOS R3

◆ OffsetTo() [2/2]

void BRect::OffsetTo ( float  x,
float  y 
)

Move the BRect to the point specified by the given x and y coordinates.

Parameters
xThe vertical coordinate of the point to move the BRect to.
yThe horizontal coordinate of the point to move the BRect to.
Since
BeOS R3

◆ OffsetToCopy() [1/2]

BRect BRect::OffsetToCopy ( BPoint  point) const

Like BRect::OffsetTo() but returns a copy of the translated BRect leaving the original unmodified.

Parameters
pointThe point to use to move the rectangle.
Returns
A copy of the BRect after it has been translated.
See also
BRect::OffsetTo(BPoint point)
Since
BeOS R5

◆ OffsetToCopy() [2/2]

BRect BRect::OffsetToCopy ( float  x,
float  y 
) const

Like BRect::OffsetTo() but returns a copy of the translated BRect leaving the original unmodified.

Parameters
xThe number of units the move the rectangle vertically.
yThe number of units the move the rectangle horizontally.
Returns
A copy of the BRect after it has been translated.
See also
BRect::OffsetTo(float x, float y)
Since
BeOS R5

◆ OffsetToSelf() [1/2]

BRect & BRect::OffsetToSelf ( BPoint  point)

Like BRect::OffsetTo() but returns the translated BRect.

Parameters
pointThe point to use to move the rectangle.
Returns
The translated BRect.
See also
BRect::OffsetTo(BPoint point)
Since
BeOS R5

◆ OffsetToSelf() [2/2]

BRect & BRect::OffsetToSelf ( float  x,
float  y 
)

Like BRect::OffsetTo() but returns the translated BRect.

Parameters
xThe vertical coordinate of the point to move the BRect to.
yThe horizontal coordinate of the point to move the BRect to.
Returns
The translated BRect.
See also
BRect::OffsetTo(float x, float y)
Since
BeOS R5

◆ operator!=()

bool BRect::operator!= ( BRect  other) const

Returns whether or not two rectangles do NOT coincide exactly.

Parameters
otherThe BRect to compare with.
Returns
true if the rectangles do NOT coincide, false otherwise.
Since
BeOS R3

◆ operator&()

BRect BRect::operator& ( BRect  other) const

Creates and returns a new BRect that is the intersection of the BRect and other.

The intersection of two rectangles is the area that they both share.

Parameters
otherThe BRect to take the intersection of.
Returns
A new BRect that is the intersection of the BRect and other.
Since
BeOS R3

◆ operator=()

BRect & BRect::operator= ( const BRect other)
inline

Creates a new BRect object as a copy of other by overloading the = operator.

Parameters
otherThe BRect object to copy.
Returns
The newly created BRect object.
Since
BeOS R3

References bottom, left, right, and top.

◆ operator==()

bool BRect::operator== ( BRect  other) const

Returns whether or not two rectangles coincide exactly.

Parameters
otherThe BRect to compare with.
Returns
true if the rectangles coincide, false otherwise.
Since
BeOS R3

◆ operator|()

BRect BRect::operator| ( BRect  other) const

Returns a new BRect that is the union of the BRect and other.

The union of two rectangles is the area that encloses both rectangles.

Parameters
otherThe BRect to take the union of.
Returns
A new BRect that is the union of the BRect and other.
Since
BeOS R3

◆ PrintToStream()

void BRect::PrintToStream ( ) const

Prints the BRect dimensions to standard output.

The format of the output looks like this:

	BRect(l:%.1f, t:%.1f, r:%.1f, b:%.1f).
Since
BeOS R3

◆ RightBottom()

BPoint BRect::RightBottom ( ) const
inline

Returns the right bottom point of the BRect.

Returns
The right bottom point as a BPoint.
Since
BeOS R3

References right.

◆ RightTop()

BPoint BRect::RightTop ( ) const
inline

Returns the right top point of the BRect.

Returns
The left right point as a BPoint.
Since
BeOS R3

References right, and top.

◆ Set()

void BRect::Set ( float  left,
float  top,
float  right,
float  bottom 
)
inline

Sets the dimensions of a BRect.

Parameters
leftThe left dimension to set.
topThe top dimension to set.
rightThe right dimension to set.
bottomThe bottom dimension to set.
Since
BeOS R3

References bottom, left, right, and top.

◆ SetLeftBottom()

void BRect::SetLeftBottom ( const BPoint  point)

Sets the left bottom point of the BRect.

Parameters
pointThe point to set.
Since
BeOS R3

◆ SetLeftTop()

void BRect::SetLeftTop ( const BPoint  point)

Sets the left top point of the BRect.

Parameters
pointThe point to set.
Since
BeOS R3

◆ SetRightBottom()

void BRect::SetRightBottom ( const BPoint  point)

Sets the right bottom point of the BRect.

Parameters
pointThe point to set.
Since
BeOS R3

◆ SetRightTop()

void BRect::SetRightTop ( const BPoint  point)

Sets the right top point of the BRect.

Parameters
pointThe point to set.
Since
BeOS R3

◆ Size()

BSize BRect::Size ( ) const
inline

Returns the dimensions of the BRect.

Returns
The dimensions of the BRect as a BSize.
Since
Haiku R1

References bottom, left, right, and top.

◆ Width()

float BRect::Width ( ) const
inline

Returns the width of the rectangle.

Returns
The width of the rectangle as a float.

References left, and right.

Member Data Documentation

◆ bottom

BRect::bottom

The value of the rectangle's bottom edge.

Since
BeOS R3

Referenced by Height(), IntegerHeight(), IsValid(), LeftBottom(), operator=(), Set(), and Size().

◆ left

BRect::left

The value of the rectangle's left edge.

Since
BeOS R3

Referenced by IntegerWidth(), IsValid(), LeftBottom(), LeftTop(), operator=(), Set(), Size(), and Width().

◆ right

BRect::right

The value of the rectangle's right edge.

Since
BeOS R3

Referenced by IntegerWidth(), IsValid(), operator=(), RightBottom(), RightTop(), Set(), Size(), and Width().

◆ top

BRect::top

The value of the rectangle's top edge.

Since
BeOS R3

Referenced by Height(), IntegerHeight(), IsValid(), operator=(), RightTop(), Set(), and Size().