]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/graphics.h
Correct names of parameters in wxAffineMatrix2D documentation.
[wxWidgets.git] / interface / wx / graphics.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: graphics.h
9cc4ab85 3// Purpose: interface of various wxGraphics* classes
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxGraphicsPath
7c913512 11
23d291c2
BP
12 A wxGraphicsPath is a native representation of a geometric path. The
13 contents are specific an private to the respective renderer. Instances are
14 reference counted and can therefore be assigned as usual. The only way to
15 get a valid instance is by using wxGraphicsContext::CreatePath() or
16 wxGraphicsRenderer::CreatePath().
7c913512 17
23324ae1 18 @library{wxcore}
23d291c2 19 @category{gdi}
23324ae1
FM
20*/
21class wxGraphicsPath : public wxGraphicsObject
22{
23public:
23324ae1 24 /**
2e4d0e91
VZ
25 Adds an arc of a circle.
26
27 The circle is defined by the coordinates of its centre (@a x, @a y) or
28 @a c and its radius @a r. The arc goes from the starting angle @a
29 startAngle to @a endAngle either clockwise or counter-clockwise
30 depending on the value of @a clockwise argument.
31
32 The angles are measured in radians but, contrary to the usual
33 mathematical convention, are always @e clockwise from the horizontal
34 axis.
23d291c2 35 */
2e4d0e91 36 //@{
23d291c2
BP
37 virtual void AddArc(wxDouble x, wxDouble y, wxDouble r,
38 wxDouble startAngle, wxDouble endAngle,
39 bool clockwise);
7c913512 40 void AddArc(const wxPoint2DDouble& c, wxDouble r,
23d291c2 41 wxDouble startAngle, wxDouble endAngle, bool clockwise);
2e4d0e91 42 //@}
23324ae1
FM
43
44 /**
23d291c2
BP
45 Appends a an arc to two tangents connecting (current) to (@a x1,@a y1)
46 and (@a x1,@a y1) to (@a x2,@a y2), also a straight line from (current)
47 to (@a x1,@a y1).
23324ae1 48 */
da1ed74c
FM
49 virtual void AddArcToPoint(wxDouble x1, wxDouble y1, wxDouble x2,
50 wxDouble y2, wxDouble r);
23324ae1
FM
51
52 /**
23d291c2
BP
53 Appends a circle around (@a x,@a y) with radius @a r as a new closed
54 subpath.
23324ae1 55 */
da1ed74c 56 virtual void AddCircle(wxDouble x, wxDouble y, wxDouble r);
23324ae1 57
23324ae1 58 /**
23d291c2
BP
59 Adds a cubic bezier curve from the current point, using two control
60 points and an end point.
61 */
a44f3b5a
FM
62 virtual void AddCurveToPoint(wxDouble cx1, wxDouble cy1,
63 wxDouble cx2, wxDouble cy2,
64 wxDouble x, wxDouble y);
23d291c2
BP
65 /**
66 Adds a cubic bezier curve from the current point, using two control
67 points and an end point.
23324ae1 68 */
7c913512
FM
69 void AddCurveToPoint(const wxPoint2DDouble& c1,
70 const wxPoint2DDouble& c2,
71 const wxPoint2DDouble& e);
23324ae1
FM
72
73 /**
74 Appends an ellipse fitting into the passed in rectangle.
75 */
da1ed74c 76 virtual void AddEllipse(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
23324ae1 77
23324ae1 78 /**
23d291c2
BP
79 Adds a straight line from the current point to (@a x,@a y).
80 */
81 virtual void AddLineToPoint(wxDouble x, wxDouble y);
82 /**
83 Adds a straight line from the current point to @a p.
23324ae1 84 */
7c913512 85 void AddLineToPoint(const wxPoint2DDouble& p);
23324ae1
FM
86
87 /**
88 Adds another path.
89 */
da1ed74c 90 virtual void AddPath(const wxGraphicsPath& path);
23324ae1
FM
91
92 /**
23d291c2
BP
93 Adds a quadratic bezier curve from the current point, using a control
94 point and an end point.
23324ae1 95 */
23d291c2
BP
96 virtual void AddQuadCurveToPoint(wxDouble cx, wxDouble cy,
97 wxDouble x, wxDouble y);
23324ae1
FM
98
99 /**
100 Appends a rectangle as a new closed subpath.
101 */
da1ed74c 102 virtual void AddRectangle(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
23324ae1
FM
103
104 /**
105 Appends a rounded rectangle as a new closed subpath.
106 */
da1ed74c
FM
107 virtual void AddRoundedRectangle(wxDouble x, wxDouble y, wxDouble w,
108 wxDouble h, wxDouble radius);
23324ae1
FM
109
110 /**
111 Closes the current sub-path.
112 */
da1ed74c 113 virtual void CloseSubpath();
23324ae1 114
23324ae1 115 /**
23d291c2 116 @return @true if the point is within the path.
23324ae1
FM
117 */
118 bool Contains(const wxPoint2DDouble& c,
328f5751 119 int fillStyle = wxODDEVEN_RULE) const;
23d291c2
BP
120 /**
121 @return @true if the point is within the path.
122 */
123 virtual bool Contains(wxDouble x, wxDouble y,
124 int fillStyle = wxODDEVEN_RULE) const;
23324ae1 125
23324ae1 126 /**
23d291c2
BP
127 Gets the bounding box enclosing all points (possibly including control
128 points).
23324ae1 129 */
328f5751 130 wxRect2DDouble GetBox() const;
23d291c2
BP
131 /**
132 Gets the bounding box enclosing all points (possibly including control
133 points).
134 */
135 virtual void GetBox(wxDouble* x, wxDouble* y,
136 wxDouble* w, wxDouble* h) const;
23324ae1 137
23324ae1
FM
138 /**
139 Gets the last point of the current path, (0,0) if not yet set.
140 */
23d291c2
BP
141 virtual void GetCurrentPoint(wxDouble* x, wxDouble* y) const;
142 /**
143 Gets the last point of the current path, (0,0) if not yet set.
144 */
145 wxPoint2DDouble GetCurrentPoint() const;
23324ae1
FM
146
147 /**
23d291c2
BP
148 Returns the native path (CGPathRef for Core Graphics, Path pointer for
149 GDIPlus and a cairo_path_t pointer for cairo).
23324ae1 150 */
da1ed74c 151 virtual void* GetNativePath() const;
23324ae1 152
23324ae1 153 /**
23d291c2
BP
154 Begins a new subpath at (@a x,@a y).
155 */
156 virtual void MoveToPoint(wxDouble x, wxDouble y);
157 /**
158 Begins a new subpath at @a p.
23324ae1 159 */
7c913512 160 void MoveToPoint(const wxPoint2DDouble& p);
23324ae1
FM
161
162 /**
163 Transforms each point of this path by the matrix.
164 */
da1ed74c 165 virtual void Transform(const wxGraphicsMatrix& matrix);
23324ae1
FM
166
167 /**
23d291c2
BP
168 Gives back the native path returned by GetNativePath() because there
169 might be some deallocations necessary (e.g. on cairo the native path
170 returned by GetNativePath() is newly allocated each time).
23324ae1 171 */
da1ed74c 172 virtual void UnGetNativePath(void* p) const;
23324ae1
FM
173};
174
175
e54c96f1 176
23324ae1
FM
177/**
178 @class wxGraphicsObject
7c913512 179
23324ae1
FM
180 This class is the superclass of native graphics objects like pens etc. It
181 allows reference counting. Not instantiated by user code.
7c913512 182
23324ae1 183 @library{wxcore}
23d291c2 184 @category{gdi}
7c913512 185
e54c96f1 186 @see wxGraphicsBrush, wxGraphicsPen, wxGraphicsMatrix, wxGraphicsPath
23324ae1
FM
187*/
188class wxGraphicsObject : public wxObject
189{
190public:
191 /**
23d291c2
BP
192 Returns the renderer that was used to create this instance, or @NULL
193 if it has not been initialized yet.
23324ae1 194 */
328f5751 195 wxGraphicsRenderer* GetRenderer() const;
23324ae1
FM
196
197 /**
23d291c2 198 @return @false if this object is valid, otherwise returns @true.
23324ae1 199 */
328f5751 200 bool IsNull() const;
23324ae1
FM
201};
202
7395c7d6 203/**
ffc78010 204 Anti-aliasing modes used by wxGraphicsContext::SetAntialiasMode().
7395c7d6
SC
205*/
206enum wxAntialiasMode
207{
208 /** No anti-aliasing */
4ee4c7b9
VZ
209 wxANTIALIAS_NONE,
210
7395c7d6
SC
211 /** The default anti-aliasing */
212 wxANTIALIAS_DEFAULT,
213};
214
215/**
4ee4c7b9 216 Compositing is done using Porter-Duff compositions
7395c7d6 217 (see http://keithp.com/~keithp/porterduff/p253-porter.pdf) with
ffc78010 218 wxGraphicsContext::SetCompositionMode().
7395c7d6
SC
219
220 The description give a short equation on how the values of a resulting
221 pixel are calculated.
ec3110ae
SC
222 @e R = Result, @e S = Source, @e D = Destination, colors premultiplied with alpha
223 @e Ra, @e Sa, @e Da their alpha components
7395c7d6
SC
224*/
225enum wxCompositionMode
226{
ec3110ae
SC
227 wxCOMPOSITION_CLEAR, /**< @e R = 0 */
228 wxCOMPOSITION_SOURCE, /**< @e R = S */
229 wxCOMPOSITION_OVER, /**< @e R = @e S + @e D*(1 - @e Sa) */
230 wxCOMPOSITION_IN, /**< @e R = @e S*@e Da */
231 wxCOMPOSITION_OUT, /**< @e R = @e S*(1 - @e Da) */
232 wxCOMPOSITION_ATOP, /**< @e R = @e S*@e Da + @e D*(1 - @e Sa) */
233
234 wxCOMPOSITION_DEST, /**< @e R = @e D, essentially a noop */
235 wxCOMPOSITION_DEST_OVER, /**< @e R = @e S*(1 - @e Da) + @e D */
236 wxCOMPOSITION_DEST_IN, /**< @e R = @e D*@e Sa */
237 wxCOMPOSITION_DEST_OUT, /**< @e R = @e D*(1 - @e Sa) */
238 wxCOMPOSITION_DEST_ATOP, /**< @e R = @e S*(1 - @e Da) + @e D*@e Sa */
239 wxCOMPOSITION_XOR, /**< @e R = @e S*(1 - @e Da) + @e D*(1 - @e Sa) */
240 wxCOMPOSITION_ADD, /**< @e R = @e S + @e D */
7395c7d6 241};
23324ae1 242
e54c96f1 243
23324ae1
FM
244/**
245 @class wxGraphicsContext
7c913512 246
9cc4ab85
BP
247 A wxGraphicsContext instance is the object that is drawn upon. It is
248 created by a renderer using wxGraphicsRenderer::CreateContext(). This can
249 be either directly using a renderer instance, or indirectly using the
250 static convenience Create() functions of wxGraphicsContext that always
251 delegate the task to the default renderer.
7c913512 252
d974a494
RR
253 @code
254 void MyCanvas::OnPaint(wxPaintEvent &event)
255 {
256 // Create paint DC
257 wxPaintDC dc(this);
23d291c2 258
d974a494 259 // Create graphics context from it
ea077571 260 wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
23d291c2 261
7e38ae60
RR
262 if (gc)
263 {
0b822969 264 // make a path that contains a circle and some lines
7e38ae60
RR
265 gc->SetPen( *wxRED_PEN );
266 wxGraphicsPath path = gc->CreatePath();
267 path.AddCircle( 50.0, 50.0, 50.0 );
268 path.MoveToPoint(0.0, 50.0);
269 path.AddLineToPoint(100.0, 50.0);
270 path.MoveToPoint(50.0, 0.0);
271 path.AddLineToPoint(50.0, 100.0 );
272 path.CloseSubpath();
273 path.AddRectangle(25.0, 25.0, 50.0, 50.0);
23d291c2 274
ea077571 275 gc->StrokePath(path);
23d291c2 276
ea077571 277 delete gc;
7e38ae60
RR
278 }
279 }
d974a494
RR
280 @endcode
281
23324ae1 282 @library{wxcore}
23d291c2 283 @category{gdi,dc}
7c913512 284
6d99a337 285 @see wxGraphicsRenderer::CreateContext(), wxGCDC, wxDC
23324ae1
FM
286*/
287class wxGraphicsContext : public wxGraphicsObject
288{
289public:
23324ae1 290 /**
0b822969
RR
291 Creates a wxGraphicsContext from a wxWindow.
292
293 @see wxGraphicsRenderer::CreateContext()
294 */
9cc4ab85 295 static wxGraphicsContext* Create(wxWindow* window);
23d291c2 296
0b822969
RR
297 /**
298 Creates a wxGraphicsContext from a wxWindowDC
299
300 @see wxGraphicsRenderer::CreateContext()
301 */
9cc4ab85 302 static wxGraphicsContext* Create(const wxWindowDC& dc);
23d291c2 303
0b822969
RR
304 /**
305 Creates a wxGraphicsContext from a wxMemoryDC
306
307 @see wxGraphicsRenderer::CreateContext()
308 */
9cc4ab85 309 static wxGraphicsContext* Create(const wxMemoryDC& dc);
23d291c2 310
0b822969 311 /**
9cc4ab85
BP
312 Creates a wxGraphicsContext from a wxPrinterDC. Under GTK+, this will
313 only work when using the GtkPrint printing backend which is available
314 since GTK+ 2.10.
0b822969 315
9cc4ab85 316 @see wxGraphicsRenderer::CreateContext(), @ref overview_unixprinting
0b822969 317 */
9cc4ab85 318 static wxGraphicsContext* Create(const wxPrinterDC& dc);
0b822969
RR
319
320 /**
9cc4ab85 321 Clips drawings to the specified region.
23324ae1 322 */
da1ed74c 323 virtual void Clip(const wxRegion& region) = 0;
0b822969
RR
324
325 /**
9cc4ab85 326 Clips drawings to the specified rectangle.
0b822969 327 */
da1ed74c 328 virtual void Clip(wxDouble x, wxDouble y, wxDouble w, wxDouble h) = 0;
23324ae1
FM
329
330 /**
9cc4ab85
BP
331 Concatenates the passed in transform with the current transform of this
332 context.
23324ae1 333 */
da1ed74c 334 virtual void ConcatTransform(const wxGraphicsMatrix& matrix) = 0;
23324ae1 335
23324ae1
FM
336 /**
337 Creates a native brush from a wxBrush.
338 */
da1ed74c 339 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush) const;
23324ae1
FM
340
341 /**
342 Creates a native graphics font from a wxFont and a text colour.
343 */
5267aefd
FM
344 virtual wxGraphicsFont CreateFont(const wxFont& font,
345 const wxColour& col = *wxBLACK) const;
23324ae1
FM
346
347 /**
9cc4ab85
BP
348 Creates a wxGraphicsContext from a native context. This native context
349 must be a CGContextRef for Core Graphics, a Graphics pointer for
350 GDIPlus, or a cairo_t pointer for cairo.
3c4f71cc 351
9cc4ab85 352 @see wxGraphicsRenderer::CreateContextFromNativeContext()
23324ae1 353 */
da1ed74c 354 static wxGraphicsContext* CreateFromNative(void* context);
23324ae1
FM
355
356 /**
19e496b6
RR
357 Creates a wxGraphicsContext from a native window.
358
9cc4ab85 359 @see wxGraphicsRenderer::CreateContextFromNativeWindow()
23324ae1 360 */
da1ed74c 361 static wxGraphicsContext* CreateFromNativeWindow(void* window);
23324ae1
FM
362
363 /**
4ee4c7b9
VZ
364 Creates a native brush with a linear gradient.
365
366 The brush starts at (@a x1, @a y1) and ends at (@a x2, @a y2). Either
367 just the start and end gradient colours (@a c1 and @a c2) or full set
368 of gradient @a stops can be specified.
369
370 The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.
23324ae1 371 */
4ee4c7b9
VZ
372 //@{
373 wxGraphicsBrush
374 CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
375 wxDouble x2, wxDouble y2,
376 const wxColour& c1, const wxColour& c2) const;
377
378 wxGraphicsBrush
379 CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
380 wxDouble x2, wxDouble y2,
381 const wxGraphicsGradientStops& stops) const;
382 //@}
23324ae1
FM
383
384 /**
9cc4ab85
BP
385 Creates a native affine transformation matrix from the passed in
386 values. The default parameters result in an identity matrix.
23324ae1 387 */
5267aefd
FM
388 virtual wxGraphicsMatrix CreateMatrix(wxDouble a = 1.0, wxDouble b = 0.0,
389 wxDouble c = 0.0, wxDouble d = 1.0,
a44f3b5a
FM
390 wxDouble tx = 0.0,
391 wxDouble ty = 0.0) const;
23324ae1
FM
392
393 /**
394 Creates a native graphics path which is initially empty.
395 */
328f5751 396 wxGraphicsPath CreatePath() const;
23324ae1
FM
397
398 /**
399 Creates a native pen from a wxPen.
400 */
da1ed74c 401 virtual wxGraphicsPen CreatePen(const wxPen& pen) const;
23324ae1
FM
402
403 /**
4ee4c7b9
VZ
404 Creates a native brush with a radial gradient.
405
d13b34d3 406 The brush originates at (@a xo, @a yc) and ends on a circle around
4ee4c7b9
VZ
407 (@a xc, @a yc) with the given @a radius.
408
409 The gradient may be specified either by its start and end colours @a
410 oColor and @a cColor or by a full set of gradient @a stops.
411
412 The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.
23324ae1 413 */
4ee4c7b9
VZ
414 //@{
415 virtual wxGraphicsBrush
416 CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
417 wxDouble xc, wxDouble yc,
418 wxDouble radius,
419 const wxColour& oColor,
420 const wxColour& cColor) const;
421
422 virtual wxGraphicsBrush
423 CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
424 wxDouble xc, wxDouble yc,
425 wxDouble radius,
426 const wxGraphicsGradientStops& stops) = 0;
427 //@}
23324ae1
FM
428
429 /**
9cc4ab85
BP
430 Draws the bitmap. In case of a mono bitmap, this is treated as a mask
431 and the current brushed is used for filling.
23324ae1 432 */
fadc2df6
FM
433 virtual void DrawBitmap(const wxBitmap& bmp, wxDouble x, wxDouble y,
434 wxDouble w, wxDouble h) = 0;
23324ae1
FM
435
436 /**
437 Draws an ellipse.
438 */
da1ed74c 439 virtual void DrawEllipse(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
23324ae1
FM
440
441 /**
442 Draws the icon.
443 */
fadc2df6
FM
444 virtual void DrawIcon(const wxIcon& icon, wxDouble x, wxDouble y,
445 wxDouble w, wxDouble h) = 0;
23324ae1
FM
446
447 /**
448 Draws a polygon.
449 */
fadc2df6 450 virtual void DrawLines(size_t n, const wxPoint2DDouble* points,
382f12e4 451 wxPolygonFillMode fillStyle = wxODDEVEN_RULE);
23324ae1
FM
452
453 /**
454 Draws the path by first filling and then stroking.
455 */
fadc2df6 456 virtual void DrawPath(const wxGraphicsPath& path,
382f12e4 457 wxPolygonFillMode fillStyle = wxODDEVEN_RULE);
23324ae1
FM
458
459 /**
460 Draws a rectangle.
461 */
fadc2df6 462 virtual void DrawRectangle(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
23324ae1
FM
463
464 /**
465 Draws a rounded rectangle.
466 */
da1ed74c
FM
467 virtual void DrawRoundedRectangle(wxDouble x, wxDouble y, wxDouble w,
468 wxDouble h, wxDouble radius);
23324ae1 469
23324ae1 470 /**
9cc4ab85 471 Draws text at the defined position.
23324ae1 472 */
7c913512 473 void DrawText(const wxString& str, wxDouble x, wxDouble y);
9cc4ab85
BP
474 /**
475 Draws text at the defined position.
476
cbd251ac
BP
477 @param str
478 The text to draw.
479 @param x
480 The x coordinate position to draw the text at.
481 @param y
482 The y coordinate position to draw the text at.
9cc4ab85
BP
483 @param angle
484 The angle relative to the (default) horizontal direction to draw
485 the string.
486 */
487 void DrawText(const wxString& str, wxDouble x, wxDouble y, wxDouble angle);
488 /**
489 Draws text at the defined position.
490
cbd251ac
BP
491 @param str
492 The text to draw.
493 @param x
494 The x coordinate position to draw the text at.
495 @param y
496 The y coordinate position to draw the text at.
9cc4ab85
BP
497 @param backgroundBrush
498 Brush to fill the text with.
499 */
5a395566 500 void DrawText(const wxString& str, wxDouble x, wxDouble y,
9cc4ab85
BP
501 const wxGraphicsBrush& backgroundBrush);
502 /**
503 Draws text at the defined position.
504
cbd251ac
BP
505 @param str
506 The text to draw.
507 @param x
508 The x coordinate position to draw the text at.
509 @param y
510 The y coordinate position to draw the text at.
9cc4ab85
BP
511 @param angle
512 The angle relative to the (default) horizontal direction to draw
513 the string.
514 @param backgroundBrush
515 Brush to fill the text with.
516 */
5a395566 517 void DrawText(const wxString& str, wxDouble x, wxDouble y,
9cc4ab85 518 wxDouble angle, const wxGraphicsBrush& backgroundBrush);
23324ae1
FM
519
520 /**
521 Fills the path with the current brush.
522 */
fadc2df6 523 virtual void FillPath(const wxGraphicsPath& path,
382f12e4 524 wxPolygonFillMode fillStyle = wxODDEVEN_RULE) = 0;
23324ae1
FM
525
526 /**
9cc4ab85
BP
527 Returns the native context (CGContextRef for Core Graphics, Graphics
528 pointer for GDIPlus and cairo_t pointer for cairo).
23324ae1 529 */
da1ed74c 530 virtual void* GetNativeContext() = 0;
23324ae1
FM
531
532 /**
4cc4bfaf 533 Fills the @a widths array with the widths from the beginning of
9cc4ab85 534 @a text to the corresponding character of @a text.
23324ae1 535 */
fadc2df6
FM
536 virtual void GetPartialTextExtents(const wxString& text,
537 wxArrayDouble& widths) const = 0;
23324ae1
FM
538
539 /**
540 Gets the dimensions of the string using the currently selected font.
9cc4ab85
BP
541
542 @param text
543 The text string to measure.
544 @param width
545 Variable to store the total calculated width of the text.
546 @param height
547 Variable to store the total calculated height of the text.
548 @param descent
549 Variable to store the dimension from the baseline of the font to
550 the bottom of the descender.
551 @param externalLeading
552 Any extra vertical space added to the font by the font designer
553 (usually is zero).
23324ae1 554 */
da1ed74c
FM
555 virtual void GetTextExtent(const wxString& text, wxDouble* width,
556 wxDouble* height, wxDouble* descent,
557 wxDouble* externalLeading) const = 0;
23324ae1
FM
558
559 /**
560 Gets the current transformation matrix of this context.
561 */
da1ed74c 562 virtual wxGraphicsMatrix GetTransform() const = 0;
23324ae1
FM
563
564 /**
565 Resets the clipping to original shape.
566 */
da1ed74c 567 virtual void ResetClip() = 0;
23324ae1
FM
568
569 /**
9cc4ab85 570 Rotates the current transformation matrix (in radians).
23324ae1 571 */
da1ed74c 572 virtual void Rotate(wxDouble angle) = 0;
23324ae1
FM
573
574 /**
575 Scales the current transformation matrix.
576 */
da1ed74c 577 virtual void Scale(wxDouble xScale, wxDouble yScale) = 0;
23324ae1 578
23324ae1
FM
579 /**
580 Sets the brush for filling paths.
581 */
582 void SetBrush(const wxBrush& brush);
9cc4ab85
BP
583 /**
584 Sets the brush for filling paths.
585 */
ccf39540 586 virtual void SetBrush(const wxGraphicsBrush& brush);
23324ae1 587
23324ae1
FM
588 /**
589 Sets the font for drawing text.
590 */
591 void SetFont(const wxFont& font, const wxColour& colour);
9cc4ab85
BP
592 /**
593 Sets the font for drawing text.
594 */
ccf39540 595 virtual void SetFont(const wxGraphicsFont& font);
23324ae1 596
23324ae1
FM
597 /**
598 Sets the pen used for stroking.
599 */
ccf39540 600 void SetPen(const wxPen& pen);
9cc4ab85
BP
601 /**
602 Sets the pen used for stroking.
603 */
ccf39540 604 virtual void SetPen(const wxGraphicsPen& pen);
23324ae1
FM
605
606 /**
607 Sets the current transformation matrix of this context
608 */
da1ed74c 609 virtual void SetTransform(const wxGraphicsMatrix& matrix) = 0;
23324ae1
FM
610
611 /**
612 Strokes a single line.
613 */
fadc2df6 614 virtual void StrokeLine(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2);
23324ae1 615
23324ae1 616 /**
9cc4ab85
BP
617 Stroke disconnected lines from begin to end points, fastest method
618 available for this purpose.
23324ae1 619 */
ccf39540
FM
620 virtual void StrokeLines(size_t n, const wxPoint2DDouble* beginPoints,
621 const wxPoint2DDouble* endPoints);
9cc4ab85 622 /**
25941fc5
VZ
623 Stroke lines connecting all the points.
624
625 Unlike the other overload of this function, this method draws a single
626 polyline and not a number of disconnected lines.
9cc4ab85 627 */
ccf39540 628 virtual void StrokeLines(size_t n, const wxPoint2DDouble* points);
23324ae1
FM
629
630 /**
631 Strokes along a path with the current pen.
632 */
da1ed74c 633 virtual void StrokePath(const wxGraphicsPath& path) = 0;
23324ae1
FM
634
635 /**
636 Translates the current transformation matrix.
637 */
da1ed74c 638 virtual void Translate(wxDouble dx, wxDouble dy) = 0;
7395c7d6
SC
639
640 /**
4ee4c7b9 641 Redirects all rendering is done into a fully transparent temporary context
7395c7d6
SC
642 */
643 virtual void BeginLayer(wxDouble opacity) = 0;
644
4ee4c7b9
VZ
645 /**
646 Composites back the drawings into the context with the opacity given at
7395c7d6
SC
647 the BeginLayer call
648 */
649 virtual void EndLayer() = 0;
650
4ee4c7b9 651 /**
7395c7d6
SC
652 Sets the antialiasing mode, returns true if it supported
653 */
654 virtual bool SetAntialiasMode(wxAntialiasMode antialias) = 0;
655
4ee4c7b9 656 /**
7395c7d6
SC
657 Returns the current shape antialiasing mode
658 */
659 virtual wxAntialiasMode GetAntialiasMode() const ;
4ee4c7b9 660
7395c7d6
SC
661 /**
662 Sets the compositing operator, returns true if it supported
663 */
664 virtual bool SetCompositionMode(wxCompositionMode op) = 0;
665
4ee4c7b9 666 /**
7395c7d6
SC
667 Returns the current compositing operator
668 */
669 virtual wxCompositionMode GetCompositionMode() const;
4ee4c7b9
VZ
670
671};
672
673/**
674 Represents a single gradient stop in a collection of gradient stops as
675 represented by wxGraphicsGradientStops.
676
677 @library{wxcore}
678 @category{gdi}
679
680 @since 2.9.1
681*/
682class wxGraphicsGradientStop
683{
684public:
685 /**
686 Creates a stop with the given colour and position.
687
688 @param col The colour of this stop. Note that the alpha component of
689 the colour is honoured thus allowing the background colours to
690 partially show through the gradient.
2028c33a
VZ
691 @param pos The stop position, must be in [0, 1] range with 0 being the
692 beginning and 1 the end of the gradient.
4ee4c7b9 693 */
2028c33a 694 wxGraphicsGradientStop(wxColour col = wxTransparentColour, float pos = 0.);
4ee4c7b9
VZ
695
696 /// Return the stop colour.
697 const wxColour& GetColour() const;
698
699 /**
700 Change the stop colour.
701
702 @param col The new colour.
703 */
704 void SetColour(const wxColour& col);
705
706 /// Return the stop position.
707 float GetPosition() const;
708
709 /**
710 Change the stop position.
711
2028c33a 712 @param pos The new position, must always be in [0, 1] range.
4ee4c7b9
VZ
713 */
714 void SetPosition(float pos);
23324ae1
FM
715};
716
4ee4c7b9
VZ
717/**
718 Represents a collection of wxGraphicGradientStop values for use with
719 CreateLinearGradientBrush and CreateRadialGradientBrush.
720
721 The stops are maintained in order of position. If two or more stops are
722 added with the same position then the one(s) added later come later.
723 This can be useful for producing discontinuities in the colour gradient.
724
725 Notice that this class is write-once, you can't modify the stops once they
726 had been added.
727
728 @library{wxcore}
729 @category{gdi}
730
731 @since 2.9.1
732*/
733class wxGraphicsGradientStops
734{
735public:
736 /**
737 Initializes the gradient stops with the given boundary colours.
738
739 Creates a wxGraphicsGradientStops instance with start colour given
740 by @a startCol and end colour given by @a endCol.
741 */
742 wxGraphicsGradientStops(wxColour startCol = wxTransparentColour,
743 wxColour endCol = wxTransparentColour);
23324ae1 744
4ee4c7b9
VZ
745 /**
746 Add a new stop.
747 */
748 //@{
749 void Add(const wxGraphicsGradientStop& stop);
750 void Add(wxColour col, float pos);
751 //@}
752
753 /**
754 Returns the stop at the given index.
755
756 @param n The index, must be in [0, GetCount()) range.
757 */
758 wxGraphicsGradientStop Item(unsigned n) const;
759
760 /**
761 Returns the number of stops.
762 */
763 unsigned GetCount() const;
764
765 /**
766 Set the start colour to @a col
767 */
768 void SetStartColour(wxColour col);
769
770 /**
771 Returns the start colour.
772 */
773 wxColour GetStartColour() const;
774
775 /**
776 Set the end colour to @a col
777 */
778 void SetEndColour(wxColour col);
779
780 /**
781 Returns the end colour.
782 */
783 wxColour GetEndColour() const;
784};
e54c96f1 785
23324ae1
FM
786/**
787 @class wxGraphicsRenderer
7c913512 788
23324ae1 789 A wxGraphicsRenderer is the instance corresponding to the rendering engine
ea077571 790 used. There may be multiple instances on a system, if there are different
9cc4ab85
BP
791 rendering engines present, but there is always only one instance per
792 engine. This instance is pointed back to by all objects created by it
793 (wxGraphicsContext, wxGraphicsPath etc) and can be retrieved through their
794 wxGraphicsObject::GetRenderer() method. Therefore you can create an
795 additional instance of a path etc. by calling
796 wxGraphicsObject::GetRenderer() and then using the appropriate CreateXXX()
797 function of that renderer.
ea077571
RR
798
799 @code
800 wxGraphicsPath *path = // from somewhere
801 wxGraphicsBrush *brush = path->GetRenderer()->CreateBrush( *wxBLACK_BRUSH );
802 @endcode
7c913512 803
23324ae1 804 @library{wxcore}
9cc4ab85 805 @category{gdi}
23324ae1
FM
806*/
807class wxGraphicsRenderer : public wxObject
808{
809public:
810 /**
ea077571 811 Creates a wxGraphicsContext from a wxWindow.
23324ae1 812 */
ea077571 813 virtual wxGraphicsContext* CreateContext(wxWindow* window) = 0;
23d291c2 814
ea077571
RR
815 /**
816 Creates a wxGraphicsContext from a wxWindowDC
817 */
9cc4ab85 818 virtual wxGraphicsContext* CreateContext(const wxWindowDC& dc) = 0 ;
23d291c2 819
ea077571
RR
820 /**
821 Creates a wxGraphicsContext from a wxMemoryDC
822 */
9cc4ab85 823 virtual wxGraphicsContext* CreateContext(const wxMemoryDC& dc) = 0 ;
23d291c2 824
ea077571
RR
825 /**
826 Creates a wxGraphicsContext from a wxPrinterDC
827 */
9cc4ab85 828 virtual wxGraphicsContext* CreateContext(const wxPrinterDC& dc) = 0 ;
23324ae1 829
23324ae1 830 /**
ea077571 831 Creates a native brush from a wxBrush.
23324ae1 832 */
da1ed74c 833 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush) = 0;
ea077571 834
23324ae1 835 /**
9cc4ab85
BP
836 Creates a wxGraphicsContext from a native context. This native context
837 must be a CGContextRef for Core Graphics, a Graphics pointer for
838 GDIPlus, or a cairo_t pointer for cairo.
23324ae1 839 */
da1ed74c 840 virtual wxGraphicsContext* CreateContextFromNativeContext(void* context) = 0;
23324ae1
FM
841
842 /**
843 Creates a wxGraphicsContext from a native window.
844 */
da1ed74c 845 virtual wxGraphicsContext* CreateContextFromNativeWindow(void* window) = 0;
23324ae1 846
27a3b24b 847 /**
4ee4c7b9 848 Creates a wxGraphicsContext that can be used for measuring texts only.
27a3b24b
KO
849 No drawing commands are allowed.
850 */
851 virtual wxGraphicsContext * CreateMeasuringContext() = 0;
852
23324ae1
FM
853 /**
854 Creates a native graphics font from a wxFont and a text colour.
855 */
5267aefd
FM
856 virtual wxGraphicsFont CreateFont(const wxFont& font,
857 const wxColour& col = *wxBLACK) = 0;
23324ae1 858
4ee4c7b9 859
23324ae1 860 /**
4ee4c7b9
VZ
861 Creates a native brush with a linear gradient.
862
863 Stops support is new since wxWidgets 2.9.1, previously only the start
864 and end colours could be specified.
23324ae1 865 */
9cc4ab85
BP
866 virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1,
867 wxDouble y1,
868 wxDouble x2,
869 wxDouble y2,
4ee4c7b9 870 const wxGraphicsGradientStops& stops) = 0;
23324ae1
FM
871
872 /**
9cc4ab85
BP
873 Creates a native affine transformation matrix from the passed in
874 values. The defaults result in an identity matrix.
23324ae1 875 */
5267aefd
FM
876 virtual wxGraphicsMatrix CreateMatrix(wxDouble a = 1.0, wxDouble b = 0.0,
877 wxDouble c = 0.0, wxDouble d = 1.0,
a44f3b5a 878 wxDouble tx = 0.0,
5267aefd 879 wxDouble ty = 0.0) = 0;
23324ae1
FM
880
881 /**
882 Creates a native graphics path which is initially empty.
883 */
da1ed74c 884 virtual wxGraphicsPath CreatePath() = 0;
23324ae1
FM
885
886 /**
887 Creates a native pen from a wxPen.
888 */
da1ed74c 889 virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0;
23324ae1
FM
890
891 /**
4ee4c7b9
VZ
892 Creates a native brush with a radial gradient.
893
894 Stops support is new since wxWidgets 2.9.1, previously only the start
895 and end colours could be specified.
23324ae1 896 */
da1ed74c
FM
897 virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
898 wxDouble xc, wxDouble yc,
899 wxDouble radius,
4ee4c7b9 900 const wxGraphicsGradientStops& stops) = 0;
23324ae1
FM
901
902 /**
903 Returns the default renderer on this platform. On OS X this is the Core
9cc4ab85
BP
904 Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and
905 on GTK we currently default to the cairo renderer.
23324ae1 906 */
ea077571 907 static wxGraphicsRenderer* GetDefaultRenderer();
23324ae1
FM
908};
909
910
e54c96f1 911
23324ae1
FM
912/**
913 @class wxGraphicsBrush
7c913512 914
9cc4ab85
BP
915 A wxGraphicsBrush is a native representation of a brush. The contents are
916 specific and private to the respective renderer. Instances are ref counted
917 and can therefore be assigned as usual. The only way to get a valid
918 instance is via wxGraphicsContext::CreateBrush() or
919 wxGraphicsRenderer::CreateBrush().
7c913512 920
23324ae1 921 @library{wxcore}
9cc4ab85 922 @category{gdi}
23324ae1
FM
923*/
924class wxGraphicsBrush : public wxGraphicsObject
925{
926public:
7c913512 927
23324ae1
FM
928};
929
930
e54c96f1 931
23324ae1
FM
932/**
933 @class wxGraphicsFont
7c913512 934
9cc4ab85
BP
935 A wxGraphicsFont is a native representation of a font. The contents are
936 specific and private to the respective renderer. Instances are ref counted
937 and can therefore be assigned as usual. The only way to get a valid
938 instance is via wxGraphicsContext::CreateFont() or
939 wxGraphicsRenderer::CreateFont().
7c913512 940
23324ae1 941 @library{wxcore}
9cc4ab85 942 @category{gdi}
23324ae1
FM
943*/
944class wxGraphicsFont : public wxGraphicsObject
945{
946public:
7c913512 947
23324ae1
FM
948};
949
950
e54c96f1 951
23324ae1
FM
952/**
953 @class wxGraphicsPen
7c913512 954
9cc4ab85
BP
955 A wxGraphicsPen is a native representation of a pen. The contents are
956 specific and private to the respective renderer. Instances are ref counted
957 and can therefore be assigned as usual. The only way to get a valid
958 instance is via wxGraphicsContext::CreatePen() or
959 wxGraphicsRenderer::CreatePen().
7c913512 960
23324ae1 961 @library{wxcore}
9cc4ab85 962 @category{gdi}
23324ae1
FM
963*/
964class wxGraphicsPen : public wxGraphicsObject
965{
966public:
7c913512 967
23324ae1
FM
968};
969
970
e54c96f1 971
23324ae1
FM
972/**
973 @class wxGraphicsMatrix
7c913512 974
9cc4ab85
BP
975 A wxGraphicsMatrix is a native representation of an affine matrix. The
976 contents are specific and private to the respective renderer. Instances are
977 ref counted and can therefore be assigned as usual. The only way to get a
978 valid instance is via wxGraphicsContext::CreateMatrix() or
979 wxGraphicsRenderer::CreateMatrix().
7c913512 980
23324ae1 981 @library{wxcore}
9cc4ab85 982 @category{gdi}
23324ae1
FM
983*/
984class wxGraphicsMatrix : public wxGraphicsObject
985{
986public:
23324ae1 987 /**
9cc4ab85
BP
988 Concatenates the matrix passed with the current matrix.
989 */
990 virtual void Concat(const wxGraphicsMatrix* t);
991 /**
992 Concatenates the matrix passed with the current matrix.
23324ae1 993 */
7c913512 994 void Concat(const wxGraphicsMatrix& t);
23324ae1
FM
995
996 /**
997 Returns the component values of the matrix via the argument pointers.
998 */
9cc4ab85
BP
999 virtual void Get(wxDouble* a = NULL, wxDouble* b = NULL,
1000 wxDouble* c = NULL, wxDouble* d = NULL,
1001 wxDouble* tx = NULL, wxDouble* ty = NULL) const;
23324ae1
FM
1002
1003 /**
9cc4ab85
BP
1004 Returns the native representation of the matrix. For CoreGraphics this
1005 is a CFAffineMatrix pointer, for GDIPlus a Matrix Pointer, and for
1006 Cairo a cairo_matrix_t pointer.
23324ae1 1007 */
da1ed74c 1008 virtual void* GetNativeMatrix() const;
23324ae1
FM
1009
1010 /**
1011 Inverts the matrix.
1012 */
da1ed74c 1013 virtual void Invert();
23324ae1 1014
9cc4ab85
BP
1015 /**
1016 Returns @true if the elements of the transformation matrix are equal.
1017 */
1018 virtual bool IsEqual(const wxGraphicsMatrix* t) const;
23324ae1
FM
1019 /**
1020 Returns @true if the elements of the transformation matrix are equal.
1021 */
328f5751 1022 bool IsEqual(const wxGraphicsMatrix& t) const;
23324ae1
FM
1023
1024 /**
1025 Return @true if this is the identity matrix.
1026 */
da1ed74c 1027 virtual bool IsIdentity() const;
23324ae1
FM
1028
1029 /**
9cc4ab85 1030 Rotates this matrix (in radians).
23324ae1 1031 */
da1ed74c 1032 virtual void Rotate(wxDouble angle);
23324ae1
FM
1033
1034 /**
1035 Scales this matrix.
1036 */
da1ed74c 1037 virtual void Scale(wxDouble xScale, wxDouble yScale);
23324ae1
FM
1038
1039 /**
9cc4ab85
BP
1040 Sets the matrix to the respective values (default values are the
1041 identity matrix).
23324ae1 1042 */
5267aefd
FM
1043 virtual void Set(wxDouble a = 1.0, wxDouble b = 0.0, wxDouble c = 0.0,
1044 wxDouble d = 1.0, wxDouble tx = 0.0, wxDouble ty = 0.0);
23324ae1
FM
1045
1046 /**
1047 Applies this matrix to a distance (ie. performs all transforms except
9cc4ab85 1048 translations).
23324ae1 1049 */
da1ed74c 1050 virtual void TransformDistance(wxDouble* dx, wxDouble* dy) const;
23324ae1
FM
1051
1052 /**
1053 Applies this matrix to a point.
1054 */
da1ed74c 1055 virtual void TransformPoint(wxDouble* x, wxDouble* y) const;
23324ae1
FM
1056
1057 /**
1058 Translates this matrix.
1059 */
da1ed74c 1060 virtual void Translate(wxDouble dx, wxDouble dy);
23324ae1 1061};
9cc4ab85 1062