From fc01a41468181a415d8abe043c5b23f55ed9145d Mon Sep 17 00:00:00 2001 From: Jaex Date: Sat, 26 Sep 2015 12:18:38 +0300 Subject: [PATCH] Auto detect scroll end option and remove duplicates --- .../Forms/ScrollingCaptureForm.Designer.cs | 52 ++++++++++++------- .../Forms/ScrollingCaptureForm.cs | 31 ++++++++++- .../ScrollingCaptureOptions.cs | 1 + 3 files changed, 64 insertions(+), 20 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs index 8da8d4c82..f4988dd13 100644 --- a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs +++ b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs @@ -33,6 +33,8 @@ private void InitializeComponent() this.lblMaximumScrollCount = new System.Windows.Forms.Label(); this.tcScrollingCapture = new System.Windows.Forms.TabControl(); this.tpCapture = new System.Windows.Forms.TabPage(); + this.lblScrollMethod = new System.Windows.Forms.Label(); + this.cbScrollMethod = new System.Windows.Forms.ComboBox(); this.tpOutput = new System.Windows.Forms.TabPage(); this.btnResetCombine = new System.Windows.Forms.Button(); this.btnGuessCombineAdjustments = new System.Windows.Forms.Button(); @@ -55,8 +57,7 @@ private void InitializeComponent() this.nudTrimRight = new System.Windows.Forms.NumericUpDown(); this.pOutput = new System.Windows.Forms.Panel(); this.pbOutput = new System.Windows.Forms.PictureBox(); - this.cbScrollMethod = new System.Windows.Forms.ComboBox(); - this.lblScrollMethod = new System.Windows.Forms.Label(); + this.cbAutoDetectScrollEnd = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.nudScrollDelay)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudMaximumScrollCount)).BeginInit(); this.tcScrollingCapture.SuspendLayout(); @@ -95,7 +96,7 @@ private void InitializeComponent() // btnCapture // this.btnCapture.Enabled = false; - this.btnCapture.Location = new System.Drawing.Point(16, 128); + this.btnCapture.Location = new System.Drawing.Point(16, 144); this.btnCapture.Name = "btnCapture"; this.btnCapture.Size = new System.Drawing.Size(152, 23); this.btnCapture.TabIndex = 2; @@ -161,6 +162,7 @@ private void InitializeComponent() // // tpCapture // + this.tpCapture.Controls.Add(this.cbAutoDetectScrollEnd); this.tpCapture.Controls.Add(this.lblScrollMethod); this.tpCapture.Controls.Add(this.cbScrollMethod); this.tpCapture.Controls.Add(this.btnSelectHandle); @@ -178,6 +180,24 @@ private void InitializeComponent() this.tpCapture.Text = "Capture"; this.tpCapture.UseVisualStyleBackColor = true; // + // lblScrollMethod + // + this.lblScrollMethod.AutoSize = true; + this.lblScrollMethod.Location = new System.Drawing.Point(16, 48); + this.lblScrollMethod.Name = "lblScrollMethod"; + this.lblScrollMethod.Size = new System.Drawing.Size(74, 13); + this.lblScrollMethod.TabIndex = 8; + this.lblScrollMethod.Text = "Scroll method:"; + // + // cbScrollMethod + // + this.cbScrollMethod.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbScrollMethod.FormattingEnabled = true; + this.cbScrollMethod.Location = new System.Drawing.Point(136, 44); + this.cbScrollMethod.Name = "cbScrollMethod"; + this.cbScrollMethod.Size = new System.Drawing.Size(176, 21); + this.cbScrollMethod.TabIndex = 7; + // // tpOutput // this.tpOutput.Controls.Add(this.btnResetCombine); @@ -438,23 +458,16 @@ private void InitializeComponent() this.pbOutput.TabIndex = 0; this.pbOutput.TabStop = false; // - // cbScrollMethod + // cbAutoDetectScrollEnd // - this.cbScrollMethod.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cbScrollMethod.FormattingEnabled = true; - this.cbScrollMethod.Location = new System.Drawing.Point(136, 44); - this.cbScrollMethod.Name = "cbScrollMethod"; - this.cbScrollMethod.Size = new System.Drawing.Size(176, 21); - this.cbScrollMethod.TabIndex = 7; - // - // lblScrollMethod - // - this.lblScrollMethod.AutoSize = true; - this.lblScrollMethod.Location = new System.Drawing.Point(16, 48); - this.lblScrollMethod.Name = "lblScrollMethod"; - this.lblScrollMethod.Size = new System.Drawing.Size(74, 13); - this.lblScrollMethod.TabIndex = 8; - this.lblScrollMethod.Text = "Scroll method:"; + this.cbAutoDetectScrollEnd.AutoSize = true; + this.cbAutoDetectScrollEnd.Location = new System.Drawing.Point(16, 120); + this.cbAutoDetectScrollEnd.Name = "cbAutoDetectScrollEnd"; + this.cbAutoDetectScrollEnd.Size = new System.Drawing.Size(129, 17); + this.cbAutoDetectScrollEnd.TabIndex = 9; + this.cbAutoDetectScrollEnd.Text = "Auto detect scroll end"; + this.cbAutoDetectScrollEnd.UseVisualStyleBackColor = true; + this.cbAutoDetectScrollEnd.CheckedChanged += new System.EventHandler(this.cbAutoDetectScrollEnd_CheckedChanged); // // ScrollingCaptureForm // @@ -524,5 +537,6 @@ private void InitializeComponent() private Button btnResetCombine; private Label lblScrollMethod; private ComboBox cbScrollMethod; + private CheckBox cbAutoDetectScrollEnd; } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs index 2307f3435..83187a636 100644 --- a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs @@ -58,6 +58,7 @@ public ScrollingCaptureForm(ScrollingCaptureOptions options) cbScrollMethod.SelectedIndex = (int)Options.ScrollMethod; nudScrollDelay.Value = Options.ScrollDelay; nudMaximumScrollCount.Value = Options.MaximumScrollCount; + cbAutoDetectScrollEnd.Checked = options.AutoDetectScrollEnd; } protected override void Dispose(bool disposing) @@ -154,6 +155,7 @@ private void StopCapture() this.ShowActivate(); tcScrollingCapture.SelectedTab = tpOutput; btnGuessEdges.Enabled = btnGuessCombineAdjustments.Enabled = btnCombine.Enabled = images.Count > 1; + RemoveLastDuplicates(); ResetCombine(); } @@ -175,6 +177,28 @@ private void Clean() } } + private void RemoveLastDuplicates() + { + if (images.Count > 1) + { + for (int i = images.Count - 1; i > 0; i--) + { + bool result = ImageHelpers.IsImagesEqual((Bitmap)images[i], (Bitmap)images[i - 1]); + + if (result) + { + Image img = images[i]; + images.Remove(img); + img.Dispose(); + } + else + { + return; + } + } + } + } + private void captureTimer_Tick(object sender, EventArgs e) { Screenshot.CaptureCursor = false; @@ -187,7 +211,7 @@ private void captureTimer_Tick(object sender, EventArgs e) currentScrollCount++; - if (currentScrollCount == Options.MaximumScrollCount || IsScrollReachedBottom(selectedWindow.Handle)) + if (currentScrollCount == Options.MaximumScrollCount || (Options.AutoDetectScrollEnd && IsScrollReachedBottom(selectedWindow.Handle))) { StopCapture(); } @@ -217,6 +241,11 @@ private void nudMaximumScrollCount_ValueChanged(object sender, EventArgs e) Options.MaximumScrollCount = (int)nudMaximumScrollCount.Value; } + private void cbAutoDetectScrollEnd_CheckedChanged(object sender, EventArgs e) + { + Options.AutoDetectScrollEnd = cbAutoDetectScrollEnd.Checked; + } + private bool IsScrollReachedBottom(IntPtr handle) { SCROLLINFO scrollInfo = new SCROLLINFO(); diff --git a/ShareX.ScreenCaptureLib/ScrollingCaptureOptions.cs b/ShareX.ScreenCaptureLib/ScrollingCaptureOptions.cs index aa45be501..f67e1accc 100644 --- a/ShareX.ScreenCaptureLib/ScrollingCaptureOptions.cs +++ b/ShareX.ScreenCaptureLib/ScrollingCaptureOptions.cs @@ -36,6 +36,7 @@ public class ScrollingCaptureOptions public ScrollingCaptureScrollMethod ScrollMethod { get; set; } = ScrollingCaptureScrollMethod.SendMessageScroll; public int ScrollDelay { get; set; } = 250; public int MaximumScrollCount { get; set; } = 20; + public bool AutoDetectScrollEnd { get; set; } = true; public int TrimLeftEdge { get; set; } = 0; public int TrimTopEdge { get; set; } = 0; public int TrimRightEdge { get; set; } = 0;