| Version: 3.2.8

List of all members
wxGraphicsContext Class Referenceabstract
Class List by Category » Graphics Device Interface (GDI) | Class List by Category » Device Contexts

`#include <wx/graphics.h>`

Inheritance diagram for wxGraphicsContext:
[legend]

## Detailed Description

A wxGraphicsContext instance is the object that is drawn upon.

It is created by 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.

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;
}
}
wxGraphicsContext
A wxGraphicsContext instance is the object that is drawn upon.
Definition: graphics.h:429
wxGraphicsContext::Create
static wxGraphicsContext * Create()
Create a lightweight context that can be used only for measuring text.
wxGraphicsContext::StrokePath
virtual void StrokePath(const wxGraphicsPath &path)=0
Strokes along a path with the current pen.
wxGraphicsContext::SetPen
void SetPen(const wxPen &pen)
Sets the pen used for stroking.
wxGraphicsContext::CreatePath
wxGraphicsPath CreatePath() const
Creates a native graphics path which is initially empty.
wxGraphicsPath
A wxGraphicsPath is a native representation of a geometric path.
Definition: graphics.h:21
wxGraphicsPath::AddCircle
virtual void AddCircle(wxDouble x, wxDouble y, wxDouble r)
Appends a circle around (x,y) with radius r as a new closed subpath.
wxGraphicsPath::MoveToPoint
virtual void MoveToPoint(wxDouble x, wxDouble y)
Begins a new subpath at (x,y).
wxGraphicsPath::CloseSubpath
virtual void CloseSubpath()
Closes the current sub-path.
wxGraphicsPath::AddLineToPoint
virtual void AddLineToPoint(wxDouble x, wxDouble y)
Adds a straight line from the current point to (x,y).
wxGraphicsPath::AddRectangle
virtual void AddRectangle(wxDouble x, wxDouble y, wxDouble w, wxDouble h)
Appends a rectangle as a new closed subpath.
wxPaintDC
A wxPaintDC must be constructed if an application wishes to paint on the client area of a window from...
Definition: dcclient.h:30
wxPaintEvent
A paint event is sent when a window's contents needs to be repainted.
Definition: event.h:2265
wxRED_PEN
wxPen * wxRED_PEN
Red pen.
Definition: pen.h:541

Remarks
  For some renderers (like Direct2D or Cairo) processing of drawing operations may be deferred (Direct2D render target normally builds up a batch of rendering commands but defers processing of these commands, Cairo operates on a separate surface) so to make drawing results visible you need to update the content of the context by calling wxGraphicsContext::Flush() or by destroying the context.

##

Library: wxCore
Category: Graphics Device Interface (GDI), Device Contexts

See also
  wxGraphicsRenderer::CreateContext(), wxGCDC, wxDC

