@@ -9,77 +9,55 @@ namespace ReClassNET.UI
99{
1010 public static class DpiUtil
1111 {
12- private const int StdDpi = 96 ;
12+ public const int DefalutDpi = 96 ;
1313
14- private static bool initialized ;
15-
16- private static int dpiX = StdDpi ;
17- private static int dpiY = StdDpi ;
14+ private static int dpiX = DefalutDpi ;
15+ private static int dpiY = DefalutDpi ;
1816
1917 private static double scaleX = 1.0 ;
2018 private static double scaleY = 1.0 ;
2119
22- public static bool ScalingRequired
20+ public static void ConfigureProcess ( )
2321 {
24- get
25- {
26- if ( Program . DesignMode )
27- {
28- return false ;
29- }
30-
31- EnsureInitialized ( ) ;
32-
33- return dpiX != StdDpi || dpiY != StdDpi ;
34- }
22+ NativeMethods . SetProcessDpiAwareness ( ) ;
3523 }
3624
37- private static void EnsureInitialized ( )
25+ public static void SetDpi ( int x , int y )
3826 {
39- if ( initialized )
27+ dpiX = x ;
28+ dpiY = y ;
29+
30+ if ( dpiX <= 0 || dpiY <= 0 )
4031 {
41- return ;
32+ dpiX = DefalutDpi ;
33+ dpiY = DefalutDpi ;
4234 }
4335
36+ scaleX = dpiX / ( double ) DefalutDpi ;
37+ scaleY = dpiY / ( double ) DefalutDpi ;
38+ }
39+
40+ public static void TrySetDpiFromCurrentDesktop ( )
41+ {
4442 try
4543 {
4644 using var g = Graphics . FromHwnd ( IntPtr . Zero ) ;
47- dpiX = ( int ) g . DpiX ;
48- dpiY = ( int ) g . DpiY ;
4945
50- if ( dpiX <= 0 || dpiY <= 0 )
51- {
52- dpiX = StdDpi ;
53- dpiY = StdDpi ;
54- }
46+ SetDpi ( ( int ) g . DpiX , ( int ) g . DpiY ) ;
5547 }
5648 catch
5749 {
5850 // ignored
5951 }
60-
61- scaleX = dpiX / ( double ) StdDpi ;
62- scaleY = dpiY / ( double ) StdDpi ;
63-
64- initialized = true ;
65- }
66-
67- public static void ConfigureProcess ( )
68- {
69- NativeMethods . SetProcessDpiAwareness ( ) ;
7052 }
7153
7254 public static int ScaleIntX ( int i )
7355 {
74- EnsureInitialized ( ) ;
75-
7656 return ( int ) Math . Round ( i * scaleX ) ;
7757 }
7858
7959 public static int ScaleIntY ( int i )
8060 {
81- EnsureInitialized ( ) ;
82-
8361 return ( int ) Math . Round ( i * scaleY ) ;
8462 }
8563
0 commit comments