Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream 4k/dpi awareness Tool fixes #339

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions neo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
elseif(MSVC)
add_compile_options(/MP) # parallel build (use all cores, or as many as configured in VS)

add_compile_options(/W4)
add_compile_options(/W3)
add_compile_options(/we4840) # treat as error when passing a class to a vararg-function (probably printf-like)
add_compile_options(/wd4100) # unreferenced formal parameter
add_compile_options(/wd4127) # conditional expression is constant
Expand All @@ -304,6 +304,7 @@ elseif(MSVC)
add_compile_options(/wd4996) # 'function': was declared deprecated
add_compile_options(/wd4068) # unknown pragma
add_compile_options(/wd4458) # declaration of 'variable' hides class member
add_compile_options(/wd4312) # smaller type
add_definitions(-D_ALLOW_KEYWORD_MACROS) # because of the "#define private public" and "#define protected public" in TypeInfo.cpp
set(CMAKE_C_FLAGS_DEBUG "-D_DEBUG /Od /Zi /MDd")
set(CMAKE_C_FLAGS_RELEASE "/Ox /Oy /MD")
Expand All @@ -321,8 +322,11 @@ set(CMAKE_CXX_FLAGS_MINSIZEREL "-DNDEBUG ${CMAKE_C_FLAGS_MINSIZEREL}")

# mingw and msvc
if(WIN32)
add_definitions(-DWINVER=0x0501)
add_definitions(-D_WIN32_WINNT=0x0501)
add_definitions(-DWINVER=0x0A00)
add_definitions(-D_WIN32_WINNT=0x0A00)
add_definitions(-DNTDDI_VERSION=0x0A000000)
#add_definitions(-DWINVER=0x0501)
#add_definitions(-D_WIN32_WINNT=0x0501)

