Add wxClientDC::CanBeUsedForDrawing()
This function can be used to check if drawing on wxClientDC actually works. This has to be a run-time, rather than compile-time, check because in wxGTK3 this depends on the backend being used: wxClientDC only doesn't work with Wayland, but does work with X11 (and, less importantly, Win32) backend(s). Currently the wxWindow parameter of this function is not used but it could be useful in the future and it will be simpler to allow not specifying it (by defaulting it to nullptr) than to add it later, so it seems better to have it.
This commit is contained in:
parent
aa14096ca9
commit
24fd54ed31
12 changed files with 80 additions and 6 deletions
|
|
@ -63,12 +63,13 @@ public:
|
|||
window from outside an EVT_PAINT() handler in some ports, this does @em not
|
||||
work on most of the platforms: neither wxOSX nor wxGTK with GTK 3 Wayland
|
||||
backend support this at all, so drawing using wxClientDC simply doesn't
|
||||
have any effect there, while wxMSW doesn't support using it for composited
|
||||
windows, so wxWindow::MSWDisableComposited() must be called to allow it to
|
||||
work. The only supported way of drawing on a window is via wxPaintDC. To
|
||||
redraw a small part of the window, use wxWindow::RefreshRect() to
|
||||
invalidate just this part and check wxWindow::GetUpdateRegion() in the
|
||||
paint event handler to redraw this part only.
|
||||
have any effect there. CanBeUsedForDrawing() can be used to determine
|
||||
whether wxClientDC can be used for drawing in the current environment, but
|
||||
it is recommended to only draw on the window using wxPaintDC, as this is
|
||||
guaranteed to work everywhere. To redraw a small part of the window, use
|
||||
wxWindow::RefreshRect() to invalidate just this part and check
|
||||
wxWindow::GetUpdateRegion() in the paint event handler to redraw this part
|
||||
only.
|
||||
|
||||
wxClientDC objects should normally be constructed as temporary stack
|
||||
objects, i.e. don't store a wxClientDC object.
|
||||
|
|
@ -88,6 +89,23 @@ public:
|
|||
Constructor. Pass a pointer to the window on which you wish to paint.
|
||||
*/
|
||||
wxClientDC(wxWindow* window);
|
||||
|
||||
/**
|
||||
Return true if drawing on wxClientDC actually works.
|
||||
|
||||
In many environments (currently this includes wxGTK when using Wayland
|
||||
backend, wxMSW when using double buffering and wxOSX in all cases),
|
||||
wxClientDC can be only used for obtaining information about the device
|
||||
context, but not for actually drawing on it. Portable code should avoid
|
||||
using wxClientDC completely, as explained in the class documentation,
|
||||
but it is also possible to optionally use it only when it does work,
|
||||
i.e. when this function returns @true.
|
||||
|
||||
@param window The window that would be used with wxClientDC.
|
||||
|
||||
@since 3.3.0
|
||||
*/
|
||||
static bool CanBeUsedForDrawing(const wxWindow* window);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue