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

@@ -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";
}

View File

@@ -54,7 +54,7 @@ namespace mpvnet
parameters.OutputAssembly = outputFile;
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);
if (errors.Count() > 0)

View File

@@ -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)
{

View File

@@ -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":

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("5.4.8.8")]
[assembly: AssemblyFileVersion("5.4.8.8")]
[assembly: AssemblyVersion("5.4.8.9")]
[assembly: AssemblyFileVersion("5.4.8.9")]

View File

@@ -328,7 +328,7 @@ help = "<int> Initial window height in percent. Default: 60"
name = "autofit-smaller"
file = "mpv"
filter = "Screen"
help = "<int> Minimum window height in percent. Default: 30"
help = "<int> Minimum window height in percent. Default: 10"
[[settings]]
name = "autofit-larger"
@@ -339,13 +339,13 @@ help = "<int> 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"

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 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

View File

@@ -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)

View File

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