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