git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12954 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-06-04 15:15:42 +00:00
parent 6a2575c9d2
commit a01d14b2db
+96 -106
View File
@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS // Copyright (c) 2001-2005, Haiku
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@@ -23,125 +23,119 @@
// Author: Frans van Nispen ([email protected]) // Author: Frans van Nispen ([email protected])
// Description: BRect represents a rectangular area. // Description: BRect represents a rectangular area.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef _RECT_H #ifndef _RECT_H
#define _RECT_H #define _RECT_H
// Standard Includes -----------------------------------------------------------
#include <math.h>
// System Includes -------------------------------------------------------------
#include <SupportDefs.h> #include <SupportDefs.h>
#include <Point.h> #include <Point.h>
// Project Includes ------------------------------------------------------------ #include <math.h>
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
// BRect class -----------------------------------------------------------------
class BRect { class BRect {
public: public:
float left; float left;
float top; float top;
float right; float right;
float bottom; float bottom;
BRect(); BRect();
BRect(const BRect &r); BRect(const BRect &r);
BRect(float l, float t, float r, float b); BRect(float l, float t, float r, float b);
BRect(BPoint lt, BPoint rb); BRect(BPoint lt, BPoint rb);
BRect &operator=(const BRect &r); BRect &operator=(const BRect &r);
void Set(float l, float t, float r, float b); void Set(float l, float t, float r, float b);
void PrintToStream() const; void PrintToStream() const;
BPoint LeftTop() const; BPoint LeftTop() const;
BPoint RightBottom() const; BPoint RightBottom() const;
BPoint LeftBottom() const; BPoint LeftBottom() const;
BPoint RightTop() const; BPoint RightTop() const;
void SetLeftTop(const BPoint p); void SetLeftTop(const BPoint p);
void SetRightBottom(const BPoint p); void SetRightBottom(const BPoint p);
void SetLeftBottom(const BPoint p); void SetLeftBottom(const BPoint p);
void SetRightTop(const BPoint p); void SetRightTop(const BPoint p);
// transformation // transformation
void InsetBy(BPoint p); void InsetBy(BPoint p);
void InsetBy(float dx, float dy); void InsetBy(float dx, float dy);
void OffsetBy(BPoint p); void OffsetBy(BPoint p);
void OffsetBy(float dx, float dy); void OffsetBy(float dx, float dy);
void OffsetTo(BPoint p); void OffsetTo(BPoint p);
void OffsetTo(float x, float y); void OffsetTo(float x, float y);
// expression transformations // expression transformations
BRect & InsetBySelf(BPoint); BRect& InsetBySelf(BPoint);
BRect & InsetBySelf(float dx, float dy); BRect& InsetBySelf(float dx, float dy);
BRect InsetByCopy(BPoint); BRect InsetByCopy(BPoint);
BRect InsetByCopy(float dx, float dy); BRect InsetByCopy(float dx, float dy);
BRect & OffsetBySelf(BPoint); BRect& OffsetBySelf(BPoint);
BRect & OffsetBySelf(float dx, float dy); BRect& OffsetBySelf(float dx, float dy);
BRect OffsetByCopy(BPoint); BRect OffsetByCopy(BPoint);
BRect OffsetByCopy(float dx, float dy); BRect OffsetByCopy(float dx, float dy);
BRect & OffsetToSelf(BPoint); BRect& OffsetToSelf(BPoint);
BRect & OffsetToSelf(float dx, float dy); BRect& OffsetToSelf(float dx, float dy);
BRect OffsetToCopy(BPoint); BRect OffsetToCopy(BPoint);
BRect OffsetToCopy(float dx, float dy); BRect OffsetToCopy(float dx, float dy);
// comparison // comparison
bool operator==(BRect r) const; bool operator==(BRect r) const;
bool operator!=(BRect r) const; bool operator!=(BRect r) const;
// intersection and union // intersection and union
BRect operator&(BRect r) const; BRect operator&(BRect r) const;
BRect operator|(BRect r) const; BRect operator|(BRect r) const;
bool Intersects(BRect r) const;
bool IsValid() const;
float Width() const;
int32 IntegerWidth() const;
float Height() const;
int32 IntegerHeight() const;
bool Contains(BPoint p) const;
bool Contains(BRect r) const;
bool Intersects(BRect r) const;
bool IsValid() const;
float Width() const;
int32 IntegerWidth() const;
float Height() const;
int32 IntegerHeight() const;
bool Contains(BPoint p) const;
bool Contains(BRect r) const;
}; };
//------------------------------------------------------------------------------
// inline definitions ---------------------------------------------------------- // inline definitions ----------------------------------------------------------
inline BPoint BRect::LeftTop() const inline BPoint
BRect::LeftTop() const
{ {
return(*((const BPoint*)&left)); return *(const BPoint *)&left;
} }
inline BPoint BRect::RightBottom() const inline BPoint
BRect::RightBottom() const
{ {
return(*((const BPoint*)&right)); return *(const BPoint *)&right;
} }
inline BPoint BRect::LeftBottom() const inline BPoint
BRect::LeftBottom() const
{ {
return(BPoint(left, bottom)); return BPoint(left, bottom);
} }
inline BPoint BRect::RightTop() const inline BPoint
BRect::RightTop() const
{ {
return(BPoint(right, top)); return BPoint(right, top);
} }
inline BRect::BRect() inline
BRect::BRect()
{ {
top = left = 0; top = left = 0;
bottom = right = -1; bottom = right = -1;
} }
inline BRect::BRect(float l, float t, float r, float b) inline
BRect::BRect(float l, float t, float r, float b)
{ {
left = l; left = l;
top = t; top = t;
@@ -149,7 +143,8 @@ inline BRect::BRect(float l, float t, float r, float b)
bottom = b; bottom = b;
} }
inline BRect::BRect(const BRect &r) inline
BRect::BRect(const BRect &r)
{ {
left = r.left; left = r.left;
top = r.top; top = r.top;
@@ -157,7 +152,8 @@ inline BRect::BRect(const BRect &r)
bottom = r.bottom; bottom = r.bottom;
} }
inline BRect::BRect(BPoint leftTop, BPoint rightBottom) inline
BRect::BRect(BPoint leftTop, BPoint rightBottom)
{ {
left = leftTop.x; left = leftTop.x;
top = leftTop.y; top = leftTop.y;
@@ -165,7 +161,8 @@ inline BRect::BRect(BPoint leftTop, BPoint rightBottom)
bottom = rightBottom.y; bottom = rightBottom.y;
} }
inline BRect &BRect::operator=(const BRect& from) inline BRect &
BRect::operator=(const BRect& from)
{ {
left = from.left; left = from.left;
top = from.top; top = from.top;
@@ -174,7 +171,8 @@ inline BRect &BRect::operator=(const BRect& from)
return *this; return *this;
} }
inline void BRect::Set(float l, float t, float r, float b) inline void
BRect::Set(float l, float t, float r, float b)
{ {
left = l; left = l;
top = t; top = t;
@@ -182,42 +180,34 @@ inline void BRect::Set(float l, float t, float r, float b)
bottom = b; bottom = b;
} }
inline bool BRect::IsValid() const inline bool
BRect::IsValid() const
{ {
if (left <= right && top <= bottom) return left <= right && top <= bottom;
return true;
else
return false;
} }
inline int32 BRect::IntegerWidth() const inline int32
BRect::IntegerWidth() const
{ {
return((int32)ceil(right - left)); return (int32)ceil(right - left);
} }
inline float BRect::Width() const inline float
BRect::Width() const
{ {
return(right - left); return right - left;
} }
inline int32 BRect::IntegerHeight() const inline int32
BRect::IntegerHeight() const
{ {
return((int32)ceil(bottom - top)); return (int32)ceil(bottom - top);
} }
inline float BRect::Height() const inline float
BRect::Height() const
{ {
return(bottom - top); return bottom - top;
} }
//------------------------------------------------------------------------------
#endif // _RECT_H #endif // _RECT_H
/*
* $Log $
*
* $Id $
*
*/