## Public Member Functions
Clipping region functions
virtual void | ResetClip ()=0
| Resets the clipping to original shape. More...
virtual void | Clip (const wxRegion &region)=0
| Sets the clipping region to the intersection of the given region and the previously set clipping region. More...
virtual void | Clip (wxDouble x, wxDouble y, wxDouble w, wxDouble h)=0
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
virtual void | GetClipBox (wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h)=0
| Returns bounding box of the current clipping region. More...
Transformation matrix
virtual wxGraphicsMatrix | CreateMatrix (wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, wxDouble tx=0.0, wxDouble ty=0.0) const
| Creates a native affine transformation matrix from the passed in values. More...
wxGraphicsMatrix | CreateMatrix (const wxAffineMatrix2DBase &mat) const
| Creates a native affine transformation matrix from the passed generic one. More...
virtual void | ConcatTransform (const wxGraphicsMatrix &matrix)=0
| Concatenates the passed in transform with the current transform of this context. More...
virtual wxGraphicsMatrix | GetTransform () const =0
| Gets the current transformation matrix of this context. More...
virtual void | Rotate (wxDouble angle)=0
| Rotates the current transformation matrix (in radians). More...
virtual void | Scale (wxDouble xScale, wxDouble yScale)=0
| Scales the current transformation matrix. More...
virtual void | SetTransform (const wxGraphicsMatrix &matrix)=0
| Sets the current transformation matrix of this context. More...
virtual void | Translate (wxDouble dx, wxDouble dy)=0
| Translates the current transformation matrix. More...
Brush and pen functions
virtual wxGraphicsBrush | CreateBrush (const wxBrush &brush) const
| Creates a native brush from a wxBrush. More...
wxGraphicsBrush | CreateLinearGradientBrush (wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxColour &c1, const wxColour &c2, const wxGraphicsMatrix &matrix=wxNullGraphicsMatrix) const
| Creates a native brush with a linear gradient. More...
wxGraphicsBrush | CreateLinearGradientBrush (wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2, const wxGraphicsGradientStops &stops, const wxGraphicsMatrix &matrix=wxNullGraphicsMatrix) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
virtual wxGraphicsBrush | CreateRadialGradientBrush (wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxColour &oColor, const wxColour &cColor, const wxGraphicsMatrix &matrix=wxNullGraphicsMatrix) const
| Creates a native brush with a radial gradient. More...
virtual wxGraphicsBrush | CreateRadialGradientBrush (wxDouble startX, wxDouble startY, wxDouble endX, wxDouble endY, wxDouble radius, const wxGraphicsGradientStops &stops, const wxGraphicsMatrix &matrix=wxNullGraphicsMatrix)=0
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
void | SetBrush (const wxBrush &brush)
| Sets the brush for filling paths. More...
virtual void | SetBrush (const wxGraphicsBrush &brush)
| Sets the brush for filling paths. More...
wxGraphicsPen | CreatePen (const wxPen &pen) const
| Creates a native pen from a wxPen. More...
wxGraphicsPen | CreatePen (const wxGraphicsPenInfo &info) const
| Creates a native pen from a wxGraphicsPenInfo. More...
void | SetPen (const wxPen &pen)
| Sets the pen used for stroking. More...
virtual void | SetPen (const wxGraphicsPen &pen)
| Sets the pen used for stroking. More...
Drawing functions
virtual void | DrawBitmap (const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h)=0
| Draws the bitmap. More...
virtual void | DrawBitmap (const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h)=0
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
virtual void | DrawEllipse (wxDouble x, wxDouble y, wxDouble w, wxDouble h)
| Draws an ellipse. More...
virtual void | DrawIcon (const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h)=0
| Draws the icon. More...
virtual void | DrawLines (size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)
| Draws a polygon. More...
virtual void | DrawPath (const wxGraphicsPath &path, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)
| Draws the path by first filling and then stroking. More...
virtual void | DrawRectangle (wxDouble x, wxDouble y, wxDouble w, wxDouble h)
| Draws a rectangle. More...
virtual void | DrawRoundedRectangle (wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius)
| Draws a rounded rectangle. More...
void | DrawText (const wxString &str, wxDouble x, wxDouble y)
| Draws text at the defined position. More...
void | DrawText (const wxString &str, wxDouble x, wxDouble y, wxDouble angle)
| Draws text at the defined position. More...
void | DrawText (const wxString &str, wxDouble x, wxDouble y, const wxGraphicsBrush &backgroundBrush)
| Draws text at the defined position. More...
void | DrawText (const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush &backgroundBrush)
| Draws text at the defined position. More...
wxGraphicsPath | CreatePath () const
| Creates a native graphics path which is initially empty. More...
virtual void | FillPath (const wxGraphicsPath &path, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)=0
| Fills the path with the current brush. More...
virtual void | StrokeLine (wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2)
| Strokes a single line. More...
virtual void | StrokeLines (size_t n, const wxPoint2DDouble *beginPoints, const wxPoint2DDouble *endPoints)
| Stroke disconnected lines from begin to end points, fastest method available for this purpose. More...
virtual void | StrokeLines (size_t n, const wxPoint2DDouble *points)
| Stroke lines connecting all the points. More...
virtual void | StrokePath (const wxGraphicsPath &path)=0
| Strokes along a path with the current pen. More...
Text functions
virtual wxGraphicsFont | CreateFont (const wxFont &font, const wxColour &col= *wxBLACK) const
| Creates a native graphics font from a wxFont and a text colour. More...
virtual wxGraphicsFont | CreateFont (double sizeInPixels, const wxString &facename, int flags=wxFONTFLAG_DEFAULT, const wxColour &col= *wxBLACK) const
| Creates a font object with the specified attributes. More...
void | SetFont (const wxFont &font, const wxColour &colour)
| Sets the font for drawing text. More...
virtual void | SetFont (const wxGraphicsFont &font)
| Sets the font for drawing text. More...
virtual void | GetPartialTextExtents (const wxString &text, wxArrayDouble &widths) const =0
| Fills the widths array with the widths from the beginning of text to the corresponding character of text. More...
virtual void | GetTextExtent (const wxString &text, wxDouble *width, wxDouble *height, wxDouble *descent, wxDouble *externalLeading) const =0
| Gets the dimensions of the string using the currently selected font. More...
Page and document start/end functions
virtual bool | StartDoc (const wxString &message)
| Begin a new document (relevant only for printing / pdf etc.) If there is a progress dialog, message will be shown. More...
virtual void | EndDoc ()
| Done with that document (relevant only for printing / pdf etc.) More...
virtual void | StartPage (wxDouble width=0, wxDouble height=0)
| Opens a new page (relevant only for printing / pdf etc.) with the given size in points. More...
virtual void | EndPage ()
| Ends the current page (relevant only for printing / pdf etc.) More...
Bitmap functions
virtual wxGraphicsBitmap | CreateBitmap (const wxBitmap &bitmap)=0
| Creates wxGraphicsBitmap from an existing wxBitmap. More...
virtual wxGraphicsBitmap | CreateBitmapFromImage (const wxImage &image)
| Creates wxGraphicsBitmap from an existing wxImage. More...
virtual wxGraphicsBitmap | CreateSubBitmap (const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h)=0
| Extracts a sub-bitmap from an existing bitmap. More...
Modifying the state
virtual void | BeginLayer (wxDouble opacity)=0
| All rendering will be done into a fully transparent temporary context. More...
virtual void | EndLayer ()=0
| Composites back the drawings into the context with the opacity given at the BeginLayer() call. More...
virtual void | PushState ()=0
| Push the current state (like transformations, clipping region and quality settings) of the context on a stack. More...
virtual void | PopState ()=0
| Sets current state of the context to the state saved by a preceding call to PushState() and removes that state from the stack of saved states. More...
virtual void | Flush ()
| Make sure that the current content of this context is immediately visible. More...
Getting/setting parameters
virtual void * | GetNativeContext ()=0
| Returns the native context (CGContextRef for Core Graphics, Graphics pointer for GDIPlus and cairo_t pointer for cairo). More...
virtual bool | SetAntialiasMode (wxAntialiasMode antialias)=0
| Sets the antialiasing mode, returns true if it supported. More...
virtual wxAntialiasMode | GetAntialiasMode () const
| Returns the current shape antialiasing mode. More...
virtual bool | SetInterpolationQuality (wxInterpolationQuality interpolation)=0
| Sets the interpolation quality, returns true if it is supported. More...
virtual wxInterpolationQuality | GetInterpolationQuality () const
| Returns the current interpolation quality. More...
virtual bool | SetCompositionMode (wxCompositionMode op)=0
| Sets the compositing operator, returns true if it supported. More...
virtual wxCompositionMode | GetCompositionMode () const
| Returns the current compositing operator. More...
void | GetSize (wxDouble *width, wxDouble *height) const
| Returns the size of the graphics context in device coordinates. More...
virtual void | GetDPI (wxDouble *dpiX, wxDouble *dpiY) const
| Returns the resolution of the graphics context in device points per inch. More...
wxWindow * | GetWindow () const
| Returns the associated window if any. More...
Offset management
virtual bool | ShouldOffset () const
| Helper to determine if a 0.5 offset should be applied for the drawing operation. More...
virtual void | EnableOffset (bool enable=true)
| Indicates whether the context should try to offset for pixel boundaries. More...
void | DisableOffset ()
| Helper to determine if a 0.5 offset should be applied for the drawing operation. More...
bool | OffsetEnabled () const
| Helper to determine if a 0.5 offset should be applied for the drawing operation. More...
wxSize | FromDIP (const wxSize &sz) const
| Convert DPI-independent pixel values to the value in pixels appropriate for the graphics context. More...
wxPoint | FromDIP (const wxPoint &pt) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
int | FromDIP (int d) const
| Convert DPI-independent value in pixels to the value in pixels appropriate for the graphics context. More...
wxSize | ToDIP (const wxSize &sz) const
| Convert pixel values of the current graphics context to DPI-independent pixel values. More...
wxPoint | ToDIP (const wxPoint &pt) const
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
int | ToDIP (int d) const
| Convert pixel values of the current graphics context to DPI-independent pixel values. More...
Public Member Functions inherited from wxGraphicsObject
wxGraphicsRenderer * | GetRenderer () const
| Returns the renderer that was used to create this instance, or NULL if it has not been initialized yet. More...
bool | IsNull () const
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to NULL the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...

