]> git.saurik.com Git - wxWidgets.git/blame - include/wx/graphics.h
use wxRound(x), not int(x+0.5)
[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
SC
20#include "wx/dynarray.h"
21
b5dbe15d
VS
22class WXDLLIMPEXP_FWD_CORE wxWindowDC;
23class WXDLLIMPEXP_FWD_CORE wxMemoryDC;
220d37c8 24#if wxUSE_PRINTING_ARCHITECTURE
0b822969 25class WXDLLIMPEXP_FWD_CORE wxPrinterDC;
220d37c8 26#endif
b5dbe15d
VS
27class WXDLLIMPEXP_FWD_CORE wxGraphicsContext;
28class WXDLLIMPEXP_FWD_CORE wxGraphicsPath;
29class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrix;
30class WXDLLIMPEXP_FWD_CORE wxGraphicsFigure;
31class WXDLLIMPEXP_FWD_CORE wxGraphicsRenderer;
32class WXDLLIMPEXP_FWD_CORE wxGraphicsPen;
33class WXDLLIMPEXP_FWD_CORE wxGraphicsBrush;
34class WXDLLIMPEXP_FWD_CORE wxGraphicsFont;
1796d384 35class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap;
774f4d12 36
50581042
SC
37/*
38 * notes about the graphics context apis
39 *
0b7dce54 40 * angles : are measured in radians, 0.0 being in direction of positiv x axis, PI/2 being
50581042
SC
41 * in direction of positive y axis.
42 */
0b7dce54 43
9e605538 44// Base class of all objects used for drawing in the new graphics API, the always point back to their
0b7dce54 45// originating rendering engine, there is no dynamic unloading of a renderer currently allowed,
9e605538 46// these references are not counted
2c820406
SC
47
48//
49// The data used by objects like graphics pens etc is ref counted, in order to avoid unnecessary expensive
50// duplication. Any operation on a shared instance that results in a modified state, uncouples this
51// instance from the other instances that were shared - using copy on write semantics
52//
0b7dce54 53
3c419e81
SC
54class WXDLLIMPEXP_FWD_CORE wxGraphicsObjectRefData;
55class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrixData;
56class WXDLLIMPEXP_FWD_CORE wxGraphicsPathData;
2c820406 57
9e605538
SC
58class WXDLLIMPEXP_CORE wxGraphicsObject : public wxObject
59{
0b7dce54
VZ
60public:
61 wxGraphicsObject();
62 wxGraphicsObject( wxGraphicsRenderer* renderer );
63 virtual ~wxGraphicsObject();
64
65 bool IsNull() const;
2c820406
SC
66
67 // returns the renderer that was used to create this instance, or NULL if it has not been initialized yet
0b7dce54
VZ
68 wxGraphicsRenderer* GetRenderer() const;
69 wxGraphicsObjectRefData* GetGraphicsData() const;
70protected:
2c820406
SC
71 virtual wxObjectRefData* CreateRefData() const;
72 virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const;
73
39013ba0 74 DECLARE_DYNAMIC_CLASS(wxGraphicsObject)
0b7dce54 75};
9e605538
SC
76
77class WXDLLIMPEXP_CORE wxGraphicsPen : public wxGraphicsObject
78{
0b7dce54 79public:
2c820406 80 wxGraphicsPen() {}
9e605538 81 virtual ~wxGraphicsPen() {}
0b7dce54 82private:
2c820406 83 DECLARE_DYNAMIC_CLASS(wxGraphicsPen)
0b7dce54 84};
9e605538 85
53a2db12 86extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPen) wxNullGraphicsPen;
2c820406 87
9e605538
SC
88class WXDLLIMPEXP_CORE wxGraphicsBrush : public wxGraphicsObject
89{
0b7dce54 90public:
2c820406 91 wxGraphicsBrush() {}
9e605538 92 virtual ~wxGraphicsBrush() {}
0b7dce54 93private:
2c820406 94 DECLARE_DYNAMIC_CLASS(wxGraphicsBrush)
0b7dce54 95};
9e605538 96
53a2db12 97extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush;
2c820406 98
9e605538 99class WXDLLIMPEXP_CORE wxGraphicsFont : public wxGraphicsObject
50581042 100{
0b7dce54 101public:
2c820406 102 wxGraphicsFont() {}
9e605538 103 virtual ~wxGraphicsFont() {}
0b7dce54 104private:
2c820406 105 DECLARE_DYNAMIC_CLASS(wxGraphicsFont)
0b7dce54 106};
9e605538 107
53a2db12 108extern WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont;
2c820406 109
1796d384
SC
110class WXDLLIMPEXP_CORE wxGraphicsBitmap : public wxGraphicsObject
111{
0b7dce54 112public:
1796d384
SC
113 wxGraphicsBitmap() {}
114 virtual ~wxGraphicsBitmap() {}
0b7dce54 115private:
1796d384 116 DECLARE_DYNAMIC_CLASS(wxGraphicsBitmap)
0b7dce54
VZ
117};
118
53a2db12 119extern WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap;
1796d384 120
a4e73390
SC
121class WXDLLIMPEXP_CORE wxGraphicsMatrix : public wxGraphicsObject
122{
0b7dce54 123public:
a4e73390
SC
124 wxGraphicsMatrix() {}
125
126 virtual ~wxGraphicsMatrix() {}
127
128 // concatenates the matrix
129 virtual void Concat( const wxGraphicsMatrix *t );
130 void Concat( const wxGraphicsMatrix &t ) { Concat( &t ); }
131
132 // sets the matrix to the respective values
0b7dce54 133 virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
a4e73390
SC
134 wxDouble tx=0.0, wxDouble ty=0.0);
135
248802d0
RD
136 // gets the component valuess of the matrix
137 virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL,
138 wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const;
0b7dce54 139
a4e73390
SC
140 // makes this the inverse matrix
141 virtual void Invert();
142
143 // returns true if the elements of the transformation matrix are equal ?
144 virtual bool IsEqual( const wxGraphicsMatrix* t) const;
145 bool IsEqual( const wxGraphicsMatrix& t) const { return IsEqual( &t ); }
146
147 // return true if this is the identity matrix
148 virtual bool IsIdentity() const;
149
150 //
151 // transformation
152 //
153
154 // add the translation to this matrix
155 virtual void Translate( wxDouble dx , wxDouble dy );
156
157 // add the scale to this matrix
158 virtual void Scale( wxDouble xScale , wxDouble yScale );
159
160 // add the rotation to this matrix (radians)
0b7dce54 161 virtual void Rotate( wxDouble angle );
a4e73390
SC
162
163 //
164 // apply the transforms
165 //
166
167 // applies that matrix to the point
168 virtual void TransformPoint( wxDouble *x, wxDouble *y ) const;
169
170 // applies the matrix except for translations
171 virtual void TransformDistance( wxDouble *dx, wxDouble *dy ) const;
172
173 // returns the native representation
174 virtual void * GetNativeMatrix() const;
175
0b7dce54 176 const wxGraphicsMatrixData* GetMatrixData() const
a4e73390 177 { return (const wxGraphicsMatrixData*) GetRefData(); }
0b7dce54 178 wxGraphicsMatrixData* GetMatrixData()
a4e73390
SC
179 { return (wxGraphicsMatrixData*) GetRefData(); }
180
0b7dce54 181private:
a4e73390 182 DECLARE_DYNAMIC_CLASS(wxGraphicsMatrix)
0b7dce54 183};
a4e73390 184
53a2db12 185extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix) wxNullGraphicsMatrix;
a4e73390 186
a4e73390 187class WXDLLIMPEXP_CORE wxGraphicsPath : public wxGraphicsObject
774f4d12 188{
0b7dce54 189public:
a4e73390
SC
190 wxGraphicsPath() {}
191 virtual ~wxGraphicsPath() {}
0b7dce54 192
a4e73390
SC
193 //
194 // These are the path primitives from which everything else can be constructed
195 //
9e605538 196
a4e73390
SC
197 // begins a new subpath at (x,y)
198 virtual void MoveToPoint( wxDouble x, wxDouble y );
199 void MoveToPoint( const wxPoint2DDouble& p);
0d3675a6 200
0b7dce54 201 // adds a straight line from the current point to (x,y)
a4e73390
SC
202 virtual void AddLineToPoint( wxDouble x, wxDouble y );
203 void AddLineToPoint( const wxPoint2DDouble& p);
0d3675a6 204
a4e73390 205 // adds a cubic Bezier curve from the current point, using two control points and an end point
0b7dce54 206 virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y );
a4e73390 207 void AddCurveToPoint( const wxPoint2DDouble& c1, const wxPoint2DDouble& c2, const wxPoint2DDouble& e);
0b7dce54 208
a4e73390
SC
209 // adds another path
210 virtual void AddPath( const wxGraphicsPath& path );
211
212 // closes the current sub-path
0b7dce54 213 virtual void CloseSubpath();
a4e73390
SC
214
215 // gets the last point of the current path, (0,0) if not yet set
216 virtual void GetCurrentPoint( wxDouble* x, wxDouble* y) const;
217 wxPoint2DDouble GetCurrentPoint() const;
218
219 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
0b7dce54 220 virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise );
a4e73390
SC
221 void AddArc( const wxPoint2DDouble& c, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise);
222
774f4d12 223 //
0b7dce54 224 // These are convenience functions which - if not available natively will be assembled
a4e73390 225 // using the primitives from above
774f4d12 226 //
a4e73390
SC
227
228 // adds a quadratic Bezier curve from the current point, using a control point and an end point
229 virtual void AddQuadCurveToPoint( wxDouble cx, wxDouble cy, wxDouble x, wxDouble y );
230
0b7dce54 231 // appends a rectangle as a new closed subpath
a4e73390
SC
232 virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
233
234 // appends an ellipsis as a new closed subpath fitting the passed rectangle
235 virtual void AddCircle( wxDouble x, wxDouble y, wxDouble r );
236
237 // 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
238 virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r );
239
a4e73390
SC
240 // appends an ellipse
241 virtual void AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
774f4d12 242
a4e73390
SC
243 // appends a rounded rectangle
244 virtual void AddRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
774f4d12 245
a4e73390
SC
246 // returns the native path
247 virtual void * GetNativePath() const;
0b7dce54 248
a4e73390
SC
249 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
250 virtual void UnGetNativePath(void *p)const;
0b7dce54 251
a4e73390
SC
252 // transforms each point of this path by the matrix
253 virtual void Transform( const wxGraphicsMatrix& matrix );
0b7dce54 254
a4e73390
SC
255 // gets the bounding box enclosing all points (possibly including control points)
256 virtual void GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h)const;
257 wxRect2DDouble GetBox()const;
0b7dce54 258
a4e73390
SC
259 virtual bool Contains( wxDouble x, wxDouble y, int fillStyle = wxODDEVEN_RULE)const;
260 bool Contains( const wxPoint2DDouble& c, int fillStyle = wxODDEVEN_RULE)const;
0b7dce54
VZ
261
262 const wxGraphicsPathData* GetPathData() const
a4e73390 263 { return (const wxGraphicsPathData*) GetRefData(); }
0b7dce54 264 wxGraphicsPathData* GetPathData()
a4e73390
SC
265 { return (wxGraphicsPathData*) GetRefData(); }
266
0b7dce54 267private:
a4e73390 268 DECLARE_DYNAMIC_CLASS(wxGraphicsPath)
0b7dce54 269};
774f4d12 270
53a2db12 271extern WXDLLIMPEXP_DATA_CORE(wxGraphicsPath) wxNullGraphicsPath;
a4e73390
SC
272
273
9e605538 274class WXDLLIMPEXP_CORE wxGraphicsContext : public wxGraphicsObject
50581042
SC
275{
276public:
9e605538 277 wxGraphicsContext(wxGraphicsRenderer* renderer);
774f4d12 278
9e605538 279 virtual ~wxGraphicsContext();
0b7dce54
VZ
280
281 static wxGraphicsContext* Create( const wxWindowDC& dc);
282 static wxGraphicsContext * Create( const wxMemoryDC& dc);
220d37c8 283#if wxUSE_PRINTING_ARCHITECTURE
0b7dce54 284 static wxGraphicsContext * Create( const wxPrinterDC& dc);
220d37c8 285#endif
773ccc31 286
0b7dce54 287 static wxGraphicsContext* CreateFromNative( void * context );
774f4d12 288
0b7dce54 289 static wxGraphicsContext* CreateFromNativeWindow( void * window );
9a02779a 290
0b7dce54 291 static wxGraphicsContext* Create( wxWindow* window );
50581042 292
ad667945
SC
293 // create a context that can be used for measuring texts only, no drawing allowed
294 static wxGraphicsContext * Create();
295
cc18b1c7 296 // begin a new document (relevant only for printing / pdf etc) if there is a progress dialog, message will be shown
0b7dce54
VZ
297 virtual bool StartDoc( const wxString& message );
298
299 // done with that document (relevant only for printing / pdf etc)
cc18b1c7
SC
300 virtual void EndDoc();
301
0b7dce54 302 // opens a new page (relevant only for printing / pdf etc) with the given size in points
cc18b1c7
SC
303 // (if both are null the default page size will be used)
304 virtual void StartPage( wxDouble width = 0, wxDouble height = 0 );
0b7dce54
VZ
305
306 // ends the current page (relevant only for printing / pdf etc)
cc18b1c7 307 virtual void EndPage();
0b7dce54 308
cc18b1c7
SC
309 // make sure that the current content of this context is immediately visible
310 virtual void Flush();
311
a4e73390 312 wxGraphicsPath CreatePath() const;
0b7dce54 313
a4e73390 314 virtual wxGraphicsPen CreatePen(const wxPen& pen) const;
0b7dce54 315
a4e73390 316 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) const;
0b7dce54 317
9e605538 318 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
0b7dce54 319 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
a4e73390 320 const wxColour&c1, const wxColour&c2) const;
9e605538 321
0b7dce54 322 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
9e605538 323 // with radius r and color cColor
2c820406 324 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
a4e73390 325 const wxColour &oColor, const wxColour &cColor) const;
9e605538
SC
326
327 // sets the font
a4e73390 328 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) const;
9e605538 329
1796d384
SC
330 // create a native bitmap representation
331 virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) const;
0b7dce54 332
1796d384
SC
333 // create a native bitmap representation
334 virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) const;
335
0d3675a6 336 // create a 'native' matrix corresponding to these values
0b7dce54 337 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
a4e73390 338 wxDouble tx=0.0, wxDouble ty=0.0) const;
0b7dce54 339
50581042
SC
340 // push the current state of the context, ie the transformation matrix on a stack
341 virtual void PushState() = 0;
342
343 // pops a stored state from the stack
344 virtual void PopState() = 0;
345
cc18b1c7 346 // clips drawings to the region intersected with the current clipping region
50581042
SC
347 virtual void Clip( const wxRegion &region ) = 0;
348
cc18b1c7 349 // clips drawings to the rect intersected with the current clipping region
774f4d12 350 virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
0b7dce54 351
0d3675a6 352 // resets the clipping to original extent
0b7dce54 353 virtual void ResetClip() = 0;
774f4d12 354
0d3675a6
RD
355 // returns the native context
356 virtual void * GetNativeContext() = 0;
774f4d12 357
e22cf4b3 358 // returns the current logical function
89efaf2b 359 virtual wxRasterModeOperation GetLogicalFunction() const { return m_logicalFunction; }
0b7dce54 360
e22cf4b3 361 // sets the current logical function, returns true if it supported
89efaf2b 362 virtual bool SetLogicalFunction(wxRasterOperationMode function);
e22cf4b3 363
cc18b1c7
SC
364 // returns the size of the graphics context in device coordinates
365 virtual void GetSize( wxDouble* width, wxDouble* height);
366
367 // returns the resolution of the graphics context in device points per inch
368 virtual void GetDPI( wxDouble* dpiX, wxDouble* dpiY);
0b7dce54 369
cc18b1c7
SC
370#if 0
371 // sets the current alpha on this context
372 virtual void SetAlpha( wxDouble alpha );
0b7dce54 373
cc18b1c7
SC
374 // returns the alpha on this context
375 virtual wxDouble GetAlpha() const;
376#endif
50581042 377 //
774f4d12 378 // transformation : changes the current transformation matrix CTM of the context
50581042 379 //
0b7dce54 380
50581042
SC
381 // translate
382 virtual void Translate( wxDouble dx , wxDouble dy ) = 0;
383
384 // scale
385 virtual void Scale( wxDouble xScale , wxDouble yScale ) = 0;
386
387 // rotate (radians)
388 virtual void Rotate( wxDouble angle ) = 0;
0b7dce54 389
0d3675a6 390 // concatenates this transform with the current transform of this context
a4e73390 391 virtual void ConcatTransform( const wxGraphicsMatrix& matrix ) = 0;
9e605538 392
0d3675a6 393 // sets the transform of this context
a4e73390 394 virtual void SetTransform( const wxGraphicsMatrix& matrix ) = 0;
50581042 395
0d3675a6 396 // gets the matrix of this context
a4e73390 397 virtual wxGraphicsMatrix GetTransform() const = 0;
50581042
SC
398 //
399 // setting the paint
400 //
0b7dce54 401
9e605538 402 // sets the pen
2c820406 403 virtual void SetPen( const wxGraphicsPen& pen );
0b7dce54 404
9e605538 405 void SetPen( const wxPen& pen );
50581042
SC
406
407 // sets the brush for filling
2c820406 408 virtual void SetBrush( const wxGraphicsBrush& brush );
0b7dce54 409
9e605538 410 void SetBrush( const wxBrush& brush );
50581042
SC
411
412 // sets the font
2c820406 413 virtual void SetFont( const wxGraphicsFont& font );
0b7dce54 414
9e605538 415 void SetFont( const wxFont& font, const wxColour& colour );
0d3675a6 416
0b7dce54 417
50581042 418 // strokes along a path with the current pen
a4e73390 419 virtual void StrokePath( const wxGraphicsPath& path ) = 0;
50581042
SC
420
421 // fills a path with the current brush
a4e73390 422 virtual void FillPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE ) = 0;
50581042
SC
423
424 // draws a path by first filling and then stroking
a4e73390 425 virtual void DrawPath( const wxGraphicsPath& path, int fillStyle = wxODDEVEN_RULE );
0b7dce54 426
50581042
SC
427 //
428 // text
429 //
50581042 430
0b7dce54
VZ
431 void DrawText( const wxString &str, wxDouble x, wxDouble y )
432 { DoDrawText(str, x, y); }
433
434 void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle )
435 { DoDrawRotatedText(str, x, y, angle); }
436
437 void DrawText( const wxString &str, wxDouble x, wxDouble y,
438 const wxGraphicsBrush& backgroundBrush )
439 { DoDrawFilledText(str, x, y, backgroundBrush); }
50581042 440
0b7dce54
VZ
441 void DrawText( const wxString &str, wxDouble x, wxDouble y,
442 wxDouble angle, const wxGraphicsBrush& backgroundBrush )
443 { DoDrawRotatedFilledText(str, x, y, angle, backgroundBrush); }
068eb463 444
068eb463 445
50581042
SC
446 virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height,
447 wxDouble *descent, wxDouble *externalLeading ) const = 0;
448
449 virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const = 0;
450
451 //
452 // image support
453 //
454
d974a494 455#ifndef __WXGTK20__
1796d384 456 virtual void DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
d974a494 457#endif
1796d384 458
50581042
SC
459 virtual void DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
460
461 virtual void DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
462
463 //
464 // convenience methods
465 //
0b7dce54 466
50581042
SC
467 // strokes a single line
468 virtual void StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2);
469
470 // stroke lines connecting each of the points
471 virtual void StrokeLines( size_t n, const wxPoint2DDouble *points);
472
473 // stroke disconnected lines from begin to end points
474 virtual void StrokeLines( size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints);
475
476 // draws a polygon
a4e73390 477 virtual void DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle = wxODDEVEN_RULE );
50581042
SC
478
479 // draws a polygon
480 virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
481
482 // draws an ellipse
483 virtual void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
484
485 // draws a rounded rectangle
486 virtual void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
487
9e605538 488 // wrappers using wxPoint2DDouble TODO
50581042 489
de3cb39f
RD
490 // helper to determine if a 0.5 offset should be applied for the drawing operation
491 virtual bool ShouldOffset() const { return false; }
9e605538 492
0b7dce54 493protected:
9da34e21 494
2c820406
SC
495 wxGraphicsPen m_pen;
496 wxGraphicsBrush m_brush;
497 wxGraphicsFont m_font;
89efaf2b 498 wxRasterOperationMode m_logicalFunction;
9e605538 499
0b7dce54
VZ
500private:
501 // implementations of overloaded public functions: we use different names
502 // for them to avoid the virtual function hiding problems in the derived
503 // classes
504 virtual void DoDrawText(const wxString& str, wxDouble x, wxDouble y) = 0;
505 virtual void DoDrawRotatedText(const wxString& str, wxDouble x, wxDouble y,
506 wxDouble angle);
507 virtual void DoDrawFilledText(const wxString& str, wxDouble x, wxDouble y,
508 const wxGraphicsBrush& backgroundBrush);
509 virtual void DoDrawRotatedFilledText(const wxString& str,
510 wxDouble x, wxDouble y,
511 wxDouble angle,
512 const wxGraphicsBrush& backgroundBrush);
513
50581042 514 DECLARE_NO_COPY_CLASS(wxGraphicsContext)
8ddf8e82 515 DECLARE_ABSTRACT_CLASS(wxGraphicsContext)
50581042
SC
516};
517
0b7dce54 518#if 0
9e605538
SC
519
520//
521// A graphics figure allows to cache path, pen etc creations, also will be a basis for layering/grouping elements
522//
523
524class WXDLLIMPEXP_CORE wxGraphicsFigure : public wxGraphicsObject
525{
0b7dce54
VZ
526public:
527 wxGraphicsFigure(wxGraphicsRenderer* renderer);
528
529 virtual ~wxGraphicsFigure();
530
0d3675a6 531 void SetPath( wxGraphicsMatrix* matrix );
0b7dce54 532
0d3675a6
RD
533 void SetMatrix( wxGraphicsPath* path);
534
535 // draws this object on the context
536 virtual void Draw( wxGraphicsContext* cg );
0b7dce54 537
0d3675a6
RD
538 // returns the path of this object
539 wxGraphicsPath* GetPath() { return m_path; }
0b7dce54 540
0d3675a6
RD
541 // returns the transformation matrix of this object, may be null if there is no transformation necessary
542 wxGraphicsMatrix* GetMatrix() { return m_matrix; }
0b7dce54
VZ
543
544private:
0d3675a6
RD
545 wxGraphicsMatrix* m_matrix;
546 wxGraphicsPath* m_path;
0b7dce54 547
9e605538 548 DECLARE_DYNAMIC_CLASS(wxGraphicsFigure)
0b7dce54
VZ
549};
550
551#endif
9e605538
SC
552
553//
554// The graphics renderer is the instance corresponding to the rendering engine used, eg there is ONE core graphics renderer
555// instance on OSX. This instance is pointed back to by all objects created by it. Therefore you can create eg additional
556// paths at any point from a given matrix etc.
557//
558
559class WXDLLIMPEXP_CORE wxGraphicsRenderer : public wxObject
560{
0b7dce54 561public:
9e605538
SC
562 wxGraphicsRenderer() {}
563
564 virtual ~wxGraphicsRenderer() {}
565
0d3675a6 566 static wxGraphicsRenderer* GetDefaultRenderer();
9e605538 567
0d3675a6 568 // Context
9e605538 569
0b7dce54
VZ
570 virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) = 0;
571 virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc) = 0;
220d37c8 572#if wxUSE_PRINTING_ARCHITECTURE
0b7dce54 573 virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc) = 0;
220d37c8
SC
574#endif
575
0d3675a6 576 virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ) = 0;
9e605538 577
0d3675a6 578 virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) = 0;
9e605538 579
0d3675a6 580 virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0;
9e605538 581
ad667945
SC
582 // create a context that can be used for measuring texts only, no drawing allowed
583 virtual wxGraphicsContext * CreateMeasuringContext() = 0;
584
0d3675a6 585 // Path
0b7dce54 586
a4e73390 587 virtual wxGraphicsPath CreatePath() = 0;
9e605538 588
0d3675a6 589 // Matrix
0b7dce54
VZ
590
591 virtual wxGraphicsMatrix CreateMatrix( wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0,
0d3675a6 592 wxDouble tx=0.0, wxDouble ty=0.0) = 0;
0b7dce54 593
9e605538 594 // Paints
0b7dce54
VZ
595
596 virtual wxGraphicsPen CreatePen(const wxPen& pen) = 0;
597
598 virtual wxGraphicsBrush CreateBrush(const wxBrush& brush ) = 0;
599
9e605538 600 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
0b7dce54 601 virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
9e605538
SC
602 const wxColour&c1, const wxColour&c2) = 0;
603
0b7dce54 604 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
9e605538 605 // with radius r and color cColor
2c820406 606 virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
9e605538
SC
607 const wxColour &oColor, const wxColour &cColor) = 0;
608
609 // sets the font
2c820406 610 virtual wxGraphicsFont CreateFont( const wxFont &font , const wxColour &col = *wxBLACK ) = 0;
d974a494 611
0b7dce54 612#ifndef __WXGTK20__
1796d384
SC
613 // create a native bitmap representation
614 virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) = 0;
0b7dce54 615
1796d384
SC
616 // create a subimage from a native image representation
617 virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) = 0;
d974a494
RR
618#endif
619
620
0b7dce54 621private:
0d3675a6 622 DECLARE_NO_COPY_CLASS(wxGraphicsRenderer)
9e605538 623 DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer)
0b7dce54 624};
9e605538 625
774f4d12 626#endif
50581042 627
8acd14d1 628#endif // _WX_GRAPHICS_H_