From a3d654269ae56f064e4efe3b6bd3c25f5029d990 Mon Sep 17 00:00:00 2001 From: Jaex Date: Fri, 26 Jun 2015 18:26:40 +0300 Subject: [PATCH] Added delay setting to webpage capture, saving this settings to application config --- ShareX.HelpersLib/TaskEx.cs | 13 ++++ .../ShareX.ScreenCaptureLib.csproj | 9 --- ShareX.ScreenCaptureLib/WebpageCapture.cs | 11 +++ ShareX/ApplicationConfig.cs | 7 ++ .../Forms/WebpageCaptureForm.Designer.cs | 34 ++++++++- .../Forms/WebpageCaptureForm.cs | 60 ++++++++++----- .../Forms/WebpageCaptureForm.resx | 73 ++++++++++++++++--- ShareX/ShareX.csproj | 9 +++ 8 files changed, 177 insertions(+), 39 deletions(-) rename {ShareX.ScreenCaptureLib => ShareX}/Forms/WebpageCaptureForm.Designer.cs (80%) rename {ShareX.ScreenCaptureLib => ShareX}/Forms/WebpageCaptureForm.cs (65%) rename {ShareX.ScreenCaptureLib => ShareX}/Forms/WebpageCaptureForm.resx (87%) diff --git a/ShareX.HelpersLib/TaskEx.cs b/ShareX.HelpersLib/TaskEx.cs index 384a878c8..8147d1e4b 100644 --- a/ShareX.HelpersLib/TaskEx.cs +++ b/ShareX.HelpersLib/TaskEx.cs @@ -24,6 +24,7 @@ #endregion License Information (GPL v3) using System; +using System.Threading; using System.Threading.Tasks; namespace ShareX.HelpersLib @@ -50,5 +51,17 @@ public static Task Run(Action thread, Action completed, bool completedInFormThre return Run(thread).ContinueWith(task => completed(), taskScheduler); } + + public static void RunDelayed(Action thread, int delay) + { + if (delay > 0) + { + Run(() => Thread.Sleep(delay), thread); + } + else + { + thread(); + } + } } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj index d01dd6485..4d366e33d 100644 --- a/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj +++ b/ShareX.ScreenCaptureLib/ShareX.ScreenCaptureLib.csproj @@ -55,12 +55,6 @@ Form - - Form - - - WebpageCaptureForm.cs - @@ -135,9 +129,6 @@ - - WebpageCaptureForm.cs - Designer diff --git a/ShareX.ScreenCaptureLib/WebpageCapture.cs b/ShareX.ScreenCaptureLib/WebpageCapture.cs index 2e2895a29..12c77accf 100644 --- a/ShareX.ScreenCaptureLib/WebpageCapture.cs +++ b/ShareX.ScreenCaptureLib/WebpageCapture.cs @@ -29,6 +29,7 @@ using System.Drawing; using System.Linq; using System.Text; +using System.Threading; using System.Windows.Forms; namespace ShareX.ScreenCaptureLib @@ -37,6 +38,8 @@ public class WebpageCapture : IDisposable { public event Action CaptureCompleted; + public int CaptureDelay { get; set; } + private WebBrowser webBrowser; public WebpageCapture() @@ -62,6 +65,14 @@ public void CapturePage(string url, Size browserSize) } private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) + { + if (webBrowser.ReadyState == WebBrowserReadyState.Complete) + { + TaskEx.RunDelayed(GetWebpageBitmap, CaptureDelay); + } + } + + private void GetWebpageBitmap() { Rectangle rect = webBrowser.Document.Body.ScrollRectangle; webBrowser.Size = new Size(rect.Width, rect.Height); diff --git a/ShareX/ApplicationConfig.cs b/ShareX/ApplicationConfig.cs index 74946b914..531fe676b 100644 --- a/ShareX/ApplicationConfig.cs +++ b/ShareX/ApplicationConfig.cs @@ -212,5 +212,12 @@ public ApplicationConfig() public List AutomateScripts = new List(); #endregion Automate Form + + #region Webpage Capture Form + + public Size WebpageCaptureBrowserSize = Size.Empty; + public float WebpageCaptureDelay = 0f; + + #endregion Webpage Capture Form } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/WebpageCaptureForm.Designer.cs b/ShareX/Forms/WebpageCaptureForm.Designer.cs similarity index 80% rename from ShareX.ScreenCaptureLib/Forms/WebpageCaptureForm.Designer.cs rename to ShareX/Forms/WebpageCaptureForm.Designer.cs index 1c274a981..961c3a050 100644 --- a/ShareX.ScreenCaptureLib/Forms/WebpageCaptureForm.Designer.cs +++ b/ShareX/Forms/WebpageCaptureForm.Designer.cs @@ -1,4 +1,4 @@ -namespace ShareX.ScreenCaptureLib +namespace ShareX { partial class WebpageCaptureForm { @@ -44,10 +44,13 @@ private void InitializeComponent() this.nudWebpageWidth = new System.Windows.Forms.NumericUpDown(); this.nudWebpageHeight = new System.Windows.Forms.NumericUpDown(); this.lblWebpageX = new System.Windows.Forms.Label(); + this.lblCaptureDelay = new System.Windows.Forms.Label(); + this.nudCaptureDelay = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.pbResult)).BeginInit(); this.pResult.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.nudWebpageWidth)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudWebpageHeight)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudCaptureDelay)).BeginInit(); this.SuspendLayout(); // // txtURL @@ -107,6 +110,7 @@ private void InitializeComponent() 0, 0, 0}); + this.nudWebpageWidth.ValueChanged += new System.EventHandler(this.nudWebpageWidth_ValueChanged); // // nudWebpageHeight // @@ -127,17 +131,42 @@ private void InitializeComponent() 0, 0, 0}); + this.nudWebpageHeight.ValueChanged += new System.EventHandler(this.nudWebpageHeight_ValueChanged); // // lblWebpageX // resources.ApplyResources(this.lblWebpageX, "lblWebpageX"); this.lblWebpageX.Name = "lblWebpageX"; // + // lblCaptureDelay + // + resources.ApplyResources(this.lblCaptureDelay, "lblCaptureDelay"); + this.lblCaptureDelay.Name = "lblCaptureDelay"; + // + // nudCaptureDelay + // + this.nudCaptureDelay.DecimalPlaces = 1; + this.nudCaptureDelay.Increment = new decimal(new int[] { + 5, + 0, + 0, + 65536}); + resources.ApplyResources(this.nudCaptureDelay, "nudCaptureDelay"); + this.nudCaptureDelay.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.nudCaptureDelay.Name = "nudCaptureDelay"; + this.nudCaptureDelay.ValueChanged += new System.EventHandler(this.nudCaptureDelay_ValueChanged); + // // WebpageCaptureForm // this.AcceptButton = this.btnCapture; resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.nudCaptureDelay); + this.Controls.Add(this.lblCaptureDelay); this.Controls.Add(this.nudWebpageHeight); this.Controls.Add(this.lblWebpageX); this.Controls.Add(this.nudWebpageWidth); @@ -152,6 +181,7 @@ private void InitializeComponent() this.pResult.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.nudWebpageWidth)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nudWebpageHeight)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudCaptureDelay)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -168,5 +198,7 @@ private void InitializeComponent() private System.Windows.Forms.NumericUpDown nudWebpageWidth; private System.Windows.Forms.NumericUpDown nudWebpageHeight; private System.Windows.Forms.Label lblWebpageX; + private System.Windows.Forms.Label lblCaptureDelay; + private System.Windows.Forms.NumericUpDown nudCaptureDelay; } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/WebpageCaptureForm.cs b/ShareX/Forms/WebpageCaptureForm.cs similarity index 65% rename from ShareX.ScreenCaptureLib/Forms/WebpageCaptureForm.cs rename to ShareX/Forms/WebpageCaptureForm.cs index 984ad64c4..717c3de3a 100644 --- a/ShareX.ScreenCaptureLib/Forms/WebpageCaptureForm.cs +++ b/ShareX/Forms/WebpageCaptureForm.cs @@ -24,6 +24,7 @@ #endregion License Information (GPL v3) using ShareX.HelpersLib; +using ShareX.ScreenCaptureLib; using System; using System.Collections.Generic; using System.ComponentModel; @@ -33,7 +34,7 @@ using System.Text; using System.Windows.Forms; -namespace ShareX.ScreenCaptureLib +namespace ShareX { public partial class WebpageCaptureForm : Form { @@ -45,14 +46,12 @@ public WebpageCaptureForm() { InitializeComponent(); Icon = ShareXResources.Icon; - CheckClipboard(); - nudWebpageWidth.Value = Screen.PrimaryScreen.Bounds.Width.Between((int)nudWebpageWidth.Minimum, (int)nudWebpageWidth.Maximum); - nudWebpageHeight.Value = Screen.PrimaryScreen.Bounds.Height.Between((int)nudWebpageHeight.Minimum, (int)nudWebpageHeight.Maximum); + LoadSettings(); webpageCapture = new WebpageCapture(); webpageCapture.CaptureCompleted += webpageCapture_CaptureCompleted; } - private void CheckClipboard() + private void LoadSettings() { if (Clipboard.ContainsText()) { @@ -63,6 +62,43 @@ private void CheckClipboard() txtURL.Text = text; } } + + Size browserSize = Program.Settings.WebpageCaptureBrowserSize; + if (browserSize.Width == 0) browserSize.Width = Screen.PrimaryScreen.Bounds.Width; + nudWebpageWidth.Value = browserSize.Width.Between((int)nudWebpageWidth.Minimum, (int)nudWebpageWidth.Maximum); + if (browserSize.Height == 0) browserSize.Height = Screen.PrimaryScreen.Bounds.Height; + nudWebpageHeight.Value = browserSize.Height.Between((int)nudWebpageHeight.Minimum, (int)nudWebpageHeight.Maximum); + + nudCaptureDelay.Value = (decimal)Program.Settings.WebpageCaptureDelay.Between((float)nudCaptureDelay.Minimum, (float)nudCaptureDelay.Maximum); + + btnCapture.Enabled = txtURL.TextLength > 0; + } + + private void webpageCapture_CaptureCompleted(Bitmap bmp) + { + pbResult.Image = bmp; + IsBusy = false; + btnCapture.Enabled = txtURL.Enabled = !IsBusy; + } + + private void txtURL_TextChanged(object sender, EventArgs e) + { + btnCapture.Enabled = txtURL.TextLength > 0; + } + + private void nudWebpageWidth_ValueChanged(object sender, EventArgs e) + { + Program.Settings.WebpageCaptureBrowserSize.Width = (int)nudWebpageWidth.Value; + } + + private void nudWebpageHeight_ValueChanged(object sender, EventArgs e) + { + Program.Settings.WebpageCaptureBrowserSize.Height = (int)nudWebpageHeight.Value; + } + + private void nudCaptureDelay_ValueChanged(object sender, EventArgs e) + { + Program.Settings.WebpageCaptureDelay = (float)nudCaptureDelay.Value; } private void btnCapture_Click(object sender, EventArgs e) @@ -75,20 +111,8 @@ private void btnCapture_Click(object sender, EventArgs e) pbResult.Image = null; } + webpageCapture.CaptureDelay = (int)nudCaptureDelay.Value * 1000; webpageCapture.CapturePage(txtURL.Text, new Size((int)nudWebpageWidth.Value, (int)nudWebpageWidth.Value)); } - - private void webpageCapture_CaptureCompleted(Bitmap bmp) - { - pbResult.Image = bmp; - - IsBusy = false; - btnCapture.Enabled = txtURL.Enabled = !IsBusy; - } - - private void txtURL_TextChanged(object sender, EventArgs e) - { - btnCapture.Enabled = txtURL.TextLength > 0; - } } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/WebpageCaptureForm.resx b/ShareX/Forms/WebpageCaptureForm.resx similarity index 87% rename from ShareX.ScreenCaptureLib/Forms/WebpageCaptureForm.resx rename to ShareX/Forms/WebpageCaptureForm.resx index cdd82ed9f..705846aa1 100644 --- a/ShareX.ScreenCaptureLib/Forms/WebpageCaptureForm.resx +++ b/ShareX/Forms/WebpageCaptureForm.resx @@ -142,7 +142,7 @@ $this - 7 + 9 True @@ -169,10 +169,10 @@ $this - 6 + 8 - 249, 35 + 336, 35 112, 23 @@ -193,7 +193,7 @@ $this - 5 + 7 0, 0 @@ -244,7 +244,7 @@ $this - 4 + 6 True @@ -271,10 +271,10 @@ $this - 3 + 5 - 88, 36 + 80, 36 64, 20 @@ -295,10 +295,10 @@ $this - 2 + 4 - 176, 36 + 168, 36 64, 20 @@ -319,7 +319,7 @@ $this - 0 + 2 True @@ -328,7 +328,7 @@ NoControl - 159, 40 + 151, 40 12, 13 @@ -349,8 +349,59 @@ $this + 3 + + + True + + + 240, 40 + + + 37, 13 + + + 9 + + + Delay: + + + lblCaptureDelay + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 1 + + 280, 36 + + + 48, 20 + + + 10 + + + Center + + + nudCaptureDelay + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + True diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index d4ed7cd59..34d5a5cae 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -179,6 +179,12 @@ AfterUploadForm.cs + + Form + + + WebpageCaptureForm.cs + @@ -718,6 +724,9 @@ WatchFolderForm.cs + + WebpageCaptureForm.cs +