BRect¶
Data Members¶
Member |
Description |
---|---|
floatleft |
The value of the rectangle’s left side. |
floattop |
The value of the rectangle’s top. |
floatright |
The value of the rectangle’s right side. |
floatbottom |
The value of the rectangle’s bottom. |
Constructor and Destructor¶
BRect()
inline BRect::BRect(float left, float top, float right, float bottom)
inline BRect::BRect(BPoint leftTop, BPoint rightBottom)
inline BRect::BRect(BRect &rect)
inline BRect::BRect()
Initializes a BRect as four sides, as two diametrically opposed
corners, or as a copy of some other BRect object. A rectangle
that’s not assigned any initial values is invalid, until a specific
assignment is made, either through a Set()
function or
by setting the object’s data members directly.
Member Functions¶
Contains(), Intersects()
bool BRect::Contains(BPoint point) const
bool BRect::Contains(BRect rect) const
bool BRect::Intersects(BRect rect) const
Contains() returns true if point or rect lies entirely within the BRect’s rectangle (and false if not). A rectangle contains the points that lie along its edges; for example, two identical rectangles contain each other.
Intersect() returns true if the BRect has any area—even a corner or part of a side—in common with rect, and false if it doesn’t.
Note
This function’s results are unpredictable if either rectangle is invalid.
See also: & (intersection)()
, | (union)()
,
BPoint::ConstrainTo()
InsetBy(), InsetBySelf(), InsetByCopy(), OffsetBy(), OffsetBySelf(), OffsetByCopy(), OffsetTo(), OffsetToSelf(), OffsetToCopy()
void BRect::InsetBy(float x, float y)
void BRect::InsetBy(BPoint point)
BRect &BRect::InsetBySelf(float x, float y)
BRect &BRect::InsetBySelf(BPoint point)
BRect BRect::InsetByCopy(float x, float y)
BRect BRect::InsetByCopy(BPoint point)
void BRect::OffsetBy(float x, float y)
void BRect::OffsetBy(BPoint point)
BRect &BRect::OffsetBySelf(float x, float y)
BRect &BRect::OffsetBySelf(BPoint point)
BRect BRect::OffsetByCopy(float x, float y)
BRect BRect::OffsetByCopy(BPoint point)
void BRect::OffsetTo(float x, float y)
void BRect::OffsetTo(BPoint point)
BRect &BRect::OffsetToSelf(float x, float y)
BRect &BRect::OffsetToSelf(BPoint point)
BRect BRect::OffsetToCopy(float x, float y)
BRect BRect::OffsetToCopy(BPoint point)
Sorting out the different versions, there are three basic rectangle-manipulation functions here:
InsetBy() insets the sides of the BRect’s rectangle by x units (left and right sides) and y units (top and bottom). Positive inset values shrink the rectangle; negative values expand it. Note that both sides of each pair moves the full amount. For example, if you inset a BRect by (4,4), the left side moves (to the right) four units and the right side moves (to the left) four units (and similarly with the top and bottom).
OffsetBy() moves the BRect horizontally by x units and vertically by y units. The rectangle’s size doesn’t change.
OffsetTo() moves the BRect to the location (x,y).
If a BPoint
argument is used, the BPoint
’s
x and y values are used as the x and
y arguments.
The …Self() versions of the functions are the same as the simpler versions, but they conveniently return the modified BRect.
The …Copy() versions copy the BRect, and then modify and return the copy (without changing the original).
IsValid()
inline bool BRect::IsValid() const
Returns true if the BRect’s right side is greater than or equal to its left and its bottom is greater than or equal to its top, and false otherwise. An invalid rectangle can’t be used to define an interface area (such as the frame of a view or window).
PrintToStream()
void BRect::PrintToStream() const
Prints the contents of the BRect object to standard out in the form:
"BRect(left, top, right, bottom)"
Set(), SetLeftTop(), SetLeftBottom(), SetRightTop(), SetRightBottom(), LeftTop(), LeftBottom(), RightTop(), RightBottom()
inline void BRect::Set(float left, float top, float right, float bottom)
void BRect::SetLeftTop(const BPoint point)
void BRect::SetLeftBottom(const BPoint point)
void BRect::SetRightTop(const BPoint point)
void BRect::SetRightBottom(const BPoint point)
BPoint BRect::LeftBottom() const
BPoint BRect::RightTop() const
BPoint BRect::RightBottom() const
Set() sets the object’s rectangle by defining the coordinates of
all four sides. The other Set…() functions move one of the
rectangle’s corners to the BPoint
argument; the other corners
and sides are modified concomittantly. None of these functions prevents you
from creating an invalid rectangle.
The BPoint
-returning functions return the coordinates of one
of the rectangle’s four corners.
Width(), IntegerWidth(), Height(), IntegerHeight()
inline float BRect::Width() const
inline int32 BRect::IntegerWidth() const
inline float BRect::Height() const
inline int32 BRect::IntegerHeight() const
Width() returns the numerical difference between the rectangle’s right and left sides (i.e. right - left). IntegerWidth() does the same, but rounds up in the case of a fractional difference.
Height() and IntegerHeight() perform similar calculations for the height of the rectangle (i.e. bottom - top and ceil(bottom - top)).
The width and height of a BRect’s rectangle, as returned through these functions
Operators¶
inline BRect &operator=(const BRect from)
Copies from’s rectangle data into the left-side object.
bool operator==(BRect) const
bool operator!=(BRect) const
== returns true if the two objects’ rectangles exactly coincide.
!= returns true if the two objects’ rectangles don’t coincide.
Creates and returns a new BRect that’s the intersection of the two operands. The new BRect encloses the area that the two operands have in common. If the two operands don’t intersect, the new BRect will be invalid.
Creates and returns a new BRect that minimally but completely encloses the area defined by both of the operands. The shaded area illustrates the union of the two outlined rectangles: