diff --git a/ShareX.UploadersLib/FileUploaders/Plik.cs b/ShareX.UploadersLib/FileUploaders/Plik.cs
index 03a6fc051..d8712f137 100644
--- a/ShareX.UploadersLib/FileUploaders/Plik.cs
+++ b/ShareX.UploadersLib/FileUploaders/Plik.cs
@@ -1,4 +1,29 @@
-using Newtonsoft.Json;
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using Newtonsoft.Json;
using ShareX.HelpersLib;
using ShareX.UploadersLib.Properties;
using System;
diff --git a/ShareX.UploadersLib/FileUploaders/PlikSettings.cs b/ShareX.UploadersLib/FileUploaders/PlikSettings.cs
index 20a97cd3b..ccea7cfaa 100644
--- a/ShareX.UploadersLib/FileUploaders/PlikSettings.cs
+++ b/ShareX.UploadersLib/FileUploaders/PlikSettings.cs
@@ -1,4 +1,29 @@
-namespace ShareX.UploadersLib.FileUploaders
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+namespace ShareX.UploadersLib.FileUploaders
{
public class PlikSettings
{
diff --git a/ShareX.UploadersLib/FileUploaders/Pomf.cs b/ShareX.UploadersLib/FileUploaders/Pomf.cs
index 2444468a4..ef66ac45f 100644
--- a/ShareX.UploadersLib/FileUploaders/Pomf.cs
+++ b/ShareX.UploadersLib/FileUploaders/Pomf.cs
@@ -197,4 +197,4 @@ public override string ToString()
}
}
}
-}
+}
\ No newline at end of file
diff --git a/ShareX/CaptureHelpers/CaptureActiveMonitor.cs b/ShareX/CaptureHelpers/CaptureActiveMonitor.cs
new file mode 100644
index 000000000..6d2380b00
--- /dev/null
+++ b/ShareX/CaptureHelpers/CaptureActiveMonitor.cs
@@ -0,0 +1,38 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using System.Drawing;
+
+namespace ShareX
+{
+ public class CaptureActiveMonitor : CaptureBase
+ {
+ protected override ImageInfo Execute(TaskSettings taskSettings)
+ {
+ Image img = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveMonitor();
+ return new ImageInfo(img);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX/CaptureHelpers/CaptureActiveWindow.cs b/ShareX/CaptureHelpers/CaptureActiveWindow.cs
new file mode 100644
index 000000000..616a27ce1
--- /dev/null
+++ b/ShareX/CaptureHelpers/CaptureActiveWindow.cs
@@ -0,0 +1,65 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using ShareX.HelpersLib;
+using System.Diagnostics;
+using System.Drawing;
+
+namespace ShareX
+{
+ public class CaptureActiveWindow : CaptureBase
+ {
+ protected override ImageInfo Execute(TaskSettings taskSettings)
+ {
+ Image img;
+ string activeWindowTitle = NativeMethods.GetForegroundWindowText();
+ string activeProcessName = null;
+
+ using (Process process = NativeMethods.GetForegroundWindowProcess())
+ {
+ if (process != null)
+ {
+ activeProcessName = process.ProcessName;
+ }
+ }
+
+ if (taskSettings.CaptureSettings.CaptureTransparent && !taskSettings.CaptureSettings.CaptureClientArea)
+ {
+ img = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveWindowTransparent();
+ }
+ else
+ {
+ img = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveWindow();
+ }
+
+ return new ImageInfo()
+ {
+ Image = img,
+ WindowTitle = activeWindowTitle,
+ ProcessName = activeProcessName
+ };
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX/CaptureHelpers/CaptureBase.cs b/ShareX/CaptureHelpers/CaptureBase.cs
new file mode 100644
index 000000000..941c975b9
--- /dev/null
+++ b/ShareX/CaptureHelpers/CaptureBase.cs
@@ -0,0 +1,119 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using ShareX.HelpersLib;
+using System;
+using System.Threading;
+
+namespace ShareX
+{
+ public abstract class CaptureBase
+ {
+ public bool AllowAutoHideForm { get; set; } = true;
+
+ protected abstract ImageInfo Execute(TaskSettings taskSettings);
+
+ public void Capture(bool autoHideForm)
+ {
+ Capture(null, autoHideForm);
+ }
+
+ public void Capture(TaskSettings taskSettings = null, bool autoHideForm = false)
+ {
+ if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
+
+ if (taskSettings.CaptureSettings.IsDelayScreenshot && taskSettings.CaptureSettings.DelayScreenshot > 0)
+ {
+ TaskEx.Run(() =>
+ {
+ int sleep = (int)(taskSettings.CaptureSettings.DelayScreenshot * 1000);
+ Thread.Sleep(sleep);
+ },
+ () =>
+ {
+ CaptureInternal(taskSettings, autoHideForm);
+ });
+ }
+ else
+ {
+ CaptureInternal(taskSettings, autoHideForm);
+ }
+ }
+
+ private void CaptureInternal(TaskSettings taskSettings, bool autoHideForm)
+ {
+ if (autoHideForm && AllowAutoHideForm)
+ {
+ Program.MainForm.Hide();
+ Thread.Sleep(250);
+ }
+
+ ImageInfo imageInfo = null;
+
+ try
+ {
+ imageInfo = Execute(taskSettings);
+ }
+ catch (Exception ex)
+ {
+ DebugHelper.WriteException(ex);
+ }
+ finally
+ {
+ if (autoHideForm && AllowAutoHideForm)
+ {
+ Program.MainForm.ForceActivate();
+ }
+
+ AfterCapture(imageInfo, taskSettings);
+ }
+ }
+
+ private void AfterCapture(ImageInfo imageInfo, TaskSettings taskSettings)
+ {
+ if (imageInfo != null && imageInfo.Image != null)
+ {
+ if (taskSettings.GeneralSettings.PlaySoundAfterCapture)
+ {
+ TaskHelpers.PlayCaptureSound(taskSettings);
+ }
+
+ if (taskSettings.AdvancedSettings.UseShareXForAnnotation && taskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.AnnotateImage) &&
+ this.GetType() == typeof(CaptureRegion))
+ {
+ taskSettings.AfterCaptureJob = taskSettings.AfterCaptureJob.Remove(AfterCaptureTasks.AnnotateImage);
+ }
+
+ if (taskSettings.ImageSettings.ImageEffectOnlyRegionCapture &&
+ this.GetType() != typeof(CaptureRegion) && this.GetType() != typeof(CaptureLastRegion))
+ {
+ taskSettings.AfterCaptureJob = taskSettings.AfterCaptureJob.Remove(AfterCaptureTasks.AddImageEffects);
+ }
+
+ UploadManager.RunImageTask(imageInfo, taskSettings);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX/CaptureHelpers/CaptureCustomRegion.cs b/ShareX/CaptureHelpers/CaptureCustomRegion.cs
new file mode 100644
index 000000000..30ad30852
--- /dev/null
+++ b/ShareX/CaptureHelpers/CaptureCustomRegion.cs
@@ -0,0 +1,39 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using System.Drawing;
+
+namespace ShareX
+{
+ public class CaptureCustomRegion : CaptureBase
+ {
+ protected override ImageInfo Execute(TaskSettings taskSettings)
+ {
+ Rectangle regionBounds = taskSettings.CaptureSettings.CaptureCustomRegion;
+ Image img = TaskHelpers.GetScreenshot(taskSettings).CaptureRectangle(regionBounds);
+ return new ImageInfo(img);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX/CaptureHelpers/CaptureFullscreen.cs b/ShareX/CaptureHelpers/CaptureFullscreen.cs
new file mode 100644
index 000000000..c4ec7ae55
--- /dev/null
+++ b/ShareX/CaptureHelpers/CaptureFullscreen.cs
@@ -0,0 +1,38 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using System.Drawing;
+
+namespace ShareX
+{
+ public class CaptureFullscreen : CaptureBase
+ {
+ protected override ImageInfo Execute(TaskSettings taskSettings)
+ {
+ Image img = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen();
+ return new ImageInfo(img);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX/CaptureHelpers/CaptureLastRegion.cs b/ShareX/CaptureHelpers/CaptureLastRegion.cs
new file mode 100644
index 000000000..783e1c03e
--- /dev/null
+++ b/ShareX/CaptureHelpers/CaptureLastRegion.cs
@@ -0,0 +1,81 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using ShareX.HelpersLib;
+using ShareX.ScreenCaptureLib;
+using System.Drawing;
+
+namespace ShareX
+{
+ public class CaptureLastRegion : CaptureRegion
+ {
+ protected override ImageInfo Execute(TaskSettings taskSettings)
+ {
+ switch (lastRegionCaptureType)
+ {
+ default:
+ case RegionCaptureType.Default:
+ if (RegionCaptureForm.LastRegionFillPath != null)
+ {
+ using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
+ {
+ Image img = RegionCaptureTasks.ApplyRegionPathToImage(screenshot, RegionCaptureForm.LastRegionFillPath);
+ return new ImageInfo(img);
+ }
+ }
+ else
+ {
+ return ExecuteRegionCapture(taskSettings);
+ }
+ case RegionCaptureType.Light:
+ if (!RegionCaptureLightForm.LastSelectionRectangle0Based.IsEmpty)
+ {
+ using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
+ {
+ Image img = ImageHelpers.CropImage(screenshot, RegionCaptureLightForm.LastSelectionRectangle0Based);
+ return new ImageInfo(img);
+ }
+ }
+ else
+ {
+ return ExecuteRegionCaptureLight(taskSettings);
+ }
+ case RegionCaptureType.Transparent:
+ if (!RegionCaptureTransparentForm.LastSelectionRectangle0Based.IsEmpty)
+ {
+ using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
+ {
+ Image img = ImageHelpers.CropImage(screenshot, RegionCaptureTransparentForm.LastSelectionRectangle0Based);
+ return new ImageInfo(img);
+ }
+ }
+ else
+ {
+ return ExecuteRegionCaptureTransparent(taskSettings);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX/CaptureHelpers/CaptureMonitor.cs b/ShareX/CaptureHelpers/CaptureMonitor.cs
new file mode 100644
index 000000000..b2a2d4cb9
--- /dev/null
+++ b/ShareX/CaptureHelpers/CaptureMonitor.cs
@@ -0,0 +1,45 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using System.Drawing;
+
+namespace ShareX
+{
+ public class CaptureMonitor : CaptureBase
+ {
+ public Rectangle MonitorRectangle { get; private set; }
+
+ public CaptureMonitor(Rectangle monitorRectangle)
+ {
+ MonitorRectangle = monitorRectangle;
+ }
+
+ protected override ImageInfo Execute(TaskSettings taskSettings)
+ {
+ Image img = TaskHelpers.GetScreenshot().CaptureRectangle(MonitorRectangle);
+ return new ImageInfo(img);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX/CaptureHelpers/CaptureRegion.cs b/ShareX/CaptureHelpers/CaptureRegion.cs
new file mode 100644
index 000000000..ff6eadb4a
--- /dev/null
+++ b/ShareX/CaptureHelpers/CaptureRegion.cs
@@ -0,0 +1,154 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using ShareX.ScreenCaptureLib;
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace ShareX
+{
+ public class CaptureRegion : CaptureBase
+ {
+ protected static RegionCaptureType lastRegionCaptureType = RegionCaptureType.Default;
+
+ public RegionCaptureType RegionCaptureType { get; protected set; }
+
+ public CaptureRegion()
+ {
+ }
+
+ public CaptureRegion(RegionCaptureType regionCaptureType)
+ {
+ RegionCaptureType = regionCaptureType;
+ }
+
+ protected override ImageInfo Execute(TaskSettings taskSettings)
+ {
+ switch (RegionCaptureType)
+ {
+ default:
+ case RegionCaptureType.Default:
+ return ExecuteRegionCapture(taskSettings);
+ case RegionCaptureType.Light:
+ return ExecuteRegionCaptureLight(taskSettings);
+ case RegionCaptureType.Transparent:
+ return ExecuteRegionCaptureTransparent(taskSettings);
+ }
+ }
+
+ protected ImageInfo ExecuteRegionCapture(TaskSettings taskSettings)
+ {
+ ImageInfo imageInfo = new ImageInfo();
+
+ RegionCaptureMode mode;
+
+ if (taskSettings.AdvancedSettings.RegionCaptureDisableAnnotation)
+ {
+ mode = RegionCaptureMode.Default;
+ }
+ else
+ {
+ mode = RegionCaptureMode.Annotation;
+ }
+
+ RegionCaptureForm form = new RegionCaptureForm(mode);
+
+ try
+ {
+ form.Config = taskSettings.CaptureSettingsReference.SurfaceOptions;
+ Image img = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen();
+ form.Prepare(img);
+ form.ShowDialog();
+
+ imageInfo.Image = form.GetResultImage();
+
+ if (imageInfo.Image != null)
+ {
+ if (form.Result == RegionResult.Region && taskSettings.UploadSettings.RegionCaptureUseWindowPattern)
+ {
+ WindowInfo windowInfo = form.GetWindowInfo();
+
+ if (windowInfo != null)
+ {
+ imageInfo.WindowTitle = windowInfo.Text;
+ imageInfo.ProcessName = windowInfo.ProcessName;
+ }
+ }
+
+ lastRegionCaptureType = RegionCaptureType.Default;
+ }
+ }
+ finally
+ {
+ if (form != null)
+ {
+ form.Dispose();
+ }
+ }
+
+ return imageInfo;
+ }
+
+ protected ImageInfo ExecuteRegionCaptureLight(TaskSettings taskSettings)
+ {
+ Image img = null;
+
+ using (RegionCaptureLightForm rectangleLight = new RegionCaptureLightForm(TaskHelpers.GetScreenshot(taskSettings)))
+ {
+ if (rectangleLight.ShowDialog() == DialogResult.OK)
+ {
+ img = rectangleLight.GetAreaImage();
+
+ if (img != null)
+ {
+ lastRegionCaptureType = RegionCaptureType.Light;
+ }
+ }
+ }
+
+ return new ImageInfo(img);
+ }
+
+ protected ImageInfo ExecuteRegionCaptureTransparent(TaskSettings taskSettings)
+ {
+ Image img = null;
+
+ using (RegionCaptureTransparentForm rectangleTransparent = new RegionCaptureTransparentForm())
+ {
+ if (rectangleTransparent.ShowDialog() == DialogResult.OK)
+ {
+ img = rectangleTransparent.GetAreaImage(TaskHelpers.GetScreenshot(taskSettings));
+
+ if (img != null)
+ {
+ lastRegionCaptureType = RegionCaptureType.Transparent;
+ }
+ }
+ }
+
+ return new ImageInfo(img);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX/CaptureHelpers/CaptureWindow.cs b/ShareX/CaptureHelpers/CaptureWindow.cs
new file mode 100644
index 000000000..79772c275
--- /dev/null
+++ b/ShareX/CaptureHelpers/CaptureWindow.cs
@@ -0,0 +1,68 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2017 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using ShareX.HelpersLib;
+using System;
+using System.Drawing;
+using System.Threading;
+
+namespace ShareX
+{
+ public class CaptureWindow : CaptureBase
+ {
+ public IntPtr WindowHandle { get; private set; }
+
+ public CaptureWindow(IntPtr windowHandle)
+ {
+ WindowHandle = windowHandle;
+
+ AllowAutoHideForm = WindowHandle != Program.MainForm.Handle;
+ }
+
+ protected override ImageInfo Execute(TaskSettings taskSettings)
+ {
+ if (NativeMethods.IsIconic(WindowHandle))
+ {
+ NativeMethods.RestoreWindow(WindowHandle);
+ }
+
+ NativeMethods.SetForegroundWindow(WindowHandle);
+ Thread.Sleep(250);
+
+ Image img;
+
+ if (taskSettings.CaptureSettings.CaptureTransparent && !taskSettings.CaptureSettings.CaptureClientArea)
+ {
+ img = TaskHelpers.GetScreenshot(taskSettings).CaptureWindowTransparent(WindowHandle);
+ }
+ else
+ {
+ img = TaskHelpers.GetScreenshot(taskSettings).CaptureWindow(WindowHandle);
+ }
+
+ return new ImageInfo(img);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX/CaptureTaskHelpers.cs b/ShareX/CaptureTaskHelpers.cs
deleted file mode 100644
index cd6da2532..000000000
--- a/ShareX/CaptureTaskHelpers.cs
+++ /dev/null
@@ -1,416 +0,0 @@
-#region License Information (GPL v3)
-
-/*
- ShareX - A program that allows you to take screenshots and share any file type
- Copyright (c) 2007-2017 ShareX Team
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
- Optionally you can also view the license at .
-*/
-
-#endregion License Information (GPL v3)
-
-using ShareX.HelpersLib;
-using ShareX.ScreenCaptureLib;
-using System;
-using System.Diagnostics;
-using System.Drawing;
-using System.Threading;
-using System.Windows.Forms;
-
-namespace ShareX
-{
- public static class CaptureTaskHelpers
- {
- private delegate ImageInfo ScreenCaptureDelegate();
-
- private enum LastRegionCaptureType { Default, Light, Transparent }
-
- private static LastRegionCaptureType lastRegionCaptureType = LastRegionCaptureType.Default;
-
- public static void CaptureScreenshot(CaptureType captureType, TaskSettings taskSettings = null, bool autoHideForm = true)
- {
- if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
-
- switch (captureType)
- {
- case CaptureType.Fullscreen:
- CaptureFullscreen(taskSettings, autoHideForm);
- break;
- case CaptureType.ActiveWindow:
- CaptureActiveWindow(taskSettings, autoHideForm);
- break;
- case CaptureType.ActiveMonitor:
- CaptureActiveMonitor(taskSettings, autoHideForm);
- break;
- case CaptureType.Region:
- CaptureRegion(taskSettings, autoHideForm);
- break;
- case CaptureType.CustomRegion:
- CaptureCustomRegion(taskSettings, autoHideForm);
- break;
- case CaptureType.LastRegion:
- CaptureLastRegion(taskSettings, autoHideForm);
- break;
- }
- }
-
- private static void DoCapture(ScreenCaptureDelegate capture, CaptureType captureType, TaskSettings taskSettings = null, bool autoHideForm = true)
- {
- if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
-
- if (taskSettings.CaptureSettings.IsDelayScreenshot && taskSettings.CaptureSettings.DelayScreenshot > 0)
- {
- TaskEx.Run(() =>
- {
- int sleep = (int)(taskSettings.CaptureSettings.DelayScreenshot * 1000);
- Thread.Sleep(sleep);
- },
- () =>
- {
- DoCaptureWork(capture, captureType, taskSettings, autoHideForm);
- });
- }
- else
- {
- DoCaptureWork(capture, captureType, taskSettings, autoHideForm);
- }
- }
-
- private static void DoCaptureWork(ScreenCaptureDelegate capture, CaptureType captureType, TaskSettings taskSettings, bool autoHideForm = true)
- {
- if (autoHideForm)
- {
- Program.MainForm.Hide();
- Thread.Sleep(250);
- }
-
- ImageInfo imageInfo = null;
-
- try
- {
- imageInfo = capture();
- }
- catch (Exception ex)
- {
- DebugHelper.WriteException(ex);
- }
- finally
- {
- if (autoHideForm)
- {
- Program.MainForm.ForceActivate();
- }
-
- AfterCapture(imageInfo, captureType, taskSettings);
- }
- }
-
- private static void AfterCapture(ImageInfo imageInfo, CaptureType captureType, TaskSettings taskSettings)
- {
- if (imageInfo != null && imageInfo.Image != null)
- {
- if (taskSettings.GeneralSettings.PlaySoundAfterCapture)
- {
- TaskHelpers.PlayCaptureSound(taskSettings);
- }
-
- if (taskSettings.AdvancedSettings.UseShareXForAnnotation && taskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.AnnotateImage)
- && captureType == CaptureType.Region)
- {
- taskSettings.AfterCaptureJob = taskSettings.AfterCaptureJob.Remove(AfterCaptureTasks.AnnotateImage);
- }
-
- if (taskSettings.ImageSettings.ImageEffectOnlyRegionCapture && !IsRegionCapture(captureType))
- {
- taskSettings.AfterCaptureJob = taskSettings.AfterCaptureJob.Remove(AfterCaptureTasks.AddImageEffects);
- }
-
- UploadManager.RunImageTask(imageInfo, taskSettings);
- }
- }
-
- private static bool IsRegionCapture(CaptureType captureType)
- {
- return captureType.HasFlagAny(CaptureType.Region, CaptureType.LastRegion);
- }
-
- public static void CaptureFullscreen(TaskSettings taskSettings, bool autoHideForm = true)
- {
- DoCapture(() =>
- {
- Image img = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen();
- return new ImageInfo(img);
- }, CaptureType.Fullscreen, taskSettings, autoHideForm);
- }
-
- public static void CaptureWindow(IntPtr handle, TaskSettings taskSettings = null, bool autoHideForm = true)
- {
- if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
-
- autoHideForm = autoHideForm && handle != Program.MainForm.Handle;
-
- DoCapture(() =>
- {
- if (NativeMethods.IsIconic(handle))
- {
- NativeMethods.RestoreWindow(handle);
- }
-
- NativeMethods.SetForegroundWindow(handle);
- Thread.Sleep(250);
-
- Image img;
-
- if (taskSettings.CaptureSettings.CaptureTransparent && !taskSettings.CaptureSettings.CaptureClientArea)
- {
- img = TaskHelpers.GetScreenshot(taskSettings).CaptureWindowTransparent(handle);
- }
- else
- {
- img = TaskHelpers.GetScreenshot(taskSettings).CaptureWindow(handle);
- }
-
- return new ImageInfo(img);
- }, CaptureType.Window, taskSettings, autoHideForm);
- }
-
- public static void CaptureActiveWindow(TaskSettings taskSettings, bool autoHideForm = true)
- {
- DoCapture(() =>
- {
- Image img;
- string activeWindowTitle = NativeMethods.GetForegroundWindowText();
- string activeProcessName = null;
-
- using (Process process = NativeMethods.GetForegroundWindowProcess())
- {
- if (process != null)
- {
- activeProcessName = process.ProcessName;
- }
- }
-
- if (taskSettings.CaptureSettings.CaptureTransparent && !taskSettings.CaptureSettings.CaptureClientArea)
- {
- img = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveWindowTransparent();
- }
- else
- {
- img = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveWindow();
- }
-
- return new ImageInfo()
- {
- Image = img,
- WindowTitle = activeWindowTitle,
- ProcessName = activeProcessName
- };
- }, CaptureType.ActiveWindow, taskSettings, autoHideForm);
- }
-
- public static void CaptureMonitor(Rectangle rect, TaskSettings taskSettings = null, bool autoHideForm = true)
- {
- DoCapture(() =>
- {
- Image img = TaskHelpers.GetScreenshot().CaptureRectangle(rect);
- return new ImageInfo(img);
- }, CaptureType.Monitor, taskSettings, autoHideForm);
- }
-
- public static void CaptureActiveMonitor(TaskSettings taskSettings, bool autoHideForm)
- {
- DoCapture(() =>
- {
- Image img = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveMonitor();
- return new ImageInfo(img);
- }, CaptureType.ActiveMonitor, taskSettings, autoHideForm);
- }
-
- public static void CaptureCustomRegion(TaskSettings taskSettings, bool autoHideForm)
- {
- DoCapture(() =>
- {
- Rectangle regionBounds = taskSettings.CaptureSettings.CaptureCustomRegion;
- Image img = TaskHelpers.GetScreenshot(taskSettings).CaptureRectangle(regionBounds);
- return new ImageInfo(img);
- }, CaptureType.CustomRegion, taskSettings, autoHideForm);
- }
-
- public static void CaptureRegion(TaskSettings taskSettings, bool autoHideForm = true)
- {
- RegionCaptureMode mode;
-
- if (taskSettings.AdvancedSettings.RegionCaptureDisableAnnotation)
- {
- mode = RegionCaptureMode.Default;
- }
- else
- {
- mode = RegionCaptureMode.Annotation;
- }
-
- RegionCaptureForm form = new RegionCaptureForm(mode);
-
- DoCapture(() =>
- {
- ImageInfo imageInfo = new ImageInfo();
-
- try
- {
- form.Config = taskSettings.CaptureSettingsReference.SurfaceOptions;
- form.Prepare(TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen());
- form.ShowDialog();
-
- imageInfo.Image = form.GetResultImage();
-
- if (imageInfo.Image != null)
- {
- if (form.Result == RegionResult.Region && taskSettings.UploadSettings.RegionCaptureUseWindowPattern)
- {
- WindowInfo windowInfo = form.GetWindowInfo();
-
- if (windowInfo != null)
- {
- imageInfo.WindowTitle = windowInfo.Text;
- imageInfo.ProcessName = windowInfo.ProcessName;
- }
- }
-
- lastRegionCaptureType = LastRegionCaptureType.Default;
- }
- }
- finally
- {
- if (form != null)
- {
- form.Dispose();
- }
- }
-
- return imageInfo;
- }, CaptureType.Region, taskSettings, autoHideForm);
- }
-
- public static void CaptureRectangleLight(TaskSettings taskSettings = null, bool autoHideForm = true)
- {
- if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
-
- DoCapture(() =>
- {
- Image img = null;
-
- using (RegionCaptureLightForm rectangleLight = new RegionCaptureLightForm(TaskHelpers.GetScreenshot(taskSettings)))
- {
- if (rectangleLight.ShowDialog() == DialogResult.OK)
- {
- img = rectangleLight.GetAreaImage();
-
- if (img != null)
- {
- lastRegionCaptureType = LastRegionCaptureType.Light;
- }
- }
- }
-
- return new ImageInfo(img);
- }, CaptureType.Region, taskSettings, autoHideForm);
- }
-
- public static void CaptureRectangleTransparent(TaskSettings taskSettings = null, bool autoHideForm = true)
- {
- if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
-
- DoCapture(() =>
- {
- Image img = null;
-
- using (RegionCaptureTransparentForm rectangleTransparent = new RegionCaptureTransparentForm())
- {
- if (rectangleTransparent.ShowDialog() == DialogResult.OK)
- {
- img = rectangleTransparent.GetAreaImage(TaskHelpers.GetScreenshot(taskSettings));
-
- if (img != null)
- {
- lastRegionCaptureType = LastRegionCaptureType.Transparent;
- }
- }
- }
-
- return new ImageInfo(img);
- }, CaptureType.Region, taskSettings, autoHideForm);
- }
-
- public static void CaptureLastRegion(TaskSettings taskSettings, bool autoHideForm = true)
- {
- switch (lastRegionCaptureType)
- {
- case LastRegionCaptureType.Default:
- if (RegionCaptureForm.LastRegionFillPath != null)
- {
- DoCapture(() =>
- {
- using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
- {
- Image img = RegionCaptureTasks.ApplyRegionPathToImage(screenshot, RegionCaptureForm.LastRegionFillPath);
- return new ImageInfo(img);
- }
- }, CaptureType.LastRegion, taskSettings, autoHideForm);
- }
- else
- {
- CaptureRegion(taskSettings, autoHideForm);
- }
- break;
- case LastRegionCaptureType.Light:
- if (!RegionCaptureLightForm.LastSelectionRectangle0Based.IsEmpty)
- {
- DoCapture(() =>
- {
- using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
- {
- Image img = ImageHelpers.CropImage(screenshot, RegionCaptureLightForm.LastSelectionRectangle0Based);
- return new ImageInfo(img);
- }
- }, CaptureType.LastRegion, taskSettings, autoHideForm);
- }
- else
- {
- CaptureRectangleLight(taskSettings, autoHideForm);
- }
- break;
- case LastRegionCaptureType.Transparent:
- if (!RegionCaptureTransparentForm.LastSelectionRectangle0Based.IsEmpty)
- {
- DoCapture(() =>
- {
- using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
- {
- Image img = ImageHelpers.CropImage(screenshot, RegionCaptureTransparentForm.LastSelectionRectangle0Based);
- return new ImageInfo(img);
- }
- }, CaptureType.LastRegion, taskSettings, autoHideForm);
- }
- else
- {
- CaptureRectangleTransparent(taskSettings, autoHideForm);
- }
- break;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/ShareX/Enums.cs b/ShareX/Enums.cs
index 3cad4c65d..11ba4caa5 100644
--- a/ShareX/Enums.cs
+++ b/ShareX/Enums.cs
@@ -247,4 +247,9 @@ public enum ScreenRecordState
{
Waiting, BeforeStart, AfterStart, AfterRecordingStart, AfterStop
}
+
+ public enum RegionCaptureType
+ {
+ Default, Light, Transparent
+ }
}
\ No newline at end of file
diff --git a/ShareX/Forms/MainForm.cs b/ShareX/Forms/MainForm.cs
index f7fc1bfb8..55ae90f95 100644
--- a/ShareX/Forms/MainForm.cs
+++ b/ShareX/Forms/MainForm.cs
@@ -1261,7 +1261,7 @@ private void pbPatreonHide_Click(object sender, EventArgs e)
private void tsmiFullscreen_Click(object sender, EventArgs e)
{
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.Fullscreen);
+ new CaptureFullscreen().Capture(true);
}
private void tsddbCapture_DropDownOpening(object sender, EventArgs e)
@@ -1275,7 +1275,7 @@ private void tsmiWindowItems_Click(object sender, EventArgs e)
WindowInfo wi = tsi.Tag as WindowInfo;
if (wi != null)
{
- CaptureTaskHelpers.CaptureWindow(wi.Handle);
+ new CaptureWindow(wi.Handle).Capture(true);
}
}
@@ -1285,28 +1285,28 @@ private void tsmiMonitorItems_Click(object sender, EventArgs e)
Rectangle rect = (Rectangle)tsi.Tag;
if (!rect.IsEmpty)
{
- CaptureTaskHelpers.CaptureMonitor(rect);
+ new CaptureMonitor(rect).Capture(true);
}
}
private void tsmiRectangle_Click(object sender, EventArgs e)
{
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.Region);
+ new CaptureRegion().Capture(true);
}
private void tsmiRectangleLight_Click(object sender, EventArgs e)
{
- CaptureTaskHelpers.CaptureRectangleLight();
+ new CaptureRegion(RegionCaptureType.Light).Capture(true);
}
private void tsmiRectangleTransparent_Click(object sender, EventArgs e)
{
- CaptureTaskHelpers.CaptureRectangleTransparent();
+ new CaptureRegion(RegionCaptureType.Transparent).Capture(true);
}
private void tsmiLastRegion_Click(object sender, EventArgs e)
{
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.LastRegion);
+ new CaptureLastRegion().Capture(true);
}
private void tsmiScreenRecordingFFmpeg_Click(object sender, EventArgs e)
@@ -1614,7 +1614,7 @@ private void cmsTray_Opened(object sender, EventArgs e)
private void tsmiTrayFullscreen_Click(object sender, EventArgs e)
{
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.Fullscreen, null, false);
+ new CaptureFullscreen().Capture();
}
private void tsmiCapture_DropDownOpening(object sender, EventArgs e)
@@ -1628,7 +1628,7 @@ private void tsmiTrayWindowItems_Click(object sender, EventArgs e)
WindowInfo wi = tsi.Tag as WindowInfo;
if (wi != null)
{
- CaptureTaskHelpers.CaptureWindow(wi.Handle, null, false);
+ new CaptureWindow(wi.Handle).Capture();
}
}
@@ -1638,28 +1638,28 @@ private void tsmiTrayMonitorItems_Click(object sender, EventArgs e)
Rectangle rect = (Rectangle)tsi.Tag;
if (!rect.IsEmpty)
{
- CaptureTaskHelpers.CaptureMonitor(rect, null, false);
+ new CaptureMonitor(rect).Capture();
}
}
private void tsmiTrayRectangle_Click(object sender, EventArgs e)
{
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.Region, null, false);
+ new CaptureRegion().Capture();
}
private void tsmiTrayRectangleLight_Click(object sender, EventArgs e)
{
- CaptureTaskHelpers.CaptureRectangleLight(null, false);
+ new CaptureRegion(RegionCaptureType.Light).Capture();
}
private void tsmiTrayRectangleTransparent_Click(object sender, EventArgs e)
{
- CaptureTaskHelpers.CaptureRectangleTransparent(null, false);
+ new CaptureRegion(RegionCaptureType.Transparent).Capture();
}
private void tsmiTrayLastRegion_Click(object sender, EventArgs e)
{
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.LastRegion, null, false);
+ new CaptureLastRegion().Capture();
}
private void tsmiTrayTextCapture_Click(object sender, EventArgs e)
diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj
index ce4bff45e..f95defc93 100644
--- a/ShareX/ShareX.csproj
+++ b/ShareX/ShareX.csproj
@@ -102,7 +102,15 @@
-
+
+
+
+
+
+
+
+
+
UserControl
diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs
index 748ea227e..3d619b6bf 100644
--- a/ShareX/TaskHelpers.cs
+++ b/ShareX/TaskHelpers.cs
@@ -94,28 +94,28 @@ public static void ExecuteJob(TaskSettings taskSettings, HotkeyType job, CLIComm
break;
// Screen capture
case HotkeyType.PrintScreen:
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.Fullscreen, safeTaskSettings, false);
+ new CaptureFullscreen().Capture(safeTaskSettings);
break;
case HotkeyType.ActiveWindow:
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.ActiveWindow, safeTaskSettings, false);
+ new CaptureActiveWindow().Capture(safeTaskSettings);
break;
case HotkeyType.ActiveMonitor:
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.ActiveMonitor, safeTaskSettings, false);
+ new CaptureActiveMonitor().Capture(safeTaskSettings);
break;
case HotkeyType.RectangleRegion:
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.Region, safeTaskSettings, false);
+ new CaptureRegion().Capture(safeTaskSettings);
break;
case HotkeyType.RectangleLight:
- CaptureTaskHelpers.CaptureRectangleLight(safeTaskSettings, false);
+ new CaptureRegion(RegionCaptureType.Light).Capture(safeTaskSettings);
break;
case HotkeyType.RectangleTransparent:
- CaptureTaskHelpers.CaptureRectangleTransparent(safeTaskSettings, false);
+ new CaptureRegion(RegionCaptureType.Transparent).Capture(safeTaskSettings);
break;
case HotkeyType.CustomRegion:
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.CustomRegion, safeTaskSettings, false);
+ new CaptureCustomRegion().Capture(safeTaskSettings);
break;
case HotkeyType.LastRegion:
- CaptureTaskHelpers.CaptureScreenshot(CaptureType.LastRegion, safeTaskSettings, false);
+ new CaptureLastRegion().Capture(safeTaskSettings);
break;
case HotkeyType.ScrollingCapture:
OpenScrollingCapture(safeTaskSettings, true);