home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AltPoly.h
-
- Contains: OpenDoc polygon: optional C++ savvy classes
-
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 5/24/96 jpa 1.1MRD: pragma internal
-
- Theory of Operation:
-
- This is an alternate definition of ODPolygon and ODContour. The data format is
- identical, but the structs defined here have a lot of useful methods including
- constructors, accessors and conversion operators.
-
- To use these instead of the regular structs defined in Polygon.h, just include
- this header file _before_ Polygon.h. An easy way to do this is to include it
- first.
-
- QuickDraw GX users take note:
- ODContour is identical in data format to a gxPolygon.
- ODPolygonData (the data stored inside an ODPolygon) is identical in data
- format to a gxPolygons <sic>.
- See <GXTypes.h>.
-
- ** The way things are done has changed since A6. SOM wants all variable-sized
- structures to adhere to a common data forma, where a small struct points to
- the data and stores its size. This is so DSOM can tell how to copy the data
- across an address-space boundary. The ODPolygon structure has most of the same
- methods as before, but you can now create them directly. However, to get the
- actual polygon data you'll need to call the GetData method. **
-
- In Progress:
- */
-
-
- #ifndef _ALTPOLY_
- #define _ALTPOLY_
-
- #ifdef SOM_Module_OpenDoc_Polygon_defined
- #error "Must include AltPoly.h *before* Polygon.xh!"
- #else
- /* Make sure Polygon.xh does NOT get included later! */
- #define SOM_Module_OpenDoc_Polygon_defined 2
- #endif
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h> /* For Destructo, used by ODTempPolygon */
- #endif
-
- #include <stddef.h> /* for size_t */
-
- #if _PLATFORM_MACINTOSH_
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h> /* for Region and Polygon types */
- #endif
- #ifndef __FIXMATH__
- #include <FixMath.h> /* Must include before GX headers... */
- #endif
- #ifndef __GXTYPES__
- #include <GXTypes.h> /* for gxShape type */
- #endif
- #endif
-
-
- #ifdef PRAGMA_INTERNAL_SUPPORTED
- #pragma internal on
- #endif
-
-
- //==============================================================================
- // Classes used in this interface
- //==============================================================================
-
- struct ODRect;
- class ODStorageUnit;
- class ODTransform;
-
- //==============================================================================
- // ODContour
- //==============================================================================
-
- struct ODContour
- {
- public:
-
- ODSLong nVertices;
- ODPoint vertex[1]; // Array size is actually nVertices
-
- ODContour* NextContour( ) const {return (ODContour*)&vertex[nVertices];}
- ODBoolean IsRectangular( ) const;
- ODBoolean AsRectangle( ODRect* ) const;
- #if _PLATFORM_MACINTOSH_
- PolyHandle AsQDPolygon( ) const;
- ODBoolean HasExactRegion( ) const;
- #endif
-
- ODBoolean operator== ( const ODContour& ) const;
- ODBoolean operator!= ( const ODContour &c ) const {return !(*this==c);}
- };
-
- //==============================================================================
- // ODPolygonData
- //==============================================================================
-
- struct ODPolygonData {
- ODSLong nContours; // Number of contours
- ODContour firstContour; // Rest of contours follow after first
- };
-
- //==============================================================================
- // ODPolygon
- //==============================================================================
-
- class ODPolygon
- {
- public:
-
- ODPolygon( );
- #if ODDebug
- ~ODPolygon( ); // Delete myself, but not data
- #endif
-
- void Delete( ); // Delete myself & my data
- void Clear( ); // Just deletes my data
-
- // ACCESSORS:
-
- ODBoolean HasData( ) const {return _length!=0;}
- ODULong GetDataSize( ) const {return _length;}
- ODPolygonData* GetData( ) const {return _buf;}
-
- void SetData( const ODPolygonData* ); // Does not copy the data!
-
- ODSLong GetNContours( ) const;
- ODContour* FirstContour( );
- const ODContour*FirstContour( ) const;
-
- // GEOMETRY:
-
- void ComputeBoundingBox( ODRect* ) const;
- ODBoolean IsRectangular( ) const;
- void Transform( Environment*, ODTransform* );
-
- ODBoolean operator== ( ODPolygon& ) const;
- ODBoolean operator!= ( ODPolygon& p ) const {return !(*this==p);}
-
- ODSLong Contains( ODPoint ) const;
- ODBoolean IsEmpty( ) const;
-
- // CONVERSIONS:
-
- ODBoolean AsRectangle( ODRect* ) const; // False if nonrectangular
- #if _PLATFORM_MACINTOSH_
- ODBoolean HasExactRegion( ) const;
- RgnHandle AsQDRegion( ) const;
- gxShape AsGXShape( ) const;
- #endif
-
- // ALLOCATION:
-
- ODPolygon* SetNVertices( ODSLong nVertices );
- ODPolygon* SetVertices( ODSLong nVertices, const ODPoint *vertices );
- ODPolygon* SetContours( ODSLong nContours, const ODSLong *contourVertices );
- ODPolygon* SetRect( const ODRect& );
-
- ODPolygon* Copy( ) const;
- ODPolygon* CopyFrom( const ODPolygon& );
- #if _PLATFORM_MACINTOSH_
- ODPolygon* CopyFrom( gxShape ); // Accepts rect, polygon(s), path(s)
- #endif
- ODPolygon* MoveFrom( ODPolygon& ); // Justs adjusts pointers, no copying
-
- // INPUT/OUTPUT:
-
- ODPolygon* ReadFrom( Environment*, ODStorageUnit* );
- ODPolygon* WriteTo( Environment*, ODStorageUnit* ) const;
-
- private:
-
- void Realloc( ODULong dataSize );
-
- // DATA MEMBERS:
-
- unsigned long _maximum; // Exact same data as an ODByteArray
- unsigned long _length;
- ODPolygonData *_buf;
- };
-
-
- //==============================================================================
- // ODTempPolygon
- //==============================================================================
-
- /* ODTempPolygon is a polygon whose destructor disposes of its data.
- This is useful if you have a local variable that's a temporary polygon
- and you want to make sure the data gets disposed.
- This _is_ exception-safe: inheriting from Destructo guarantees that the
- data will be cleaned up even if an exception is thrown.
- */
-
- class ODTempPolygon :public ODPolygon, Destructo
- {
- public:
- ODTempPolygon( );
- ~ODTempPolygon( );
- };
-
-
- /* ODTempPolygonPtr is a _pointer_ to a polygon, whose destructor deletes
- the polygon structure (and its data.) Yes, it is a class, but due to the
- magic of operator overloading it can be used just as a pointer. See the
- implementation of ODPolygon::Copy in AltPoly.cpp for an example. */
-
- class ODTempPolygonPtr :Destructo
- {
- public:
- ODTempPolygonPtr( );
- ODTempPolygonPtr( ODPolygon* );
- ~ODTempPolygonPtr( );
- operator ODPolygon* ( ) {return fPoly;}
- ODPolygon* operator-> ( ) {return fPoly;}
- ODPolygon* operator= ( ODPolygon *p ) {return (fPoly=p);}
- ODPolygon* DontDelete( ) {ODPolygon* temp=fPoly; fPoly=kODNULL; return temp;}
-
- private:
- ODPolygon *fPoly;
- };
-
-
- /* TempGXShape is a temporary reference to a gxShape. It will be released when
- the reference goes out of scope. For an example, see the implementation of
- ODPolygon::CopyFrom( gxShape ). */
-
- class TempGXShape :Destructo
- {
- public:
- TempGXShape( );
- TempGXShape( gxShape );
- ~TempGXShape( );
- operator gxShape ( ) {return fShape;}
- gxShape operator= ( gxShape s ) {return (fShape=s);}
- gxShape DontRelease( ) {gxShape temp=fShape; fShape=kODNULL; return temp;}
-
- private:
- gxShape fShape;
- };
-
-
- //==============================================================================
- // Polygon Edge Iterator
- //==============================================================================
-
- class PolyEdgeIterator {
- public:
-
- PolyEdgeIterator( const ODPolygon* );
-
- void CurrentEdge( const ODPoint* &v1, const ODPoint* &v2 );
- const ODContour* CurrentContour( ) {return fCurContour;}
- long CurrentContourIndex( ) {return fCurContourIndex;}
- long CurrentEdgeIndex( ) {return fCurVertex;}
-
- ODBoolean Next( );
- ODBoolean IsNotComplete( );
-
- private:
- const ODPolygon* const fPoly;
- const ODContour* fCurContour;
- long fCurContourIndex;
- long fCurVertex;
- };
-
-
- #ifdef PRAGMA_INTERNAL_SUPPORTED
- #pragma internal off
- #endif
-
- #endif //_ALTPOLY_