Skip to content
This repository was archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
More tweaks to Dark theme. Made theme an app setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryochan7 committed Dec 4, 2020
1 parent 72c0f37 commit 9c1f527
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 15 deletions.
6 changes: 4 additions & 2 deletions DS4Windows/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--<ResourceDictionary Source="DS4Forms/Themes/LightTheme.xaml" />-->
<ResourceDictionary Source="DS4Forms/Themes/DarkTheme.xaml" />
<ResourceDictionary Source="DS4Forms/Themes/DefaultTheme.xaml" />
<!--<ResourceDictionary Source="DS4Forms/Themes/DarkTheme.xaml" />-->
</ResourceDictionary.MergedDictionaries>

<!--<SolidColorBrush x:Key="ForegroundColor" Color="{x:Static SystemColors.ActiveCaptionTextColor}" />-->

<Style TargetType="{x:Type Button}" x:Key="NoBGHoverBtn">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
Expand Down
22 changes: 22 additions & 0 deletions DS4Windows/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public struct COPYDATASTRUCT
private MemoryMappedFile ipcResultDataMMF = null; // MemoryMappedFile for inter-process communication used to exchange string result data between cmdline client process and the background running DS4Windows app
private MemoryMappedViewAccessor ipcResultDataMMA = null;

private static Dictionary<DS4Windows.AppThemeChoice, string> themeLocs = new
Dictionary<DS4Windows.AppThemeChoice, string>()
{
[DS4Windows.AppThemeChoice.Default] = "DS4Forms/Themes/DefaultTheme.xaml",
[DS4Windows.AppThemeChoice.Dark] = "DS4Forms/Themes/DarkTheme.xaml",
};

private void Application_Startup(object sender, StartupEventArgs e)
{
runShutdown = true;
Expand Down Expand Up @@ -171,6 +178,12 @@ private void Application_Startup(object sender, StartupEventArgs e)
}

SetUICulture(DS4Windows.Global.UseLang);
DS4Windows.AppThemeChoice themeChoice = DS4Windows.Global.UseCurrentTheme;
if (themeChoice != DS4Windows.AppThemeChoice.Default)
{
ChangeTheme(DS4Windows.Global.UseCurrentTheme);
}

DS4Windows.Global.LoadLinkedProfiles();
DS4Forms.MainWindow window = new DS4Forms.MainWindow(parser);
MainWindow = window;
Expand Down Expand Up @@ -602,6 +615,15 @@ private void SetUICulture(string culture)
catch (CultureNotFoundException) { /* Skip setting culture that we cannot set */ }
}

public static void ChangeTheme(DS4Windows.AppThemeChoice themeChoice)
{
if (themeLocs.TryGetValue(themeChoice, out string loc))
{
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(loc, uriKind: UriKind.Relative) });
}
}

private void Application_Exit(object sender, ExitEventArgs e)
{
if (runShutdown)
Expand Down
23 changes: 23 additions & 0 deletions DS4Windows/DS4Control/ScpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public enum TrayIconChoice : uint
Black,
}

public enum AppThemeChoice : uint
{
Default,
Dark,
}

public class DS4ControlSettings
{
public DS4Controls control;
Expand Down Expand Up @@ -1228,6 +1234,12 @@ public static TrayIconChoice UseIconChoice
set => m_Config.useIconChoice = value;
}

public static AppThemeChoice UseCurrentTheme
{
get => m_Config.useCurrentTheme;
set => m_Config.useCurrentTheme = value;
}

public static bool UseCustomSteamFolder
{
set { m_Config.useCustomSteamFolder = value; }
Expand Down Expand Up @@ -2529,6 +2541,7 @@ public void setSZOutCurveMode(int index, int value)
public double udpSmoothingBeta = DEFAULT_UDP_SMOOTH_BETA;
public bool useCustomSteamFolder;
public string customSteamFolder;
public AppThemeChoice useCurrentTheme;
public string fakeExeFileName = string.Empty;

// Cache whether profile has custom action
Expand Down Expand Up @@ -5016,6 +5029,15 @@ public bool Load()
catch { missingSetting = true; }
}

try
{
Item = m_Xdoc.SelectSingleNode("/Profile/AppTheme");
string temp = Item.InnerText;
Enum.TryParse(temp, out AppThemeChoice choice);
useCurrentTheme = choice;
}
catch { missingSetting = true; useCurrentTheme = AppThemeChoice.Default; }

try { Item = m_Xdoc.SelectSingleNode("/Profile/UseUDPServer"); Boolean.TryParse(Item.InnerText, out useUDPServ); }
catch { missingSetting = true; }
try { Item = m_Xdoc.SelectSingleNode("/Profile/UDPServerPort"); int temp; int.TryParse(Item.InnerText, out temp); udpServPort = Math.Min(Math.Max(temp, 1024), 65535); }
Expand Down Expand Up @@ -5155,6 +5177,7 @@ public bool Save()
XmlNode xmlFlashWhenLate = m_Xdoc.CreateNode(XmlNodeType.Element, "FlashWhenLate", null); xmlFlashWhenLate.InnerText = flashWhenLate.ToString(); rootElement.AppendChild(xmlFlashWhenLate);
XmlNode xmlFlashWhenLateAt = m_Xdoc.CreateNode(XmlNodeType.Element, "FlashWhenLateAt", null); xmlFlashWhenLateAt.InnerText = flashWhenLateAt.ToString(); rootElement.AppendChild(xmlFlashWhenLateAt);
XmlNode xmlAppIconChoice = m_Xdoc.CreateNode(XmlNodeType.Element, "AppIcon", null); xmlAppIconChoice.InnerText = useIconChoice.ToString(); rootElement.AppendChild(xmlAppIconChoice);
XmlNode xmlAppThemeChoice = m_Xdoc.CreateNode(XmlNodeType.Element, "AppTheme", null); xmlAppThemeChoice.InnerText = useCurrentTheme.ToString(); rootElement.AppendChild(xmlAppThemeChoice);
XmlNode xmlUseUDPServ = m_Xdoc.CreateNode(XmlNodeType.Element, "UseUDPServer", null); xmlUseUDPServ.InnerText = useUDPServ.ToString(); rootElement.AppendChild(xmlUseUDPServ);
XmlNode xmlUDPServPort = m_Xdoc.CreateNode(XmlNodeType.Element, "UDPServerPort", null); xmlUDPServPort.InnerText = udpServPort.ToString(); rootElement.AppendChild(xmlUDPServPort);
XmlNode xmlUDPServListenAddress = m_Xdoc.CreateNode(XmlNodeType.Element, "UDPServerListenAddress", null); xmlUDPServListenAddress.InnerText = udpServListenAddress; rootElement.AppendChild(xmlUDPServListenAddress);
Expand Down
12 changes: 6 additions & 6 deletions DS4Windows/DS4Forms/ControllerReadingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<Label Content="{lex:Loc LeftStick}" HorizontalAlignment="Center" Padding="0"/>
<Label Content="" HorizontalAlignment="Center" Padding="0"/>
<Canvas x:Name="lsCanvas" Width="130" Height="130" ClipToBounds="True">
<Rectangle Stroke="{DynamicResource ForegroundColor}" Width="130" Height="130">
<Rectangle Width="130" Height="130" Stroke="{DynamicResource ForegroundColor}">
</Rectangle>
<Ellipse x:Name="lsDeadEllipse" Width="{Binding Path=Width, ElementName=lsCanvas}"
Height="{Binding Path=Height, ElementName=lsCanvas}" Fill="#FFCF1F1F">
Expand Down Expand Up @@ -72,8 +72,8 @@
<Label Content="{lex:Loc RightStick}" HorizontalAlignment="Center" Padding="0"/>
<Label Content="" HorizontalAlignment="Center" Padding="0"/>
<Canvas x:Name="rsCanvas" Width="130" Height="130" ClipToBounds="True">
<Rectangle Stroke="{DynamicResource ForegroundColor}" Width="{Binding Path=Width, ElementName=rsCanvas}"
Height="{Binding Path=Height, ElementName=rsCanvas}">
<Rectangle Width="{Binding Path=Width, ElementName=rsCanvas}"
Height="{Binding Path=Height, ElementName=rsCanvas}" Stroke="{DynamicResource ForegroundColor}">
</Rectangle>
<Ellipse x:Name="rsDeadEllipse" Width="{Binding Path=Width, ElementName=rsCanvas}"
Height="{Binding Path=Height, ElementName=rsCanvas}" Fill="#FFCF1F1F">
Expand Down Expand Up @@ -107,8 +107,8 @@
<StackPanel Grid.Column="2">
<TextBlock Text="SixAxis: X Axis is flipped so it is easier to read" TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center"/>
<Canvas x:Name="sixaxisCanvas" Width="130" Height="130" ClipToBounds="True">
<Rectangle Stroke="{DynamicResource ForegroundColor}" Width="{Binding Path=Width, ElementName=sixaxisCanvas}"
Height="{Binding Path=Height, ElementName=sixaxisCanvas}">
<Rectangle Width="{Binding Path=Width, ElementName=sixaxisCanvas}"
Height="{Binding Path=Height, ElementName=sixaxisCanvas}" Stroke="{DynamicResource ForegroundColor}">
</Rectangle>
<Ellipse x:Name="sixAxisDeadEllipse" Width="{Binding Path=Width, ElementName=sixaxisCanvas}"
Height="{Binding Path=Height, ElementName=sixaxisCanvas}" Fill="#FFCF1F1F">
Expand Down Expand Up @@ -199,7 +199,7 @@
</StackPanel>
</StackPanel>
</StackPanel>
<Border Grid.Column="1" BorderThickness="1">
<Border Grid.Column="1" BorderThickness="1" BorderBrush="{DynamicResource ForegroundColor}">
<StackPanel Orientation="Horizontal" Margin="10" HorizontalAlignment="Center">
<StackPanel Margin="0,0,10,0">
<Label Content="{lex:Loc Gyro}" HorizontalAlignment="Center" Padding="0"/>
Expand Down
9 changes: 8 additions & 1 deletion DS4Windows/DS4Forms/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
</local:AutoProfiles>
</TabItem>
<TabItem Header="Output Slots" IsEnabled="{Binding FullTabsEnabled,Mode=OneWay}">
<local:OutputSlotManagerControl x:Name="slotManControl" Background="{DynamicResource BackgroundColor}">
<local:OutputSlotManagerControl x:Name="slotManControl">

