@wxheader{graphics.h}
A wxGraphicsContext instance is the object that is drawn upon. It is created by
- a renderer using the CreateContext calls.., this can be either directly using a renderer
- instance, or indirectly using the static convenience CreateXXX functions of
- wxGraphicsContext that always delegate the task to the default renderer.
+ a renderer using wxGraphicsRenderer::CreateContext(). This can be either directly
+ using a renderer instance, or indirectly using the static convenience Create()
+ functions of wxGraphicsContext that always delegate the task to the default renderer.
+
+ @code
+ void MyCanvas::OnPaint(wxPaintEvent &event)
+ {
+ // Create paint DC
+ wxPaintDC dc(this);
+
+ // Create graphics context from it
+ wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
+
+ if (gc)
+ {
+ // make a path that contains a circle and some lines
+ gc->SetPen( *wxRED_PEN );
+ wxGraphicsPath path = gc->CreatePath();
+ path.AddCircle( 50.0, 50.0, 50.0 );
+ path.MoveToPoint(0.0, 50.0);
+ path.AddLineToPoint(100.0, 50.0);
+ path.MoveToPoint(50.0, 0.0);
+ path.AddLineToPoint(50.0, 100.0 );
+ path.CloseSubpath();
+ path.AddRectangle(25.0, 25.0, 50.0, 50.0);
+
+ gc->StrokePath(path);
+
+ delete gc;
+ }
+ }
+ @endcode
+
@library{wxcore}
@category{FIXME}
- @see wxGraphicsRenderer:: CreateContext
+ @see wxGraphicsRenderer::CreateContext(), wxGCDC, wxDC
*/
class wxGraphicsContext : public wxGraphicsObject
{
public:
- //@{
/**
- Clips drawings to the rectangle.
+ Creates a wxGraphicsContext from a wxWindow.
+
+ @see wxGraphicsRenderer::CreateContext()
+ */
+ static wxGraphicsContext* Create( wxWindow* window ) ;
+
+ /**
+ Creates a wxGraphicsContext from a wxWindowDC
+
+ @see wxGraphicsRenderer::CreateContext()
+ */
+ static wxGraphicsContext* Create( const wxWindowDC& dc) ;
+
+ /**
+ Creates a wxGraphicsContext from a wxMemoryDC
+
+ @see wxGraphicsRenderer::CreateContext()
+ */
+ static wxGraphicsContext * Create( const wxMemoryDC& dc) ;
+
+ /**
+ Creates a wxGraphicsContext from a wxPrinterDC. Under
+ GTK+, this will only work when using the GtkPrint
+ printing backend which is available since GTK+ 2.10.
+
+ @see wxGraphicsRenderer::CreateContext(), @ref overview_unixprinting "Printing under Unix"
+ */
+ static wxGraphicsContext * Create( const wxPrinterDC& dc) ;
+
+ /**
+ Clips drawings to the region
*/
void Clip(const wxRegion& region);
+
+ /**
+ Clips drawings to the rectangle.
+ */
void Clip(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
- //@}
/**
Concatenates the passed in transform with the current transform of this context
*/
void ConcatTransform(const wxGraphicsMatrix& matrix);
- //@{
- /**
- Creates a wxGraphicsContext from a wxWindow.
-
- @see wxGraphicsRenderer:: CreateContext
- */
- wxGraphicsContext* Create(const wxWindowDC& dc);
- wxGraphicsContext* Create(wxWindow* window);
- //@}
/**
Creates a native brush from a wxBrush.
eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a
cairo_t pointer for cairo.
- Creates a wxGraphicsContext from a native window.
-
@see wxGraphicsRenderer:: CreateContextFromNativeContext
*/
wxGraphicsContext* CreateFromNative(void* context);
/**
+ Creates a wxGraphicsContext from a native window.
+
@see wxGraphicsRenderer:: CreateContextFromNativeWindow
*/
wxGraphicsContext* CreateFromNativeWindow(void* window);
@wxheader{graphics.h}
A wxGraphicsRenderer is the instance corresponding to the rendering engine
- used. There may be multiple instances on a system, if there are different rendering engines present, but there is always one instance per engine, eg there is ONE core graphics renderer instance on OSX. This instance is pointed back to by all objects created by it (wxGraphicsContext, wxGraphicsPath etc). Therefore you can create ag additional instances of paths etc. by calling GetRenderer() and then using the appropriate CreateXXX function.
+ used. There may be multiple instances on a system, if there are different
+ rendering engines present, but there is always only one instance per engine.
+ This instance is pointed back to by all objects created by it (wxGraphicsContext,
+ wxGraphicsPath etc) and can be retrieved through their wxGraphicsObject::GetRenderer()
+ method. Therefore you can create an additional instance of a path etc. by calling
+ wxGraphicsObject::GetRenderer() and then using the appropriate CreateXXX function
+ of that renderer.
+
+ @code
+ wxGraphicsPath *path = // from somewhere
+ wxGraphicsBrush *brush = path->GetRenderer()->CreateBrush( *wxBLACK_BRUSH );
+ @endcode
@library{wxcore}
@category{FIXME}
{
public:
/**
- Creates a native brush from a wxBrush.
+ Creates a wxGraphicsContext from a wxWindow.
*/
- wxGraphicsBrush CreateBrush(const wxBrush& brush);
+ virtual wxGraphicsContext* CreateContext(wxWindow* window) = 0;
+
+ /**
+ Creates a wxGraphicsContext from a wxWindowDC
+ */
+ virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) = 0 ;
+
+ /**
+ Creates a wxGraphicsContext from a wxMemoryDC
+ */
+ virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc) = 0 ;
+
+ /**
+ Creates a wxGraphicsContext from a wxPrinterDC
+ */
+ virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc) = 0 ;
- //@{
/**
- Creates a wxGraphicsContext from a wxWindow.
+ Creates a native brush from a wxBrush.
*/
- wxGraphicsContext* CreateContext(const wxWindowDC& dc);
- wxGraphicsContext* CreateContext(wxWindow* window);
- //@}
+ wxGraphicsBrush CreateBrush(const wxBrush& brush);
+
/**
Creates a wxGraphicsContext from a native context. This native context must be
- eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a cairo_t pointer for cairo.
+ eg a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus or a cairo_t
+ pointer for cairo.
*/
wxGraphicsContext* CreateContextFromNativeContext(void* context);
Returns the default renderer on this platform. On OS X this is the Core
Graphics (a.k.a. Quartz 2D) renderer, on MSW the GDIPlus renderer, and on GTK we currently default to the cairo renderer.
*/
- wxGraphicsRenderer* GetDefaultRenderer();
+ static wxGraphicsRenderer* GetDefaultRenderer();
};