working on start-size option

This commit is contained in:
Frank Skare
2021-05-11 10:19:14 +02:00
parent 6f7f127279
commit b1388e10e5
11 changed files with 96 additions and 83 deletions

View File

@@ -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) 5.4.8.8 Beta (2021-05-09)

View File

@@ -212,15 +212,15 @@ Save volume and mute on exit and restore it on start. Default: yes
#### --start-size=\<value\> #### --start-size=\<value\>
Setting to remember the window height. Setting to remember the window size.
**video** **video**
Window size is set to video resolution. Window size is set to video resolution.
**previous-height** **height-session**
Height is remembered in the current session. Default Height is remembered in the current session. Default
**always-height** **height-always**
Height is always remembered. Height is always remembered.
**always** **always**

View File

@@ -18,7 +18,7 @@ namespace mpvnet
public static string DarkMode { get; set; } = "always"; public static string DarkMode { get; set; } = "always";
public static string DarkTheme { get; set; } = "dark"; public static string DarkTheme { get; set; } = "dark";
public static string LightTheme { get; set; } = "light"; 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 RememberPosition { get; set; }
public static bool DebugMode { get; set; } public static bool DebugMode { get; set; }
@@ -96,7 +96,7 @@ namespace mpvnet
public static string Version { public static string Version {
get { 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" + $"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"; $"{core.get_property_string("mpv-version")} ({File.GetLastWriteTime(Folder.Startup + "mpv-1.dll").ToShortDateString()})\nffmpeg {core.get_property_string("ffmpeg-version")}\nMIT License";
} }

View File

@@ -54,7 +54,7 @@ namespace mpvnet
parameters.OutputAssembly = outputFile; parameters.OutputAssembly = outputFile;
CompilerResults results = provider.CompileAssemblyFromFile(parameters, file); CompilerResults results = provider.CompileAssemblyFromFile(parameters, file);
var errors = results.Errors.Cast<CompilerError>().Select((i) => "Line Number " + var errors = results.Errors.Cast<CompilerError>().Select(i => "Line Number " +
i.Line + "\r\n" + "Error Number: " + i.ErrorNumber + "\r\n" + i.ErrorText); i.Line + "\r\n" + "Error Number: " + i.ErrorNumber + "\r\n" + i.ErrorText);
if (errors.Count() > 0) if (errors.Count() > 0)

View File

@@ -12,7 +12,6 @@ using VB = Microsoft.VisualBasic;
using static mpvnet.NewLine; using static mpvnet.NewLine;
using static mpvnet.Core; using static mpvnet.Core;
using System.Threading.Tasks;
namespace mpvnet namespace mpvnet
{ {
@@ -35,6 +34,7 @@ namespace mpvnet
case "playlist-first": PlaylistFirst(); break; case "playlist-first": PlaylistFirst(); break;
case "playlist-last": PlaylistLast(); break; case "playlist-last": PlaylistLast(); break;
case "scale-window": ScaleWindow(float.Parse(args[0], CultureInfo.InvariantCulture)); 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 "shell-execute": ProcessHelp.ShellExecute(args[0]); break;
case "show-about": ShowDialog(typeof(AboutWindow)); 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; 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); ProcessHelp.ShellExecute(file);
} }
public static void ScaleWindow(float factor) public static void ScaleWindow(float factor) => core.RaiseScaleWindow(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) public static void ShowText(string text, int duration = 0, int fontSize = 0)
{ {

View File

@@ -137,16 +137,16 @@ namespace mpvnet
switch (type) switch (type)
{ {
case "bool": case "boolean": 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; break;
case "string": 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; break;
case "int": case "integer": 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; break;
case "float": case "double": 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; break;
case "nil": case "none": case "native": case "nil": case "none": case "native":
core.observe_property(name, () => App.RunTask(() => PropertyChanged.Invoke(name, null))); core.observe_property(name, () => App.RunTask(() => PropertyChanged.Invoke(name, null)));
@@ -168,11 +168,11 @@ namespace mpvnet
break; break;
case "end-file": case "end-file":
core.EndFileAsync += (reason) => Event.Invoke("end-file", new object[] { reason }); core.EndFileAsync += reason => Event.Invoke("end-file", new object[] { reason });
break; break;
case "client-message": case "client-message":
core.ClientMessageAsync += (args) => Event.Invoke("client-message", args); core.ClientMessageAsync += args => Event.Invoke("client-message", args);
break; break;
case "shutdown": case "shutdown":

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 // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.4.8.8")] [assembly: AssemblyVersion("5.4.8.9")]
[assembly: AssemblyFileVersion("5.4.8.8")] [assembly: AssemblyFileVersion("5.4.8.9")]

View File

@@ -328,7 +328,7 @@ help = "<int> Initial window height in percent. Default: 60"
name = "autofit-smaller" name = "autofit-smaller"
file = "mpv" file = "mpv"
filter = "Screen" filter = "Screen"
help = "<int> Minimum window height in percent. Default: 30" help = "<int> Minimum window height in percent. Default: 10"
[[settings]] [[settings]]
name = "autofit-larger" name = "autofit-larger"
@@ -339,12 +339,12 @@ help = "<int> Maximum window height in percent. Default: 80"
[[settings]] [[settings]]
name = "start-size" name = "start-size"
file = "mpvnet" file = "mpvnet"
default = "previous-height" default = "height-session"
filter = "Screen" filter = "Screen"
help = "Setting to remember the window size. (mpv.net specific setting)" help = "Setting to remember the window size. (mpv.net specific setting)"
options = [{ name = "video", help = "Window size is set to video resolution" }, options = [{ name = "video", help = "Window size is set to video resolution" },
{ name = "previous-height", help = "Height is remembered in the current session" }, { name = "height-session", help = "Height is remembered in the current session" },
{ name = "always-height", help = "Height is always remembered" }, { name = "height-always", help = "Height is always remembered" },
{ name = "always", help = "Size is always remembered" }] { name = "always", help = "Size is always remembered" }]
[[settings]] [[settings]]

View File

@@ -135,9 +135,10 @@
Alt++ script-message mpv.net scale-window 1.2 #menu: View > Zoom > Enlarge 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 Alt+- script-message mpv.net scale-window 0.8 #menu: View > Zoom > Shrink
_ ignore #menu: View > Zoom > - _ ignore #menu: View > Zoom > -
Alt+0 set window-scale 0.5 #menu: View > Zoom > 50 % Alt+0 script-message mpv.net window-scale 0.5 #menu: View > Zoom > 50 %
Alt+1 set window-scale 1.0 #menu: View > Zoom > 100 % Alt+1 script-message mpv.net window-scale 1.0 #menu: View > Zoom > 100 %
Alt+2 set window-scale 2.0 #menu: View > Zoom > 200 % 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 b cycle border #menu: View > Toggle Border
i script-message mpv.net show-info #menu: View > File/Stream Info i script-message mpv.net show-info #menu: View > File/Stream Info
t script-binding stats/display-stats #menu: View > Show Statistics t script-binding stats/display-stats #menu: View > Show Statistics

View File

@@ -51,6 +51,7 @@ namespace mpvnet
core.Shutdown += Shutdown; core.Shutdown += Shutdown;
core.VideoSizeChanged += VideoSizeChanged; core.VideoSizeChanged += VideoSizeChanged;
core.ScaleWindow += ScaleWindow; core.ScaleWindow += ScaleWindow;
core.WindowScale += WindowScale;
core.FileLoaded += FileLoaded; core.FileLoaded += FileLoaded;
core.Idle += Idle; core.Idle += Idle;
core.Seek += () => UpdateProgressBar(); core.Seek += () => UpdateProgressBar();
@@ -69,7 +70,6 @@ namespace mpvnet
core.observe_property_string("title", PropChangeTitle); core.observe_property_string("title", PropChangeTitle);
core.observe_property_int("edition", PropChangeEdition); core.observe_property_int("edition", PropChangeEdition);
core.observe_property_double("window-scale", PropChangeWindowScale);
if (core.GPUAPI != "vulkan") if (core.GPUAPI != "vulkan")
core.ProcessCommandLine(false); core.ProcessCommandLine(false);
@@ -116,13 +116,13 @@ namespace mpvnet
if (core.WindowMaximized) if (core.WindowMaximized)
{ {
SetFormPosAndSize(1, true); SetFormPosAndSize(true);
WindowState = FormWindowState.Maximized; WindowState = FormWindowState.Maximized;
} }
if (core.WindowMinimized) if (core.WindowMinimized)
{ {
SetFormPosAndSize(1, true); SetFormPosAndSize(true);
WindowState = FormWindowState.Minimized; WindowState = FormWindowState.Minimized;
} }
} }
@@ -132,21 +132,23 @@ namespace mpvnet
} }
} }
void ScaleWindow(float value) { void ScaleWindow(float scale) {
BeginInvoke(new Action(() => { BeginInvoke(new Action(() => {
if (value < 1 && (Width == MinimumSize.Width || Height == MinimumSize.Height)) int w = (int)(ClientSize.Width * scale);
return; int h = (int)Math.Ceiling(w * core.VideoSize.Height / (double)core.VideoSize.Width);
SetFormPosAndSize(value, false, false, false); SetSize(w, h, Screen.FromControl(this), false);
})); }));
} }
void WindowScale(double scale) void WindowScale(float scale)
{ {
if (!WasShown()) BeginInvoke(new Action(() => {
return; SetSize(
(int)(core.VideoSize.Width * scale),
Size size = new Size((int)(core.VideoSize.Width * scale), (int)(core.VideoSize.Height * scale)); (int)Math.Ceiling(core.VideoSize.Height * scale),
SetSize(size, core.VideoSize, Screen.FromControl(this), false, false); Screen.FromControl(this), false);
core.command($"show-text \"window-scale {scale.ToString(CultureInfo.InvariantCulture)}\"");
}));
} }
public MenuItem FindMenuItem(string text) => FindMenuItem(text, ContextMenu.Items); public MenuItem FindMenuItem(string text) => FindMenuItem(text, ContextMenu.Items);
@@ -313,18 +315,16 @@ namespace mpvnet
if (mi.DropDownItems.Count > 0) if (mi.DropDownItems.Count > 0)
{ {
MenuItem val = FindMenuItem(text, mi.DropDownItems); MenuItem val = FindMenuItem(text, mi.DropDownItems);
if (val != null) return val;
if (val != null)
return val;
} }
} }
} }
return null; return null;
} }
void SetFormPosAndSize( void SetFormPosAndSize(bool force = false, bool checkAutofit = true)
double scale = 1,
bool force = false,
bool checkAutofitSmaller = true,
bool checkAutofitLarger = true)
{ {
if (!force) if (!force)
{ {
@@ -352,16 +352,16 @@ namespace mpvnet
int width = videoSize.Width; int width = videoSize.Width;
if (App.StartSize == "previous") if (App.StartSize == "previous")
App.StartSize = "previous-height"; App.StartSize = "height-session";
if (core.WasInitialSizeSet || scale != 1) if (core.WasInitialSizeSet)
{ {
if (App.StartSize == "always") if (App.StartSize == "always")
{ {
width = ClientSize.Width; width = ClientSize.Width;
height = ClientSize.Height; 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; height = ClientSize.Height;
width = height * videoSize.Width / videoSize.Height; width = height * videoSize.Width / videoSize.Height;
@@ -372,7 +372,7 @@ namespace mpvnet
int savedHeight = RegistryHelp.GetInt("Height"); int savedHeight = RegistryHelp.GetInt("Height");
int savedWidth = RegistryHelp.GetInt("Width"); int savedWidth = RegistryHelp.GetInt("Width");
if (App.StartSize == "always-height" && savedHeight != 0) if (App.StartSize == "height-always" && savedHeight != 0)
{ {
height = savedHeight; height = savedHeight;
width = height * videoSize.Width / videoSize.Height; width = height * videoSize.Width / videoSize.Height;
@@ -382,7 +382,7 @@ namespace mpvnet
height = savedHeight; height = savedHeight;
width = savedWidth; width = savedWidth;
} }
else if (App.StartSize == "previous-height") else if (App.StartSize == "height-session")
{ {
height = autoFitHeight; height = autoFitHeight;
width = height * videoSize.Width / videoSize.Height; width = height * videoSize.Width / videoSize.Height;
@@ -391,43 +391,48 @@ namespace mpvnet
core.WasInitialSizeSet = true; core.WasInitialSizeSet = true;
} }
height = Convert.ToInt32(height * scale); SetSize(width, height, screen, checkAutofit);
width = Convert.ToInt32(width * scale);
SetSize(new Size(width, height), videoSize, screen, checkAutofitSmaller, checkAutofitLarger);
} }
void SetSize( void SetSize(int width, int height, Screen screen, bool checkAutofit = true)
Size size,
Size videoSize,
Screen screen,
bool checkAutofitSmaller = true,
bool checkAutofitLarger = true)
{ {
int height = size.Height; int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height) - FontHeight / 2;
int width = size.Width; int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width) - FontHeight / 2;
int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height); int startWidth = width;
int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width); int startHeight = height;
if (checkAutofitSmaller && (height < maxHeight * core.AutofitSmaller)) if (checkAutofit)
{
if (height < maxHeight * core.AutofitSmaller)
{ {
height = Convert.ToInt32(maxHeight * core.AutofitSmaller); height = Convert.ToInt32(maxHeight * core.AutofitSmaller);
width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); width = Convert.ToInt32(height * startWidth / (double)startHeight);
} }
float autofitLarger = checkAutofitLarger ? core.AutofitLarger : 1; if (height > maxHeight * core.AutofitLarger)
if (height > maxHeight * autofitLarger)
{ {
height = Convert.ToInt32(maxHeight * autofitLarger); height = Convert.ToInt32(maxHeight * core.AutofitLarger);
width = Convert.ToInt32(height * videoSize.Width / videoSize.Height); width = Convert.ToInt32(height * startWidth / (double)startHeight);
}
} }
if (width > maxWidth) if (width > maxWidth)
{ {
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); Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
@@ -765,8 +770,6 @@ namespace mpvnet
void PropChangeEdition(int value) => core.Edition = value; void PropChangeEdition(int value) => core.Edition = value;
void PropChangeWindowScale(double value) => BeginInvoke(new Action(() => WindowScale(value)));
void PropChangeWindowMaximized() void PropChangeWindowMaximized()
{ {
if (!WasShown()) if (!WasShown())
@@ -857,7 +860,6 @@ namespace mpvnet
WPF.Init(); WPF.Init();
System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y); Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y);
MinimumSize = new Size(FontHeight * 9, FontHeight * 9);
UpdateCheck.DailyCheck(); UpdateCheck.DailyCheck();
core.LoadScripts(); core.LoadScripts();
GlobalHotkey.RegisterGlobalHotkeys(Handle); GlobalHotkey.RegisterGlobalHotkeys(Handle);
@@ -871,7 +873,7 @@ namespace mpvnet
{ {
base.OnActivated(e); base.OnActivated(e);
Message m = new Message() { Msg = 0x0202 }; // WM_LBUTTONUP 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) protected override void OnResize(EventArgs e)

View File

@@ -76,6 +76,7 @@ namespace mpvnet
public event Action VideoSizeChanged; public event Action VideoSizeChanged;
public event Action VideoSizeChangedAsync; public event Action VideoSizeChangedAsync;
public event Action<float> ScaleWindow; public event Action<float> ScaleWindow;
public event Action<float> WindowScale;
public Dictionary<string, List<Action>> PropChangeActions { get; set; } = new Dictionary<string, List<Action>>(); public Dictionary<string, List<Action>> PropChangeActions { get; set; } = new Dictionary<string, List<Action>>();
public Dictionary<string, List<Action<int>>> IntPropChangeActions { get; set; } = new Dictionary<string, List<Action<int>>>(); public Dictionary<string, List<Action<int>>> IntPropChangeActions { get; set; } = new Dictionary<string, List<Action<int>>>();
@@ -1298,6 +1299,11 @@ namespace mpvnet
ScaleWindow(value); ScaleWindow(value);
} }
public void RaiseWindowScale(float value)
{
WindowScale(value);
}
void ReadMetaData() void ReadMetaData()
{ {
string path = get_property_string("path"); string path = get_property_string("path");