#include <wx/dc.h>
Base class for device context not providing any drawing functions.
Objects of this class can't be created directly, please see wxDC for the description of how to create objects of the derived classes.
Public Member Functions | |
bool | IsOk () const |
Returns true if the DC is ok to use. More... | |
double | GetContentScaleFactor () const |
Returns the factor used for converting logical pixels to physical ones. More... | |
int | GetDepth () const |
Returns the depth (number of bits/pixel) of this DC. More... | |
wxPoint | GetDeviceOrigin () const |
Returns the current device origin. More... | |
wxMappingMode | GetMapMode () const |
Gets the current mapping mode for the device context. More... | |
wxSize | GetPPI () const |
Returns the resolution of the device in pixels per inch. More... | |
wxSize | FromDIP (const wxSize &sz) const |
Convert DPI-independent pixel values to the value in pixels appropriate for the DC. 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 DC. More... | |
wxSize | ToDIP (const wxSize &sz) const |
Convert pixel values of the current DC 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 DC to DPI-independent pixel values. More... | |
void | GetSize (wxCoord *width, wxCoord *height) const |
Gets the horizontal and vertical extent of this device context in device units. More... | |
wxSize | GetSize () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | GetSizeMM (wxCoord *width, wxCoord *height) const |
Returns the horizontal and vertical resolution in millimetres. More... | |
wxSize | GetSizeMM () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | GetUserScale (double *x, double *y) const |
Gets the current user scale factor. More... | |
const wxFont & | GetFont () const |
Gets the current font. More... | |
wxLayoutDirection | GetLayoutDirection () const |
Gets the current layout direction of the device context. More... | |
void | SetFont (const wxFont &font) |
Sets the current font for the DC. More... | |
void | SetLayoutDirection (wxLayoutDirection dir) |
Sets the current layout direction for the device context. More... | |
query capabilities | |
bool | CanDrawBitmap () const |
Does the DC support drawing bitmaps? More... | |
bool | CanGetTextExtent () const |
Does the DC support calculating the size required to draw text? More... | |
Coordinate conversion functions | |
wxCoord | DeviceToLogicalX (wxCoord x) const |
Convert device X coordinate to logical coordinate, using the current mapping mode, user scale factor, device origin and axis orientation. More... | |
wxCoord | DeviceToLogicalXRel (wxCoord x) const |
Convert device X coordinate to relative logical coordinate, using the current mapping mode and user scale factor but ignoring the axis orientation. More... | |
wxCoord | DeviceToLogicalY (wxCoord y) const |
Converts device Y coordinate to logical coordinate, using the current mapping mode, user scale factor, device origin and axis orientation. More... | |
wxCoord | DeviceToLogicalYRel (wxCoord y) const |
Convert device Y coordinate to relative logical coordinate, using the current mapping mode and user scale factor but ignoring the axis orientation. More... | |
wxCoord | LogicalToDeviceX (wxCoord x) const |
Converts logical X coordinate to device coordinate, using the current mapping mode, user scale factor, device origin and axis orientation. More... | |
wxCoord | LogicalToDeviceXRel (wxCoord x) const |
Converts logical X coordinate to relative device coordinate, using the current mapping mode and user scale factor but ignoring the axis orientation. More... | |
wxCoord | LogicalToDeviceY (wxCoord y) const |
Converts logical Y coordinate to device coordinate, using the current mapping mode, user scale factor, device origin and axis orientation. More... | |
wxCoord | LogicalToDeviceYRel (wxCoord y) const |
Converts logical Y coordinate to relative device coordinate, using the current mapping mode and user scale factor but ignoring the axis orientation. More... | |
wxPoint | DeviceToLogical (wxCoord x, wxCoord y) const |
Converts device (x, y) coordinates to logical coordinates taking into account all applied transformations like the current mapping mode, scale factors, device origin, axes orientation, affine transformation. More... | |
wxPoint | DeviceToLogical (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... | |
wxSize | DeviceToLogicalRel (int x, int y) const |
Converts device x, y coordinates to relative logical coordinates taking into account all applied transformations like the current mapping mode, scale factors, affine transformation. More... | |
wxSize | DeviceToLogicalRel (const wxSize &dim) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
wxPoint | LogicalToDevice (wxCoord x, wxCoord y) const |
Converts logical (x, y) coordinates to device coordinates taking into account all applied transformations like the current mapping mode, scale factors, device origin, axes orientation, affine transformation. More... | |
wxPoint | LogicalToDevice (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... | |
wxSize | LogicalToDeviceRel (int x, int y) const |
Converts logical x, y coordinates to relative device coordinates taking into account all applied transformations like the current mapping mode, scale factors, affine transformation. More... | |
wxSize | LogicalToDeviceRel (const wxSize &dim) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | SetAxisOrientation (bool xLeftRight, bool yBottomUp) |
Sets the x and y axis orientation (i.e. the direction from lowest to highest values on the axis). More... | |
void | SetDeviceOrigin (wxCoord x, wxCoord y) |
Sets the device origin (i.e. the origin in pixels after scaling has been applied). More... | |
void | SetMapMode (wxMappingMode mode) |
The mapping mode of the device context defines the unit of measurement used to convert logical units to device units. More... | |
void | SetUserScale (double xScale, double yScale) |
Sets the user scaling factor, useful for applications which require 'zooming'. More... | |
void | SetLogicalScale (double x, double y) |
Set the scale to use for translating wxDC coordinates to the physical pixels. More... | |
void | GetLogicalScale (double *x, double *y) const |
Return the scale set by the last call to SetLogicalScale(). More... | |
void | SetLogicalOrigin (wxCoord x, wxCoord y) |
Change the offset used for translating wxDC coordinates. More... | |
void | GetLogicalOrigin (wxCoord *x, wxCoord *y) const |
Return the coordinates of the logical point (0, 0). More... | |
wxPoint | GetLogicalOrigin () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
Transformation matrix | |
See the notes about the availability of these functions in the class documentation. | |
bool | CanUseTransformMatrix () const |
Check if the use of transformation matrix is supported by the current system. More... | |
bool | SetTransformMatrix (const wxAffineMatrix2D &matrix) |
Set the transformation matrix. More... | |
wxAffineMatrix2D | GetTransformMatrix () const |
Return the transformation matrix used by this device context. More... | |
void | ResetTransformMatrix () |
Revert the transformation matrix to identity matrix. More... | |
Text/character extent functions | |
wxCoord | GetCharHeight () const |
Gets the character height of the currently set font. More... | |
wxCoord | GetCharWidth () const |
Gets the average character width of the currently set font. More... | |
wxFontMetrics | GetFontMetrics () const |
Returns the various font characteristics. More... | |
void | GetMultiLineTextExtent (const wxString &string, wxCoord *w, wxCoord *h, wxCoord *heightLine=nullptr, const wxFont *font=nullptr) const |
Gets the dimensions of the string using the currently selected font. More... | |
wxSize | GetMultiLineTextExtent (const wxString &string) const |
Gets the dimensions of the string using the currently selected font. More... | |
bool | GetPartialTextExtents (const wxString &text, wxArrayInt &widths) const |
Fills the widths array with the widths from the beginning of text to the corresponding character of text. More... | |
void | GetTextExtent (const wxString &string, wxCoord *w, wxCoord *h, wxCoord *descent=nullptr, wxCoord *externalLeading=nullptr, const wxFont *font=nullptr) const |
Gets the dimensions of the string using the currently selected font. More... | |
wxSize | GetTextExtent (const wxString &string) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
Public Member Functions inherited from wxObject | |
wxObject () | |
Default ctor; initializes to nullptr 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=nullptr, int lineNum=0) |
The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. 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... | |
bool wxReadOnlyDC::CanDrawBitmap | ( | ) | const |
Does the DC support drawing bitmaps?
bool wxReadOnlyDC::CanGetTextExtent | ( | ) | const |
Does the DC support calculating the size required to draw text?
bool wxReadOnlyDC::CanUseTransformMatrix | ( | ) | const |
Check if the use of transformation matrix is supported by the current system.
This function returns true for MSW and GTK+ 3 platforms and since 3.1.1 also for wxGCDC in all ports.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Converts device (x, y) coordinates to logical coordinates taking into account all applied transformations like the current mapping mode, scale factors, device origin, axes orientation, affine transformation.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
wxSize wxReadOnlyDC::DeviceToLogicalRel | ( | int | x, |
int | y | ||
) | const |
Converts device x, y coordinates to relative logical coordinates taking into account all applied transformations like the current mapping mode, scale factors, affine transformation.
Use this for converting distances like e.g. width and height.
Convert device X coordinate to logical coordinate, using the current mapping mode, user scale factor, device origin and axis orientation.
Convert device X coordinate to relative logical coordinate, using the current mapping mode and user scale factor but ignoring the axis orientation.
Use this for converting a horizontal distance like for example a width.
Converts device Y coordinate to logical coordinate, using the current mapping mode, user scale factor, device origin and axis orientation.
Convert device Y coordinate to relative logical coordinate, using the current mapping mode and user scale factor but ignoring the axis orientation.
Use this for converting a vertical distance like for example a height.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Convert DPI-independent pixel values to the value in pixels appropriate for the DC.
See wxWindow::FromDIP(const wxSize& sz) for more info about converting device independent pixel values.
int wxReadOnlyDC::FromDIP | ( | int | d | ) | const |
Convert DPI-independent value in pixels to the value in pixels appropriate for the DC.
This is the same as FromDIP(const wxSize& sz) overload, but assumes that the resolution is the same in horizontal and vertical directions.
wxCoord wxReadOnlyDC::GetCharHeight | ( | ) | const |
Gets the character height of the currently set font.
wxCoord wxReadOnlyDC::GetCharWidth | ( | ) | const |
Gets the average character width of the currently set font.
double wxReadOnlyDC::GetContentScaleFactor | ( | ) | const |
Returns the factor used for converting logical pixels to physical ones.
Returns the same value as wxWindow::GetDPIScaleFactor() for the device contexts associated with a window and the same value as wxBitmap::GetScaleFactor() for the associated bitmap for wxMemoryDC.
int wxReadOnlyDC::GetDepth | ( | ) | const |
Returns the depth (number of bits/pixel) of this DC.
wxPoint wxReadOnlyDC::GetDeviceOrigin | ( | ) | const |
Returns the current device origin.
const wxFont& wxReadOnlyDC::GetFont | ( | ) | const |
Gets the current font.
Notice that even although each device context object has some default font after creation, this method would return a wxNullFont initially and only after calling SetFont() a valid font is returned.
wxFontMetrics wxReadOnlyDC::GetFontMetrics | ( | ) | const |
Returns the various font characteristics.
This method allows retrieving some of the font characteristics not returned by GetTextExtent(), notably internal leading and average character width.
Currently this method returns correct results only under wxMSW, in the other ports the internal leading will always be 0 and the average character width will be computed as the width of the character 'x'.
wxLayoutDirection wxReadOnlyDC::GetLayoutDirection | ( | ) | const |
Gets the current layout direction of the device context.
On platforms where RTL layout is supported, the return value will either be wxLayout_LeftToRight
or wxLayout_RightToLeft
. If RTL layout is not supported, the return value will be wxLayout_Default
.
wxPoint wxReadOnlyDC::GetLogicalOrigin | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Return the coordinates of the logical point (0, 0).
void wxReadOnlyDC::GetLogicalScale | ( | double * | x, |
double * | y | ||
) | const |
Return the scale set by the last call to SetLogicalScale().
wxMappingMode wxReadOnlyDC::GetMapMode | ( | ) | const |
Gets the current mapping mode for the device context.
Gets the dimensions of the string using the currently selected font.
string is the text string to measure.
wxPerl Note: Not supported by wxPerl.
void wxReadOnlyDC::GetMultiLineTextExtent | ( | const wxString & | string, |
wxCoord * | w, | ||
wxCoord * | h, | ||
wxCoord * | heightLine = nullptr , |
||
const wxFont * | font = nullptr |
||
) | const |
Gets the dimensions of the string using the currently selected font.
string is the text string to measure, heightLine, if non nullptr, is where to store the height of a single line.
The text extent is set in the given w and h pointers.
If the optional parameter font is specified and valid, then it is used for the text extent calculation, otherwise the currently selected font is used.
If string is empty, its horizontal extent is 0 but, for convenience when using this function for allocating enough space for a possibly multi-line string, its vertical extent is the same as the height of an empty line of text. Please note that this behaviour differs from that of GetTextExtent().
wxPerl Note: In wxPerl this method is implemented as GetMultiLineTextExtent(string, font = undef) returning a 3-element list (width, height, line_height)
bool wxReadOnlyDC::GetPartialTextExtents | ( | const wxString & | text, |
wxArrayInt & | widths | ||
) | const |
Fills the widths array with the widths from the beginning of text to the corresponding character of text.
The generic version simply builds a running total of the widths of each character using GetTextExtent(), however if the various platforms have a native API function that is faster or more accurate than the generic implementation then it should be used instead.
wxPerl Note: In wxPerl this method only takes the text parameter and returns the widths as a list of integers.
wxSize wxReadOnlyDC::GetPPI | ( | ) | const |
Returns the resolution of the device in pixels per inch.
wxSize wxReadOnlyDC::GetSize | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Gets the horizontal and vertical extent of this device context in device units.
It can be used to scale graphics to fit the page.
For example, if maxX and 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:
wxPerl Note: In wxPerl there are two methods instead of a single overloaded method:
wxSize wxReadOnlyDC::GetSizeMM | ( | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the horizontal and vertical resolution in millimetres.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
wxPerl Note: Not supported by wxPerl.
void wxReadOnlyDC::GetTextExtent | ( | const wxString & | string, |
wxCoord * | w, | ||
wxCoord * | h, | ||
wxCoord * | descent = nullptr , |
||
wxCoord * | externalLeading = nullptr , |
||
const wxFont * | font = nullptr |
||
) | const |
Gets the dimensions of the string using the currently selected font.
string is the text string to measure, descent is the dimension from the baseline of the font to the bottom of the descender, and externalLeading is any extra vertical space added to the font by the font designer (usually is zero).
The text extent is returned in w and h pointers or as a wxSize object depending on which version of this function is used.
If the optional parameter font is specified and valid, then it is used for the text extent calculation. Otherwise the currently selected font is.
If string is empty, its extent is 0 in both directions, as expected.
wxPerl Note: In wxPerl this method is implemented as GetTextExtent(string, font = undef) returning a 4-element list (width, height, descent, externalLeading)
wxAffineMatrix2D wxReadOnlyDC::GetTransformMatrix | ( | ) | const |
Return the transformation matrix used by this device context.
By default the transformation matrix is the identity matrix.
void wxReadOnlyDC::GetUserScale | ( | double * | x, |
double * | y | ||
) | const |
Gets the current user scale factor.
wxPerl Note: In wxPerl this method takes no arguments and return a two element array (x, y).
bool wxReadOnlyDC::IsOk | ( | ) | const |
Returns true if the DC is ok to use.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Converts logical (x, y) coordinates to device coordinates taking into account all applied transformations like the current mapping mode, scale factors, device origin, axes orientation, affine transformation.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
wxSize wxReadOnlyDC::LogicalToDeviceRel | ( | int | x, |
int | y | ||
) | const |
Converts logical x, y coordinates to relative device coordinates taking into account all applied transformations like the current mapping mode, scale factors, affine transformation.
Use this for converting distances like e.g. width and height.
Converts logical X coordinate to device coordinate, using the current mapping mode, user scale factor, device origin and axis orientation.
Converts logical X coordinate to relative device coordinate, using the current mapping mode and user scale factor but ignoring the axis orientation.
Use this for converting a horizontal distance like for example a width.
Converts logical Y coordinate to device coordinate, using the current mapping mode, user scale factor, device origin and axis orientation.
Converts logical Y coordinate to relative device coordinate, using the current mapping mode and user scale factor but ignoring the axis orientation.
Use this for converting a vertical distance like for example a height.
void wxReadOnlyDC::ResetTransformMatrix | ( | ) |
Revert the transformation matrix to identity matrix.
void wxReadOnlyDC::SetAxisOrientation | ( | bool | xLeftRight, |
bool | yBottomUp | ||
) |
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.
xLeftRight | True to set the x axis orientation to the natural left to right orientation, false to invert it. |
yBottomUp | True to set the y axis orientation to the natural bottom up orientation, false to invert it. |
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 wxReadOnlyDC::SetFont | ( | const wxFont & | font | ) |
Sets the current font for the DC.
The font parameter should be valid, although in wxMSW port (only) the argument wxNullFont is also accepted and resets the device context font to the default value used by the system (which is not generally useful).
void wxReadOnlyDC::SetLayoutDirection | ( | wxLayoutDirection | dir | ) |
Sets the current layout direction for the device context.
dir | May be either wxLayout_Default , wxLayout_LeftToRight or wxLayout_RightToLeft . |
Change the offset used for translating wxDC coordinates.
void wxReadOnlyDC::SetLogicalScale | ( | double | x, |
double | y | ||
) |
Set the scale to use for translating wxDC coordinates to the physical pixels.
The effect of calling this function is similar to that of calling SetUserScale().
void wxReadOnlyDC::SetMapMode | ( | wxMappingMode | mode | ) |
The mapping mode of the device context defines the unit of measurement used to convert logical units to 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.
bool wxReadOnlyDC::SetTransformMatrix | ( | const wxAffineMatrix2D & | matrix | ) |
Set the transformation matrix.
If transformation matrix is supported on the current system, the specified matrix will be used to transform between wxDC and physical coordinates. Otherwise the function returns false and doesn't change the coordinate mapping.
void wxReadOnlyDC::SetUserScale | ( | double | xScale, |
double | yScale | ||
) |
Sets the user scaling factor, useful for applications which require 'zooming'.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Convert pixel values of the current DC to DPI-independent pixel values.
See wxWindow::ToDIP(const wxSize& sz) for more info about converting device independent pixel values.
int wxReadOnlyDC::ToDIP | ( | int | d | ) | const |
Convert pixel values of the current DC 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.