Add OSXMakeDPIFromScaleFactor() helper

No real changes, just avoid repeating wxRound(scaleFactor*72) in several
places and do it in this single function instead.
This commit is contained in:
Vadim Zeitlin
2020-07-21 17:13:41 +02:00
parent a2c55fa834
commit a8bb796f8c
3 changed files with 14 additions and 3 deletions

View File

@@ -294,6 +294,9 @@ public:
// internal response to size events // internal response to size events
virtual void MacOnInternalSize() {} virtual void MacOnInternalSize() {}
// Return the DPI corresponding to the given scale factor.
static wxSize OSXMakeDPIFromScaleFactor(double scaleFactor);
protected: protected:
// For controls like radio buttons which are genuinely composite // For controls like radio buttons which are genuinely composite
wxList m_subControls; wxList m_subControls;

View File

@@ -629,8 +629,8 @@ extern int wxOSXGetIdFromSelector(SEL action );
doubleValue]; doubleValue];
if (newBackingScaleFactor != oldBackingScaleFactor) if (newBackingScaleFactor != oldBackingScaleFactor)
{ {
wxSize oldDPI((int)(oldBackingScaleFactor*72.0),(int)(oldBackingScaleFactor*72.0)); const wxSize oldDPI = wxWindow::OSXMakeDPIFromScaleFactor(oldBackingScaleFactor);
wxSize newDPI((int)(newBackingScaleFactor*72.0),(int)(newBackingScaleFactor*72.0)); const wxSize newDPI = wxWindow::OSXMakeDPIFromScaleFactor(newBackingScaleFactor);
wxDPIChangedEvent event(oldDPI, newDPI); wxDPIChangedEvent event(oldDPI, newDPI);
event.SetEventObject(wxpeer); event.SetEventObject(wxpeer);

View File

@@ -2620,6 +2620,14 @@ bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event )
return handled ; return handled ;
} }
/* static */
wxSize wxWindowMac::OSXMakeDPIFromScaleFactor(double scaleFactor)
{
const int dpi = wxRound(scaleFactor*72.0);
return wxSize(dpi, dpi);
}
wxSize wxWindowMac::GetDPI() const wxSize wxWindowMac::GetDPI() const
{ {
double scaleFactor; double scaleFactor;
@@ -2628,7 +2636,7 @@ wxSize wxWindowMac::GetDPI() const
else else
scaleFactor = wxOSXGetMainScreenContentScaleFactor(); scaleFactor = wxOSXGetMainScreenContentScaleFactor();
return wxSize(wxRound(scaleFactor*72.0),wxRound(scaleFactor*72.0)); return OSXMakeDPIFromScaleFactor(scaleFactor);
} }
// //