This commit is contained in:
Frank Skare
2019-03-25 09:50:14 +01:00
parent 8a6659b1bf
commit 07b6d4379e
30 changed files with 2870 additions and 77 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using static mpvnet.StaticUsing;
@@ -22,21 +23,20 @@ namespace mpvnet
if (commands == null)
{
commands = new List<Command>();
var type = typeof(Command);
var methods = type.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
Type type = typeof(Command);
MethodInfo[] methods = type.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
foreach (var i in methods)
{
var parameters = i.GetParameters();
ParameterInfo[] parameters = i.GetParameters();
if (parameters == null || parameters.Length != 1 || parameters[0].ParameterType != typeof(string[]))
continue;
var cmd = new Command() { Name = i.Name.Replace("_","-"), Action = (Action<string[]>)i.CreateDelegate(typeof(Action<string[]>)) };
Command cmd = new Command() { Name = i.Name.Replace("_","-"), Action = (Action<string[]>)i.CreateDelegate(typeof(Action<string[]>)) };
commands.Add(cmd);
}
}
return commands;
}
}
@@ -70,6 +70,16 @@ namespace mpvnet
Process.Start(NativeHelp.GetAssociatedApplication(".txt"), mp.mpvConfPath);
}
public static void show_conf_editor(string[] args)
{
using (var p = new Process())
{
p.StartInfo.FileName = Application.StartupPath + "\\mpvSettingsEditor.exe";
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
p.Start();
}
}
public static void history(string[] args)
{
var fp = mp.mpvConfFolderPath + "history.txt";
@@ -89,24 +99,24 @@ namespace mpvnet
public static void set_setting(string[] args)
{
bool changed = false;
string fp = mp.mpvConfPath;
var confLines = File.ReadAllLines(fp);
var lines = File.ReadAllLines(mp.mpvConfPath);
for (int i = 0; i < confLines.Length; i++)
for (int i = 0; i < lines.Length; i++)
{
if (confLines[i].Left("=").Trim() == args[0])
if (lines[i].Contains("=") &&
lines[i].Substring(0, lines[i].IndexOf("=")).Trim("# ".ToCharArray()) == args[0])
{
confLines[i] = args[0] + "=" + args[1];
lines[i] = args[0] + " = " + args[1];
changed = true;
}
}
if (changed)
File.WriteAllText(fp, String.Join(Environment.NewLine, confLines));
File.WriteAllText(mp.mpvConfPath, String.Join(Environment.NewLine, lines));
else
File.WriteAllText(fp, File.ReadAllText(fp) + Environment.NewLine + args[0] + "=" + args[1]);
File.WriteAllText(mp.mpvConfPath, File.ReadAllText(mp.mpvConfPath) + Environment.NewLine + args[0] + " = " + args[1]);
MsgInfo("Please restart mpv.net");
MainForm.Instance.ShowMsgBox("Please restart mpv.net", MessageBoxIcon.Information);
}
public static void show_info(string[] args)

View File

@@ -8,6 +8,7 @@ using System.Diagnostics;
using static mpvnet.StaticUsing;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace mpvnet
{
@@ -368,6 +369,17 @@ namespace mpvnet
}
}
public DialogResult ShowMsgBox(string message, MessageBoxIcon icon)
{
var buttons = MessageBoxButtons.OK;
if (icon == MessageBoxIcon.Question) buttons = MessageBoxButtons.OKCancel;
var fn = new Func<DialogResult>(() => MessageBox.Show(
message, Application.ProductName, buttons, MessageBoxIcon.Information));
return (DialogResult)Invoke(fn);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);

View File

