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