-
This commit is contained in:
@@ -34,7 +34,7 @@ namespace mpvnet
|
||||
private Point LastCursorPosChanged;
|
||||
private int LastCursorChangedTickCount;
|
||||
|
||||
public ContextMenuEx Menu;
|
||||
public ContextMenuEx CM;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
@@ -50,8 +50,9 @@ namespace mpvnet
|
||||
mpv.FileLoaded += Mpv_FileLoaded;
|
||||
mpv.VideoSizeChanged += Mpv_VideoSizeChanged;
|
||||
|
||||
Menu = new ContextMenuEx();
|
||||
ContextMenu = Menu;
|
||||
CM = new ContextMenuEx();
|
||||
ContextMenu = CM;
|
||||
CM.Popup += CM_Popup;
|
||||
ContextMenu.MenuItems.Add("About mpv.net", About);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -60,6 +61,11 @@ namespace mpvnet
|
||||
}
|
||||
}
|
||||
|
||||
private void CM_Popup(object sender, EventArgs e)
|
||||
{
|
||||
CursorHelp.Show();
|
||||
}
|
||||
|
||||
private void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
|
||||
{
|
||||
HandleException(e.Exception);
|
||||
@@ -109,6 +115,7 @@ namespace mpvnet
|
||||
{
|
||||
WindowState = FormWindowState.Normal;
|
||||
FormBorderStyle = FormBorderStyle.Sizable;
|
||||
SetFormPosSize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,14 +138,14 @@ namespace mpvnet
|
||||
case 0x0214: // WM_SIZING
|
||||
var rc = Marshal.PtrToStructure<Native.RECT>(m.LParam);
|
||||
var r = rc;
|
||||
subtract_window_borders(Handle, ref r);
|
||||
NativeHelp.SubtractWindowBorders(Handle, ref r);
|
||||
int c_w = r.Right - r.Left, c_h = r.Bottom - r.Top;
|
||||
float aspect = mpv.VideoSize.Width / (float)mpv.VideoSize.Height;
|
||||
int d_w = (int)(c_h * aspect - c_w);
|
||||
int d_h = (int)(c_w / aspect - c_h);
|
||||
int[] d_corners = { d_w, d_h, -d_w, -d_h };
|
||||
int[] corners = { rc.Left, rc.Top, rc.Right, rc.Bottom };
|
||||
int corner = get_resize_border(m.WParam.ToInt32());
|
||||
int corner = NativeHelp.GetResizeBorder(m.WParam.ToInt32());
|
||||
|
||||
if (corner >= 0)
|
||||
corners[corner] -= d_corners[corner];
|
||||
@@ -151,46 +158,15 @@ namespace mpvnet
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
|
||||
static int get_resize_border(int v)
|
||||
{
|
||||
switch (v)
|
||||
{
|
||||
case 1 /* WMSZ_LEFT */ : return 3;
|
||||
case 3 /* WMSZ_TOP */ : return 2;
|
||||
case 2 /* WMSZ_RIGHT */ : return 3;
|
||||
case 6 /* WMSZ_BOTTOM */ : return 2;
|
||||
case 4 /* WMSZ_TOPLEFT */ : return 1;
|
||||
case 5 /* WMSZ_TOPRIGHT */ : return 1;
|
||||
case 7 /* WMSZ_BOTTOMLEFT */ : return 3;
|
||||
case 8 /* WMSZ_BOTTOMRIGHT */: return 3;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static void subtract_window_borders(IntPtr hwnd, ref Native.RECT rc)
|
||||
{
|
||||
var b = new Native.RECT(0, 0, 0, 0);
|
||||
add_window_borders(hwnd, ref b);
|
||||
rc.Left -= b.Left;
|
||||
rc.Top -= b.Top;
|
||||
rc.Right -= b.Right;
|
||||
rc.Bottom -= b.Bottom;
|
||||
}
|
||||
|
||||
static void add_window_borders(IntPtr hwnd, ref Native.RECT rc)
|
||||
{
|
||||
Native.AdjustWindowRect(ref rc, (uint)Native.GetWindowLongPtrW(hwnd, -16 /* GWL_STYLE */), false);
|
||||
}
|
||||
|
||||
void SetFormPosSize()
|
||||
{
|
||||
if (IsFullscreen) return;
|
||||
if (IsFullscreen || mpv.VideoSize.Width == 0) return;
|
||||
var wa = Screen.GetWorkingArea(this);
|
||||
int h = (int)(wa.Height * 0.6);
|
||||
int w = (int)(h * mpv.VideoSize.Width / (float)mpv.VideoSize.Height);
|
||||
Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
|
||||
var r = new Native.RECT(new Rectangle(0, 0, w, h));
|
||||
add_window_borders(Handle, ref r);
|
||||
NativeHelp.AddWindowBorders(Handle, ref r);
|
||||
int l = middlePos.X - r.Width / 2;
|
||||
int t = middlePos.Y - r.Height / 2;
|
||||
if (l < 0) l = 0;
|
||||
@@ -275,7 +251,7 @@ namespace mpvnet
|
||||
}
|
||||
else if (Environment.TickCount - LastCursorChangedTickCount > 1500 &&
|
||||
!IsMouseInOSC() && ClientRectangle.Contains(PointToClient(MousePosition)) &&
|
||||
Form.ActiveForm == this && !Menu.Visible)
|
||||
Form.ActiveForm == this && !CM.Visible)
|
||||
{
|
||||
CursorHelp.Hide();
|
||||
}
|
||||
|
||||
56
mpvnet/NativeHelp.cs
Normal file
56
mpvnet/NativeHelp.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
*mpv.net
|
||||
*Copyright(C) 2017 stax76
|
||||
*
|
||||
*This program is free software: you can redistribute it and/or modify
|
||||
*it under the terms of the GNU General Public License as published by
|
||||
*the Free Software Foundation, either version 3 of the License, or
|
||||
*(at your option) any later version.
|
||||
*
|
||||
*This program is distributed in the hope that it will be useful,
|
||||
*but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
*GNU General Public License for more details.
|
||||
*
|
||||
*You should have received a copy of the GNU General Public License
|
||||
*along with this program. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace mpvnet
|
||||
{
|
||||
public static class NativeHelp
|
||||
{
|
||||
public static int GetResizeBorder(int v)
|
||||
{
|
||||
switch (v)
|
||||
{
|
||||
case 1 /* WMSZ_LEFT */ : return 3;
|
||||
case 3 /* WMSZ_TOP */ : return 2;
|
||||
case 2 /* WMSZ_RIGHT */ : return 3;
|
||||
case 6 /* WMSZ_BOTTOM */ : return 2;
|
||||
case 4 /* WMSZ_TOPLEFT */ : return 1;
|
||||
case 5 /* WMSZ_TOPRIGHT */ : return 1;
|
||||
case 7 /* WMSZ_BOTTOMLEFT */ : return 3;
|
||||
case 8 /* WMSZ_BOTTOMRIGHT */: return 3;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SubtractWindowBorders(IntPtr hwnd, ref Native.RECT rc)
|
||||
{
|
||||
var b = new Native.RECT(0, 0, 0, 0);
|
||||
AddWindowBorders(hwnd, ref b);
|
||||
rc.Left -= b.Left;
|
||||
rc.Top -= b.Top;
|
||||
rc.Right -= b.Right;
|
||||
rc.Bottom -= b.Bottom;
|
||||
}
|
||||
|
||||
public static void AddWindowBorders(IntPtr hwnd, ref Native.RECT rc)
|
||||
{
|
||||
Native.AdjustWindowRect(ref rc, (uint)Native.GetWindowLongPtrW(hwnd, -16 /* GWL_STYLE */), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,17 +55,17 @@ namespace mpvnet
|
||||
{
|
||||
LoadLibrary("mpv-1.dll");
|
||||
MpvHandle = mpv_create();
|
||||
SetStringProp("hwdec", "auto");
|
||||
SetIntProp("input-ar-delay", 500);
|
||||
SetIntProp("input-ar-rate", 20);
|
||||
SetIntProp("osd-duration", 3000);
|
||||
SetIntProp("volume", 50);
|
||||
SetStringProp("hwdec", "auto");
|
||||
SetStringProp("input-default-bindings", "yes");
|
||||
SetStringProp("opengl-backend", "angle");
|
||||
SetIntProp("osd-duration", 3000);
|
||||
SetStringProp("osd-playing-msg", "'${filename}'");
|
||||
SetStringProp("profile", "opengl-hq");
|
||||
SetStringProp("screenshot-directory", "~~desktop/");
|
||||
SetStringProp("vo", "opengl");
|
||||
SetIntProp("volume", 50);
|
||||
SetStringProp("keep-open", "always");
|
||||
SetStringProp("keep-open-pause", "no");
|
||||
SetStringProp("osc", "yes");
|
||||
@@ -123,7 +123,6 @@ namespace mpvnet
|
||||
if (eventData.format == mpv_format.MPV_FORMAT_FLAG)
|
||||
foreach (var action in BoolPropChangeActions)
|
||||
action.Invoke(Marshal.PtrToStructure<int>(eventData.data) == 1);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -171,17 +170,13 @@ namespace mpvnet
|
||||
{
|
||||
var lpBuffer = IntPtr.Zero;
|
||||
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref lpBuffer);
|
||||
var ret = Marshal.PtrToStringAnsi(lpBuffer);
|
||||
mpv_free(lpBuffer);
|
||||
|
||||
if (err < 0)
|
||||
{
|
||||
throw new Exception($"{name}: {(mpv_error)err}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var ret = Marshal.PtrToStringAnsi(lpBuffer);
|
||||
mpv_free(lpBuffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int GetIntProp(string name)
|
||||
@@ -190,7 +185,7 @@ namespace mpvnet
|
||||
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref lpBuffer);
|
||||
|
||||
if (err < 0)
|
||||
throw new Exception($"{(mpv_error)err}");
|
||||
throw new Exception($"{name}: {(mpv_error)err}");
|
||||
else
|
||||
return lpBuffer.ToInt32();
|
||||
}
|
||||
@@ -201,7 +196,7 @@ namespace mpvnet
|
||||
int err = mpv_set_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val);
|
||||
|
||||
if (err < 0)
|
||||
throw new Exception($"{(mpv_error)err}");
|
||||
throw new Exception($"{name}: {(mpv_error)err}");
|
||||
}
|
||||
|
||||
public static void ObserveBoolProp(string name, Action<bool> action)
|
||||
@@ -210,7 +205,7 @@ namespace mpvnet
|
||||
int err = mpv_observe_property(MpvHandle, (ulong)action.GetHashCode(), name, mpv_format.MPV_FORMAT_FLAG);
|
||||
|
||||
if (err < 0)
|
||||
throw new Exception($"{(mpv_error)err}");
|
||||
throw new Exception($"{name}: {(mpv_error)err}");
|
||||
}
|
||||
|
||||
public static void UnobserveBoolProp(string name, Action<bool> action)
|
||||
@@ -219,7 +214,7 @@ namespace mpvnet
|
||||
int err = mpv_unobserve_property(MpvHandle, (ulong)action.GetHashCode());
|
||||
|
||||
if (err < 0)
|
||||
throw new Exception($"{(mpv_error)err}");
|
||||
throw new Exception($"{name}: {(mpv_error)err}");
|
||||
}
|
||||
|
||||
public static void ProcessCommandLine()
|
||||
@@ -270,8 +265,6 @@ namespace mpvnet
|
||||
}
|
||||
}
|
||||
|
||||
public static void Terminate() => libmpv.mpv_terminate_destroy(MpvHandle);
|
||||
|
||||
public static IntPtr AllocateUtf8IntPtrArrayWithSentinel(string[] arr, out IntPtr[] byteArrayPointers)
|
||||
{
|
||||
int numberOfStrings = arr.Length + 1; // add extra element for extra null pointer last (sentinel)
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
<Compile Include="Misc.cs" />
|
||||
<Compile Include="mpv.cs" />
|
||||
<Compile Include="Native.cs" />
|
||||
<Compile Include="NativeHelp.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="StringExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user