From 4d55423fc77bdaa379f96b2ab3580b2152af18c7 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Tue, 21 Apr 2020 04:31:10 +0200 Subject: [PATCH] scripts moved from wiki to folder --- mpv.net/Misc/Command.cs | 5 ---- mpv.net/WinForms/MainForm.cs | 7 +++++ scripts/examples/key-binding.cs | 26 +++++++++++++++++++ ...bserve-property-and-draw-text-on-screen.cs | 17 ++++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 scripts/examples/key-binding.cs create mode 100644 scripts/examples/observe-property-and-draw-text-on-screen.cs diff --git a/mpv.net/Misc/Command.cs b/mpv.net/Misc/Command.cs index 46547c4..9159828 100644 --- a/mpv.net/Misc/Command.cs +++ b/mpv.net/Misc/Command.cs @@ -47,11 +47,6 @@ namespace mpvnet case "add-files-to-playlist": OpenFiles("append"); break; // deprecated 2019 default: Msg.ShowError($"No command '{id}' found."); break; } - - MainForm.Instance.BeginInvoke(new Action(() => { - Message m = new Message() { Msg = 0x0202 }; // WM_LBUTTONUP - WinAPI.SendMessage(MainForm.Instance.Handle, m.Msg, m.WParam, m.LParam); - })); } public static void InvokeOnMainThread(Action action) => MainForm.Instance.Invoke(action); diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 7305ba6..65dbf8e 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -715,6 +715,13 @@ namespace mpvnet ShownTickCount = Environment.TickCount; } + protected override void OnActivated(EventArgs e) + { + base.OnActivated(e); + Message m = new Message() { Msg = 0x0202 }; // WM_LBUTTONUP + WinAPI.SendMessage(MainForm.Instance.Handle, m.Msg, m.WParam, m.LParam); + } + protected override void OnResize(EventArgs e) { base.OnResize(e); diff --git a/scripts/examples/key-binding.cs b/scripts/examples/key-binding.cs new file mode 100644 index 0000000..487fdf9 --- /dev/null +++ b/scripts/examples/key-binding.cs @@ -0,0 +1,26 @@ + +using System.Reflection; + +using mpvnet; + +class Script +{ + public Script() + { + string content = "ctrl+รถ script-message my-message-1 my-argument-1"; + string sectionName = Assembly.GetExecutingAssembly().GetName().Name; + mp.commandv("define-section", sectionName, content, "force"); + mp.commandv("enable-section", sectionName); + mp.ClientMessage += ClientMessage; + } + + void ClientMessage(string[] args) + { + switch (args[0]) + { + case "my-message-1": + Msg.Show(args[1]); + break; + } + } +} diff --git a/scripts/examples/observe-property-and-draw-text-on-screen.cs b/scripts/examples/observe-property-and-draw-text-on-screen.cs new file mode 100644 index 0000000..03cc264 --- /dev/null +++ b/scripts/examples/observe-property-and-draw-text-on-screen.cs @@ -0,0 +1,17 @@ + +// Draws text on screen when full screen property changes. + +using mpvnet; + +class Script +{ + public Script() + { + mp.observe_property_bool("fullscreen", FullscreenChange); + } + + void FullscreenChange(bool value) + { + mp.commandv("show-text", "fullscreen: " + value.ToString()); + } +}