set(sys_libs ${sys_libs}
winmm
Expand Down Expand Up @@ -857,9 +861,10 @@ 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")
set(TOOLS_DEFINES "ID_ALLOW_TOOLS;_AFXDLL")
else()
set(src_editor_tools "tools/edit_stub.cpp" "tools/edit_public.h")
endif()
Expand Down
15 changes: 11 additions & 4 deletions neo/tools/common/PropTree/PropTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ CPropTree::CPropTree() :
m_bDisableInput(FALSE)
{
m_Root.Expand();

// init global resources only once
if (!s_nInstanceCount)
InitGlobalResources();
Expand Down Expand Up @@ -192,13 +191,16 @@ void CPropTree::OnSize(UINT nType, int cx, int cy)

void CPropTree::ResizeChildWindows(int cx, int cy)
{
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());
int sh = int(m_nInfoHeight * scaling_factor);

if (m_bShowInfo)
{
if (IsWindow(m_List.m_hWnd))
m_List.MoveWindow(0, 0, cx, cy - m_nInfoHeight);
m_List.MoveWindow(0, 0, cx, cy - sh);

if (IsWindow(m_Info.m_hWnd))
m_Info.MoveWindow(0, cy - m_nInfoHeight, cx, m_nInfoHeight);
m_Info.MoveWindow(0, cy - sh, cx, sh);
}
else
{
Expand All @@ -210,6 +212,9 @@ void CPropTree::ResizeChildWindows(int cx, int cy)

void CPropTree::InitGlobalResources()
{
float scaling_factor = GetWindowScalingFactor(GetSafeHwnd());


NONCLIENTMETRICS info;
info.cbSize = sizeof(info);

Expand All @@ -221,7 +226,9 @@ void CPropTree::InitGlobalResources()
CWindowDC dc(NULL);
lf.lfCharSet = (BYTE)GetTextCharsetInfo(dc.GetSafeHdc(), NULL, 0);

lf.lfHeight = info.lfMenuFont.lfHeight;
int fh = int(info.lfMenuFont.lfHeight * scaling_factor);

lf.lfHeight = fh;
lf.lfWeight = info.lfMenuFont.lfWeight;
lf.lfItalic = info.lfMenuFont.lfItalic;

Expand Down
59 changes: 38 additions & 21 deletions neo/tools/common/PropTree/PropTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void _DotHLine(HDC hdc, LONG x, LONG y, LONG w)


// draw the plus/minus button
static void _DrawExpand(HDC hdc, LONG x, LONG y, BOOL bExpand, BOOL bFill)
static void _DrawExpand(HDC hdc, LONG x, LONG y, BOOL bExpand, BOOL bFill,LONG EXPANDBOX, LONG EXPANDBOXHALF)
{
HPEN hPen;
HPEN oPen;
Expand All @@ -57,17 +57,17 @@ static void _DrawExpand(HDC hdc, LONG x, LONG y, BOOL bExpand, BOOL bFill)
oPen = (HPEN)SelectObject(hdc, hPen);
oBrush = (HBRUSH)SelectObject(hdc, GetStockObject(bFill ? WHITE_BRUSH : NULL_BRUSH));

Rectangle(hdc, x, y, x + PROPTREEITEM_EXPANDBOX, y + PROPTREEITEM_EXPANDBOX);
Rectangle(hdc, x, y, x + EXPANDBOX, y + EXPANDBOX);
SelectObject(hdc, GetStockObject(BLACK_PEN));

if (!bExpand)
{
MoveToEx(hdc, x + PROPTREEITEM_EXPANDBOXHALF, y + 2, NULL);
LineTo(hdc, x + PROPTREEITEM_EXPANDBOXHALF, y + PROPTREEITEM_EXPANDBOX - 2);
MoveToEx(hdc, x + EXPANDBOXHALF, y + 2, NULL);
LineTo(hdc, x + EXPANDBOXHALF, y + EXPANDBOX - 2);
}

MoveToEx(hdc, x + 2, y + PROPTREEITEM_EXPANDBOXHALF, NULL);
LineTo(hdc, x + PROPTREEITEM_EXPANDBOX - 2, y + PROPTREEITEM_EXPANDBOXHALF);
MoveToEx(hdc, x + 2, y + EXPANDBOXHALF, NULL);
LineTo(hdc, x + EXPANDBOX - 2, y + EXPANDBOXHALF);

SelectObject(hdc, oPen);
SelectObject(hdc, oBrush);
Expand Down Expand Up @@ -260,6 +260,11 @@ UINT CPropTreeItem::GetCtrlID()

LONG CPropTreeItem::GetHeight()
{
if (m_pProp)
{
float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
return PROPTREEITEM_DEFHEIGHT * scaling_factor;
}
return PROPTREEITEM_DEFHEIGHT;
}

Expand Down Expand Up @@ -396,19 +401,26 @@ LONG CPropTreeItem::DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y)

ASSERT(m_pProp!=NULL);

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);
int PROPTREEITEM_EXPANDBOX_s = int(PROPTREEITEM_EXPANDBOX * scaling_factor);
int PROPTREEITEM_EXPANDCOLUMN_s = int(PROPTREEITEM_EXPANDCOLUMN * scaling_factor);
int PROPTREEITEM_EXPANDBOXHALF_s = int(PROPTREEITEM_EXPANDBOXHALF * scaling_factor);
// Add TreeItem the list of visble items
m_pProp->AddToVisibleList(this);

// store the item's location
m_loc = CPoint(x, y);

// store the items rectangle position
m_rc.SetRect(m_pProp->GetOrigin().x + PROPTREEITEM_SPACE, m_loc.y, rc.right, m_loc.y + GetHeight()-1);
m_rc.SetRect(m_pProp->GetOrigin().x + PROPTREEITEM_SPACE_s, m_loc.y, rc.right, m_loc.y + GetHeight()-1);
m_rc.OffsetRect(0, -m_pProp->GetOrigin().y);

// init temp drawing variables
nTotal = GetHeight();
ey = (nTotal >> 1) - (PROPTREEITEM_EXPANDBOX >> 1) - 2;
ey = (nTotal >> 1) - (PROPTREEITEM_EXPANDBOX_s >> 1) - 2;

bool bCheck = false;

Expand All @@ -418,9 +430,9 @@ LONG CPropTreeItem::DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y)
nCol = m_pProp->GetOrigin().x;

if (IsRootLevel())
drc.SetRect(pt.x + PROPTREEITEM_EXPANDCOLUMN, pt.y, rc.right, pt.y + nTotal);
drc.SetRect(pt.x + PROPTREEITEM_EXPANDCOLUMN_s, pt.y, rc.right, pt.y + nTotal);
else
drc.SetRect(pt.x + PROPTREEITEM_EXPANDCOLUMN, pt.y, nCol, pt.y + nTotal);
drc.SetRect(pt.x + PROPTREEITEM_EXPANDCOLUMN_s, pt.y, nCol, pt.y + nTotal);

// root level items are shaded
if (IsRootLevel())
Expand All @@ -433,14 +445,14 @@ LONG CPropTreeItem::DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y)
// calc/draw expand box position
if (GetChild())
{
m_rcExpand.left = PROPTREEITEM_EXPANDCOLUMN/2 - PROPTREEITEM_EXPANDBOXHALF;
m_rcExpand.left = PROPTREEITEM_EXPANDCOLUMN_s /2 - PROPTREEITEM_EXPANDBOXHALF_s;
m_rcExpand.top = m_loc.y + ey;
m_rcExpand.right = m_rcExpand.left + PROPTREEITEM_EXPANDBOX - 1;
m_rcExpand.bottom = m_rcExpand.top + PROPTREEITEM_EXPANDBOX - 1;
m_rcExpand.right = m_rcExpand.left + PROPTREEITEM_EXPANDBOX_s - 1;
m_rcExpand.bottom = m_rcExpand.top + PROPTREEITEM_EXPANDBOX_s - 1;

ir = m_rcExpand;
ir.OffsetRect(0, -m_pProp->GetOrigin().y);
_DrawExpand(pDC->m_hDC, ir.left, ir.top, IsExpanded(), !IsRootLevel());
_DrawExpand(pDC->m_hDC, ir.left, ir.top, IsExpanded(), !IsRootLevel(), PROPTREEITEM_EXPANDBOX_s, PROPTREEITEM_EXPANDBOXHALF_s);
}
else
m_rcExpand.SetRectEmpty();
Expand All @@ -450,11 +462,11 @@ LONG CPropTreeItem::DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y)
{
bCheck = true;

ir.left = drc.left + PROPTREEITEM_SPACE;
ir.left = drc.left + PROPTREEITEM_SPACE_s;
ir.top = m_loc.y + ey;

ir.right = ir.left + PROPTREEITEM_CHECKBOX;
ir.bottom = ir.top + PROPTREEITEM_CHECKBOX;
ir.right = ir.left + PROPTREEITEM_CHECKBOX_s;
ir.bottom = ir.top + PROPTREEITEM_CHECKBOX_s;

m_rcCheckbox = ir;
}
Expand All @@ -472,11 +484,11 @@ LONG CPropTreeItem::DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y)

