From b1388e10e59dddf1a36d37800e4bd0264bd34a33 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Tue, 11 May 2021 10:19:14 +0200 Subject: [PATCH] working on start-size option --- docs/Changelog.md | 9 ++- docs/Manual.md | 6 +- src/Misc/App.cs | 4 +- src/Misc/CSharpScriptHost.cs | 2 +- src/Misc/Commands.cs | 9 ++- src/Misc/PowerShell.cs | 12 ++-- src/Properties/AssemblyInfo.cs | 4 +- src/Resources/editor.toml.txt | 12 ++-- src/Resources/input.conf.txt | 7 ++- src/WinForms/MainForm.cs | 108 +++++++++++++++++---------------- src/mpv/Core.cs | 6 ++ 11 files changed, 96 insertions(+), 83 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index b8cc420..8e87418 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,8 +1,13 @@ -5.4.8.9 Beta (???) +5.4.8.9 Beta (2021-??-??) ========================= -- Reworked [start-size](Manual.md#--start-sizevalue) option. +- New `start-size` option to always keep and remember the width and height. +- There is an issue with the `window-scale` mpv property, it does not + work correctly in mpv either. I've removed support for it and + added an own implementation `script-message mpv.net window-scale`. +- The previous Beta replaced the CS-Script library with an own + C# scripting implementation. 5.4.8.8 Beta (2021-05-09) diff --git a/docs/Manual.md b/docs/Manual.md index 1e347f0..56c8324 100644 --- a/docs/Manual.md +++ b/docs/Manual.md @@ -212,15 +212,15 @@ Save volume and mute on exit and restore it on start. Default: yes #### --start-size=\ -Setting to remember the window height. +Setting to remember the window size. **video** Window size is set to video resolution. -**previous-height** +**height-session** Height is remembered in the current session. Default -**always-height** +**height-always** Height is always remembered. **always** diff --git a/src/Misc/App.cs b/src/Misc/App.cs index 5e83472..cc53b6f 100644 --- a/src/Misc/App.cs +++ b/src/Misc/App.cs @@ -18,7 +18,7 @@ namespace mpvnet public static string DarkMode { get; set; } = "always"; public static string DarkTheme { get; set; } = "dark"; public static string LightTheme { get; set; } = "light"; - public static string StartSize { get; set; } = "previous-height"; + public static string StartSize { get; set; } = "height-session"; public static bool RememberPosition { get; set; } public static bool DebugMode { get; set; } @@ -96,7 +96,7 @@ namespace mpvnet public static string Version { get { - return "Copyright (C) 2017-2021 mpv.net/mpv/mplayer\n" + + return "Copyright (C) 2000-2021 mpv.net/mpv/mplayer\n" + $"mpv.net {Application.ProductVersion} ({File.GetLastWriteTime(Application.ExecutablePath).ToShortDateString()})\n" + $"{core.get_property_string("mpv-version")} ({File.GetLastWriteTime(Folder.Startup + "mpv-1.dll").ToShortDateString()})\nffmpeg {core.get_property_string("ffmpeg-version")}\nMIT License"; } diff --git a/src/Misc/CSharpScriptHost.cs b/src/Misc/CSharpScriptHost.cs index a7797ad..f3bf744 100644 --- a/src/Misc/CSharpScriptHost.cs +++ b/src/Misc/CSharpScriptHost.cs @@ -54,7 +54,7 @@ namespace mpvnet parameters.OutputAssembly = outputFile; CompilerResults results = provider.CompileAssemblyFromFile(parameters, file); - var errors = results.Errors.Cast().Select((i) => "Line Number " + + var errors = results.Errors.Cast().Select(i => "Line Number " + i.Line + "\r\n" + "Error Number: " + i.ErrorNumber + "\r\n" + i.ErrorText); if (errors.Count() > 0) diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index 85c219a..b854970 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -12,7 +12,6 @@ using VB = Microsoft.VisualBasic; using static mpvnet.NewLine; using static mpvnet.Core; -using System.Threading.Tasks; namespace mpvnet { @@ -35,6 +34,7 @@ namespace mpvnet case "playlist-first": PlaylistFirst(); break; case "playlist-last": PlaylistLast(); break; case "scale-window": ScaleWindow(float.Parse(args[0], CultureInfo.InvariantCulture)); break; + case "window-scale": WindowScale(float.Parse(args[0], CultureInfo.InvariantCulture)); break; case "shell-execute": ProcessHelp.ShellExecute(args[0]); break; case "show-about": ShowDialog(typeof(AboutWindow)); break; case "show-audio-devices": ShowTextWithEditor("audio-device-list", core.get_property_osd_string("audio-device-list")); break; @@ -350,10 +350,9 @@ namespace mpvnet ProcessHelp.ShellExecute(file); } - public static void ScaleWindow(float factor) - { - core.RaiseScaleWindow(factor); - } + public static void ScaleWindow(float factor) => core.RaiseScaleWindow(factor); + + public static void WindowScale(float value) => core.RaiseWindowScale(value); public static void ShowText(string text, int duration = 0, int fontSize = 0) { diff --git a/src/Misc/PowerShell.cs b/src/Misc/PowerShell.cs index 2b86832..e700fd5 100644 --- a/src/Misc/PowerShell.cs +++ b/src/Misc/PowerShell.cs @@ -137,16 +137,16 @@ namespace mpvnet switch (type) { case "bool": case "boolean": - core.observe_property_bool(name, (value) => App.RunTask(() => PropertyChanged.Invoke(name, value))); + core.observe_property_bool(name, value => App.RunTask(() => PropertyChanged.Invoke(name, value))); break; case "string": - core.observe_property_string(name, (value) => App.RunTask(() => PropertyChanged.Invoke(name, value))); + core.observe_property_string(name, value => App.RunTask(() => PropertyChanged.Invoke(name, value))); break; case "int": case "integer": - core.observe_property_int(name, (value) => App.RunTask(() => PropertyChanged.Invoke(name, value))); + core.observe_property_int(name, value => App.RunTask(() => PropertyChanged.Invoke(name, value))); break; case "float": case "double": - core.observe_property_double(name, (value) => App.RunTask(() => PropertyChanged.Invoke(name, value))); + core.observe_property_double(name, value => App.RunTask(() => PropertyChanged.Invoke(name, value))); break; case "nil": case "none": case "native": core.observe_property(name, () => App.RunTask(() => PropertyChanged.Invoke(name, null))); @@ -168,11 +168,11 @@ namespace mpvnet break; case "end-file": - core.EndFileAsync += (reason) => Event.Invoke("end-file", new object[] { reason }); + core.EndFileAsync += reason => Event.Invoke("end-file", new object[] { reason }); break; case "client-message": - core.ClientMessageAsync += (args) => Event.Invoke("client-message", args); + core.ClientMessageAsync += args => Event.Invoke("client-message", args); break; case "shutdown": diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index 2ad11d3..d8a0f3c 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -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("5.4.8.8")] -[assembly: AssemblyFileVersion("5.4.8.8")] +[assembly: AssemblyVersion("5.4.8.9")] +[assembly: AssemblyFileVersion("5.4.8.9")] diff --git a/src/Resources/editor.toml.txt b/src/Resources/editor.toml.txt index d52ea20..9a46e9d 100644 --- a/src/Resources/editor.toml.txt +++ b/src/Resources/editor.toml.txt @@ -328,7 +328,7 @@ help = " Initial window height in percent. Default: 60" name = "autofit-smaller" file = "mpv" filter = "Screen" -help = " Minimum window height in percent. Default: 30" +help = " Minimum window height in percent. Default: 10" [[settings]] name = "autofit-larger" @@ -339,13 +339,13 @@ help = " Maximum window height in percent. Default: 80" [[settings]] name = "start-size" file = "mpvnet" -default = "previous-height" +default = "height-session" filter = "Screen" help = "Setting to remember the window size. (mpv.net specific setting)" -options = [{ name = "video", help = "Window size is set to video resolution" }, - { name = "previous-height", help = "Height is remembered in the current session" }, - { name = "always-height", help = "Height is always remembered" }, - { name = "always", help = "Size is always remembered" }] +options = [{ name = "video", help = "Window size is set to video resolution" }, + { name = "height-session", help = "Height is remembered in the current session" }, + { name = "height-always", help = "Height is always remembered" }, + { name = "always", help = "Size is always remembered" }] [[settings]] name = "start-threshold" diff --git a/src/Resources/input.conf.txt b/src/Resources/input.conf.txt index 33eb150..be6e21f 100644 --- a/src/Resources/input.conf.txt +++ b/src/Resources/input.conf.txt @@ -135,9 +135,10 @@ Alt++ script-message mpv.net scale-window 1.2 #menu: View > Zoom > Enlarge Alt+- script-message mpv.net scale-window 0.8 #menu: View > Zoom > Shrink _ ignore #menu: View > Zoom > - - Alt+0 set window-scale 0.5 #menu: View > Zoom > 50 % - Alt+1 set window-scale 1.0 #menu: View > Zoom > 100 % - Alt+2 set window-scale 2.0 #menu: View > Zoom > 200 % + Alt+0 script-message mpv.net window-scale 0.5 #menu: View > Zoom > 50 % + Alt+1 script-message mpv.net window-scale 1.0 #menu: View > Zoom > 100 % + Alt+2 script-message mpv.net window-scale 2.0 #menu: View > Zoom > 200 % + Alt+3 script-message mpv.net window-scale 3.0 #menu: View > Zoom > 300 % b cycle border #menu: View > Toggle Border i script-message mpv.net show-info #menu: View > File/Stream Info t script-binding stats/display-stats #menu: View > Show Statistics diff --git a/src/WinForms/MainForm.cs b/src/WinForms/MainForm.cs index 0442298..52452fb 100644 --- a/src/WinForms/MainForm.cs +++ b/src/WinForms/MainForm.cs @@ -51,6 +51,7 @@ namespace mpvnet core.Shutdown += Shutdown; core.VideoSizeChanged += VideoSizeChanged; core.ScaleWindow += ScaleWindow; + core.WindowScale += WindowScale; core.FileLoaded += FileLoaded; core.Idle += Idle; core.Seek += () => UpdateProgressBar(); @@ -69,7 +70,6 @@ namespace mpvnet core.observe_property_string("title", PropChangeTitle); core.observe_property_int("edition", PropChangeEdition); - core.observe_property_double("window-scale", PropChangeWindowScale); if (core.GPUAPI != "vulkan") core.ProcessCommandLine(false); @@ -116,13 +116,13 @@ namespace mpvnet if (core.WindowMaximized) { - SetFormPosAndSize(1, true); + SetFormPosAndSize(true); WindowState = FormWindowState.Maximized; } if (core.WindowMinimized) { - SetFormPosAndSize(1, true); + SetFormPosAndSize(true); WindowState = FormWindowState.Minimized; } } @@ -132,21 +132,23 @@ namespace mpvnet } } - void ScaleWindow(float value) { + void ScaleWindow(float scale) { BeginInvoke(new Action(() => { - if (value < 1 && (Width == MinimumSize.Width || Height == MinimumSize.Height)) - return; - SetFormPosAndSize(value, false, false, false); + int w = (int)(ClientSize.Width * scale); + int h = (int)Math.Ceiling(w * core.VideoSize.Height / (double)core.VideoSize.Width); + SetSize(w, h, Screen.FromControl(this), false); })); } - void WindowScale(double scale) + void WindowScale(float scale) { - if (!WasShown()) - return; - - Size size = new Size((int)(core.VideoSize.Width * scale), (int)(core.VideoSize.Height * scale)); - SetSize(size, core.VideoSize, Screen.FromControl(this), false, false); + BeginInvoke(new Action(() => { + SetSize( + (int)(core.VideoSize.Width * scale), + (int)Math.Ceiling(core.VideoSize.Height * scale), + Screen.FromControl(this), false); + core.command($"show-text \"window-scale {scale.ToString(CultureInfo.InvariantCulture)}\""); + })); } public MenuItem FindMenuItem(string text) => FindMenuItem(text, ContextMenu.Items); @@ -313,18 +315,16 @@ namespace mpvnet if (mi.DropDownItems.Count > 0) { MenuItem val = FindMenuItem(text, mi.DropDownItems); - if (val != null) return val; + + if (val != null) + return val; } } } return null; } - void SetFormPosAndSize( - double scale = 1, - bool force = false, - bool checkAutofitSmaller = true, - bool checkAutofitLarger = true) + void SetFormPosAndSize(bool force = false, bool checkAutofit = true) { if (!force) { @@ -352,16 +352,16 @@ namespace mpvnet int width = videoSize.Width; if (App.StartSize == "previous") - App.StartSize = "previous-height"; + App.StartSize = "height-session"; - if (core.WasInitialSizeSet || scale != 1) + if (core.WasInitialSizeSet) { if (App.StartSize == "always") { width = ClientSize.Width; height = ClientSize.Height; } - else if (App.StartSize == "always-height" || App.StartSize == "previous-height") + else if (App.StartSize == "height-always" || App.StartSize == "height-session") { height = ClientSize.Height; width = height * videoSize.Width / videoSize.Height; @@ -372,7 +372,7 @@ namespace mpvnet int savedHeight = RegistryHelp.GetInt("Height"); int savedWidth = RegistryHelp.GetInt("Width"); - if (App.StartSize == "always-height" && savedHeight != 0) + if (App.StartSize == "height-always" && savedHeight != 0) { height = savedHeight; width = height * videoSize.Width / videoSize.Height; @@ -382,7 +382,7 @@ namespace mpvnet height = savedHeight; width = savedWidth; } - else if (App.StartSize == "previous-height") + else if (App.StartSize == "height-session") { height = autoFitHeight; width = height * videoSize.Width / videoSize.Height; @@ -391,43 +391,48 @@ namespace mpvnet core.WasInitialSizeSet = true; } - height = Convert.ToInt32(height * scale); - width = Convert.ToInt32(width * scale); - - SetSize(new Size(width, height), videoSize, screen, checkAutofitSmaller, checkAutofitLarger); + SetSize(width, height, screen, checkAutofit); } - void SetSize( - Size size, - Size videoSize, - Screen screen, - bool checkAutofitSmaller = true, - bool checkAutofitLarger = true) + void SetSize(int width, int height, Screen screen, bool checkAutofit = true) { - int height = size.Height; - int width = size.Width; + int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height) - FontHeight / 2; + int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width) - FontHeight / 2; - int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height); - int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width); + int startWidth = width; + int startHeight = height; - if (checkAutofitSmaller && (height < maxHeight * core.AutofitSmaller)) + if (checkAutofit) { - height = Convert.ToInt32(maxHeight * core.AutofitSmaller); - width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); - } + if (height < maxHeight * core.AutofitSmaller) + { + height = Convert.ToInt32(maxHeight * core.AutofitSmaller); + width = Convert.ToInt32(height * startWidth / (double)startHeight); + } - float autofitLarger = checkAutofitLarger ? core.AutofitLarger : 1; - - if (height > maxHeight * autofitLarger) - { - height = Convert.ToInt32(maxHeight * autofitLarger); - width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); + if (height > maxHeight * core.AutofitLarger) + { + height = Convert.ToInt32(maxHeight * core.AutofitLarger); + width = Convert.ToInt32(height * startWidth / (double)startHeight); + } } if (width > maxWidth) { width = maxWidth; - height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width); + height = (int)Math.Ceiling(width * startHeight / (double)width); + } + + if (height > maxHeight) + { + height = maxHeight; + width = Convert.ToInt32(height * startWidth / (double)startHeight); + } + + if (height < maxHeight * 0.1) + { + height = Convert.ToInt32(maxHeight * 0.1); + width = Convert.ToInt32(height * startWidth / (double)startHeight); } Point middlePos = new Point(Left + Width / 2, Top + Height / 2); @@ -764,8 +769,6 @@ namespace mpvnet void PropChangeTitle(string value) { Title = value; SetTitle(); } void PropChangeEdition(int value) => core.Edition = value; - - void PropChangeWindowScale(double value) => BeginInvoke(new Action(() => WindowScale(value))); void PropChangeWindowMaximized() { @@ -857,7 +860,6 @@ namespace mpvnet WPF.Init(); System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y); - MinimumSize = new Size(FontHeight * 9, FontHeight * 9); UpdateCheck.DailyCheck(); core.LoadScripts(); GlobalHotkey.RegisterGlobalHotkeys(Handle); @@ -871,7 +873,7 @@ namespace mpvnet { base.OnActivated(e); Message m = new Message() { Msg = 0x0202 }; // WM_LBUTTONUP - SendMessage(MainForm.Instance.Handle, m.Msg, m.WParam, m.LParam); + SendMessage(Handle, m.Msg, m.WParam, m.LParam); } protected override void OnResize(EventArgs e) diff --git a/src/mpv/Core.cs b/src/mpv/Core.cs index d76dddd..3b25732 100644 --- a/src/mpv/Core.cs +++ b/src/mpv/Core.cs @@ -76,6 +76,7 @@ namespace mpvnet public event Action VideoSizeChanged; public event Action VideoSizeChangedAsync; public event Action ScaleWindow; + public event Action WindowScale; public Dictionary> PropChangeActions { get; set; } = new Dictionary>(); public Dictionary>> IntPropChangeActions { get; set; } = new Dictionary>>(); @@ -1298,6 +1299,11 @@ namespace mpvnet ScaleWindow(value); } + public void RaiseWindowScale(float value) + { + WindowScale(value); + } + void ReadMetaData() { string path = get_property_string("path");