automated ifacecheck fixes
[wxWidgets.git] / interface / wx / graphics.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: graphics.h
3 // Purpose: interface of wxGraphicsPath
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxGraphicsPath
11
12 A wxGraphicsPath is a native representation of an geometric path. The contents
13 are specific an private to the respective renderer. Instances are ref counted and can
14 therefore be assigned as usual. The only way to get a valid instance is via
15 wxGraphicsContext::CreatePath or wxGraphicsRenderer::CreatePath.
16
17 @library{wxcore}
18 @category{FIXME}
19 */
20 class wxGraphicsPath : public wxGraphicsObject
21 {
22 public:
23 //@{
24 /**
25
26 */
27 void AddArc(wxDouble x, wxDouble y, wxDouble r,
28 wxDouble startAngle,
29 wxDouble endAngle, bool clockwise);
30 void AddArc(const wxPoint2DDouble& c, wxDouble r,
31 wxDouble startAngle,
32 wxDouble endAngle,
33 bool clockwise);
34 //@}
35
36 /**
37 Appends a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to
38 (x2,y2), also a straight line from (current) to (x1,y1).
39 */
40 virtual void AddArcToPoint(wxDouble x1, wxDouble y1, wxDouble x2,
41 wxDouble y2, wxDouble r);
42
43 /**
44 Appends a circle around (x,y) with radius r as a new closed subpath.
45 */
46 virtual void AddCircle(wxDouble x, wxDouble y, wxDouble r);
47
48 //@{
49 /**
50
51 */
52 void AddCurveToPoint(wxDouble cx1, wxDouble cy1, wxDouble cx2,
53 wxDouble cy2,
54 wxDouble x,
55 wxDouble y);
56 void AddCurveToPoint(const wxPoint2DDouble& c1,
57 const wxPoint2DDouble& c2,
58 const wxPoint2DDouble& e);
59 //@}
60
61 /**
62 Appends an ellipse fitting into the passed in rectangle.
63 */
64 virtual void AddEllipse(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
65
66 //@{
67 /**
68
69 */
70 void AddLineToPoint(wxDouble x, wxDouble y);
71 void AddLineToPoint(const wxPoint2DDouble& p);
72 //@}
73
74 /**
75 Adds another path.
76 */
77 virtual void AddPath(const wxGraphicsPath& path);
78
79 /**
80 Adds a quadratic Bezier curve from the current point, using a control point and
81 an end point.
82 */
83 virtual void AddQuadCurveToPoint(wxDouble cx, wxDouble cy, wxDouble x,
84 wxDouble y);
85
86 /**
87 Appends a rectangle as a new closed subpath.
88 */
89 virtual void AddRectangle(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
90
91 /**
92 Appends a rounded rectangle as a new closed subpath.
93 */
94 virtual void AddRoundedRectangle(wxDouble x, wxDouble y, wxDouble w,
95 wxDouble h, wxDouble radius);
96
97 /**
98 Closes the current sub-path.
99 */
100 virtual void CloseSubpath();
101
102 //@{
103 /**
104 Returns @true if the point is within the path.
105 */
106 bool Contains(const wxPoint2DDouble& c,
107 int fillStyle = wxODDEVEN_RULE) const;
108 const bool Contains(wxDouble x, wxDouble y,
109 int fillStyle = wxODDEVEN_RULE) const;
110 //@}
111
112 //@{
113 /**
114 Gets the bounding box enclosing all points (possibly including control points).
115 */
116 wxRect2DDouble GetBox() const;
117 const void GetBox(wxDouble* x, wxDouble* y, wxDouble* w,
118 wxDouble* h) const;
119 //@}
120
121 //@{
122 /**
123 Gets the last point of the current path, (0,0) if not yet set.
124 */
125 void GetCurrentPoint(wxDouble* x, wxDouble* y) const;
126 const wxPoint2DDouble GetCurrentPoint() const;
127 //@}
128
129 /**
130 Returns the native path (CGPathRef for Core Graphics, Path pointer for GDIPlus
131 and a cairo_path_t pointer for cairo).
132 */
133 virtual void* GetNativePath() const;
134
135 //@{
136 /**
137 Begins a new subpath at (x,y)
138 */
139 void MoveToPoint(wxDouble x, wxDouble y);
140 void MoveToPoint(const wxPoint2DDouble& p);
141 //@}
142
143 /**
144 Transforms each point of this path by the matrix.
145 */
146 virtual void Transform(const wxGraphicsMatrix& matrix);
147
148 /**
149 Gives back the native path returned by GetNativePath() because there might be
150 some deallocations necessary (eg on cairo the native path returned by
151 GetNativePath is newly allocated each time).
152 */
153 virtual void UnGetNativePath(void* p) const;
154 };
155
156
157
158 /**
159 @class wxGraphicsObject
160
161 This class is the superclass of native graphics objects like pens etc. It
162 allows reference counting. Not instantiated by user code.
163
164 @library{wxcore}
165 @category{FIXME}
166
167 @see wxGraphicsBrush, wxGraphicsPen, wxGraphicsMatrix, wxGraphicsPath
168 */
169 class wxGraphicsObject : public wxObject
170 {
171 public:
172 /**
173 Returns the renderer that was used to create this instance, or @NULL if it has
174 not been initialized yet
175 */
176 wxGraphicsRenderer* GetRenderer() const;
177
178 /**
179 Is this object valid (@false) or still empty (@true)?
180 */
181 bool IsNull() const;
182 };
183
184
185
186 /**
187 @class wxGraphicsContext
188
189 A wxGraphicsContext instance is the object that is drawn upon. It is created by
190 a renderer using wxGraphicsRenderer::CreateContext(). This can be either directly
191 using a renderer instance, or indirectly using the static convenience Create()
192 functions of wxGraphicsContext that always delegate the task to the default renderer.
193
194 @code
195 void MyCanvas::OnPaint(wxPaintEvent &event)
196 {
197 // Create paint DC
198 wxPaintDC dc(this);
199
200 // Create graphics context from it
201 wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
202
203 if (gc)
204 {
205 // make a path that contains a circle and some lines
206 gc->SetPen( *wxRED_PEN );
207 wxGraphicsPath path = gc->CreatePath();
208 path.AddCircle( 50.0, 50.0, 50.0 );
209 path.MoveToPoint(0.0, 50.0);
210 path.AddLineToPoint(100.0, 50.0);
211 path.MoveToPoint(50.0, 0.0);
212 path.AddLineToPoint(50.0, 100.0 );
213 path.CloseSubpath();
214 path.AddRectangle(25.0, 25.0, 50.0, 50.0);
215
216 gc->StrokePath(path);
217
218 delete gc;
219 }
220 }
221 @endcode
222
223
224 @library{wxcore}
225 @category{FIXME}
226
227 @see wxGraphicsRenderer::CreateContext(), wxGCDC, wxDC
228 */
229 class wxGraphicsContext : public wxGraphicsObject
230 {
231 public:
232 /**
233 Creates a wxGraphicsContext from a wxWindow.
234
235 @see wxGraphicsRenderer::CreateContext()
236 */
237 static wxGraphicsContext* Create( wxWindow* window ) ;
238
239 /**
240 Creates a wxGraphicsContext from a wxWindowDC
241
242 @see wxGraphicsRenderer::CreateContext()
243 */
244 static wxGraphicsContext* Create( const wxWindowDC& dc) ;
245
246 /**
247 Creates a wxGraphicsContext from a wxMemoryDC
248
249 @see wxGraphicsRenderer::CreateContext()
250 */
251 static wxGraphicsContext * Create( const wxMemoryDC& dc) ;
252
253 /**
254 Creates a wxGraphicsContext from a wxPrinterDC. Under
255 GTK+, this will only work when using the GtkPrint
256 printing backend which is available since GTK+ 2.10.
257
258 @see wxGraphicsRenderer::CreateContext(), @ref overview_unixprinting "Printing under Unix"
259 */
260 static wxGraphicsContext * Create( const wxPrinterDC& dc) ;
261
262 /**
263 Clips drawings to the region
264 */
265 virtual void Clip(const wxRegion& region) = 0;
266
267 /**
268 Clips drawings to the rectangle.
269 */
270 virtual void Clip(wxDouble x, wxDouble y, wxDouble w, wxDouble h) = 0;
271
272 /**
273 Concatenates the passed in transform with the current transform of this context
274 */
275 virtual void ConcatTransform(const wxGraphicsMatrix& matrix) = 0;
276
277
278 /**
279 Creates a native brush from a wxBrush.
280 */
281 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush) const;
282
283 /**
284 Creates a native graphics font from a wxFont and a text colour.
285 */
286 virtual wxGraphicsFont CreateFont(const wxFont& font,
287 const wxColour& col = *wxBLACK) const;
288
289 /**
290 Creates a wxGraphicsContext from a native context. This native context must be
291 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a
292 cairo_t pointer for cairo.
293
294 @see wxGraphicsRenderer:: CreateContextFromNativeContext
295 */
296 static wxGraphicsContext* CreateFromNative(void* context);
297
298 /**
299 Creates a wxGraphicsContext from a native window.
300
301 @see wxGraphicsRenderer:: CreateContextFromNativeWindow
302 */
303 static wxGraphicsContext* CreateFromNativeWindow(void* window);
304
305 /**
306 Creates a native brush, having a linear gradient, starting at (x1,y1) with
307 color c1 to (x2,y2) with color c2
308 */
309 wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1,
310 wxDouble y1,
311 wxDouble x2,
312 wxDouble y2,
313 const wxColouramp;c1,
314 const wxColouramp;c2) const;
315
316 /**
317 Creates a native affine transformation matrix from the passed in values. The
318 defaults result in an identity matrix.
319 */
320 virtual wxGraphicsMatrix CreateMatrix(wxDouble a = 1.0, wxDouble b = 0.0,
321 wxDouble c = 0.0, wxDouble d = 1.0,
322 wxDouble tx = 0.0,
323 wxDouble ty = 0.0) const;
324
325 /**
326 Creates a native graphics path which is initially empty.
327 */
328 wxGraphicsPath CreatePath() const;
329
330 /**
331 Creates a native pen from a wxPen.
332 */
333 virtual wxGraphicsPen CreatePen(const wxPen& pen) const;
334
335 /**
336 Creates a native brush, having a radial gradient originating at (xo,yc) with
337 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
338 */
339 virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
340 wxDouble xc, wxDouble yc,
341 wxDouble radius,
342 const wxColour& oColor,
343 const wxColour& cColor) const;
344
345 /**
346 Draws the bitmap. In case of a mono bitmap, this is treated as a mask and the
347 current brushed is used for filling.
348 */
349 virtual void DrawBitmap(const wxBitmap& bmp, wxDouble x, wxDouble y,
350 wxDouble w, wxDouble h) = 0;
351
352 /**
353 Draws an ellipse.
354 */
355 virtual void DrawEllipse(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
356
357 /**
358 Draws the icon.
359 */
360 virtual void DrawIcon(const wxIcon& icon, wxDouble x, wxDouble y,
361 wxDouble w, wxDouble h) = 0;
362
363 /**
364 Draws a polygon.
365 */
366 virtual void DrawLines(size_t n, const wxPoint2DDouble* points,
367 int fillStyle = wxODDEVEN_RULE);
368
369 /**
370 Draws the path by first filling and then stroking.
371 */
372 virtual void DrawPath(const wxGraphicsPath& path,
373 int fillStyle = wxODDEVEN_RULE);
374
375 /**
376 Draws a rectangle.
377 */
378 virtual void DrawRectangle(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
379
380 /**
381 Draws a rounded rectangle.
382 */
383 virtual void DrawRoundedRectangle(wxDouble x, wxDouble y, wxDouble w,
384 wxDouble h, wxDouble radius);
385
386 //@{
387 /**
388 Draws a text at the defined position, at the given angle.
389 */
390 void DrawText(const wxString& str, wxDouble x, wxDouble y,
391 wxDouble angle);
392 void DrawText(const wxString& str, wxDouble x, wxDouble y);
393 //@}
394
395 /**
396 Fills the path with the current brush.
397 */
398 virtual void FillPath(const wxGraphicsPath& path,
399 int fillStyle = wxODDEVEN_RULE) = 0;
400
401 /**
402 Returns the native context (CGContextRef for Core Graphics, Graphics pointer
403 for GDIPlus and cairo_t pointer for cairo).
404 */
405 virtual void* GetNativeContext() = 0;
406
407 /**
408 Fills the @a widths array with the widths from the beginning of
409 @a text to the corresponding character of @e text.
410 */
411 virtual void GetPartialTextExtents(const wxString& text,
412 wxArrayDouble& widths) const = 0;
413
414 /**
415 Gets the dimensions of the string using the currently selected font.
416 @e string is the text string to measure, @e w and @e h are
417 the total width and height respectively, @a descent is the
418 dimension from the baseline of the font to the bottom of the
419 descender, and @a externalLeading is any extra vertical space added
420 to the font by the font designer (usually is zero).
421 */
422 virtual void GetTextExtent(const wxString& text, wxDouble* width,
423 wxDouble* height, wxDouble* descent,
424 wxDouble* externalLeading) const = 0;
425
426 /**
427 Gets the current transformation matrix of this context.
428 */
429 virtual wxGraphicsMatrix GetTransform() const = 0;
430
431 /**
432 Resets the clipping to original shape.
433 */
434 virtual void ResetClip() = 0;
435
436 /**
437 Rotates the current transformation matrix (radians),
438 */
439 virtual void Rotate(wxDouble angle) = 0;
440
441 /**
442 Scales the current transformation matrix.
443 */
444 virtual void Scale(wxDouble xScale, wxDouble yScale) = 0;
445
446 //@{
447 /**
448 Sets the brush for filling paths.
449 */
450 void SetBrush(const wxBrush& brush);
451 void SetBrush(const wxGraphicsBrush& brush);
452 //@}
453
454 //@{
455 /**
456 Sets the font for drawing text.
457 */
458 void SetFont(const wxFont& font, const wxColour& colour);
459 void SetFont(const wxGraphicsFont& font);
460 //@}
461
462 //@{
463 /**
464 Sets the pen used for stroking.
465 */
466 void SetPen(const wxGraphicsPen& pen);
467 void SetPen(const wxPen& pen);
468 //@}
469
470 /**
471 Sets the current transformation matrix of this context
472 */
473 virtual void SetTransform(const wxGraphicsMatrix& matrix) = 0;
474
475 /**
476 Strokes a single line.
477 */
478 virtual void StrokeLine(wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2);
479
480 //@{
481 /**
482 Stroke disconnected lines from begin to end points, fastest method available
483 for this purpose.
484 */
485 void StrokeLines(size_t n, const wxPoint2DDouble* beginPoints,
486 const wxPoint2DDouble* endPoints);
487 void StrokeLines(size_t n, const wxPoint2DDouble* points);
488 //@}
489
490 /**
491 Strokes along a path with the current pen.
492 */
493 virtual void StrokePath(const wxGraphicsPath& path) = 0;
494
495 /**
496 Translates the current transformation matrix.
497 */
498 virtual void Translate(wxDouble dx, wxDouble dy) = 0;
499 };
500
501
502
503 /**
504 @class wxGraphicsRenderer
505
506 A wxGraphicsRenderer is the instance corresponding to the rendering engine
507 used. There may be multiple instances on a system, if there are different
508 rendering engines present, but there is always only one instance per engine.
509 This instance is pointed back to by all objects created by it (wxGraphicsContext,
510 wxGraphicsPath etc) and can be retrieved through their wxGraphicsObject::GetRenderer()
511 method. Therefore you can create an additional instance of a path etc. by calling
512 wxGraphicsObject::GetRenderer() and then using the appropriate CreateXXX function
513 of that renderer.
514
515 @code
516 wxGraphicsPath *path = // from somewhere
517 wxGraphicsBrush *brush = path->GetRenderer()->CreateBrush( *wxBLACK_BRUSH );
518 @endcode
519
520 @library{wxcore}
521 @category{FIXME}
522 */
523 class wxGraphicsRenderer : public wxObject
524 {
525 public:
526 /**
527 Creates a wxGraphicsContext from a wxWindow.
528 */
529 virtual wxGraphicsContext* CreateContext(wxWindow* window) = 0;
530
531 /**
532 Creates a wxGraphicsContext from a wxWindowDC
533 */
534 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) = 0 ;
535
536 /**
537 Creates a wxGraphicsContext from a wxMemoryDC
538 */
539 virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc) = 0 ;
540
541 /**
542 Creates a wxGraphicsContext from a wxPrinterDC
543 */
544 virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc) = 0 ;
545
546 /**
547 Creates a native brush from a wxBrush.
548 */
549 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush) = 0;
550
551
552 /**
553 Creates a wxGraphicsContext from a native context. This native context must be
554 eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a cairo_t
555 pointer for cairo.
556 */
557 virtual wxGraphicsContext* CreateContextFromNativeContext(void* context) = 0;
558
559 /**
560 Creates a wxGraphicsContext from a native window.
561 */
562 virtual wxGraphicsContext* CreateContextFromNativeWindow(void* window) = 0;
563
564 /**
565 Creates a native graphics font from a wxFont and a text colour.
566 */
567 virtual wxGraphicsFont CreateFont(const wxFont& font,
568 const wxColour& col = *wxBLACK) = 0;
569
570 /**
571 Creates a native brush, having a linear gradient, starting at (x1,y1) with
572 color c1 to (x2,y2) with color c2
573 */
574 wxGraphicsBrush CreateLinearGradientBrush(wxDouble x1,
575 wxDouble y1,
576 wxDouble x2,
577 wxDouble y2,
578 const wxColouramp;c1,
579 const wxColouramp;c2);
580
581 /**
582 Creates a native affine transformation matrix from the passed in values. The
583 defaults result in an identity matrix.
584 */
585 virtual wxGraphicsMatrix CreateMatrix(wxDouble a = 1.0, wxDouble b = 0.0,
586 wxDouble c = 0.0, wxDouble d = 1.0,
587 wxDouble tx = 0.0,
588 wxDouble ty = 0.0) = 0;
589
590 /**
591 Creates a native graphics path which is initially empty.
592 */
593 virtual wxGraphicsPath CreatePath() = 0;
594
595 /**
596 Creates a native pen from a wxPen.
597 */
598 virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0;
599
600 /**
601 Creates a native brush, having a radial gradient originating at (xo,yc) with
602 color oColour and ends on a circle around (xc,yc) with radius r and color cColour
603 */
604 virtual wxGraphicsBrush CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
605 wxDouble xc, wxDouble yc,
606 wxDouble radius,
607 const wxColour& oColour,
608 const wxColour& cColour) = 0;
609
610 /**
611 Returns the default renderer on this platform. On OS X this is the Core
612 Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and on GTK we currently default to the cairo renderer.
613 */
614 static wxGraphicsRenderer* GetDefaultRenderer();
615 };
616
617
618
619 /**
620 @class wxGraphicsBrush
621
622 A wxGraphicsBrush is a native representation of a brush. The contents
623 are specific and private to the respective renderer. Instances are ref counted and can
624 therefore be assigned as usual. The only way to get a valid instance is via
625 wxGraphicsContext::CreateBrush or wxGraphicsRenderer::CreateBrush.
626
627 @library{wxcore}
628 @category{FIXME}
629 */
630 class wxGraphicsBrush : public wxGraphicsObject
631 {
632 public:
633
634 };
635
636
637
638 /**
639 @class wxGraphicsFont
640
641 A wxGraphicsFont is a native representation of a font. The contents
642 are specific and private to the respective renderer. Instances are ref counted and can
643 therefore be assigned as usual. The only way to get a valid instance is via
644 wxGraphicsContext::CreateFont or wxGraphicsRenderer::CreateFont.
645
646 @library{wxcore}
647 @category{FIXME}
648 */
649 class wxGraphicsFont : public wxGraphicsObject
650 {
651 public:
652
653 };
654
655
656
657 /**
658 @class wxGraphicsPen
659
660 A wxGraphicsPen is a native representation of a pen. The contents
661 are specific and private to the respective renderer. Instances are ref counted and can
662 therefore be assigned as usual. The only way to get a valid instance is via
663 wxGraphicsContext::CreatePen or wxGraphicsRenderer::CreatePen.
664
665 @library{wxcore}
666 @category{FIXME}
667 */
668 class wxGraphicsPen : public wxGraphicsObject
669 {
670 public:
671
672 };
673
674
675
676 /**
677 @class wxGraphicsMatrix
678
679 A wxGraphicsMatrix is a native representation of an affine matrix. The contents
680 are specific and private to the respective renderer. Instances are ref counted and can
681 therefore be assigned as usual. The only way to get a valid instance is via
682 wxGraphicsContext::CreateMatrix or wxGraphicsRenderer::CreateMatrix.
683
684 @library{wxcore}
685 @category{FIXME}
686 */
687 class wxGraphicsMatrix : public wxGraphicsObject
688 {
689 public:
690 //@{
691 /**
692
693 */
694 void Concat(const wxGraphicsMatrix* t);
695 void Concat(const wxGraphicsMatrix& t);
696 //@}
697
698 /**
699 Returns the component values of the matrix via the argument pointers.
700 */
701 virtual void Get(wxDouble* a = NULL, wxDouble* b = NULL, wxDouble* c = NULL,
702 wxDouble* d = NULL, wxDouble* tx = NULL,
703 wxDouble* ty = NULL) const;
704
705 /**
706 Returns the native representation of the matrix. For CoreGraphics this is a
707 CFAffineMatrix pointer. For GDIPlus a Matrix Pointer and for Cairo a cairo_matrix_t pointer.
708 */
709 virtual void* GetNativeMatrix() const;
710
711 /**
712 Inverts the matrix.
713 */
714 virtual void Invert();
715
716 /**
717 Returns @true if the elements of the transformation matrix are equal.
718 */
719 bool IsEqual(const wxGraphicsMatrix& t) const;
720
721 /**
722 Return @true if this is the identity matrix.
723 */
724 virtual bool IsIdentity() const;
725
726 /**
727 Rotates this matrix (radians).
728 */
729 virtual void Rotate(wxDouble angle);
730
731 /**
732 Scales this matrix.
733 */
734 virtual void Scale(wxDouble xScale, wxDouble yScale);
735
736 /**
737 Sets the matrix to the respective values (default values are the identity
738 matrix)
739 */
740 virtual void Set(wxDouble a = 1.0, wxDouble b = 0.0, wxDouble c = 0.0,
741 wxDouble d = 1.0, wxDouble tx = 0.0, wxDouble ty = 0.0);
742
743 /**
744 Applies this matrix to a distance (ie. performs all transforms except
745 translations)
746 */
747 virtual void TransformDistance(wxDouble* dx, wxDouble* dy) const;
748
749 /**
750 Applies this matrix to a point.
751 */
752 virtual void TransformPoint(wxDouble* x, wxDouble* y) const;
753
754 /**
755 Translates this matrix.
756 */
757 virtual void Translate(wxDouble dx, wxDouble dy);
758 };
759