@@ -6,6 +6,11 @@ namespace OpenHardwareMonitor.UI
66{
77 internal static class TreeViewAdvThemeExtender
88 {
9+ private static Brush BackgroundBrush ;
10+ private static Brush SelectedBackBrush ;
11+ private static Pen ForegroundPen ;
12+ private static Pen LinePen ;
13+
914 internal static void SubscribeToThemes ( )
1015 {
1116 Theme . OnCurrentChanged += ( ) => { AssignRendersTheme ( ) ; } ;
@@ -23,17 +28,26 @@ internal static void SubscribeToThemes()
2328
2429 internal static void AssignRendersTheme ( )
2530 {
31+ BackgroundBrush ? . Dispose ( ) ;
32+ BackgroundBrush = new SolidBrush ( Theme . Current . BackgroundColor ) ;
33+ SelectedBackBrush ? . Dispose ( ) ;
34+ SelectedBackBrush = new SolidBrush ( Theme . Current . SelectedBackgroundColor ) ;
35+ ForegroundPen ? . Dispose ( ) ;
36+ ForegroundPen = new Pen ( Theme . Current . ForegroundColor ) ;
37+ LinePen ? . Dispose ( ) ;
38+ LinePen = new Pen ( Theme . Current . LineColor ) ;
39+
2640 TreeViewAdv . CustomPlusMinusRenderFunc = ( g , rect , isExpanded ) =>
2741 {
2842 int x = rect . Left ;
2943 int y = rect . Top + 5 ;
3044 int size = 8 ;
31- g . FillRectangle ( Theme . BackgroundBrush , x - 1 , y - 1 , size + 4 , size + 4 ) ;
32- g . DrawRectangle ( Theme . ForegroundPen , x , y , size , size ) ;
33- g . DrawLine ( Theme . ForegroundPen , x + 2 , y + size / 2 , x + size - 2 , y + size / 2 ) ;
45+ g . FillRectangle ( BackgroundBrush , x - 1 , y - 1 , size + 4 , size + 4 ) ;
46+ g . DrawRectangle ( ForegroundPen , x , y , size , size ) ;
47+ g . DrawLine ( ForegroundPen , x + 2 , y + size / 2 , x + size - 2 , y + size / 2 ) ;
3448 if ( ! isExpanded )
3549 {
36- g . DrawLine ( Theme . ForegroundPen , x + size / 2 , y + 2 , x + size / 2 , y + size - 2 ) ;
50+ g . DrawLine ( ForegroundPen , x + size / 2 , y + 2 , x + size / 2 , y + size - 2 ) ;
3751 }
3852 } ;
3953
@@ -42,33 +56,33 @@ internal static void AssignRendersTheme()
4256 int x = rect . Left ;
4357 int y = rect . Top + 1 ;
4458 int size = 12 ;
45- g . FillRectangle ( Theme . BackgroundBrush , x - 1 , y - 1 , 12 , 12 ) ;
46- g . DrawRectangle ( Theme . ForegroundPen , x , y , size , size ) ;
59+ g . FillRectangle ( BackgroundBrush , x - 1 , y - 1 , 12 , 12 ) ;
60+ g . DrawRectangle ( ForegroundPen , x , y , size , size ) ;
4761 if ( isChecked )
4862 {
4963 x += 3 ;
5064 y += 3 ;
51- g . DrawLine ( Theme . ForegroundPen , x , y + 3 , x + 2 , y + 5 ) ;
52- g . DrawLine ( Theme . ForegroundPen , x + 2 , y + 5 , x + 6 , y + 1 ) ;
53- g . DrawLine ( Theme . ForegroundPen , x , y + 4 , x + 2 , y + 6 ) ;
54- g . DrawLine ( Theme . ForegroundPen , x + 2 , y + 6 , x + 6 , y + 2 ) ;
65+ g . DrawLine ( ForegroundPen , x , y + 3 , x + 2 , y + 5 ) ;
66+ g . DrawLine ( ForegroundPen , x + 2 , y + 5 , x + 6 , y + 1 ) ;
67+ g . DrawLine ( ForegroundPen , x , y + 4 , x + 2 , y + 6 ) ;
68+ g . DrawLine ( ForegroundPen , x + 2 , y + 6 , x + 6 , y + 2 ) ;
5569 }
5670 } ;
5771
5872 TreeViewAdv . CustomColumnBackgroundRenderFunc = ( g , rect , isPressed , isHot ) =>
5973 {
60- g . FillRectangle ( Theme . BackgroundBrush , rect ) ;
61- g . DrawLine ( Theme . LinePen , rect . Left , rect . Top , rect . Right , rect . Top ) ;
62- g . DrawLine ( Theme . LinePen , rect . Left , rect . Top + 1 , rect . Right , rect . Top + 1 ) ;
74+ g . FillRectangle ( BackgroundBrush , rect ) ;
75+ g . DrawLine ( LinePen , rect . Left , rect . Top , rect . Right , rect . Top ) ;
76+ g . DrawLine ( LinePen , rect . Left , rect . Top + 1 , rect . Right , rect . Top + 1 ) ;
6377 } ;
6478
6579 TreeViewAdv . CustomColumnTextRenderFunc = ( g , rect , font , text ) =>
6680 {
6781 TextRenderer . DrawText ( g , text , font , rect , Theme . Current . ForegroundColor , TextFormatFlags . Left ) ;
6882 } ;
6983
70- TreeViewAdv . CustomHorizontalLinePen = Theme . LinePen ;
71- TreeViewAdv . CustomSelectedRowBrush = Theme . SelectedBackBrush ;
84+ TreeViewAdv . CustomHorizontalLinePen = LinePen ;
85+ TreeViewAdv . CustomSelectedRowBrush = SelectedBackBrush ;
7286 TreeViewAdv . CustomSelectedTextColor = Theme . Current . SelectedForegroundColor ;
7387 }
7488 }
0 commit comments