Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Use Windows 10 graphics capture to record #751

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
286 changes: 179 additions & 107 deletions ScreenToGif/Model/ApplicationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Window>().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
Expand Down Expand Up @@ -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<RecorderWindow>().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<RecorderWindow>().FirstOrDefault();

OpenRecorder.Execute(null);
return;
}
case 3: //Webcam.
{
if (!OpenWebcamRecorder.CanExecute(null))
{
var rec = Application.Current.Windows.OfType<RecorderWindow>().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<RecorderWindow>().FirstOrDefault();

OpenWebcamRecorder.Execute(null);
break;
}
case 4: //Board.
{
if (!OpenBoardRecorder.CanExecute(null))
{
var rec = Application.Current.Windows.OfType<RecorderWindow>().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<RecorderWindow>().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<Window>().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<Window>().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<Window>().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<Window>().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<Window>().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<Window>().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;
}
}
}

Expand Down Expand Up @@ -870,7 +942,7 @@ private async Task<bool> 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
{
Expand All @@ -886,7 +958,7 @@ private async Task<bool> 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.
Expand Down Expand Up @@ -990,7 +1062,7 @@ internal async Task<bool> DownloadUpdate()

Global.UpdateAvailable.IsDownloading = true;
}

using (var webClient = new WebClient())
{
webClient.Credentials = CredentialCache.DefaultNetworkCredentials;
Expand Down
7 changes: 6 additions & 1 deletion ScreenToGif/Resources/Localization/StringResources.en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
<s:String x:Key="S.StartUp.Title">ScreenToGif - StartUp</s:String>
<s:String x:Key="S.StartUp.Recorder">Recorder</s:String>
<s:String x:Key="S.StartUp.Recorder.Tooltip">Opens the screen recorder, where you can easily start recording your screen.</s:String>
<s:String x:Key="S.StartUp.SystemCapture">System capture</s:String>
<s:String x:Key="S.StartUp.SystemCapture.Tooltip">Opens the system capture, where you can start recording your window or monitor.</s:String>
<s:String x:Key="S.StartUp.Webcam">Webcam</s:String>
<s:String x:Key="S.StartUp.Webcam.Tooltip">Opens the webcam recorder.</s:String>
<s:String x:Key="S.StartUp.Board">Board</s:String>
Expand Down Expand Up @@ -649,7 +651,10 @@
<s:String x:Key="S.Board.AutoRecord">Auto Record</s:String>
<s:String x:Key="S.Board.AutoRecordToolTip">Enables recording while drawing.</s:String>
<s:String x:Key="S.Board.CtrlHold">Ctrl [Hold]</s:String>


<!--System capture-->
<s:String x:Key="S.SystemCapture.Title">ScreenToGif - System Capture</s:String>

<!--Color selector-->
<s:String x:Key="S.ColorSelector.Title">Color Selector</s:String>
<s:String x:Key="S.ColorSelector.Select">Select a Color</s:String>
Expand Down
Loading