Use wxRescaleCoord() in wxMSW DPI update code too
Use the same scaling function as elsewhere instead of using ceil/floor(). Provide wxRescaleCoordWithFrom specialization for int to allow using it with just single coordinates too.
This commit is contained in:
@@ -82,6 +82,7 @@
|
||||
#include "wx/msw/dcclient.h"
|
||||
#include "wx/msw/seh.h"
|
||||
#include "wx/private/textmeasure.h"
|
||||
#include "wx/private/rescale.h"
|
||||
|
||||
#if wxUSE_TOOLTIPS
|
||||
#include "wx/tooltip.h"
|
||||
@@ -4891,20 +4892,9 @@ void wxWindowMSW::MSWUpdateFontOnDPIChange(const wxSize& newDPI)
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to update the given coordinate by the scaling factor if it
|
||||
// is set, i.e. different from wxDefaultCoord.
|
||||
static void ScaleCoordIfSet(int& coord, float scaleFactor)
|
||||
{
|
||||
if ( coord != wxDefaultCoord )
|
||||
{
|
||||
const float coordScaled = coord * scaleFactor;
|
||||
coord = int(scaleFactor > 1 ? std::ceil(coordScaled) : std::floor(coordScaled));
|
||||
}
|
||||
}
|
||||
|
||||
// Called from MSWUpdateonDPIChange() to recursively update the window
|
||||
// sizer and any child sizers and spacers.
|
||||
static void UpdateSizerOnDPIChange(wxSizer* sizer, float scaleFactor)
|
||||
static void UpdateSizerOnDPIChange(wxSizer* sizer, wxSize oldDPI, wxSize newDPI)
|
||||
{
|
||||
if ( !sizer )
|
||||
{
|
||||
@@ -4919,27 +4909,25 @@ static void UpdateSizerOnDPIChange(wxSizer* sizer, float scaleFactor)
|
||||
wxSizerItem* sizerItem = node->GetData();
|
||||
|
||||
int border = sizerItem->GetBorder();
|
||||
ScaleCoordIfSet(border, scaleFactor);
|
||||
border = wxRescaleCoord(border).From(oldDPI).To(newDPI);
|
||||
sizerItem->SetBorder(border);
|
||||
|
||||
// only scale sizers and spacers, not windows
|
||||
if ( sizerItem->IsSizer() || sizerItem->IsSpacer() )
|
||||
{
|
||||
wxSize min = sizerItem->GetMinSize();
|
||||
ScaleCoordIfSet(min.x, scaleFactor);
|
||||
ScaleCoordIfSet(min.y, scaleFactor);
|
||||
min = wxRescaleCoord(min).From(oldDPI).To(newDPI);
|
||||
sizerItem->SetMinSize(min);
|
||||
|
||||
if ( sizerItem->IsSpacer() )
|
||||
{
|
||||
wxSize size = sizerItem->GetSize();
|
||||
ScaleCoordIfSet(size.x, scaleFactor);
|
||||
ScaleCoordIfSet(size.y, scaleFactor);
|
||||
size = wxRescaleCoord(size).From(oldDPI).To(newDPI);
|
||||
sizerItem->SetDimension(wxDefaultPosition, size);
|
||||
}
|
||||
|
||||
// Update any child sizers if this is a sizer
|
||||
UpdateSizerOnDPIChange(sizerItem->GetSizer(), scaleFactor);
|
||||
UpdateSizerOnDPIChange(sizerItem->GetSizer(), oldDPI, newDPI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4948,12 +4936,10 @@ void
|
||||
wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI)
|
||||
{
|
||||
// update min and max size if necessary
|
||||
const float scaleFactor = (float)newDPI.y / oldDPI.y;
|
||||
|
||||
ScaleCoordIfSet(m_minHeight, scaleFactor);
|
||||
ScaleCoordIfSet(m_minWidth, scaleFactor);
|
||||
ScaleCoordIfSet(m_maxHeight, scaleFactor);
|
||||
ScaleCoordIfSet(m_maxWidth, scaleFactor);
|
||||
m_minHeight = wxRescaleCoord(m_minHeight).From(oldDPI).To(newDPI);
|
||||
m_minWidth = wxRescaleCoord(m_minWidth).From(oldDPI).To(newDPI);
|
||||
m_maxHeight = wxRescaleCoord(m_maxHeight).From(oldDPI).To(newDPI);
|
||||
m_maxWidth = wxRescaleCoord(m_maxWidth).From(oldDPI).To(newDPI);
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
@@ -4961,7 +4947,7 @@ wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI)
|
||||
MSWUpdateFontOnDPIChange(newDPI);
|
||||
|
||||
// update sizers
|
||||
UpdateSizerOnDPIChange(GetSizer(), scaleFactor);
|
||||
UpdateSizerOnDPIChange(GetSizer(), oldDPI, newDPI);
|
||||
|
||||
// update children
|
||||
for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
|
||||
|
||||
Reference in New Issue
Block a user