Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Add system theme supprot.
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatHuang2007 committed Mar 28, 2022
1 parent 1c39bcb commit 1994e2e
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/OGFrp.Main/About/AboutBox.xaml.vb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Public Class AboutBox

Public Sub SetTheme(Theme As Theme)
Me.Background = Theme.contentBackground
Me.Foreground = Theme.contentForeground
End Sub

Private Sub Lb_OpenSource_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles Lb_OpenSource.MouseDown
Process.Start("https://github.com/MarchStudio/OGFrp")
End Sub
Expand Down
1 change: 1 addition & 0 deletions src/OGFrp.Main/MainPanel.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Public Class MainPanel

Public Assets As AssetModel
Public Config As Config
Public Theme As Theme

Dim SelectedBg As Brush

Expand Down
4 changes: 2 additions & 2 deletions src/OGFrp.Main/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Background" Value="#80808080"/>
<Setter TargetName="border" Property="Background" Value="#40808080"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="border" Property="Background" Value="#80404040"/>
<Setter TargetName="border" Property="Background" Value="#60404040"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down
21 changes: 18 additions & 3 deletions src/OGFrp.Main/MainWindow.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,25 @@ Class MainWindow
Dim ac As New Assets() 'Temp用ac
Dim Assets As AssetModel
Dim Config As New Config()
Dim Theme As New Theme()

Private Sub _init_() Handles Me.Loaded
Me.Theme.GetSystemTheme()
Config.ReadConfig()
Me.Assets = ac.SearchAsset(Config.Lang.Val)
Me.LoginBox.Assets = Me.Assets
Me.LoginBox.Visibility = Visibility.Visible
Me.LoginBox.Config = Me.Config
Me.LoginBox._init_()
Me.txtTitle.Foreground = Brushes.Black
Me.txtTitle.Foreground = Me.Theme.titleActiveTextColor
Me.txtTitle.Text = Assets.Welcome
Me.MainPanel.Assets = Me.Assets
Me.MainPanel.ctm_SettingsPage.Config = Me.Config
Me.MainPanel.Theme = Me.Theme
Me.bd_titlefillL.Background = Me.Theme.titleActiveColor
Me.bd_titlefillR.Background = Me.Theme.titleActiveColor
Me.Bt_Close.Foreground = Me.Theme.titleActiveTextColor
Me.Bt_Min.Foreground = Me.Theme.titleActiveTextColor
End Sub

Private Sub MainWindow_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
Expand All @@ -74,13 +81,21 @@ Class MainWindow

Private Sub MainWindow_Activated(sender As Object, e As EventArgs) Handles Me.Activated
If Me.bd_titlefillL.Visibility = Visibility.Visible Then
Me.txtTitle.Foreground = Brushes.Black
Me.txtTitle.Foreground = Me.Theme.titleActiveTextColor
Else
Me.txtTitle.Foreground = Brushes.White
End If
Me.bd_titlefillL.Background = Me.Theme.titleActiveColor
Me.bd_titlefillR.Background = Me.Theme.titleActiveColor
Me.Bt_Close.Foreground = Me.Theme.titleActiveTextColor
Me.Bt_Min.Foreground = Me.Theme.titleActiveTextColor
End Sub

Private Sub MainWindow_Deactivated(sender As Object, e As EventArgs) Handles Me.Deactivated
Me.txtTitle.Foreground = Brushes.DarkGray
Me.txtTitle.Foreground = Me.Theme.titleInactiveTextColor
Me.bd_titlefillL.Background = Me.Theme.titleInactiveColor
Me.bd_titlefillR.Background = Me.Theme.titleInactiveColor
Me.Bt_Close.Foreground = Me.Theme.titleInactiveTextColor
Me.Bt_Min.Foreground = Me.Theme.titleInactiveTextColor
End Sub
End Class
1 change: 1 addition & 0 deletions src/OGFrp.Main/OGFrp.Main.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<Compile Include="SettingsPage.xaml.vb">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
<Compile Include="Theme\Theme.vb" />
<Compile Include="UserDisplay.xaml.vb">
<DependentUpon>UserDisplay.xaml</DependentUpon>
</Compile>
Expand Down
50 changes: 50 additions & 0 deletions src/OGFrp.Main/Theme/Theme.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Public Class Theme

Public titleActiveColor As Brush
Public titleInactiveColor As Brush
Public titleActiveTextColor As Brush
Public titleInactiveTextColor As Brush
Public contentBackground As Brush
Public contentForeground As Brush

Public Sub New()
titleActiveColor = New SolidColorBrush(Color.FromArgb(204, 255, 255, 255))
titleInactiveColor = New SolidColorBrush(Color.FromArgb(255, 255, 255, 255))
titleActiveTextColor = Brushes.Black
titleInactiveTextColor = Brushes.Gray
contentBackground = New SolidColorBrush(Color.FromArgb(204, 255, 255, 255))
contentForeground = Brushes.Black
End Sub

Public Sub CalcBorW(ByVal red As Integer, ByVal green As Integer, ByVal blue As Integer)
If (red * 0.299 + green * 0.587 + blue * 0.114) > 186 Then
Me.titleActiveTextColor = Brushes.Black
Else
Me.titleActiveTextColor = Brushes.White
End If
End Sub

Public Sub GetSystemTheme()
If Environment.OSVersion.Version.Major = 6 Then
If Environment.OSVersion.Version.Minor = 1 Or Environment.OSVersion.Version.Minor = 0 Then '判断Windows 7或Vista
'PASS
Else 'Windows 8及以上版本的Win系统
Dim FormTitleColor As Boolean = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM", "ColorPrevalence", True)
Dim A As Integer = 204
Dim R As Integer = 255
Dim G As Integer = 255
Dim B As Integer = 255
If FormTitleColor Then
Dim FormColorSource As String = Hex(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM", "ColorizationColor", Int32.Parse("FF000000", Globalization.NumberStyles.HexNumber)))
A = 255
R = Int32.Parse(FormColorSource.Substring(2, 2), Globalization.NumberStyles.HexNumber)
G = Int32.Parse(FormColorSource.Substring(4, 2), Globalization.NumberStyles.HexNumber)
B = Int32.Parse(FormColorSource.Substring(6, 2), Globalization.NumberStyles.HexNumber)
End If
Me.titleActiveColor = New SolidColorBrush(Color.FromArgb(A, R, G, B))
CalcBorW(R, G, B) '设置标题栏字体颜色为黑色或白色
End If
End If
End Sub

End Class

0 comments on commit 1994e2e

Please sign in to comment.