@@ -214,8 +214,7 @@ public class ToolStripRendererEx : ToolStripSystemRenderer
if (e.Item is ToolStripMenuItem && !(e.Item.Owner is MenuStrip))
{
var r = e.TextRectangle;
Rectangle rect = e.TextRectangle;
var dropDown = e.ToolStrip as ToolStripDropDownMenu;
if (dropDown == null || dropDown.ShowImageMargin || dropDown.ShowCheckMargin)
@@ -223,7 +222,7 @@ public class ToolStripRendererEx : ToolStripSystemRenderer
else
TextOffset = Convert.ToInt32(e.Item.Height * 0.2);
e.TextRectangle = new Rectangle(TextOffset, Convert.ToInt32((e.Item.Height - r.Height) / 2.0), r.Width, r.Height);
e.TextRectangle = new Rectangle(TextOffset, Convert.ToInt32((e.Item.Height - rect.Height) / 2.0), rect.Width, rect.Height);
}
base.OnRenderItemText(e);
@@ -279,31 +278,22 @@ public class ToolStripRendererEx : ToolStripSystemRenderer
public void DrawButton(ToolStripItemRenderEventArgs e)
{
var g = e.Graphics;
var r = new Rectangle(Point.Empty, e.Item.Size);
var r2 = new Rectangle(r.X, r.Y, r.Width - 1, r.Height - 1);
var gx = e.Graphics;
var rect = new Rectangle(Point.Empty, e.Item.Size);
var rect2 = new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
using (Pen pen = new Pen(ColorBorder))
{
g.DrawRectangle(pen, r2);
}
r2.Inflate(-1, -1);
gx.DrawRectangle(pen, rect2);
rect2.Inflate(-1, -1);
var tsb = e.Item as ToolStripButton;
if (!(tsb == null) && tsb.Checked)
{
if (tsb != null && tsb.Checked)
using (SolidBrush brush = new SolidBrush(ColorChecked))
{
g.FillRectangle(brush, r2);
}
}
gx.FillRectangle(brush, rect2);
else
using (SolidBrush brush = new SolidBrush(ColorBottom))
{
g.FillRectangle(brush, r2);
}
gx.FillRectangle(brush, rect2);
}
protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e)
@@ -332,7 +322,7 @@ public class ToolStripRendererEx : ToolStripSystemRenderer
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
{
var x = Convert.ToInt32(e.ImageRectangle.Height * 0.2);
int x = Convert.ToInt32(e.ImageRectangle.Height * 0.2);
e.Graphics.DrawImage(e.Image, new Point(x, x));
}
@@ -341,28 +331,21 @@ public class ToolStripRendererEx : ToolStripSystemRenderer
if (e.Item.IsOnDropDown)
{
e.Graphics.Clear(ColorBackground);
var right = e.Item.Width - Convert.ToInt32(TextOffset / 5.0);
var top = e.Item.Height / 2;
int right = e.Item.Width - Convert.ToInt32(TextOffset / 5.0);
int top = e.Item.Height / 2;
top -= 1;
var b = e.Item.Bounds;
using (Pen p = new Pen(Color.Gray))
{
e.Graphics.DrawLine(p, new Point(TextOffset, top), new Point(right, top));
}
}
else if (e.Vertical)
{
var b = e.Item.Bounds;
var bounds = e.Item.Bounds;
using (Pen p = new Pen(SystemColors.ControlDarkDark))
{
e.Graphics.DrawLine(p,
Convert.ToInt32(b.Width / 2.0),
Convert.ToInt32(b.Height * 0.15),
Convert.ToInt32(b.Width / 2.0),
Convert.ToInt32(b.Height * 0.85));
}
Convert.ToInt32(bounds.Width / 2.0),
Convert.ToInt32(bounds.Height * 0.15),
Convert.ToInt32(bounds.Width / 2.0),
Convert.ToInt32(bounds.Height * 0.85));
}
}
}
@@ -383,21 +366,24 @@ public struct HSLColor
private double hue;
public int Hue {
public int Hue
{
get => System.Convert.ToInt32(hue * 240);
set => hue = CheckRange(value / 240.0);
}
private double saturation;
public int Saturation {
public int Saturation
{
get => System.Convert.ToInt32(saturation * 240);
set => saturation = CheckRange(value / 240.0);
}
private double luminosity;
public int Luminosity {
public int Luminosity
{
get => System.Convert.ToInt32(luminosity * 240);
set => luminosity = CheckRange(value / 240.0);
}
@@ -408,7 +394,6 @@ public struct HSLColor
value = 0;
else if (value > 1)
value = 1;
return value;
}
@@ -438,9 +423,8 @@ public struct HSLColor
}
else
{
var temp2 = GetTemp2(this);
var temp1 = 2.0 * luminosity - temp2;
double temp2 = GetTemp2(this);
double temp1 = 2.0 * luminosity - temp2;
r = GetColorComponent(temp1, temp2, hue + 1.0 / 3.0);
g = GetColorComponent(temp1, temp2, hue);
b = GetColorComponent(temp1, temp2, hue - 1.0 / 3.0);
@@ -473,7 +457,6 @@ public struct HSLColor
temp3 += 1;
else if (temp3 > 1)
temp3 -= 1;
return temp3;
}
@@ -500,7 +483,7 @@ public struct HSLColor
public void SetRGB(int red, int green, int blue)
{
var hc = HSLColor.Convert(Color.FromArgb(red, green, blue));
HSLColor hc = HSLColor.Convert(Color.FromArgb(red, green, blue));
hue = hc.hue;
saturation = hc.saturation;
luminosity = hc.luminosity;

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

View File

@@ -53,8 +53,6 @@
Ctrl+8 add saturation 1 #menu: Ctrl+8 ; Video > Increase Saturation
_ ignore #menu: _ ; Video > -
Ctrl+S async screenshot #menu: Ctrl+S ; Video > Take Screenshot
Ctrl+Shift+S screenshot each-frame #menu: Ctrl+Shift+S ; Video > Take Screenshots All Frames
_ ignore #menu: _ ; Video > -
d cycle deinterlace #menu: D ; Video > Toggle Deinterlace
a cycle-values video-aspect "16:9" "4:3" "2.35:1" "-1" #menu: A ; Video > Cycle Aspect Ratio
@@ -99,7 +97,8 @@
_ script-message mpv.net set-setting hwdec yes #menu: _ ; Settings > Hardware Decoding > Enable
_ script-message mpv.net set-setting hwdec no #menu: _ ; Settings > Hardware Decoding > Disable
p script-message mpv.net show-prefs #menu: P ; Settings > Show Preferences
p script-message mpv.net show-prefs #menu: P ; Settings > Show mpv config file
e script-message mpv.net show-conf-editor #menu: E ; Settings > Show mpv config editor
k script-message mpv.net show-keys #menu: K ; Settings > Show Keys
c script-message mpv.net open-config-folder #menu: C ; Settings > Open Config Folder

View File

@@ -1,4 +1,5 @@
# https://mpv.io/manual/master/
# mpv manual: https://mpv.io/manual/master/
# mpv.net mpv.conf defaults: https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpv.conf.txt
input-ar-delay = 500
input-ar-rate = 20

View File

@@ -27,7 +27,7 @@ namespace mpvnet
public static extern int mpv_set_option_string(IntPtr mpvHandle, byte[] name, byte[] value);
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int mpv_get_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref IntPtr data);
public static extern int mpv_get_property(IntPtr mpvHandle, byte[] name, mpv_format format, out IntPtr data);
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int mpv_get_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref double data);

