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