1 /******************************************************************************** 2 * * 3 * D e v i c e C o n t e x t B a s e C l a s s * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1999,2020 by Jeroen van der Zijp. All Rights Reserved. * 7 ********************************************************************************* 8 * This library is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU Lesser General Public License as published by * 10 * the Free Software Foundation; either version 3 of the License, or * 11 * (at your option) any later version. * 12 * * 13 * This library is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 * GNU Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public License * 19 * along with this program. If not, see <http://www.gnu.org/licenses/> * 20 ********************************************************************************/ 21 #ifndef FXDC_H 22 #define FXDC_H 23 24 25 namespace FX { 26 27 28 /// Drawing (BITBLT) functions 29 enum FXFunction { 30 BLT_CLR, /// D := 0 31 BLT_SRC_AND_DST, /// D := S & D 32 BLT_SRC_AND_NOT_DST, /// D := S & ~D 33 BLT_SRC, /// D := S 34 BLT_NOT_SRC_AND_DST, /// D := ~S & D 35 BLT_DST, /// D := D 36 BLT_SRC_XOR_DST, /// D := S ^ D 37 BLT_SRC_OR_DST, /// D := S | D 38 BLT_NOT_SRC_AND_NOT_DST, /// D := ~S & ~D == D := ~(S | D) 39 BLT_NOT_SRC_XOR_DST, /// D := ~S ^ D 40 BLT_NOT_DST, /// D := ~D 41 BLT_SRC_OR_NOT_DST, /// D := S | ~D 42 BLT_NOT_SRC, /// D := ~S 43 BLT_NOT_SRC_OR_DST, /// D := ~S | D 44 BLT_NOT_SRC_OR_NOT_DST, /// D := ~S | ~D == ~(S & D) 45 BLT_SET /// D := 1 46 }; 47 48 49 /// Line Styles 50 enum FXLineStyle { 51 LINE_SOLID, /// Solid lines 52 LINE_ONOFF_DASH, /// On-off dashed lines 53 LINE_DOUBLE_DASH /// Double dashed lines 54 }; 55 56 57 /// Line Cap Styles 58 enum FXCapStyle { 59 CAP_NOT_LAST, /// Don't include last end cap 60 CAP_BUTT, /// Butting line end caps 61 CAP_ROUND, /// Round line end caps 62 CAP_PROJECTING /// Projecting line end caps 63 }; 64 65 66 /// Line Join Styles 67 enum FXJoinStyle { 68 JOIN_MITER, /// Mitered or pointy joints 69 JOIN_ROUND, /// Round line joints 70 JOIN_BEVEL /// Beveled or flat joints 71 }; 72 73 74 /// Fill Styles 75 enum FXFillStyle { 76 FILL_SOLID, /// Fill with solid color 77 FILL_TILED, /// Fill with tiled bitmap 78 FILL_STIPPLED, /// Fill where stipple mask is 1 79 FILL_OPAQUESTIPPLED /// Fill with foreground where mask is 1, background otherwise 80 }; 81 82 83 /// Fill Rules 84 enum FXFillRule { 85 RULE_EVEN_ODD, /// Even odd polygon filling 86 RULE_WINDING /// Winding rule polygon filling 87 }; 88 89 90 /// Stipple/dither patterns 91 enum FXStipplePattern { 92 STIPPLE_0 = 0, 93 STIPPLE_NONE = 0, 94 STIPPLE_BLACK = 0, /// All ones 95 STIPPLE_1 = 1, 96 STIPPLE_2 = 2, 97 STIPPLE_3 = 3, 98 STIPPLE_4 = 4, 99 STIPPLE_5 = 5, 100 STIPPLE_6 = 6, 101 STIPPLE_7 = 7, 102 STIPPLE_8 = 8, 103 STIPPLE_GRAY = 8, /// 50% gray 104 STIPPLE_9 = 9, 105 STIPPLE_10 = 10, 106 STIPPLE_11 = 11, 107 STIPPLE_12 = 12, 108 STIPPLE_13 = 13, 109 STIPPLE_14 = 14, 110 STIPPLE_15 = 15, 111 STIPPLE_16 = 16, 112 STIPPLE_WHITE = 16, /// All zeroes 113 STIPPLE_HORZ = 17, /// Horizontal hatch pattern 114 STIPPLE_VERT = 18, /// Vertical hatch pattern 115 STIPPLE_CROSS = 19, /// Cross-hatch pattern 116 STIPPLE_DIAG = 20, /// Diagonal // hatch pattern 117 STIPPLE_REVDIAG = 21, /// Reverse diagonal \\ hatch pattern 118 STIPPLE_CROSSDIAG = 22 /// Cross-diagonal hatch pattern 119 }; 120 121 122 /// Line segment 123 struct FXSegment { 124 FXshort x1,y1,x2,y2; 125 }; 126 127 128 /// Arc 129 struct FXArc { 130 FXshort x,y,w,h,a,b; 131 }; 132 133 134 class FXApp; 135 class FXImage; 136 class FXBitmap; 137 class FXIcon; 138 class FXFont; 139 class FXDrawable; 140 class FXRegion; 141 142 143 /** 144 * Abstract Device Context 145 * 146 * A Device Context is used to maintain the state of the graphics drawing system. 147 * Defining your drawing code in terms of the Abstract Device Context allows the 148 * drawing commands to be rendered on different types of surfaces, such as windows 149 * and images (FXDCWindow), or on paper (FXDCPrint). 150 * WYSYWYG may be obtained by using the same identical drawing code in your 151 * application regardless of the actual device surface being utilized. 152 */ 153 class FXAPI FXDC { 154 friend class FXFont; 155 private: 156 FXApp *app; // Application 157 protected: 158 void *ctx; // Context handle 159 FXFont *font; // Drawing font 160 FXStipplePattern pattern; // Stipple pattern 161 FXBitmap *stipple; // Stipple bitmap 162 FXImage *tile; // Tile image 163 FXBitmap *mask; // Mask bitmap 164 FXRectangle clip; // Clip rectangle 165 FXColor fg; // Foreground color 166 FXColor bg; // Background color 167 FXuint width; // Line width 168 FXCapStyle cap; // Line cap style 169 FXJoinStyle join; // Line join style 170 FXLineStyle style; // Line style 171 FXFillStyle fill; // Fill style 172 FXFillRule rule; // Fill rule 173 FXFunction rop; // RasterOp 174 FXchar dashpat[32]; // Line dash pattern data 175 FXuint dashlen; // Line dash pattern length 176 FXuint dashoff; // Line dash pattern offset 177 FXint tx; // Tile dx 178 FXint ty; // Tile dy 179 FXint cx; // Clip x 180 FXint cy; // Clip y 181 private: 182 FXDC(); 183 FXDC(const FXDC&); 184 FXDC &operator=(const FXDC&); 185 public: 186 187 /// Construct dummy DC 188 FXDC(FXApp* a); 189 190 /// Get application getApp()191 FXApp* getApp() const { return app; } 192 193 /// Get context handle context()194 void* context() const { return ctx; } 195 196 /// Read back pixel 197 virtual FXColor readPixel(FXint x,FXint y); 198 199 /// Draw points 200 virtual void drawPoint(FXint x,FXint y); 201 virtual void drawPoints(const FXPoint* points,FXuint npoints); 202 virtual void drawPointsRel(const FXPoint* points,FXuint npoints); 203 204 /// Draw lines 205 virtual void drawLine(FXint x1,FXint y1,FXint x2,FXint y2); 206 virtual void drawLines(const FXPoint* points,FXuint npoints); 207 virtual void drawLinesRel(const FXPoint* points,FXuint npoints); 208 virtual void drawLineSegments(const FXSegment* segments,FXuint nsegments); 209 210 /// Draw rectangles 211 virtual void drawRectangle(FXint x,FXint y,FXint w,FXint h); 212 virtual void drawRectangles(const FXRectangle* rectangles,FXuint nrectangles); 213 214 /// Draw rounded rectangle with ellipse with ew and ellips height eh 215 virtual void drawRoundRectangle(FXint x,FXint y,FXint w,FXint h,FXint ew,FXint eh); 216 217 /** 218 * Draw arcs. 219 * The argument ang1 specifies the start of the arc relative to the 220 * three-o'clock position from the center, in units of degrees*64. 221 * The argument ang2 specifies the path and extent of the arc relative 222 * to the start of the arc, in units of degrees*64. 223 * The arguments x,y,w,h specify the bounding rectangle. 224 */ 225 virtual void drawArc(FXint x,FXint y,FXint w,FXint h,FXint ang1,FXint ang2); 226 virtual void drawArcs(const FXArc* arcs,FXuint narcs); 227 228 /// Draw ellipse 229 virtual void drawEllipse(FXint x,FXint y,FXint w,FXint h); 230 231 /// Filled rectangles 232 virtual void fillRectangle(FXint x,FXint y,FXint w,FXint h); 233 virtual void fillRectangles(const FXRectangle* rectangles,FXuint nrectangles); 234 235 /// Filled rounded rectangle with ellipse with ew and ellips height eh 236 virtual void fillRoundRectangle(FXint x,FXint y,FXint w,FXint h,FXint ew,FXint eh); 237 238 /// Fill chord 239 virtual void fillChord(FXint x,FXint y,FXint w,FXint h,FXint ang1,FXint ang2); 240 virtual void fillChords(const FXArc* chords,FXuint nchords); 241 242 /// Fill arcs 243 virtual void fillArc(FXint x,FXint y,FXint w,FXint h,FXint ang1,FXint ang2); 244 virtual void fillArcs(const FXArc* arcs,FXuint narcs); 245 246 /// Fill ellipse 247 virtual void fillEllipse(FXint x,FXint y,FXint w,FXint h); 248 249 /// Filled polygon 250 virtual void fillPolygon(const FXPoint* points,FXuint npoints); 251 virtual void fillConcavePolygon(const FXPoint* points,FXuint npoints); 252 virtual void fillComplexPolygon(const FXPoint* points,FXuint npoints); 253 254 /// Filled polygon with relative points 255 virtual void fillPolygonRel(const FXPoint* points,FXuint npoints); 256 virtual void fillConcavePolygonRel(const FXPoint* points,FXuint npoints); 257 virtual void fillComplexPolygonRel(const FXPoint* points,FXuint npoints); 258 259 /// Fill vertical gradient rectangle 260 virtual void fillVerticalGradient(FXint x,FXint y,FXint w,FXint h,FXColor top,FXColor bottom); 261 262 /// Fill horizontal gradient rectangle 263 virtual void fillHorizontalGradient(FXint x,FXint y,FXint w,FXint h,FXColor left,FXColor right); 264 265 /// Draw hashed box 266 virtual void drawHashBox(FXint x,FXint y,FXint w,FXint h,FXint b=1); 267 268 /// Draw focus rectangle 269 virtual void drawFocusRectangle(FXint x,FXint y,FXint w,FXint h); 270 271 /// Draw area from source 272 virtual void drawArea(const FXDrawable* source,FXint sx,FXint sy,FXint sw,FXint sh,FXint dx,FXint dy); 273 274 /// Draw area stretched area from source 275 virtual void drawArea(const FXDrawable* source,FXint sx,FXint sy,FXint sw,FXint sh,FXint dx,FXint dy,FXint dw,FXint dh); 276 277 /// Draw image 278 virtual void drawImage(const FXImage* image,FXint dx,FXint dy); 279 280 /// Draw bitmap 281 virtual void drawBitmap(const FXBitmap* bitmap,FXint dx,FXint dy); 282 283 /// Draw icon 284 virtual void drawIcon(const FXIcon* icon,FXint dx,FXint dy); 285 virtual void drawIconShaded(const FXIcon* icon,FXint dx,FXint dy); 286 virtual void drawIconSunken(const FXIcon* icon,FXint dx,FXint dy); 287 288 /// Draw string with base line starting at x, y 289 virtual void drawText(FXint x,FXint y,const FXString& string); 290 virtual void drawText(FXint x,FXint y,const FXchar* string,FXuint length); 291 292 /// Draw text starting at x, y over filled background 293 virtual void drawImageText(FXint x,FXint y,const FXString& string); 294 virtual void drawImageText(FXint x,FXint y,const FXchar* string,FXuint length); 295 296 /// Set foreground drawing color 297 virtual void setForeground(FXColor clr); 298 299 /// Get foreground drawing color getForeground()300 FXColor getForeground() const { return fg; } 301 302 /// Set background drawing color 303 virtual void setBackground(FXColor clr); 304 305 /// Get background drawing color getBackground()306 FXColor getBackground() const { return bg; } 307 308 /** 309 * Set dash pattern and dash offset. 310 * A dash pattern of [1 2 3 4] is a repeating pattern of 1 foreground pixel, 311 * 2 background pixels, 3 foreground pixels, and 4 background pixels. 312 * The offset is where in the pattern the system will start counting. 313 * The maximum length of the dash pattern is 32. 314 */ 315 virtual void setDashes(FXuint dashoffset,const FXchar *dashpattern,FXuint dashlength); 316 317 /// Get dash pattern getDashPattern()318 const FXchar* getDashPattern() const { return dashpat; } 319 320 /// Get dash offset getDashOffset()321 FXuint getDashOffset() const { return dashoff; } 322 323 /// Get dash length getDashLength()324 FXuint getDashLength() const { return dashlen; } 325 326 /// Set line width:- 0 means thinnest/fastest possible 327 virtual void setLineWidth(FXuint linewidth=0); 328 329 /// Get line width getLineWidth()330 FXuint getLineWidth() const { return width; } 331 332 /// Set line cap style 333 virtual void setLineCap(FXCapStyle capstyle=CAP_BUTT); 334 335 /// Get line cap style getLineCap()336 FXCapStyle getLineCap() const { return cap; } 337 338 /// Set line join style 339 virtual void setLineJoin(FXJoinStyle joinstyle=JOIN_MITER); 340 341 /// Get line join style getLineJoin()342 FXJoinStyle getLineJoin() const { return join; } 343 344 /// Set line style 345 virtual void setLineStyle(FXLineStyle linestyle=LINE_SOLID); 346 347 /// Get line style getLineStyle()348 FXLineStyle getLineStyle() const { return style; } 349 350 /// Set fill style 351 virtual void setFillStyle(FXFillStyle fillstyle=FILL_SOLID); 352 353 /// Get fill style getFillStyle()354 FXFillStyle getFillStyle() const { return fill; } 355 356 /// Set fill rule 357 virtual void setFillRule(FXFillRule fillrule=RULE_EVEN_ODD); 358 359 /// Get fill rule getFillRule()360 FXFillRule getFillRule() const { return rule; } 361 362 /// Set rasterop function 363 virtual void setFunction(FXFunction func=BLT_SRC); 364 365 /// Get rasterop function getFunction()366 FXFunction getFunction() const { return rop; } 367 368 /// Set the tile image 369 virtual void setTile(FXImage* image,FXint dx=0,FXint dy=0); 370 371 /// Get the tile image getTile()372 FXImage *getTile() const { return tile; } 373 374 /// Set the stipple pattern 375 virtual void setStipple(FXBitmap *bitmap,FXint dx=0,FXint dy=0); 376 377 /// Get stipple bitmap getStippleBitmap()378 FXBitmap *getStippleBitmap() const { return stipple; } 379 380 /// Set the stipple pattern 381 virtual void setStipple(FXStipplePattern pat,FXint dx=0,FXint dy=0); 382 383 /// Get pattern getStipplePattern()384 FXStipplePattern getStipplePattern() const { return pattern; } 385 386 /// Set clip region 387 virtual void setClipRegion(const FXRegion& region); 388 389 /// Set clip rectangle 390 virtual void setClipRectangle(FXint x,FXint y,FXint w,FXint h); 391 392 /// Change clip rectangle 393 virtual void setClipRectangle(const FXRectangle& rectangle); 394 395 /// Return clip rectangle getClipRectangle()396 const FXRectangle& getClipRectangle() const { return clip; } 397 398 /// Return clip x getClipX()399 FXint getClipX() const { return clip.x; } 400 401 /// Return clip y getClipY()402 FXint getClipY() const { return clip.y; } 403 404 /// Return clip width getClipWidth()405 FXint getClipWidth() const { return clip.w; } 406 407 /// Return clip height getClipHeight()408 FXint getClipHeight() const { return clip.h; } 409 410 /// Clear clipping 411 virtual void clearClipRectangle(); 412 413 /// Set clip mask 414 virtual void setClipMask(FXBitmap* bitmap,FXint dx=0,FXint dy=0); 415 416 /// Clear clip mask 417 virtual void clearClipMask(); 418 419 /// Set font to draw text with 420 virtual void setFont(FXFont *fnt); 421 422 /// Get text font getFont()423 FXFont* getFont() const { return font; } 424 425 /// Clip against child windows 426 virtual void clipChildren(FXbool yes); 427 428 /// Destructor 429 virtual ~FXDC(); 430 }; 431 432 } 433 434 #endif 435