]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/graphics.h
Add wxNavigationEnabled<> helper for implementing TAB navigation.
[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
a173c813
SC
215/**
216 Interpolation quality used by wxGraphicsContext::SetInterpolationQuality().
217 */
218enum wxInterpolationQuality
219{
3399af21
SC
220 /** default interpolation, based on type of context, in general medium quality */
221 wxINTERPOLATION_DEFAULT,
a173c813
SC
222 /** no interpolation */
223 wxINTERPOLATION_NONE,
224 /** fast interpolation, suited for interactivity */
225 wxINTERPOLATION_FAST,
226 /** better quality */
227 wxINTERPOLATION_GOOD,
228 /** best quality, not suited for interactivity */
229 wxINTERPOLATION_BEST
230};
231
7395c7d6 232/**
4ee4c7b9 233 Compositing is done using Porter-Duff compositions
7395c7d6 234 (see http://keithp.com/~keithp/porterduff/p253-porter.pdf) with
ffc78010 235 wxGraphicsContext::SetCompositionMode().
7395c7d6
SC
236
237 The description give a short equation on how the values of a resulting
238 pixel are calculated.
ec3110ae
SC
239 @e R = Result, @e S = Source, @e D = Destination, colors premultiplied with alpha
240 @e Ra, @e Sa, @e Da their alpha components
7395c7d6
SC
241*/
242enum wxCompositionMode
243{
fec4e458
VZ
244 /**
245 Indicates invalid or unsupported composition mode.
246
247 This value can't be passed to wxGraphicsContext::SetCompositionMode().
248
249 @since 2.9.2
250 */
251 wxCOMPOSITION_INVALID = -1,
ec3110ae
SC
252 wxCOMPOSITION_CLEAR, /**< @e R = 0 */
253 wxCOMPOSITION_SOURCE, /**< @e R = S */
254 wxCOMPOSITION_OVER, /**< @e R = @e S + @e D*(1 - @e Sa) */
255 wxCOMPOSITION_IN, /**< @e R = @e S*@e Da */
256 wxCOMPOSITION_OUT, /**< @e R = @e S*(1 - @e Da) */
257 wxCOMPOSITION_ATOP, /**< @e R = @e S*@e Da + @e D*(1 - @e Sa) */
258
259 wxCOMPOSITION_DEST, /**< @e R = @e D, essentially a noop */
260 wxCOMPOSITION_DEST_OVER, /**< @e R = @e S*(1 - @e Da) + @e D */
261 wxCOMPOSITION_DEST_IN, /**< @e R = @e D*@e Sa */
262 wxCOMPOSITION_DEST_OUT, /**< @e R = @e D*(1 - @e Sa) */
263 wxCOMPOSITION_DEST_ATOP, /**< @e R = @e S*(1 - @e Da) + @e D*@e Sa */
264 wxCOMPOSITION_XOR, /**< @e R = @e S*(1 - @e Da) + @e D*(1 - @e Sa) */
bbd783e0 265 wxCOMPOSITION_ADD /**< @e R = @e S + @e D */
7395c7d6 266};
23324ae1 267
e54c96f1 268
23324ae1
FM
269/**
270 @class wxGraphicsContext
7c913512 271
9cc4ab85
BP
272 A wxGraphicsContext instance is the object that is drawn upon. It is
273 created by a renderer using wxGraphicsRenderer::CreateContext(). This can
274 be either directly using a renderer instance, or indirectly using the
275 static convenience Create() functions of wxGraphicsContext that always
276 delegate the task to the default renderer.
7c913512 277
d974a494
RR
278 @code
279 void MyCanvas::OnPaint(wxPaintEvent &event)
280 {
281 // Create paint DC
282 wxPaintDC dc(this);
23d291c2 283
d974a494 284 // Create graphics context from it
ea077571 285 wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
23d291c2 286
7e38ae60
RR
287 if (gc)
288 {
0b822969 289 // make a path that contains a circle and some lines
7e38ae60
RR
290 gc->SetPen( *wxRED_PEN );
291 wxGraphicsPath path = gc->CreatePath();
292 path.AddCircle( 50.0, 50.0, 50.0 );
293 path.MoveToPoint(0.0, 50.0);
294 path.AddLineToPoint(100.0, 50.0);
295 path.MoveToPoint(50.0, 0.0);
296 path.AddLineToPoint(50.0, 100.0 );
297 path.CloseSubpath();
298 path.AddRectangle(25.0, 25.0, 50.0, 50.0);
23d291c2 299
ea077571 300 gc->StrokePath(path);
23d291c2 301
ea077571 302 delete gc;
7e38ae60
RR
303 }
304 }
d974a494
RR
305 @endcode
306
23324ae1 307 @library{wxcore}
23d291c2 308 @category{gdi,dc}
7c913512 309
6d99a337 310 @see wxGraphicsRenderer::CreateContext(), wxGCDC, wxDC
23324ae1
FM
311*/
312class wxGraphicsContext : public wxGraphicsObject
313{
314public:
23324ae1 315 /**
0b822969
RR
316 Creates a wxGraphicsContext from a wxWindow.
317
318 @see wxGraphicsRenderer::CreateContext()
319 */
9cc4ab85 320 static wxGraphicsContext* Create(wxWindow* window);
23d291c2 321
0b822969
RR
322 /**
323 Creates a wxGraphicsContext from a wxWindowDC
324
325 @see wxGraphicsRenderer::CreateContext()
326 */
9cc4ab85 327 static wxGraphicsContext* Create(const wxWindowDC& dc);
23d291c2 328
0b822969
RR
329 /**
330 Creates a wxGraphicsContext from a wxMemoryDC
331
332 @see wxGraphicsRenderer::CreateContext()
333 */
9cc4ab85 334 static wxGraphicsContext* Create(const wxMemoryDC& dc);
23d291c2 335
0b822969 336 /**
9cc4ab85
BP
337 Creates a wxGraphicsContext from a wxPrinterDC. Under GTK+, this will
338 only work when using the GtkPrint printing backend which is available
339 since GTK+ 2.10.
0b822969 340
9cc4ab85 341 @see wxGraphicsRenderer::CreateContext(), @ref overview_unixprinting
0b822969 342 */
9cc4ab85 343 static wxGraphicsContext* Create(const wxPrinterDC& dc);
0b822969 344
1bf9327b
VZ
345 /**
346 Creates a wxGraphicsContext from a wxEnhMetaFileDC.
347
348 This function, as wxEnhMetaFileDC class itself, is only available only
349 under MSW.
350
351 @see wxGraphicsRenderer::CreateContext()
352 */
353 static wxGraphicsContext* Create(const wxEnhMetaFileDC& dc);
354
0b822969 355 /**
9cc4ab85 356 Clips drawings to the specified region.
23324ae1 357 */
da1ed74c 358 virtual void Clip(const wxRegion& region) = 0;
0b822969
RR
359
360 /**
9cc4ab85 361 Clips drawings to the specified rectangle.
0b822969 362 */
da1ed74c 363 virtual void Clip(wxDouble x, wxDouble y, wxDouble w, wxDouble h) = 0;
23324ae1
FM
364
365 /**
9cc4ab85
BP
366 Concatenates the passed in transform with the current transform of this
367 context.
23324ae1 368 */
da1ed74c 369 virtual void ConcatTransform(const wxGraphicsMatrix& matrix) = 0;
23324ae1 370
23324ae1
FM
371 /**
372 Creates a native brush from a wxBrush.
373 */
da1ed74c 374 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush) const;
23324ae1
FM
375
376 /**
377 Creates a native graphics font from a wxFont and a text colour.
378 */
5267aefd
FM
379 virtual wxGraphicsFont CreateFont(const wxFont& font,
380 const wxColour& col = *wxBLACK) const;
23324ae1
FM
381
382 /**
9cc4ab85
BP
383 Creates a wxGraphicsContext from a native context. This native context
384 must be a CGContextRef for Core Graphics, a Graphics pointer for
385 GDIPlus, or a cairo_t pointer for cairo.
3c4f71cc 386
9cc4ab85 387 @see wxGraphicsRenderer::CreateContextFromNativeContext()
23324ae1 388 */
da1ed74c 389 static wxGraphicsContext* CreateFromNative(void* context);
23324ae1
FM
390
391 /**
19e496b6
RR
392 Creates a wxGraphicsContext from a native window.
393
9cc4ab85 394 @see wxGraphicsRenderer::CreateContextFromNativeWindow()
23324ae1 395 */
da1ed74c 396 static wxGraphicsContext* CreateFromNativeWindow(void* window);
23324ae1
FM
397
398 /**
4ee4c7b9
VZ
399 Creates a native brush with a linear gradient.
400
401 The brush starts at (@a x1, @a y1) and ends at (@a x2, @a y2). Either
402 just the start and end gradient colours (@a c1 and @a c2) or full set
403 of gradient @a stops can be specified.
404
405 The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.
23324ae1 406 */
4ee4c7b9
VZ
407 //@{
408 wxGraphicsBrush
409 CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
410 wxDouble x2, wxDouble y2,
411 const wxColour& c1, const wxColour& c2) const;
412
413 wxGraphicsBrush
414 CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
415 wxDouble x2, wxDouble y2,
416 const wxGraphicsGradientStops& stops) const;
417 //@}
23324ae1
FM
418
419 /**
9cc4ab85
BP
420 Creates a native affine transformation matrix from the passed in
421 values. The default parameters result in an identity matrix.
23324ae1 422 */
5267aefd
FM
423 virtual wxGraphicsMatrix CreateMatrix(wxDouble a = 1.0, wxDouble b = 0.0,
424 wxDouble c = 0.0, wxDouble d = 1.0,
a44f3b5a
FM
425 wxDouble tx = 0.0,
426 wxDouble ty = 0.0) const;
23324ae1
FM
427
428 /**
429 Creates a native graphics path which is initially empty.
430 */
328f5751 431 wxGraphicsPath CreatePath() const;
23324ae1
FM
432
433 /**
434 Creates a native pen from a wxPen.
435 */
da1ed74c 436 virtual wxGraphicsPen CreatePen(const wxPen& pen) const;
23324ae1
FM
437
438 /**
4ee4c7b9
VZ
439 Creates a native brush with a radial gradient.
440
d13b34d3 441 The brush originates at (@a xo, @a yc) and ends on a circle around
4ee4c7b9
VZ
442 (@a xc, @a yc) with the given @a radius.
443
444 The gradient may be specified either by its start and end colours @a
445 oColor and @a cColor or by a full set of gradient @a stops.
446
447 The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.
23324ae1 448 */
4ee4c7b9
VZ
449 //@{
450 virtual wxGraphicsBrush
451 CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
452 wxDouble xc, wxDouble yc,
453 wxDouble radius,
454 const wxColour& oColor,
455 const wxColour& cColor) const;
456
457 virtual wxGraphicsBrush
458 CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
459 wxDouble xc, wxDouble yc,
460 wxDouble radius,
461 const wxGraphicsGradientStops& stops) = 0;
462 //@}
23324ae1
FM
463
464 /**
9cc4ab85
BP
465 Draws the bitmap. In case of a mono bitmap, this is treated as a mask
466 and the current brushed is used for filling.
23324ae1 467 */
fadc2df6
FM
468 virtual void DrawBitmap(const wxBitmap& bmp, wxDouble x, wxDouble y,
469 wxDouble w, wxDouble h) = 0;
23324ae1
FM
470
471 /**
472 Draws an ellipse.
473 */
da1ed74c 474 virtual void DrawEllipse(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
23324ae1
FM
475
476 /**
477 Draws the icon.
478 */
fadc2df6
FM
479 virtual void DrawIcon(const wxIcon& icon, wxDouble x, wxDouble y,
480 wxDouble w, wxDouble h) = 0;
23324ae1
FM
481
482 /**
483 Draws a polygon.
484 */
fadc2df6 485 virtual void DrawLines(size_t n, const wxPoint2DDouble* points,
382f12e4 486 wxPolygonFillMode fillStyle = wxODDEVEN_RULE);
23324ae1
FM
487
488 /**
489 Draws the path by first filling and then stroking.
490 */
fadc2df6 491 virtual void DrawPath(const wxGraphicsPath& path,
382f12e4 492 wxPolygonFillMode fillStyle = wxODDEVEN_RULE);
23324ae1
FM
493
494 /**
495 Draws a rectangle.
496 */
fadc2df6 497 virtual void DrawRectangle(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
23324ae1
FM
498
499 /**
500 Draws a rounded rectangle.
501 */
da1ed74c
FM
502 virtual void DrawRoundedRectangle(wxDouble x, wxDouble y, wxDouble w,
503 wxDouble h, wxDouble radius);
23324ae1 504
23324ae1 505 /**
9cc4ab85 506 Draws text at the defined position.
23324ae1 507 */
7c913512 508 void DrawText(const wxString& str, wxDouble x, wxDouble y);
9cc4ab85
BP
509 /**
510 Draws text at the defined position.
511
cbd251ac
BP
512 @param str
513 The text to draw.
514 @param x
515 The x coordinate position to draw the text at.
516 @param y
517 The y coordinate position to draw the text at.
9cc4ab85
BP
518 @param angle
519 The angle relative to the (default) horizontal direction to draw
520 the string.
521 */
522 void DrawText(const wxString& str, wxDouble x, wxDouble y, wxDouble angle);
523 /**
524 Draws text at the defined position.
525
cbd251ac
BP
526 @param str
527 The text to draw.
528 @param x
529 The x coordinate position to draw the text at.
530 @param y
531 The y coordinate position to draw the text at.
9cc4ab85
BP
532 @param backgroundBrush
533 Brush to fill the text with.
534 */
5a395566 535 void DrawText(const wxString& str, wxDouble x, wxDouble y,
9cc4ab85
BP
536 const wxGraphicsBrush& backgroundBrush);
537 /**
538 Draws text at the defined position.
539
cbd251ac
BP
540 @param str
541 The text to draw.
542 @param x
543 The x coordinate position to draw the text at.
544 @param y
545 The y coordinate position to draw the text at.
9cc4ab85
BP
546 @param angle
547 The angle relative to the (default) horizontal direction to draw
548 the string.
549 @param backgroundBrush
550 Brush to fill the text with.
551 */
5a395566 552 void DrawText(const wxString& str, wxDouble x, wxDouble y,
9cc4ab85 553 wxDouble angle, const wxGraphicsBrush& backgroundBrush);
23324ae1
FM
554
555 /**
556 Fills the path with the current brush.
557 */
fadc2df6 558 virtual void FillPath(const wxGraphicsPath& path,
382f12e4 559 wxPolygonFillMode fillStyle = wxODDEVEN_RULE) = 0;
23324ae1
FM
560
561 /**
9cc4ab85
BP
562 Returns the native context (CGContextRef for Core Graphics, Graphics
563 pointer for GDIPlus and cairo_t pointer for cairo).
23324ae1 564 */
da1ed74c 565 virtual void* GetNativeContext() = 0;
23324ae1
FM
566
567 /**
4cc4bfaf 568 Fills the @a widths array with the widths from the beginning of
9cc4ab85 569 @a text to the corresponding character of @a text.
23324ae1 570 */
fadc2df6
FM
571 virtual void GetPartialTextExtents(const wxString& text,
572 wxArrayDouble& widths) const = 0;
23324ae1
FM
573
574 /**
575 Gets the dimensions of the string using the currently selected font.
9cc4ab85
BP
576
577 @param text
578 The text string to measure.
579 @param width
580 Variable to store the total calculated width of the text.
581 @param height
582 Variable to store the total calculated height of the text.
583 @param descent
584 Variable to store the dimension from the baseline of the font to
585 the bottom of the descender.
586 @param externalLeading
587 Any extra vertical space added to the font by the font designer
588 (usually is zero).
23324ae1 589 */
da1ed74c
FM
590 virtual void GetTextExtent(const wxString& text, wxDouble* width,
591 wxDouble* height, wxDouble* descent,
592 wxDouble* externalLeading) const = 0;
23324ae1
FM
593
594 /**
595 Gets the current transformation matrix of this context.
596 */
da1ed74c 597 virtual wxGraphicsMatrix GetTransform() const = 0;
23324ae1
FM
598
599 /**
600 Resets the clipping to original shape.
601 */
da1ed74c 602 virtual void ResetClip() = 0;
23324ae1
FM
603
604 /**
9cc4ab85 605 Rotates the current transformation matrix (in radians).
23324ae1 606 */
da1ed74c 607 virtual void Rotate(wxDouble angle) = 0;
23324ae1
FM
608
609 /**
610 Scales the current transformation matrix.
611 */
da1ed74c 612 virtual void Scale(wxDouble xScale, wxDouble yScale) = 0;
23324ae1 613
23324ae1
FM
614 /**
615 Sets the brush for filling paths.
616 */
617 void SetBrush(const wxBrush& brush);
9cc4ab85
BP
618 /**
619 Sets the brush for filling paths.
620 */
ccf39540 621 virtual void SetBrush(const wxGraphicsBrush& brush);
23324ae1 622
23324ae1
FM
623 /**
624 Sets the font for drawing text.
625 */
626 void SetFont(const wxFont& font, const wxColour& colour);
9cc4ab85
BP
627 /**
628 Sets the font for drawing text.
629 */
ccf39540 630 virtual void SetFont(const wxGraphicsFont& font);
23324ae1 631
23324ae1
FM
632 /**
633 Sets the pen used for stroking.
634 */
ccf39540 635 void SetPen(const wxPen& pen);
9cc4ab85
BP
636 /**
637 Sets the pen used for stroking.
638 */
ccf39540 639 virtual void SetPen(const wxGraphicsPen& pen);
23324ae1
FM
640
641 /**
642 Sets the current transformation matrix of this context
643 */
da1ed74c 644 virtual void SetTransform(const wxGraphicsMatrix& matrix) = 0;
23324ae1
FM
645
646 /**
647 Strokes a single line.
648 */
fadc2df6 649 virtual void StrokeLine(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2);
23324ae1 650
23324ae1 651 /**
9cc4ab85
BP
652 Stroke disconnected lines from begin to end points, fastest method
653 available for this purpose.
23324ae1 654 */
ccf39540
FM
655 virtual void StrokeLines(size_t n, const wxPoint2DDouble* beginPoints,
656 const wxPoint2DDouble* endPoints);
9cc4ab85 657 /**
25941fc5
VZ
658 Stroke lines connecting all the points.
659
660 Unlike the other overload of this function, this method draws a single
661 polyline and not a number of disconnected lines.
9cc4ab85 662 */
ccf39540 663 virtual void StrokeLines(size_t n, const wxPoint2DDouble* points);
23324ae1
FM
664
665 /**
666 Strokes along a path with the current pen.
667 */
da1ed74c 668 virtual void StrokePath(const wxGraphicsPath& path) = 0;
23324ae1
FM
669
670 /**
671 Translates the current transformation matrix.
672 */
da1ed74c 673 virtual void Translate(wxDouble dx, wxDouble dy) = 0;
7395c7d6
SC
674
675 /**
4ee4c7b9 676 Redirects all rendering is done into a fully transparent temporary context
7395c7d6
SC
677 */
678 virtual void BeginLayer(wxDouble opacity) = 0;
679
4ee4c7b9
VZ
680 /**
681 Composites back the drawings into the context with the opacity given at
7395c7d6
SC
682 the BeginLayer call
683 */
684 virtual void EndLayer() = 0;
685
4ee4c7b9 686 /**
7395c7d6
SC
687 Sets the antialiasing mode, returns true if it supported
688 */
689 virtual bool SetAntialiasMode(wxAntialiasMode antialias) = 0;
690
4ee4c7b9 691 /**
7395c7d6
SC
692 Returns the current shape antialiasing mode
693 */
694 virtual wxAntialiasMode GetAntialiasMode() const ;
4ee4c7b9 695
a173c813
SC
696 /**
697 Sets the interpolation quality, returns true if it supported
698 */
699 virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation) = 0;
700
701 /**
702 Returns the current interpolation quality
703 */
704 virtual wxInterpolationQuality GetInterpolationQuality() const;
705
7395c7d6
SC
706 /**
707 Sets the compositing operator, returns true if it supported
708 */
709 virtual bool SetCompositionMode(wxCompositionMode op) = 0;
710
4ee4c7b9 711 /**
7395c7d6
SC
712 Returns the current compositing operator
713 */
714 virtual wxCompositionMode GetCompositionMode() const;
4ee4c7b9
VZ
715
716};
717
718/**
719 Represents a single gradient stop in a collection of gradient stops as
720 represented by wxGraphicsGradientStops.
721
722 @library{wxcore}
723 @category{gdi}
724
725 @since 2.9.1
726*/
727class wxGraphicsGradientStop
728{
729public:
730 /**
731 Creates a stop with the given colour and position.
732
733 @param col The colour of this stop. Note that the alpha component of
734 the colour is honoured thus allowing the background colours to
735 partially show through the gradient.
2028c33a
VZ
736 @param pos The stop position, must be in [0, 1] range with 0 being the
737 beginning and 1 the end of the gradient.
4ee4c7b9 738 */
2028c33a 739 wxGraphicsGradientStop(wxColour col = wxTransparentColour, float pos = 0.);
4ee4c7b9
VZ
740
741 /// Return the stop colour.
742 const wxColour& GetColour() const;
743
744 /**
745 Change the stop colour.
746
747 @param col The new colour.
748 */
749 void SetColour(const wxColour& col);
750
751 /// Return the stop position.
752 float GetPosition() const;
753
754 /**
755 Change the stop position.
756
2028c33a 757 @param pos The new position, must always be in [0, 1] range.
4ee4c7b9
VZ
758 */
759 void SetPosition(float pos);
23324ae1
FM
760};
761
4ee4c7b9
VZ
762/**
763 Represents a collection of wxGraphicGradientStop values for use with
764 CreateLinearGradientBrush and CreateRadialGradientBrush.
765
766 The stops are maintained in order of position. If two or more stops are
767 added with the same position then the one(s) added later come later.
768 This can be useful for producing discontinuities in the colour gradient.
769
770 Notice that this class is write-once, you can't modify the stops once they
771 had been added.
772
773 @library{wxcore}
774 @category{gdi}
775
776 @since 2.9.1
777*/
778class wxGraphicsGradientStops
779{
780public:
781 /**
782 Initializes the gradient stops with the given boundary colours.
783
784 Creates a wxGraphicsGradientStops instance with start colour given
785 by @a startCol and end colour given by @a endCol.
786 */
787 wxGraphicsGradientStops(wxColour startCol = wxTransparentColour,
788 wxColour endCol = wxTransparentColour);
23324ae1 789
4ee4c7b9
VZ
790 /**
791 Add a new stop.
792 */
793 //@{
794 void Add(const wxGraphicsGradientStop& stop);
795 void Add(wxColour col, float pos);
796 //@}
797
798 /**
799 Returns the stop at the given index.
800
801 @param n The index, must be in [0, GetCount()) range.
802 */
803 wxGraphicsGradientStop Item(unsigned n) const;
804
805 /**
806 Returns the number of stops.
807 */
808 unsigned GetCount() const;
809
810 /**
811 Set the start colour to @a col
812 */
813 void SetStartColour(wxColour col);
814
815 /**
816 Returns the start colour.
817 */
818 wxColour GetStartColour() const;
819
820 /**
821 Set the end colour to @a col
822 */
823 void SetEndColour(wxColour col);
824
825 /**
826 Returns the end colour.
827 */
828 wxColour GetEndColour() const;
829};
e54c96f1 830
23324ae1
FM
831/**
832 @class wxGraphicsRenderer
7c913512 833
23324ae1 834 A wxGraphicsRenderer is the instance corresponding to the rendering engine
ea077571 835 used. There may be multiple instances on a system, if there are different
9cc4ab85
BP
836 rendering engines present, but there is always only one instance per
837 engine. This instance is pointed back to by all objects created by it
838 (wxGraphicsContext, wxGraphicsPath etc) and can be retrieved through their
839 wxGraphicsObject::GetRenderer() method. Therefore you can create an
840 additional instance of a path etc. by calling
841 wxGraphicsObject::GetRenderer() and then using the appropriate CreateXXX()
842 function of that renderer.
ea077571
RR
843
844 @code
845 wxGraphicsPath *path = // from somewhere
846 wxGraphicsBrush *brush = path->GetRenderer()->CreateBrush( *wxBLACK_BRUSH );
847 @endcode
7c913512 848
23324ae1 849 @library{wxcore}
9cc4ab85 850 @category{gdi}
23324ae1
FM
851*/
852class wxGraphicsRenderer : public wxObject
853{
854public:
855 /**
ea077571 856 Creates a wxGraphicsContext from a wxWindow.
23324ae1 857 */
ea077571 858 virtual wxGraphicsContext* CreateContext(wxWindow* window) = 0;
23d291c2 859
ea077571
RR
860 /**
861 Creates a wxGraphicsContext from a wxWindowDC
862 */
9cc4ab85 863 virtual wxGraphicsContext* CreateContext(const wxWindowDC& dc) = 0 ;
23d291c2 864
ea077571
RR
865 /**
866 Creates a wxGraphicsContext from a wxMemoryDC
867 */
9cc4ab85 868 virtual wxGraphicsContext* CreateContext(const wxMemoryDC& dc) = 0 ;
23d291c2 869
ea077571
RR
870 /**
871 Creates a wxGraphicsContext from a wxPrinterDC
872 */
9cc4ab85 873 virtual wxGraphicsContext* CreateContext(const wxPrinterDC& dc) = 0 ;
23324ae1 874
1bf9327b
VZ
875 /**
876 Creates a wxGraphicsContext from a wxEnhMetaFileDC.
877
878 This function, as wxEnhMetaFileDC class itself, is only available only
879 under MSW.
880 */
881 virtual wxGraphicsContext* CreateContext(const wxEnhMetaFileDC& dc) = 0;
882
23324ae1 883 /**
ea077571 884 Creates a native brush from a wxBrush.
23324ae1 885 */
da1ed74c 886 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush) = 0;
ea077571 887
23324ae1 888 /**
9cc4ab85
BP
889 Creates a wxGraphicsContext from a native context. This native context
890 must be a CGContextRef for Core Graphics, a Graphics pointer for
891 GDIPlus, or a cairo_t pointer for cairo.
23324ae1 892 */
da1ed74c 893 virtual wxGraphicsContext* CreateContextFromNativeContext(void* context) = 0;
23324ae1
FM
894
895 /**
896 Creates a wxGraphicsContext from a native window.
897 */
da1ed74c 898 virtual wxGraphicsContext* CreateContextFromNativeWindow(void* window) = 0;
23324ae1 899
27a3b24b 900 /**
4ee4c7b9 901 Creates a wxGraphicsContext that can be used for measuring texts only.
27a3b24b
KO
902 No drawing commands are allowed.
903 */
904 virtual wxGraphicsContext * CreateMeasuringContext() = 0;
905
23324ae1
FM
906 /**
907 Creates a native graphics font from a wxFont and a text colour.
908 */
5267aefd
FM
909 virtual wxGraphicsFont CreateFont(const wxFont& font,
910 const wxColour& col = *wxBLACK) = 0;
23324ae1 911
4ee4c7b9 912
23324ae1 913 /**
4ee4c7b9
VZ
914 Creates a native brush with a linear gradient.
915
916 Stops support is new since wxWidgets 2.9.1, previously only the start
917 and end colours could be specified.
23324ae1 918 */
9cc4ab85
BP
919 virtual wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1,
920 wxDouble y1,
921 wxDouble x2,
922 wxDouble y2,
4ee4c7b9 923 const wxGraphicsGradientStops& stops) = 0;
23324ae1
FM
924
925 /**
9cc4ab85
BP
926 Creates a native affine transformation matrix from the passed in
927 values. The defaults result in an identity matrix.
23324ae1 928 */
5267aefd
FM
929 virtual wxGraphicsMatrix CreateMatrix(wxDouble a = 1.0, wxDouble b = 0.0,
930 wxDouble c = 0.0, wxDouble d = 1.0,
a44f3b5a 931 wxDouble tx = 0.0,
5267aefd 932 wxDouble ty = 0.0) = 0;
23324ae1
FM
933
934 /**
935 Creates a native graphics path which is initially empty.
936 */
da1ed74c 937 virtual wxGraphicsPath CreatePath() = 0;
23324ae1
FM
938
939 /**
940 Creates a native pen from a wxPen.
941 */
da1ed74c 942 virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0;
23324ae1
FM
943
944 /**
4ee4c7b9
VZ
945 Creates a native brush with a radial gradient.
946
947 Stops support is new since wxWidgets 2.9.1, previously only the start
948 and end colours could be specified.
23324ae1 949 */
da1ed74c
FM
950 virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
951 wxDouble xc, wxDouble yc,
952 wxDouble radius,
4ee4c7b9 953 const wxGraphicsGradientStops& stops) = 0;
23324ae1
FM
954
955 /**
956 Returns the default renderer on this platform. On OS X this is the Core
9cc4ab85
BP
957 Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and
958 on GTK we currently default to the cairo renderer.
23324ae1 959 */
ea077571 960 static wxGraphicsRenderer* GetDefaultRenderer();
23324ae1
FM
961};
962
963
e54c96f1 964
23324ae1
FM
965/**
966 @class wxGraphicsBrush
7c913512 967
9cc4ab85
BP
968 A wxGraphicsBrush is a native representation of a brush. The contents are
969 specific and private to the respective renderer. Instances are ref counted
970 and can therefore be assigned as usual. The only way to get a valid
971 instance is via wxGraphicsContext::CreateBrush() or
972 wxGraphicsRenderer::CreateBrush().
7c913512 973
23324ae1 974 @library{wxcore}
9cc4ab85 975 @category{gdi}
23324ae1
FM
976*/
977class wxGraphicsBrush : public wxGraphicsObject
978{
979public:
7c913512 980
23324ae1
FM
981};
982
983
e54c96f1 984
23324ae1
FM
985/**
986 @class wxGraphicsFont
7c913512 987
9cc4ab85
BP
988 A wxGraphicsFont is a native representation of a font. The contents are
989 specific and private to the respective renderer. Instances are ref counted
990 and can therefore be assigned as usual. The only way to get a valid
991 instance is via wxGraphicsContext::CreateFont() or
992 wxGraphicsRenderer::CreateFont().
7c913512 993
23324ae1 994 @library{wxcore}
9cc4ab85 995 @category{gdi}
23324ae1
FM
996*/
997class wxGraphicsFont : public wxGraphicsObject
998{
999public:
7c913512 1000
23324ae1
FM
1001};
1002
1003
e54c96f1 1004
23324ae1
FM
1005/**
1006 @class wxGraphicsPen
7c913512 1007
9cc4ab85
BP
1008 A wxGraphicsPen is a native representation of a pen. The contents are
1009 specific and private to the respective renderer. Instances are ref counted
1010 and can therefore be assigned as usual. The only way to get a valid
1011 instance is via wxGraphicsContext::CreatePen() or
1012 wxGraphicsRenderer::CreatePen().
7c913512 1013
23324ae1 1014 @library{wxcore}
9cc4ab85 1015 @category{gdi}
23324ae1
FM
1016*/
1017class wxGraphicsPen : public wxGraphicsObject
1018{
1019public:
7c913512 1020
23324ae1
FM
1021};
1022
1023
e54c96f1 1024
23324ae1
FM
1025/**
1026 @class wxGraphicsMatrix
7c913512 1027
9cc4ab85
BP
1028 A wxGraphicsMatrix is a native representation of an affine matrix. The
1029 contents are specific and private to the respective renderer. Instances are
1030 ref counted and can therefore be assigned as usual. The only way to get a
1031 valid instance is via wxGraphicsContext::CreateMatrix() or
1032 wxGraphicsRenderer::CreateMatrix().
7c913512 1033
23324ae1 1034 @library{wxcore}
9cc4ab85 1035 @category{gdi}
23324ae1
FM
1036*/
1037class wxGraphicsMatrix : public wxGraphicsObject
1038{
1039public:
23324ae1 1040 /**
9cc4ab85
BP
1041 Concatenates the matrix passed with the current matrix.
1042 */
1043 virtual void Concat(const wxGraphicsMatrix* t);
1044 /**
1045 Concatenates the matrix passed with the current matrix.
23324ae1 1046 */
7c913512 1047 void Concat(const wxGraphicsMatrix& t);
23324ae1
FM
1048
1049 /**
1050 Returns the component values of the matrix via the argument pointers.
1051 */
9cc4ab85
BP
1052 virtual void Get(wxDouble* a = NULL, wxDouble* b = NULL,
1053 wxDouble* c = NULL, wxDouble* d = NULL,
1054 wxDouble* tx = NULL, wxDouble* ty = NULL) const;
23324ae1
FM
1055
1056 /**
9cc4ab85
BP
1057 Returns the native representation of the matrix. For CoreGraphics this
1058 is a CFAffineMatrix pointer, for GDIPlus a Matrix Pointer, and for
1059 Cairo a cairo_matrix_t pointer.
23324ae1 1060 */
da1ed74c 1061 virtual void* GetNativeMatrix() const;
23324ae1
FM
1062
1063 /**
1064 Inverts the matrix.
1065 */
da1ed74c 1066 virtual void Invert();
23324ae1 1067
9cc4ab85
BP
1068 /**
1069 Returns @true if the elements of the transformation matrix are equal.
1070 */
1071 virtual bool IsEqual(const wxGraphicsMatrix* t) const;
23324ae1
FM
1072 /**
1073 Returns @true if the elements of the transformation matrix are equal.
1074 */
328f5751 1075 bool IsEqual(const wxGraphicsMatrix& t) const;
23324ae1
FM
1076
1077 /**
1078 Return @true if this is the identity matrix.
1079 */
da1ed74c 1080 virtual bool IsIdentity() const;
23324ae1
FM
1081
1082 /**
9cc4ab85 1083 Rotates this matrix (in radians).
23324ae1 1084 */
da1ed74c 1085 virtual void Rotate(wxDouble angle);
23324ae1
FM
1086
1087 /**
1088 Scales this matrix.
1089 */
da1ed74c 1090 virtual void Scale(wxDouble xScale, wxDouble yScale);
23324ae1
FM
1091
1092 /**
9cc4ab85
BP
1093 Sets the matrix to the respective values (default values are the
1094 identity matrix).
23324ae1 1095 */
5267aefd
FM
1096 virtual void Set(wxDouble a = 1.0, wxDouble b = 0.0, wxDouble c = 0.0,
1097 wxDouble d = 1.0, wxDouble tx = 0.0, wxDouble ty = 0.0);
23324ae1
FM
1098
1099 /**
1100 Applies this matrix to a distance (ie. performs all transforms except
9cc4ab85 1101 translations).
23324ae1 1102 */
da1ed74c 1103 virtual void TransformDistance(wxDouble* dx, wxDouble* dy) const;
23324ae1
FM
1104
1105 /**
1106 Applies this matrix to a point.
1107 */
da1ed74c 1108 virtual void TransformPoint(wxDouble* x, wxDouble* y) const;
23324ae1
FM
1109
1110 /**
1111 Translates this matrix.
1112 */
da1ed74c 1113 virtual void Translate(wxDouble dx, wxDouble dy);
23324ae1 1114};
9cc4ab85 1115