11using System ;
22using System . IO ;
33using System . Linq ;
4+ using Avalonia ;
45using Avalonia . Controls ;
56using Avalonia . Input ;
67using Avalonia . Interactivity ;
78using Avalonia . Platform . Storage ;
9+ using Avalonia . Styling ;
810using OxyPlot ;
911using OxyPlot . Avalonia ;
1012using OxyPlot . Axes ;
@@ -21,6 +23,12 @@ public MainWindow()
2123 {
2224 InitializeComponent ( ) ;
2325 DataContext = new MainViewModel ( ) ;
26+
27+ if ( Application . Current is not null )
28+ {
29+ Application . Current . RequestedThemeVariant = GlobalConfig . Theme ;
30+ ViewModel . UpdateIsDarkMode ( GlobalConfig . Theme == ThemeVariant . Dark ) ;
31+ }
2432
2533 DragDrop . SetAllowDrop ( this , true ) ;
2634 AddHandler ( DragDrop . DropEvent , Drop ) ;
@@ -70,6 +78,21 @@ private async void LoadReplayButton_Click(object? sender, RoutedEventArgs e)
7078 var replayPath = files . Single ( ) . TryGetLocalPath ( ) ! ;
7179 AnalyseReplay ( replayPath ) ;
7280 }
81+
82+ private void ThemeToggleButton_Click ( object sender , RoutedEventArgs e )
83+ {
84+ var app = Application . Current ;
85+
86+ if ( app is null )
87+ return ;
88+
89+ var currentTheme = app . ActualThemeVariant ;
90+ var newTheme = currentTheme == ThemeVariant . Dark ? ThemeVariant . Light : ThemeVariant . Dark ;
91+ app . RequestedThemeVariant = newTheme ;
92+
93+ ViewModel . UpdateIsDarkMode ( newTheme == ThemeVariant . Dark ) ;
94+ GlobalConfig . UpdateTheme ( newTheme ) ;
95+ }
7396
7497 private void Drop ( object ? sender , DragEventArgs e )
7598 {
@@ -102,18 +125,29 @@ private void AnalyseReplay(string replayPath)
102125 var plotModel = new PlotModel
103126 {
104127 Title = "Key Hold Time Distribution" ,
105- Background = OxyColors . White
128+ Background = ViewModel . IsDarkMode ? OxyColors . Black : OxyColors . White ,
129+ TextColor = ViewModel . IsDarkMode ? OxyColors . White : OxyColors . Black ,
130+ TitleColor = ViewModel . IsDarkMode ? OxyColors . White : OxyColors . Black ,
131+ PlotAreaBorderColor = ViewModel . IsDarkMode ? OxyColors . Gray : OxyColors . Black
106132 } ;
107133
134+ var gridColour = ViewModel . IsDarkMode ? OxyColors . DarkGray : OxyColors . LightGray ;
135+ var axisColour = ViewModel . IsDarkMode ? OxyColors . White : OxyColors . Black ;
136+
108137 plotModel . Axes . Add ( new LinearAxis
109138 {
110139 Position = AxisPosition . Bottom ,
111140 Title = "pressing time (ms)" ,
112141 TitleFontSize = 15 ,
142+ TitleColor = axisColour ,
143+ TextColor = axisColour ,
144+ AxislineColor = axisColour ,
145+ TicklineColor = axisColour ,
113146 Minimum = 0 ,
114147 Maximum = 160 ,
115148 MajorGridlineStyle = LineStyle . Solid ,
116- MajorGridlineColor = OxyColors . LightGray ,
149+ MajorGridlineColor = gridColour ,
150+ MinorGridlineColor = gridColour ,
117151 IsZoomEnabled = false ,
118152 IsPanEnabled = false ,
119153 } ) ;
@@ -125,9 +159,14 @@ private void AnalyseReplay(string replayPath)
125159 Position = AxisPosition . Left ,
126160 Title = "count" ,
127161 TitleFontSize = 15 ,
162+ TitleColor = axisColour ,
163+ TextColor = axisColour ,
164+ AxislineColor = axisColour ,
165+ TicklineColor = axisColour ,
128166 Maximum = maxHoldTimeCount + maxHoldTimeCount * 0.1 ,
129167 MajorGridlineStyle = LineStyle . Solid ,
130- MajorGridlineColor = OxyColors . LightGray ,
168+ MajorGridlineColor = gridColour ,
169+ MinorGridlineColor = gridColour ,
131170 IsZoomEnabled = false ,
132171 IsPanEnabled = false ,
133172 } ) ;
@@ -138,15 +177,18 @@ private void AnalyseReplay(string replayPath)
138177 {
139178 LegendPosition = LegendPosition . RightTop ,
140179 LegendPlacement = LegendPlacement . Inside ,
141- LegendFontSize = 10
180+ LegendFontSize = 10 ,
181+ LegendTextColor = ViewModel . IsDarkMode ? OxyColors . White : OxyColors . Black ,
182+ LegendBackground = OxyColors . Transparent ,
183+ LegendBorder = ViewModel . IsDarkMode ? OxyColors . Gray : OxyColors . LightGray
142184 } ) ;
143185
144186 for ( var i = 0 ; i < analysis . HoldTimes . Length ; i ++ )
145187 {
146188 var lineSeries = new LineSeries
147189 {
148190 Title = $ "key { i + 1 } ",
149- Color = GetRainbowColor ( i , analysis . HoldTimes . Length ) ,
191+ Color = GetRainbowColor ( i , analysis . HoldTimes . Length , ViewModel . IsDarkMode ) ,
150192 StrokeThickness = 2 ,
151193 TrackerFormatString = "{0}\n Hold Time: {2:0} ms\n Count: {4:0}" ,
152194 } ;
@@ -163,13 +205,13 @@ private void AnalyseReplay(string replayPath)
163205 PlotView . Model = plotModel ;
164206 }
165207
166- private static OxyColor GetRainbowColor ( int index , int total )
208+ private static OxyColor GetRainbowColor ( int index , int total , bool isDarkTheme )
167209 {
168- const double saturation = 0.9 ;
169- const double value = 0.9 ;
210+ var saturation = isDarkTheme ? 0.8 : 0.9 ;
211+ var value = isDarkTheme ? 0.9 : 0.8 ;
170212
171- const double c = value * saturation ;
172- const double m = value - c ;
213+ var c = value * saturation ;
214+ var m = value - c ;
173215
174216 // Create a hue using the index & total
175217 // Then do standard HSV->RGB conversion
0 commit comments