Make wxRescaleCoord() private functions
They're probably not that useful in application code, which should just use wxDPIChangedEvent::Scale() instead, so move them to a private header instead of making them part of the public API.
This commit is contained in:
@@ -3142,8 +3142,8 @@ public:
|
|||||||
|
|
||||||
// Scale the value by the ratio between new and old DPIs carried by this
|
// Scale the value by the ratio between new and old DPIs carried by this
|
||||||
// event.
|
// event.
|
||||||
int ScaleX(int x) const { return wxRescaleCoord(x, m_newDPI.x, m_oldDPI.x); }
|
int ScaleX(int x) const;
|
||||||
int ScaleY(int y) const { return wxRescaleCoord(y, m_newDPI.y, m_oldDPI.y); }
|
int ScaleY(int y) const;
|
||||||
|
|
||||||
wxSize Scale(wxSize sz) const { return wxSize(ScaleX(sz.x), ScaleY(sz.y)); }
|
wxSize Scale(wxSize sz) const { return wxSize(ScaleX(sz.x), ScaleY(sz.y)); }
|
||||||
|
|
||||||
|
@@ -1104,23 +1104,5 @@ extern wxRect WXDLLIMPEXP_CORE wxGetClientDisplayRect();
|
|||||||
// set global cursor
|
// set global cursor
|
||||||
extern void WXDLLIMPEXP_CORE wxSetCursor(const wxCursor& cursor);
|
extern void WXDLLIMPEXP_CORE wxSetCursor(const wxCursor& cursor);
|
||||||
|
|
||||||
// Scale the given value by the ratio between 2 other values, with rounding.
|
|
||||||
// Do not scale the value if it's -1, just return it unchanged in this case.
|
|
||||||
extern int WXDLLIMPEXP_CORE wxRescaleCoord(int n, int newScale, int oldScale);
|
|
||||||
|
|
||||||
inline wxPoint
|
|
||||||
wxRescaleCoord(wxPoint pt, wxSize newScale, wxSize oldScale)
|
|
||||||
{
|
|
||||||
return wxPoint(wxRescaleCoord(pt.x, newScale.x, oldScale.x),
|
|
||||||
wxRescaleCoord(pt.y, newScale.y, oldScale.y));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline wxSize
|
|
||||||
wxRescaleCoord(wxSize sz, wxSize newScale, wxSize oldScale)
|
|
||||||
{
|
|
||||||
return wxSize(wxRescaleCoord(sz.x, newScale.x, oldScale.x),
|
|
||||||
wxRescaleCoord(sz.y, newScale.y, oldScale.y));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// _WX_GDICMNH__
|
// _WX_GDICMNH__
|
||||||
|
43
include/wx/private/rescale.h
Normal file
43
include/wx/private/rescale.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: wx/private/rescale.h
|
||||||
|
// Purpose: Helpers for rescaling coordinates
|
||||||
|
// Author: Vadim Zeitlin
|
||||||
|
// Created: 2021-07-13
|
||||||
|
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _WX_PRIVATE_RESCALE_H_
|
||||||
|
#define _WX_PRIVATE_RESCALE_H_
|
||||||
|
|
||||||
|
#include "wx/gdicmn.h"
|
||||||
|
#include "wx/math.h"
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
// Required in order to use wxMulDivInt32().
|
||||||
|
#include "wx/msw/wrapwin.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Scale the given value by the ratio between 2 other values, with rounding.
|
||||||
|
// Do not scale the value if it's -1, just return it unchanged in this case.
|
||||||
|
inline int wxRescaleCoord(int n, int newScale, int oldScale)
|
||||||
|
{
|
||||||
|
return n == -1 ? -1 : wxMulDivInt32(n, newScale, oldScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline wxPoint
|
||||||
|
wxRescaleCoord(wxPoint pt, wxSize newScale, wxSize oldScale)
|
||||||
|
{
|
||||||
|
return wxPoint(wxRescaleCoord(pt.x, newScale.x, oldScale.x),
|
||||||
|
wxRescaleCoord(pt.y, newScale.y, oldScale.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline wxSize
|
||||||
|
wxRescaleCoord(wxSize sz, wxSize newScale, wxSize oldScale)
|
||||||
|
{
|
||||||
|
return wxSize(wxRescaleCoord(sz.x, newScale.x, oldScale.x),
|
||||||
|
wxRescaleCoord(sz.y, newScale.y, oldScale.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _WX_PRIVATE_RESCALE_H_
|
@@ -3450,7 +3450,8 @@ public:
|
|||||||
|
|
||||||
This is a convenience function to use in wxEVT_DPI_CHANGED event
|
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.
|
handlers, as they often need to update some sizes to the new DPI.
|
||||||
It simply calls wxRescaleCoord() with GetNewDPI() and GetOldDPI().
|
It simply calls wxMulDivInt32() with new and old DPI values, but
|
||||||
|
is more readable and less error-prone.
|
||||||
|
|
||||||
For example, the returned value will be twice bigger than the original
|
For example, the returned value will be twice bigger than the original
|
||||||
one when switching from normal (96) DPI to high (2x, 192) DPI.
|
one when switching from normal (96) DPI to high (2x, 192) DPI.
|
||||||
|
@@ -1344,21 +1344,3 @@ void wxDisplaySizeMM(int* width, int* height);
|
|||||||
*/
|
*/
|
||||||
wxSize wxGetDisplaySizeMM();
|
wxSize wxGetDisplaySizeMM();
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
/**
|
|
||||||
Scale the given value by the ratio between 2 other values, with rounding.
|
|
||||||
|
|
||||||
Do not scale the value if it's -1, just return it unchanged in this case.
|
|
||||||
|
|
||||||
This simply calls wxMulDivInt32() with the provided arguments, but provides
|
|
||||||
a more clear name for this operation.
|
|
||||||
|
|
||||||
@since 3.1.6
|
|
||||||
*/
|
|
||||||
int wxRescaleCoord(int n, int newScale, int oldScale);
|
|
||||||
|
|
||||||
/// @overload
|
|
||||||
wxPoint wxRescaleCoord(wxPoint pt, wxSize newScale, wxSize oldScale);
|
|
||||||
|
|
||||||
/// @overload
|
|
||||||
wxSize wxRescaleCoord(wxSize sz, wxSize newScale, wxSize oldScale);
|
|
||||||
|
@@ -51,6 +51,10 @@
|
|||||||
wxDEFINE_SCOPED_PTR(wxEvent, wxEventPtr)
|
wxDEFINE_SCOPED_PTR(wxEvent, wxEventPtr)
|
||||||
#endif // wxUSE_BASE
|
#endif // wxUSE_BASE
|
||||||
|
|
||||||
|
#if wxUSE_GUI
|
||||||
|
#include "wx/private/rescale.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxWin macros
|
// wxWin macros
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -933,6 +937,20 @@ wxHelpEvent::Origin wxHelpEvent::GuessOrigin(Origin origin)
|
|||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxDPIChangedEvent
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
int wxDPIChangedEvent::ScaleX(int x) const
|
||||||
|
{
|
||||||
|
return wxRescaleCoord(x, m_newDPI.x, m_oldDPI.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wxDPIChangedEvent::ScaleY(int y) const
|
||||||
|
{
|
||||||
|
return wxRescaleCoord(y, m_newDPI.y, m_oldDPI.y);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // wxUSE_GUI
|
#endif // wxUSE_GUI
|
||||||
|
|
||||||
|
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include "wx/display.h"
|
#include "wx/display.h"
|
||||||
#include "wx/gdiobj.h"
|
#include "wx/gdiobj.h"
|
||||||
#include "wx/math.h"
|
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
@@ -33,10 +32,6 @@
|
|||||||
#include "wx/math.h"
|
#include "wx/math.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
// Required in order to use wxMulDivInt32().
|
|
||||||
#include "wx/msw/wrapwin.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
wxIMPLEMENT_ABSTRACT_CLASS(wxGDIObject, wxObject);
|
wxIMPLEMENT_ABSTRACT_CLASS(wxGDIObject, wxObject);
|
||||||
|
|
||||||
@@ -926,8 +921,3 @@ wxResourceCache::~wxResourceCache ()
|
|||||||
node = node->GetNext ();
|
node = node->GetNext ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxRescaleCoord(int n, int newScale, int oldScale)
|
|
||||||
{
|
|
||||||
return n == -1 ? -1 : wxMulDivInt32(n, newScale, oldScale);
|
|
||||||
}
|
|
||||||
|
@@ -74,12 +74,9 @@
|
|||||||
#include "wx/display.h"
|
#include "wx/display.h"
|
||||||
#include "wx/platinfo.h"
|
#include "wx/platinfo.h"
|
||||||
#include "wx/recguard.h"
|
#include "wx/recguard.h"
|
||||||
|
#include "wx/private/rescale.h"
|
||||||
#include "wx/private/window.h"
|
#include "wx/private/window.h"
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
#include "wx/msw/wrapwin.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Windows List
|
// Windows List
|
||||||
WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows;
|
WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows;
|
||||||
|
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
#include "wx/stockitem.h"
|
#include "wx/stockitem.h"
|
||||||
#include "wx/msw/private/button.h"
|
#include "wx/msw/private/button.h"
|
||||||
#include "wx/msw/private/dc.h"
|
#include "wx/msw/private/dc.h"
|
||||||
|
#include "wx/private/rescale.h"
|
||||||
#include "wx/private/window.h"
|
#include "wx/private/window.h"
|
||||||
|
|
||||||
#if wxUSE_MARKUP
|
#if wxUSE_MARKUP
|
||||||
|
Reference in New Issue
Block a user