+
+
+ /**
+ Copy attributes from another DC.
+
+ The copied attributes currently are:
+ - Font
+ - Text foreground and background colours
+ - Background brush
+ - Layout direction
+
+ @param dc
+ A valid (i.e. its IsOk() must return @true) source device context.
+ */
+ void CopyAttributes(const wxDC& dc);
+
+ /**
+ Returns the depth (number of bits/pixel) of this DC.
+
+ @see wxDisplayDepth()
+ */
+ int GetDepth() const;
+
+ /**
+ Returns the current device origin.
+
+ @see SetDeviceOrigin()
+ */
+ wxPoint GetDeviceOrigin() const;
+
+ /**
+ Gets the current logical function.
+
+ @see SetLogicalFunction()
+ */
+ wxRasterOperationMode GetLogicalFunction() const;
+
+ /**
+ Gets the current mapping mode for the device context.
+
+ @see SetMapMode()
+ */
+ wxMappingMode GetMapMode() const;
+
+ /**
+ Gets in @a colour the colour at the specified location. Not available
+ for wxPostScriptDC or wxMetafileDC.
+
+ @note Setting a pixel can be done using DrawPoint().
+
+ @note This method shouldn't be used with wxPaintDC as accessing the DC
+ while drawing can result in unexpected results, notably in wxGTK.
+ */
+ bool GetPixel(wxCoord x, wxCoord y, wxColour* colour) const;
+
+ /**
+ Returns the resolution of the device in pixels per inch.
+ */
+ wxSize GetPPI() const;
+
+ /**
+ Gets the horizontal and vertical extent of this device context in @e device units.
+ It can be used to scale graphics to fit the page.
+
+ For example, if @e maxX and @e maxY represent the maximum horizontal
+ and vertical 'pixel' values used in your application, the following
+ code will scale the graphic to fit on the printer page:
+
+ @code
+ wxCoord w, h;
+ dc.GetSize(&w, &h);
+ double scaleX = (double)(maxX / w);
+ double scaleY = (double)(maxY / h);
+ dc.SetUserScale(min(scaleX, scaleY),min(scaleX, scaleY));
+ @endcode
+
+ @beginWxPerlOnly
+ In wxPerl there are two methods instead of a single overloaded
+ method:
+ - GetSize(): returns a Wx::Size object.
+ - GetSizeWH(): returns a 2-element list (width, height).
+ @endWxPerlOnly
+ */
+ void GetSize(wxCoord* width, wxCoord* height) const;
+
+ /**
+ @overload
+ */
+ wxSize GetSize() const;
+
+ /**
+ Returns the horizontal and vertical resolution in millimetres.
+ */
+ void GetSizeMM(wxCoord* width, wxCoord* height) const;
+
+ /**
+ @overload
+ */
+ wxSize GetSizeMM() const;
+
+ /**
+ Gets the current user scale factor.
+
+ @beginWxPerlOnly
+ In wxPerl this method takes no arguments and return a two
+ element array (x, y).
+ @endWxPerlOnly
+
+ @see SetUserScale()
+ */
+ void GetUserScale(double* x, double* y) const;
+
+ /**
+ Returns @true if the DC is ok to use.
+ */
+ bool IsOk() const;
+
+ /**
+ Sets the x and y axis orientation (i.e., the direction from lowest to
+ highest values on the axis). The default orientation is x axis from
+ left to right and y axis from top down.
+
+ @param xLeftRight
+ True to set the x axis orientation to the natural left to right
+ orientation, @false to invert it.
+ @param yBottomUp
+ True to set the y axis orientation to the natural bottom up
+ orientation, @false to invert it.
+ */
+ void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
+
+ /**
+ Sets the device origin (i.e., the origin in pixels after scaling has
+ been applied). This function may be useful in Windows printing
+ operations for placing a graphic on a page.
+ */
+ void SetDeviceOrigin(wxCoord x, wxCoord y);
+
+ /**
+ Sets the current logical function for the device context.
+ It determines how a @e source pixel (from a pen or brush colour, or source
+ device context if using Blit()) combines with a @e destination pixel in
+ the current device context.
+ Text drawing is not affected by this function.
+
+ See ::wxRasterOperationMode enumeration values for more info.
+
+ The default is @c wxCOPY, which simply draws with the current colour.
+ The others combine the current colour and the background using a logical
+ operation. @c wxINVERT is commonly used for drawing rubber bands or moving
+ outlines, since drawing twice reverts to the original colour.
+ */
+ void SetLogicalFunction(wxRasterOperationMode function);
+
+ /**
+ The mapping mode of the device context defines the unit of measurement
+ used to convert @e logical units to @e device units.
+
+ Note that in X, text drawing isn't handled consistently with the mapping mode;
+ a font is always specified in point size. However, setting the user scale (see
+ SetUserScale()) scales the text appropriately. In Windows, scalable
+ TrueType fonts are always used; in X, results depend on availability of
+ fonts, but usually a reasonable match is found.
+
+ The coordinate origin is always at the top left of the screen/printer.
+
+ Drawing to a Windows printer device context uses the current mapping
+ mode, but mapping mode is currently ignored for PostScript output.
+ */
+ void SetMapMode(wxMappingMode mode);
+
+ /**
+ If this is a window DC or memory DC, assigns the given palette to the
+ window or bitmap associated with the DC. If the argument is
+ ::wxNullPalette, the current palette is selected out of the device
+ context, and the original palette restored.
+
+ @see wxPalette
+ */
+ void SetPalette(const wxPalette& palette);
+
+ /**
+ Sets the user scaling factor, useful for applications which require
+ 'zooming'.
+ */
+ void SetUserScale(double xScale, double yScale);
+
+
+ /**
+ @name Transformation matrix
+
+ See the notes about the availability of these functions in the class
+ documentation.
+ */
+ //@{
+
+ /**
+ Check if the use of transformation matrix is supported by the current
+ system.
+
+ Currently this function always returns @false for non-MSW platforms and
+ may return @false for old (Windows 9x/ME) Windows systems. Normally
+ support for the transformation matrix is always available in any
+ relatively recent Windows versions.
+
+ @since 2.9.2
+ */
+ bool CanUseTransformMatrix() const;
+
+ /**
+ Set the transformation matrix.
+
+ If transformation matrix is supported on the current system, the
+ specified @a matrix will be used to transform between wxDC and physical
+ coordinates. Otherwise the function returns @false and doesn't change
+ the coordinate mapping.
+
+ @since 2.9.2
+ */
+ bool SetTransformMatrix(const wxAffineMatrix2D& matrix);
+
+ /**
+ Return the transformation matrix used by this device context.
+
+ By default the transformation matrix is the identity matrix.
+
+ @since 2.9.2
+ */
+ wxAffineMatrix2D GetTransformMatrix() const;
+
+ /**
+ Revert the transformation matrix to identity matrix.
+
+ @since 2.9.2
+ */
+ void ResetTransformMatrix();
+
+ //@}
+
+
+ /**
+ @name query capabilities
+ */
+ //@{
+
+ /**
+ Does the DC support drawing bitmaps?
+ */
+ bool CanDrawBitmap() const;
+
+ /**
+ Does the DC supoprt calculating the size required to draw text?
+ */
+ bool CanGetTextExtent() const;
+
+ //@}
+
+ /**
+ Returns a value that can be used as a handle to the native drawing
+ context, if this wxDC has something that could be thought of in that
+ way. (Not all of them do.)
+
+ For example, on Windows the return value is an HDC, on OSX it is a
+ CGContextRef and on wxGTK it will be a GdkDrawable. If the DC is a
+ wxGCDC then the return value will be the value returned from
+ wxGraphicsContext::GetNativeContext. A value of NULL is returned if
+ the DC does not have anything that fits the handle concept.
+
+ @since 2.9.5
+ */
+ void* GetHandle() const;
+
+
+ /**
+ If supported by the platform and the type of DC, fetch the contents of the DC, or a subset of it, as a bitmap.
+ */
+ wxBitmap GetAsBitmap(const wxRect *subrect = NULL) const;
+
+
+ void SetLogicalScale(double x, double y);
+ void GetLogicalScale(double *x, double *y) const;
+ void SetLogicalOrigin(wxCoord x, wxCoord y);
+ void GetLogicalOrigin(wxCoord *x, wxCoord *y) const;
+ wxPoint GetLogicalOrigin() const;
+
+};
+
+
+
+/**
+ @class wxDCClipper
+
+ wxDCClipper is a helper class for setting a clipping region on a wxDC
+ during its lifetime.
+
+ An object of wxDCClipper class is typically created on the stack so that it
+ is automatically destroyed when the object goes out of scope. A typical
+ usage example:
+
+ @code
+ void MyFunction(wxDC& dc)
+ {
+ wxDCClipper clip(dc, rect);
+ // ... drawing functions here are affected by clipping rect ...
+ }
+
+ void OtherFunction()
+ {
+ wxDC dc;
+ MyFunction(dc);
+ // ... drawing functions here are not affected by clipping rect ...
+ }
+ @endcode
+
+ @note Unlike other similar classes such as wxDCFontChanger, wxDCClipper
+ currently doesn't restore the previously active clipping region when it
+ is destroyed but simply resets clipping on the associated wxDC. This
+ may be changed in the future wxWidgets versions but has to be taken
+ into account explicitly in the current one.
+
+ @library{wxcore}
+ @category{gdi}
+
+ @see wxDC::SetClippingRegion(), wxDCFontChanger, wxDCTextColourChanger, wxDCPenChanger,
+ wxDCBrushChanger
+*/
+class wxDCClipper
+{
+public:
+ //@{
+ /**
+ Sets the clipping region to the specified region/coordinates.
+
+ The clipping region is automatically unset when this object is destroyed.
+ */
+ wxDCClipper(wxDC& dc, const wxRegion& region);
+ wxDCClipper(wxDC& dc, const wxRect& rect);
+ wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h);
+ //@}
+
+ /**
+ Destroys the clipping region associated with the DC passed to the ctor.
+ */
+ ~wxDCClipper();
+};
+
+
+/**
+ @class wxDCBrushChanger
+
+ wxDCBrushChanger is a small helper class for setting a brush on a wxDC
+ and unsetting it automatically in the destructor, restoring the previous one.
+
+ @library{wxcore}
+ @category{gdi}
+
+ @see wxDC::SetBrush(), wxDCFontChanger, wxDCTextColourChanger, wxDCPenChanger,
+ wxDCClipper
+*/
+class wxDCBrushChanger
+{
+public:
+ /**
+ Sets @a brush on the given @a dc, storing the old one.
+
+ @param dc
+ The DC where the brush must be temporary set.
+ @param brush
+ The brush to set.
+ */
+ wxDCBrushChanger(wxDC& dc, const wxBrush& brush);
+
+ /**
+ Restores the brush originally selected in the DC passed to the ctor.
+ */
+ ~wxDCBrushChanger();
+};
+
+
+/**
+ @class wxDCPenChanger
+
+ wxDCPenChanger is a small helper class for setting a pen on a wxDC
+ and unsetting it automatically in the destructor, restoring the previous one.
+
+ @library{wxcore}
+ @category{gdi}
+
+ @see wxDC::SetPen(), wxDCFontChanger, wxDCTextColourChanger, wxDCBrushChanger,
+ wxDCClipper
+*/
+class wxDCPenChanger
+{
+public:
+ /**
+ Sets @a pen on the given @a dc, storing the old one.
+
+ @param dc
+ The DC where the pen must be temporary set.
+ @param pen
+ The pen to set.
+ */
+ wxDCPenChanger(wxDC& dc, const wxPen& pen);
+
+ /**
+ Restores the pen originally selected in the DC passed to the ctor.
+ */
+ ~wxDCPenChanger();
+};
+
+
+
+/**
+ @class wxDCTextColourChanger
+
+ wxDCTextColourChanger is a small helper class for setting a foreground
+ text colour on a wxDC and unsetting it automatically in the destructor,
+ restoring the previous one.
+
+ @library{wxcore}
+ @category{gdi}
+
+ @see wxDC::SetTextForeground(), wxDCFontChanger, wxDCPenChanger, wxDCBrushChanger,
+ wxDCClipper
+*/
+class wxDCTextColourChanger
+{
+public:
+ /**
+ Trivial constructor not changing anything.
+
+ This constructor is useful if you don't know beforehand if the colour
+ needs to be changed or not. It simply creates the object which won't do
+ anything in its destructor unless Set() is called -- in which case it
+ would reset the previous colour.
+ */
+ wxDCTextColourChanger(wxDC& dc);
+
+ /**
+ Sets @a col on the given @a dc, storing the old one.
+
+ @param dc
+ The DC where the colour must be temporary set.
+ @param col
+ The colour to set.
+ */
+ wxDCTextColourChanger(wxDC& dc, const wxColour& col);
+
+ /**
+ Set the colour to use.
+
+ This method is meant to be called once only and only on the objects
+ created with the constructor overload not taking wxColour argument and
+ has the same effect as the other constructor, i.e. sets the colour to
+ the given @a col and ensures that the old value is restored when this
+ object is destroyed.
+ */
+ void Set(const wxColour& col);
+
+ /**
+ Restores the colour originally selected in the DC passed to the ctor.
+ */
+ ~wxDCTextColourChanger();
+};
+
+
+
+/**
+ @class wxDCFontChanger
+
+ wxDCFontChanger is a small helper class for setting a font on a wxDC and
+ unsetting it automatically in the destructor, restoring the previous one.
+
+ @since 2.9.0
+
+ @library{wxcore}
+ @category{gdi}
+
+ @see wxDC::SetFont(), wxDCTextColourChanger, wxDCPenChanger, wxDCBrushChanger,
+ wxDCClipper
+*/
+class wxDCFontChanger
+{
+public:
+ /**
+ Trivial constructor not changing anything.
+
+ This constructor is useful if you don't know beforehand if the font
+ needs to be changed or not. It simply creates the object which won't do
+ anything in its destructor unless Set() is called -- in which case it
+ would reset the previous font.
+
+ @since 2.9.1
+ */
+ wxDCFontChanger(wxDC& dc);
+
+ /**
+ Sets @a font on the given @a dc, storing the old one.
+
+ @param dc
+ The DC where the font must be temporary set.
+ @param font
+ The font to set.
+ */
+ wxDCFontChanger(wxDC& dc, const wxFont& font);
+
+ /**
+ Set the font to use.
+
+ This method is meant to be called once only and only on the objects
+ created with the constructor overload not taking wxColour argument and
+ has the same effect as the other constructor, i.e. sets the font to
+ the given @a font and ensures that the old value is restored when this
+ object is destroyed.
+ */
+ void Set(const wxFont& font);
+
+ /**
+ Restores the font originally selected in the DC passed to the ctor.
+ */
+ ~wxDCFontChanger();