- Wrapped GetDpiForWindow in GetWindowScalingFactor

- Use GetDeviceCaps for dpi on anything else than win10.
This commit is contained in:
HarrievG 2021-05-09 02:45:54 +02:00 committed by Daniel Gibson
parent 67d325cc61
commit e67b77ba5d
23 changed files with 54 additions and 59 deletions

View file

@ -863,6 +863,7 @@ if (TOOLS AND MFC_FOUND AND MSVC)
${src_sound_editor} ${src_sound_editor}
"tools/edit_public.h" "tools/edit_public.h"
"tools/edit_gui_common.h" "tools/edit_gui_common.h"
"tools/edit_gui_common.cpp"
) )
SET(CMAKE_MFC_FLAG 2) SET(CMAKE_MFC_FLAG 2)
set(TOOLS_DEFINES "ID_ALLOW_TOOLS;_AFXDLL") set(TOOLS_DEFINES "ID_ALLOW_TOOLS;_AFXDLL")

View file

@ -191,8 +191,7 @@ void CPropTree::OnSize(UINT nType, int cx, int cy)
void CPropTree::ResizeChildWindows(int cx, int cy) void CPropTree::ResizeChildWindows(int cx, int cy)
{ {
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int sh = int(m_nInfoHeight * scaling_factor); int sh = int(m_nInfoHeight * scaling_factor);
if (m_bShowInfo) if (m_bShowInfo)
@ -213,8 +212,7 @@ void CPropTree::ResizeChildWindows(int cx, int cy)
void CPropTree::InitGlobalResources() void CPropTree::InitGlobalResources()
{ {
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
NONCLIENTMETRICS info; NONCLIENTMETRICS info;

View file

@ -262,8 +262,7 @@ LONG CPropTreeItem::GetHeight()
{ {
if (m_pProp) if (m_pProp)
{ {
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
return PROPTREEITEM_DEFHEIGHT * scaling_factor; return PROPTREEITEM_DEFHEIGHT * scaling_factor;
} }
return PROPTREEITEM_DEFHEIGHT; return PROPTREEITEM_DEFHEIGHT;
@ -402,8 +401,7 @@ LONG CPropTreeItem::DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y)
ASSERT(m_pProp!=NULL); ASSERT(m_pProp!=NULL);
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int PNINDENT_s = int(PNINDENT * scaling_factor); int PNINDENT_s = int(PNINDENT * scaling_factor);
int PROPTREEITEM_SPACE_s = int(PROPTREEITEM_SPACE * scaling_factor); int PROPTREEITEM_SPACE_s = int(PROPTREEITEM_SPACE * scaling_factor);
int PROPTREEITEM_CHECKBOX_s = int(PROPTREEITEM_CHECKBOX * scaling_factor); int PROPTREEITEM_CHECKBOX_s = int(PROPTREEITEM_CHECKBOX * scaling_factor);

View file

@ -54,8 +54,7 @@ LONG CPropTreeItemButton::DrawItem( CDC* pDC, const RECT& rc, LONG x, LONG y )
nTotal = CPropTreeItem::DrawItem( pDC, rc, x, y ); nTotal = CPropTreeItem::DrawItem( pDC, rc, x, y );
textSize = pDC->GetOutputTextExtent( buttonText ); textSize = pDC->GetOutputTextExtent( buttonText );
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s2 = int(2 * scaling_factor); int s2 = int(2 * scaling_factor);
int s4 = int(4 * scaling_factor); int s4 = int(4 * scaling_factor);
int s12 = int(12 * scaling_factor); int s12 = int(12 * scaling_factor);

View file

@ -65,8 +65,7 @@ void CPropTreeItemCheck::DrawAttribute(CDC* pDC, const RECT& rc)
return; return;
} }
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int CHECK_BOX_SIZE_s = int(CHECK_BOX_SIZE * scaling_factor); int CHECK_BOX_SIZE_s = int(CHECK_BOX_SIZE * scaling_factor);
checkRect.left = m_rc.left; checkRect.left = m_rc.left;

View file

@ -221,8 +221,7 @@ void CPropTreeItemColor::OnActivate(int activateType, CPoint point)
m_cPrevColor = m_cColor; m_cPrevColor = m_cColor;
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
r = m_rc; r = m_rc;
r.right = r.left + 150 * scaling_factor; r.right = r.left + 150 * scaling_factor;
@ -261,8 +260,7 @@ void CPropTreeItemColor::OnPaint()
{ {
CPaintDC dc(this); CPaintDC dc(this);
CPoint pt; CPoint pt;
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s3 = int(3 * scaling_factor); int s3 = int(3 * scaling_factor);
int s7 = int(7 * scaling_factor); int s7 = int(7 * scaling_factor);
int s13 = int(13 * scaling_factor); int s13 = int(13 * scaling_factor);

View file

@ -128,8 +128,8 @@ void CPropTreeList::UpdateResize()
SCROLLINFO si; SCROLLINFO si;
LONG nHeight; LONG nHeight;
CRect rc; CRect rc;
UINT dpi = GetDpiForWindow(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f; float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
ASSERT(m_pProp!=NULL); ASSERT(m_pProp!=NULL);
@ -168,8 +168,7 @@ void CPropTreeList::OnPaint()
CRect rc; CRect rc;
GetClientRect(rc); GetClientRect(rc);
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
rc.InflateRect(scaling_factor, scaling_factor); rc.InflateRect(scaling_factor, scaling_factor);
// draw control background // draw control background
@ -572,8 +571,7 @@ void CPropTreeList::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*)
LONG nHeight; LONG nHeight;
SetFocus(); SetFocus();
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
GetClientRect(rc); GetClientRect(rc);
nHeight = rc.Height(); nHeight = rc.Height();

View file

@ -103,8 +103,7 @@ void CPropTreeView::OnPaint()
} }
void CPropTreeView::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { void CPropTreeView::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) {
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s20 = int(20 * scaling_factor); int s20 = int(20 * scaling_factor);
// #HvGNote : This should be the right way to do it, but hardcoded is fine too. // #HvGNote : This should be the right way to do it, but hardcoded is fine too.

View file

@ -587,8 +587,7 @@ bool rvPropertyGrid::ReflectMessage ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM
case WM_MEASUREITEM: case WM_MEASUREITEM:
{ {
UINT dpi = GetDpiForWindow(hWnd); float scaling_factor = GetWindowScalingFactor(hWnd);
float scaling_factor = static_cast<float>(dpi) / 96.0f;
MEASUREITEMSTRUCT* mis = (MEASUREITEMSTRUCT*) lParam; MEASUREITEMSTRUCT* mis = (MEASUREITEMSTRUCT*) lParam;
mis->itemHeight = 18 * scaling_factor; mis->itemHeight = 18 * scaling_factor;

View file

@ -659,8 +659,7 @@ void DialogDeclBrowser::OnSize( UINT nType, int cx, int cy ) {
GetClientRect( clientRect ); GetClientRect( clientRect );
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96;
float scaled_toolbar_height = (TOOLBAR_HEIGHT * scaling_factor); float scaled_toolbar_height = (TOOLBAR_HEIGHT * scaling_factor);
float scaled_button_space = (BUTTON_SPACE * scaling_factor); float scaled_button_space = (BUTTON_SPACE * scaling_factor);
float scaled_border_size = (BORDER_SIZE * scaling_factor); float scaled_border_size = (BORDER_SIZE * scaling_factor);

View file

@ -235,8 +235,7 @@ void DialogDeclEditor::LoadDecl( idDecl *decl ) {
SetWindowText( va( "Declaration Editor (%s, line %d)", decl->GetFileName(), decl->GetLineNum() ) ); SetWindowText( va( "Declaration Editor (%s, line %d)", decl->GetFileName(), decl->GetLineNum() ) );
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96;
rect.left = initialRect.left; rect.left = initialRect.left;
rect.right = rect.left + (maxCharsPerLine * FONT_WIDTH + 32) *scaling_factor; rect.right = rect.left + (maxCharsPerLine * FONT_WIDTH + 32) *scaling_factor;
@ -386,8 +385,7 @@ void DialogDeclEditor::OnSize( UINT nType, int cx, int cy ) {
CDialog::OnSize( nType, cx, cy ); CDialog::OnSize( nType, cx, cy );
GetClientRect( clientRect ); GetClientRect( clientRect );
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96;
float scaled_toolbar_height = (TOOLBAR_HEIGHT * scaling_factor); float scaled_toolbar_height = (TOOLBAR_HEIGHT * scaling_factor);
float scaled_button_space = (BUTTON_SPACE * scaling_factor); float scaled_button_space = (BUTTON_SPACE * scaling_factor);

View file

@ -0,0 +1,22 @@
#include "edit_gui_common.h"
//https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt
float GetWindowScalingFactor(HWND window)
{
float scaling_factor = 1.0f;
#if (WINVER == 0x0A00) // Windows 10
UINT dpi = GetDpiForWindow(window);
scaling_factor = static_cast<float>(dpi) / 96.0f;
#else
HDC hdc = GetDC(window);
int LogicalScreenHeight = GetDeviceCaps(hdc, VERTRES);
int PhysicalScreenHeight = GetDeviceCaps(hdc, DESKTOPVERTRES);
scaling_factor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight;
#endif
return scaling_factor;// 1.25 = 125%
}

View file

@ -179,4 +179,5 @@
// Compilers for map, model, video etc. processing. // Compilers for map, model, video etc. processing.
#include "tools/compilers/compiler_public.h" #include "tools/compilers/compiler_public.h"
float GetWindowScalingFactor(HWND window);
#endif // TOOLS_EDIT_GUI_COMMON_H #endif // TOOLS_EDIT_GUI_COMMON_H

View file

@ -334,8 +334,7 @@ void MEMainFrame::OnSize(UINT nType, int cx, int cy)
CFrameWnd::OnSize(nType, cx, cy); CFrameWnd::OnSize(nType, cx, cy);
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s5 = int(5 * scaling_factor); int s5 = int(5 * scaling_factor);
CRect statusRect; CRect statusRect;

View file

@ -241,8 +241,7 @@ void MaterialEditView::OnSize(UINT nType, int cx, int cy) {
m_tabs.GetItemRect(0, tabRect); m_tabs.GetItemRect(0, tabRect);
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s2 = int(2 * scaling_factor); int s2 = int(2 * scaling_factor);
int s8 = int(8 * scaling_factor); int s8 = int(8 * scaling_factor);
int s4 = int(4 * scaling_factor); int s4 = int(4 * scaling_factor);

View file

@ -160,8 +160,7 @@ void ToggleListView::OnSize(UINT nType, int cx, int cy) {
* Returns the size of each item in the toggle list. * Returns the size of each item in the toggle list.
*/ */
void ToggleListView::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { void ToggleListView::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) {
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
lpMeasureItemStruct->itemHeight = TOGGLELIST_ITEMHEIGHT * scaling_factor; lpMeasureItemStruct->itemHeight = TOGGLELIST_ITEMHEIGHT * scaling_factor;
} }

View file

@ -938,8 +938,7 @@ void CDialogTextures::OnSize(UINT nType, int cx, int cy)
return; return;
} }
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s8 = int(8 * scaling_factor); int s8 = int(8 * scaling_factor);
int s4 = int(4 * scaling_factor); int s4 = int(4 * scaling_factor);
int s12 = int(12 * scaling_factor); int s12 = int(12 * scaling_factor);

View file

@ -74,9 +74,7 @@ void CEditViewDlg::OnSize(UINT nType, int cx, int cy) {
return; return;
} }
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
UINT dpi = GetDpiForWindow(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s2 = int(2 * scaling_factor); int s2 = int(2 * scaling_factor);
int s8 = int(8 * scaling_factor); int s8 = int(8 * scaling_factor);
int s4 = int(4 * scaling_factor); int s4 = int(4 * scaling_factor);

View file

@ -164,9 +164,8 @@ void CEntityDlg::OnSize(UINT nType, int cx, int cy)
CDialog::OnSize(nType, cx, cy); CDialog::OnSize(nType, cx, cy);
CRect rect, crect, crect2; CRect rect, crect, crect2;
GetClientRect(rect); GetClientRect(rect);
float scaling_factor = GetWindowScalingFactor(staticTitle.GetSafeHwnd());
UINT dpi = GetDpiForWindow(staticTitle.GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s2 = int( 2 * scaling_factor); int s2 = int( 2 * scaling_factor);
int s8 = int( 8 * scaling_factor); int s8 = int( 8 * scaling_factor);
int s4 = int( 4 * scaling_factor); int s4 = int( 4 * scaling_factor);

View file

@ -131,8 +131,7 @@ void CInspectorDialog::OnSize(UINT nType, int cx, int cy)
POSITION pos; POSITION pos;
WORD wID; WORD wID;
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s5 = int(5 * scaling_factor); int s5 = int(5 * scaling_factor);
int s4 = int(4 * scaling_factor); int s4 = int(4 * scaling_factor);

View file

@ -1797,8 +1797,7 @@ void CMainFrame::OnSize(UINT nType, int cx, int cy) {
CRect rctParent; CRect rctParent;
GetClientRect(rctParent); GetClientRect(rctParent);
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
UINT nID; UINT nID;
UINT nStyle; UINT nStyle;

View file

@ -108,8 +108,7 @@ BOOL CMediaPreviewDlg::OnInitDialog()
void CMediaPreviewDlg::OnSize(UINT nType, int cx, int cy) void CMediaPreviewDlg::OnSize(UINT nType, int cx, int cy)
{ {
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s8 = int(8 * scaling_factor); int s8 = int(8 * scaling_factor);
int s4 = int(4 * scaling_factor); int s4 = int(4 * scaling_factor);

View file

@ -88,8 +88,7 @@ BOOL CPropertyList::PreCreateWindow(CREATESTRUCT& cs) {
} }
void CPropertyList::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { void CPropertyList::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) {
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s20 = int(20 * scaling_factor); int s20 = int(20 * scaling_factor);
if (measureItem && !measureItem->m_curValue.IsEmpty()) { if (measureItem && !measureItem->m_curValue.IsEmpty()) {
@ -111,8 +110,7 @@ void CPropertyList::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) {
void CPropertyList::DrawItem(LPDRAWITEMSTRUCT lpDIS) { void CPropertyList::DrawItem(LPDRAWITEMSTRUCT lpDIS) {
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s3 = 3;// int(3 * scaling_factor); int s3 = 3;// int(3 * scaling_factor);
CDC dc; CDC dc;
@ -196,8 +194,7 @@ void CPropertyList::OnSelchange() {
static int recurse = 0; static int recurse = 0;
//m_curSel = GetCurSel(); //m_curSel = GetCurSel();
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s3 = int(3 * scaling_factor); int s3 = int(3 * scaling_factor);
GetItemRect(m_curSel,rect); GetItemRect(m_curSel,rect);
@ -280,8 +277,7 @@ void CPropertyList::DisplayButton(CRect region) {
//displays a button if the property is a file/color/font chooser //displays a button if the property is a file/color/font chooser
m_nLastBox = 2; m_nLastBox = 2;
m_prevSel = m_curSel; m_prevSel = m_curSel;
UINT dpi = GetDpiForWindow(GetSafeHwnd()); float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
float scaling_factor = static_cast<float>(dpi) / 96.0f;
int s3 = int(3 * scaling_factor); int s3 = int(3 * scaling_factor);
if (region.Width() > 25) { if (region.Width() > 25) {