Add wxDPIChangedEvent::Scale() and use it in this event handlers

This is more concise and less error-prone than multiplying/dividing DPI
values manually.

No real changes except, maybe, in wxSlider code where the rounding was
done differently before for some reason.
This commit is contained in:
Vadim Zeitlin
2021-07-11 19:31:51 +01:00
parent 453468f2f9
commit 3787f55a6b
9 changed files with 51 additions and 17 deletions

View File

@@ -3444,6 +3444,38 @@ public:
Returns the new DPI.
*/
wxSize GetNewDPI() const;
/**
Rescale a value in pixels to match the new DPI.
This is a convenience function to use in wxEVT_DPI_CHANGED event
handlers, as they often need to update some sizes to the new DPI.
It simply calls wxRescaleCoord() with GetNewDPI() and GetOldDPI().
For example, the returned value will be twice bigger than the original
one when switching from normal (96) DPI to high (2x, 192) DPI.
@since 3.1.6
*/
wxSize Scale(wxSize sz) const;
/**
Rescale horizontal component to match the new DPI.
This is the same as Scale(), but for the horizontal component only.
@since 3.1.6
*/
int ScaleX(int x) const;
/**
Rescale vertical component to match the new DPI.
This is the same as Scale(), but for the vertical component only.
@since 3.1.6
*/
int ScaleY(int y) const;
};