## Static Public Member Functions
Creating a context
static wxGraphicsContext * | Create (wxWindow *window)
| Creates a wxGraphicsContext from a wxWindow. More...
static wxGraphicsContext * | Create (const wxWindowDC &windowDC)
| Creates a wxGraphicsContext from a wxWindowDC. More...
static wxGraphicsContext * | Create (const wxMemoryDC &memoryDC)
| Creates a wxGraphicsContext from a wxMemoryDC. More...
static wxGraphicsContext * | Create (const wxPrinterDC &printerDC)
| Creates a wxGraphicsContext from a wxPrinterDC. More...
static wxGraphicsContext * | Create (const wxEnhMetaFileDC &metaFileDC)
| Creates a wxGraphicsContext from a wxEnhMetaFileDC. More...
static wxGraphicsContext * | CreateFromUnknownDC (wxDC &dc)
| Creates a wxGraphicsContext from a DC of unknown specific type. More...
static wxGraphicsContext * | Create (wxImage &image)
| Creates a wxGraphicsContext associated with a wxImage. More...
static wxGraphicsContext * | CreateFromNative (void *context)
| Creates a wxGraphicsContext from a native context. More...
static wxGraphicsContext * | CreateFromNativeWindow (void *window)
| Creates a wxGraphicsContext from a native window. More...
static wxGraphicsContext * | CreateFromNativeHDC (WXHDC dc)
| Creates a wxGraphicsContext from a native DC handle. More...
static wxGraphicsContext * | Create ()
| Create a lightweight context that can be used only for measuring text. More...

## Additional Inherited Members
Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object. More...
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Member Function Documentation

## ◆ BeginLayer()

virtual void wxGraphicsContext::BeginLayer | ( | wxDouble | opacity | ) |
| pure virtual

All rendering will be done into a fully transparent temporary context.

Layers can be nested by making balanced calls to BeginLayer()/EndLayer().

## ◆ Clip() [1/2]

virtual void wxGraphicsContext::Clip | ( | const wxRegion & | region | ) |
| pure virtual

Sets the clipping region to the intersection of the given region and the previously set clipping region.

The clipping region is an area to which drawing is restricted.

Remarks
  - Clipping region should be given in logical coordinates.
  - Calling this function can only make the clipping region smaller, never larger.
  - You need to call ResetClip() first if you want to set the clipping region exactly to the region specified.
  - If resulting clipping region is empty, then all drawing upon the context is clipped out (all changes made by drawing operations are masked out).

## ◆ Clip() [2/2]

