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