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