]> git.saurik.com Git - wxWidgets.git/blob - include/wx/graphics.h
Fix wxRect::SetRightTop() which set the wrong corner.
[wxWidgets.git] / include / wx / graphics.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/graphics.h
3 // Purpose: graphics context header
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created:
7 // Copyright: (c) Stefan Csomor
8 // RCS-ID: $Id$
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GRAPHICS_H_
13 #define _WX_GRAPHICS_H_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_GRAPHICS_CONTEXT
18
19 #include "wx/geometry.h"
20 #include "wx/dynarray.h"
21 #include "wx/dc.h"
22 #include "wx/vector.h"
23
24 enum wxAntialiasMode
25 {
26 wxANTIALIAS_NONE, // should be 0
27 wxANTIALIAS_DEFAULT,
28 };
29
30 enum wxCompositionMode
31 {
32 // R = Result, S = Source, D = Destination, premultiplied with alpha
33 // Ra, Sa, Da their alpha components
34
35 // classic Porter-Duff compositions
36 // http://keithp.com/~keithp/porterduff/p253-porter.pdf
37
38 wxCOMPOSITION_CLEAR, /* R = 0 */
39 wxCOMPOSITION_SOURCE, /* R = S */
40 wxCOMPOSITION_OVER, /* R = S + D*(1 - Sa) */
41 wxCOMPOSITION_IN, /* R = S*Da */
42 wxCOMPOSITION_OUT, /* R = S*(1 - Da) */
43 wxCOMPOSITION_ATOP, /* R = S*Da + D*(1 - Sa) */
44
45 wxCOMPOSITION_DEST, /* R = D, essentially a noop */
46 wxCOMPOSITION_DEST_OVER, /* R = S*(1 - Da) + D */
47 wxCOMPOSITION_DEST_IN, /* R = D*Sa */
48 wxCOMPOSITION_DEST_OUT, /* R = D*(1 - Sa) */
49 wxCOMPOSITION_DEST_ATOP, /* R = S*(1 - Da) + D*Sa */
50 wxCOMPOSITION_XOR, /* R = S*(1 - Da) + D*(1 - Sa) */
51
52 // mathematical compositions
53 wxCOMPOSITION_ADD, /* R = S + D */
54 };
55
56 class WXDLLIMPEXP_FWD_CORE wxWindowDC;
57 class WXDLLIMPEXP_FWD_CORE wxMemoryDC;
58 #if wxUSE_PRINTING_ARCHITECTURE
59 class WXDLLIMPEXP_FWD_CORE wxPrinterDC;
60 #endif
61 #if wxUSE_ENH_METAFILE
62 class WXDLLIMPEXP_FWD_CORE wxEnhMetaFileDC;
63 #endif
64 class WXDLLIMPEXP_FWD_CORE wxGraphicsContext;
65 class WXDLLIMPEXP_FWD_CORE wxGraphicsPath;
66 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrix;
67 class WXDLLIMPEXP_FWD_CORE wxGraphicsFigure;
68 class WXDLLIMPEXP_FWD_CORE wxGraphicsRenderer;
69 class WXDLLIMPEXP_FWD_CORE wxGraphicsPen;
70 class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush;
71 class WXDLLIMPEXP_FWD_CORE wxGraphicsFont;
72 class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap;
73
74 /*
75 * notes about the graphics context apis
76 *
77 * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being
78 * in direction of positive y axis.
79 */
80
81 // Base class of all objects used for drawing in the new graphics API, the always point back to their
82 // originating rendering engine, there is no dynamic unloading of a renderer currently allowed,
83 // these references are not counted
84
85 //
86 // The data used by objects like graphics pens etc is ref counted, in order to avoid unnecessary expensive
87 // duplication. Any operation on a shared instance that results in a modified state, uncouples this
88 // instance from the other instances that were shared - using copy on write semantics
89 //
90
91 class WXDLLIMPEXP_FWD_CORE wxGraphicsObjectRefData;
92 class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrixData;
93 class WXDLLIMPEXP_FWD_CORE wxGraphicsPathData;
94
95 class WXDLLIMPEXP_CORE wxGraphicsObject : public wxObject
96 {
97 public:
98 wxGraphicsObject();
99 wxGraphicsObject( wxGraphicsRenderer* renderer );
100 virtual ~wxGraphicsObject();
101
102 bool IsNull() const;
103
104 // returns the renderer that was used to create this instance, or NULL if it has not been initialized yet
105 wxGraphicsRenderer* GetRenderer() const;
106 wxGraphicsObjectRefData* GetGraphicsData() const;
107 protected:
108 virtual wxObjectRefData* CreateRefData() const;
109 virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const;
110
111 DECLARE_DYNAMIC_CLASS(wxGraphicsObject)
112 };
113
114 class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject
115 {
116 public:
117 wxGraphicsPen() {}
118 virtual ~wxGraphicsPen() {}
119 private:
120 DECLARE_DYNAMIC_CLASS(wxGraphicsPen)
121 };
122
123 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPen) wxNullGraphicsPen;
124
125 class WXDLLIMPEXP_CORE wxGraphicsBrush : public wxGraphicsObject
126 {
127 public:
128 wxGraphicsBrush() {}
129 virtual ~wxGraphicsBrush() {}
130 private:
131 DECLARE_DYNAMIC_CLASS(wxGraphicsBrush)
132 };
133
134 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush;
135
136 class WXDLLIMPEXP_CORE wxGraphicsFont : public wxGraphicsObject
137 {
138 public:
139 wxGraphicsFont() {}
140 virtual ~wxGraphicsFont() {}
141 private:
142 DECLARE_DYNAMIC_CLASS(wxGraphicsFont)
143 };
144
145 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont;
146
147 class WXDLLIMPEXP_CORE wxGraphicsBitmap : public wxGraphicsObject
148 {
149 public:
150 wxGraphicsBitmap() {}
151 virtual ~wxGraphicsBitmap() {}
152 private:
153 DECLARE_DYNAMIC_CLASS(wxGraphicsBitmap)
154 };
155
156 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap;
157
158 class WXDLLIMPEXP_CORE wxGraphicsMatrix : public wxGraphicsObject
159 {
160 public:
161 wxGraphicsMatrix() {}
162
163 virtual ~wxGraphicsMatrix() {}
164
165 // concatenates the matrix
166 virtual void Concat( const wxGraphicsMatrix *t );
167 void Concat( const wxGraphicsMatrix &t ) { Concat( &t ); }
168
169 // sets the matrix to the respective values
170 virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
171 wxDouble tx=0.0, wxDouble ty=0.0);
172
173 // gets the component valuess of the matrix
174 virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL,
175 wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const;
176
177 // makes this the inverse matrix
178 virtual void Invert();
179
180 // returns true if the elements of the transformation matrix are equal ?
181 virtual bool IsEqual( const wxGraphicsMatrix* t) const;
182 bool IsEqual( const wxGraphicsMatrix& t) const { return IsEqual( &t ); }
183
184 // return true if this is the identity matrix
185 virtual bool IsIdentity() const;
186
187 //
188 // transformation
189 //
190
191 // add the translation to this matrix
192 virtual void Translate( wxDouble dx , wxDouble dy );
193
194 // add the scale to this matrix
195 virtual void Scale( wxDouble xScale , wxDouble yScale );
196
197 // add the rotation to this matrix (radians)
198 virtual void Rotate( wxDouble angle );
199
200 //
201 // apply the transforms
202 //
203
204 // applies that matrix to the point
205 virtual void TransformPoint( wxDouble *x, wxDouble *y ) const;
206
207 // applies the matrix except for translations
208 virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const;
209
210 // returns the native representation
211 virtual void * GetNativeMatrix() const;
212
213 const wxGraphicsMatrixData* GetMatrixData() const
214 { return (const wxGraphicsMatrixData*) GetRefData(); }
215 wxGraphicsMatrixData* GetMatrixData()
216 { return (wxGraphicsMatrixData*) GetRefData(); }
217
218 private:
219 DECLARE_DYNAMIC_CLASS(wxGraphicsMatrix)
220 };
221
222 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix) wxNullGraphicsMatrix;
223
224 class WXDLLIMPEXP_CORE wxGraphicsPath : public wxGraphicsObject
225 {
226 public:
227 wxGraphicsPath() {}
228 virtual ~wxGraphicsPath() {}
229
230 //
231 // These are the path primitives from which everything else can be constructed
232 //
233
234 // begins a new subpath at (x,y)
235 virtual void MoveToPoint( wxDouble x, wxDouble y );
236 void MoveToPoint( const wxPoint2DDouble& p);
237
238 // adds a straight line from the current point to (x,y)
239 virtual void AddLineToPoint( wxDouble x, wxDouble y );
240 void AddLineToPoint( const wxPoint2DDouble& p);
241
242 // adds a cubic Bezier curve from the current point, using two control points and an end point
243 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y );
244 void AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e);
245
246 // adds another path
247 virtual void AddPath( const wxGraphicsPath& path );
248
249 // closes the current sub-path
250 virtual void CloseSubpath();
251
252 // gets the last point of the current path, (0,0) if not yet set
253 virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const;
254 wxPoint2DDouble GetCurrentPoint() const;
255
256 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
257 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise );
258 void AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise);
259
260 //
261 // These are convenience functions which - if not available natively will be assembled
262 // using the primitives from above
263 //
264
265 // adds a quadratic Bezier curve from the current point, using a control point and an end point
266 virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y );
267
268 // appends a rectangle as a new closed subpath
269 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
270
271 // appends an ellipsis as a new closed subpath fitting the passed rectangle
272 virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
273
274 // appends a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
275 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r );
276
277 // appends an ellipse
278 virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
279
280 // appends a rounded rectangle
281 virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
282
283 // returns the native path
284 virtual void * GetNativePath() const;
285
286 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
287 virtual void UnGetNativePath(void *p)const;
288
289 // transforms each point of this path by the matrix
290 virtual void Transform( const wxGraphicsMatrix& matrix );
291
292 // gets the bounding box enclosing all points (possibly including control points)
293 virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h)const;
294 wxRect2DDouble GetBox()const;
295
296 virtual bool Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle = wxODDEVEN_RULE)const;
297 bool Contains( const wxPoint2DDouble& c, wxPolygonFillMode fillStyle = wxODDEVEN_RULE)const;
298
299 const wxGraphicsPathData* GetPathData() const
300 { return (const wxGraphicsPathData*) GetRefData(); }
301 wxGraphicsPathData* GetPathData()
302 { return (wxGraphicsPathData*) GetRefData(); }
303
304 private:
305 DECLARE_DYNAMIC_CLASS(wxGraphicsPath)
306 };
307
308 extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPath) wxNullGraphicsPath;
309
310
311 // Describes a single gradient stop.
312 class wxGraphicsGradientStop
313 {
314 public:
315 wxGraphicsGradientStop(wxColour col = wxTransparentColour,
316 float pos = 0.)
317 : m_col(col),
318 m_pos(pos)
319 {
320 }
321
322 // default copy ctor, assignment operator and dtor are ok
323
324 const wxColour& GetColour() const { return m_col; }
325 void SetColour(const wxColour& col) { m_col = col; }
326
327 float GetPosition() const { return m_pos; }
328 void SetPosition(float pos)
329 {
330 wxASSERT_MSG( pos >= 0 && pos <= 1, "invalid gradient stop position" );
331
332 m_pos = pos;
333 }
334
335 private:
336 // The colour of this gradient band.
337 wxColour m_col;
338
339 // Its starting position: 0 is the beginning and 1 is the end.
340 float m_pos;
341 };
342
343 // A collection of gradient stops ordered by their positions (from lowest to
344 // highest). The first stop (index 0, position 0.0) is always the starting
345 // colour and the last one (index GetCount() - 1, position 1.0) is the end
346 // colour.
347 class WXDLLIMPEXP_CORE wxGraphicsGradientStops
348 {
349 public:
350 wxGraphicsGradientStops(wxColour startCol = wxTransparentColour,
351 wxColour endCol = wxTransparentColour)
352 {
353 // we can't use Add() here as it relies on having start/end stops as
354 // first/last array elements so do it manually
355 m_stops.push_back(wxGraphicsGradientStop(startCol, 0.f));
356 m_stops.push_back(wxGraphicsGradientStop(endCol, 1.f));
357 }
358
359 // default copy ctor, assignment operator and dtor are ok for this class
360
361
362 // Add a stop in correct order.
363 void Add(const wxGraphicsGradientStop& stop);
364 void Add(wxColour col, float pos) { Add(wxGraphicsGradientStop(col, pos)); }
365
366 // Get the number of stops.
367 unsigned GetCount() const { return m_stops.size(); }
368
369 // Return the stop at the given index (which must be valid).
370 wxGraphicsGradientStop Item(unsigned n) const { return m_stops.at(n); }
371
372 // Get/set start and end colours.
373 void SetStartColour(wxColour col)
374 { m_stops[0].SetColour(col); }
375 wxColour GetStartColour() const
376 { return m_stops[0].GetColour(); }
377 void SetEndColour(wxColour col)
378 { m_stops[m_stops.size() - 1].SetColour(col); }
379 wxColour GetEndColour() const
380 { return m_stops[m_stops.size() - 1].GetColour(); }
381
382 private:
383 // All the stops stored in ascending order of positions.
384 wxVector<wxGraphicsGradientStop> m_stops;
385 };
386
387 class WXDLLIMPEXP_CORE wxGraphicsContext : public wxGraphicsObject
388 {
389 public:
390 wxGraphicsContext(wxGraphicsRenderer* renderer);
391
392 virtual ~wxGraphicsContext();
393
394 static wxGraphicsContext* Create( const wxWindowDC& dc);
395 static wxGraphicsContext * Create( const wxMemoryDC& dc);
396 #if wxUSE_PRINTING_ARCHITECTURE
397 static wxGraphicsContext * Create( const wxPrinterDC& dc);
398 #endif
399 #if wxUSE_ENH_METAFILE
400 static wxGraphicsContext * Create( const wxEnhMetaFileDC& dc);
401 #endif
402
403 static wxGraphicsContext* CreateFromNative( void * context );
404
405 static wxGraphicsContext* CreateFromNativeWindow( void * window );
406
407 static wxGraphicsContext* Create( wxWindow* window );
408
409 // create a context that can be used for measuring texts only, no drawing allowed
410 static wxGraphicsContext * Create();
411
412 // begin a new document (relevant only for printing / pdf etc) if there is a progress dialog, message will be shown
413 virtual bool StartDoc( const wxString& message );
414
415 // done with that document (relevant only for printing / pdf etc)
416 virtual void EndDoc();
417
418 // opens a new page (relevant only for printing / pdf etc) with the given size in points
419 // (if both are null the default page size will be used)
420 virtual void StartPage( wxDouble width = 0, wxDouble height = 0 );
421
422 // ends the current page (relevant only for printing / pdf etc)
423 virtual void EndPage();
424
425 // make sure that the current content of this context is immediately visible
426 virtual void Flush();
427
428 wxGraphicsPath CreatePath() const;
429
430 virtual wxGraphicsPen CreatePen(const wxPen& pen) const;
431
432 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) const;
433
434 // sets the brush to a linear gradient, starting at (x1,y1) and ending at
435 // (x2,y2) with the given boundary colours or the specified stops
436 wxGraphicsBrush
437 CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
438 wxDouble x2, wxDouble y2,
439 const wxColour& c1, const wxColour& c2) const;
440 wxGraphicsBrush
441 CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
442 wxDouble x2, wxDouble y2,
443 const wxGraphicsGradientStops& stops) const;
444
445 // sets the brush to a radial gradient originating at (xo,yc) and ending
446 // on a circle around (xc,yc) with the given radius; the colours may be
447 // specified by just the two extremes or the full array of gradient stops
448 wxGraphicsBrush
449 CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
450 wxDouble xc, wxDouble yc, wxDouble radius,
451 const wxColour& oColor, const wxColour& cColor) const;
452
453 wxGraphicsBrush
454 CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
455 wxDouble xc, wxDouble yc, wxDouble radius,
456 const wxGraphicsGradientStops& stops) const;
457
458 // sets the font
459 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) const;
460
461 // create a native bitmap representation
462 virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) const;
463
464 // create a native bitmap representation
465 virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) const;
466
467 // create a 'native' matrix corresponding to these values
468 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
469 wxDouble tx=0.0, wxDouble ty=0.0) const;
470
471 // push the current state of the context, ie the transformation matrix on a stack
472 virtual void PushState() = 0;
473
474 // pops a stored state from the stack
475 virtual void PopState() = 0;
476
477 // clips drawings to the region intersected with the current clipping region
478 virtual void Clip( const wxRegion &region ) = 0;
479
480 // clips drawings to the rect intersected with the current clipping region
481 virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
482
483 // resets the clipping to original extent
484 virtual void ResetClip() = 0;
485
486 // returns the native context
487 virtual void * GetNativeContext() = 0;
488
489 // returns the current shape antialiasing mode
490 virtual wxAntialiasMode GetAntialiasMode() const { return m_antialias; }
491
492 // sets the antialiasing mode, returns true if it supported
493 virtual bool SetAntialiasMode(wxAntialiasMode antialias) = 0;
494
495 // returns the current compositing operator
496 virtual wxCompositionMode GetCompositionMode() const { return m_composition; }
497
498 // sets the compositing operator, returns true if it supported
499 virtual bool SetCompositionMode(wxCompositionMode op) = 0;
500
501 // returns the size of the graphics context in device coordinates
502 virtual void GetSize( wxDouble* width, wxDouble* height);
503
504 // returns the resolution of the graphics context in device points per inch
505 virtual void GetDPI( wxDouble* dpiX, wxDouble* dpiY);
506
507 #if 0
508 // sets the current alpha on this context
509 virtual void SetAlpha( wxDouble alpha );
510
511 // returns the alpha on this context
512 virtual wxDouble GetAlpha() const;
513 #endif
514
515 // all rendering is done into a fully transparent temporary context
516 virtual void BeginLayer(wxDouble opacity) = 0;
517
518 // composites back the drawings into the context with the opacity given at
519 // the BeginLayer call
520 virtual void EndLayer() = 0;
521
522 //
523 // transformation : changes the current transformation matrix CTM of the context
524 //
525
526 // translate
527 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
528
529 // scale
530 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
531
532 // rotate (radians)
533 virtual void Rotate( wxDouble angle ) = 0;
534
535 // concatenates this transform with the current transform of this context
536 virtual void ConcatTransform( const wxGraphicsMatrix& matrix ) = 0;
537
538 // sets the transform of this context
539 virtual void SetTransform( const wxGraphicsMatrix& matrix ) = 0;
540
541 // gets the matrix of this context
542 virtual wxGraphicsMatrix GetTransform() const = 0;
543 //
544 // setting the paint
545 //
546
547 // sets the pen
548 virtual void SetPen( const wxGraphicsPen& pen );
549
550 void SetPen( const wxPen& pen );
551
552 // sets the brush for filling
553 virtual void SetBrush( const wxGraphicsBrush& brush );
554
555 void SetBrush( const wxBrush& brush );
556
557 // sets the font
558 virtual void SetFont( const wxGraphicsFont& font );
559
560 void SetFont( const wxFont& font, const wxColour& colour );
561
562
563 // strokes along a path with the current pen
564 virtual void StrokePath( const wxGraphicsPath& path ) = 0;
565
566 // fills a path with the current brush
567 virtual void FillPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle = wxODDEVEN_RULE ) = 0;
568
569 // draws a path by first filling and then stroking
570 virtual void DrawPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
571
572 //
573 // text
574 //
575
576 void DrawText( const wxString &str, wxDouble x, wxDouble y )
577 { DoDrawText(str, x, y); }
578
579 void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle )
580 { DoDrawRotatedText(str, x, y, angle); }
581
582 void DrawText( const wxString &str, wxDouble x, wxDouble y,
583 const wxGraphicsBrush& backgroundBrush )
584 { DoDrawFilledText(str, x, y, backgroundBrush); }
585
586 void DrawText( const wxString &str, wxDouble x, wxDouble y,
587 wxDouble angle, const wxGraphicsBrush& backgroundBrush )
588 { DoDrawRotatedFilledText(str, x, y, angle, backgroundBrush); }
589
590
591 virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height,
592 wxDouble *descent = NULL, wxDouble *externalLeading = NULL ) const = 0;
593
594 virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const = 0;
595
596 //
597 // image support
598 //
599
600 virtual void DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
601
602 virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
603
604 virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
605
606 //
607 // convenience methods
608 //
609
610 // strokes a single line
611 virtual void StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2);
612
613 // stroke lines connecting each of the points
614 virtual void StrokeLines( size_t n, const wxPoint2DDouble *points);
615
616 // stroke disconnected lines from begin to end points
617 virtual void StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints);
618
619 // draws a polygon
620 virtual void DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
621
622 // draws a rectangle
623 virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
624
625 // draws an ellipse
626 virtual void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
627
628 // draws a rounded rectangle
629 virtual void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
630
631 // wrappers using wxPoint2DDouble TODO
632
633 // helper to determine if a 0.5 offset should be applied for the drawing operation
634 virtual bool ShouldOffset() const { return false; }
635
636 protected:
637
638 wxGraphicsPen m_pen;
639 wxGraphicsBrush m_brush;
640 wxGraphicsFont m_font;
641 wxAntialiasMode m_antialias;
642 wxCompositionMode m_composition;
643
644 protected:
645 // implementations of overloaded public functions: we use different names
646 // for them to avoid the virtual function hiding problems in the derived
647 // classes
648 virtual void DoDrawText(const wxString& str, wxDouble x, wxDouble y) = 0;
649 virtual void DoDrawRotatedText(const wxString& str, wxDouble x, wxDouble y,
650 wxDouble angle);
651 virtual void DoDrawFilledText(const wxString& str, wxDouble x, wxDouble y,
652 const wxGraphicsBrush& backgroundBrush);
653 virtual void DoDrawRotatedFilledText(const wxString& str,
654 wxDouble x, wxDouble y,
655 wxDouble angle,
656 const wxGraphicsBrush& backgroundBrush);
657
658 wxDECLARE_NO_COPY_CLASS(wxGraphicsContext);
659 DECLARE_ABSTRACT_CLASS(wxGraphicsContext)
660 };
661
662 #if 0
663
664 //
665 // A graphics figure allows to cache path, pen etc creations, also will be a basis for layering/grouping elements
666 //
667
668 class WXDLLIMPEXP_CORE wxGraphicsFigure : public wxGraphicsObject
669 {
670 public:
671 wxGraphicsFigure(wxGraphicsRenderer* renderer);
672
673 virtual ~wxGraphicsFigure();
674
675 void SetPath( wxGraphicsMatrix* matrix );
676
677 void SetMatrix( wxGraphicsPath* path);
678
679 // draws this object on the context
680 virtual void Draw( wxGraphicsContext* cg );
681
682 // returns the path of this object
683 wxGraphicsPath* GetPath() { return m_path; }
684
685 // returns the transformation matrix of this object, may be null if there is no transformation necessary
686 wxGraphicsMatrix* GetMatrix() { return m_matrix; }
687
688 private:
689 wxGraphicsMatrix* m_matrix;
690 wxGraphicsPath* m_path;
691
692 DECLARE_DYNAMIC_CLASS(wxGraphicsFigure)
693 };
694
695 #endif
696
697 //
698 // The graphics renderer is the instance corresponding to the rendering engine used, eg there is ONE core graphics renderer
699 // instance on OSX. This instance is pointed back to by all objects created by it. Therefore you can create eg additional
700 // paths at any point from a given matrix etc.
701 //
702
703 class WXDLLIMPEXP_CORE wxGraphicsRenderer : public wxObject
704 {
705 public:
706 wxGraphicsRenderer() {}
707
708 virtual ~wxGraphicsRenderer() {}
709
710 static wxGraphicsRenderer* GetDefaultRenderer();
711
712 static wxGraphicsRenderer* GetCairoRenderer();
713 // Context
714
715 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) = 0;
716 virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc) = 0;
717 #if wxUSE_PRINTING_ARCHITECTURE
718 virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc) = 0;
719 #endif
720 #if wxUSE_ENH_METAFILE
721 virtual wxGraphicsContext * CreateContext( const wxEnhMetaFileDC& dc) = 0;
722 #endif
723
724 virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ) = 0;
725
726 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) = 0;
727
728 virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0;
729
730 // create a context that can be used for measuring texts only, no drawing allowed
731 virtual wxGraphicsContext * CreateMeasuringContext() = 0;
732
733 // Path
734
735 virtual wxGraphicsPath CreatePath() = 0;
736
737 // Matrix
738
739 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
740 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
741
742 // Paints
743
744 virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0;
745
746 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) = 0;
747
748 // Gradient brush creation functions may not honour all the stops specified
749 // stops and use just its boundary colours (this is currently the case
750 // under OS X)
751 virtual wxGraphicsBrush
752 CreateLinearGradientBrush(wxDouble x1, wxDouble y1,
753 wxDouble x2, wxDouble y2,
754 const wxGraphicsGradientStops& stops) = 0;
755
756 virtual wxGraphicsBrush
757 CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
758 wxDouble xc, wxDouble yc,
759 wxDouble radius,
760 const wxGraphicsGradientStops& stops) = 0;
761
762 // sets the font
763 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) = 0;
764
765 // create a native bitmap representation
766 virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) = 0;
767
768 // create a graphics bitmap from a native bitmap
769 virtual wxGraphicsBitmap CreateBitmapFromNativeBitmap( void* bitmap ) = 0;
770
771 // create a subimage from a native image representation
772 virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
773
774 private:
775 wxDECLARE_NO_COPY_CLASS(wxGraphicsRenderer);
776 DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer)
777 };
778
779 #endif
780
781 #endif // _WX_GRAPHICS_H_