window-size mpv property support added

This commit is contained in:
Frank Skare
2019-10-14 15:50:20 +02:00
parent b94f9de582
commit 4a202245b5
6 changed files with 86 additions and 24 deletions

View File

@@ -6,6 +6,7 @@
context menu item in explorer with multi selection support use my
[Open with++](https://github.com/stax76/OpenWithPlusPlus#add-to-mpvnet-playlist) shell extension, as far as I know multi selection
can not be done using the Registry
- window-size mpv property support added
### 5.4.2

View File

@@ -103,7 +103,7 @@ mpv.net is meant to be a small single person project, it's designed to be mpv co
The target audience of mpv.net are programmers, nerds and software enthusiasts that need something more advanced than typical media players.
Furthermore mpv.net is well suited for users who are interested to learn mpv, Linux, portable apps and the command line.
Furthermore mpv.net is well suited for people who are interested to learn mpv and the command line.
## Requirements
@@ -155,6 +155,8 @@ A third way is to drag and drop files on the main window.
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 works in all mpv.net features that open files or URLs.
Pressing the shift key while opening a single file will suppress loading all files in the folder.
### Open > Open URL
The Open URL menu entry can be used to open URLs for example from YouTube.

View File

@@ -81,6 +81,7 @@ Table of contents
- File history feature to log time and filename
- A-B loop feature
- Watch later feature to save the position
- Files can be added to the playlist from explorer using --queue with [Open with++](https://github.com/stax76/OpenWithPlusPlus#add-to-mpvnet-playlist)
- [Manual](#manual)
### Screenshots

View File

@@ -134,6 +134,8 @@
Ctrl+t set ontop yes #menu: View > On Top > Enable
Ctrl+T set ontop no #menu: View > On Top > Disable
Alt++ no-osd set window-scale 1.2 #menu: View > Window Size > Enlarge
Alt+- no-osd set window-scale 0.8 #menu: View > Window Size > Shrink
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

@@ -30,6 +30,13 @@ namespace mpvnet
try
{
object recent = RegHelp.GetObject(App.RegPath, "Recent");
if (recent is string[] r)
RecentFiles = new List<string>(r);
else
RecentFiles = new List<string>();
Instance = this;
Hwnd = Handle;
mp.Init();
@@ -48,6 +55,7 @@ namespace mpvnet
mp.observe_property_string("aid", PropChangeAid);
mp.observe_property_string("vid", PropChangeVid);
mp.observe_property_int("edition", PropChangeEdition);
mp.observe_property_double("window-scale", PropChangeWindowScale);
if (mp.GPUAPI != "vulkan")
mp.ProcessCommandLine(false);
@@ -58,13 +66,6 @@ namespace mpvnet
Text = "mpv.net " + Application.ProductVersion;
TaskbarButtonCreatedMessage = Native.RegisterWindowMessage("TaskbarButtonCreated");
object recent = RegHelp.GetObject(App.RegPath, "Recent");
if (recent is string[] r)
RecentFiles = new List<string>(r);
else
RecentFiles = new List<string>();
ContextMenu = new ContextMenuStripEx(components);
ContextMenu.Opened += ContextMenu_Opened;
ContextMenu.Opening += ContextMenu_Opening;
@@ -233,6 +234,7 @@ namespace mpvnet
{
if (mi.Text.StartsWith(text) && mi.Text.Trim() == text)
return mi;
if (mi.DropDownItems.Count > 0)
{
MenuItem val = FindMenuItem(text, mi.DropDownItems);
@@ -245,7 +247,7 @@ namespace mpvnet
bool WasInitialSizeSet;
void SetFormPosAndSize()
void SetFormPosAndSize(double scale = 1)
{
if (WindowState == FormWindowState.Maximized)
return;
@@ -265,7 +267,6 @@ namespace mpvnet
mp.VideoSize = new Size((int)(autoFitHeight * (16 / 9.0)), autoFitHeight);
Size size = mp.VideoSize;
int height = size.Height;
if (App.RememberHeight)
@@ -279,6 +280,7 @@ namespace mpvnet
}
}
height = Convert.ToInt32(height * scale);
int width = Convert.ToInt32(height * size.Width / (double)size.Height);
if (height > screen.WorkingArea.Height * 0.9)
@@ -317,10 +319,17 @@ namespace mpvnet
int minTop = screens.Select(val => val.WorkingArea.Y).Min();
int maxBottom = screens.Select(val => val.WorkingArea.Bottom).Max();
if (left < minLeft) left = minLeft;
if (left + rect.Width > maxRight) left = maxRight - rect.Width;
if (top < minTop) top = minTop;
if (top + rect.Height > maxBottom) top = maxBottom - rect.Height;
if (left < minLeft)
left = minLeft;
if (left + rect.Width > maxRight)
left = maxRight - rect.Width;
if (top < minTop)
top = minTop;
if (top + rect.Height > maxBottom)
top = maxBottom - rect.Height;
Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */);
}
@@ -373,7 +382,8 @@ namespace mpvnet
foreach (CommandItem item in items)
{
if (string.IsNullOrEmpty(item.Path)) continue;
if (string.IsNullOrEmpty(item.Path))
continue;
string path = item.Path.Replace("&", "&&");
MenuItem menuItem = ContextMenu.Add(path, () => {
try {
@@ -382,7 +392,8 @@ namespace mpvnet
Msg.ShowException(ex);
}
});
if (menuItem != null) menuItem.ShortcutKeyDisplayString = item.Input + " ";
if (menuItem != null)
menuItem.ShortcutKeyDisplayString = item.Input + " ";
}
}
@@ -405,9 +416,13 @@ namespace mpvnet
UpdateProgressBar();
}));
if (RecentFiles.Contains(path)) RecentFiles.Remove(path);
if (RecentFiles.Contains(path))
RecentFiles.Remove(path);
RecentFiles.Insert(0, path);
while (RecentFiles.Count > App.RecentCount) RecentFiles.RemoveAt(App.RecentCount);
while (RecentFiles.Count > App.RecentCount)
RecentFiles.RemoveAt(App.RecentCount);
}
protected override CreateParams CreateParams {
@@ -420,7 +435,7 @@ namespace mpvnet
protected override void WndProc(ref Message m)
{
Debug.WriteLine(m);
//Debug.WriteLine(m);
switch (m.Msg)
{
@@ -463,7 +478,10 @@ namespace mpvnet
break;
case 0x112: // WM_SYSCOMMAND
if (m.WParam.ToInt32() == 0xf120) // SC_RESTORE
SetFormPosAndSize();
{
CycleFullscreen(true);
CycleFullscreen(false);
}
break;
case 0x0214: // WM_SIZING
var rc = Marshal.PtrToStructure<Native.RECT>(m.LParam);
@@ -546,6 +564,15 @@ namespace mpvnet
void PropChangeEdition(int value) => mp.Edition = value;
void PropChangeWindowScale(double value)
{
if (value != 1)
{
BeginInvoke(new Action(() => SetFormPosAndSize(value)));
mp.command("no-osd set window-scale 1");
}
}
void PropChangeBorder(bool enabled) {
mp.Border = enabled;
@@ -660,5 +687,11 @@ namespace mpvnet
base.OnLostFocus(e);
CursorHelp.Show();
}
protected override void OnKeyDown(KeyEventArgs e)
{
e.SuppressKeyPress = true; // prevent beep using alt key
base.OnKeyDown(e);
}
}
}

View File

@@ -58,6 +58,7 @@ namespace mpvnet
public static List<KeyValuePair<string, Action<bool>>> BoolPropChangeActions { get; set; } = new List<KeyValuePair<string, Action<bool>>>();
public static List<KeyValuePair<string, Action<int>>> IntPropChangeActions { get; set; } = new List<KeyValuePair<string, Action<int>>>();
public static List<KeyValuePair<string, Action<double>>> DoublePropChangeActions { get; set; } = new List<KeyValuePair<string, Action<double>>>();
public static List<KeyValuePair<string, Action<string>>> StringPropChangeActions { get; set; } = new List<KeyValuePair<string, Action<string>>>();
public static List<MediaTrack> MediaTracks { get; set; } = new List<MediaTrack>();
public static List<KeyValuePair<string, double>> Chapters { get; set; } = new List<KeyValuePair<string, double>>();
@@ -382,22 +383,33 @@ namespace mpvnet
var propData = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property));
if (propData.format == mpv_format.MPV_FORMAT_FLAG)
{
lock (BoolPropChangeActions)
foreach (var i in BoolPropChangeActions)
if (i.Key== propData.name)
i.Value.Invoke(Marshal.PtrToStructure<int>(propData.data) == 1);
if (propData.format == mpv_format.MPV_FORMAT_STRING)
}
else if (propData.format == mpv_format.MPV_FORMAT_STRING)
{
lock (StringPropChangeActions)
foreach (var i in StringPropChangeActions)
if (i.Key == propData.name)
i.Value.Invoke(StringFromNativeUtf8(Marshal.PtrToStructure<IntPtr>(propData.data)));
if (propData.format == mpv_format.MPV_FORMAT_INT64)
}
else if(propData.format == mpv_format.MPV_FORMAT_INT64)
{
lock (IntPropChangeActions)
foreach (var i in IntPropChangeActions)
if (i.Key == propData.name)
i.Value.Invoke(Marshal.PtrToStructure<int>(propData.data));
}
else if (propData.format == mpv_format.MPV_FORMAT_DOUBLE)
{
lock (DoublePropChangeActions)
foreach (var i in DoublePropChangeActions)
if (i.Key == propData.name)
i.Value.Invoke(Marshal.PtrToStructure<double>(propData.data));
}
break;
case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
PlaybackRestart?.Invoke();
@@ -557,6 +569,17 @@ namespace mpvnet
IntPropChangeActions.Add(new KeyValuePair<string, Action<int>>(name, action));
}
public static void observe_property_double(string name, Action<double> action)
{
int err = mpv_observe_property(Handle, (ulong)action.GetHashCode(), name, mpv_format.MPV_FORMAT_DOUBLE);
if (err < 0)
throw new Exception($"{name}: {(mpv_error)err}");
else
lock (DoublePropChangeActions)
DoublePropChangeActions.Add(new KeyValuePair<string, Action<double>>(name, action));
}
public static void observe_property_bool(string name, Action<bool> action)
{
int err = mpv_observe_property(Handle, (ulong)action.GetHashCode(), name, mpv_format.MPV_FORMAT_FLAG);