2007-05-12 20:19:24 +04:00
|
|
|
/*
|
2012-11-04 17:07:46 +04:00
|
|
|
* Copyright 2001-2012, Haiku, Inc. All rights reserved.
|
2007-05-12 20:19:24 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-07-09 16:24:59 +04:00
|
|
|
#ifndef _RECT_H
|
|
|
|
#define _RECT_H
|
|
|
|
|
|
|
|
|
2012-11-04 17:07:46 +04:00
|
|
|
#include <math.h>
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <Point.h>
|
2007-05-12 20:50:16 +04:00
|
|
|
#include <Size.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
class BRect {
|
2009-08-27 15:12:41 +04:00
|
|
|
public:
|
|
|
|
float left;
|
|
|
|
float top;
|
|
|
|
float right;
|
|
|
|
float bottom;
|
|
|
|
|
|
|
|
BRect();
|
|
|
|
BRect(const BRect& other);
|
|
|
|
BRect(float left, float top, float right,
|
|
|
|
float bottom);
|
|
|
|
BRect(BPoint leftTop, BPoint rightBottom);
|
|
|
|
BRect(BPoint leftTop, BSize size);
|
2011-03-17 04:08:01 +03:00
|
|
|
BRect(float side);
|
2009-08-27 15:12:41 +04:00
|
|
|
|
|
|
|
BRect& operator=(const BRect& other);
|
|
|
|
void Set(float left, float top, float right,
|
|
|
|
float bottom);
|
|
|
|
|
|
|
|
void PrintToStream() const;
|
|
|
|
|
|
|
|
BPoint LeftTop() const;
|
|
|
|
BPoint RightBottom() const;
|
|
|
|
BPoint LeftBottom() const;
|
|
|
|
BPoint RightTop() const;
|
|
|
|
|
|
|
|
void SetLeftTop(const BPoint leftTop);
|
|
|
|
void SetRightBottom(const BPoint rightBottom);
|
|
|
|
void SetLeftBottom(const BPoint leftBottom);
|
|
|
|
void SetRightTop(const BPoint rightTop);
|
|
|
|
|
|
|
|
// Transformation
|
|
|
|
void InsetBy(BPoint inset);
|
|
|
|
void InsetBy(float dx, float dy);
|
|
|
|
void OffsetBy(BPoint delta);
|
|
|
|
void OffsetBy(float dx, float dy);
|
|
|
|
void OffsetTo(BPoint offset);
|
|
|
|
void OffsetTo(float x, float y);
|
|
|
|
|
|
|
|
// Expression transformations
|
|
|
|
BRect& InsetBySelf(BPoint inset);
|
|
|
|
BRect& InsetBySelf(float dx, float dy);
|
2012-11-04 17:07:46 +04:00
|
|
|
BRect InsetByCopy(BPoint inset) const;
|
|
|
|
BRect InsetByCopy(float dx, float dy) const;
|
2009-08-27 15:12:41 +04:00
|
|
|
BRect& OffsetBySelf(BPoint offset);
|
|
|
|
BRect& OffsetBySelf(float dx, float dy);
|
2012-11-04 17:07:46 +04:00
|
|
|
BRect OffsetByCopy(BPoint offset) const;
|
|
|
|
BRect OffsetByCopy(float dx, float dy) const;
|
2009-08-27 15:12:41 +04:00
|
|
|
BRect& OffsetToSelf(BPoint offset);
|
|
|
|
BRect& OffsetToSelf(float dx, float dy);
|
2012-11-04 17:07:46 +04:00
|
|
|
BRect OffsetToCopy(BPoint offset) const;
|
|
|
|
BRect OffsetToCopy(float dx, float dy) const;
|
2009-08-27 15:12:41 +04:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
BSize Size() const;
|
|
|
|
|
|
|
|
bool Intersects(BRect r) const;
|
|
|
|
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
|
|
|
|
2009-08-27 15:12:41 +04:00
|
|
|
// #pragma mark - inline definitions
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2005-06-04 19:15:42 +04:00
|
|
|
inline BPoint
|
|
|
|
BRect::LeftTop() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2011-03-17 04:08:01 +03: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
|
|
|
{
|
2011-03-17 04:08:01 +03: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()
|
2011-03-17 04:08:01 +03:00
|
|
|
:
|
|
|
|
left(0),
|
2012-11-04 17:07:46 +04:00
|
|
|
top(0),
|
2011-03-17 04:08:01 +03:00
|
|
|
right(-1),
|
|
|
|
bottom(-1)
|
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(float l, float t, float r, float b)
|
2011-03-17 04:08:01 +03:00
|
|
|
:
|
|
|
|
left(l),
|
|
|
|
top(t),
|
|
|
|
right(r),
|
|
|
|
bottom(b)
|
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
|
2009-08-27 15:12:41 +04:00
|
|
|
BRect::BRect(const BRect& r)
|
2011-03-17 04:08:01 +03:00
|
|
|
:
|
|
|
|
left(r.left),
|
|
|
|
top(r.top),
|
|
|
|
right(r.right),
|
|
|
|
bottom(r.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
|
|
|
|
BRect::BRect(BPoint leftTop, BPoint rightBottom)
|
2011-03-17 04:08:01 +03:00
|
|
|
:
|
|
|
|
left(leftTop.x),
|
|
|
|
top(leftTop.y),
|
|
|
|
right(rightBottom.x),
|
|
|
|
bottom(rightBottom.y)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-05-12 20:19:24 +04:00
|
|
|
|
2007-05-12 20:50:16 +04:00
|
|
|
inline
|
|
|
|
BRect::BRect(BPoint leftTop, BSize size)
|
2011-03-17 04:08:01 +03:00
|
|
|
:
|
|
|
|
left(leftTop.x),
|
|
|
|
top(leftTop.y),
|
|
|
|
right(leftTop.x + size.width),
|
|
|
|
bottom(leftTop.y + size.height)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
BRect::BRect(float side)
|
|
|
|
:
|
|
|
|
left(0),
|
|
|
|
top(0),
|
|
|
|
right(side - 1),
|
|
|
|
bottom(side - 1)
|
2007-05-12 20:50:16 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-27 15:12:41 +04:00
|
|
|
inline BRect&
|
2005-06-04 19:15:42 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-03-17 04:08:01 +03: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
|