color theme related improvements

This commit is contained in:
Frank Skare
2019-07-17 18:18:33 +02:00
parent a82f558acf
commit 2af84941ca
15 changed files with 121 additions and 99 deletions

View File

@@ -1,6 +1,12 @@
### 4.7.4
### 4.7.6.1
- fix for mouse button back/forward causing freeze
- fix for WM_APPCOMMAND not working but crashing in input editor learn window
- on Win 7 the theme color was hardcoded to DarkSlateGrey because
WPF was returning a bad color on Win 7, this was fixed by reading
the theme color from the Registry on Win 7
- new option color-dark was added to overwrite the OS theme color used in dark mode
- new option color-light was added to overwrite the OS theme color used in non dark mode
### 4.7.3

View File

@@ -48,7 +48,7 @@ Table of contents
- Very high degree of mpv compatibility, almost all mpv features are available
- Great usability due to everything in the application being searchable
- Open source built with modern tools and applications
- Open source built with modern tools
- Customizable context menu defined in the same file as the key bindings ([Screenshot](#context-menu-screenshot), [Defaults](https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/inputConf.txt))
- Searchable config dialog ([Screenshot](#config-editor-screenshot), [Defaults](https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpvConf.txt))
- Searchable input (key/mouse) binding editor ([Screenshot](#input-editor-screenshot), [Defaults](https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/inputConf.txt))

View File

@@ -1,5 +1,5 @@
// this addon writes a rating to the filename of the current video,
// the input.conf defaults contain key bindings for this addon
// this addon writes a rating to the filename of rated videos when mpv.net
// shuts down. The input.conf defaults contain key bindings for this addon.
using System;
using System.ComponentModel.Composition;
@@ -7,30 +7,36 @@ using System.Collections.Generic;
using System.IO;
using mpvnet;
using System.Diagnostics;
// the assembly name must end with 'Addon'
namespace RatingAddon
{
[Export(typeof(IAddon))]
public class RatingAddon : IAddon
{
// dictionory to store the filename and the rating
Dictionary<string, int> Dic = new Dictionary<string, int>();
public RatingAddon()
public RatingAddon() // plugin initialization
{
mp.ClientMessage += ClientMessage; //handles keys defined in input.conf
mp.Shutdown += Shutdown;
mp.Shutdown += Shutdown; // handles MPV_EVENT_SHUTDOWN
}
// handles MPV_EVENT_SHUTDOWN
void Shutdown()
{
if (App.DebugMode) Trace.WriteLine("aaa");
foreach (var i in Dic)
{
string filepath = i.Key;
int rating = i.Value;
if (App.DebugMode) Trace.WriteLine("bbb");
if (String.IsNullOrEmpty(filepath) || ! File.Exists(filepath))
return;
if (App.DebugMode) Trace.WriteLine("ccc");
string basename = Path.GetFileNameWithoutExtension(filepath);
for (int x = 0; x < 6; x++)
@@ -39,11 +45,12 @@ namespace RatingAddon
basename += $" ({rating}stars)";
string newPath = Path.Combine(Path.GetDirectoryName(filepath), basename + Path.GetExtension(filepath));
if (App.DebugMode) Trace.WriteLine("ddd");
if (filepath.ToLower() != newPath.ToLower())
File.Move(filepath, newPath);
if (App.DebugMode) Trace.WriteLine("eee");
File.SetLastWriteTime(newPath, DateTime.Now);
if (App.DebugMode) Trace.WriteLine("fff");
}
}

View File

@@ -15,7 +15,7 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox x:Name="ValueTextBox" Text="{Binding Path=Text, ElementName=StringSettingControl1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="150" HorizontalAlignment="Left" Height="20" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" Background="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" TextChanged="ValueTextBox_TextChanged"/>
<TextBox x:Name="ValueTextBox" Text="{Binding Path=Text, ElementName=StringSettingControl1, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="150" HorizontalAlignment="Left" Height="20" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" Background="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" CaretBrush="{Binding Path=Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" TextChanged="ValueTextBox_TextChanged"/>
<Button x:Name="Button" Height="20" Grid.Column="1" Visibility="{Binding Path=Text, ElementName=StringSettingControl1}" Margin="5,0,0,0" Width="20" Click="Button_Click">...</Button>
</Grid>
<TextBox x:Name="HelpTextBox" TextWrapping="WrapWithOverflow" BorderThickness="0" IsReadOnly="True" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" Background="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"></TextBox>

View File

@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
@@ -64,11 +65,14 @@ namespace DynamicGUI
{
d.FullOpen = true;
try {
if (!string.IsNullOrEmpty(ValueTextBox.Text))
{
Color col = GetColor(ValueTextBox.Text);
d.Color = System.Drawing.Color.FromArgb(col.A, col.R, col.G, col.B);
}
} catch {}
if (d.ShowDialog() == WinForms.DialogResult.OK)
ValueTextBox.Text = System.Drawing.ColorTranslator.ToHtml(d.Color);
ValueTextBox.Text = "#" + d.Color.ToArgb().ToString("X8");
}
break;
}

View File

@@ -22,6 +22,8 @@ namespace mpvnet
public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName;
public static string DarkMode { get; set; } = "always";
public static string ProcessInstance { get; set; } = "single";
public static string DarkColor { get; set; }
public static string LightColor { get; set; }
public static string[] VideoTypes { get; } = "mkv mp4 mpg avi mov webm vob wmv flv avs 264 h264 asf webm mpeg mpv y4m avc hevc 265 h265 m2v m2ts vpy mts m4v".Split(' ');
public static string[] AudioTypes { get; } = "mp3 mp2 ac3 ogg opus flac wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 mka aac mpa".Split(' ');
@@ -31,7 +33,7 @@ namespace mpvnet
public static bool RememberHeight { get; set; } = true;
public static bool RememberPosition { get; set; }
public static bool DebugMode { get; set; } = false;
public static bool DebugMode { get; set; }
public static bool IsDarkMode {
get => (DarkMode == "system" && Sys.IsDarkTheme) || DarkMode == "always";
@@ -49,12 +51,11 @@ namespace mpvnet
{
try
{
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\mpvnet-debug.log";
string filePath = mp.ConfFolder + "\\mpvnet-debug.log";
if (File.Exists(filePath)) File.Delete(filePath);
Trace.Listeners.Clear();
Trace.Listeners.Add(new TextWriterTraceListener(filePath));
foreach (Screen screen in Screen.AllScreens)
Trace.WriteLine(screen);
Trace.AutoFlush = true;
}
catch (Exception e)
{
@@ -94,6 +95,8 @@ namespace mpvnet
case "process-instance": ProcessInstance = value; break;
case "dark-mode": DarkMode = value; break;
case "debug-mode": DebugMode = value == "yes"; break;
case "dark-color": DarkColor = value.Trim('\'', '"'); break;
case "light-color": LightColor = value.Trim('\'', '"'); break;
case "url-whitelist":
UrlWhitelist = value.Split(' ', ',', ';');
break;

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.7.4.0")]
[assembly: AssemblyFileVersion("4.7.4.0")]
[assembly: AssemblyVersion("4.7.6.1")]
[assembly: AssemblyFileVersion("4.7.6.1")]

View File

@@ -7,6 +7,18 @@ options = [{ name = "always" },
{ name = "system" , help = "Available on Windows 10 or higher" },
{ name = "never" }]
[[settings]]
name = "dark-color"
type = "color"
filter = "General"
help = "Theme color used in dark-mode. Leave empty to use OS theme."
[[settings]]
name = "light-color"
type = "color"
filter = "General"
help = "Theme color used when dark-mode is disabled. Leave empty to use OS theme"
[[settings]]
name = "url-whitelist"
filter = "General"
@@ -17,7 +29,7 @@ help = "mpv.net specific whitelist setting to monitor the clipboard for URLs to
name = "process-instance"
default = "single"
filter = "General"
help = "mpv.net specific setting that defines if more then one mpv.net process is allowed.\n\nTip: Whenever the control key is pressed when files or URLs are opened, the playlist is not cleared but the files or URLs are appended to the playlist."
help = "mpv.net specific setting that defines if more then one mpv.net process is allowed.\n\nTip: Whenever the control key is pressed when files or URLs are opened, the playlist is not cleared but the files or URLs are appended to the playlist. This not only works on process startup but in all mpv.net features that open files."
options = [{ name = "multi", help = "Create a new process everytime the shell starts mpv.net" },
{ name = "single", help = "Force a single process everytime the shell starts mpv.net" },
{ name = "queue", help = "Force a single process and add files to playlist" }]
@@ -26,7 +38,7 @@ options = [{ name = "multi", help = "Create a new process everytime the shell s
name = "debug-mode"
default = "no"
filter = "General"
help = "mpv.net specific setting that writes debug info to a file located on the desktop."
help = "mpv.net specific debugging setting, enable this only when a developer asks for it."
options = [{ name = "yes" },
{ name = "no" }]

View File

@@ -1,5 +1,6 @@
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace mpvnet
{
@@ -9,7 +10,6 @@ namespace mpvnet
{
InitializeComponent();
Version.Text = $"Version {System.Windows.Forms.Application.ProductVersion}";
Foreground = WPF.WPF.ThemeBrush;
}
protected override void OnPreviewKeyDown(KeyEventArgs e) => Close();

View File

@@ -187,7 +187,9 @@ namespace mpvnet
OnKeyUp(new WF.KeyEventArgs((WF.Keys)(unchecked((int)(long)m.WParam)) | ModifierKeys));
else if (m.Msg == WM_APPCOMMAND)
{
switch ((AppCommand)(m.LParam.ToInt32() >> 16))
var value = (AppCommand)(m.LParam.ToInt64() >> 16 & ~0xf000);
switch (value)
{
case AppCommand.MEDIA_CHANNEL_DOWN:
SetKey("Channel_Down");
@@ -231,6 +233,9 @@ namespace mpvnet
case AppCommand.VolumeMute:
SetKey("Mute");
break;
default:
Msg.ShowError($"AppCommand {value} not supported,\nplease contact support.");
break;
}
}
}

View File

@@ -1,7 +1,11 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Media;
using Microsoft.Win32;
using mpvnet;
namespace WPF
{
public class WPF
@@ -22,12 +26,42 @@ namespace WPF
}
}
public static Brush ThemeBrush {
public static Brush ThemeBrush { get; } = new SolidColorBrush(ThemeColor);
static bool WasThemeColorSet;
static Color _ThemeColor;
public static Color ThemeColor {
get {
if (!WasThemeColorSet)
{
Color? color = null;
try {
if (App.IsDarkMode && !string.IsNullOrEmpty(App.DarkColor))
color = (Color)ColorConverter.ConvertFromString(App.DarkColor);
else if (!App.IsDarkMode && !string.IsNullOrEmpty(App.LightColor))
color = (Color)ColorConverter.ConvertFromString(App.LightColor);
} catch { }
if (!color.HasValue)
{
if (Environment.OSVersion.Version.Major < 10)
return new SolidColorBrush(Colors.DarkSlateGray);
{
int argb = Convert.ToInt32(Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM", "ColorizationColor", 0));
if (argb == 0) System.Drawing.Color.Blue.ToArgb();
var c = System.Drawing.Color.FromArgb(argb);
color = Color.FromArgb(c.A, c.R, c.G, c.B);
}
else
return SystemParameters.WindowGlassBrush;
color = SystemParameters.WindowGlassColor;
}
_ThemeColor = color.Value;
WasThemeColorSet = true;
}
return _ThemeColor;
}
}
}

View File

@@ -8,7 +8,6 @@ using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Threading.Tasks;
namespace mpvnet
{
@@ -47,7 +46,10 @@ namespace mpvnet
else
RecentFiles = new List<string>();
if (App.IsDarkMode) ToolStripRendererEx.ColorTheme = Color.Black;
var wpfColor = WPF.WPF.ThemeColor;
Color color = Color.FromArgb(wpfColor.A, wpfColor.R, wpfColor.G, wpfColor.B);
ToolStripRendererEx.InitColors(color, App.IsDarkMode);
ContextMenu = new ContextMenuStripEx(components);
ContextMenu.Opened += ContextMenu_Opened;
ContextMenu.Opening += ContextMenu_Opening;
@@ -403,8 +405,6 @@ namespace mpvnet
mp.command_string("mouse 1 1"); // osc won't always auto hide
break;
case 0x319: // WM_APPCOMMAND
case 0x020C: // WM_XBUTTONUP
case 0x020B: // WM_XBUTTONDOWN
if (mp.WindowHandle != IntPtr.Zero)
Native.PostMessage(mp.WindowHandle, m.Msg, m.WParam, m.LParam);
break;
@@ -567,6 +567,12 @@ namespace mpvnet
Native.PostMessage(Handle, 0xA1 /* WM_NCLBUTTONDOWN */, HTCAPTION, IntPtr.Zero);
}
if (e.Button == MouseButtons.XButton1)
mp.command_string($"mouse {e.Location.X} {e.Location.Y} 7 single");
if (e.Button == MouseButtons.XButton2)
mp.command_string($"mouse {e.Location.X} {e.Location.Y} 8 single");
if (Width - e.Location.X < 10 && e.Location.Y < 10)
mp.commandv("quit");
}

View File

@@ -131,8 +131,10 @@ public class MenuItem : ToolStripMenuItem
public class ToolStripRendererEx : ToolStripSystemRenderer
{
public static bool IsDarkMode { get; set; }
public static Color ColorForeground { get; set; } = Color.Black;
public static Color ColorTheme { get; set; } = Color.Empty;
public static Color ColorTheme { get; set; }
public static Color ColorChecked { get; set; }
public static Color ColorBorder { get; set; }
public static Color ColorTop { get; set; }
@@ -146,19 +148,7 @@ public class ToolStripRendererEx : ToolStripSystemRenderer
int TextOffset;
public ToolStripRendererEx()
{
var argb = Convert.ToInt32(Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM", "ColorizationColor", 0));
if (argb == 0)
argb = Color.LightBlue.ToArgb();
if (ColorTheme == Color.Empty)
InitColors(Color.FromArgb(argb));
else
InitColors(ColorTheme);
}
public static void InitColors(Color c)
public static void InitColors(Color c, bool darkMode)
{
ColorBorder = HSLColor.Convert(c).ToColorSetLuminosity(100);
ColorChecked = HSLColor.Convert(c).ToColorSetLuminosity(160);
@@ -166,7 +156,7 @@ public class ToolStripRendererEx : ToolStripSystemRenderer
ColorBackground = HSLColor.Convert(c).ToColorSetLuminosity(210);
ColorTop = HSLColor.Convert(c).ToColorSetLuminosity(240);
if (ColorTheme == Color.Black)
if (darkMode)
{
ColorBorder = Color.White;
ColorBackground = Color.FromArgb(50, 50, 50);

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
@@ -213,14 +214,16 @@ namespace mpvnet
if (WindowHandle == IntPtr.Zero)
WindowHandle = FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null);
// System.Diagnostics.Debug.WriteLine(evt.event_id.ToString());
// Debug.WriteLine(evt.event_id.ToString());
try
{
switch (evt.event_id)
{
case mpv_event_id.MPV_EVENT_SHUTDOWN:
if (App.DebugMode) Trace.WriteLine("before Shutdown.Invoke");
Shutdown?.Invoke();
if (App.DebugMode) Trace.WriteLine("after Shutdown.Invoke");
WriteHistory(null);
ShutdownAutoResetEvent.Set();
return;

View File

@@ -1,48 +0,0 @@
# exit the script if the exit code is greater than 0
function CheckExitCode {
if ($LastExitCode -gt 0) {
Write-Host "`nExit code $LastExitCode was returned.`n" -ForegroundColor Red
exit
}
}
# exit the script if the file don't exist
function CheckFileExist($path) {
if (![IO.File]::Exists($path)) {
Write-Host "`nFile is missing:`n`n$path`n" -ForegroundColor Red
exit
}
}
$msbuild = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"
$innoSetup = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
$sevenZip = "C:\Program Files\7-Zip\7z.exe"
# exit the script if one of the executables don't exist
CheckFileExist($msbuild); CheckFileExist($innoSetup); CheckFileExist($sevenZip);
# build the projects using msbuild
& $msbuild mpv.net.sln /p:Configuration=Debug /p:Platform=x64; CheckExitCode
& $msbuild mpv.net.sln /p:Configuration=Debug /p:Platform=x86; CheckExitCode
# build the setups using inno setup
& $innoSetup /Darch="x64" setup.iss; CheckExitCode
& $innoSetup /Darch="x86" setup.iss; CheckExitCode
# create the x64 portable archives using 7zip
$scriptDir = Split-Path -Path $PSCommandPath -Parent
$desktopDir = [Environment]::GetFolderPath("Desktop")
$exePath = $scriptDir + "\mpv.net\bin\x64\mpvnet.exe"
$version = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath).FileVersion
$targetDir = $desktopDir + "\mpv.net-portable-x64-" + $version
Copy-Item $scriptDir\mpv.net\bin\x64 $targetDir -Recurse -Exclude System.Management.Automation.xml -Force
& $sevenZip a -t7z -mx9 "$targetDir.7z" -r "$targetDir\*"; CheckExitCode
& $sevenZip a -tzip -mx9 "$targetDir.zip" -r "$targetDir\*"; CheckExitCode
# create the x86 portable archives using 7zip
$exePath = $scriptDir + "\mpv.net\bin\x86\mpvnet.exe"
$version = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath).FileVersion
$targetDir = $desktopDir + "\mpv.net-portable-x86-" + $version
Copy-Item $scriptDir\mpv.net\bin\x86 $targetDir -Recurse -Exclude System.Management.Automation.xml -Force
& $sevenZip a -t7z -mx9 "$targetDir.7z" -r "$targetDir\*"; CheckExitCode
& $sevenZip a -tzip -mx9 "$targetDir.zip" -r "$targetDir\*"; CheckExitCode