home *** CD-ROM | disk | FTP | other *** search
- /*
- File: GXShpe.cpp
-
- Contains: QDGXShape class, private to ODShape.
-
- Owned by: Jens Alfke
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <13> 8/29/95 jpa Throw kODErrInvalidPlatformShape instead of
- kODErrInvalidValue. [1278284]
- <12> 8/16/95 NP 1274946: ErrorDef.idl problems. Add include
- file.
- <11> 5/25/95 jpa Use new GX headers [1241078, 1253324]
- <10> 3/20/95 jpa No need to wrap TRY around use of
- ODTempPolygon. [1215160]
- <9> 1/12/95 jpa Removed five-dollar comment, now bug
- 1209729. [1209502]
- <8> 12/5/94 jpa gxSolidFill -> gxWindingFill. [1191192]
- <7> 10/24/94 jpa Fixed IsRectangular to use ODPolygon
- properly. Fixed ContainsPoint. [1186370,
- <6> 9/29/94 RA 1189812: Mods for 68K build.
- <5> 9/9/94 jpa Implemented InitQDRegion. Fixed crasher in
- Copy. [1179306] [1181523]
- <4> 8/17/94 jpa Fixed bug in Copy method that was
- accidentally deleting the copied gxShape
- <3> 8/8/94 jpa Added Outset method [1178690]
- <2> 8/2/94 jpa Don't dispose NULL GX shapes.
- <1> 6/15/94 jpa first checked in
-
- In Progress:
-
- */
-
-
- #ifndef _ALTPOINT_
- #include "AltPoint.h" /* Use C++ savvy ODPoint and ODRect*/
- #endif
-
- #ifndef _ALTPOLY_
- #include "AltPoly.h"
- #endif
-
- #ifndef _GXSHPE_
- #include "GXShpe.h"
- #endif
-
- #ifndef _RECTSHPE_
- #include "RectShpe.h"
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include "Trnsform.xh"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _UTILERRS_
- #include "UtilErrs.h"
- #endif
-
- #ifndef __GXGRAPHICS__
- #include <GXGraphics.h>
- #endif
-
-
- #pragma segment QDGXShape
-
-
- QDGXShape::QDGXShape( ODGeometryMode mode )
- :RealShape(mode),
- fGXShape(kODNULL),
- fBoundsValid(kODFalse)
- {
- #if ODDebug
- fType = 3;
- #endif
- }
-
-
- QDGXShape::~QDGXShape( )
- {
- if( fGXShape )
- GXDisposeShape(fGXShape);
- }
-
-
- ODSize
- QDGXShape::Purge( ODSize bytes )
- {
- if( bytes==0 )
- fBoundsValid = kODFalse; // Zero means just flush cache
- return RealShape::Purge(bytes);
- }
-
-
- void
- QDGXShape::GetBoundingBox( ODRect *bounds )
- {
- if( !fBoundsValid ) {
- if( fGXShape ) {
- ClearGXError();
- GXGetShapeBounds(fGXShape,0,(gxRectangle*)&fBounds);
- ThrowIfFirstGXError();
- } else
- fBounds.Clear();
- }
- if( bounds )
- *bounds = fBounds;
- }
-
-
- RealShape*
- QDGXShape::SetRectangle( const ODRect *r )
- {
- if( fGXShape )
- GXSetRectangle(fGXShape, (gxRectangle*)r);
- else {
- fGXShape = GXNewRectangle((gxRectangle*)r);
- GXSetShapeFill(fGXShape,gxWindingFill);
- }
- this->Purge(0);
- ThrowIfFirstGXError();
- return this;
- }
-
-
- void
- QDGXShape::CopyPolygon( ODPolygon &poly )
- {
- ASSERT_NOT_NULL(fGXShape);
- poly.CopyFrom(fGXShape);
- }
-
-
- RealShape*
- QDGXShape::SetPolygon( const ODPolygon &poly )
- {
- ClearGXError();
- if( fGXShape && GXGetShapeType(fGXShape)==gxPolygonType )
- GXSetPolygons(fGXShape, (gxPolygons*)poly.GetData() );
- else {
- gxShape shape = GXNewPolygons( (gxPolygons*)poly.GetData() );
- GXSetShapeFill(shape,gxWindingFill);
- if( shape ) {
- if( fGXShape ) GXDisposeShape(fGXShape);
- fGXShape = shape;
- }
- }
- this->Purge(0);
- ThrowIfFirstGXError();
- return this;
- }
-
-
- void
- QDGXShape::InitQDRegion( )
- {
- // Unfortunately in GX 1.0 there is no good way to convert a shape to a region.
-
- ODTempPolygon poly;
- poly.CopyFrom(fGXShape);
- fQDRegion = poly.AsQDRegion();
- }
-
-
- gxShape
- QDGXShape::CopyGXShape( )
- {
- ASSERT_NOT_NULL(fGXShape);
- return GXCloneShape(fGXShape);
- }
-
-
- void
- QDGXShape::SetPlatformShape( ODGraphicsSystem system, ODPlatformShape s )
- {
- ASSERT(system==kODQuickDrawGX,kODErrAssertionFailed);
-
- ASSERT_NOT_NULL(s);
- if( s != fGXShape ) {
- gxShapeType type = GXGetShapeType((gxShape)s);
- if( type!=gxRectangleType && type!=gxPolygonType && type!=gxPathType
- && type!=gxEmptyType && type!=gxFullType )
- THROW(kODErrInvalidPlatformShape);
-
- if( fGXShape ) GXDisposeShape(fGXShape);
- fGXShape = (gxShape) s;
- this->Purge(0);
- }
- }
-
-
- ODBoolean
- QDGXShape::IsSameAs( RealShape *shape )
- {
- ASSERT_NOT_NULL(fGXShape);
- if( shape==this )
- return kODTrue;
- if( this->IsEmpty() )
- return shape->IsEmpty();
- else if( shape->IsEmpty() )
- return this->IsEmpty();
- else {
- gxShape itsShape = (gxShape) shape->GetPlatformShape(kODQuickDrawGX);
- ClearGXError();
- Boolean same = GXEqualShape(fGXShape,itsShape);
- GXDisposeShape(itsShape);
- ThrowIfFirstGXError();
- return same;
- }
- }
-
-
- ODBoolean
- QDGXShape::IsEmpty( )
- {
- ASSERT_NOT_NULL(fGXShape);
- gxShapeType type= GXGetShapeType(fGXShape);
- return (type==gxEmptyType || type==gxPointType || type==gxLineType || type==gxCurveType);
- }
-
-
- ODBoolean
- QDGXShape::ContainsPoint( ODPoint point )
- {
- // We have to make the rectangle sliiightly non-empty or GX will ignore it.
- ASSERT_NOT_NULL(fGXShape);
- gxRectangle r = {point.x,point.y, point.x+1,point.y+1};
- return GXTouchesBoundsShape(&r,fGXShape);
- }
-
-
- ODBoolean
- QDGXShape::IsRectangular( )
- {
- ASSERT_NOT_NULL(fGXShape);
- gxShapeType type = GXGetShapeType(fGXShape);
- if( type==gxRectangleType )
- return kODTrue;
-
- else if( type==gxPolygonType ) {
- gxShapeAttribute attr = GXGetShapeAttributes(fGXShape);
- GXSetShapeAttributes(fGXShape, attr | gxDirectShape);
- GXLockShape(fGXShape);
- ODSLong size;
- ODPolygon poly;
- poly.SetData( (ODPolygonData*) GXGetShapeStructure(fGXShape,&size) );
- ODBoolean result = poly.IsRectangular();
- GXUnlockShape(fGXShape);
- GXSetShapeAttributes(fGXShape,attr);
- return result;
-
- } else
- return kODFalse;
- }
-
-
- RealShape*
- QDGXShape::Copy( )
- {
- ASSERT_NOT_NULL(fGXShape);
- gxShape shape = GXCopyToShape(kODNULL,fGXShape);
- QDGXShape *s = kODNULL; ODVolatile(s);
- TRY{
- s = new QDGXShape(fMode);
- s->SetPlatformShape(kODQuickDrawGX, shape);
- }CATCH_ALL{
- GXDisposeShape(shape);
- delete s;
- RERAISE;
- }ENDTRY
- return s;
- }
-
-
- RealShape*
- QDGXShape::Transform( Environment *ev, ODTransform *xform )
- {
- ASSERT_NOT_NULL(fGXShape);
-
- ClearGXError();
- gxMapping map;
- xform->GetMatrix(ev,(ODMatrix*)&map);
- GXMapShape(fGXShape,&map);
- ThrowIfGXError();
- this->Purge(0);
- return this;
- }
-
-
- RealShape*
- QDGXShape::Outset( ODCoordinate distance )
- {
- ASSERT_NOT_NULL(fGXShape);
-
- ClearGXError();
- GXInsetShape(fGXShape,-distance);
- ThrowIfGXError();
- this->Purge(0);
- return this;
- }
-
-
- RealShape*
- QDGXShape::Subtract( RealShape *shape )
- {
- ASSERT_NOT_NULL(fGXShape);
- ClearGXError();
- gxShape itsShape = (gxShape) shape->GetPlatformShape(kODQuickDrawGX);
- GXDifferenceShape(fGXShape,itsShape);
- GXDisposeShape(itsShape);
- ThrowIfFirstGXError();
- this->Purge(0);
- return this;
- }
-
-
- RealShape*
- QDGXShape::Intersect( RealShape *shape )
- {
- ASSERT_NOT_NULL(fGXShape);
- ClearGXError();
- gxShape itsShape = (gxShape) shape->GetPlatformShape(kODQuickDrawGX);
- GXIntersectShape(fGXShape,itsShape);
- GXDisposeShape(itsShape);
- ThrowIfFirstGXError();
- this->Purge(0);
- return this;
- }
-
-
- RealShape*
- QDGXShape::Union( RealShape *shape )
- {
- ASSERT_NOT_NULL(fGXShape);
- ClearGXError();
- gxShape itsShape = (gxShape) shape->GetPlatformShape(kODQuickDrawGX);
- GXUnionShape(fGXShape,itsShape);
- GXDisposeShape(itsShape);
- ThrowIfFirstGXError();
- this->Purge(0);
- return this;
- }
-