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