2015-06-26 20:10:27 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2016-01-04 04:16:01 +13:00
|
|
|
|
Copyright (c) 2007-2016 ShareX Team
|
2015-06-26 20:10:27 +12:00
|
|
|
|
|
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
using ShareX.HelpersLib;
|
2016-03-22 02:16:33 +13:00
|
|
|
|
using ShareX.ScreenCaptureLib.Properties;
|
2015-06-26 20:10:27 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2016-03-22 02:16:33 +13:00
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
2015-06-26 20:10:27 +12:00
|
|
|
|
{
|
2016-02-26 09:55:54 +13:00
|
|
|
|
public partial class WebpageCaptureForm : Form
|
2015-06-26 20:10:27 +12:00
|
|
|
|
{
|
2016-04-01 23:11:43 +13:00
|
|
|
|
public event Action<Image> ImageUploadRequested;
|
|
|
|
|
public event Action<Image> ImageCopyRequested;
|
2015-06-27 03:59:30 +12:00
|
|
|
|
|
2016-03-22 02:16:33 +13:00
|
|
|
|
public WebpageCaptureOptions Options { get; set; }
|
2015-06-26 20:10:27 +12:00
|
|
|
|
public bool IsBusy { get; private set; }
|
|
|
|
|
|
|
|
|
|
private WebpageCapture webpageCapture;
|
2015-07-02 04:07:36 +12:00
|
|
|
|
private bool stopRequested;
|
2015-06-26 20:10:27 +12:00
|
|
|
|
|
2016-03-22 02:16:33 +13:00
|
|
|
|
public WebpageCaptureForm(WebpageCaptureOptions options)
|
2015-06-26 20:10:27 +12:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2016-02-26 09:55:54 +13:00
|
|
|
|
Icon = ShareXResources.Icon;
|
2016-03-22 02:16:33 +13:00
|
|
|
|
Options = options;
|
2015-06-27 03:26:40 +12:00
|
|
|
|
LoadSettings();
|
2015-06-26 20:10:27 +12:00
|
|
|
|
webpageCapture = new WebpageCapture();
|
|
|
|
|
webpageCapture.CaptureCompleted += webpageCapture_CaptureCompleted;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 03:26:40 +12:00
|
|
|
|
private void LoadSettings()
|
2015-06-28 01:03:15 +12:00
|
|
|
|
{
|
|
|
|
|
CheckClipboardURL();
|
|
|
|
|
|
2016-03-22 02:16:33 +13:00
|
|
|
|
Size browserSize = Options.BrowserSize;
|
2015-06-28 01:03:15 +12:00
|
|
|
|
if (browserSize.Width == 0) browserSize.Width = Screen.PrimaryScreen.Bounds.Width;
|
2016-03-01 10:09:22 +13:00
|
|
|
|
nudWebpageWidth.SetValue(browserSize.Width);
|
2015-06-28 01:03:15 +12:00
|
|
|
|
if (browserSize.Height == 0) browserSize.Height = Screen.PrimaryScreen.Bounds.Height;
|
2016-03-01 10:09:22 +13:00
|
|
|
|
nudWebpageHeight.SetValue(browserSize.Height);
|
2015-06-28 01:03:15 +12:00
|
|
|
|
|
2016-03-22 02:16:33 +13:00
|
|
|
|
nudCaptureDelay.SetValue((decimal)Options.Delay);
|
2015-07-02 04:07:36 +12:00
|
|
|
|
|
|
|
|
|
UpdateControls();
|
2015-06-28 01:03:15 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckClipboardURL()
|
2015-06-26 20:10:27 +12:00
|
|
|
|
{
|
|
|
|
|
if (Clipboard.ContainsText())
|
|
|
|
|
{
|
|
|
|
|
string text = Clipboard.GetText();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(text) && URLHelpers.IsValidURLRegex(text))
|
|
|
|
|
{
|
|
|
|
|
txtURL.Text = text;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-28 01:03:15 +12:00
|
|
|
|
}
|
2015-06-26 20:10:27 +12:00
|
|
|
|
|
2015-06-28 01:03:15 +12:00
|
|
|
|
private void CleanPictureBox()
|
|
|
|
|
{
|
|
|
|
|
if (pbResult.Image != null)
|
|
|
|
|
{
|
|
|
|
|
pbResult.Image.Dispose();
|
|
|
|
|
pbResult.Image = null;
|
|
|
|
|
}
|
2015-06-26 20:10:27 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtURL_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-07-02 04:07:36 +12:00
|
|
|
|
UpdateControls();
|
2015-06-26 20:10:27 +12:00
|
|
|
|
}
|
2015-06-27 03:26:40 +12:00
|
|
|
|
|
|
|
|
|
private void nudWebpageWidth_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-03-22 02:16:33 +13:00
|
|
|
|
Options.BrowserSize = new Size((int)nudWebpageWidth.Value, Options.BrowserSize.Height);
|
2015-06-27 03:26:40 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void nudWebpageHeight_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-03-22 02:16:33 +13:00
|
|
|
|
Options.BrowserSize = new Size(Options.BrowserSize.Width, (int)nudWebpageHeight.Value);
|
2015-06-27 03:26:40 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void nudCaptureDelay_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-03-22 02:16:33 +13:00
|
|
|
|
Options.Delay = (float)nudCaptureDelay.Value;
|
2015-06-27 03:26:40 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCapture_Click(object sender, EventArgs e)
|
2015-07-02 04:07:36 +12:00
|
|
|
|
{
|
|
|
|
|
if (IsBusy)
|
|
|
|
|
{
|
2015-07-02 13:50:49 +12:00
|
|
|
|
StopCapture();
|
2015-07-02 04:07:36 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-02 13:50:49 +12:00
|
|
|
|
StartCapture();
|
2015-07-02 04:07:36 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-02 13:50:49 +12:00
|
|
|
|
private void StartCapture()
|
2015-06-27 03:26:40 +12:00
|
|
|
|
{
|
|
|
|
|
IsBusy = true;
|
2015-07-02 04:07:36 +12:00
|
|
|
|
stopRequested = false;
|
|
|
|
|
UpdateControls();
|
2015-06-28 02:01:22 +12:00
|
|
|
|
|
|
|
|
|
lock (this)
|
|
|
|
|
{
|
|
|
|
|
CleanPictureBox();
|
|
|
|
|
}
|
2015-06-27 03:26:40 +12:00
|
|
|
|
|
|
|
|
|
webpageCapture.CaptureDelay = (int)nudCaptureDelay.Value * 1000;
|
|
|
|
|
webpageCapture.CapturePage(txtURL.Text, new Size((int)nudWebpageWidth.Value, (int)nudWebpageWidth.Value));
|
|
|
|
|
}
|
2015-06-27 03:59:30 +12:00
|
|
|
|
|
2015-07-02 13:50:49 +12:00
|
|
|
|
private void StopCapture()
|
2015-07-02 04:07:36 +12:00
|
|
|
|
{
|
|
|
|
|
IsBusy = false;
|
|
|
|
|
stopRequested = true;
|
|
|
|
|
webpageCapture.Stop();
|
|
|
|
|
UpdateControls();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-28 02:01:22 +12:00
|
|
|
|
private void webpageCapture_CaptureCompleted(Bitmap bmp)
|
|
|
|
|
{
|
2015-07-02 04:07:36 +12:00
|
|
|
|
if (!stopRequested && !IsDisposed)
|
2015-06-28 02:01:22 +12:00
|
|
|
|
{
|
|
|
|
|
lock (this)
|
|
|
|
|
{
|
|
|
|
|
CleanPictureBox();
|
|
|
|
|
pbResult.Image = bmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IsBusy = false;
|
2015-07-02 04:07:36 +12:00
|
|
|
|
UpdateControls();
|
2015-06-28 02:01:22 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-02 04:07:36 +12:00
|
|
|
|
private void UpdateControls()
|
|
|
|
|
{
|
2015-08-12 05:33:30 +12:00
|
|
|
|
btnCapture.Text = IsBusy ? Resources.WebpageCaptureForm_UpdateControls_Stop : Resources.WebpageCaptureForm_UpdateControls_Capture;
|
2015-07-02 04:07:36 +12:00
|
|
|
|
txtURL.Enabled = btnUpload.Enabled = btnCopy.Enabled = nudWebpageWidth.Enabled = nudWebpageHeight.Enabled = nudCaptureDelay.Enabled = !IsBusy;
|
|
|
|
|
btnCapture.Enabled = txtURL.TextLength > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-01 23:11:43 +13:00
|
|
|
|
protected void OnImageUploadRequested(Image img)
|
|
|
|
|
{
|
|
|
|
|
if (ImageUploadRequested != null)
|
|
|
|
|
{
|
|
|
|
|
ImageUploadRequested(img);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnImageCopyRequested(Image img)
|
|
|
|
|
{
|
|
|
|
|
if (ImageCopyRequested != null)
|
|
|
|
|
{
|
|
|
|
|
ImageCopyRequested(img);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 03:59:30 +12:00
|
|
|
|
private void btnUpload_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (pbResult.Image != null)
|
|
|
|
|
{
|
2015-06-28 02:01:22 +12:00
|
|
|
|
Image img;
|
|
|
|
|
|
|
|
|
|
lock (this)
|
|
|
|
|
{
|
|
|
|
|
img = (Image)pbResult.Image.Clone();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 03:59:30 +12:00
|
|
|
|
OnImageUploadRequested(img);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCopy_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (pbResult.Image != null)
|
|
|
|
|
{
|
2015-06-28 02:01:22 +12:00
|
|
|
|
Image img;
|
|
|
|
|
|
|
|
|
|
lock (this)
|
|
|
|
|
{
|
|
|
|
|
img = (Image)pbResult.Image.Clone();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 03:59:30 +12:00
|
|
|
|
OnImageCopyRequested(img);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-26 20:10:27 +12:00
|
|
|
|
}
|
|
|
|
|
}
|