virtual void wxGraphicsContext::Clip | ( | wxDouble | x,
|  | wxDouble | y,
|  | wxDouble | w,
|  | wxDouble | h
| ) |  |
| pure virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

## ◆ ConcatTransform()

virtual void wxGraphicsContext::ConcatTransform | ( | const wxGraphicsMatrix & | matrix | ) |
| pure virtual

Concatenates the passed in transform with the current transform of this context.

## ◆ Create() [1/7]

static wxGraphicsContext* wxGraphicsContext::Create | ( |  | ) |
| static

Create a lightweight context that can be used only for measuring text.

## ◆ Create() [2/7]

static wxGraphicsContext* wxGraphicsContext::Create | ( | const wxEnhMetaFileDC & | metaFileDC | ) |
| static

Creates a wxGraphicsContext from a wxEnhMetaFileDC.

This function, as wxEnhMetaFileDC class itself, is only available only under MSW.

See also
  wxGraphicsRenderer::CreateContext()

## ◆ Create() [3/7]

static wxGraphicsContext* wxGraphicsContext::Create | ( | const wxMemoryDC & | memoryDC | ) |
| static

Creates a wxGraphicsContext from a wxMemoryDC.

See also
  wxGraphicsRenderer::CreateContext()

## ◆ Create() [4/7]

static wxGraphicsContext* wxGraphicsContext::Create | ( | const wxPrinterDC & | printerDC | ) |
| static

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 also
  wxGraphicsRenderer::CreateContext(), Printing Under Unix (GTK+)

## ◆ Create() [5/7]

static wxGraphicsContext* wxGraphicsContext::Create | ( | const wxWindowDC & | windowDC | ) |
| static

Creates a wxGraphicsContext from a wxWindowDC.

See also
  wxGraphicsRenderer::CreateContext()

## ◆ Create() [6/7]

static wxGraphicsContext* wxGraphicsContext::Create | ( | wxImage & | image | ) |
| static

Creates a wxGraphicsContext associated with a wxImage.

The image specifies the size of the context as well as whether alpha is supported (if wxImage::HasAlpha()) or not and the initial contents of the context. The image object must have a life time greater than that of the new context as the context copies its contents back to the image when it is destroyed.

Since
  2.9.3

## ◆ Create() [7/7]

static wxGraphicsContext* wxGraphicsContext::Create | ( | wxWindow * | window | ) |
| static

Creates a wxGraphicsContext from a wxWindow.

See also
  wxGraphicsRenderer::CreateContext()

## ◆ CreateBitmap()

virtual wxGraphicsBitmap wxGraphicsContext::CreateBitmap | ( | const wxBitmap & | bitmap | ) |
| pure virtual

Creates wxGraphicsBitmap from an existing wxBitmap.

Returns an invalid wxNullGraphicsBitmap on failure.

## ◆ CreateBitmapFromImage()

virtual wxGraphicsBitmap wxGraphicsContext::CreateBitmapFromImage | ( | const wxImage & | image | ) |
| virtual

Creates wxGraphicsBitmap from an existing wxImage.

This method is more efficient than converting wxImage to wxBitmap first and then calling CreateBitmap() but otherwise has the same effect.

Returns an invalid wxNullGraphicsBitmap on failure.

Since
  2.9.3

## ◆ CreateBrush()

virtual wxGraphicsBrush wxGraphicsContext::CreateBrush | ( | const wxBrush & | brush | ) | const
| virtual

Creates a native brush from a wxBrush.

## ◆ CreateFont() [1/2]

virtual wxGraphicsFont wxGraphicsContext::CreateFont | ( | const wxFont & | font,
|  | const wxColour & | col = `*wxBLACK`
| ) |  | const
| virtual

Creates a native graphics font from a wxFont and a text colour.

Remarks
  For Direct2D graphics fonts can be created from TrueType fonts only.

## ◆ CreateFont() [2/2]

virtual wxGraphicsFont wxGraphicsContext::CreateFont | ( | double | sizeInPixels,
|  | const wxString & | facename,
|  | int | flags = `wxFONTFLAG_DEFAULT`,
|  | const wxColour & | col = `*wxBLACK`
| ) |  | const
| virtual

Creates a font object with the specified attributes.

The use of overload taking wxFont is preferred, see wxGraphicsRenderer::CreateFont() for more details.

Remarks
  For Direct2D graphics fonts can be created from TrueType fonts only.

Since
  2.9.3

## ◆ CreateFromNative()

static wxGraphicsContext* wxGraphicsContext::CreateFromNative | ( | void * | context | ) |
| static

Creates a wxGraphicsContext from a native context.

This native context must be a CGContextRef for Core Graphics, a Graphics pointer for GDIPlus, or a cairo_t pointer for cairo.

See also
  wxGraphicsRenderer::CreateContextFromNativeContext()

## ◆ CreateFromNativeHDC()

static wxGraphicsContext* wxGraphicsContext::CreateFromNativeHDC | ( | WXHDC | dc | ) |
| static

Creates a wxGraphicsContext from a native DC handle.

Windows only.

See also
  wxGraphicsRenderer::CreateContextFromNativeHDC()

Since
  3.1.1

## ◆ CreateFromNativeWindow()

