The BRect class defines a rectangle using integer precision. More...
#include <BRect.h>
Public Member Functions | |
BRect () | |
Constructs a BRect with an origin X and Y of 0 and corner X and Y of -1. More... | |
BRect (const BPoint &topleft, const BPoint &bottomright) | |
Constructs a BRect with an given origin and corner. More... | |
BRect (const BPoint &topleft, const BSize &size) | |
Constructs a BRect with an given origin and size. More... | |
BRect (int left, int top, int width, int height) | |
Constructs a BRect with an given origin, width and height. More... | |
bool | IsNull () const |
Returns true if corner X is origin X - 1 and corner Y is origin Y - 1; otherwise returns false. More... | |
bool | IsEmpty () const |
Returns true if origin X is great than corner X or origin Y is great than corner Y; otherwise returns false. More... | |
bool | IsValid () const |
Returns true if origin X is less than or equal to corner X and origin Y is less than or equal to corner Y; otherwise returns false. More... | |
BRect | Normalized () const |
Returns a normalized rectangle; i.e., a rectangle that has a non - negative width and height. More... | |
int | X () const |
Retrieves the origin X. More... | |
int | Y () const |
Retrieves the origin Y. More... | |
void | SetX (int x) |
Sets the origin X. More... | |
void | SetY (int y) |
Sets the origin Y. More... | |
void | SetLeft (int pos) |
Sets the origin X. More... | |
void | SetTop (int pos) |
Sets the origin Y. More... | |
void | SetRight (int pos) |
Sets the corner X. More... | |
void | SetBottom (int pos) |
Sets the corner Y. More... | |
void | SetTopLeft (const BPoint &p) |
Sets the origin X and Y. More... | |
void | SetBottomRight (const BPoint &p) |
Sets the corner X and Y. More... | |
void | SetTopRight (const BPoint &p) |
Sets the origin Y and corner X. More... | |
void | SetBottomLeft (const BPoint &p) |
Sets the origin X and corner Y. More... | |
BPoint | TopLeft () const |
Retrieves the origin X and Y. More... | |
BPoint | BottomRight () const |
Retrieves the corner X and Y. More... | |
BPoint | TopRight () const |
Retrieves the origin Y and corner X. More... | |
BPoint | BottomLeft () const |
Retrieves the origin X and corner Y. More... | |
BPoint | Center () const |
Retrieves the X and Y in the center of the rectangle. More... | |
BSize | Size () const |
Retrieves the width and height as a BSize. More... | |
void | SetWidth (int w) |
Sets the width, and thus the corner X. More... | |
void | SetHeight (int h) |
Sets the height, and thus the corner Y. More... | |
void | SetSize (const BSize &s) |
Sets both the width and height, and thus the corner X and Y. More... | |
void | MoveLeft (int pos) |
Moves the rectangle, leaving the origin X at the given position. The rectangle's size is unchanged. More... | |
void | MoveTop (int pos) |
Moves the rectangle, leaving the origin Y at the given position. The rectangle's size is unchanged. More... | |
void | MoveRight (int pos) |
Moves the rectangle, leaving the corner X at the given position. The rectangle's size is unchanged. More... | |
void | MoveBottom (int pos) |
Moves the rectangle, leaving the corner Y at the given position. The rectangle's size is unchanged. More... | |
void | MoveTopLeft (const BPoint &p) |
Moves the rectangle, leaving the origin X and Y at the given point. The rectangle's size is unchanged. More... | |
void | MoveBottomRight (const BPoint &p) |
Moves the rectangle, leaving the corner X and Y at the given point. The rectangle's size is unchanged. More... | |
void | MoveTopRight (const BPoint &p) |
Moves the rectangle, leaving the origin Y and corner X at the given point. The rectangle's size is unchanged. More... | |
void | MoveBottomLeft (const BPoint &p) |
Moves the rectangle, leaving the origin X and corner Y at the given point. The rectangle's size is unchanged. More... | |
void | MoveCenter (const BPoint &p) |
Moves the rectangle, leaving the center point at the given position. The rectangle's size is unchanged. More... | |
void | MoveTo (int x, int y) |
Moves the rectangle, leaving the origin X and Y at the given X and Y. The rectangle's size is unchanged. More... | |
void | MoveTo (const BPoint &p) |
Moves the rectangle, leaving the origin X and Y at the given point. The rectangle's size is unchanged. More... | |
void | Translate (int dx, int dy) |
Resizes the rectangle by altering the X of the origin and corner by dx, and altering the Y of the origin and corner by dy. More... | |
void | Translate (const BPoint &p) |
Resizes the rectangle by altering the X of the origin and corner by the X and Y in the given offset. More... | |
BRect | Translated (int dx, int dy) const |
Creates a new BRect with values from this BRect but translated by the given dx and dy. More... | |
BRect | Translated (const BPoint &p) const |
Creates a new BRect with values from this BRect but translated by the by the X and Y in the given offset. More... | |
void | SetRect (int x, int y, int w, int h) |
Sets the values in the BRect to the given origin, width and height. More... | |
void | GetRect (int *x, int *y, int *w, int *h) const |
Retrieves the origin, width and height from the BRect. More... | |
void | SetCoords (int ox, int oy, int cx, int cy) |
Sets the values in the BRect to the given origin and corner. More... | |
void | GetCoords (int *ox, int *oy, int *cx, int *cy) const |
Retrieves the origin and corner from the BRect. More... | |
void | Adjust (int ox, int oy, int cx, int cy) |
Changes the origin and corner values independently. More... | |
BRect | Adjusted (int ox, int oy, int cx, int cy) const |
Creates a new BRect with the values of this BRect but also changes the origin and corner values independently. More... | |
bool | Contains (const BPoint &p, bool proper=false) const |
Tells whether the given point is inside the rectangle or not. More... | |
bool | Contains (int x, int y, bool proper=false) const |
Tells whether the given point is inside the rectangle or not. More... | |
bool | Contains (const BRect &r, bool proper=false) const |
Tells whether the given rectangle is inside this rectangle or not. More... | |
BRect | Unite (const BRect &r) const |
Retrieves the united rectangle, given the other rectangle. More... | |
BRect | United (const BRect &other) const |
Retrieves the united rectangle, given the other rectangle. More... | |
BRect | Intersect (const BRect &r) const |
Retrieves the intersection rectangle given the other rectangle. More... | |
BRect | Intersected (const BRect &other) const |
Retrieves the intersection rectangle given the other rectangle. More... | |
bool | Intersects (const BRect &r) const |
Returns true if this rectangle intersects with the given rectangle (i.e., there is at least one pixel that is within both rectangles), otherwise returns false. More... | |
BRect | operator| (const BRect &r) const |
Returns the bounding rectangle of this rectangle and the given rectangle. More... | |
BRect | operator& (const BRect &r) const |
Returns the intersection rectangle of this rectangle and the given rectangle. More... | |
BRect & | operator|= (const BRect &r) |
Sets values to the bounding rectangle of this rectangle and the given rectangle. More... | |
BRect & | operator&= (const BRect &r) |
Sets values to the intersection rectangle of this rectangle and the given rectangle. More... | |
Friends | |
bool | operator== (const BRect &, const BRect &) |
Operator overload for == (equality test). More... | |
bool | operator!= (const BRect &, const BRect &) |
Operator overload for != (not equal test). More... | |
The BRect class defines a rectangle using integer precision.
A rectangle is normally expressed as an upper-left corner and a size. The size (width and height) of a BRect is always equivalent to the mathematical rectangle that forms the basis for its rendering.
A BRect can be constructed with a set of left, top, width and height integers, or from a BPoint and a BSize. There is a third constructor that creates a BRect using the top-left and bottom-right coordinates.
The BRect class provides a collection of functions that return the various rectangle coordinates and enable manipulation of these. BRect also provides functions to move the rectangle relative to the various coordinates. In addition there is a MoveTo() function that moves the rectangle, leaving its top left corner at the given coordinates. Alternatively, the Translate() function moves the rectangle the given offset relative to the current position, and the Translated() function returns a translated copy of this rectangle.
The Size() function returns the rectange's dimensions as a BSize. The dimensions can also be retrieved separately using the Width() and Height() functions. To manipulate the dimensions use the SetSize(), SetWidth() or SetHeight() functions. Alternatively, the size can be changed by applying either of the functions setting the rectangle coordinates, for example, SetBottom() or SetRight().
The Contains() function tells whether a given point is inside the rectangle or not, and the Intersects() function returns true if this rectangle intersects with a given rectangle. The BRect class also provides the Intersected() function which returns the intersection rectangle, and the United() function which returns the rectangle that encloses the given rectangle.
The BRect class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. BRect also provides functions to move the rectangle relative to the various coordinates. For example the Left(), SetLeft() and MoveLeft() functions as an example: Left() returns the x-coordinate of the rectangle's left edge, SetLeft() sets the left edge of the rectangle to the given x coordinate (it may change the width, but will never change the rectangle's right edge) and MoveLeft() moves the entire rectangle horizontally, leaving the rectangle's left edge at the given x coordinate and its size unchanged.
Constructs a BRect with an given origin and corner.
Constructs a BRect with an given origin and size.
BRect | ( | int | left, |
int | top, | ||
int | width, | ||
int | height | ||
) |
Constructs a BRect with an given origin, width and height.
void Adjust | ( | int | ox, |
int | oy, | ||
int | cx, | ||
int | cy | ||
) |
Changes the origin and corner values independently.
BRect Adjusted | ( | int | ox, |
int | oy, | ||
int | cx, | ||
int | cy | ||
) | const |
BPoint BottomLeft | ( | ) | const |
Retrieves the origin X and corner Y.
BPoint BottomRight | ( | ) | const |
Retrieves the corner X and Y.
Referenced by operator!=(), and operator==().
BPoint Center | ( | ) | const |
Retrieves the X and Y in the center of the rectangle.
bool Contains | ( | const BPoint & | p, |
bool | proper = false |
||
) | const |
Tells whether the given point is inside the rectangle or not.
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false. If proper is true, this function only returns true if the given point is inside the rectangle (i.e., not on the edge).
bool Contains | ( | int | x, |
int | y, | ||
bool | proper = false |
||
) | const |
Tells whether the given point is inside the rectangle or not.
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false. If proper is true, this function only returns true if the given point is inside the rectangle (i.e., not on the edge).
bool Contains | ( | const BRect & | r, |
bool | proper = false |
||
) | const |
Tells whether the given rectangle is inside this rectangle or not.
Returns true if the given rectangle is inside or on the edge of the rectangle, otherwise returns false. If proper is true, this function only returns true if the given rectangle is inside this rectangle (i.e., not on the edge).
void GetCoords | ( | int * | ox, |
int * | oy, | ||
int * | cx, | ||
int * | cy | ||
) | const |
Retrieves the origin and corner from the BRect.
void GetRect | ( | int * | x, |
int * | y, | ||
int * | w, | ||
int * | h | ||
) | const |
Retrieves the origin, width and height from the BRect.
Retrieves the intersection rectangle given the other rectangle.
Retrieves the intersection rectangle given the other rectangle.
bool Intersects | ( | const BRect & | r | ) | const |
Returns true if this rectangle intersects with the given rectangle (i.e., there is at least one pixel that is within both rectangles), otherwise returns false.
The intersection rectangle can be retrieved using the Intersected () function.
bool IsEmpty | ( | ) | const |
Returns true if origin X is great than corner X or origin Y is great than corner Y; otherwise returns false.
bool IsNull | ( | ) | const |
Returns true if corner X is origin X - 1 and corner Y is origin Y - 1; otherwise returns false.
bool IsValid | ( | ) | const |
Returns true if origin X is less than or equal to corner X and origin Y is less than or equal to corner Y; otherwise returns false.
void MoveBottom | ( | int | pos | ) |
Moves the rectangle, leaving the corner Y at the given position. The rectangle's size is unchanged.
void MoveBottomLeft | ( | const BPoint & | p | ) |
Moves the rectangle, leaving the origin X and corner Y at the given point. The rectangle's size is unchanged.
void MoveBottomRight | ( | const BPoint & | p | ) |
Moves the rectangle, leaving the corner X and Y at the given point. The rectangle's size is unchanged.
void MoveCenter | ( | const BPoint & | p | ) |
Moves the rectangle, leaving the center point at the given position. The rectangle's size is unchanged.
void MoveLeft | ( | int | pos | ) |
Moves the rectangle, leaving the origin X at the given position. The rectangle's size is unchanged.
void MoveRight | ( | int | pos | ) |
Moves the rectangle, leaving the corner X at the given position. The rectangle's size is unchanged.
void MoveTo | ( | int | x, |
int | y | ||
) |
Moves the rectangle, leaving the origin X and Y at the given X and Y. The rectangle's size is unchanged.
void MoveTo | ( | const BPoint & | p | ) |
Moves the rectangle, leaving the origin X and Y at the given point. The rectangle's size is unchanged.
void MoveTop | ( | int | pos | ) |
Moves the rectangle, leaving the origin Y at the given position. The rectangle's size is unchanged.
void MoveTopLeft | ( | const BPoint & | p | ) |
Moves the rectangle, leaving the origin X and Y at the given point. The rectangle's size is unchanged.
void MoveTopRight | ( | const BPoint & | p | ) |
Moves the rectangle, leaving the origin Y and corner X at the given point. The rectangle's size is unchanged.
BRect Normalized | ( | ) | const |
Returns a normalized rectangle; i.e., a rectangle that has a non - negative width and height.
If Width () < 0 the function swaps the left and right corners, and if Height () < 0 it swaps the top and bottom corners.
Returns the intersection rectangle of this rectangle and the given rectangle.
Returns an empty rectangle if there is no intersection.
Sets values to the intersection rectangle of this rectangle and the given rectangle.
Returns an empty rectangle if there is no intersection.
Returns the bounding rectangle of this rectangle and the given rectangle.
Sets values to the bounding rectangle of this rectangle and the given rectangle.
void SetBottom | ( | int | pos | ) |
Sets the corner Y.
void SetBottomLeft | ( | const BPoint & | p | ) |
Sets the origin X and corner Y.
void SetBottomRight | ( | const BPoint & | p | ) |
Sets the corner X and Y.
void SetCoords | ( | int | ox, |
int | oy, | ||
int | cx, | ||
int | cy | ||
) |
Sets the values in the BRect to the given origin and corner.
void SetHeight | ( | int | h | ) |
Sets the height, and thus the corner Y.
void SetLeft | ( | int | pos | ) |
Sets the origin X.
void SetRect | ( | int | x, |
int | y, | ||
int | w, | ||
int | h | ||
) |
Sets the values in the BRect to the given origin, width and height.
void SetRight | ( | int | pos | ) |
Sets the corner X.
void SetSize | ( | const BSize & | s | ) |
Sets both the width and height, and thus the corner X and Y.
void SetTop | ( | int | pos | ) |
Sets the origin Y.
void SetTopLeft | ( | const BPoint & | p | ) |
Sets the origin X and Y.
void SetTopRight | ( | const BPoint & | p | ) |
Sets the origin Y and corner X.
void SetWidth | ( | int | w | ) |
Sets the width, and thus the corner X.
void SetX | ( | int | x | ) |
Sets the origin X.
void SetY | ( | int | y | ) |
Sets the origin Y.
BPoint TopLeft | ( | ) | const |
Retrieves the origin X and Y.
Referenced by operator!=(), and operator==().
BPoint TopRight | ( | ) | const |
Retrieves the origin Y and corner X.
void Translate | ( | int | dx, |
int | dy | ||
) |
Resizes the rectangle by altering the X of the origin and corner by dx, and altering the Y of the origin and corner by dy.
[in] | dx | The distance by which to move the X of both the origin and corner |
[in] | dy | The distance by which to move the Y of both the origin and corner |
void Translate | ( | const BPoint & | p | ) |
Resizes the rectangle by altering the X of the origin and corner by the X and Y in the given offset.
[in] | p | The point containing the offset by which to move the origin and corner |
BRect Translated | ( | int | dx, |
int | dy | ||
) | const |
Retrieves the united rectangle, given the other rectangle.
int X | ( | ) | const |
Retrieves the origin X.
int Y | ( | ) | const |
Retrieves the origin Y.
Operator overload for != (not equal test).
Operator overload for == (equality test).