NAME
Graphic - persistent structured graphics objectsSYNOPSIS
#include <InterViews/graphic.h>DESCRIPTION
#include <InterViews/Graphic/ellipses.h>
#include <InterViews/Graphic/instance.h>
#include <InterViews/Graphic/label.h>
#include <InterViews/Graphic/lines.h>
#include <InterViews/Graphic/picture.h>
#include <InterViews/Graphic/polygons.h>
#include <InterViews/Graphic/rasterrect.h>
#include <InterViews/Graphic/splines.h>
#include <InterViews/Graphic/stencil.h>
This manual page describes the Graphic base class for structured graphics objects and the derived classes provided by the libgraphic library. See the Introduction for a general overview of the libgraphic library.STATE OPERATIONS
Graphic(Graphic* = nil)DRAWING OPERATIONSCreate a new graphic having a copy of the given graphic's state. All state values are set to nil (undefined) by default.virtual Graphic* Copy()Returns an exact duplicate of the graphic. This function should be redefined in user-derived graphic classes to guarantee these semantics.void SetBrush(PBrush*)
PBrush* GetBrush()Set or return the graphic's brush.void SetColors(PColor* fg, PColor* bg)
PColor* GetFgColor()
PColor* GetBgColor()Set or return the graphic's colors.void SetFont(PFont*)
PFont* GetFont()Set or return the graphic's label font.void SetPattern(PPattern*)
PPattern* GetPattern()
void FillBg(bool mode)
bool BgFilled()Set or return the graphic's fill pattern and mode. If the mode is true, fill operations will set pixels corresponding to 1's in the current fill pattern to the foreground color and pixels corresponding to 0's to the background color. If false, then only foreground pixels will be set. The default mode is true.Graphic* Parent()
virtual bool HasChildren()Parent returns the graphic's parent, if any. HasChildren returns false by default; it should be redefined if a subclass should provide this information.void SetTag(Ref)
Ref GetTag()Set or return a tag associated with the graphic.virtual Graphic& operator = (Graphic&)The assignment operator is overloaded to copy the passed graphic's graphic state into this object's.void Translate(float dx, float dy)
void Rotate(float angle, float cx = 0.0, float cy = 0.0)
void Scale(float x, float y, float cx = 0.0, float cy = 0.0)
void SetTransformer(Transformer*)
Transformer* GetTransformer()
void TotalTransformation(Transformer&)Coordinates passed to drawing operations are transformed according to the current translation (cumulative), rotation, and scale factor. Optionally, scaling and rotation can be performed relative to a point (cx, cy). Internally, a transformation matrix is stored that can be directly set and accessed using SetTransformer and GetTransformer. The default transformer is nil, meaning no transformations are performed. TotalTransformation postmultiplies the given transformer by the total transformation incurred by the graphic's parents, if any.virtual void GetBounds(float& left, float& bottom, float& right, float& top)Unless otherwise noted, input and output coordinates are relative to the coordinate system defined by the graphic's transformer.
Return the exact coordinates of the smallest box circumscribing the graphic. The return values are in absolute coordinates.void GetBox(Coord& left, Coord& bottom, Coord& right, Coord& top)
void GetBox(BoxObj&)Return the smallest box circumscribing the graphic, in Coords. The return values are in absolute coordinates. A BoxObj represents a rectangle defined by lower left and upper right coordinates. BoxObj is defined invirtual void GetCenter(float& x, float& y). Return the center point of the graphic in absolute coordinates.virtual bool Contains(PointObj&)
virtual bool Intersects(BoxObj&)Return whether or not the graphic contains the given point or intersects the given rectangular area specified in absolute coordinates. PointObj, defined in <InterViews/Graphic/geomobjs.h>, describes a point.void Align(Alignment, Graphic*, Alignment)Position the given graphic relative to this. The graphic that performs the operation stays fixed, while the graphic supplied as the argument is translated appropriately. The first Alignment parameter specifies the alignment with respect to this, while the second specifies the alignment with respect to the given graphic.
virtual void Draw(Canvas*)DERIVED CLASSES AND OPERATIONS
virtual void Erase(Canvas*)Draw draws the graphic on the given canvas using its current state. Erase erases the graphic by temporarily setting its foreground color equal to its background color and then drawing it.virtual void Draw(Canvas*, Coord left, Coord bottom, Coord right, Coord top)
virtual void Erase(Canvas*, Coord left, Coord bottom, Coord right, Coord top)Draw or erase the graphic on the canvas within the given bounding box, specified in absolute coordinates, without using fine clipping. The bounding box should be used simply as a hint about the graphic's visibility.virtual void DrawClipped(Canvas*, Coord left, Coord bottom, Coord right, Coord top)
virtual void EraseClipped(Canvas*, Coord left, Coord bottom, Coord right, Coord top)Draw or erase the graphic on the canvas strictly within the given bounding box, specified in absolute coordinates.
The following derived class are predefined. In addition to the inherited operations, each derived class defines a GetOriginal(...) operation that returns the values supplied to the constructor when the object was created.FILESPoint(Coord x, Coord y, Graphic* graphic = nil)
Line(Coord x0, Coord y0, Coord x1, Coord y1, Graphic* graphic = nil)
MultiLine(Coord* x, Coord* y, int n, Graphic* graphic = nil)Define a point, line, or set of connected lines at the specified coordinates, optionally having the same state as the given graphic. MultiLine's constructor copies the arrays of Coords that define its vertices. MultiLine provides two GetOriginal operations: one returns copies of the stored arrays, while the other the returns constant pointers to the arrays. MultiLine also defines == and != operators that compare the vertices of one instance against another's; two MultiLine instances are considered equivalent if they share the same vertices.Ellipse(Coord x0, Coord y0, int r1, int r2, Graphic* graphic = nil)
FillEllipse(Coord x0, Coord y0, int r1, int r2, Graphic* graphic = nil)Define an ellipse or filled ellipse with center at (x0,y0) and radii r1 and r2.Circle(Coord x0, Coord y0, int radius, Graphic* graphic = nil)
FillCircle(Coord x0, Coord y0, int radius, Graphic* graphic = nil)Define a circle or filled circle with center at (x0,y0) and radius radius.Rect(Coord x0, Coord y0, Coord x1, Coord y1, Graphic* graphic = nil)
FillRect(Coord x0, Coord y0, Coord x1, Coord y1, Graphic* graphic = nil)Define a rectangle or filled rectangle at the specified coordinates.Polygon(Coord* x, Coord* y, int n, Graphic* graphic = nil)
FillPolygon(Coord* x, Coord* y, int n, Graphic* graphic = nil)Define a polygon or filled polygon specified by the n vertices. The vertex semantics are the same as those for MultiLine.BSpline(Coord* x, Coord* y, int n, Graphic* graphic = nil)
ClosedBSpline(Coord* x, Coord* y, int n, Graphic* graphic = nil)
FillBSpline(Coord* x, Coord* y, int n, Graphic* graphic = nil)Define a B-spline specified by the n control vertices. If closed or filled, the last point is connected to the first point. The vertex semantics are the same as those for MultiLine.Label(const char* string, Graphic* graphic = nil)
Label(const char* string, int n, Graphic* graphic = nil)Define a string or substring of text. If background fill mode is on, then the characters are drawn in the foreground color and other pixels within character boundaries are set to the background color. If background fill mode is off, only the foreground pixels are set.Stencil(Bitmap* image, Bitmap* mask = nil, Graphic* graphic = nil)A stencil graphic is defined by an image Bitmap and an optional mask Bitmap. The image defines the bits that will be drawn in the current foreground color (set bits) and background color (clear bits), and the mask defines which parts of the image will be drawn. The stencil graphic adopts the width and height of the mask if there is one; otherwise, it adopts the width and height of the image.RasterRect(Raster*, Graphic* graphic = nil)A raster rect is a graphic that displays a color raster image defined by a Raster object. The raster rect adopts the width and height of the Raster.Picture(Graphic* graphic = nil)
void Picture::Append(Graphic*)
void Picture::Prepend(Graphic*)
void Picture::InsertAfterCur(Graphic*)
void Picture::InsertBeforeCur(Graphic*)
void Picture::Remove(Graphic*)
void Picture::RemoveCur()
void Picture::SetCurrent(Graphic*)
Graphic* Picture::GetCurrent()
Graphic* Picture::First()
Graphic* Picture::Last()
Graphic* Picture::Next()
Graphic* Picture::Prev()
bool Picture::IsEmpty()
bool Picture::AtEnd()
Graphic* Picture::FirstGraphicContaining(PointObj&)
Graphic* Picture::LastGraphicContaining(PointObj&)
int Picture::GraphicsContaining(PointObj&, Graphic**&)
Graphic* Picture::FirstGraphicIntersecting(BoxObj&)
Graphic* Picture::LastGraphicIntersecting(BoxObj&)
int Picture::GraphicsIntersecting(BoxObj&, Graphic**&)
Graphic* Picture::FirstGraphicWithin(BoxObj&)
Graphic* Picture::LastGraphicWithin(BoxObj&)
int Picture::GraphicsWithin(BoxObj&, Graphic**&)
void Picture::Propagate()A Picture is a graphic that contains other graphics (subgraphics). The subgraphics are deallocated when the picture is destroyed. A picture has its own state which is ``concatenated'' with the state of its subgraphics when the picture is drawn or erased. The semantics of concatentation are that subgraphics are drawn with the picture's state information substituted for their own, except for attributes that are undefined (nil) in the picture; the subgraphics' individual attributes are used for these values. Furthermore, each subgraphic's transformer is postmultiplied by the picture's transformer when the picture is drawn, so that subgraphics are drawn relative to the picture's coordinate system.Instance(Graphic* obj = nil, Graphic* graphic = nil)Several operations are defined on Picture to allow subgraphics to be added, removed, and manipulated. Append and Prepend allow subgraphics to be added to the beginning and end of the picture, respectively. Subgraphics are drawn starting from the beginning of the picture, so that the most recently appended graphic is drawn last. Each picture maintains a pointer to its ``current'' subgraphic which can be set explicitly using SetCurrent and retrieved with GetCurrent. InsertAfterCur and InsertBeforeCur insert a graphic after or before the current subgraphic, respectively. Remove and RemoveCur remove a subgraphic from the picture. First and Last return the first and last graphics in the picture. Next and Prev return the subgraphic following and preceding the current one, respectively, and set the current subgraphic to the value returned. IsEmpty returns whether or not the picture has any subgraphics, and AtEnd returns true if the current subgraphic pointer has been advanced past the last subgraphic.
FirstGraphicContaining, LastGraphicContaining, FirstGraphicIntersecting, LastGraphicIntersecting, FirstGraphicWithin, and LastGraphicWithin return the first or last graphic in the picture that contains a point, intersects a box, and falls completely within a box, respectively. GraphicsContaining, GraphicsIntersecting, and GraphicsWithin return as a side-effect an array containing those subgraphics that contain a point, intersect a box, and fall completely within a box, respectively. These functions return the size of the array.
Finally, Propagate modifies the graphics state of the picture's subgraphics by concatenating in place each subgraphic's state with the picture's own. This is useful when the subgraphics should retain their appearance after removal from the picture. The picture's transformer is set to nil following the propagation to avoid concatenating its coordinate transformation twice.
An Instance of a graphic consists of all the usual state plus a reference to another graphic specified by obj. When drawn or erased, the instance concatenates the state of the graphic it references with its own.
SEE ALSOpersistent paint objects
persistent geometry objects
Introduction , Bitmap , Canvas , Transformer , Painter , Persistent , Raster