/* * Copyright (c) 1987, 1988, 1989 Stanford University * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Stanford not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. Stanford makes no representations about * the suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * Interface to Graphic base class and FullGraphic, a subclass of Graphic * for which all graphics state is defined. */ #ifndef base_h #define base_h #include #include #include static const int UNDEF = -1; class Canvas; class GraphicToPainter; class Graphic : public Persistent { public: Graphic(Graphic* gr = nil); virtual ~Graphic(); virtual void Draw(Canvas*); virtual void Draw(Canvas*, Coord, Coord, Coord, Coord); virtual void DrawClipped(Canvas*, Coord, Coord, Coord, Coord); virtual void Erase(Canvas*); virtual void Erase(Canvas*, Coord, Coord, Coord, Coord); virtual void EraseClipped(Canvas*, Coord, Coord, Coord, Coord); virtual void FillBg(bool); virtual int BgFilled(); virtual void SetColors(PColor* f, PColor* b); virtual PColor* GetFgColor(); virtual PColor* GetBgColor(); virtual void SetPattern(PPattern*); virtual PPattern* GetPattern(); virtual void SetBrush(PBrush*); virtual PBrush* GetBrush(); virtual void SetFont(PFont*); virtual PFont* GetFont(); // These changed to virtual by SVS 4/25/94 virtual void Translate(float dx, float dy); virtual void Scale(float sx, float sy, float ctrx = 0.0, float ctry = 0.0); virtual void Rotate(float angle, float ctrx = 0.0, float ctry = 0.0); void Align(Alignment, Graphic*, Alignment); void SetTransformer(Transformer*); Transformer* GetTransformer(); void TotalTransformation(Transformer&); void GetBounds(float&, float&, float&, float&); void GetBox(Coord&, Coord&, Coord&, Coord&); void GetBox(BoxObj&); virtual void GetCenter(float&, float&); virtual bool Contains(PointObj&); virtual bool Intersects(BoxObj&); void SetTag(Ref); Ref GetTag(); Graphic* Parent(); virtual bool HasChildren (); virtual Graphic& operator = (Graphic&); virtual Graphic* Copy(); virtual Persistent* GetCluster(); virtual ClassId GetClassId(); virtual bool IsA(ClassId); protected: /* * Member functions that declare a "Graphic* gs" parameter * take into account that graphic's graphic state information when * performing their function. This is useful in hierarchical graphic objects * (such as Pictures) where higher-level graphics' graphics state influences * lower (and ultimately leaf) graphics'. */ void update(Graphic* gs); /* updates painter w/gs' state */ virtual void draw(Canvas*, Graphic* gs); virtual void drawClipped(Canvas*, Coord, Coord, Coord, Coord, Graphic* gs); virtual void erase(Canvas*, Graphic* gs); virtual void eraseClipped(Canvas*, Coord, Coord, Coord, Coord,Graphic* gs); /* * Bounding box operations. */ virtual void getExtent(float&, float&, float&, float&, float&,Graphic* gs); /* Returns lower-left and center coordinates, and a tolerance (tol) * (in canvas coordinates) by which the final extent will be grown * in each direction (i.e. l-=tol, b-=tol, r+=tol, t+=tol). */ void GetExtent(Extent& e); void getBounds(float&, float&, float&, float&, Graphic* gs); void getBox(Coord&, Coord&, Coord&, Coord&, Graphic* gs); void getBox(BoxObj&, Graphic* gs); virtual bool contains(PointObj&, Graphic* gs); virtual bool intersects(BoxObj&, Graphic* gs); /* * Parent-related operations. */ Graphic* getRoot(); /* top level parent */ void totalGS(Graphic& p); void parentXform(Transformer& t); /* parents' transformation */ void setParent(Graphic*, Graphic* parent); void unsetParent(Graphic*); /* * Bounding box caching operations. */ void cachingOn(); void cachingOff(); virtual bool extentCached(); virtual void uncacheExtent(); virtual void uncacheParents(); virtual void uncacheChildren(); virtual void invalidateCaches(); /* * Graphics state concatentation operations. */ virtual void concatGS(Graphic* a, Graphic* b, Graphic* dest); virtual void concatTransformer( Transformer* a, Transformer* b, Transformer* dest ); virtual void concat(Graphic* a, Graphic* b, Graphic* dest); /* * Convenient transformations that check first if there's a transformer and * then perform the (inverse) transformation. The functions use the * transformer of the supplied Graphic if there is one; otherwise this' * transformer is used. */ void transform(Coord& x, Coord& y, Graphic* = nil); void transform(Coord x, Coord y, Coord& tx, Coord& ty, Graphic* = nil); void transform(float x, float y, float& tx, float& ty, Graphic* = nil); void transformList( Coord x[], Coord y[], int n, Coord tx[], Coord ty[], Graphic* = nil ); void transformRect( float, float, float, float, float&, float&, float&, float&, Graphic* = nil ); void invTransform(Coord& tx, Coord& ty, Graphic* = nil); void invTransform(Coord tx, Coord ty, Coord& x, Coord& y, Graphic* = nil); void invTransform(float tx, float ty, float& x, float& y, Graphic* = nil); void invTransformList( Coord tx[], Coord ty[], int n, Coord x[], Coord y[], Graphic* = nil ); void invTransformRect( float, float, float, float, float&, float&, float&, float&, Graphic* = nil ); /* * Painter-equivalent rendering operations. Graphic subclasses should use * to draw themselves instead of using a painter directly. */ void pText(Canvas* c, char* s, int n, Coord x, Coord y); void pPoint(Canvas* c, Coord x, Coord y); void pMultiPoint(Canvas*, Coord x[], Coord y[], int); void pLine(Canvas*, Coord, Coord, Coord, Coord); void pRect(Canvas*, Coord, Coord, Coord, Coord); void pFillRect(Canvas*, Coord, Coord, Coord, Coord); void pRasterRect(Canvas*, Coord, Coord, Raster*); void pStencil(Canvas*, Coord, Coord, Bitmap*, Bitmap*); void pCircle(Canvas*, Coord, Coord, int); void pFillCircle(Canvas*, Coord, Coord, int); void pEllipse(Canvas*, Coord, Coord, int, int); void pFillEllipse(Canvas*, Coord, Coord, int, int); void pMultiLine(Canvas*, Coord x[], Coord y[], int); void pPolygon(Canvas*, Coord x[], Coord y[], int); void pFillPolygon(Canvas*, Coord x[], Coord y[], int); void pBSpline(Canvas*, Coord x[], Coord y[], int); void pClosedBSpline(Canvas*, Coord x[], Coord y[], int); void pFillBSpline(Canvas*, Coord x[], Coord y[], int); /* * "Helper" functions that allow graphic subclasses to call * the protected member functions redefined by other graphic subclasses. */ void drawGraphic(Graphic*, Canvas*, Graphic*); void drawClippedGraphic(Graphic*,Canvas*, Coord,Coord,Coord,Coord,Graphic*); void eraseGraphic(Graphic*, Canvas*, Graphic*); void eraseClippedGraphic( Graphic*, Canvas*, Coord, Coord, Coord, Coord, Graphic* ); void getExtentGraphic( Graphic*, float&, float&, float&, float&, float&, Graphic* gs ); bool containsGraphic(Graphic*, PointObj&, Graphic* gs); bool intersectsGraphic(Graphic*, BoxObj&, Graphic* gs); bool extentCachedGraphic(Graphic*); void uncacheExtentGraphic(Graphic*); void uncacheParentsGraphic(Graphic*); void uncacheChildrenGraphic(Graphic*); void invalidateCachesGraphic(Graphic*); void concatGSGraphic(Graphic*, Graphic*, Graphic*, Graphic*); void concatTransformerGraphic( Graphic*,Transformer*, Transformer*, Transformer* ); void concatGraphic(Graphic*, Graphic*, Graphic*, Graphic*); /* * Persistent read/write operations. */ virtual bool read(PFile*); virtual bool write(PFile*); protected: static Transformer* identity; /* identity matrix */ static bool caching; /* state of bounding box caching */ private: Ref parent; int fillBg; Ref fg; Ref bg; Ref tag; Transformer* t; static GraphicToPainter* painters; static Painter* p; }; class FullGraphic : public Graphic { public: FullGraphic(Graphic* = nil); virtual void SetPattern(PPattern*); virtual PPattern* GetPattern(); virtual void SetBrush(PBrush*); virtual PBrush* GetBrush(); virtual void SetFont(PFont*); virtual PFont* GetFont(); virtual Graphic* Copy(); virtual ClassId GetClassId(); virtual bool IsA(ClassId); protected: virtual bool read(PFile*); virtual bool write(PFile*); private: Ref pat; Ref brush; Ref font; }; #endif