static wxGraphicsContext* wxGraphicsContext::CreateFromNativeWindow | ( | void * | window | ) |
| static

Creates a wxGraphicsContext from a native window.

See also
  wxGraphicsRenderer::CreateContextFromNativeWindow()

## ◆ CreateFromUnknownDC()

static wxGraphicsContext* wxGraphicsContext::CreateFromUnknownDC | ( | wxDC & | dc | ) |
| static

Creates a wxGraphicsContext from a DC of unknown specific type.

Creates a wxGraphicsContext if dc is a supported type (i.e. has a corresponding Create() method, e.g. wxWindowDC or wxMemoryDC). Returns NULL if the DC is unsupported.

This method is only useful as a helper in generic code that operates with wxDC and doesn't known its exact type. Use Create() instead if you know that the DC is e.g. wxWindowDC.

See also
  wxGraphicsRenderer::CreateContextFromUnknownDC()

Since
  3.1.1

## ◆ CreateLinearGradientBrush() [1/2]

wxGraphicsBrush wxGraphicsContext::CreateLinearGradientBrush | ( | wxDouble | x1,
|  | wxDouble | y1,
|  | wxDouble | x2,
|  | wxDouble | y2,
|  | const wxColour & | c1,
|  | const wxColour & | c2,
|  | const wxGraphicsMatrix & | matrix = `wxNullGraphicsMatrix`
| ) |  | const

Creates a native brush with a linear gradient.

The brush starts at (x1, y1) and ends at (x2, y2). Either just the start and end gradient colours (c1 and c2) or full set of gradient stops can be specified.

The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.

The matrix parameter was added in wxWidgets 3.1.3

## ◆ CreateLinearGradientBrush() [2/2]

wxGraphicsBrush wxGraphicsContext::CreateLinearGradientBrush | ( | wxDouble | x1,
|  | wxDouble | y1,
|  | wxDouble | x2,
|  | wxDouble | y2,
|  | const wxGraphicsGradientStops & | stops,
|  | const wxGraphicsMatrix & | matrix = `wxNullGraphicsMatrix`
| ) |  | const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

## ◆ CreateMatrix() [1/2]

wxGraphicsMatrix wxGraphicsContext::CreateMatrix | ( | const wxAffineMatrix2DBase & | mat | ) | const

Creates a native affine transformation matrix from the passed generic one.

Since
  2.9.4

## ◆ CreateMatrix() [2/2]

virtual wxGraphicsMatrix wxGraphicsContext::CreateMatrix | ( | wxDouble | a = `1.0`,
|  | wxDouble | b = `0.0`,
|  | wxDouble | c = `0.0`,
|  | wxDouble | d = `1.0`,
|  | wxDouble | tx = `0.0`,
|  | wxDouble | ty = `0.0`
| ) |  | const
| virtual

Creates a native affine transformation matrix from the passed in values.

The default parameters result in an identity matrix.

## ◆ CreatePath()

wxGraphicsPath wxGraphicsContext::CreatePath | ( |  | ) | const

Creates a native graphics path which is initially empty.

## ◆ CreatePen() [1/2]

wxGraphicsPen wxGraphicsContext::CreatePen | ( | const wxGraphicsPenInfo & | info | ) | const

Creates a native pen from a wxGraphicsPenInfo.

Since
  3.1.1

## ◆ CreatePen() [2/2]

wxGraphicsPen wxGraphicsContext::CreatePen | ( | const wxPen & | pen | ) | const

Creates a native pen from a wxPen.

Prefer to use the overload taking wxGraphicsPenInfo unless you already have a wxPen as constructing one only to pass it to this method is wasteful.

## ◆ CreateRadialGradientBrush() [1/2]

virtual wxGraphicsBrush wxGraphicsContext::CreateRadialGradientBrush | ( | wxDouble | startX,
|  | wxDouble | startY,
|  | wxDouble | endX,
|  | wxDouble | endY,
|  | wxDouble | radius,
|  | const wxColour & | oColor,
|  | const wxColour & | cColor,
|  | const wxGraphicsMatrix & | matrix = `wxNullGraphicsMatrix`
| ) |  | const
| virtual

Creates a native brush with a radial gradient.

The brush originates at (startX, startY) and ends on a circle around (endX, endY) with the given radius.

The gradient may be specified either by its start and end colours oColor and cColor or by a full set of gradient stops.

The version taking wxGraphicsGradientStops is new in wxWidgets 2.9.1.

The ability to apply a transformation matrix to the gradient was added in 3.1.3

## ◆ CreateRadialGradientBrush() [2/2]

virtual wxGraphicsBrush wxGraphicsContext::CreateRadialGradientBrush | ( | wxDouble | startX,
|  | wxDouble | startY,
|  | wxDouble | endX,
|  | wxDouble | endY,
|  | wxDouble | radius,
|  | const wxGraphicsGradientStops & | stops,
|  | const wxGraphicsMatrix & | matrix = `wxNullGraphicsMatrix`
| ) |  |
| pure virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

## ◆ CreateSubBitmap()

virtual wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap | ( | const wxGraphicsBitmap & | bitmap,
|  | wxDouble | x,
|  | wxDouble | y,
|  | wxDouble | w,
|  | wxDouble | h
| ) |  |
| pure virtual

