I always thought that BRect provides two cords for position and two cords for dimensions — X-pos, Y-pos, Width, Height. But everytime I’m trying to get it works I’m getting strange results. Looks like actual width and height are bound to position, so when I change position cords, visual dimensions changing too.
Someone, please explain this until I get to a nuthouse.
The [BeBook](file:///boot/system/documentation/BeBook/BRect.html) shows these constructors:
inline BRect(float left,
float top,
float right,
float bottom);
inline BRect(BPoint leftTop,
BPoint rightBottom);
So either the coordinates for the top-left and bottom-right of the rectangle, or their coordinates as BPoints. To move the BRect, you should probably use it’s OffsetBy() or OffsetTo().
Regards,
Humdinger
A BRect does not store the width and height internally, but the left-top and bottom-right coordinates (in appropriately named left, top, right, bottom variables). This makes it possible to move any side of the rectangle without complex math (just change one of the 4 “sides”).
If you need the width and height, simply use the Width() and Height() methods. Use OffsetBy/OffsetTo to move the rectangle, and so on. In most cases you won’t need to mess with the coordinates directly.
Ooops…
Thank you all, guys, for cool functions and for cool explanation.