From 69857e0548943a2a9d9d2dcee997d33f59e42f1d Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Tue, 11 May 2021 17:55:37 +0200 Subject: [PATCH] new window features --- docs/Changelog.md | 8 +++-- docs/Manual.md | 6 ++++ src/Resources/editor.toml.txt | 2 ++ src/WinForms/MainForm.cs | 63 +++++++++++++++++++++++++++++++---- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/docs/Changelog.md b/docs/Changelog.md index 8e87418..b2f9177 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -2,12 +2,14 @@ 5.4.8.9 Beta (2021-??-??) ========================= -- 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 + work correctly in mpv either, so 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 +- The previous Beta replaced the CS-Script library with my own C# scripting implementation. +- If a player window border is near to a screen border and the window size + changes, the player windows sticks to that near screen border location. +- `start-size` option has new options, see in config editor and manual. 5.4.8.8 Beta (2021-05-09) diff --git a/docs/Manual.md b/docs/Manual.md index 56c8324..553684e 100644 --- a/docs/Manual.md +++ b/docs/Manual.md @@ -217,6 +217,12 @@ Setting to remember the window size. **video** Window size is set to video resolution. +**width-session** +Width is remembered in the current session. + +**width-always** +Width is always remembered. + **height-session** Height is remembered in the current session. Default diff --git a/src/Resources/editor.toml.txt b/src/Resources/editor.toml.txt index 9a46e9d..fbe25b1 100644 --- a/src/Resources/editor.toml.txt +++ b/src/Resources/editor.toml.txt @@ -343,6 +343,8 @@ 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 = "width-session", help = "Width is remembered in the current session" }, + { name = "width-always", help = "Width is always remembered" }, { 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" }] diff --git a/src/WinForms/MainForm.cs b/src/WinForms/MainForm.cs index 52452fb..f1a7ece 100644 --- a/src/WinForms/MainForm.cs +++ b/src/WinForms/MainForm.cs @@ -366,6 +366,11 @@ namespace mpvnet height = ClientSize.Height; width = height * videoSize.Width / videoSize.Height; } + else if (App.StartSize == "width-always" || App.StartSize == "width-session") + { + width = ClientSize.Width; + height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width); + } } else { @@ -377,16 +382,26 @@ namespace mpvnet height = savedHeight; width = height * videoSize.Width / videoSize.Height; } - else if (App.StartSize == "always" && savedHeight != 0) - { - height = savedHeight; - width = savedWidth; - } else if (App.StartSize == "height-session") { height = autoFitHeight; width = height * videoSize.Width / videoSize.Height; } + if (App.StartSize == "width-always" && savedHeight != 0) + { + width = savedWidth; + height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width); + } + else if (App.StartSize == "width-session") + { + width = autoFitHeight / 9 * 16; + height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width); + } + else if (App.StartSize == "always" && savedHeight != 0) + { + height = savedHeight; + width = savedWidth; + } core.WasInitialSizeSet = true; } @@ -420,7 +435,7 @@ namespace mpvnet if (width > maxWidth) { width = maxWidth; - height = (int)Math.Ceiling(width * startHeight / (double)width); + height = (int)Math.Ceiling(width * startHeight / (double)startWidth); } if (height > maxHeight) @@ -440,6 +455,14 @@ namespace mpvnet NativeHelp.AddWindowBorders(Handle, ref rect); int left = middlePos.X - rect.Width / 2; int top = middlePos.Y - rect.Height / 2; + Rectangle workingArea = screen.WorkingArea; + Rectangle currentRect = new Rectangle(Left, Top, Width, Height); + + if (HorizontalLocation(screen) == -1) left = Left; + if (HorizontalLocation(screen) == 1) left = currentRect.Right - rect.Width; + + if (VerticalLocation(screen) == -1) top = Top; + if (VerticalLocation(screen) == 1) top = currentRect.Bottom - rect.Height; Screen[] screens = Screen.AllScreens; int minLeft = screens.Select(val => val.WorkingArea.X).Min(); @@ -462,6 +485,34 @@ namespace mpvnet SetWindowPos(Handle, IntPtr.Zero, left, top, rect.Width, rect.Height, 4); } + public int HorizontalLocation(Screen screen) + { + Rectangle workingArea = screen.WorkingArea; + Rectangle rect = new Rectangle(Left - workingArea.X, Top - workingArea.Y, Width, Height); + + if (rect.X * 3 < workingArea.Width - rect.Right) + return -1; + + if (rect.X > (workingArea.Width - rect.Right) * 3) + return 1; + + return 0; + } + + public int VerticalLocation(Screen screen) + { + Rectangle workingArea = screen.WorkingArea; + Rectangle rect = new Rectangle(Left - workingArea.X, Top - workingArea.Y, Width, Height); + + if (rect.Y * 3 < workingArea.Height - rect.Bottom) + return -1; + + if (rect.Y > (workingArea.Height - rect.Bottom) * 3) + return 1; + + return 0; + } + public void CycleFullscreen(bool enabled) { LastCycleFullscreen = Environment.TickCount;