2007-05-12 20:19:24 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Frans van Nispen
|
|
|
|
*/
|
2002-07-09 16:24:59 +04:00
|
|
|
#ifndef _RECT_H
|
|
|
|
#define _RECT_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
#include <Point.h>
|
2007-05-12 20:50:16 +04:00
|
|
|
#include <Size.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
#include <math.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
class BRect {
|
2005-06-04 19:15:42 +04:00
|
|
|
public:
|
|
|
|
float left;
|
|
|
|
float top;
|
|
|
|
float right;
|
|
|
|
float bottom;
|
|
|
|
|
|
|
|
BRect();
|
|
|
|
BRect(const BRect &r);
|
|
|
|
BRect(float l, float t, float r, float b);
|
|
|
|
BRect(BPoint lt, BPoint rb);
|
2007-05-12 20:50:16 +04:00
|
|
|
BRect(BPoint leftTop, BSize size);
|
2005-06-04 19:15:42 +04:00
|
|
|
|
|
|
|
BRect &operator=(const BRect &r);
|
|
|
|
void Set(float l, float t, float r, float b);
|
|
|
|
|
|
|
|
void PrintToStream() const;
|
|
|
|
|
|
|
|
BPoint LeftTop() const;
|
|
|
|
BPoint RightBottom() const;
|
|
|
|
BPoint LeftBottom() const;
|
|
|
|
BPoint RightTop() const;
|
|
|
|
|
|
|
|
void SetLeftTop(const BPoint p);
|
|
|
|
void SetRightBottom(const BPoint p);
|
|
|
|
void SetLeftBottom(const BPoint p);
|
|
|
|
void SetRightTop(const BPoint p);
|
|
|
|
|
|
|
|
// transformation
|
|
|
|
void InsetBy(BPoint p);
|
|
|
|
void InsetBy(float dx, float dy);
|
|
|
|
void OffsetBy(BPoint p);
|
|
|
|
void OffsetBy(float dx, float dy);
|
|
|
|
void OffsetTo(BPoint p);
|
|
|
|
void OffsetTo(float x, float y);
|
|
|
|
|
|
|
|
// expression transformations
|
|
|
|
BRect& InsetBySelf(BPoint);
|
|
|
|
BRect& InsetBySelf(float dx, float dy);
|
|
|
|
BRect InsetByCopy(BPoint);
|
|
|
|
BRect InsetByCopy(float dx, float dy);
|
|
|
|
BRect& OffsetBySelf(BPoint);
|
|
|
|
BRect& OffsetBySelf(float dx, float dy);
|
|
|
|
BRect OffsetByCopy(BPoint);
|
|
|
|
BRect OffsetByCopy(float dx, float dy);
|
|
|
|
BRect& OffsetToSelf(BPoint);
|
|
|
|
BRect& OffsetToSelf(float dx, float dy);
|
|
|
|
BRect OffsetToCopy(BPoint);
|
|
|
|
BRect OffsetToCopy(float dx, float dy);
|
|
|
|
|
|
|
|
// comparison
|
|
|
|
bool operator==(BRect r) const;
|
|
|
|
bool operator!=(BRect r) const;
|
|
|
|
|
|
|
|
// intersection and union
|
|
|
|
BRect operator&(BRect r) const;
|
|
|
|
BRect operator|(BRect r) const;
|
|
|
|
|
|
|
|
bool IsValid() const;
|
|
|
|
float Width() const;
|
|
|
|
int32 IntegerWidth() const;
|
|
|
|
float Height() const;
|
|
|
|
int32 IntegerHeight() const;
|
2007-05-12 20:50:16 +04:00
|
|
|
BSize Size() const;
|
|
|
|
|
|
|
|
bool Intersects(BRect r) const;
|
2005-06-04 19:15:42 +04:00
|
|
|
bool Contains(BPoint p) const;
|
|
|
|
bool Contains(BRect r) const;
|
2002-07-09 16:24:59 +04:00
|
|
|
};
|
2005-06-04 19:15:42 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
// inline definitions ----------------------------------------------------------
|
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline BPoint
|
|
|
|
BRect::LeftTop() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-06-04 19:15:42 +04:00
|
|
|
return *(const BPoint *)&left;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline BPoint
|
|
|
|
BRect::RightBottom() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-06-04 19:15:42 +04:00
|
|
|
return *(const BPoint *)&right;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline BPoint
|
|
|
|
BRect::LeftBottom() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-06-04 19:15:42 +04:00
|
|
|
return BPoint(left, bottom);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline BPoint
|
|
|
|
BRect::RightTop() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-06-04 19:15:42 +04:00
|
|
|
return BPoint(right, top);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline
|
|
|
|
BRect::BRect()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
top = left = 0;
|
|
|
|
bottom = right = -1;
|
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline
|
|
|
|
BRect::BRect(float l, float t, float r, float b)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
left = l;
|
|
|
|
top = t;
|
|
|
|
right = r;
|
|
|
|
bottom = b;
|
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline
|
|
|
|
BRect::BRect(const BRect &r)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
left = r.left;
|
|
|
|
top = r.top;
|
|
|
|
right = r.right;
|
|
|
|
bottom = r.bottom;
|
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline
|
|
|
|
BRect::BRect(BPoint leftTop, BPoint rightBottom)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
left = leftTop.x;
|
|
|
|
top = leftTop.y;
|
|
|
|
right = rightBottom.x;
|
|
|
|
bottom = rightBottom.y;
|
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2007-05-12 20:50:16 +04:00
|
|
|
inline
|
|
|
|
BRect::BRect(BPoint leftTop, BSize size)
|
|
|
|
: left(leftTop.x),
|
|
|
|
top(leftTop.y),
|
|
|
|
right(leftTop.x + size.width),
|
|
|
|
bottom(leftTop.y + size.height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline BRect &
|
|
|
|
BRect::operator=(const BRect& from)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
left = from.left;
|
|
|
|
top = from.top;
|
|
|
|
right = from.right;
|
|
|
|
bottom = from.bottom;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline void
|
|
|
|
BRect::Set(float l, float t, float r, float b)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
left = l;
|
|
|
|
top = t;
|
|
|
|
right = r;
|
|
|
|
bottom = b;
|
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline bool
|
|
|
|
BRect::IsValid() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-06-04 19:15:42 +04:00
|
|
|
return left <= right && top <= bottom;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline int32
|
|
|
|
BRect::IntegerWidth() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-06-04 19:15:42 +04:00
|
|
|
return (int32)ceil(right - left);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline float
|
|
|
|
BRect::Width() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-06-04 19:15:42 +04:00
|
|
|
return right - left;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline int32
|
|
|
|
BRect::IntegerHeight() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-06-04 19:15:42 +04:00
|
|
|
return (int32)ceil(bottom - top);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline float
|
|
|
|
BRect::Height() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2005-06-04 19:15:42 +04:00
|
|
|
return bottom - top;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2007-05-12 20:50:16 +04:00
|
|
|
inline BSize
|
|
|
|
BRect::Size() const
|
|
|
|
{
|
|
|
|
return BSize(right - left, bottom - top);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#endif // _RECT_H
|