Merge branch 'memorydc-scale-factor-docs'

Improve wxMemoryDC docs.

See #22567.

See #22581.
This commit is contained in:
Vadim Zeitlin 2022-06-29 17:21:58 +02:00
commit 2e555335e4
2 changed files with 38 additions and 15 deletions

View file

@ -1500,6 +1500,9 @@ public:
- Background brush
- Layout direction
Note that the scaling factor is not considered to be an attribute of
wxDC and is @e not copied by this function.
@param dc
A valid (i.e. its IsOk() must return @true) source device context.
*/

View file

@ -38,6 +38,25 @@
This happens automatically when wxMemoryDC object goes out of scope.
Note that the scaling factor of the bitmap determines the scaling factor
used by this device context, so when using a memory device context as a
back buffer for a window, you should typically create the bitmap using the
same scale factor as used by the window, e.g.
@code
void MyWindow::OnPaint(wxPaintEvent&)
{
wxBitmap bmp;
bmp.CreateWithDIPSize(GetClientSize(), GetDPIScaleFactor());
{
wxMemoryDC memdc(bmp);
... use memdc to draw on the bitmap ...
}
wxPaintDC dc(this);
dc.DrawBitmap(bmp, wxPoint(0, 0));
}
@endcode
@library{wxcore}
@category{dc}
@ -76,13 +95,11 @@ public:
wxMemoryDC(wxBitmap& bitmap);
/**
Works exactly like SelectObjectAsSource() but this is the function you
should use when you select a bitmap because you want to modify it, e.g.
drawing on this DC.
Allow using this device context object to modify the given bitmap
contents.
Using SelectObjectAsSource() when modifying the bitmap may incur some
problems related to wxBitmap being a reference counted object (see
@ref overview_refcount).
Note that if you need to only use the existing bitmap contents instead
of modifying it, you should use SelectObjectAsSource() instead.
Before using the updated bitmap data, make sure to select it out of
context first either by selecting ::wxNullBitmap into the device
@ -91,22 +108,25 @@ public:
If the bitmap is already selected in this device context, nothing is
done. If it is selected in another context, the function asserts and
drawing on the bitmap won't work correctly.
@see wxDC::DrawBitmap()
*/
void SelectObject(wxBitmap& bitmap);
/**
Selects the given bitmap into the device context, to use as the memory
bitmap. Selecting the bitmap into a memory DC allows you to draw into
the DC (and therefore the bitmap) and also to use wxDC::Blit() to copy
the bitmap to a window. For this purpose, you may find wxDC::DrawIcon()
easier to use instead.
bitmap.
Selecting the bitmap as source into a memory DC allows you to copy its
contents to another device context using wxDC::Blit(). Note that using
wxDC::DrawBitmap() or wxDC::DrawIcon() is a simpler way to do the same
thing.
@note Modifying a bitmap selected only as a source may not work
correctly and can notably modify the other bitmaps sharing the same
data due to the use of reference counting (see @ref overview_refcount).
If the argument is ::wxNullBitmap (or some other uninitialised wxBitmap)
the current bitmap is selected out of the device context, and the
original bitmap restored, allowing the current bitmap to be destroyed
safely.
the current bitmap is selected out of the device context, allowing the
current bitmap to be destroyed safely.
*/
void SelectObjectAsSource(const wxBitmap& bitmap);