1- /*
2- -Custom font fallback
3- -Custom font collection
4- -EDIT/RichEdit
5- -Show red attribute on parse error
6- ?Character glyph map
7- ?App translucency
8- +Rendering mode
9- +GDI AddFontMemResource
10- +Add font open dialog for font file
11- +Get all characters
12- +Add font selection dialog
13- +Hit test canvas
14- +Pan scroll canvas
15- +Font fallback enable/disable
16- +Store settings
17- +Load settings
18- +Transform drawable objects
19- +Context menu on drawable objects right-click
20- +Drawable object absolute placement
21- +Draw labels
22- +Reflow drawable objects
23- +GDI+ DrawString/MeasureString
24- +GDI+ DrawDriverString
25- +Show red box on drawing error
26- +Draw object background colors and object together
27- +Fix user32 DrawText for vertical
28- +Save selected font file
29- */
30- // ----------------------------------------------------------------------------
1+ // ----------------------------------------------------------------------------
312// History: 2015-06-19 Dwayne Robinson - Created
3+ // 2022-03-17 Updated for high DPI
324// ----------------------------------------------------------------------------
335
346#if USE_CPP_MODULES
@@ -279,6 +251,10 @@ MainWindow::DialogProcResult CALLBACK MainWindow::DialogProc(HWND hwnd, UINT mes
279251 Resize (IddMainWindow);
280252 break ;
281253
254+ case WM_DPICHANGED:
255+ dpiScaler_.UpdateDpi (hwnd);
256+ break ;
257+
282258 case WM_KEYDOWN:
283259 TranslateAccelerator (hwnd, g_accelTable, &Application::g_msg);
284260 break ;
@@ -467,6 +443,8 @@ INT_PTR MainWindow::InitializeMainDialog()
467443 DefWindowProc (hwnd_, WM_SETICON, ICON_BIG, LPARAM (LoadIcon (Application::g_hModule, MAKEINTRESOURCE (1 ))));
468444 SetWindowText (hwnd_, BUILD_TITLE_STRING);
469445
446+ dpiScaler_.UpdateDpi (hwnd_); // Must be done before resizing.
447+
470448 Edit_LimitText (GetWindowFromId (hwnd_, IdcLog), 1048576 );
471449
472450 // Subclass the values edit box for a few reasons.
@@ -586,7 +564,7 @@ void MainWindow::InitializeDrawableObjectsListView()
586564 // columns to data arrays (including strings) and enumerations than
587565 // simple numeric values.
588566 lc.iSubItem = attribute.id ;
589- lc.cx = ( attribute.IsTypeArray () || attribute.id == 0 ) ? 120 : 80 ;
567+ lc.cx = dpiScaler_. ScaleSizeX (( attribute.IsTypeArray () || attribute.id == 0 ) ? 120 : 80 ) ;
590568 lc.pszText = const_cast <LPWSTR>(ToWChar (attribute.display ));
591569 ListView_InsertColumn (listViewHwnd, lc.iSubItem , &lc);
592570 }
@@ -652,8 +630,8 @@ void MainWindow::UpdateDrawableObjectsListView()
652630void MainWindow::InitializeAttributesListView ()
653631{
654632 const static ListViewColumnInfo columnInfo[] = {
655- { 0 , 120 , u" Attribute" },
656- { 1 , 400 , u" Value" },
633+ { 0 , dpiScaler_. ScaleSizeX ( 120 ) , u" Attribute" },
634+ { 1 , dpiScaler_. ScaleSizeX ( 400 ) , u" Value" },
657635 };
658636 auto listViewHwnd = GetWindowFromId (hwnd_, IdcAttributesList);
659637 ListView_SetExtendedListViewStyle (listViewHwnd, LVS_EX_LABELTIP | LVS_EX_DOUBLEBUFFER | LVS_EX_HEADERDRAGDROP | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERINALLVIEWS);
@@ -709,8 +687,8 @@ void MainWindow::FillAttributesListView()
709687void MainWindow::InitializeAttributeValuesListView ()
710688{
711689 const static ListViewColumnInfo columnInfo[] = {
712- { 0 , 120 , u" Name" },
713- { 1 , 400 , u" Value" },
690+ { 0 , dpiScaler_. ScaleSizeX ( 120 ) , u" Name" },
691+ { 1 , dpiScaler_. ScaleSizeX ( 400 ) , u" Value" },
714692 };
715693 auto listViewHwnd = GetWindowFromId (hwnd_, IdcAttributeValuesList);
716694 ListView_SetExtendedListViewStyle (listViewHwnd, LVS_EX_LABELTIP | LVS_EX_DOUBLEBUFFER | LVS_EX_HEADERDRAGDROP | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERINALLVIEWS);
@@ -3060,9 +3038,12 @@ void MainWindow::Resize(int id)
30603038 hwnd = hwnd_;
30613039 GetClientRect (hwnd, &clientRect);
30623040 if (IsRectEmpty (&clientRect))
3041+ {
30633042 return ; // Avoid unnecessary resizing logic if minimized.
3043+ }
30643044
3065- InflateRect (&clientRect, -spacing, -spacing);
3045+ auto inflatedSpacing = dpiScaler_.ScaleSizeX (spacing);
3046+ InflateRect (&clientRect, -inflatedSpacing, -inflatedSpacing);
30663047
30673048 WindowPosition windowPositions[] = {
30683049 /* 00 */ WindowPosition (GetWindowFromId (hwnd, IdcDrawableObjectListLoad), PositionOptionsAlignTop),
@@ -3100,12 +3081,14 @@ void MainWindow::Resize(int id)
31003081 WindowPosition& windowPositionAttributeValuesList = windowPositions[22 ];
31013082
31023083 // Apply initial overall resizing.
3103- WindowPosition::ReflowGrid (windowPositions, uint32_t (countof (windowPositions)), clientRect, spacing, 0 , PositionOptionsNone);
3104- windowPositionDrawableObjectsList.ClampRect ({0x7FFF ,340 });
3105- windowPositionAttributesList.ClampRect ({340 ,340 });
3106- windowPositionAttributeValuesList.ClampRect ({340 ,340 });
3107- windowPositionEditText.ClampRect ({0x7FFF ,160 });
3108- WindowPosition::ReflowGrid (windowPositions, uint32_t (countof (windowPositions)), clientRect, spacing, 0 , PositionOptionsNone);
3084+ const int32_t attributeListWidth = dpiScaler_.ScaleSizeX (340 );
3085+ const int32_t attributeListHeight = dpiScaler_.ScaleSizeY (340 );
3086+ WindowPosition::ReflowGrid (windowPositions, uint32_t (countof (windowPositions)), clientRect, inflatedSpacing, 0 , PositionOptionsNone);
3087+ windowPositionDrawableObjectsList.ClampRect ({0x7FFF ,attributeListWidth});
3088+ windowPositionAttributesList.ClampRect ({attributeListHeight,attributeListWidth});
3089+ windowPositionAttributeValuesList.ClampRect ({attributeListHeight,attributeListWidth});
3090+ windowPositionEditText.ClampRect ({0x7FFF , dpiScaler_.ScaleSizeY (160 )});
3091+ WindowPosition::ReflowGrid (windowPositions, uint32_t (countof (windowPositions)), clientRect, inflatedSpacing, 0 , PositionOptionsNone);
31093092
31103093 // Resize the objects edit and list controls.
31113094 RECT attributesRect = windowPositionAttributesList.rect ;
@@ -3119,9 +3102,11 @@ void MainWindow::Resize(int id)
31193102 #if 0 // todo::: enable slider for variable fonts.
31203103 windowPositionAttributeValuesSlider.options &= ~PositionOptionsIgnored;
31213104 #endif
3105+
31223106 windowPositionAttributeValuesList.SetOptions (PositionOptionsFillHeight, PositionOptionsAlignVMask | PositionOptionsUseSlackHeight);
31233107 WindowPosition::ReflowGrid (&windowPositionAttributeValuesEdit, 3 , attributeValuesRect, /* spacing*/ 0 , 0 , PositionOptionsFlowVertical | PositionOptionsUnwrapped);
3124- windowPositionAttributeValuesEdit.ClampRect ({0x7FFF , (GetWindowStyle (windowPositionAttributeValuesEdit.hwnd ) & ES_MULTILINE) ? 48 *3 /2 : 12 *3 /2 });
3108+ int windowPositionAttributeValuesEditHeight = (GetWindowStyle (windowPositionAttributeValuesEdit.hwnd ) & ES_MULTILINE) ? 48 *3 /2 : 12 *3 /2 ;
3109+ windowPositionAttributeValuesEdit.ClampRect ({0x7FFF , dpiScaler_.ScaleSizeX (windowPositionAttributeValuesEditHeight)});
31253110 WindowPosition::ReflowGrid (&windowPositionAttributeValuesEdit, 3 , attributeValuesRect, /* spacing*/ 0 , 0 , PositionOptionsFlowVertical | PositionOptionsUnwrapped);
31263111
31273112 WindowPosition::Update (windowPositions, uint32_t (countof (windowPositions)));
0 commit comments