1- namespace MW5 . Api . Legend
1+ using System . Drawing ;
2+ using System . Windows . Forms ;
3+ namespace MW5 . Api . Legend
24{
3- internal class Constants
5+ // TODO turn this in to service?
6+ public class Constants
47 {
5- public const int ItemHeight = 19 ;
8+
9+ public Constants ( Control control )
10+ {
11+ Control = control ;
12+ }
13+
14+ public int _itemHeight => ( int ) ( 19.0 * GetScalingFactor ( ) ) ;
15+
16+ public int ItemHeight => TextHeight + 4 ;
617 public const int ItemPad = 4 ;
718 public const int ItemRightPad = 5 ;
819 // TEXT
9- public const int TextHeight = 14 ;
20+
21+ public static Font DefaultLegendFont = new Font ( "Arial" , 8 , GraphicsUnit . Pixel ) ;
22+
23+ public int _textHeight = - 1 ;
24+ public int TextHeight
25+ {
26+ get
27+ {
28+ var scale = GetScalingFactor ( ) ;
29+ return ( int ) ( 14.0 * scale ) ; /*
30+ if (_textHeight < 0)
31+ {
32+
33+ _textHeight = TextRenderer
34+ .MeasureText("HçjÊ{}g", DefaultLegendFont)
35+ .Height + (int) (4 * scale);
36+ }
37+
38+ return _textHeight;*/
39+ }
40+ }
41+
42+ public Control Control { get ; }
43+
44+ private double GetScalingFactor ( )
45+ {
46+ var graphics = Control . CreateGraphics ( ) ;
47+ return graphics . DpiX / 96.0 ;
48+ }
49+
1050 public const int TextTopPad = 3 ;
1151 public const int TextLeftPad = 30 ;
1252 public const int TextRightPad = 25 ;
1353 public const int TextRightPadNoIcon = 8 ;
1454 public const int TextEditingRightPad = 10 ;
1555 // CHECK BOX
16- public const int CheckTopPad = 4 ;
17- public const int CheckBoxSize = 12 ;
56+ public int CheckTopPad => ( ItemHeight - CheckBoxSize ) / 2 ;
57+ public int CheckBoxSize => 12 ;
1858 // EXPANSION BOX
1959 public const int ExpandBoxTopPad = 5 ;
2060 public const int ExpandBoxLeftPad = 3 ;
2161 public const int ExpandBoxSize = 8 ;
2262 // LIST ITEMS
2363 public const int ListItemIndent = 18 ;
2464 public const int IconRightPad = 25 ;
25- public const int IconTopPad = 3 ;
65+ public int IconTopPad => ( ItemHeight - IconSize ) / 2 ;
2666 public const int IconSize = 13 ;
2767 public const int VertLineGrpTopOffset = 14 ;
2868 // COLOR SCHEME CONSTANTS
29- public const int CsItemHeight = 14 ;
30- public const int CsTopPad = 1 ;
69+ public int CsItemHeight => ( int ) ( 14 * GetScalingFactor ( ) ) ;
3170 public const int CsPatchHeight = 12 ;
32- public const int CsTextTopPad = 3 ;
3371 // SCROLLBAR
3472 public const int ScrollWidth = 15 ;
3573 // MISC
@@ -53,24 +91,13 @@ internal class Constants
5391
5492 public const int VerticalPad = 2 ;
5593
56- public static int ItemHeightAndPad ( )
57- {
58- return ItemHeight + VerticalPad ;
59- }
94+ public int ItemHeightAndPad => ItemHeight + VerticalPad ;
6095
61- public static int CsItemHeightAndPad ( )
62- {
63- return CsItemHeight + VerticalPad ;
64- }
96+ public int CsItemHeightAndPad => CsItemHeight + VerticalPad ;
6597
66- public static int CategoryCheckboxWidthWithPadding ( )
67- {
68- return CheckBoxSize + 5 ;
69- }
98+ public int CategoryCheckboxWidthWithPadding
99+ => CheckBoxSize + 5 ;
70100
71- public static int CheckboxTopOffset ( )
72- {
73- return ( TextHeight - CheckBoxSize ) / 2 ;
74- }
101+ public int CheckboxTopOffset => ( TextHeight - CheckBoxSize ) / 2 ;
75102 }
76103}
0 commit comments