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