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