</local:OutputSlotManagerControl>
</TabItem>
Expand Down Expand Up @@ -290,6 +290,13 @@
<ComboBoxItem>Black</ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="{StaticResource spaceMargin}">
<Label Content="App Theme:" />
<ComboBox x:Name="appThemeCom" SelectedIndex="{Binding AppChoiceIndex,FallbackValue='0'}" Margin="10,0,0,0">
<ComboBoxItem>Default</ComboBoxItem>
<ComboBoxItem>Dark</ComboBoxItem>
</ComboBox>
</StackPanel>

<CheckBox Content="{lex:Loc CheckUpdateStartup}" Margin="{StaticResource spaceMargin}"
IsChecked="{Binding CheckForUpdates}" />
Expand Down
7 changes: 7 additions & 0 deletions DS4Windows/DS4Forms/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ private void SetupEvents()
trayIconVM.RequestOpen += TrayIconVM_RequestOpen;
trayIconVM.RequestServiceChange += TrayIconVM_RequestServiceChange;
settingsWrapVM.IconChoiceIndexChanged += SettingsWrapVM_IconChoiceIndexChanged;
settingsWrapVM.AppChoiceIndexChanged += SettingsWrapVM_AppChoiceIndexChanged;

autoProfControl.AutoDebugChanged += AutoProfControl_AutoDebugChanged;
autoprofileChecker.RequestServiceChange += AutoprofileChecker_RequestServiceChange;
Expand Down Expand Up @@ -431,6 +432,12 @@ private void SetupEvents()
}
}

private void SettingsWrapVM_AppChoiceIndexChanged(object sender, EventArgs e)
{
AppThemeChoice choice = Global.UseCurrentTheme;
App.ChangeTheme(choice);
}

private void SettingsWrapVM_IconChoiceIndexChanged(object sender, EventArgs e)
{
trayIconVM.IconSource = Global.iconChoiceResources[Global.UseIconChoice];
Expand Down
72 changes: 68 additions & 4 deletions DS4Windows/DS4Forms/Themes/DarkTheme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,71 @@
<Setter Property="Foreground" Value="{StaticResource ForegroundColor}" />
</Style>

<ControlTemplate x:Key="CheckBoxControlTemplate1" TargetType="{x:Type CheckBox}">
<Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border x:Name="checkBoxBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid x:Name="markGrid">
<Path x:Name="optionMark" Data="F1M9.97498,1.22334L4.6983,9.09834 4.52164,9.09834 0,5.19331 1.27664,3.52165 4.255,6.08833 8.33331,1.52588E-05 9.97498,1.22334z" Fill="{StaticResource ForegroundColor}" Margin="1" Opacity="0" Stretch="None"/>
<Rectangle x:Name="indeterminateMark" Fill="{StaticResource ForegroundColor}" Margin="2" Opacity="0"/>
</Grid>
</Border>
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="1" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasContent" Value="True">
<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="14,0,0,0" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Padding" Value="4,-1,0,0"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource BackgroundColor}" />
<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource SecondaryColor}" />
<Setter Property="Fill" TargetName="optionMark" Value="{StaticResource ForegroundColor}" />
<Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource ForegroundColor}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource BackgroundColor}" />
<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="#FF807D7D"/>
<Setter Property="Fill" TargetName="optionMark" Value="#FFE6E6E6"/>
<Setter Property="Fill" TargetName="indeterminateMark" Value="#FFE6E6E6"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" TargetName="checkBoxBorder" Value="{StaticResource AccentColor}"/>
<Setter Property="BorderBrush" TargetName="checkBoxBorder" Value="{StaticResource SecondaryColor}"/>
<Setter Property="Fill" TargetName="optionMark" Value="{StaticResource ForegroundColor}"/>
<Setter Property="Fill" TargetName="indeterminateMark" Value="{StaticResource ForegroundColor}"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Opacity" TargetName="optionMark" Value="1"/>
<Setter Property="Opacity" TargetName="indeterminateMark" Value="0"/>
</Trigger>
<Trigger Property="IsChecked" Value="{x:Null}">
<Setter Property="Opacity" TargetName="optionMark" Value="0"/>
<Setter Property="Opacity" TargetName="indeterminateMark" Value="1"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

