Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXDC.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *               D e v i c e   C o n t e x t   B a s e   C l a s s               *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1999,2009 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 *********************************************************************************
00021 * $Id: FXDC.h,v 1.44 2009/01/06 13:07:22 fox Exp $                              *
00022 ********************************************************************************/
00023 #ifndef FXDC_H
00024 #define FXDC_H
00025 
00026 namespace FX {
00027 
00028 /// Drawing (BITBLT) functions
00029 enum FXFunction {
00030   BLT_CLR,                        /// D := 0
00031   BLT_SRC_AND_DST,                /// D := S & D
00032   BLT_SRC_AND_NOT_DST,            /// D := S & ~D
00033   BLT_SRC,                        /// D := S
00034   BLT_NOT_SRC_AND_DST,            /// D := ~S & D
00035   BLT_DST,                        /// D := D
00036   BLT_SRC_XOR_DST,                /// D := S ^ D
00037   BLT_SRC_OR_DST,                 /// D := S | D
00038   BLT_NOT_SRC_AND_NOT_DST,        /// D := ~S & ~D  ==  D := ~(S | D)
00039   BLT_NOT_SRC_XOR_DST,            /// D := ~S ^ D
00040   BLT_NOT_DST,                    /// D := ~D
00041   BLT_SRC_OR_NOT_DST,             /// D := S | ~D
00042   BLT_NOT_SRC,                    /// D := ~S
00043   BLT_NOT_SRC_OR_DST,             /// D := ~S | D
00044   BLT_NOT_SRC_OR_NOT_DST,         /// D := ~S | ~D  ==  ~(S & D)
00045   BLT_SET                         /// D := 1
00046   };
00047 
00048 
00049 /// Line Styles
00050 enum FXLineStyle {
00051   LINE_SOLID,                     /// Solid lines
00052   LINE_ONOFF_DASH,                /// On-off dashed lines
00053   LINE_DOUBLE_DASH                /// Double dashed lines
00054   };
00055 
00056 
00057 /// Line Cap Styles
00058 enum FXCapStyle {
00059   CAP_NOT_LAST,                   /// Don't include last end cap
00060   CAP_BUTT,                       /// Butting line end caps
00061   CAP_ROUND,                      /// Round line end caps
00062   CAP_PROJECTING                  /// Projecting line end caps
00063   };
00064 
00065 
00066 /// Line Join Styles
00067 enum FXJoinStyle {
00068   JOIN_MITER,                     /// Mitered or pointy joints
00069   JOIN_ROUND,                     /// Round line joints
00070   JOIN_BEVEL                      /// Beveled or flat joints
00071   };
00072 
00073 
00074 /// Fill Styles
00075 enum FXFillStyle {
00076   FILL_SOLID,                     /// Fill with solid color
00077   FILL_TILED,                     /// Fill with tiled bitmap
00078   FILL_STIPPLED,                  /// Fill where stipple mask is 1
00079   FILL_OPAQUESTIPPLED             /// Fill with foreground where mask is 1, background otherwise
00080   };
00081 
00082 
00083 /// Fill Rules
00084 enum FXFillRule {
00085   RULE_EVEN_ODD,                  /// Even odd polygon filling
00086   RULE_WINDING                    /// Winding rule polygon filling
00087   };
00088 
00089 
00090 /// Stipple/dither patterns
00091 enum FXStipplePattern {
00092   STIPPLE_0         = 0,
00093   STIPPLE_NONE      = 0,
00094   STIPPLE_BLACK     = 0,            /// All ones
00095   STIPPLE_1         = 1,
00096   STIPPLE_2         = 2,
00097   STIPPLE_3         = 3,
00098   STIPPLE_4         = 4,
00099   STIPPLE_5         = 5,
00100   STIPPLE_6         = 6,
00101   STIPPLE_7         = 7,
00102   STIPPLE_8         = 8,
00103   STIPPLE_GRAY      = 8,            /// 50% gray
00104   STIPPLE_9         = 9,
00105   STIPPLE_10        = 10,
00106   STIPPLE_11        = 11,
00107   STIPPLE_12        = 12,
00108   STIPPLE_13        = 13,
00109   STIPPLE_14        = 14,
00110   STIPPLE_15        = 15,
00111   STIPPLE_16        = 16,
00112   STIPPLE_WHITE     = 16,           /// All zeroes
00113   STIPPLE_HORZ      = 17,           /// Horizontal hatch pattern
00114   STIPPLE_VERT      = 18,           /// Vertical hatch pattern
00115   STIPPLE_CROSS     = 19,           /// Cross-hatch pattern
00116   STIPPLE_DIAG      = 20,           /// Diagonal // hatch pattern
00117   STIPPLE_REVDIAG   = 21,           /// Reverse diagonal \\ hatch pattern
00118   STIPPLE_CROSSDIAG = 22            /// Cross-diagonal hatch pattern
00119   };
00120 
00121 
00122 /// Line segment
00123 struct FXSegment {
00124   FXshort x1,y1,x2,y2;
00125   };
00126 
00127 
00128 /// Arc
00129 struct FXArc {
00130   FXshort x,y,w,h,a,b;
00131   };
00132 
00133 
00134 class FXApp;
00135 class FXImage;
00136 class FXBitmap;
00137 class FXIcon;
00138 class FXFont;
00139 class FXDrawable;
00140 class FXRegion;
00141 
00142 
00143 /**
00144 * Abstract Device Context
00145 *
00146 * A Device Context is used to maintain the state of the graphics drawing system.
00147 * Defining your drawing code in terms of the Abstract Device Context allows the
00148 * drawing commands to be rendered on different types of surfaces, such as windows
00149 * and images (FXDCWindow), or on paper (FXDCPrint).
00150 * WYSYWYG may be obtained by using the same identical drawing code in your
00151 * application regardless of the actual device surface being utilized.
00152 */
00153 class FXAPI FXDC {
00154   friend class FXFont;
00155 private:
00156   FXApp           *app;         // Application
00157 protected:
00158   void            *ctx;         // Context handle
00159   FXFont          *font;        // Drawing font
00160   FXStipplePattern pattern;     // Stipple pattern
00161   FXBitmap        *stipple;     // Stipple bitmap
00162   FXImage         *tile;        // Tile image
00163   FXBitmap        *mask;        // Mask bitmap
00164   FXRectangle      clip;        // Clip rectangle
00165   FXColor          fg;          // Foreground color
00166   FXColor          bg;          // Background color
00167   FXuint           width;       // Line width
00168   FXCapStyle       cap;         // Line cap style
00169   FXJoinStyle      join;        // Line join style
00170   FXLineStyle      style;       // Line style
00171   FXFillStyle      fill;        // Fill style
00172   FXFillRule       rule;        // Fill rule
00173   FXFunction       rop;         // RasterOp
00174   FXchar           dashpat[32]; // Line dash pattern data
00175   FXuint           dashlen;     // Line dash pattern length
00176   FXuint           dashoff;     // Line dash pattern offset
00177   FXint            tx;          // Tile dx
00178   FXint            ty;          // Tile dy
00179   FXint            cx;          // Clip x
00180   FXint            cy;          // Clip y
00181 private:
00182   FXDC();
00183   FXDC(const FXDC&);
00184   FXDC &operator=(const FXDC&);
00185 public:
00186 
00187   /// Construct dummy DC
00188   FXDC(FXApp* a);
00189 
00190   /// Get application
00191   FXApp* getApp() const { return app; }
00192 
00193   /// Get context handle
00194   void* context() const { return ctx; }
00195 
00196   /// Read back pixel
00197   virtual FXColor readPixel(FXint x,FXint y);
00198 
00199   /// Draw points
00200   virtual void drawPoint(FXint x,FXint y);
00201   virtual void drawPoints(const FXPoint* points,FXuint npoints);
00202   virtual void drawPointsRel(const FXPoint* points,FXuint npoints);
00203 
00204   /// Draw lines
00205   virtual void drawLine(FXint x1,FXint y1,FXint x2,FXint y2);
00206   virtual void drawLines(const FXPoint* points,FXuint npoints);
00207   virtual void drawLinesRel(const FXPoint* points,FXuint npoints);
00208   virtual void drawLineSegments(const FXSegment* segments,FXuint nsegments);
00209 
00210   /// Draw rectangles
00211   virtual void drawRectangle(FXint x,FXint y,FXint w,FXint h);
00212   virtual void drawRectangles(const FXRectangle* rectangles,FXuint nrectangles);
00213 
00214   /// Draw rounded rectangle with ellipse with ew and ellips height eh
00215   virtual void drawRoundRectangle(FXint x,FXint y,FXint w,FXint h,FXint ew,FXint eh);
00216 
00217   /**
00218   * Draw arcs.
00219   * The argument ang1 specifies the start of the arc relative to the
00220   * three-o'clock position from the center, in units of degrees*64.
00221   * The argument ang2 specifies the path and extent of the arc relative
00222   * to the start of the arc, in units of degrees*64.
00223   * The arguments x,y,w,h specify the bounding rectangle.
00224   */
00225   virtual void drawArc(FXint x,FXint y,FXint w,FXint h,FXint ang1,FXint ang2);
00226   virtual void drawArcs(const FXArc* arcs,FXuint narcs);
00227 
00228   /// Draw ellipse
00229   virtual void drawEllipse(FXint x,FXint y,FXint w,FXint h);
00230 
00231   /// Filled rectangles
00232   virtual void fillRectangle(FXint x,FXint y,FXint w,FXint h);
00233   virtual void fillRectangles(const FXRectangle* rectangles,FXuint nrectangles);
00234 
00235   /// Filled rounded rectangle with ellipse with ew and ellips height eh
00236   virtual void fillRoundRectangle(FXint x,FXint y,FXint w,FXint h,FXint ew,FXint eh);
00237 
00238   /// Fill chord
00239   virtual void fillChord(FXint x,FXint y,FXint w,FXint h,FXint ang1,FXint ang2);
00240   virtual void fillChords(const FXArc* chords,FXuint nchords);
00241 
00242   /// Fill arcs
00243   virtual void fillArc(FXint x,FXint y,FXint w,FXint h,FXint ang1,FXint ang2);
00244   virtual void fillArcs(const FXArc* arcs,FXuint narcs);
00245 
00246   /// Fill ellipse
00247   virtual void fillEllipse(FXint x,FXint y,FXint w,FXint h);
00248 
00249   /// Filled polygon
00250   virtual void fillPolygon(const FXPoint* points,FXuint npoints);
00251   virtual void fillConcavePolygon(const FXPoint* points,FXuint npoints);
00252   virtual void fillComplexPolygon(const FXPoint* points,FXuint npoints);
00253 
00254   /// Filled polygon with relative points
00255   virtual void fillPolygonRel(const FXPoint* points,FXuint npoints);
00256   virtual void fillConcavePolygonRel(const FXPoint* points,FXuint npoints);
00257   virtual void fillComplexPolygonRel(const FXPoint* points,FXuint npoints);
00258 
00259   /// Fill vertical gradient rectangle
00260   virtual void fillVerticalGradient(FXint x,FXint y,FXint w,FXint h,FXColor top,FXColor bottom);
00261 
00262   /// Fill horizontal gradient rectangle
00263   virtual void fillHorizontalGradient(FXint x,FXint y,FXint w,FXint h,FXColor left,FXColor right);
00264 
00265   /// Draw hashed box
00266   virtual void drawHashBox(FXint x,FXint y,FXint w,FXint h,FXint b=1);
00267 
00268   /// Draw focus rectangle
00269   virtual void drawFocusRectangle(FXint x,FXint y,FXint w,FXint h);
00270 
00271   /// Draw area from source
00272   virtual void drawArea(const FXDrawable* source,FXint sx,FXint sy,FXint sw,FXint sh,FXint dx,FXint dy);
00273 
00274   /// Draw area stretched area from source
00275   virtual void drawArea(const FXDrawable* source,FXint sx,FXint sy,FXint sw,FXint sh,FXint dx,FXint dy,FXint dw,FXint dh);
00276 
00277   /// Draw image
00278   virtual void drawImage(const FXImage* image,FXint dx,FXint dy);
00279 
00280   /// Draw bitmap
00281   virtual void drawBitmap(const FXBitmap* bitmap,FXint dx,FXint dy);
00282 
00283   /// Draw icon
00284   virtual void drawIcon(const FXIcon* icon,FXint dx,FXint dy);
00285   virtual void drawIconShaded(const FXIcon* icon,FXint dx,FXint dy);
00286   virtual void drawIconSunken(const FXIcon* icon,FXint dx,FXint dy);
00287 
00288   /// Draw string with base line starting at x, y
00289   virtual void drawText(FXint x,FXint y,const FXString& string);
00290   virtual void drawText(FXint x,FXint y,const FXchar* string,FXuint length);
00291 
00292   /// Draw text starting at x, y over filled background
00293   virtual void drawImageText(FXint x,FXint y,const FXString& string);
00294   virtual void drawImageText(FXint x,FXint y,const FXchar* string,FXuint length);
00295 
00296   /// Set foreground drawing color
00297   virtual void setForeground(FXColor clr);
00298 
00299   /// Get foreground drawing color
00300   FXColor getForeground() const { return fg; }
00301 
00302   /// Set background drawing color
00303   virtual void setBackground(FXColor clr);
00304 
00305   /// Get background drawing color
00306   FXColor getBackground() const { return bg; }
00307 
00308   /**
00309   * Set dash pattern and dash offset.
00310   * A dash pattern of [1 2 3 4] is a repeating pattern of 1 foreground pixel,
00311   * 2 background pixels, 3 foreground pixels, and 4 background pixels.
00312   * The offset is where in the pattern the system will start counting.
00313   * The maximum length of the dash pattern is 32.
00314   */
00315   virtual void setDashes(FXuint dashoffset,const FXchar *dashpattern,FXuint dashlength);
00316 
00317   /// Get dash pattern
00318   const FXchar* getDashPattern() const { return dashpat; }
00319 
00320   /// Get dash offset
00321   FXuint getDashOffset() const { return dashoff; }
00322 
00323   /// Get dash length
00324   FXuint getDashLength() const { return dashlen; }
00325 
00326   /// Set line width:- 0 means thinnest/fastest possible
00327   virtual void setLineWidth(FXuint linewidth=0);
00328 
00329   /// Get line width
00330   FXuint getLineWidth() const { return width; }
00331 
00332   /// Set line cap style
00333   virtual void setLineCap(FXCapStyle capstyle=CAP_BUTT);
00334 
00335   /// Get line cap style
00336   FXCapStyle getLineCap() const { return cap; }
00337 
00338   /// Set line join style
00339   virtual void setLineJoin(FXJoinStyle joinstyle=JOIN_MITER);
00340 
00341   /// Get line join style
00342   FXJoinStyle getLineJoin() const { return join; }
00343 
00344   /// Set line style
00345   virtual void setLineStyle(FXLineStyle linestyle=LINE_SOLID);
00346 
00347   /// Get line style
00348   FXLineStyle getLineStyle() const { return style; }
00349 
00350   /// Set fill style
00351   virtual void setFillStyle(FXFillStyle fillstyle=FILL_SOLID);
00352 
00353   /// Get fill style
00354   FXFillStyle getFillStyle() const { return fill; }
00355 
00356   /// Set fill rule
00357   virtual void setFillRule(FXFillRule fillrule=RULE_EVEN_ODD);
00358 
00359   /// Get fill rule
00360   FXFillRule getFillRule() const { return rule; }
00361 
00362   /// Set rasterop function
00363   virtual void setFunction(FXFunction func=BLT_SRC);
00364 
00365   /// Get rasterop function
00366   FXFunction getFunction() const { return rop; }
00367 
00368   /// Set the tile image
00369   virtual void setTile(FXImage* image,FXint dx=0,FXint dy=0);
00370 
00371   /// Get the tile image
00372   FXImage *getTile() const { return tile; }
00373 
00374   /// Set the stipple pattern
00375   virtual void setStipple(FXBitmap *bitmap,FXint dx=0,FXint dy=0);
00376 
00377   /// Get stipple bitmap
00378   FXBitmap *getStippleBitmap() const { return stipple; }
00379 
00380   /// Set the stipple pattern
00381   virtual void setStipple(FXStipplePattern pat,FXint dx=0,FXint dy=0);
00382 
00383   /// Get pattern
00384   FXStipplePattern getStipplePattern() const { return pattern; }
00385 
00386   /// Set clip region
00387   virtual void setClipRegion(const FXRegion& region);
00388 
00389   /// Set clip rectangle
00390   virtual void setClipRectangle(FXint x,FXint y,FXint w,FXint h);
00391 
00392   /// Change clip rectangle
00393   virtual void setClipRectangle(const FXRectangle& rectangle);
00394 
00395   /// Return clip rectangle
00396   const FXRectangle& getClipRectangle() const { return clip; }
00397 
00398   /// Return clip x
00399   FXint getClipX() const { return clip.x; }
00400 
00401   /// Return clip y
00402   FXint getClipY() const { return clip.y; }
00403 
00404   /// Return clip width
00405   FXint getClipWidth() const { return clip.w; }
00406 
00407   /// Return clip height
00408   FXint getClipHeight() const { return clip.h; }
00409 
00410   /// Clear clipping
00411   virtual void clearClipRectangle();
00412 
00413   /// Set clip mask
00414   virtual void setClipMask(FXBitmap* bitmap,FXint dx=0,FXint dy=0);
00415 
00416   /// Clear clip mask
00417   virtual void clearClipMask();
00418 
00419   /// Set font to draw text with
00420   virtual void setFont(FXFont *fnt);
00421 
00422   /// Get text font
00423   FXFont* getFont() const { return font; }
00424 
00425   /// Clip against child windows
00426   virtual void clipChildren(FXbool yes);
00427 
00428   /// Destructor
00429   virtual ~FXDC();
00430   };
00431 
00432 }
00433 
00434 #endif

Copyright © 1997-2009 Jeroen van der Zijp