Extracts a sub-bitmap from an existing bitmap.

## ◆ DisableOffset()

void wxGraphicsContext::DisableOffset | ( |  | ) |

Helper to determine if a 0.5 offset should be applied for the drawing operation.

## ◆ DrawBitmap() [1/2]

virtual void wxGraphicsContext::DrawBitmap | ( | const wxBitmap & | bmp,
|  | wxDouble | x,
|  | wxDouble | y,
|  | wxDouble | w,
|  | wxDouble | h
| ) |  |
| pure virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

## ◆ DrawBitmap() [2/2]

virtual void wxGraphicsContext::DrawBitmap | ( | const wxGraphicsBitmap & | bmp,
|  | wxDouble | x,
|  | wxDouble | y,
|  | wxDouble | w,
|  | wxDouble | h
| ) |  |
| pure virtual

Draws the bitmap.

In case of a mono bitmap, this is treated as a mask and the current brushed is used for filling.

## ◆ DrawEllipse()

virtual void wxGraphicsContext::DrawEllipse | ( | wxDouble | x,
|  | wxDouble | y,
|  | wxDouble | w,
|  | wxDouble | h
| ) |  |
| virtual

Draws an ellipse.

## ◆ DrawIcon()

virtual void wxGraphicsContext::DrawIcon | ( | const wxIcon & | icon,
|  | wxDouble | x,
|  | wxDouble | y,
|  | wxDouble | w,
|  | wxDouble | h
| ) |  |
| pure virtual

Draws the icon.

## ◆ DrawLines()

virtual void wxGraphicsContext::DrawLines | ( | size_t | n,
|  | const wxPoint2DDouble * | points,
|  | wxPolygonFillMode | fillStyle = `wxODDEVEN_RULE`
| ) |  |
| virtual

Draws a polygon.

## ◆ DrawPath()

virtual void wxGraphicsContext::DrawPath | ( | const wxGraphicsPath & | path,
|  | wxPolygonFillMode | fillStyle = `wxODDEVEN_RULE`
| ) |  |
| virtual

Draws the path by first filling and then stroking.

## ◆ DrawRectangle()

virtual void wxGraphicsContext::DrawRectangle | ( | wxDouble | x,
|  | wxDouble | y,
|  | wxDouble | w,
|  | wxDouble | h
| ) |  |
| virtual

Draws a rectangle.

## ◆ DrawRoundedRectangle()

virtual void wxGraphicsContext::DrawRoundedRectangle | ( | wxDouble | x,
|  | wxDouble | y,
|  | wxDouble | w,
|  | wxDouble | h,
|  | wxDouble | radius
| ) |  |
| virtual

Draws a rounded rectangle.

## ◆ DrawText() [1/4]

void wxGraphicsContext::DrawText | ( | const wxString & | str,
|  | wxDouble | x,
|  | wxDouble | y
| ) |  |

Draws text at the defined position.

## ◆ DrawText() [2/4]

void wxGraphicsContext::DrawText | ( | const wxString & | str,
|  | wxDouble | x,
|  | wxDouble | y,
|  | const wxGraphicsBrush & | backgroundBrush
| ) |  |

Draws text at the defined position.

Parameters

  str | The text to draw.
  x | The x coordinate position to draw the text at.
  y | The y coordinate position to draw the text at.
  backgroundBrush | Brush to fill the text with.

## ◆ DrawText() [3/4]

void wxGraphicsContext::DrawText | ( | const wxString & | str,
|  | wxDouble | x,
|  | wxDouble | y,
|  | wxDouble | angle
| ) |  |

Draws text at the defined position.

Parameters

  str | The text to draw.
  x | The x coordinate position to draw the text at.
  y | The y coordinate position to draw the text at.
  angle | The angle, in radians, relative to the (default) horizontal direction to draw the string.

## ◆ DrawText() [4/4]

void wxGraphicsContext::DrawText | ( | const wxString & | str,
|  | wxDouble | x,
|  | wxDouble | y,
|  | wxDouble | angle,
|  | const wxGraphicsBrush & | backgroundBrush
| ) |  |

Draws text at the defined position.

Parameters

  str | The text to draw.
  x | The x coordinate position to draw the text at.
  y | The y coordinate position to draw the text at.
  angle | The angle, in radians, relative to the (default) horizontal direction to draw the string.
  backgroundBrush | Brush to fill the text with.

## ◆ EnableOffset()

virtual void wxGraphicsContext::EnableOffset | ( | bool | enable = `true` | ) |
| virtual

Indicates whether the context should try to offset for pixel boundaries.

This only makes sense on bitmap devices like screen. By default this is turned off.

## ◆ EndDoc()

virtual void wxGraphicsContext::EndDoc | ( |  | ) |
| virtual

Done with that document (relevant only for printing / pdf etc.)

## ◆ EndLayer()

virtual void wxGraphicsContext::EndLayer | ( |  | ) |
| pure virtual

Composites back the drawings into the context with the opacity given at the BeginLayer() call.

## ◆ EndPage()

virtual void wxGraphicsContext::EndPage | ( |  | ) |
| virtual

Ends the current page (relevant only for printing / pdf etc.)

## ◆ FillPath()