View File

@@ -125,12 +125,10 @@ namespace mpvnet
PowerShellScript.Init(scriptPath);
foreach (var scriptPath in Directory.GetFiles(mp.mpvConfFolderPath + "Scripts"))
{
if (Path.GetExtension(scriptPath) == ".py")
PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
else if (Path.GetExtension(scriptPath) == ".ps1")
PowerShellScript.Init(scriptPath);
}
}
public static void EventLoop()
@@ -307,8 +305,7 @@ namespace mpvnet
if (MpvHandle == IntPtr.Zero)
return;
IntPtr[] byteArrayPointers;
var mainPtr = AllocateUtf8IntPtrArrayWithSentinel(args, out byteArrayPointers);
IntPtr mainPtr = AllocateUtf8IntPtrArrayWithSentinel(args, out IntPtr[] byteArrayPointers);
int err = mpv_command(MpvHandle, mainPtr);
if (err < 0)
@@ -333,7 +330,7 @@ namespace mpvnet
public static void set_property_string(string name, string value, bool throwOnException = false)
{
var bytes = GetUtf8Bytes(value);
byte[] bytes = GetUtf8Bytes(value);
int err = mpv_set_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref bytes);
if (err < 0 && throwOnException)
@@ -342,8 +339,7 @@ namespace mpvnet
public static string get_property_string(string name, bool throwOnException = false)
{
var lpBuffer = IntPtr.Zero;
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, ref lpBuffer);
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_STRING, out IntPtr lpBuffer);
if (err < 0 && throwOnException)
throw new Exception($"{name}: {(mpv_error)err}");
@@ -356,8 +352,7 @@ namespace mpvnet
public static int get_property_int(string name, bool throwOnException = false)
{
var lpBuffer = IntPtr.Zero;
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref lpBuffer);
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, out IntPtr lpBuffer);
if (err < 0 && throwOnException)
throw new Exception($"{name}: {(mpv_error)err}");
@@ -378,8 +373,7 @@ namespace mpvnet
public static bool get_property_bool(string name, bool throwOnException = false)
{
var lpBuffer = IntPtr.Zero;
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_FLAG, ref lpBuffer);
int err = mpv_get_property(MpvHandle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_FLAG, out IntPtr lpBuffer);
if (err < 0 && throwOnException)
throw new Exception($"{name}: {(mpv_error)err}");