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

Copyright © 1997-2010 Jeroen van der Zijp