virtual void wxGraphicsContext::FillPath | ( | const wxGraphicsPath & | path,
|  | wxPolygonFillMode | fillStyle = `wxODDEVEN_RULE`
| ) |  |
| pure virtual

Fills the path with the current brush.

## ◆ Flush()

virtual void wxGraphicsContext::Flush | ( |  | ) |
| virtual

Make sure that the current content of this context is immediately visible.

## ◆ FromDIP() [1/3]

wxPoint wxGraphicsContext::FromDIP | ( | const wxPoint & | pt | ) | const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

## ◆ FromDIP() [2/3]

wxSize wxGraphicsContext::FromDIP | ( | const wxSize & | sz | ) | const

Convert DPI-independent pixel values to the value in pixels appropriate for the graphics context.

See wxWindow::FromDIP(const wxSize& sz) and wxDC::FromDIP(const wxSize& sz) for more info about converting device independent pixel values.

Since
  3.1.7

## ◆ FromDIP() [3/3]

int wxGraphicsContext::FromDIP | ( | int | d | ) | const

Convert DPI-independent value in pixels to the value in pixels appropriate for the graphics context.

This is the same as FromDIP(const wxSize& sz) overload, but assumes that the resolution is the same in horizontal and vertical directions.

Since
  3.1.7

## ◆ GetAntialiasMode()

virtual wxAntialiasMode wxGraphicsContext::GetAntialiasMode | ( |  | ) | const
| virtual

Returns the current shape antialiasing mode.

## ◆ GetClipBox()

virtual void wxGraphicsContext::GetClipBox | ( | wxDouble * | x,
|  | wxDouble * | y,
|  | wxDouble * | w,
|  | wxDouble * | h
| ) |  |
| pure virtual

Returns bounding box of the current clipping region.

Remarks
  - If clipping region is empty, then empty rectangle is returned (x, y, w, h are set to zero).

Since
  3.1.1

## ◆ GetCompositionMode()

virtual wxCompositionMode wxGraphicsContext::GetCompositionMode | ( |  | ) | const
| virtual

Returns the current compositing operator.

## ◆ GetDPI()

virtual void wxGraphicsContext::GetDPI | ( | wxDouble * | dpiX,
|  | wxDouble * | dpiY
| ) |  | const
| virtual

Returns the resolution of the graphics context in device points per inch.

## ◆ GetInterpolationQuality()

virtual wxInterpolationQuality wxGraphicsContext::GetInterpolationQuality | ( |  | ) | const
| virtual

Returns the current interpolation quality.

## ◆ GetNativeContext()

virtual void* wxGraphicsContext::GetNativeContext | ( |  | ) |
| pure virtual

Returns the native context (CGContextRef for Core Graphics, Graphics pointer for GDIPlus and cairo_t pointer for cairo).

## ◆ GetPartialTextExtents()

virtual void wxGraphicsContext::GetPartialTextExtents | ( | const wxString & | text,
|  | wxArrayDouble & | widths
| ) |  | const
| pure virtual

Fills the widths array with the widths from the beginning of text to the corresponding character of text.

## ◆ GetSize()

void wxGraphicsContext::GetSize | ( | wxDouble * | width,
|  | wxDouble * | height
| ) |  | const

Returns the size of the graphics context in device coordinates.

## ◆ GetTextExtent()

virtual void wxGraphicsContext::GetTextExtent | ( | const wxString & | text,
|  | wxDouble * | width,
|  | wxDouble * | height,
|  | wxDouble * | descent,
|  | wxDouble * | externalLeading
| ) |  | const
| pure virtual

Gets the dimensions of the string using the currently selected font.

Parameters

  text | The text string to measure.
  width | Variable to store the total calculated width of the text.
  height | Variable to store the total calculated height of the text.
  descent | Variable to store the dimension from the baseline of the font to the bottom of the descender.
  externalLeading | Any extra vertical space added to the font by the font designer (usually is zero).

## ◆ GetTransform()

virtual wxGraphicsMatrix wxGraphicsContext::GetTransform | ( |  | ) | const
| pure virtual

Gets the current transformation matrix of this context.

## ◆ GetWindow()

wxWindow* wxGraphicsContext::GetWindow | ( |  | ) | const

Returns the associated window if any.

If this context was created using Create() overload taking wxWindow or wxWindowDC, this method returns the corresponding window. Otherwise returns NULL.

Returns
  A possibly NULL window pointer.

Since
  3.1.2

## ◆ OffsetEnabled()

bool wxGraphicsContext::OffsetEnabled | ( |  | ) | const

Helper to determine if a 0.5 offset should be applied for the drawing operation.

## ◆ PopState()

virtual void wxGraphicsContext::PopState | ( |  | ) |
| pure virtual

Sets current state of the context to the state saved by a preceding call to PushState() and removes that state from the stack of saved states.

See also
  PushState()

## ◆ PushState()

virtual void wxGraphicsContext::PushState | ( |  | ) |
| pure virtual

Push the current state (like transformations, clipping region and quality settings) of the context on a stack.

Multiple balanced calls to PushState() and PopState() can be nested.

See also
  PopState()

## ◆ ResetClip()

virtual void wxGraphicsContext::ResetClip | ( |  | ) |
| pure virtual

Resets the clipping to original shape.

## ◆ Rotate()

virtual void wxGraphicsContext::Rotate | ( | wxDouble | angle | ) |
| pure virtual

