Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MathewSachin committed Jan 27, 2018
1 parent 4c68cda commit ba820ff
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 98 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

(c) Copyright 2017 Mathew Sachin.
(c) Copyright 2018 Mathew Sachin.

Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and associated documentation files (the "Software"),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![MIT License](https://img.shields.io/github/license/MathewSachin/Captura.svg?style=flat-square)](LICENSE.md)
[![Chat](https://img.shields.io/gitter/room/MathewSachin/Screna.svg?style=flat-square)](https://gitter.im/MathewSachin/Screna)
[![Downloads](https://img.shields.io/github/downloads/MathewSachin/Captura/total.svg?style=flat-square)](https://github.com/MathewSachin/Captura/releases)
© [Copyright 2017](LICENSE.md) Mathew Sachin
© [Copyright 2018](LICENSE.md) Mathew Sachin

:link: https://mathewsachin.github.io/Captura/

Expand Down
2 changes: 1 addition & 1 deletion choco/captura.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<bugTrackerUrl>https://github.com/MathewSachin/Captura/issues</bugTrackerUrl>
<docsUrl>https://github.com/MathewSachin/Captura/wiki</docsUrl>
<mailingListUrl>https://gitter.im/MathewSachin/Screna</mailingListUrl>
<copyright>(c) 2017 Mathew Sachin</copyright>
<copyright>(c) 2018 Mathew Sachin</copyright>
<tags>captura screen capture recording loopback screenshot screencast</tags>
<summary>Capture Screen/Audio/Cursor/Clicks/Keystrokes</summary>
<description>
Expand Down
2 changes: 1 addition & 1 deletion licenses/Captura, Screna, ManagedBass.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

(c) Copyright 2017 Mathew Sachin.
(c) Copyright 2018 Mathew Sachin.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
164 changes: 84 additions & 80 deletions src/Captura.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,132 +77,136 @@ static void List()
{
Banner();

using (var vm = ServiceProvider.Get<MainViewModel>())
{
vm.Init(false, false, false, false);

var underline = $"\n{new string('-', 30)}";

var video = vm.VideoViewModel;
var underline = $"\n{new string('-', 30)}";

#region FFmpeg
var ffmpegExists = FFMpegService.FFMpegExists;
#region FFmpeg
var ffmpegExists = FFMpegService.FFMpegExists;

WriteLine($"FFmpeg Available: {(ffmpegExists ? "YES" : "NO")}");
WriteLine($"FFmpeg Available: {(ffmpegExists ? "YES" : "NO")}");

WriteLine();
WriteLine();

if (ffmpegExists)
{
WriteLine("FFmpeg ENCODERS" + underline);
if (ffmpegExists)
{
WriteLine("FFmpeg ENCODERS" + underline);

video.SelectedVideoWriterKind = ServiceProvider.Get<FFMpegWriterProvider>();
var writerProvider = ServiceProvider.Get<FFMpegWriterProvider>();

for (var i = 0; i < video.AvailableVideoWriters.Count; ++i)
{
WriteLine($"{i.ToString().PadRight(2)}: {video.AvailableVideoWriters[i]}");
}
var i = 0;

WriteLine();
foreach (var codec in writerProvider)
{
WriteLine($"{i.ToString().PadRight(2)}: {codec}");
++i;
}
#endregion

#region SharpAvi
var sharpAviExists = ServiceProvider.FileExists("SharpAvi.dll");

WriteLine($"SharpAvi Available: {(sharpAviExists ? "YES" : "NO")}");

WriteLine();
}
#endregion

if (sharpAviExists)
{
WriteLine("SharpAvi ENCODERS" + underline);
#region SharpAvi
var sharpAviExists = ServiceProvider.FileExists("SharpAvi.dll");

video.SelectedVideoWriterKind = ServiceProvider.Get<SharpAviWriterProvider>();
WriteLine($"SharpAvi Available: {(sharpAviExists ? "YES" : "NO")}");

for (var i = 0; i < video.AvailableVideoWriters.Count; ++i)
{
WriteLine($"{i.ToString().PadRight(2)}: {video.AvailableVideoWriters[i]}");
}
WriteLine();

WriteLine();
}
#endregion
if (sharpAviExists)
{
WriteLine("SharpAvi ENCODERS" + underline);

#region Windows
WriteLine("AVAILABLE WINDOWS" + underline);
var writerProvider = ServiceProvider.Get<SharpAviWriterProvider>();

video.SelectedVideoSourceKind = ServiceProvider.Get<WindowSourceProvider>();
var i = 0;

foreach (var source in video.AvailableVideoSources.OfType<WindowItem>())
foreach (var codec in writerProvider)
{
WriteLine($"{source.Window.Handle.ToString().PadRight(10)}: {source}");
WriteLine($"{i.ToString().PadRight(2)}: {codec}");
++i;
}

WriteLine();
#endregion
}
#endregion

#region Screens
WriteLine("AVAILABLE SCREENS" + underline);
#region Windows
WriteLine("AVAILABLE WINDOWS" + underline);

video.SelectedVideoSourceKind = ServiceProvider.Get<ScreenSourceProvider>();
var winProvider = ServiceProvider.Get<WindowSourceProvider>();

for (var i = 0; i < video.AvailableVideoSources.Count; ++i)
{
WriteLine($"{i.ToString().PadRight(2)}: {video.AvailableVideoSources[i]}");
}
foreach (var source in winProvider.OfType<WindowItem>())
{
WriteLine($"{source.Window.Handle.ToString().PadRight(10)}: {source}");
}

WriteLine();
#endregion
WriteLine();
#endregion

#region MouseKeyHook
WriteLine($"MouseKeyHook Available: {(vm.MouseKeyHookAvailable ? "YES" : "NO")}");
#region Screens
WriteLine("AVAILABLE SCREENS" + underline);

WriteLine();
#endregion
var scrProvider = ServiceProvider.Get<ScreenSourceProvider>();

var audio = vm.AudioViewModel.AudioSource;
var j = 0;

WriteLine($"ManagedBass Available: {(audio is BassAudioSource ? "YES" : "NO")}");
// First is Full Screen
foreach (var screen in scrProvider.Skip(1))
{
WriteLine($"{j.ToString().PadRight(2)}: {screen}");

WriteLine();
++j;
}

#region Microphones
if (audio.AvailableRecordingSources.Count > 1)
{
WriteLine("AVAILABLE MICROPHONES" + underline);
WriteLine();
#endregion

for (var i = 1; i < audio.AvailableRecordingSources.Count; ++i)
{
WriteLine($"{(i - 1).ToString().PadRight(2)}: {audio.AvailableRecordingSources[i]}");
}
#region MouseKeyHook
WriteLine($"MouseKeyHook Available: {(ServiceProvider.Get<MainViewModel>().MouseKeyHookAvailable ? "YES" : "NO")}");

WriteLine();
}
#endregion
WriteLine();
#endregion

var audio = ServiceProvider.Get<AudioSource>();

WriteLine($"ManagedBass Available: {(audio is BassAudioSource ? "YES" : "NO")}");

WriteLine();

#region Microphones
if (audio.AvailableRecordingSources.Count > 1)
{
WriteLine("AVAILABLE MICROPHONES" + underline);

#region Speaker
if (audio.AvailableLoopbackSources.Count > 1)
for (var i = 1; i < audio.AvailableRecordingSources.Count; ++i)
{
WriteLine("AVAILABLE SPEAKER SOURCES" + underline);
WriteLine($"{(i - 1).ToString().PadRight(2)}: {audio.AvailableRecordingSources[i]}");
}

for (var i = 1; i < audio.AvailableLoopbackSources.Count; ++i)
{
WriteLine($"{(i - 1).ToString().PadRight(2)}: {audio.AvailableLoopbackSources[i]}");
}
WriteLine();
}
#endregion

WriteLine();
#region Speaker
if (audio.AvailableLoopbackSources.Count > 1)
{
WriteLine("AVAILABLE SPEAKER SOURCES" + underline);

for (var i = 1; i < audio.AvailableLoopbackSources.Count; ++i)
{
WriteLine($"{(i - 1).ToString().PadRight(2)}: {audio.AvailableLoopbackSources[i]}");
}
#endregion

WriteLine();
}
#endregion
}

static void Banner()
{
var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(3);

WriteLine($@"Captura v{version}
(c) 2017 Mathew Sachin
(c) 2018 Mathew Sachin
");
}

Expand Down
2 changes: 1 addition & 1 deletion src/Captura/Views/AboutView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
LineHeight="30"
Style="{StaticResource TextColor}">
<Run FontSize="20" Text="{local:Loc AppName}"/> <Run Text="{Binding AppVersion, Mode=OneWay}"/><LineBreak/>
(c) 2017 <Hyperlink CommandParameter="https://github.com/MathewSachin">Mathew Sachin</Hyperlink>
(c) 2018 <Hyperlink CommandParameter="https://github.com/MathewSachin">Mathew Sachin</Hyperlink>
</TextBlock>

<TextBlock DockPanel.Dock="Bottom"
Expand Down
6 changes: 3 additions & 3 deletions src/Screna/ImageProviders/OverlayedImageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class OverlayedImageProvider : IImageProvider
/// <param name="Transform">Point Transform Function.</param>
public OverlayedImageProvider(IImageProvider ImageProvider, Func<Point, Point> Transform, params IOverlay[] Overlays)
{
_imageProvider = ImageProvider;
_overlays = Overlays;
_transform = Transform;
_imageProvider = ImageProvider ?? throw new ArgumentNullException(nameof(ImageProvider));
_overlays = Overlays ?? throw new ArgumentNullException(nameof(Overlays));
_transform = Transform ?? throw new ArgumentNullException(nameof(Transform));

Width = ImageProvider.Width;
Height = ImageProvider.Height;
Expand Down
2 changes: 1 addition & 1 deletion src/Screna/ImageProviders/WindowProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static Func<Point, Point> GetTransformer(Window Window)
/// </summary>
public WindowProvider(Window Window, bool IncludeCursor, out Func<Point, Point> Transform)
{
_window = Window;
_window = Window ?? throw new ArgumentNullException(nameof(Window));
_includeCursor = IncludeCursor;

var size = Window.Rectangle.Even().Size;
Expand Down
17 changes: 9 additions & 8 deletions src/Screna/Overlays/MouseCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static Point CursorPosition
}

// hCursor -> (Icon, Hotspot)
static readonly Dictionary<IntPtr, Tuple<Bitmap, Point>> _cursors = new Dictionary<IntPtr, Tuple<Bitmap, Point>>();
static readonly Dictionary<IntPtr, Tuple<Bitmap, Point>> Cursors = new Dictionary<IntPtr, Tuple<Bitmap, Point>>();

/// <summary>
/// Draws this overlay.
Expand All @@ -59,6 +59,7 @@ public static Point CursorPosition
public static void Draw(Graphics g, Func<Point, Point> Transform = null)
{
// ReSharper disable once RedundantAssignment
// ReSharper disable once InlineOutVariableDeclaration
var cursorInfo = new CursorInfo { cbSize = Marshal.SizeOf<CursorInfo>() };

if (!GetCursorInfo(out cursorInfo))
Expand All @@ -70,9 +71,9 @@ public static void Draw(Graphics g, Func<Point, Point> Transform = null)
Bitmap icon;
Point hotspot;

if (_cursors.ContainsKey(cursorInfo.hCursor))
if (Cursors.ContainsKey(cursorInfo.hCursor))
{
var tuple = _cursors[cursorInfo.hCursor];
var tuple = Cursors[cursorInfo.hCursor];

icon = tuple.Item1;
hotspot = tuple.Item2;
Expand All @@ -84,18 +85,18 @@ public static void Draw(Graphics g, Func<Point, Point> Transform = null)
if (hIcon == IntPtr.Zero)
return;

if (!GetIconInfo(hIcon, out var _icInfo))
if (!GetIconInfo(hIcon, out var icInfo))
return;

icon = Icon.FromHandle(hIcon).ToBitmap();
hotspot = new Point(_icInfo.xHotspot, _icInfo.yHotspot);
hotspot = new Point(icInfo.xHotspot, icInfo.yHotspot);

_cursors.Add(cursorInfo.hCursor, Tuple.Create(icon, hotspot));
Cursors.Add(cursorInfo.hCursor, Tuple.Create(icon, hotspot));

DestroyIcon(hIcon);

DeleteObject(_icInfo.hbmColor);
DeleteObject(_icInfo.hbmMask);
DeleteObject(icInfo.hbmColor);
DeleteObject(icInfo.hbmMask);
}

var location = new Point(cursorInfo.ptScreenPos.X - hotspot.X,
Expand Down
3 changes: 3 additions & 0 deletions src/Screna/Recorder/Recorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public Recorder(IVideoFileWriter VideoWriter, IImageProvider ImageProvider, int
_imageProvider = ImageProvider ?? throw new ArgumentNullException(nameof(ImageProvider));
_audioProvider = AudioProvider;

if (FrameRate <= 0)
throw new ArgumentException("Frame Rate must be possitive", nameof(FrameRate));

_frameRate = FrameRate;

_continueCapturing = new ManualResetEvent(false);
Expand Down
14 changes: 13 additions & 1 deletion src/Screna/ScreenShot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ public static class ScreenShot
/// <returns>The Captured Image.</returns>
public static Bitmap Capture(Screen Screen, bool IncludeCursor = false)
{
if (Screen == null)
throw new ArgumentNullException(nameof(Screen));

return Capture(Screen.Bounds, IncludeCursor);
}

public static Bitmap Capture(Window Window, bool IncludeCursor = false)
{
if (Window == null)
throw new ArgumentNullException(nameof(Window));

return Capture(Window.Rectangle, IncludeCursor);
}

/// <summary>
/// Captures the entire Desktop.
/// </summary>
Expand All @@ -64,6 +70,9 @@ public static Bitmap Capture(bool IncludeCursor = false)
/// <param name="IncludeCursor">Whether to include Mouse Cursor.</param>
public static Bitmap CaptureTransparent(Window Window, bool IncludeCursor = false)
{
if (Window == null)
throw new ArgumentNullException(nameof(Window));

var backdrop = new Form
{
AllowTransparency = true,
Expand Down Expand Up @@ -137,6 +146,9 @@ public static Bitmap CaptureTransparent(Window Window, bool IncludeCursor = fals
/// <param name="ResizeHeight">Capture Height.</param>
public static Bitmap CaptureTransparent(Window Window, bool IncludeCursor, bool DoResize, int ResizeWidth, int ResizeHeight)
{
if (Window == null)
throw new ArgumentNullException(nameof(Window));

var startButtonHandle = User32.FindWindow("Button", "Start");
var taskbarHandle = User32.FindWindow("Shell_TrayWnd", null);

Expand Down
Loading

0 comments on commit ba820ff

Please sign in to comment.