// calc label position
ir = drc;
ir.left += PROPTREEITEM_SPACE;
ir.left += PROPTREEITEM_SPACE_s;

// offset the label text if item has a check box
if (bCheck)
OffsetRect(&ir, PROPTREEITEM_CHECKBOX + PROPTREEITEM_SPACE * 2, 0);
OffsetRect(&ir, PROPTREEITEM_CHECKBOX_s + PROPTREEITEM_SPACE_s * 2, 0);

// draw label
if (!m_sLabel.IsEmpty())
Expand All @@ -498,7 +510,7 @@ LONG CPropTreeItem::DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y)

CRect dr;
dr = drc;
dr.left = PROPTREEITEM_EXPANDCOLUMN;
dr.left = PROPTREEITEM_EXPANDCOLUMN_s;

pDC->Rectangle(&dr);

Expand Down Expand Up @@ -531,7 +543,12 @@ LONG CPropTreeItem::DrawItem(CDC* pDC, const RECT& rc, LONG x, LONG y)
}

// draw horzontal sep
_DotHLine(pDC->m_hDC, PROPTREEITEM_EXPANDCOLUMN, pt.y + nTotal - 1, rc.right - PROPTREEITEM_EXPANDCOLUMN + 1);
float tmpScale = scaling_factor;
while (tmpScale > 0)
{
_DotHLine(pDC->m_hDC, PROPTREEITEM_EXPANDCOLUMN_s, pt.y + nTotal - 1, rc.right - PROPTREEITEM_EXPANDCOLUMN_s + 1);
tmpScale -= 1.0f;
}

// draw separators
if (!IsRootLevel())
Expand Down
16 changes: 10 additions & 6 deletions neo/tools/common/PropTree/PropTreeItemButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ LONG CPropTreeItemButton::DrawItem( CDC* pDC, const RECT& rc, LONG x, LONG y )
nTotal = CPropTreeItem::DrawItem( pDC, rc, x, y );

textSize = pDC->GetOutputTextExtent( buttonText );
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);

buttonRect.left = m_rc.right - ( textSize.cx + 12 + 4);
buttonRect.top = m_rc.top + ((m_rc.bottom - m_rc.top)/2)-BUTTON_SIZE/2;
buttonRect.right = buttonRect.left + textSize.cx + 12;
buttonRect.bottom = buttonRect.top + BUTTON_SIZE;
buttonRect.left = m_rc.right - ( textSize.cx + s12 + s4);
buttonRect.top = m_rc.top + ((m_rc.bottom - m_rc.top)/2)- (textSize.cy + s4) /2;
buttonRect.right = buttonRect.left + textSize.cx + s12;
buttonRect.bottom = buttonRect.top + (textSize.cy + s4);

UINT buttonStyle;

Expand All @@ -70,8 +74,8 @@ LONG CPropTreeItemButton::DrawItem( CDC* pDC, const RECT& rc, LONG x, LONG y )
pDC->DrawFrameControl(&buttonRect, DFC_BUTTON, buttonStyle );

