shapes.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:45k
- /*
- * shapes.h
- *
- * Geometric Shapes GUI classes.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: shapes.h,v $
- * Revision 1.17 1999/08/17 03:46:40 robertj
- * Fixed usage of inlines in optimised version.
- *
- * Revision 1.16 1999/03/09 08:01:47 robertj
- * Changed comments for doc++ support (more to come).
- *
- * Revision 1.15 1999/02/16 08:08:28 robertj
- * MSVC 6.0 compatibility changes.
- *
- * Revision 1.14 1998/09/23 06:19:56 robertj
- * Added open source copyright license.
- *
- * Revision 1.13 1997/07/08 13:02:07 robertj
- * DLL support.
- *
- * Revision 1.12 1996/08/17 10:00:32 robertj
- * Changes for Windows DLL support.
- *
- * Revision 1.11 1996/08/08 10:08:52 robertj
- * Directory structure changes for common files.
- *
- * Revision 1.10 1995/06/17 11:13:20 robertj
- * Documentation update.
- *
- * Revision 1.9 1995/04/25 11:00:32 robertj
- * Fixed function hiding ancestor virtual.
- *
- * Revision 1.8 1995/03/14 12:42:35 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.7 1995/01/21 05:22:29 robertj
- * Documentation.
- *
- * Revision 1.6 1994/12/05 11:34:23 robertj
- * Major rewrite of images, pictures and pixmaps.
- * Renamed PPict, PPixels and PImage to make sure all uses are found.
- *
- * Revision 1.5 1994/10/23 04:56:18 robertj
- * Changed PImage descendents to be pointers for polymorphism.
- *
- * Revision 1.4 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.3 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.2 1994/06/25 11:55:15 robertj
- * Unix version synchronisation.
- *
- * Revision 1.1 1994/04/01 14:16:42 robertj
- * Initial revision
- *
- * Revision 1.5 1994/01/03 04:42:23 robertj
- * Mass changes to common container classes and interactors etc etc etc.
- *
- * Revision 1.4 1993/11/20 17:26:28 robertj
- * Started implementation.
- *
- * Revision 1.3 1993/10/16 20:33:20 robertj
- * Added PShape API.
- *
- * Revision 1.2 1993/07/14 12:49:16 robertj
- * Fixed RCS keywords.
- *
- */
- #ifndef _PSHAPES
- #define _PSHAPES
- #ifdef __GNUC__
- #pragma interface
- #endif
- /**A class representing a graphics shape object. This is an abstract class for
- a number of objects representing graphics that may be drawn on a canvas, eg
- ref{PLine} or ref{PEllipse} etc.
- A shape has all the niformation needed to draw it. This comes from the
- PCanvasState ancestor plus shape specific information such as the end
- points for a line.
- All shapes have at least a position, plus the capability of a common set of
- behavour as defined by this class, eg the ref{Draw()} function draws the
- shape on a ref{PCanvas}.
- */
- class PShape : public PObject, public PCanvasState {
- PCLASSINFO(PShape, PObject);
- public:
- /**@name Construction */
- //@{
- /** Create a new graphic shape. */
- PShape(
- PORDINATE x, /// Horizontal position for the shape.
- PORDINATE y /// Vertical position for the shape.
- );
- /** Create a new graphic shape. */
- PShape(
- const PPoint & pt /// Position for the shape.
- );
- //@}
- // New functions for class
- void SetPosition(
- PORDINATE x, // Horizontal position for the shape.
- PORDINATE y // Vertical position for the shape.
- );
- void SetPosition(
- const PPoint & pt // Position for the shape.
- );
- /* Set the position of the shape. This changes the internal position only,
- it is up to the application to redraw the canvas to reflect the change.
- The user should not override this function. If some form of action is
- required on changing the shapes position then the
- ref{_SetPosition()} function should be overridden.
- */
- PPoint GetPosition() const;
- /* Get the current position of the shape.
- @return
- point for position of shape.
- */
- void Offset(
- PORDINATE dx, // Amount to move the shape horizontally.
- PORDINATE dy // Amount to move the shape vertically.
- );
- void Offset(
- const PPoint & pt // Amount to move the shape.
- );
- /* Move the position of the shape by the offset specified. This will use
- the ref{GetPosition()} and ref{SetPosition()} functions.
- */
- void SetDimensions(
- PDIMENSION width, // New width for shape.
- PDIMENSION height // New height for shape.
- );
- void SetDimensions(
- const PDim & dim // New dimensions for shape.
- );
- /* Set the dimensions of the shape. The exact semantics of this function
- is dependent on the descendent class. Not all shapes can change their
- dimensions, being defined by other factors, eg a text lines width and
- height is defined by the text and font size used.
- The user should not override this function. If some form of action is
- required on changing the shapes position then the
- ref{_SetPosition()} function should be overridden.
- */
- virtual PDim GetDimensions() const = 0;
- /* Get the dimensions of the shape. This is defined by the descendent
- class as the definition of the dimensions is specific to the type of
- shape, eg a text lines width and height is defined by the text and font
- size used.
- @return
- dimensions of the shape.
- */
- void Grow(
- PORDINATE dx, // Amount to grow/shrink the shape horizontally.
- PORDINATE dy // Amount to grow/shrink the shape vertically.
- );
- void Grow(
- const PPoint & pt // Amount to grow/shrink the shape.
- );
- /* Increase the size of the shape by the amount specified. If the values
- are negative then the dimensions are decreased. This uses the
- ref{GetDimensions()} and ref{SetDimensions()} functions.
-
- Note this will not have an effect on all shapes.
- */
- PRect GetBounds() const;
- /* Get the smallest rectangle that completely encloses the shape. This
- uses the ref{GetPosition()} and ref{GetDimensions()} functions.
- */
- virtual BOOL InShape(
- const PPoint & pt // Point to determine if inside shape.
- ) const;
- /* Determine if the point is within the content of the shape.
-
- Note that the contents of a shape is usually the bounding box but not
- always. For example a ref{PLine} might encompass a very large bounding
- box but the line only occupies a thin slice of it. This function would
- then be altered to detect a point near the line.
- @return
- TRUE if point is "inside" the shape.
- */
- virtual BOOL IsComposite() const;
- /* Determine if the shape is a composite shape, ie is made up of a
- collection of other shapes.
- @return
- TRUE if the shape is composite.
- */
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const = 0;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- protected:
- // New functions for class
- virtual void _SetPosition(
- const PPoint & pt // Position for the shape.
- );
- /* Set the position of the shape. This changes the internal position only,
- it is up to the application to redraw the canvas to reflect the change.
- The user should override this function instead of the
- ref{SetPosition()} functions.
- */
- virtual void _SetDimensions(
- const PDim & dim // New dimensions for shape.
- );
- /* Set the dimensions of the shape. The exact semantics of this function
- is dependent on the descendent class. Not all shapes can change their
- dimensions, being defined by other factors, eg a text lines width is
- defined by the text and font size.
- The user should override this function instead of the
- ref{SetDimensions()} functions.
- */
- // Member variables
- PPoint position;
- // Location of the shape on the canvas.
- };
- /**A class representing a simple straight line graphic shape.
- */
- class PLine : public PShape
- {
- PCLASSINFO(PLine, PShape);
- public:
- PLine(
- PORDINATE x1, // Horizontal position of start of line.
- PORDINATE y1, // Vertical position of start of line.
- PORDINATE x2, // Horizontal position of end of line.
- PORDINATE y2 // Vertical position of end of line.
- );
- PLine(
- const PPoint & pt1, // Position of start of line.
- const PPoint & pt2 // Position of end of line.
- );
- // Construct a new line shape.
- // Overrides from class PObject
- virtual Comparison Compare(
- const PObject & obj // Line shape object to compare against.
- ) const;
- /* Compare the two graphic shape objects to determine if they are the same
- shape.
- @return
- #EqualTo# if the two shapes match is form and position,
- #LessThan# if the form is the same but their positions are
- different and #GreaterThan# if the form and position are
- both different.
- */
- // Overrides from class PShape
- virtual PDim GetDimensions() const;
- /* Get the dimensions of the shape. This returns the horizontal and
- vertical lengths of the line.
- @return
- dimensions of the shape.
- */
- virtual BOOL InShape(
- const PPoint & pt // Point to determine if inside shape.
- ) const;
- /* Determine if the point is within the content of the shape.
-
- This overrides the usual behaviour as a line might encompass a very
- large bounding box but the line only occupies a thin slice of it. This
- function is altered to detect a point near the line.
- @return
- TRUE if point is "inside" the shape.
- */
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- protected:
- // Member variables
- PPoint otherEnd;
- // Location of the other end of the line.
- };
- /**A class representing a graphic shape that is orthogonal, ie specified by a
- rectangle.
- */
- class POrthoShape : public PShape
- {
- PCLASSINFO(POrthoShape, PShape);
- public:
- POrthoShape(
- PORDINATE x, // Horizontal position of the orthogonal shape.
- PORDINATE y, // Vertical position of the orthogonal shape.
- PDIMENSION dx, // Width of the orthogonal shape.
- PDIMENSION dy // Height of the orthogonal shape.
- );
- POrthoShape(
- const PPoint & p1, // First corner of orthogonal shape.
- const PPoint & p2 // Second, opposite, corner of orthogonal shape.
- );
- POrthoShape(
- const PPoint & topLeft, // Top left corner ofthe orthogonal shape.
- const PDim & dim // Dimensions of the orthogonal shape.
- );
- POrthoShape(
- const PRect & rect // Rectangle for the orthogonal shape.
- );
- // Create a new orthoganal shape.
- // Overrides from class PObject
- Comparison Compare(
- const PObject & obj // Orthogonal shape object to compare against.
- ) const;
- /* Compare the two graphic shape objects to determine if they are the same
- shape.
- @return
- #EqualTo# if the two shapes match is form and position,
- #LessThan# if the form is the same but their positions are
- different and #GreaterThan# if the form and position are
- both different.
- */
- // Overrides from class PShape
- virtual PDim GetDimensions() const;
- /* Get the dimensions of the shape. This returns the horizontal and
- vertical lengths of the line.
- @return
- dimensions of the shape.
- */
- protected:
- // Overrides from class PShape
- virtual void _SetDimensions(
- const PDim & dim // New dimensions for shape.
- );
- /* Set the dimensions of the shape. This sets the dimensions of the
- rectangle that defines an othogonal shape.
- The user should override this function instead of the
- ref{SetDimensions()} functions.
- */
- // Member variables
- PDim dimensions;
- // Size of the rectangular shape.
- };
- /**A class representing a simple rectangle graphic shape.
- */
- class PRectangle : public POrthoShape
- {
- PCLASSINFO(PRectangle, POrthoShape);
- public:
- PRectangle(
- PORDINATE x, // Horizontal position of the orthogonal shape.
- PORDINATE y, // Vertical position of the orthogonal shape.
- PDIMENSION dx, // Width of the orthogonal shape.
- PDIMENSION dy // Height of the orthogonal shape.
- );
- PRectangle(
- const PPoint & p1, // First corner of orthogonal shape.
- const PPoint & p2 // Second, opposite, corner of orthogonal shape.
- );
- PRectangle(
- const PPoint & topLeft, // Top left corner ofthe orthogonal shape.
- const PDim & dim // Dimensions of the orthogonal shape.
- );
- PRectangle(
- const PRect & rect // Rectangle for the orthogonal shape.
- );
- // Create a new rectangle shape.
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- };
- /**A class representing a rectangle graphic shape with rounded corners.
- */
- class PRoundedRectangle : public PRectangle
- {
- PCLASSINFO(PRoundedRectangle, PRectangle);
- public:
- PRoundedRectangle(
- PORDINATE x, // Horizontal position of the orthogonal shape.
- PORDINATE y, // Vertical position of the orthogonal shape.
- PDIMENSION dx, // Width of the orthogonal shape.
- PDIMENSION dy, // Height of the orthogonal shape.
- PDIMENSION cornerWidth, // Horizontal width of rounded corner.
- PDIMENSION cornerHeight // Vertical height of rounded corner.
- );
- PRoundedRectangle(
- const PPoint & p1, // First corner of orthogonal shape.
- const PPoint & p2, // Second, opposite, corner of orthogonal shape.
- PDIMENSION cornerWidth, // Horizontal width of rounded corner.
- PDIMENSION cornerHeight // Vertical height of rounded corner.
- );
- PRoundedRectangle(
- const PPoint & topLeft, // Top left corner ofthe orthogonal shape.
- const PDim & dim, // Dimensions of the orthogonal shape.
- PDIMENSION cornerWidth, // Horizontal width of rounded corner.
- PDIMENSION cornerHeight // Vertical height of rounded corner.
- );
- PRoundedRectangle(
- const PRect & rect, // Rectangle for the orthogonal shape.
- PDIMENSION cornerWidth, // Horizontal width of rounded corner.
- PDIMENSION cornerHeight // Vertical height of rounded corner.
- );
- // Create a new rounded rectangle shape.
- // Overrides from class PObject
- Comparison Compare(
- const PObject & obj // Rounded rectangle object to compare against.
- ) const;
- /* Compare the two graphic shape objects to determine if they are the same
- shape.
- @return
- #EqualTo# if the two shapes match is form and position,
- #LessThan# if the form is the same but their positions are
- different and #GreaterThan# if the form and position are
- both different.
- */
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- // New functions for class
- void SetCornerWidth(
- PDIMENSION width // New width for rounded corner.
- );
- // Set the width of the rounded corner.
-
- PDIMENSION GetCornerWidth();
- /* Get the width of the rounded corner.
- @return
- width of rounded corner.
- */
-
- void SetCornerHeight(
- PDIMENSION height // Height of rounded corner.
- );
- // Set the width of the rounded corner.
-
- PDIMENSION GetCornerHeight();
- /* Get the width of the rounded corner.
- @return
- height of rounded corner.
- */
- protected:
- // Member variables
- PDim corner;
- // Size of the rounded corners.
- };
- /**A class representing an ellipse graphic shape.
- Note that the semi-major axes of the ellipse must be horizontal and
- vertical.
- */
- class PEllipse : public POrthoShape
- {
- PCLASSINFO(PEllipse, POrthoShape);
- public:
- PEllipse(
- PORDINATE x, // Horizontal position of the orthogonal shape.
- PORDINATE y, // Vertical position of the orthogonal shape.
- PDIMENSION dx, // Width of the orthogonal shape.
- PDIMENSION dy // Height of the orthogonal shape.
- );
- PEllipse(
- const PPoint & p1, // First corner of orthogonal shape.
- const PPoint & p2 // Second, opposite, corner of orthogonal shape.
- );
- PEllipse(
- const PPoint & topLeft, // Top left corner ofthe orthogonal shape.
- const PDim & dim // Dimensions of the orthogonal shape.
- );
- PEllipse(
- const PRect & rect // Rectangle for the orthogonal shape.
- );
- // Create a new ellipse shape.
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- };
- /**A class representing a part of ellipse graphic shape. An arc is an
- unfilled object so only a line segment is drawn.
-
- The arc is always part of an ellipse that would fit in the rectangle. The
- start and end indicate how much of the arc is drawn. Thus drawing from 0 to
- 360 degrees would result in a complete ellipse.
- Note that the semi-major axes of the ellipse must be horizontal and
- vertical.
- */
- class PArc : public POrthoShape
- {
- PCLASSINFO(PArc, POrthoShape);
- public:
- PArc(
- PORDINATE x, // Horizontal position of the orthogonal shape.
- PORDINATE y, // Vertical position of the orthogonal shape.
- PDIMENSION dx, // Width of the orthogonal shape.
- PDIMENSION dy, // Height of the orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- PArc(
- const PPoint & p1, // First corner of orthogonal shape.
- const PPoint & p2, // Second, opposite, corner of orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- PArc(
- const PPoint & topLeft, // Top left corner ofthe orthogonal shape.
- const PDim & dim, // Dimensions of the orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- PArc(
- const PRect & rect, // Rectangle for the orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- // Create a new arc shape.
- // Overrides from class PObject
- Comparison Compare(
- const PObject & obj // Arc shape object to compare against.
- ) const;
- /* Compare the two graphic shape objects to determine if they are the same
- shape.
- @return
- #EqualTo# if the two shapes match is form and position,
- #LessThan# if the form is the same but their positions are
- different and #GreaterThan# if the form and position are
- both different.
- */
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- // New functions for class
- void SetStartAngle(
- PORDINATE start // New starting angle, in degrees.
- );
- // Set the starting angle of the partial ellipse.
- PORDINATE GetStartAngle();
- /* Get the starting angle of the partial ellipse.
- @return
- starting angle, in degrees.
- */
- void SetEndAngle(
- PORDINATE finish // New finishing angle, in degrees.
- );
- // Set the finishing angle of the partial ellipse.
-
- PORDINATE GetEndAngle();
- /* Get the finishing angle of the partial ellipse.
- @return
- finishing angle, in degrees.
- */
-
- protected:
- // Member variables
- PORDINATE startAngle;
- // Starting angle of the partial ellipse, in degrees.
- PORDINATE endAngle;
- // Finishing angle of the partial ellipse, in degrees.
- };
- /**A class representing a pie segment graphic shape. A pie is an arc with two
- lines connecting the ends of the arc to the centre of the ellipse the arc
- is part of.
- The arc is always part of an ellipse that would fit in the rectangle. The
- start and end indicate how much of the arc is drawn. Thus drawing from 0 to
- 360 degrees would result in a complete ellipse.
- Note that the semi-major axes of the ellipse must be horizontal and
- vertical.
- */
- class PPie : public PArc
- {
- PCLASSINFO(PPie, PArc);
- public:
- PPie(
- PORDINATE x, // Horizontal position of the orthogonal shape.
- PORDINATE y, // Vertical position of the orthogonal shape.
- PDIMENSION dx, // Width of the orthogonal shape.
- PDIMENSION dy, // Height of the orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- PPie(
- const PPoint & p1, // First corner of orthogonal shape.
- const PPoint & p2, // Second, opposite, corner of orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- PPie(
- const PPoint & topLeft, // Top left corner ofthe orthogonal shape.
- const PDim & dim, // Dimensions of the orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- PPie(
- const PRect & rect, // Rectangle for the orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- // Create a new pie shape
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- };
- /**A class representing a chord segment graphic shape. A chord is an arc with
- a single line connecting the ends of the arc across the chord of the
- ellipse.
- The arc is always part of an ellipse that would fit in the rectangle. The
- start and end indicate how much of the arc is drawn. Thus drawing from 0 to
- 360 degrees would result in a complete ellipse.
- Note that the semi-major axes of the ellipse must be horizontal and
- vertical.
- */
- class PChord : public PArc
- {
- PCLASSINFO(PChord, PArc);
- public:
- PChord(
- PORDINATE x, // Horizontal position of the orthogonal shape.
- PORDINATE y, // Vertical position of the orthogonal shape.
- PDIMENSION dx, // Width of the orthogonal shape.
- PDIMENSION dy, // Height of the orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- PChord(
- const PPoint & p1, // First corner of orthogonal shape.
- const PPoint & p2, // Second, opposite, corner of orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- PChord(
- const PPoint & topLeft, // Top left corner ofthe orthogonal shape.
- const PDim & dim, // Dimensions of the orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- PChord(
- const PRect & rect, // Rectangle for the orthogonal shape.
- PORDINATE startAngle, // Starting angle, in degrees, for arc.
- PORDINATE endAngle // Ending angle, in degrees, for arc.
- );
- // Create a new chord shape
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- };
- /**A class representing a pixel image graphic shape.
- */
- class PPixShape : public POrthoShape
- {
- PCLASSINFO(PPixShape, POrthoShape);
- public:
- PPixShape(
- PORDINATE x, // Horizontal position for the shape.
- PORDINATE y, // Vertical position for the shape.
- const PPixelImage & pix // Pixel image to contain in the shape
- );
- PPixShape(
- const PPoint & pt, // Position for the shape.
- const PPixelImage & pix // Pixel image to contain in the shape
- );
- // Create a new pixel image graphic shape.
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- // New functions for class
- void SetPixels(
- const PPixelImage & img // New pixel image for shape.
- );
- // Set the image for the shape.
- PPixelImage GetPixels() const;
- /* Get the pixel image for the shape.
- @return
- current pixel image for shape.
- */
- protected:
- // Member variables
- PPixelImage pixels;
- // Pixel image in the shape.
- };
- /**A class representing a picture image graphic shape.
- */
- class PPicShape : public POrthoShape
- {
- PCLASSINFO(PPicShape, POrthoShape);
- public:
- PPicShape(
- PORDINATE x, // Horizontal position for the shape.
- PORDINATE y, // Vertical position for the shape.
- const PPictImage & pic // Picture image to contain in the shape.
- );
- PPicShape(
- const PPoint & pt, // Position for the shape.
- const PPictImage & pic // Picture image to contain in the shape.
- );
- // Create a new picture image graphic shape.
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- // New functions for class
- void SetPicture(
- const PPictImage & img // New picture image for shape.
- );
- // Set the image for the shape.
- PPictImage GetPicture() const;
- /* Get the picture image for the shape.
- @return
- current picture image for shape.
- */
- protected:
- // Member variables
- PPictImage picture;
- // Picture image in the shape.
- };
- /**A class representing a lines of text graphic shape. The dimensions for this
- shape is determined by the font used and the text it contains. Multiple
- lines are permitted but no word wrapping or ellipses will be performed.
- */
- class PTextLines : public PShape
- {
- PCLASSINFO(PTextLines, PShape);
- public:
- PTextLines(
- PORDINATE x, // Horizontal position for the shape.
- PORDINATE y, // Vertical position for the shape.
- const PString & text // Text for the shape.
- );
- PTextLines(
- const PPoint & pt, // Position for the shape.
- const PString & text // Text for the shape.
- );
- // Create a new text lines shape.
- // Overrides from class PObject
- Comparison Compare(
- const PObject & obj // Text line shape object to compare against.
- ) const;
- /* Compare the two graphic shape objects to determine if they are the same
- shape.
- @return
- #EqualTo# if the two shapes match is form and position,
- #LessThan# if the form is the same but their positions are
- different and #GreaterThan# if the form and position are
- both different.
- */
- // Overrides from class PShape
- virtual PDim GetDimensions() const;
- /* Get the dimensions of the shape. This returns the horizontal and
- vertical dimensions of the line of text. This must be calculated for a
- canvas by either a ref{Draw()} or ref{GetDimensions(PCanvas)}
- function call.
- @return
- dimensions of the shape.
- */
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- // New functions for class
- void SetText(
- const PString & text // New text for shape.
- );
- // Set the text for the text shape.
- PString GetText() const;
- /* Get the text for the text shape.
- @return
- text in shape.
- */
- virtual PDim GetDimensions(
- PCanvas & canvas // Canvas to calculate the dimensions for.
- );
- /* Get the dimensions of the shape, calculating for the specified canvas.
- The dimensions are saved and will be henceforth returned by the
- parameterless version of the ref{GetDimensions()} function.
- @return
- dimensions of the text.
- */
-
- protected:
- // Member variables
- PString text;
- // Text lines for the shape.
- PDim dimensions;
- // Last dimension calculated for the text lines.
- };
- /**A class representing a lines of text graphic shape. Unlike the ancestor
- class, the width of a text block is fixed and the text is word wrapped to
- fit within that bounds. Extra lines may be added to fit. The vertical
- dimension cannot be set as it is determined by the font and text selected.
- */
- class PTextBlock : public PTextLines
- {
- PCLASSINFO(PTextBlock, PTextLines);
- public:
- PTextBlock(
- PORDINATE x, // Horizontal position for the shape.
- PORDINATE y, // Vertical position for the shape.
- const PString & text, // Text for the shape.
- PDIMENSION width // Width of the text block.
- );
- PTextBlock(
- const PPoint & pt, // Position for the shape.
- const PString & text, // Text for the shape.
- PDIMENSION width // Width of the text block.
- );
- // Create a new text block shape.
- // Overrides from class PObject
- Comparison Compare(
- const PObject & obj // Text block shape object to compare against.
- ) const;
- /* Compare the two graphic shape objects to determine if they are the same
- shape.
- @return
- #EqualTo# if the two shapes match is form and position,
- #LessThan# if the form is the same but their positions are
- different and #GreaterThan# if the form and position are
- both different.
- */
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- // Overrides from class PTextLines
- virtual PDim GetDimensions() const { return PTextLines::GetDimensions(); }
- /* Get the dimensions of the shape. This returns the horizontal and
- vertical dimensions of the line of text. This must be calculated for a
- canvas by either a ref{Draw()} or ref{GetDimensions(PCanvas&)}
- function call.
- @return
- dimensions of the shape.
- */
- virtual PDim GetDimensions(
- PCanvas & canvas // Canvas to calculate the dimensions for.
- );
- /* Get the dimensions of the shape, calculating for the specified canvas.
- The dimensions are saved and will be henceforth returned by the
- parameterless version of the ref{GetDimensions()} function.
- @return
- dimensions of the text.
- */
- protected:
- void _SetDimensions(
- const PDim & dim // New dimensions for shape.
- );
- /* Set the dimensions of the shape. For a text block the vertical
- dimension is ignored as it is defined by the text in the block.
- */
- };
- /**A class representing a graphic drawing shape with variable number of
- point components, eg polylines and polygons.
- */
- class PPolyShape : public PShape
- {
- PCLASSINFO(PPolyShape, PShape);
- public:
- PPolyShape(
- PORDINATE x, // Horizontal position for the first point in the shape.
- PORDINATE y // Vertical position for the first point in the shape.
- );
- PPolyShape(
- const PPoint & pt // Position for the first point in the shape.
- );
- PPolyShape(
- const PPointArray & pts // Array of points for the shape.
- );
- PPolyShape(
- const PPoint * ptArray, // Pointer to an array of points for shape.
- PINDEX numPts // Number of points #ptArray# points at.
- );
- // Create a new "poly" graphic shape.
- // Overrides from class PShape
- virtual PDim GetDimensions() const;
- /* Get the dimensions of the shape. This returns the horizontal and
- vertical dimensions of the bounding box for the polyline, polygon etc.
- @return
- dimensions of the shape.
- */
- // New functions for class
- void AddPoint(
- PORDINATE x, // Horizontal position for the point to add.
- PORDINATE y // Vertical position for the point to add.
- );
- void AddPoint(
- const PPoint & pt // Position for the point to add.
- );
- // Add a new point to the "poly" shape.
- void RemovePoint(
- PINDEX idx // Index position of the point to remove from the shape.
- );
- // Remove a point from the "poly" shape.
- PPoint & operator[](
- PINDEX idx // Index position of the point to get from the shape.
- ) const;
- /* Get the point from the "poly" shape at the specified index position.
- @return
- point at index in the shape.
- */
- protected:
- // Overrides from class PShape
- virtual void _SetPosition(
- const PPoint & pt // New position for the "poly" shape.
- );
- /* Set the position of the shape. This will move every point in the
- "poly" shape by the same amount so the shape does not change only its
- position.
- */
- // Member variables
- PPointArray points;
- // Location of the points defining the poly shape on the canvas.
- };
- /**A class representing a graphic drawing shape with variable number of
- line segments. This is an unfilled object, so only the line segments are
- drawn.
- */
- class PPolyLine : public PPolyShape
- {
- PCLASSINFO(PPolyLine, PPolyShape);
- public:
- PPolyLine(
- PORDINATE x, // Horizontal position for the first point in the shape.
- PORDINATE y // Vertical position for the first point in the shape.
- );
- PPolyLine(
- const PPoint & pt // Position for the first point in the shape.
- );
- PPolyLine(
- const PPointArray & pts // Array of points for the shape.
- );
- PPolyLine(
- const PPoint * ptArray, // Pointer to an array of points for shape.
- PINDEX numPts // Number of points #ptArray# points at.
- );
- // Create a new polyline graphic shape.
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- };
- /**A class representing a graphic drawing shape with variable number of
- sides. This is an filled object, so there is an implicit line connecting
- the last point back to the first.
- */
- class PPolygon : public PPolyShape
- {
- PCLASSINFO(PPolygon, PPolyShape);
- public:
- PPolygon(
- PORDINATE x, // Horizontal position for the first point in the shape.
- PORDINATE y // Vertical position for the first point in the shape.
- );
- PPolygon(
- const PPoint & pt // Position for the first point in the shape.
- );
- PPolygon(
- const PPointArray & pts // Array of points for the shape.
- );
- PPolygon(
- const PPoint * ptArray, // Pointer to an array of points for shape.
- PINDEX numPts // Number of points #ptArray# points at.
- );
- // Create a new polygon graphic shape
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- };
- /**A class representing a graphic drawing shape which constitutes a variable
- mathematical curve given a sequence of "control" points. This is an
- abstract class with different formulae being appliend by the descendent
- clases eg ref{PBezier}.
- */
- class PCurve : public PPolyShape
- {
- PCLASSINFO(PCurve, PPolyShape);
- public:
- PCurve(
- PORDINATE x, // Horizontal position for the first point in the shape.
- PORDINATE y // Vertical position for the first point in the shape.
- );
- PCurve(
- const PPoint & pt // Position for the first point in the shape.
- );
- PCurve(
- const PPointArray & pts // Array of points for the shape.
- );
- PCurve(
- const PPoint * ptArray, // Pointer to an array of points for shape.
- PINDEX numPts // Number of points #ptArray# points at.
- );
- // Create a new curve graphic shape.
- };
- /**A class representing a graphic drawing shape which constitutes a variable
- mathematical curve given a sequence of "control" points. This implements
- a Bezier curve.
- */
- class PBezier : public PCurve
- {
- PCLASSINFO(PBezier, PCurve);
- public:
- PBezier(
- PORDINATE x, // Horizontal position for the first point in the shape.
- PORDINATE y // Vertical position for the first point in the shape.
- );
- PBezier(
- const PPoint & pt // Position for the first point in the shape.
- );
- PBezier(
- const PPointArray & pts // Array of points for the shape.
- );
- PBezier(
- const PPoint * ptArray, // Pointer to an array of points for shape.
- PINDEX numPts // Number of points #ptArray# points at.
- );
- // Create a new Bezier curve graphic shape.
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- };
- /**A class representing a graphic drawing shape which constitutes a variable
- mathematical curve given a sequence of "control" points. This implements
- a B-Spline curve.
- */
- class PBSpline : public PCurve
- {
- PCLASSINFO(PBSpline, PCurve);
- public:
- PBSpline(
- PORDINATE x, // Horizontal position for the first point in the shape.
- PORDINATE y // Vertical position for the first point in the shape.
- );
- PBSpline(
- const PPoint & pt // Position for the first point in the shape.
- );
- PBSpline(
- const PPointArray & pts // Array of points for the shape.
- );
- PBSpline(
- const PPoint * ptArray, // Pointer to an array of points for shape.
- PINDEX numPts // Number of points #ptArray# points at.
- );
- // Create a new B-Spline curve graphic shape.
- // Overrides from class PShape
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- };
- PLIST(PShapeList, PShape);
- /**A class representing a graphic drawing shape that is made from a collection
- of other shapes. Note that this can be recursive, ie a composite shape may
- contain other composite shapes.
- */
- class PCompositeShape : public PShape
- {
- PCLASSINFO(PCompositeShape, PShape);
- public:
- PCompositeShape();
- PCompositeShape(
- PShape & shape // First shape in composite.
- );
- // Create a new composite graphic shape.
- // Override from class PShape
- virtual PDim GetDimensions() const;
- /* Get the dimensions of the shape. This returns the dimensions of the
- bounding box for all the shapes contained in the composite shape.
- @return
- dimensions of the shape.
- */
- virtual BOOL IsComposite() const;
- /* Determine if the shape is a composite shape.
- @return
- TRUE always.
- */
- virtual void Draw(
- PCanvas & canvas // Canvas to draw the shape on.
- ) const;
- /* Draw the shape on the supplied canvas. The canvas state is altered to
- state embodied by the shape ancestor. The canvas state is {bf not}
- restored afterward.
- */
- // New functions for class
- void Add(
- PShape & shape // Shape to add to the composite shape.
- );
- // Add a shape to the composite shape.
- void Remove(
- PShape & shape // Shape to remove from the composite shape.
- );
- void Remove(
- PINDEX idx // Index position of shape to remove from the composite shape.
- );
- // Remove the shape from the composite shape.
- PShape & operator[](
- PINDEX idx
- );
- /* Get the shape at the specified index.
- @return
- reference to shape at index position.
- */
- PShape * Find(
- const PPoint & pt // Point to search for shape with.
- );
- /* Find a shape in the composite shape at the location. This will return
- a shape within this particular composite shape, so a composite shape
- may be returned.
- @return
- pointer to shape that the point is within, or NULL if there was no such
- shape.
- */
- PShape * FindPrimitive(
- const PPoint & pt // Point to search for shape with.
- );
- /* Find a non-composite shape in the composite shape at the location. This
- will recursively descend into nested shapes intil a primitive shape is
- detected as being around the point.
- @return
- pointer to shape that the point is within, or NULL if there was no such
- shape.
- */
- protected:
- // Override from class PShape
- virtual void _SetPosition(
- const PPoint & pt // Position for the shape.
- );
- /* Set the position of the shape. This will move every shape contained
- within the composite shape so that their relative positions do not
- change but the position of the whole does.
- */
- // New functions for class
- void CalculateBounds();
- // Recalculate the position and dimensions of the composite shape.
- // Member variables
- PShapeList shapes;
- // List of shapes that make up the composite shape.
- PDim dimensions;
- // Bounding size of all the shapes in the composite shape.
- };
- #if P_USE_INLINES
- #include <pwclib/shapes.inl>
- #endif
- #endif