<!-- CheckBox style -->
<Style x:Key="CheckBoxStyle" TargetType="{x:Type CheckBox}">
<Setter Property="Background" Value="{StaticResource BackgroundColor}" />
<Setter Property="Foreground" Value="{StaticResource ForegroundColor}" />
<Setter Property="Template" Value="{StaticResource CheckBoxControlTemplate1}" />
</Style>

<!-- RadioButton style -->
Expand Down Expand Up @@ -566,15 +628,17 @@

<!-- ComboBox Style -->
<Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
<!--<Setter Property="Background" Value="{StaticResource BackgroundColor}" />
<Setter Property="Foreground" Value="{StaticResource BackgroundColor}" />-->
<!--<Setter Property="Background" Value="{StaticResource BackgroundColor}" />-->
<Setter Property="BorderBrush" Value="{StaticResource ForegroundColor}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Foreground" Value="{StaticResource ForegroundColor}" />
<Setter Property="Template" Value="{StaticResource ComboBoxControlTemplate1}" />
</Style>

<!-- ComboBoxItem Style -->
<Style x:Key="ComboBoxItemStyle" TargetType="{x:Type ComboBoxItem}">
<Setter Property="Background" Value="{StaticResource BackgroundColor}" />
<Setter Property="BorderBrush" Value="{StaticResource BackgroundColor}" />
<!--<Setter Property="BorderBrush" Value="{StaticResource ForegroundColor}" />-->
<Setter Property="Foreground" Value="{StaticResource ForegroundColor}" />
</Style>

Expand All @@ -601,9 +665,9 @@
<Style BasedOn="{StaticResource ButtonStyle}" TargetType="{x:Type Button}" />
<Style BasedOn="{StaticResource TextBoxStyle}" TargetType="{x:Type TextBox}" />
<Style BasedOn="{StaticResource RichTextBoxStyle}" TargetType="{x:Type RichTextBox}" />
<Style BasedOn="{StaticResource CheckBoxStyle}" TargetType="{x:Type CheckBox}" />
<Style BasedOn="{StaticResource TabControlStyle}" TargetType="{x:Type TabControl}" />
<Style BasedOn="{StaticResource TabItemStyle}" TargetType="{x:Type TabItem}" />
<Style BasedOn="{StaticResource CheckBoxStyle}" TargetType="{x:Type CheckBox}" />
<Style BasedOn="{StaticResource RadioButtonStyle}" TargetType="{x:Type RadioButton}" />
<Style BasedOn="{StaticResource TextBlockStyle}" TargetType="{x:Type TextBlock}" />
<Style BasedOn="{StaticResource ListBoxStyle}" TargetType="{x:Type ListBox}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DS4WinWPF.DS4Forms.Themes">
<!-- Brushes -->
<SolidColorBrush x:Key="SecondaryColor" Color="{DynamicResource {x:Static SystemColors.ControlBrush}}" />
<SolidColorBrush x:Key="ForegroundColor" Color="{x:Static SystemColors.ActiveCaptionTextColor}" />
<SolidColorBrush x:Key="SecondaryColor" Color="{x:Static SystemColors.ControlColor}" />
<SolidColorBrush x:Key="AccentColor" Color="#FF0066CC" />
</ResourceDictionary>
Loading

0 comments on commit 9c1f527

Please sign in to comment.