diff --git a/ScreenToGif/Model/ApplicationViewModel.cs b/ScreenToGif/Model/ApplicationViewModel.cs index 7b0e1c10..d6d15fba 100644 --- a/ScreenToGif/Model/ApplicationViewModel.cs +++ b/ScreenToGif/Model/ApplicationViewModel.cs @@ -11,9 +11,12 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Input; +using System.Windows.Interop; using System.Xml.Linq; using System.Xml.XPath; +using Windows.Graphics.Capture; using ScreenToGif.Controls; +using ScreenToGif.SystemCapture; using ScreenToGif.Util; using ScreenToGif.Windows; using ScreenToGif.Windows.Other; @@ -141,6 +144,75 @@ public ICommand OpenRecorder } } + public ICommand OpenSystemCapture + { + get + { + return new RelayCommand + { + CanExecutePredicate = o => + { + //True if all windows are not Recorders. + return Application.Current?.Windows.OfType().All(a => !(a is RecorderWindow)) ?? false; + }, + ExecuteAction = async a => + { + if (!GraphicsCaptureSession.IsSupported()) + { + MessageBox.Show("Not supported"); + return; + } + + var caller = a as Window; + if (caller == null) + return; + + var picker = new GraphicsCapturePicker(); + var hwnd = new WindowInteropHelper(caller).Handle; + picker.SetWindow(hwnd); + var item = await picker.PickSingleItemAsync(); + if (item == null) + return; + + var editor = a as Editor; + + if (editor == null) + caller.Hide(); + + var systemCapture = new Windows.SystemCapture(item); + systemCapture.Closed += (sender, args) => + { + var window = sender as Windows.SystemCapture; + + if (window?.Project != null && window.Project.Any) + { + if (editor == null) + { + ShowEditor(window.Project); + caller.Close(); + } + else + editor.RecorderCallback(window.Project); + } + else + { + if (editor == null) + { + caller.Show(); + CloseOrNot(); + } + else + editor.RecorderCallback(null); + } + }; + + Application.Current.MainWindow = systemCapture; + systemCapture.Show(); + } + }; + } + } + public ICommand OpenWebcamRecorder { get @@ -524,141 +596,141 @@ private void Interact(int action, int open) switch (action) { case 1: //Open a window. - { - switch (open) { - case 1: //Startup. - { - OpenLauncher.Execute(null); - break; - } - case 2: //Recorder. + switch (open) { - if (!OpenRecorder.CanExecute(null)) - { - var rec = Application.Current.Windows.OfType().FirstOrDefault(); - - if (rec != null) + case 1: //Startup. { - if (rec.WindowState == WindowState.Minimized) - rec.WindowState = WindowState.Normal; - - //Bring to foreground. - rec.Activate(); - return; + OpenLauncher.Execute(null); + break; } - } + case 2: //Recorder. + { + if (!OpenRecorder.CanExecute(null)) + { + var rec = Application.Current.Windows.OfType().FirstOrDefault(); - OpenRecorder.Execute(null); - return; - } - case 3: //Webcam. - { - if (!OpenWebcamRecorder.CanExecute(null)) - { - var rec = Application.Current.Windows.OfType().FirstOrDefault(); + if (rec != null) + { + if (rec.WindowState == WindowState.Minimized) + rec.WindowState = WindowState.Normal; - if (rec != null) - { - if (rec.WindowState == WindowState.Minimized) - rec.WindowState = WindowState.Normal; + //Bring to foreground. + rec.Activate(); + return; + } + } - //Bring to foreground. - rec.Activate(); + OpenRecorder.Execute(null); return; } - } + case 3: //Webcam. + { + if (!OpenWebcamRecorder.CanExecute(null)) + { + var rec = Application.Current.Windows.OfType().FirstOrDefault(); - OpenWebcamRecorder.Execute(null); - break; - } - case 4: //Board. - { - if (!OpenBoardRecorder.CanExecute(null)) - { - var rec = Application.Current.Windows.OfType().FirstOrDefault(); + if (rec != null) + { + if (rec.WindowState == WindowState.Minimized) + rec.WindowState = WindowState.Normal; - if (rec != null) - { - if (rec.WindowState == WindowState.Minimized) - rec.WindowState = WindowState.Normal; + //Bring to foreground. + rec.Activate(); + return; + } + } - //Bring to foreground. - rec.Activate(); - return; + OpenWebcamRecorder.Execute(null); + break; } - } + case 4: //Board. + { + if (!OpenBoardRecorder.CanExecute(null)) + { + var rec = Application.Current.Windows.OfType().FirstOrDefault(); - OpenBoardRecorder.Execute(null); - break; - } - case 5: //Editor. - { - OpenEditor.Execute(null); - break; - } - } + if (rec != null) + { + if (rec.WindowState == WindowState.Minimized) + rec.WindowState = WindowState.Normal; - break; - } + //Bring to foreground. + rec.Activate(); + return; + } + } - case 2: //Minimize/restore all windows. - { - var all = Application.Current.Windows.OfType().Where(w => w.Content != null).ToList(); + OpenBoardRecorder.Execute(null); + break; + } + case 5: //Editor. + { + OpenEditor.Execute(null); + break; + } + } - if (all.Count == 0) - { - Interact(1, open); - return; + break; } - if (all.Any(n => n.WindowState != WindowState.Minimized)) - { - //Minimize all windows. - foreach (var window in all) - window.WindowState = WindowState.Minimized; - } - else + case 2: //Minimize/restore all windows. { - //Restore all windows. - foreach (var window in all) - window.WindowState = WindowState.Normal; - } + var all = Application.Current.Windows.OfType().Where(w => w.Content != null).ToList(); - break; - } + if (all.Count == 0) + { + Interact(1, open); + return; + } - case 3: //Minimize all windows. - { - var all = Application.Current.Windows.OfType().Where(w => w.Content != null).ToList(); + if (all.Any(n => n.WindowState != WindowState.Minimized)) + { + //Minimize all windows. + foreach (var window in all) + window.WindowState = WindowState.Minimized; + } + else + { + //Restore all windows. + foreach (var window in all) + window.WindowState = WindowState.Normal; + } - if (all.Count == 0) - { - Interact(1, open); - return; + break; } - foreach (var window in all) - window.WindowState = WindowState.Minimized; + case 3: //Minimize all windows. + { + var all = Application.Current.Windows.OfType().Where(w => w.Content != null).ToList(); - break; - } + if (all.Count == 0) + { + Interact(1, open); + return; + } - case 4: //Restore all windows. - { - var all = Application.Current.Windows.OfType().Where(w => w.Content != null).ToList(); + foreach (var window in all) + window.WindowState = WindowState.Minimized; - if (all.Count == 0) - { - Interact(1, open); - return; + break; } - foreach (var window in all) - window.WindowState = WindowState.Normal; + case 4: //Restore all windows. + { + var all = Application.Current.Windows.OfType().Where(w => w.Content != null).ToList(); - break; - } + if (all.Count == 0) + { + Interact(1, open); + return; + } + + foreach (var window in all) + window.WindowState = WindowState.Normal; + + break; + } } } @@ -870,7 +942,7 @@ private async Task CheckOnGithub() var version = Version.Parse(release.XPathSelectElement("tag_name")?.Value ?? "0.1"); if (version.Major == 0 || version <= Assembly.GetExecutingAssembly().GetName().Version) - return true; + return true; Global.UpdateAvailable = new UpdateAvailable { @@ -886,7 +958,7 @@ private async Task CheckOnGithub() InstallerName = release.XPathSelectElement("assets/item[2]/name")?.Value ?? "ScreenToGif.Setup.msi", }; - Application.Current.Dispatcher?.BeginInvoke(new Action(() => NotificationManager.AddNotification(string.Format(LocalizationHelper.Get("S.Updater.NewRelease.Info"), + Application.Current.Dispatcher?.BeginInvoke(new Action(() => NotificationManager.AddNotification(string.Format(LocalizationHelper.Get("S.Updater.NewRelease.Info"), Global.UpdateAvailable.Version), StatusType.Update, "update", PromptUpdate))); //Download update to be installed when the app closes. @@ -990,7 +1062,7 @@ internal async Task DownloadUpdate() Global.UpdateAvailable.IsDownloading = true; } - + using (var webClient = new WebClient()) { webClient.Credentials = CredentialCache.DefaultNetworkCredentials; diff --git a/ScreenToGif/Resources/Localization/StringResources.en.xaml b/ScreenToGif/Resources/Localization/StringResources.en.xaml index bdfb8a8a..673acecc 100644 --- a/ScreenToGif/Resources/Localization/StringResources.en.xaml +++ b/ScreenToGif/Resources/Localization/StringResources.en.xaml @@ -129,6 +129,8 @@ ScreenToGif - StartUp Recorder Opens the screen recorder, where you can easily start recording your screen. + System capture + Opens the system capture, where you can start recording your window or monitor. Webcam Opens the webcam recorder. Board @@ -649,7 +651,10 @@ Auto Record Enables recording while drawing. Ctrl [Hold] - + + + ScreenToGif - System Capture + Color Selector Select a Color diff --git a/ScreenToGif/Resources/Localization/StringResources.zh.xaml b/ScreenToGif/Resources/Localization/StringResources.zh.xaml index 8369c6f5..b140a486 100644 --- a/ScreenToGif/Resources/Localization/StringResources.zh.xaml +++ b/ScreenToGif/Resources/Localization/StringResources.zh.xaml @@ -130,6 +130,8 @@ ScreenToGif - 启动 录像机 打开屏幕录像机,您可以在其中轻松开始录制屏幕。 + 系统捕获 + 打开系统捕获,您可以在其中录制窗口或屏幕。 摄像头 打开摄像头录像机。 画板 @@ -655,6 +657,9 @@ 在绘图时启用录制 Ctrl [按住] + + ScreenToGif - 系统捕获 + 颜色选择器 选择颜色 diff --git a/ScreenToGif/ScreenToGif.csproj b/ScreenToGif/ScreenToGif.csproj index 711c3257..81a44aaa 100644 --- a/ScreenToGif/ScreenToGif.csproj +++ b/ScreenToGif/ScreenToGif.csproj @@ -107,15 +107,6 @@ MinimumRecommendedRules.ruleset - - ..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll - - - ..\packages\SharpDX.Direct3D11.4.2.0\lib\net45\SharpDX.Direct3D11.dll - - - ..\packages\SharpDX.DXGI.4.2.0\lib\net45\SharpDX.DXGI.dll - @@ -330,6 +321,8 @@ + + ShadowPanel.xaml @@ -599,6 +592,9 @@ Startup.xaml + + SystemCapture.xaml + Webcam.xaml @@ -775,7 +771,6 @@ - Designer MSBuild:Compile @@ -940,6 +935,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -977,6 +976,15 @@ + + + 10.0.19041.1 + + + 4.2.0 + + +