Rotates the current transformation matrix (in radians).

## ◆ Scale()

virtual void wxGraphicsContext::Scale | ( | wxDouble | xScale,
|  | wxDouble | yScale
| ) |  |
| pure virtual

Scales the current transformation matrix.

## ◆ SetAntialiasMode()

virtual bool wxGraphicsContext::SetAntialiasMode | ( | wxAntialiasMode | antialias | ) |
| pure virtual

Sets the antialiasing mode, returns true if it supported.

## ◆ SetBrush() [1/2]

void wxGraphicsContext::SetBrush | ( | const wxBrush & | brush | ) |

Sets the brush for filling paths.

## ◆ SetBrush() [2/2]

virtual void wxGraphicsContext::SetBrush | ( | const wxGraphicsBrush & | brush | ) |
| virtual

Sets the brush for filling paths.

## ◆ SetCompositionMode()

virtual bool wxGraphicsContext::SetCompositionMode | ( | wxCompositionMode | op | ) |
| pure virtual

Sets the compositing operator, returns true if it supported.

## ◆ SetFont() [1/2]

void wxGraphicsContext::SetFont | ( | const wxFont & | font,
|  | const wxColour & | colour
| ) |  |

Sets the font for drawing text.

Remarks
  For Direct2D only TrueType fonts can be used.

## ◆ SetFont() [2/2]

virtual void wxGraphicsContext::SetFont | ( | const wxGraphicsFont & | font | ) |
| virtual

Sets the font for drawing text.

## ◆ SetInterpolationQuality()

virtual bool wxGraphicsContext::SetInterpolationQuality | ( | wxInterpolationQuality | interpolation | ) |
| pure virtual

Sets the interpolation quality, returns true if it is supported.

Remarks
  Not implemented in Cairo backend currently.

## ◆ SetPen() [1/2]

virtual void wxGraphicsContext::SetPen | ( | const wxGraphicsPen & | pen | ) |
| virtual

Sets the pen used for stroking.

## ◆ SetPen() [2/2]

void wxGraphicsContext::SetPen | ( | const wxPen & | pen | ) |

Sets the pen used for stroking.

## ◆ SetTransform()

virtual void wxGraphicsContext::SetTransform | ( | const wxGraphicsMatrix & | matrix | ) |
| pure virtual

Sets the current transformation matrix of this context.

## ◆ ShouldOffset()

virtual bool wxGraphicsContext::ShouldOffset | ( |  | ) | const
| virtual

Helper to determine if a 0.5 offset should be applied for the drawing operation.

## ◆ StartDoc()

virtual bool wxGraphicsContext::StartDoc | ( | const wxString & | message | ) |
| virtual

Begin a new document (relevant only for printing / pdf etc.) If there is a progress dialog, message will be shown.

## ◆ StartPage()

virtual void wxGraphicsContext::StartPage | ( | wxDouble | width = `0`,
|  | wxDouble | height = `0`
| ) |  |
| virtual

Opens a new page (relevant only for printing / pdf etc.) with the given size in points.

(If both are null the default page size will be used.)

## ◆ StrokeLine()

virtual void wxGraphicsContext::StrokeLine | ( | wxDouble | x1,
|  | wxDouble | y1,
|  | wxDouble | x2,
|  | wxDouble | y2
| ) |  |
| virtual

Strokes a single line.

## ◆ StrokeLines() [1/2]

virtual void wxGraphicsContext::StrokeLines | ( | size_t | n,
|  | const wxPoint2DDouble * | beginPoints,
|  | const wxPoint2DDouble * | endPoints
| ) |  |
| virtual

Stroke disconnected lines from begin to end points, fastest method available for this purpose.

## ◆ StrokeLines() [2/2]

virtual void wxGraphicsContext::StrokeLines | ( | size_t | n,
|  | const wxPoint2DDouble * | points
| ) |  |
| virtual

Stroke lines connecting all the points.

Unlike the other overload of this function, this method draws a single polyline and not a number of disconnected lines.

## ◆ StrokePath()

virtual void wxGraphicsContext::StrokePath | ( | const wxGraphicsPath & | path | ) |
| pure virtual

Strokes along a path with the current pen.

## ◆ ToDIP() [1/3]

wxPoint wxGraphicsContext::ToDIP | ( | const wxPoint & | pt | ) | const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

## ◆ ToDIP() [2/3]

wxSize wxGraphicsContext::ToDIP | ( | const wxSize & | sz | ) | const

Convert pixel values of the current graphics context to DPI-independent pixel values.

See wxWindow::ToDIP(const wxSize& sz) and wxDC::ToDIP(const wxSize& sz) for more info about converting device independent pixel values.

Since
  3.1.7

## ◆ ToDIP() [3/3]

int wxGraphicsContext::ToDIP | ( | int | d | ) | const

Convert pixel values of the current graphics context to DPI-independent pixel values.

This is the same as ToDIP(const wxSize& sz) overload, but assumes that the resolution is the same in horizontal and vertical directions.

Since
  3.1.7

## ◆ Translate()

virtual void wxGraphicsContext::Translate | ( | wxDouble | dx,
|  | wxDouble | dy
| ) |  |
| pure virtual

Translates the current transformation matrix.