textRect = buttonRect;
textRect.left += 4;
textRect.right -= 8;
textRect.left += s4;
textRect.right -= s4-s4;
pDC->DrawText( buttonText, textRect, DT_SINGLELINE|DT_VCENTER );

//Adjust hit test rect to acount for window scrolling
Expand Down
9 changes: 6 additions & 3 deletions neo/tools/common/PropTree/PropTreeItemCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ void CPropTreeItemCheck::DrawAttribute(CDC* pDC, const RECT& rc)
return;
}

float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());
int CHECK_BOX_SIZE_s = int(CHECK_BOX_SIZE * scaling_factor);

checkRect.left = m_rc.left;
checkRect.top = m_rc.top + ((m_rc.bottom - m_rc.top)/2)-CHECK_BOX_SIZE/2;
checkRect.right = checkRect.left + CHECK_BOX_SIZE;
checkRect.bottom = checkRect.top + CHECK_BOX_SIZE;
checkRect.top = m_rc.top + ((m_rc.bottom - m_rc.top)/2)- CHECK_BOX_SIZE_s /2;
checkRect.right = checkRect.left + CHECK_BOX_SIZE_s;
checkRect.bottom = checkRect.top + CHECK_BOX_SIZE_s;

if(!m_bActivated)
pDC->DrawFrameControl(&checkRect, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_FLAT |(checkState ? DFCS_CHECKED : 0));
Expand Down
28 changes: 18 additions & 10 deletions neo/tools/common/PropTree/PropTreeItemColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ static ColorTableEntry _crColors[] =
{RGB(0xFF, 0xFF, 0xFF)}
};

static void ColorBox(CDC* pDC, CPoint pt, COLORREF clr, BOOL bHover)
static void ColorBox(CDC* pDC, CPoint pt, COLORREF clr, BOOL bHover,float scale)
{
CBrush br(clr);

CBrush* obr = pDC->SelectObject(&br);

pDC->PatBlt(pt.x, pt.y, 13, 13, PATCOPY);
pDC->PatBlt(pt.x, pt.y, 13* scale, 13* scale, PATCOPY);
pDC->SelectObject(obr);

CRect rc;
rc.SetRect(pt.x - 2, pt.y - 2, pt.x + 15, pt.y + 15);
rc.SetRect(pt.x - 2, pt.y - 2, pt.x + 15 * scale, pt.y + 15 * scale);

pDC->DrawEdge(&rc, (bHover) ? BDR_SUNKENOUTER : BDR_RAISEDINNER, BF_RECT);
}
Expand Down Expand Up @@ -221,9 +221,11 @@ void CPropTreeItemColor::OnActivate(int activateType, CPoint point)

m_cPrevColor = m_cColor;

float scaling_factor = GetWindowScalingFactor(m_pProp->GetSafeHwnd());

r = m_rc;
r.right = r.left + 150;
r.bottom = r.top + 120;
r.right = r.left + 150 * scaling_factor;
r.bottom = r.top + 120 * scaling_factor;

ASSERT(m_pProp!=NULL);
m_pProp->GetCtrlParent()->ClientToScreen(r);
Expand All @@ -237,7 +239,7 @@ void CPropTreeItemColor::OnActivate(int activateType, CPoint point)
DWORD dwStyle = WS_POPUP|WS_DLGFRAME;

CreateEx(0, pszClassName, _T(""), dwStyle, r, m_pProp->GetCtrlParent(), 0);
m_rcButton.SetRect(40, 94, 110, 114);
m_rcButton.SetRect(40, 94 * scaling_factor, 110 * scaling_factor, 114 * scaling_factor);
}

SetWindowPos(NULL, r.left, r.top, r.Width() + 1, r.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
Expand All @@ -258,13 +260,19 @@ void CPropTreeItemColor::OnPaint()
{
CPaintDC dc(this);
CPoint pt;
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);
int s18 = int(18 * scaling_factor);

for (LONG i=0; i<40; i++)
{
pt.x = (i & 7) * 18 + 3;
pt.y = (i >> 3) * 18 + 3;
ColorBox(&dc, pt, _crColors[i].color, m_nSpot==i);
SetRect(&_crColors[i].rcSpot, pt.x, pt.y, pt.x + 13, pt.y + 13);
pt.x = (i & 7) * s18 + s3;
pt.y = (i >> 3) * s18 + s3;
ColorBox(&dc, pt, _crColors[i].color, m_nSpot==i, scaling_factor);
SetRect(&_crColors[i].rcSpot, pt.x, pt.y, pt.x + s13, pt.y + s13);
InflateRect(&_crColors[i].rcSpot, int(scaling_factor),int(scaling_factor));
}

ASSERT(m_pProp!=NULL);
Expand Down