canstate.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:21k
- /*
- * canstate.h
- *
- * Canvas state class.
- *
- * 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: canstate.h,v $
- * Revision 1.15 1999/03/10 03:49:50 robertj
- * More documentation adjustments.
- *
- * Revision 1.14 1999/03/09 08:01:47 robertj
- * Changed comments for doc++ support (more to come).
- *
- * Revision 1.13 1998/09/23 06:22:53 robertj
- * Added open source copyright license.
- *
- * Revision 1.12 1997/07/08 13:02:04 robertj
- * DLL support.
- *
- * Revision 1.11 1996/08/17 10:00:28 robertj
- * Changes for Windows DLL support.
- *
- * Revision 1.10 1995/10/14 14:52:55 robertj
- * Changed return values to references for efficency.
- *
- * Revision 1.9 1995/03/14 12:41:00 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.8 1995/01/27 11:00:44 robertj
- * Added pattern origin.
- *
- * Revision 1.7 1995/01/21 05:12:47 robertj
- * Documentation.
- * Added origin changing function, simpler than setting rectangles.
- *
- * Revision 1.6 1994/11/24 11:48:28 robertj
- * Documentation.
- *
- * Revision 1.5 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.4 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.3 1994/03/07 07:38:19 robertj
- * Major enhancementsacross the board.
- *
- * Revision 1.2 1993/12/09 16:11:23 robertj
- * Removed canvas state "owner" canvas.
- *
- * Revision 1.1 1993/10/16 20:33:20 robertj
- * Initial revision
- *
- */
- #define _PCANVASSTATE
- #ifdef __GNUC__
- #pragma interface
- #endif
- class PCanvas;
- /**A class representing the state of a PCanvas. The state of a canvas is the
- current font, colours, line & fill modes etc that describes the way in which
- drawing operations are performed. Note that this class is not descended
- from the standard PObject class as multiple inheritance is used and common
- ancestors should be avoided at all costs.
- */
- class PCanvasState {
- public:
- /**Create a new canvas state with default values. These values are:
- begin{description}
- item[penStyle] Solid
- item[penWidth] 0 Hairline
- item[penMode] SrcCopy
- item[penFgColour] Black
- item[penBkColour] White
- item[fillFgColour] Clear
- item[fillBkColour] Clear
- item[fillPattern] Solid
- item[fillMode] SrcCopy
- item[font] System, 10 point
- item[textFgColour] Black
- item[textBkColour] White
- item[palette] Empty palette
- item[polyFillMode] Winding
- item[viewport] (0, 0, 100, 100) Scaling to pixels, no offset
- item[map] (0, 0, 100, 100)
- end{description}
- */
- PCanvasState();
- /** Create a copy of the canvas state. */
- PCanvasState(
- const PCanvasState & s /// Source canvas state
- );
- /**@name New functions for class */
- /**This enum describes the types of styles that the pen uses. The pen is
- used to draw lines as well as border about other shapes eg rectangles,
- ellipses etc.
- */
- enum PenStyles {
- /// Drawn with all pixels connected
- Solid,
- /// Drawn with short line segments with equal sized gaps
- Dotted,
- /// Drawn with long line segments with short gaps
- Dashed,
- /// Drawn with alternating dots and dashes
- DotDashed
- };
- /**Set the pen style to be used by future drawing operations. The pen is
- used to draw lines as well as border about other shapes eg rectangles,
- ellipses etc.
- @return
- TRUE if the pen style was changed, FALSE if the new pen style was
- identical to the current setting.
- */
- virtual BOOL SetPenStyle(
- PenStyles style /// New pen style to set in the canvas state
- );
- /**Get the pen style to be used by future drawing operations. The pen is
- used to draw lines as well as border about other shapes eg rectangles,
- ellipses etc.
- @return
- the current pen style used in the canvas state.
- */
- PenStyles GetPenStyle() const;
- /**Set the pen width to be used by future drawing operations. The pen is
- used to draw lines as well as border about other shapes eg rectangles,
- ellipses etc.
- @return
- TRUE if the pen width was changed, FALSE if the new pen width was
- identical to the current setting.
- */
- virtual BOOL SetPenWidth(
- int width
- /**Width of lines drawn by the pen in the current coordinate system used
- by the canvas state. A value of 0 indicates "hairline" or, by
- definition, one pixel wide regardless of the current coordinate
- transform.
- */
- );
- /**Get the pen width to be used by future drawing operations. The pen is
- used to draw lines as well as border about other shapes eg rectangles,
- ellipses etc.
- @return
- the current pen width used in the canvas state.
- */
- int GetPenWidth() const;
- /**This enum describes the set of transfer modes for pixels as they are
- drawn. As a drawing operation is performed (pen or fill) pixels are
- placed on the canvas as a combination of the drawing colour eg pen
- foreground colour, and the current colour of the canvas pixel. Many of
- these modes may have odd behaviour on colour canvases and are really
- only useful if the combination is made between black and white (1 bit)
- pixels.
- If the logical modes, eg SrcAndDst, are used on a colour canvas then
- the boolean states for source and destination are derived by comparing
- the colour to the current drawing foreground colour.
- */
- enum DrawingModes {
- /**Pixels are drawn in the requested colour
- */
- SrcCopy,
- /**Pixels are drawn in the inverse of the colour
- */
- SrcInvert,
- /**The result is the AND of the requested colour and the current colour
- of the canvas pixel.
- */
- SrcAndDst,
- /**The result is the AND of the inverse of the requested colour and the
- current colour of the canvas pixel.
- */
- NotSrcAndDst,
- /**The result is the AND of the requested colour and the inverse of the
- current colour of the canvas pixel.
- */
- SrcAndNotDst,
- /**The result is the inverse of the AND of the requested colour and the
- current colour of the canvas pixel.
- */
- InvertSrcAndDst,
- /**The result is the OR of the requested colour and the current colour
- of the canvas pixel.
- */
- SrcOrDst,
- /**The result is the OR of the inverse of the requested colour and the
- current colour of the canvas pixel.
- */
- NotSrcOrDst,
- /**The result is the OR of the requested colour and the inverse of the
- current colour of the canvas pixel.
- */
- SrcOrNotDst,
- /**The result is the inverse of the OR of the requested colour and the
- current colour of the canvas pixel.
- */
- InvertSrcOrDst,
- /**The result is the eXclusive OR of the requested colour and the
- current colour of the canvas pixel.
- */
- SrcXorDst,
- /**The result is the inverse of the eXclusive OR of the requested colour
- and the current colour of the canvas pixel.
- */
- InvertSrcXorDst,
- /**Pixels on the canvas are inverted.
- */
- InvertDst,
- /**No change is made to the canvas pixels.
- */
- CopyDst
- };
- /**Set the pen mode to be used by future drawing operations. The pen is
- used to draw lines as well as border about other shapes eg rectangles,
- ellipses etc.
- @return
- TRUE if the pen mode was changed, FALSE if the new pen mode was
- identical to the current setting.
- */
- virtual BOOL SetPenMode(
- DrawingModes mode /// New mode to be used for pen drawing operations.
- );
- /**Get the pen mode to be used by future drawing operations. The pen is
- used to draw lines as well as border about other shapes eg rectangles,
- ellipses etc.
- @return
- the current pen mode used in the canvas state.
- */
- DrawingModes GetPenMode() const;
- /**Set the pen foreground colour to be used by future drawing operations.
- The pen is used to draw lines as well as border about other shapes eg
- rectangles, ellipses etc.
- @return
- TRUE if the pen foreground colour was changed, FALSE if the new pen
- foreground colour was identical to the current setting.
- */
- virtual BOOL SetPenFgColour(
- const PColour & colour /// New colour for the pen foreground
- );
- /**Get the pen foreground colour to be used by future drawing operations.
- The pen is used to draw lines as well as border about other shapes eg
- rectangles, ellipses etc.
- @return
- the current pen foreground colour used in the canvas state.
- */
- const PColour & GetPenFgColour() const;
- /**Set the pen background colour to be used by future drawing operations.
- The pen background colour is used to draw the gaps in the drawn line
- when pen styles Dotted, Dashed or DotDashed are used.
- The pen is used to draw lines as well as border about other shapes eg
- rectangles, ellipses etc.
- @return
- TRUE if the pen background colour was changed, FALSE if the new pen
- background colour was identical to the current setting.
- */
- virtual BOOL SetPenBkColour(
- const PColour & colour /// New colour for the pen background
- );
- /**Get the pen background colour to be used by future drawing operations.
- The pen background colour is used to draw the gaps in the drawn line
- when pen styles Dotted, Dashed or DotDashed are used. The pen is used
- to draw lines as well as border about other shapes eg rectangles,
- ellipses etc.
- @return
- the current pen background colour used in the canvas state.
- */
- const PColour & GetPenBkColour() const;
- /**Set the fill pattern to be used by future drawing operations. The fill
- pattern is a (usually) small bitmap which is tiled into the interior of
- solid shapes eg rectangles, ellipses etc.
- @return
- TRUE if the fill pattern was changed, FALSE if the new fill pattern was
- identical to the current setting.
- */
- virtual BOOL SetFillPattern(
- const PPattern & pattern /// New pattern to be used for drawing fills
- );
- /**Get the fill pattern to be used by future drawing operations. The fill
- pattern is a (usually) small bitmap which is tiled into the interior of
- solid shapes eg rectangles, ellipses etc.
- @return
- the current fill pattern used in the canvas state.
- */
- PPattern GetFillPattern() const;
- /**Set the origin for the pattern. This sets the offset from 0 to 7 for
- origin for a pattern.
- */
- virtual BOOL SetPatternOrigin(
- const PPoint & pt /// New origin for pattern.
- );
- /**Get the origin for the pattern. This sets the offset from 0 to 7 for
- origin for a pattern.
- @return
- point origin for patterns.
- */
- PPoint GetPatternOrigin() const;
- /**Set the fill mode to be used by future drawing operations. The fill is
- used for the internal parts of solid shapes eg rectangles, ellipses etc.
- @return
- TRUE if the fill mode was changed, FALSE if the new fill mode was
- identical to the current setting.
- */
- virtual BOOL SetFillMode(DrawingModes style);
- /**Get the fill mode to be used by future drawing operations. The fill is
- used for the internal parts of solid shapes eg rectangles, ellipses etc.
- @return
- the current fill mode used in the canvas state.
- */
- DrawingModes GetFillMode() const;
- /**Set the fill foreground colour to be used by future drawing operations.
- The fill is used for the internal parts of solid shapes eg rectangles,
- ellipses etc.
- @return
- TRUE if the fill foreground colour was changed, FALSE if the new fill
- foreground colour was identical to the current setting.
- */
- virtual BOOL SetFillFgColour(
- const PColour & colour /// New colour for the fill foreground
- );
- /**Get the fill foreground colour to be used by future drawing operations.
- The fill is used for the internal parts of solid shapes eg rectangles,
- ellipses etc.
- @return
- the current fill foreground colour used in the canvas state.
- */
- const PColour & GetFillFgColour() const;
- /**Set the fill background colour to be used by future drawing operations.
- The fill is used for the internal parts of solid shapes eg rectangles,
- ellipses etc.
- @return
- TRUE if the fill background colour was changed, FALSE if the new fill
- background colour was identical to the current setting.
- */
- virtual BOOL SetFillBkColour(
- const PColour & colour /// New colour for the fill background
- );
- /**Get the fill background colour to be used by future drawing operations.
- The fill is used for the internal parts of solid shapes eg rectangles,
- ellipses etc.
- @return
- the current fill background colour used in the canvas state.
- */
- const PColour & GetFillBkColour() const;
- /** Set the font drawing tool to be used by future drawing operations. */
- virtual BOOL SetFont(const PFont & newFont);
- /** Get the font drawing tool that is used by drawing operations. */
- PFont GetFont() const;
- /**Set the text foreground colour to be used by future drawing operations.
- @return
- TRUE if the text foreground colour was changed, FALSE if the new text
- foreground colour was identical to the current setting.
- */
- virtual BOOL SetTextFgColour(
- const PColour & colour /// New colour for the text foreground
- );
- /**Get the text foreground colour to be used by future drawing operations.
- @return
- the current text foreground colour used in the canvas state.
- */
- const PColour & GetTextFgColour() const;
- /**Set the text background colour to be used by future drawing operations.
- The background colour is for the "surrounds" of the characters drawn
- up to the size of the rectangular character cell.
- @return
- TRUE if the fill background colour was changed, FALSE if the new fill
- background colour was identical to the current setting.
- */
- virtual BOOL SetTextBkColour(
- const PColour & colour /// New colour for the text background
- );
- /**Get the text background colour to be used by future drawing operations.
- The background colour is for the "surrounds" of the characters drawn
- up to the size of the rectangular character cell.
- @return
- the current text background colour used in the canvas state.
- */
- const PColour & GetTextBkColour() const;
- /**This enum describes the ways in which a complex, overlapping polygon
- may be filled.
-
- When the fill mode is Alternating, the area between odd-numbered and
- even-numbered polygon sides on each scan line is filled. That is, the
- area between the first and second side, between the third and fourth
- side, and so on is filled.
- When the fill mode is Winding, any region that has a nonzero winding
- value is filled. This value is defined as the number of times a pen
- used to draw the polygon would go around the region. The direction of
- each edge of the polygon is important.
- */
- enum PolyFillMode {
- /**Selects alternate mode (fills area between odd-numbered and
- even-numbered polygon sides on each scan line).
- */
- Winding,
- /**Selects winding mode (fills any region with a nonzero winding value).
- */
- Alternating
- };
- /**Set the polygon fill mode to be used by future drawing operations.
- @return
- TRUE if the polygon fill mode was changed, FALSE if the new polygon
- fill mode was identical to the current setting.
- */
- virtual BOOL SetPolyFillMode(
- PolyFillMode newMode /// New polygon fill mode
- );
- /**Get the polygon fill mode to be used by future drawing operations.
- @return
- the current polygon fill mode used in the canvas state.
- */
- PolyFillMode GetPolyFillMode() const;
- /**Set the colour palette to be used by future drawing operations.
- @return
- TRUE if the colour palette was changed, FALSE if the new colour palette
- was identical to the current setting.
- */
- virtual BOOL SetPalette(
- const PPalette & newPal /// New palette to use
- );
- /**Get the colour palette to be used by future drawing operations.
- @return
- the current colour palette used in the canvas state.
- */
- PPalette GetPalette() const;
- /**Set the source rectangle to be used in the coordinate transform in
- future drawing operations. This is a rectangle in the world coordinates
- of the application.
- The mapping rectangle (in user coordinates) is transformed into the
- viewport rectangle (in device coordinates). This provides a scaling
- factor as well as origin shifting.
- @return
- TRUE if the mapping rectangle was changed, FALSE if the new mapping
- rectangle was identical to the current setting.
- */
- virtual BOOL SetMappingRect(
- const PRect & rect /// New mapping rectangle
- );
- /**Get the source rectangle that is used in the coordinate transform of
- drawing operations.
- The mapping rectangle (in user coordinates) is transformed into the
- viewport rectangle (in device coordinates). This provides a scaling
- factor as well as origin shifting.
- @return
- the current mapping rectangle used in the canvas state.
- */
- PRect GetMappingRect() const;
- /**Set the destination rectangle to be used in the coordinate transform in
- future drawing operations. This is a rectangle in the device coordinates
- (pixels) of the screen, printer etc.
- The mapping rectangle (in user coordinates) is transformed into the
- viewport rectangle (in device coordinates). This provides a scaling
- factor as well as origin shifting.
- @return
- TRUE if the mapping rectangle was changed, FALSE if the new mapping
- rectangle was identical to the current setting.
- */
- virtual BOOL SetViewportRect(
- const PRect & rect /// New viewport rectangle
- );
- /**Get the destination rectangle that is used in the coordinate transform
- of drawing operations.
- The mapping rectangle (in user coordinates) is transformed into the
- viewport rectangle (in device coordinates). This provides a scaling
- factor as well as origin shifting.
- @return
- the current mapping rectangle used in the canvas state.
- */
- PRect GetViewportRect() const;
- /**Set the origin of the user coordinate system. This is a shorthand way
- of adjusting the map and viewport rectangles.
- */
- void SetOrigin(const PPoint & pt);
- /**Set the origin of the user coordinate system. This is a shorthand way
- of adjusting the map and viewport rectangles.
- @return
- point in user coordinates at origin of the canvas.
- */
- PPoint GetOrigin() const;
- protected:
- // Member variables
- PenStyles penStyle;
- int penWidth;
- DrawingModes penMode;
- PColour penFgColour, penBkColour;
- PColour fillFgColour, fillBkColour;
- PPattern fillPattern;
- PPoint patternOrigin;
- DrawingModes fillMode;
- PFont font;
- PColour textFgColour, textBkColour;
- PPalette palette;
- PolyFillMode polyFillMode;
- PRect viewport, map;
- #ifdef DOC_PLUS_PLUS
- };
- #endif
- // Class declaration continued in platform specific header file ///////////////