home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 13.4 KB | 376 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWRect.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWRECT_H
- #define FWRECT_H
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef SLPTRECT_H
- #include "SLPtRect.h"
- #endif
-
- //========================================================================================
- // Typedefs
- //========================================================================================
-
- typedef unsigned short FW_PointSelector;
-
- const FW_PointSelector FW_kTopLeft = 0;
- const FW_PointSelector FW_kBotRight = 1;
-
- //========================================================================================
- // Forward Class Declarations
- //========================================================================================
-
- class FW_CRect;
-
- //========================================================================================
- // Global
- //========================================================================================
-
- extern const FW_CRect FW_kZeroRect;
-
- //========================================================================================
- // Global operators << and >>
- //========================================================================================
-
- FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_SRect& rect);
- FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_SRect& rect);
-
- //========================================================================================
- // class FW_CPlatformRect
- //========================================================================================
-
- class FW_CPlatformRect : public FW_PlatformRect
- {
- public:
- FW_CPlatformRect();
-
- FW_CPlatformRect(FW_PlatformCoordinate l, FW_PlatformCoordinate t,
- FW_PlatformCoordinate r, FW_PlatformCoordinate b);
-
- FW_CPlatformRect(const FW_CPlatformPoint& topLeft, const FW_CPlatformPoint& botRight);
-
- FW_CPlatformRect(const FW_PlatformRect& plfmRect);
- FW_CPlatformRect(const FW_CPlatformRect& other);
- FW_CPlatformRect(const FW_SRect& rect);
-
- FW_CPlatformRect& operator=(const FW_CPlatformRect& other);
- FW_CPlatformRect& operator=(const FW_PlatformRect& plfmRect);
- FW_CPlatformRect& operator=(const FW_SRect& rect);
-
- const FW_CPlatformPoint& TopLeft() const;
- FW_CPlatformPoint& TopLeft();
- const FW_CPlatformPoint& BotRight() const;
- FW_CPlatformPoint& BotRight();
-
- FW_CPlatformPoint TopRight() const; // Note: it is impossible to return non-const reference
- FW_CPlatformPoint BotLeft() const; // Note: it is impossible to return non-const reference
-
- FW_Boolean operator==(const FW_CPlatformRect& rect) const;
- FW_Boolean operator!=(const FW_CPlatformRect& rect) const;
-
- void Set(FW_PlatformCoordinate l, FW_PlatformCoordinate t,
- FW_PlatformCoordinate r, FW_PlatformCoordinate b);
- };
-
- inline FW_CPlatformRect::FW_CPlatformRect() {left = right = top = bottom = 0;}
-
- //========================================================================================
- // Transformation utilities
- //========================================================================================
-
- void FW_Transform(Environment* ev, FW_SRect& rect, ODTransform* transform);
- void FW_InverseTransform(Environment* ev, FW_SRect& rect, ODTransform* transform);
-
- FW_CRect FW_TransformCopy(Environment* ev, const FW_SRect& rect, ODTransform* transform);
- FW_CRect FW_InverseTransformCopy(Environment* ev, const FW_SRect& rect, ODTransform* transform);
-
- //========================================================================================
- // class FW_CRect
- //========================================================================================
-
- class FW_CRect : public FW_SRect
- {
- //----------------------------------------------------------------------------------------
- // Constructors/Destructors
- //
- public:
- FW_CRect();
- FW_CRect(FW_Fixed l, FW_Fixed t, FW_Fixed r, FW_Fixed b);
-
- FW_CRect(const FW_PlatformRect& plfmRect);
- FW_CRect(const FW_SRect& rect);
- FW_CRect(const FW_CRect& other);
- FW_CRect(const ODRect& odRect);
-
- FW_CRect(FW_CReadableStream& stream);
-
- FW_CRect(const FW_SPoint& topLeft, const FW_SPoint& botRight);
- FW_CRect(const FW_SPoint& startPoint, const FW_SPoint& endPoint, FW_Fixed penSize);
- FW_CRect(const FW_SPoint& topLeft, FW_Fixed width, FW_Fixed height);
-
- //----------------------------------------------------------------------------------------
- // operators
- //
- public:
- // ----- Assignement -----
- FW_CRect& operator=(const FW_SRect& sRect);
- FW_CRect& operator=(const FW_CRect& other);
- FW_CRect& operator=(const ODRect& odRect);
- FW_CRect& operator=(const FW_PlatformRect& plfmRect);
-
- // ----- Modification -----
- void operator&=(const FW_SRect& rect); // Intersect with rectangle
- void operator|=(const FW_SRect& rect); // Union with rectangle
- void operator|=(const FW_SPoint& point); // Expand to fit point
-
- // ----- Conversion -----
- // It is too dangerous to have automatic conversion. Use AsPlatformRect.
- // operator FW_PlatformRect() const;
-
- operator ODRect() const
- { return * (ODRect*) this; }
-
- operator ODRect*()
- { return (ODRect*) this; }
-
- operator FW_SRect*() const
- { return (FW_SRect*) this; }
-
- // ----- Array -----
- FW_CPoint& operator[](FW_PointSelector sel);
- const FW_CPoint& operator[](FW_PointSelector sel) const;
-
- // ----- Testing -----
- FW_Boolean operator==(const FW_SRect& sRect) const;
- FW_Boolean operator!=(const FW_SRect& sRect) const
- {return !(*this==sRect);}
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- // ----- Conversion -----
- FW_CPlatformRect AsPlatformRect() const;
-
- // ----- Modification -----
- void Clear();
- void Set(FW_Fixed left, FW_Fixed top, FW_Fixed right, FW_Fixed bottom);
- void Set(const FW_SPoint& topLeft, FW_Fixed width, FW_Fixed height);
- void Set(const FW_SPoint& topLeft, const FW_SPoint& botRight);
- void SetInt(short left, short top, short right, short bottom);
- void Offset(FW_Fixed x, FW_Fixed y);
- void Offset(const FW_SPoint& offset);
- void Place(FW_Fixed x, FW_Fixed y);
- void Place(const FW_SPoint& offset);
- void Inset(FW_Fixed x, FW_Fixed y);
- void Inset(FW_Fixed inset)
- {Inset(inset, inset);}
- void Map(const FW_SRect& srcRect, const FW_SRect& dstRect);
- void PlaceInCenterOf(const FW_SRect& srcRect);
-
- void Sort();
-
- FW_CRect& operator+=(const FW_SPoint& pt);
- FW_CRect operator+(const FW_SPoint& pt) const;
-
- FW_CRect& operator-=(const FW_SPoint& pt);
- FW_CRect operator-(const FW_SPoint& pt) const;
-
- // ----- OpenDoc Transform -----
- // Modify the rectangle
- void Transform(Environment* ev, ODTransform* transform)
- { FW_Transform(ev, *this, transform); }
- void InverseTransform(Environment* ev, ODTransform* transform)
- { FW_InverseTransform(ev, *this, transform); }
-
- // Return a modified copy
- FW_CRect TransformCopy(Environment* ev, ODTransform* transform) const
- { return FW_TransformCopy(ev, *this, transform); }
- FW_CRect InverseTransformCopy(Environment* ev, ODTransform* transform) const
- { return FW_InverseTransformCopy(ev, *this, transform); }
-
- // ----- Accessors -----
-
- const FW_CPoint& TopLeft() const
- {return *(FW_CPoint*)&left;}
- FW_CPoint& TopLeft()
- {return *(FW_CPoint*)&left;}
- const FW_CPoint& BotRight() const
- {return *(FW_CPoint*)&right;}
- FW_CPoint& BotRight()
- {return *(FW_CPoint*)&right;}
- FW_Fixed Width() const
- {return FW_Fixed(right-left);}
- FW_Fixed Height() const
- {return FW_Fixed(bottom-top);}
- FW_Fixed Length(FW_XYSelector selector) const;
- FW_CPoint Size() const;
-
- FW_CPoint TopRight() const; // Note: it is impossible to return a non-const reference
- FW_CPoint BotLeft() const; // Note: it is impossible to return a non-const reference
-
- FW_CPoint Center() const;
-
- // ----- Testing -----
- FW_Boolean IsEmpty() const;
- FW_Boolean Contains(const FW_SPoint& point) const;
- FW_Boolean Contains(const FW_SRect& rect) const;
- FW_Boolean IsIntersecting(const FW_SRect& rect) const;
-
- // ----- Operation on Rectangle -----
- void Intersection(const FW_SRect& rect);
- void Intersection(const FW_SRect& rect1, const FW_SRect& rect2);
-
- void Union(const FW_SRect& rect);
- void Union(const FW_SRect& rect1, const FW_SRect& rect2);
- };
-
- //========================================================================================
- // Inlines
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::FW_CPlatformRect
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformRect::FW_CPlatformRect(FW_PlatformCoordinate l, FW_PlatformCoordinate t,
- FW_PlatformCoordinate r, FW_PlatformCoordinate b)
- {
- left = l; top = t;
- right = r; bottom = b;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::FW_CPlatformRect
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformRect::FW_CPlatformRect(const FW_CPlatformPoint& topLeft,
- const FW_CPlatformPoint& botRight)
- {
- #ifdef FW_BUILD_MAC
- left = topLeft.h; top = topLeft.v;
- right = botRight.h; bottom = botRight.v;
- #endif
- #ifdef FW_BUILD_WIN
- left = topLeft.x; top = topLeft.y;
- right = botRight.x; bottom = botRight.y;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::FW_CPlatformRect
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformRect::FW_CPlatformRect(const FW_CPlatformRect& other)
- {
- left = other.left; top = other.top;
- right = other.right; bottom = other.bottom;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::FW_CPlatformRect
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformRect::FW_CPlatformRect(const FW_PlatformRect& plfmRect)
- {
- left = plfmRect.left; top = plfmRect.top;
- right = plfmRect.right; bottom = plfmRect.bottom;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::operator=
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformRect& FW_CPlatformRect::operator=(const FW_CPlatformRect& other)
- {
- left = other.left; top = other.top;
- right = other.right; bottom = other.bottom;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::operator=
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformRect& FW_CPlatformRect::operator=(const FW_PlatformRect& plfmRect)
- {
- left = plfmRect.left; top = plfmRect.top;
- right = plfmRect.right; bottom = plfmRect.bottom;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::Set
- //----------------------------------------------------------------------------------------
- inline void FW_CPlatformRect::Set(FW_PlatformCoordinate l, FW_PlatformCoordinate t,
- FW_PlatformCoordinate r, FW_PlatformCoordinate b)
- {
- left = l; top = t;
- right = r; bottom = b;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::TopLeft
- //----------------------------------------------------------------------------------------
- inline const FW_CPlatformPoint& FW_CPlatformRect::TopLeft() const
- {
- return *(FW_CPlatformPoint*)this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::TopLeft
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformPoint& FW_CPlatformRect::TopLeft()
- {
- return *(FW_CPlatformPoint*)this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::BotRight
- //----------------------------------------------------------------------------------------
- inline const FW_CPlatformPoint& FW_CPlatformRect::BotRight() const
- {
- #ifdef FW_BUILD_MAC
- return *(FW_CPlatformPoint*)⊥
- #endif
- #ifdef FW_BUILD_WIN
- return *(FW_CPlatformPoint*)&right;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformRect::BotRight
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformPoint& FW_CPlatformRect::BotRight()
- {
- #ifdef FW_BUILD_MAC
- return *(FW_CPlatformPoint*)⊥
- #endif
- #ifdef FW_BUILD_WIN
- return *(FW_CPlatformPoint*)&right;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRect:: operator&=
- //----------------------------------------------------------------------------------------
- inline void FW_CRect:: operator&=(const FW_SRect &r)
- {
- Intersection(r);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRect:: operator|=
- //----------------------------------------------------------------------------------------
- inline void FW_CRect:: operator|= (const FW_SRect &r)
- {
- Union(r);
- }
-
- #endif
-