mirror of
https://github.com/dhewm/dhewm3.git
synced 2024-11-23 12:53:09 +00:00
- Wrapped GetDpiForWindow in GetWindowScalingFactor
- Use GetDeviceCaps for dpi on anything else than win10.
This commit is contained in:
parent
67d325cc61
commit
e67b77ba5d
23 changed files with 54 additions and 59 deletions
|
@ -863,6 +863,7 @@ if (TOOLS AND MFC_FOUND AND MSVC)
|
|||
${src_sound_editor}
|
||||
"tools/edit_public.h"
|
||||
"tools/edit_gui_common.h"
|
||||
"tools/edit_gui_common.cpp"
|
||||
)
|
||||
SET(CMAKE_MFC_FLAG 2)
|
||||
set(TOOLS_DEFINES "ID_ALLOW_TOOLS;_AFXDLL")
|
||||
|
|
|
@ -191,8 +191,7 @@ void CPropTree::OnSize(UINT nType, int cx, int cy)
|
|||
|
||||
void CPropTree::ResizeChildWindows(int cx, int cy)
|
||||
{
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int sh = int(m_nInfoHeight * scaling_factor);
|
||||
|
||||
if (m_bShowInfo)
|
||||
|
@ -213,8 +212,7 @@ void CPropTree::ResizeChildWindows(int cx, int cy)
|
|||
|
||||
void CPropTree::InitGlobalResources()
|
||||
{
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
|
||||
|
||||
NONCLIENTMETRICS info;
|
||||
|
|
|
@ -262,8 +262,7 @@ LONG CPropTreeItem::GetHeight()
|
|||
{
|
||||
if (m_pProp)
|
||||
{
|
||||
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
|
||||
return PROPTREEITEM_DEFHEIGHT * scaling_factor;
|
||||
}
|
||||
return PROPTREEITEM_DEFHEIGHT;
|
||||
|
@ -402,8 +401,7 @@ LONG CPropTreeItem::DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y)
|
|||
|
||||
ASSERT(m_pProp!=NULL);
|
||||
|
||||
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
|
||||
int PNINDENT_s = int(PNINDENT * scaling_factor);
|
||||
int PROPTREEITEM_SPACE_s = int(PROPTREEITEM_SPACE * scaling_factor);
|
||||
int PROPTREEITEM_CHECKBOX_s = int(PROPTREEITEM_CHECKBOX * scaling_factor);
|
||||
|
|
|
@ -54,8 +54,7 @@ LONG CPropTreeItemButton::DrawItem( CDC* pDC, const RECT& rc, LONG x, LONG y )
|
|||
nTotal = CPropTreeItem::DrawItem( pDC, rc, x, y );
|
||||
|
||||
textSize = pDC->GetOutputTextExtent( buttonText );
|
||||
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
|
||||
int s2 = int(2 * scaling_factor);
|
||||
int s4 = int(4 * scaling_factor);
|
||||
int s12 = int(12 * scaling_factor);
|
||||
|
|
|
@ -65,8 +65,7 @@ void CPropTreeItemCheck::DrawAttribute(CDC* pDC, const RECT& rc)
|
|||
return;
|
||||
}
|
||||
|
||||
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
|
||||
int CHECK_BOX_SIZE_s = int(CHECK_BOX_SIZE * scaling_factor);
|
||||
|
||||
checkRect.left = m_rc.left;
|
||||
|
|
|
@ -221,8 +221,7 @@ void CPropTreeItemColor::OnActivate(int activateType, CPoint point)
|
|||
|
||||
m_cPrevColor = m_cColor;
|
||||
|
||||
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
|
||||
|
||||
r = m_rc;
|
||||
r.right = r.left + 150 * scaling_factor;
|
||||
|
@ -261,8 +260,7 @@ void CPropTreeItemColor::OnPaint()
|
|||
{
|
||||
CPaintDC dc(this);
|
||||
CPoint pt;
|
||||
UINT dpi = GetDpiForWindow(m_pProp->GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
|
||||
int s3 = int(3 * scaling_factor);
|
||||
int s7 = int(7 * scaling_factor);
|
||||
int s13 = int(13 * scaling_factor);
|
||||
|
|
|
@ -128,8 +128,8 @@ void CPropTreeList::UpdateResize()
|
|||
SCROLLINFO si;
|
||||
LONG nHeight;
|
||||
CRect rc;
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
|
||||
ASSERT(m_pProp!=NULL);
|
||||
|
||||
|
@ -168,8 +168,7 @@ void CPropTreeList::OnPaint()
|
|||
|
||||
CRect rc;
|
||||
GetClientRect(rc);
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
rc.InflateRect(scaling_factor, scaling_factor);
|
||||
|
||||
// draw control background
|
||||
|
@ -572,8 +571,7 @@ void CPropTreeList::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*)
|
|||
LONG nHeight;
|
||||
|
||||
SetFocus();
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
GetClientRect(rc);
|
||||
nHeight = rc.Height();
|
||||
|
||||
|
|
|
@ -103,8 +103,7 @@ void CPropTreeView::OnPaint()
|
|||
}
|
||||
|
||||
void CPropTreeView::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) {
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s20 = int(20 * scaling_factor);
|
||||
|
||||
// #HvGNote : This should be the right way to do it, but hardcoded is fine too.
|
||||
|
|
|
@ -587,8 +587,7 @@ bool rvPropertyGrid::ReflectMessage ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM
|
|||
|
||||
case WM_MEASUREITEM:
|
||||
{
|
||||
UINT dpi = GetDpiForWindow(hWnd);
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(hWnd);
|
||||
|
||||
MEASUREITEMSTRUCT* mis = (MEASUREITEMSTRUCT*) lParam;
|
||||
mis->itemHeight = 18 * scaling_factor;
|
||||
|
|
|
@ -659,8 +659,7 @@ void DialogDeclBrowser::OnSize( UINT nType, int cx, int cy ) {
|
|||
|
||||
GetClientRect( clientRect );
|
||||
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
float scaled_toolbar_height = (TOOLBAR_HEIGHT * scaling_factor);
|
||||
float scaled_button_space = (BUTTON_SPACE * scaling_factor);
|
||||
float scaled_border_size = (BORDER_SIZE * scaling_factor);
|
||||
|
|
|
@ -235,8 +235,7 @@ void DialogDeclEditor::LoadDecl( idDecl *decl ) {
|
|||
|
||||
SetWindowText( va( "Declaration Editor (%s, line %d)", decl->GetFileName(), decl->GetLineNum() ) );
|
||||
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
|
||||
rect.left = initialRect.left;
|
||||
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 );
|
||||
|
||||
GetClientRect( clientRect );
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
float scaled_toolbar_height = (TOOLBAR_HEIGHT * scaling_factor);
|
||||
float scaled_button_space = (BUTTON_SPACE * scaling_factor);
|
||||
|
||||
|
|
22
neo/tools/edit_gui_common.cpp
Normal file
22
neo/tools/edit_gui_common.cpp
Normal 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%
|
||||
}
|
||||
|
||||
|
|
@ -179,4 +179,5 @@
|
|||
// Compilers for map, model, video etc. processing.
|
||||
#include "tools/compilers/compiler_public.h"
|
||||
|
||||
float GetWindowScalingFactor(HWND window);
|
||||
#endif // TOOLS_EDIT_GUI_COMMON_H
|
||||
|
|
|
@ -334,8 +334,7 @@ void MEMainFrame::OnSize(UINT nType, int cx, int cy)
|
|||
|
||||
CFrameWnd::OnSize(nType, cx, cy);
|
||||
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s5 = int(5 * scaling_factor);
|
||||
|
||||
CRect statusRect;
|
||||
|
|
|
@ -241,8 +241,7 @@ void MaterialEditView::OnSize(UINT nType, int cx, int cy) {
|
|||
m_tabs.GetItemRect(0, tabRect);
|
||||
|
||||
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s2 = int(2 * scaling_factor);
|
||||
int s8 = int(8 * scaling_factor);
|
||||
int s4 = int(4 * scaling_factor);
|
||||
|
|
|
@ -160,8 +160,7 @@ void ToggleListView::OnSize(UINT nType, int cx, int cy) {
|
|||
* Returns the size of each item in the toggle list.
|
||||
*/
|
||||
void ToggleListView::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) {
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
lpMeasureItemStruct->itemHeight = TOGGLELIST_ITEMHEIGHT * scaling_factor;
|
||||
}
|
||||
|
||||
|
|
|
@ -938,8 +938,7 @@ void CDialogTextures::OnSize(UINT nType, int cx, int cy)
|
|||
return;
|
||||
}
|
||||
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s8 = int(8 * scaling_factor);
|
||||
int s4 = int(4 * scaling_factor);
|
||||
int s12 = int(12 * scaling_factor);
|
||||
|
|
|
@ -74,9 +74,7 @@ void CEditViewDlg::OnSize(UINT nType, int cx, int cy) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s2 = int(2 * scaling_factor);
|
||||
int s8 = int(8 * scaling_factor);
|
||||
int s4 = int(4 * scaling_factor);
|
||||
|
|
|
@ -164,9 +164,8 @@ void CEntityDlg::OnSize(UINT nType, int cx, int cy)
|
|||
CDialog::OnSize(nType, cx, cy);
|
||||
CRect rect, crect, crect2;
|
||||
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 s8 = int( 8 * scaling_factor);
|
||||
int s4 = int( 4 * scaling_factor);
|
||||
|
|
|
@ -131,8 +131,7 @@ void CInspectorDialog::OnSize(UINT nType, int cx, int cy)
|
|||
POSITION pos;
|
||||
WORD wID;
|
||||
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s5 = int(5 * scaling_factor);
|
||||
int s4 = int(4 * scaling_factor);
|
||||
|
||||
|
|
|
@ -1797,8 +1797,7 @@ void CMainFrame::OnSize(UINT nType, int cx, int cy) {
|
|||
|
||||
CRect rctParent;
|
||||
GetClientRect(rctParent);
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
|
||||
UINT nID;
|
||||
UINT nStyle;
|
||||
|
|
|
@ -108,8 +108,7 @@ BOOL CMediaPreviewDlg::OnInitDialog()
|
|||
|
||||
void CMediaPreviewDlg::OnSize(UINT nType, int cx, int cy)
|
||||
{
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s8 = int(8 * scaling_factor);
|
||||
int s4 = int(4 * scaling_factor);
|
||||
|
||||
|
|
|
@ -88,8 +88,7 @@ BOOL CPropertyList::PreCreateWindow(CREATESTRUCT& cs) {
|
|||
}
|
||||
|
||||
void CPropertyList::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) {
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s20 = int(20 * scaling_factor);
|
||||
|
||||
if (measureItem && !measureItem->m_curValue.IsEmpty()) {
|
||||
|
@ -111,8 +110,7 @@ void CPropertyList::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) {
|
|||
|
||||
void CPropertyList::DrawItem(LPDRAWITEMSTRUCT lpDIS) {
|
||||
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s3 = 3;// int(3 * scaling_factor);
|
||||
|
||||
CDC dc;
|
||||
|
@ -196,8 +194,7 @@ void CPropertyList::OnSelchange() {
|
|||
static int recurse = 0;
|
||||
//m_curSel = GetCurSel();
|
||||
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s3 = int(3 * scaling_factor);
|
||||
|
||||
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
|
||||
m_nLastBox = 2;
|
||||
m_prevSel = m_curSel;
|
||||
UINT dpi = GetDpiForWindow(GetSafeHwnd());
|
||||
float scaling_factor = static_cast<float>(dpi) / 96.0f;
|
||||
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
|
||||
int s3 = int(3 * scaling_factor);
|
||||
|
||||
if (region.Width() > 25) {
|
||||
|
|
Loading…
Reference in a new issue