home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 15.2 KB | 516 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPoint.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWPOINT_H
- #define FWPOINT_H
-
- // ----- OpenDoc Includes -----
-
- #ifndef FWODTYPS_H
- #include "FWODTyps.h"
- #endif
-
- #ifndef FWFXMATH_H
- #include "FWFxMath.h"
- #endif
-
- #ifndef SLPTRECT_H
- #include "SLPtRect.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // Forward Declarations
- //========================================================================================
-
- class ODTransform;
-
- class FW_CPoint;
- class FW_CRect;
-
- class FW_CWritableStream;
- class FW_CReadableStream;
-
- //========================================================================================
- // Global operators
- //========================================================================================
-
- FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_SPoint& point);
- FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_SPoint& point);
-
- FW_Boolean operator==(const FW_SPoint& pt1, const FW_SPoint& pt2);
- FW_Boolean operator!=(const FW_SPoint& pt1, const FW_SPoint& pt2);
- FW_Boolean operator==(const FW_SPoint& pt1, const ODPoint& odPoint);
- FW_Boolean operator!=(const FW_SPoint& pt1, const ODPoint& odPoint);
-
- //========================================================================================
- // Global
- //========================================================================================
-
- extern const FW_CPoint FW_kZeroPoint;
-
- //========================================================================================
- // Typedefs
- //========================================================================================
-
- typedef unsigned short FW_XYSelector;
-
- const FW_XYSelector FW_kHorizontal = 0;
- const FW_XYSelector FW_kVertical = 1;
-
- //========================================================================================
- // class FW_CPlatformPoint
- //========================================================================================
-
- class FW_CPlatformPoint : public FW_PlatformPoint
- {
- public:
- FW_CPlatformPoint();
- FW_CPlatformPoint(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy);
- FW_CPlatformPoint(const FW_CPlatformPoint& other);
- FW_CPlatformPoint(const FW_PlatformPoint& plfmPoint);
- FW_CPlatformPoint(const FW_SPoint& point);
-
- FW_CPlatformPoint& operator=(const FW_CPlatformPoint& other);
- FW_CPlatformPoint& operator=(const FW_PlatformPoint& plfmPoint);
- FW_CPlatformPoint& operator=(const FW_SPoint& point);
-
- void Set(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy);
-
- FW_Boolean operator==(const FW_CPlatformPoint& pt) const;
- FW_Boolean operator!=(const FW_CPlatformPoint& pt) const;
-
- FW_PlatformCoordinate X() const;
- FW_PlatformCoordinate Y() const;
-
- FW_PlatformCoordinate& X();
- FW_PlatformCoordinate& Y();
- };
-
- //========================================================================================
- // Global utilities for working with FW_PlatformPoint
- //========================================================================================
-
- inline void FW_SetXY(FW_PlatformPoint& pt, FW_PlatformCoordinate xx, FW_PlatformCoordinate yy)
- {
- #ifdef FW_BUILD_WIN
- pt.x = xx; pt.y = yy;
- #endif
- #ifdef FW_BUILD_MAC
- pt.h = xx; pt.v = yy;
- #endif
- }
-
- inline FW_PlatformCoordinate& FW_PointX(FW_PlatformPoint& pt)
- {
- #ifdef FW_BUILD_WIN
- return pt.x;
- #endif
- #ifdef FW_BUILD_MAC
- return pt.h;
- #endif
- }
-
- inline FW_PlatformCoordinate& FW_PointY(FW_PlatformPoint& pt)
- {
- #ifdef FW_BUILD_WIN
- return pt.y;
- #endif
- #ifdef FW_BUILD_MAC
- return pt.v;
- #endif
- }
-
- inline FW_PlatformCoordinate FW_PointX(const FW_PlatformPoint& pt)
- {
- #ifdef FW_BUILD_WIN
- return pt.x;
- #endif
- #ifdef FW_BUILD_MAC
- return pt.h;
- #endif
- }
-
- inline FW_PlatformCoordinate FW_PointY(const FW_PlatformPoint& pt)
- {
- #ifdef FW_BUILD_WIN
- return pt.y;
- #endif
- #ifdef FW_BUILD_MAC
- return pt.v;
- #endif
- }
-
- //========================================================================================
- // Transformation utilities
- //========================================================================================
-
- void FW_Transform(Environment* ev, FW_SPoint& pt, ODTransform* transform);
- void FW_InverseTransform(Environment* ev, FW_SPoint& pt, ODTransform* transform);
-
- FW_CPoint FW_TransformCopy(Environment* ev, const FW_SPoint& pt, ODTransform* transform);
- FW_CPoint FW_InverseTransformCopy(Environment* ev, const FW_SPoint& pt, ODTransform* transform);
-
- void FW_TransformPoints(Environment* ev, ODTransform* transform, FW_SPoint* pts, long count);
- void FW_InverseTransformPoints(Environment* ev, ODTransform* transform, FW_SPoint* pts, long count);
-
- //========================================================================================
- // class FW_CPoint
- //========================================================================================
-
- class FW_CPoint : public FW_SPoint
- {
- //----------------------------------------------------------------------------------------
- // Constructors/Destructors
- //
- public:
- FW_CPoint()
- { x.fRep = 0; y.fRep = 0; }
-
- FW_CPoint(FW_Fixed xx, FW_Fixed yy)
- { x = xx; y = yy; }
-
- FW_CPoint(FW_PlatformPoint plfmPoint);
- FW_CPoint(const FW_CPoint& other);
- FW_CPoint(const FW_SPoint& point);
- FW_CPoint(const ODPoint& odPoint);
-
- FW_CPoint(FW_CReadableStream& stream);
-
- //----------------------------------------------------------------------------------------
- // operators
- //
- public:
- // ----- Assignement -----
- FW_CPoint& operator=(const FW_SPoint& point);
- FW_CPoint& operator=(const FW_CPoint& other);
- FW_CPoint& operator=(const ODPoint& odPoint);
- FW_CPoint& operator=(FW_PlatformPoint plfmPoint);
-
- // ----- Conversion -----
-
- // It is too dangerous to have automatic conversion. Use AsPlatformPoint.
- // operator FW_PlatformPoint() const;
-
- operator ODPoint() const
- { return * (ODPoint*) this; }
-
- operator ODPoint*()
- { return (ODPoint*) this; }
-
- operator FW_SPoint*() const
- { return (FW_SPoint*) this; }
-
- // ----- Modification -----
- FW_CPoint& operator+=(const FW_SPoint& point);
- FW_CPoint& operator-=(const FW_SPoint& point);
- FW_CPoint& operator+=(const ODPoint& odPoint);
- FW_CPoint& operator-=(const ODPoint& odPoint);
-
- FW_CPoint operator+(const FW_SPoint& point) const;
- FW_CPoint operator-(const FW_SPoint& point) const;
- FW_CPoint operator+(const ODPoint& odPoint) const;
- FW_CPoint operator-(const ODPoint& odPoint) const;
- FW_CPoint operator-() const;
-
- FW_CPoint& operator+=(FW_CPlatformPoint plfmPoint);
- FW_CPoint& operator-=(FW_CPlatformPoint plfmPoint);
- FW_CPoint operator+(FW_CPlatformPoint plfmPoint) const;
- FW_CPoint operator-(FW_CPlatformPoint plfmPoint) const;
-
- FW_Fixed& operator[](FW_XYSelector selector);
- FW_Fixed operator[](FW_XYSelector selector) const;
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- // ----- Modification -----
- void Clear();
- void Set(FW_Fixed xx, FW_Fixed yy);
- void Offset(FW_Fixed xx, FW_Fixed yy);
- void Map(const FW_SRect& srcRect, const FW_SRect& destRect);
-
- // ----- Conversion -----
- FW_CPlatformPoint AsPlatformPoint() const;
-
- // ----- Accessors -----
- short IntX() const;
- short IntY() const;
-
- // ----- OpenDoc transforms -----
-
- // Modify the point
- void Transform(Environment* ev, ODTransform* transform)
- { FW_Transform(ev, *this, transform); }
-
- void InverseTransform(Environment* ev, ODTransform* transform)
- { FW_InverseTransform(ev, *this, transform); }
-
- // Return a transformed copy
- FW_CPoint TransformCopy(Environment* ev, ODTransform* transform) const
- { return FW_TransformCopy(ev, *this, transform); }
-
- FW_CPoint InverseTransformCopy(Environment* ev, ODTransform* transform) const
- { return FW_InverseTransformCopy(ev, *this, transform); }
-
- // ----- Utilities -----
- static FW_XYSelector GetOrthogonal(FW_XYSelector selector)
- {return (selector + 1) & 1;}
- };
-
- //========================================================================================
- // inlines
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::Clear
- //----------------------------------------------------------------------------------------
-
- inline void FW_CPoint::Clear()
- {
- x.fRep = y.fRep = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::Set
- //----------------------------------------------------------------------------------------
- inline void FW_CPoint::Set(FW_Fixed xx, FW_Fixed yy)
- {
- x = xx, y = yy;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::IntX
- //----------------------------------------------------------------------------------------
- inline short FW_CPoint::IntX() const
- {
- return FW_FixedToInt(x);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPoint::IntY
- //----------------------------------------------------------------------------------------
- inline short FW_CPoint::IntY() const
- {
- return FW_FixedToInt(y);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::FW_CPlatformPoint
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformPoint::FW_CPlatformPoint()
- {
- #ifdef FW_BUILD_WIN
- x = y = 0;
- #endif
- #ifdef FW_BUILD_MAC
- h = v = 0;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::FW_CPlatformPoint
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformPoint::FW_CPlatformPoint(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy)
- {
- #ifdef FW_BUILD_WIN
- x = xx; y = yy;
- #endif
- #ifdef FW_BUILD_MAC
- h = xx; v = yy;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::FW_CPlatformPoint
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformPoint::FW_CPlatformPoint(const FW_SPoint& point)
- {
- #ifdef FW_BUILD_WIN
- x = FW_FixedToInt(point.x), y = FW_FixedToInt(point.y);
- #endif
- #ifdef FW_BUILD_MAC
- h = FW_FixedToInt(point.x), v = FW_FixedToInt(point.y);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::FW_CPlatformPoint
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformPoint::FW_CPlatformPoint(const FW_CPlatformPoint& other)
- {
- #ifdef FW_BUILD_WIN
- x = other.x; y = other.y;
- #endif
- #ifdef FW_BUILD_MAC
- h = other.h; v = other.v;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::FW_CPlatformPoint
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformPoint::FW_CPlatformPoint(const FW_PlatformPoint& plfmPoint)
- {
- #ifdef FW_BUILD_WIN
- x = plfmPoint.x; y = plfmPoint.y;
- #endif
- #ifdef FW_BUILD_MAC
- h = plfmPoint.h; v = plfmPoint.v;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::operator=
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformPoint& FW_CPlatformPoint::operator=(const FW_SPoint& point)
- {
- #ifdef FW_BUILD_WIN
- x = FW_FixedToInt(point.x), y = FW_FixedToInt(point.y);
- #endif
- #ifdef FW_BUILD_MAC
- h = FW_FixedToInt(point.x), v = FW_FixedToInt(point.y);
- #endif
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::operator=
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformPoint& FW_CPlatformPoint::operator=(const FW_CPlatformPoint& other)
- {
- #ifdef FW_BUILD_WIN
- x = other.x; y = other.y;
- #endif
- #ifdef FW_BUILD_MAC
- h = other.h; v = other.v;
- #endif
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::operator=
- //----------------------------------------------------------------------------------------
- inline FW_CPlatformPoint& FW_CPlatformPoint::operator=(const FW_PlatformPoint& plfmPoint)
- {
- #ifdef FW_BUILD_WIN
- x = plfmPoint.x; y = plfmPoint.y;
- #endif
- #ifdef FW_BUILD_MAC
- h = plfmPoint.h; v = plfmPoint.v;
- #endif
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::Set
- //----------------------------------------------------------------------------------------
- inline void FW_CPlatformPoint::Set(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy)
- {
- #ifdef FW_BUILD_WIN
- x = xx; y = yy;
- #endif
- #ifdef FW_BUILD_MAC
- h = xx; v = yy;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::X
- //----------------------------------------------------------------------------------------
- inline FW_PlatformCoordinate FW_CPlatformPoint::X() const
- {
- #ifdef FW_BUILD_WIN
- return x;
- #endif
- #ifdef FW_BUILD_MAC
- return h;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::Y
- //----------------------------------------------------------------------------------------
- inline FW_PlatformCoordinate FW_CPlatformPoint::Y() const
- {
- #ifdef FW_BUILD_WIN
- return y;
- #endif
- #ifdef FW_BUILD_MAC
- return v;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::X
- //----------------------------------------------------------------------------------------
- inline FW_PlatformCoordinate& FW_CPlatformPoint::X()
- {
- #ifdef FW_BUILD_WIN
- return x;
- #endif
- #ifdef FW_BUILD_MAC
- return h;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::Y
- //----------------------------------------------------------------------------------------
-
- inline FW_PlatformCoordinate& FW_CPlatformPoint::Y()
- {
- #ifdef FW_BUILD_WIN
- return y;
- #endif
- #ifdef FW_BUILD_MAC
- return v;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::operator==
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CPlatformPoint::operator==(const FW_CPlatformPoint& pt) const
- {
- #ifdef FW_BUILD_WIN
- return x == pt.x && y == pt.y;
- #endif
- #ifdef FW_BUILD_MAC
- return h == pt.h && v == pt.v;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformPoint::operator!=
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CPlatformPoint::operator!=(const FW_CPlatformPoint& pt) const
- {
- #ifdef FW_BUILD_WIN
- return x != pt.x || y != pt.y;
- #endif
- #ifdef FW_BUILD_MAC
- return h != pt.h || v != pt.v;
- #endif
- }
-
- #endif
-