]> git.saurik.com Git - wxWidgets.git/blame - include/wx/graphics.h
changing colour derivation
[wxWidgets.git] / include / wx / graphics.h
CommitLineData
50581042
SC
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
f07d9b97
MR
15#include "wx/defs.h"
16
8acd14d1
SC
17#if wxUSE_GRAPHICS_CONTEXT
18
50581042 19#include "wx/geometry.h"
50581042
SC
20#include "wx/dynarray.h"
21
b5dbe15d
VS
22class WXDLLIMPEXP_FWD_CORE wxWindowDC;
23class WXDLLIMPEXP_FWD_CORE wxMemoryDC;
24class WXDLLIMPEXP_FWD_CORE wxGraphicsContext;
25class WXDLLIMPEXP_FWD_CORE wxGraphicsPath;
26class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrix;
27class WXDLLIMPEXP_FWD_CORE wxGraphicsFigure;
28class WXDLLIMPEXP_FWD_CORE wxGraphicsRenderer;
29class WXDLLIMPEXP_FWD_CORE wxGraphicsPen;
30class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush;
31class WXDLLIMPEXP_FWD_CORE wxGraphicsFont;
774f4d12 32
50581042
SC
33/*
34 * notes about the graphics context apis
35 *
36 * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being
37 * in direction of positive y axis.
38 */
39
9e605538
SC
40// Base class of all objects used for drawing in the new graphics API, the always point back to their
41// originating rendering engine, there is no dynamic unloading of a renderer currently allowed,
42// these references are not counted
2c820406
SC
43
44//
45// The data used by objects like graphics pens etc is ref counted, in order to avoid unnecessary expensive
46// duplication. Any operation on a shared instance that results in a modified state, uncouples this
47// instance from the other instances that were shared - using copy on write semantics
48//
9e605538 49
2c820406
SC
50class WXDLLIMPEXP_CORE wxGraphicsObjectRefData : public wxObjectRefData
51{
52public :
53 wxGraphicsObjectRefData( wxGraphicsRenderer* renderer );
54 wxGraphicsObjectRefData( const wxGraphicsObjectRefData* data );
55 wxGraphicsRenderer* GetRenderer() const ;
56 virtual wxGraphicsObjectRefData* Clone() const ;
57
58protected :
59 wxGraphicsRenderer* m_renderer;
60} ;
61
9e605538
SC
62class WXDLLIMPEXP_CORE wxGraphicsObject : public wxObject
63{
64public :
2c820406
SC
65 wxGraphicsObject() ;
66 wxGraphicsObject( wxGraphicsRenderer* renderer ) ;
67 virtual ~wxGraphicsObject() ;
0d3675a6 68
2c820406
SC
69 bool IsNull() const ;
70
71 // returns the renderer that was used to create this instance, or NULL if it has not been initialized yet
72 wxGraphicsRenderer* GetRenderer() const ;
73 wxGraphicsObjectRefData* GetGraphicsData() const ;
9e605538 74protected :
2c820406
SC
75 virtual wxObjectRefData* CreateRefData() const;
76 virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const;
77
39013ba0 78 DECLARE_DYNAMIC_CLASS(wxGraphicsObject)
9e605538
SC
79} ;
80
81class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject
82{
83public :
2c820406 84 wxGraphicsPen() {}
9e605538 85 virtual ~wxGraphicsPen() {}
9e605538 86private :
2c820406 87 DECLARE_DYNAMIC_CLASS(wxGraphicsPen)
9e605538
SC
88} ;
89
2c820406
SC
90extern WXDLLEXPORT_DATA(wxGraphicsPen) wxNullGraphicsPen;
91
9e605538
SC
92class WXDLLIMPEXP_CORE wxGraphicsBrush : public wxGraphicsObject
93{
94public :
2c820406 95 wxGraphicsBrush() {}
9e605538 96 virtual ~wxGraphicsBrush() {}
9e605538 97private :
2c820406 98 DECLARE_DYNAMIC_CLASS(wxGraphicsBrush)
9e605538
SC
99} ;
100
2c820406
SC
101extern WXDLLEXPORT_DATA(wxGraphicsBrush) wxNullGraphicsBrush;
102
9e605538 103class WXDLLIMPEXP_CORE wxGraphicsFont : public wxGraphicsObject
50581042
SC
104{
105public :
2c820406 106 wxGraphicsFont() {}
9e605538 107 virtual ~wxGraphicsFont() {}
9e605538 108private :
2c820406 109 DECLARE_DYNAMIC_CLASS(wxGraphicsFont)
9e605538
SC
110} ;
111
2c820406
SC
112extern WXDLLEXPORT_DATA(wxGraphicsFont) wxNullGraphicsFont;
113
114
a4e73390 115class WXDLLIMPEXP_CORE wxGraphicsMatrixData : public wxGraphicsObjectRefData
9e605538
SC
116{
117public :
a4e73390
SC
118 wxGraphicsMatrixData( wxGraphicsRenderer* renderer) :
119 wxGraphicsObjectRefData(renderer) {}
120
121 virtual ~wxGraphicsMatrixData() {}
122
123 // concatenates the matrix
124 virtual void Concat( const wxGraphicsMatrixData *t ) = 0;
125
126 // sets the matrix to the respective values
127 virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
128 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
129
248802d0
RD
130 // gets the component valuess of the matrix
131 virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL,
132 wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const = 0;
133
a4e73390
SC
134 // makes this the inverse matrix
135 virtual void Invert() = 0;
136
137 // returns true if the elements of the transformation matrix are equal ?
138 virtual bool IsEqual( const wxGraphicsMatrixData* t) const = 0;
139
140 // return true if this is the identity matrix
141 virtual bool IsIdentity() const = 0;
142
143 //
144 // transformation
145 //
146
147 // add the translation to this matrix
148 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
149
150 // add the scale to this matrix
151 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
152
153 // add the rotation to this matrix (radians)
154 virtual void Rotate( wxDouble angle ) = 0;
155
156 //
157 // apply the transforms
158 //
159
160 // applies that matrix to the point
161 virtual void TransformPoint( wxDouble *x, wxDouble *y ) const = 0;
162
163 // applies the matrix except for translations
164 virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const =0;
165
166 // returns the native representation
167 virtual void * GetNativeMatrix() const = 0;
168} ;
169
170class WXDLLIMPEXP_CORE wxGraphicsMatrix : public wxGraphicsObject
171{
172public :
173 wxGraphicsMatrix() {}
174
175 virtual ~wxGraphicsMatrix() {}
176
177 // concatenates the matrix
178 virtual void Concat( const wxGraphicsMatrix *t );
179 void Concat( const wxGraphicsMatrix &t ) { Concat( &t ); }
180
181 // sets the matrix to the respective values
182 virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
183 wxDouble tx=0.0, wxDouble ty=0.0);
184
248802d0
RD
185 // gets the component valuess of the matrix
186 virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL,
187 wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const;
188
a4e73390
SC
189 // makes this the inverse matrix
190 virtual void Invert();
191
192 // returns true if the elements of the transformation matrix are equal ?
193 virtual bool IsEqual( const wxGraphicsMatrix* t) const;
194 bool IsEqual( const wxGraphicsMatrix& t) const { return IsEqual( &t ); }
195
196 // return true if this is the identity matrix
197 virtual bool IsIdentity() const;
198
199 //
200 // transformation
201 //
202
203 // add the translation to this matrix
204 virtual void Translate( wxDouble dx , wxDouble dy );
205
206 // add the scale to this matrix
207 virtual void Scale( wxDouble xScale , wxDouble yScale );
208
209 // add the rotation to this matrix (radians)
210 virtual void Rotate( wxDouble angle );
211
212 //
213 // apply the transforms
214 //
215
216 // applies that matrix to the point
217 virtual void TransformPoint( wxDouble *x, wxDouble *y ) const;
218
219 // applies the matrix except for translations
220 virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const;
221
222 // returns the native representation
223 virtual void * GetNativeMatrix() const;
224
225 const wxGraphicsMatrixData* GetMatrixData() const
226 { return (const wxGraphicsMatrixData*) GetRefData(); }
227 wxGraphicsMatrixData* GetMatrixData()
228 { return (wxGraphicsMatrixData*) GetRefData(); }
229
230private :
231 DECLARE_DYNAMIC_CLASS(wxGraphicsMatrix)
232} ;
233
234extern WXDLLEXPORT_DATA(wxGraphicsMatrix) wxNullGraphicsMatrix;
235
236class WXDLLIMPEXP_CORE wxGraphicsPathData : public wxGraphicsObjectRefData
237{
238public :
239 wxGraphicsPathData(wxGraphicsRenderer* renderer) : wxGraphicsObjectRefData(renderer) {}
240 virtual ~wxGraphicsPathData() {}
9e605538 241
50581042
SC
242 //
243 // These are the path primitives from which everything else can be constructed
244 //
245
246 // begins a new subpath at (x,y)
247 virtual void MoveToPoint( wxDouble x, wxDouble y ) = 0;
248
249 // adds a straight line from the current point to (x,y)
250 virtual void AddLineToPoint( wxDouble x, wxDouble y ) = 0;
251
252 // adds a cubic Bezier curve from the current point, using two control points and an end point
253 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) = 0;
a4e73390 254
0d3675a6 255 // adds another path
a4e73390 256 virtual void AddPath( const wxGraphicsPathData* path ) =0;
50581042
SC
257
258 // closes the current sub-path
259 virtual void CloseSubpath() = 0;
260
261 // gets the last point of the current path, (0,0) if not yet set
a4e73390 262 virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const = 0;
50581042
SC
263
264 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
265 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) = 0;
266
267 //
268 // These are convenience functions which - if not available natively will be assembled
269 // using the primitives from above
270 //
271
272 // adds a quadratic Bezier curve from the current point, using a control point and an end point
273 virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y );
274
275 // appends a rectangle as a new closed subpath
276 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
277
278 // appends an ellipsis as a new closed subpath fitting the passed rectangle
279 virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
280
59720690 281 // 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)
50581042 282 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
a4e73390 283
59720690
SC
284 // appends an ellipse
285 virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
286
287 // appends a rounded rectangle
288 virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
289
0d3675a6
RD
290 // returns the native path
291 virtual void * GetNativePath() const = 0;
a4e73390 292
0d3675a6 293 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
a4e73390
SC
294 virtual void UnGetNativePath(void *p) const= 0;
295
0d3675a6 296 // transforms each point of this path by the matrix
a4e73390
SC
297 virtual void Transform( const wxGraphicsMatrixData* matrix ) =0;
298
0d3675a6 299 // gets the bounding box enclosing all points (possibly including control points)
a4e73390
SC
300 virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const=0;
301
302 virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxODDEVEN_RULE) const=0;
50581042
SC
303};
304
a4e73390 305class WXDLLIMPEXP_CORE wxGraphicsPath : public wxGraphicsObject
774f4d12
SC
306{
307public :
a4e73390
SC
308 wxGraphicsPath() {}
309 virtual ~wxGraphicsPath() {}
0d3675a6 310
a4e73390
SC
311 //
312 // These are the path primitives from which everything else can be constructed
313 //
9e605538 314
a4e73390
SC
315 // begins a new subpath at (x,y)
316 virtual void MoveToPoint( wxDouble x, wxDouble y );
317 void MoveToPoint( const wxPoint2DDouble& p);
0d3675a6 318
a4e73390
SC
319 // adds a straight line from the current point to (x,y)
320 virtual void AddLineToPoint( wxDouble x, wxDouble y );
321 void AddLineToPoint( const wxPoint2DDouble& p);
0d3675a6 322
a4e73390
SC
323 // adds a cubic Bezier curve from the current point, using two control points and an end point
324 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y ) ;
325 void AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e);
0d3675a6 326
a4e73390
SC
327 // adds another path
328 virtual void AddPath( const wxGraphicsPath& path );
329
330 // closes the current sub-path
331 virtual void CloseSubpath() ;
332
333 // gets the last point of the current path, (0,0) if not yet set
334 virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const;
335 wxPoint2DDouble GetCurrentPoint() const;
336
337 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
338 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) ;
339 void AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise);
340
774f4d12 341 //
a4e73390
SC
342 // These are convenience functions which - if not available natively will be assembled
343 // using the primitives from above
774f4d12 344 //
a4e73390
SC
345
346 // adds a quadratic Bezier curve from the current point, using a control point and an end point
347 virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y );
348
349 // appends a rectangle as a new closed subpath
350 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
351
352 // appends an ellipsis as a new closed subpath fitting the passed rectangle
353 virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
354
355 // 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)
356 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
774f4d12 357
a4e73390
SC
358 // appends an ellipse
359 virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
774f4d12 360
a4e73390
SC
361 // appends a rounded rectangle
362 virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
774f4d12 363
a4e73390
SC
364 // returns the native path
365 virtual void * GetNativePath() const;
0d3675a6 366
a4e73390
SC
367 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
368 virtual void UnGetNativePath(void *p)const;
0d3675a6 369
a4e73390
SC
370 // transforms each point of this path by the matrix
371 virtual void Transform( const wxGraphicsMatrix& matrix );
0d3675a6 372
a4e73390
SC
373 // gets the bounding box enclosing all points (possibly including control points)
374 virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h)const;
375 wxRect2DDouble GetBox()const;
0d3675a6 376
a4e73390
SC
377 virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxODDEVEN_RULE)const;
378 bool Contains( const wxPoint2DDouble& c, int fillStyle = wxODDEVEN_RULE)const;
0d3675a6 379
a4e73390
SC
380 const wxGraphicsPathData* GetPathData() const
381 { return (const wxGraphicsPathData*) GetRefData(); }
382 wxGraphicsPathData* GetPathData()
383 { return (wxGraphicsPathData*) GetRefData(); }
384
385private :
386 DECLARE_DYNAMIC_CLASS(wxGraphicsPath)
774f4d12 387} ;
774f4d12 388
a4e73390
SC
389extern WXDLLEXPORT_DATA(wxGraphicsPath) wxNullGraphicsPath;
390
391
9e605538 392class WXDLLIMPEXP_CORE wxGraphicsContext : public wxGraphicsObject
50581042
SC
393{
394public:
9e605538 395 wxGraphicsContext(wxGraphicsRenderer* renderer);
774f4d12 396
9e605538 397 virtual ~wxGraphicsContext();
50581042
SC
398
399 static wxGraphicsContext* Create( const wxWindowDC& dc) ;
773ccc31 400 static wxGraphicsContext * Create( const wxMemoryDC& dc) ;
773ccc31 401
bf2185eb 402 static wxGraphicsContext* CreateFromNative( void * context ) ;
774f4d12 403
bf2185eb 404 static wxGraphicsContext* CreateFromNativeWindow( void * window ) ;
9a02779a 405
774f4d12 406 static wxGraphicsContext* Create( wxWindow* window ) ;
50581042 407
ad667945
SC
408 // create a context that can be used for measuring texts only, no drawing allowed
409 static wxGraphicsContext * Create();
410
cc18b1c7
SC
411 // begin a new document (relevant only for printing / pdf etc) if there is a progress dialog, message will be shown
412 virtual bool StartDoc( const wxString& message ) ;
413
414 // done with that document (relevant only for printing / pdf etc)
415 virtual void EndDoc();
416
417 // opens a new page (relevant only for printing / pdf etc) with the given size in points
418 // (if both are null the default page size will be used)
419 virtual void StartPage( wxDouble width = 0, wxDouble height = 0 );
420
421 // ends the current page (relevant only for printing / pdf etc)
422 virtual void EndPage();
423
424 // make sure that the current content of this context is immediately visible
425 virtual void Flush();
426
a4e73390 427 wxGraphicsPath CreatePath() const;
0d3675a6 428
a4e73390 429 virtual wxGraphicsPen CreatePen(const wxPen& pen) const;
9e605538 430
a4e73390 431 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) const;
9e605538
SC
432
433 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2c820406 434 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
a4e73390 435 const wxColour&c1, const wxColour&c2) const;
9e605538
SC
436
437 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
438 // with radius r and color cColor
2c820406 439 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
a4e73390 440 const wxColour &oColor, const wxColour &cColor) const;
9e605538
SC
441
442 // sets the font
a4e73390 443 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) const;
9e605538 444
0d3675a6 445 // create a 'native' matrix corresponding to these values
a4e73390
SC
446 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
447 wxDouble tx=0.0, wxDouble ty=0.0) const;
0d3675a6 448
50581042
SC
449 // push the current state of the context, ie the transformation matrix on a stack
450 virtual void PushState() = 0;
451
452 // pops a stored state from the stack
453 virtual void PopState() = 0;
454
cc18b1c7 455 // clips drawings to the region intersected with the current clipping region
50581042
SC
456 virtual void Clip( const wxRegion &region ) = 0;
457
cc18b1c7 458 // clips drawings to the rect intersected with the current clipping region
774f4d12 459 virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
0d3675a6
RD
460
461 // resets the clipping to original extent
462 virtual void ResetClip() = 0 ;
774f4d12 463
0d3675a6
RD
464 // returns the native context
465 virtual void * GetNativeContext() = 0;
774f4d12 466
e22cf4b3
SC
467 // returns the current logical function
468 virtual int GetLogicalFunction() const { return m_logicalFunction; }
469
470 // sets the current logical function, returns true if it supported
471 virtual bool SetLogicalFunction(int function) ;
472
cc18b1c7
SC
473 // returns the size of the graphics context in device coordinates
474 virtual void GetSize( wxDouble* width, wxDouble* height);
475
476 // returns the resolution of the graphics context in device points per inch
477 virtual void GetDPI( wxDouble* dpiX, wxDouble* dpiY);
478
479#if 0
480 // sets the current alpha on this context
481 virtual void SetAlpha( wxDouble alpha );
482
483 // returns the alpha on this context
484 virtual wxDouble GetAlpha() const;
485#endif
50581042 486 //
774f4d12 487 // transformation : changes the current transformation matrix CTM of the context
50581042
SC
488 //
489
490 // translate
491 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
492
493 // scale
494 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
495
496 // rotate (radians)
497 virtual void Rotate( wxDouble angle ) = 0;
0d3675a6
RD
498
499 // concatenates this transform with the current transform of this context
a4e73390 500 virtual void ConcatTransform( const wxGraphicsMatrix& matrix ) = 0;
9e605538 501
0d3675a6 502 // sets the transform of this context
a4e73390 503 virtual void SetTransform( const wxGraphicsMatrix& matrix ) = 0;
50581042 504
0d3675a6 505 // gets the matrix of this context
a4e73390 506 virtual wxGraphicsMatrix GetTransform() const = 0;
50581042
SC
507 //
508 // setting the paint
509 //
510
9e605538 511 // sets the pen
2c820406 512 virtual void SetPen( const wxGraphicsPen& pen );
9e605538
SC
513
514 void SetPen( const wxPen& pen );
50581042
SC
515
516 // sets the brush for filling
2c820406 517 virtual void SetBrush( const wxGraphicsBrush& brush );
9e605538
SC
518
519 void SetBrush( const wxBrush& brush );
50581042
SC
520
521 // sets the font
2c820406 522 virtual void SetFont( const wxGraphicsFont& font );
9e605538
SC
523
524 void SetFont( const wxFont& font, const wxColour& colour );
0d3675a6 525
50581042 526
50581042 527 // strokes along a path with the current pen
a4e73390 528 virtual void StrokePath( const wxGraphicsPath& path ) = 0;
50581042
SC
529
530 // fills a path with the current brush
a4e73390 531 virtual void FillPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE ) = 0;
50581042
SC
532
533 // draws a path by first filling and then stroking
a4e73390 534 virtual void DrawPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE );
0d3675a6 535
50581042
SC
536 //
537 // text
538 //
539
540 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y ) = 0;
541
542 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle );
543
068eb463
SC
544 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, const wxGraphicsBrush& backgroundBrush ) ;
545
546 virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush& backgroundBrush );
547
50581042
SC
548 virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height,
549 wxDouble *descent, wxDouble *externalLeading ) const = 0;
550
551 virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const = 0;
552
553 //
554 // image support
555 //
556
557 virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
558
559 virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
560
561 //
562 // convenience methods
563 //
564
565 // strokes a single line
566 virtual void StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2);
567
568 // stroke lines connecting each of the points
569 virtual void StrokeLines( size_t n, const wxPoint2DDouble *points);
570
571 // stroke disconnected lines from begin to end points
572 virtual void StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints);
573
574 // draws a polygon
a4e73390 575 virtual void DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle = wxODDEVEN_RULE );
50581042
SC
576
577 // draws a polygon
578 virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
579
580 // draws an ellipse
581 virtual void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
582
583 // draws a rounded rectangle
584 virtual void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
585
9e605538 586 // wrappers using wxPoint2DDouble TODO
50581042 587
de3cb39f
RD
588 // helper to determine if a 0.5 offset should be applied for the drawing operation
589 virtual bool ShouldOffset() const { return false; }
9e605538 590
9da34e21
JS
591protected :
592
2c820406
SC
593 wxGraphicsPen m_pen;
594 wxGraphicsBrush m_brush;
595 wxGraphicsFont m_font;
e22cf4b3 596 int m_logicalFunction;
9e605538
SC
597
598private :
50581042 599 DECLARE_NO_COPY_CLASS(wxGraphicsContext)
8ddf8e82 600 DECLARE_ABSTRACT_CLASS(wxGraphicsContext)
50581042
SC
601};
602
9e605538
SC
603#if 0
604
605//
606// A graphics figure allows to cache path, pen etc creations, also will be a basis for layering/grouping elements
607//
608
609class WXDLLIMPEXP_CORE wxGraphicsFigure : public wxGraphicsObject
610{
611public :
0d3675a6
RD
612 wxGraphicsFigure(wxGraphicsRenderer* renderer) ;
613
614 virtual ~wxGraphicsFigure() ;
615
616 void SetPath( wxGraphicsMatrix* matrix );
617
618 void SetMatrix( wxGraphicsPath* path);
619
620 // draws this object on the context
621 virtual void Draw( wxGraphicsContext* cg );
622
623 // returns the path of this object
624 wxGraphicsPath* GetPath() { return m_path; }
625
626 // returns the transformation matrix of this object, may be null if there is no transformation necessary
627 wxGraphicsMatrix* GetMatrix() { return m_matrix; }
628
9e605538 629private :
0d3675a6
RD
630 wxGraphicsMatrix* m_matrix;
631 wxGraphicsPath* m_path;
9e605538
SC
632
633 DECLARE_DYNAMIC_CLASS(wxGraphicsFigure)
634} ;
635
636#endif
637
638//
639// The graphics renderer is the instance corresponding to the rendering engine used, eg there is ONE core graphics renderer
640// instance on OSX. This instance is pointed back to by all objects created by it. Therefore you can create eg additional
641// paths at any point from a given matrix etc.
642//
643
644class WXDLLIMPEXP_CORE wxGraphicsRenderer : public wxObject
645{
646public :
647 wxGraphicsRenderer() {}
648
649 virtual ~wxGraphicsRenderer() {}
650
0d3675a6 651 static wxGraphicsRenderer* GetDefaultRenderer();
9e605538 652
0d3675a6 653 // Context
9e605538 654
0d3675a6 655 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) = 0 ;
773ccc31 656 virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc) = 0 ;
888dde65 657
0d3675a6 658 virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ) = 0;
9e605538 659
0d3675a6 660 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) = 0;
9e605538 661
0d3675a6 662 virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0;
9e605538 663
ad667945
SC
664 // create a context that can be used for measuring texts only, no drawing allowed
665 virtual wxGraphicsContext * CreateMeasuringContext() = 0;
666
0d3675a6
RD
667 // Path
668
a4e73390 669 virtual wxGraphicsPath CreatePath() = 0;
9e605538 670
0d3675a6
RD
671 // Matrix
672
a4e73390 673 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
0d3675a6 674 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
9e605538
SC
675
676 // Paints
677
2c820406 678 virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0 ;
9e605538 679
2c820406 680 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) = 0 ;
9e605538
SC
681
682 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2c820406 683 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
9e605538
SC
684 const wxColour&c1, const wxColour&c2) = 0;
685
686 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
687 // with radius r and color cColor
2c820406 688 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
9e605538
SC
689 const wxColour &oColor, const wxColour &cColor) = 0;
690
691 // sets the font
2c820406 692 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) = 0;
9e605538
SC
693
694private :
0d3675a6 695 DECLARE_NO_COPY_CLASS(wxGraphicsRenderer)
9e605538
SC
696 DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer)
697} ;
698
774f4d12 699#endif
50581042 700
8acd14d1 701#endif // _WX_GRAPHICS_H_