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