From b6f9fbc346e0458aff756eab1bd0efadc3e9a4d8 Mon Sep 17 00:00:00 2001 From: Jaex Date: Thu, 11 Apr 2024 03:47:06 +0300 Subject: [PATCH] Added scrolling capture status indicator --- ShareX.ScreenCaptureLib/Enums.cs | 7 +++++ .../Forms/ScrollingCaptureForm.Designer.cs | 18 +++++++++++-- .../Forms/ScrollingCaptureForm.cs | 16 +++++++++++- .../Properties/Resources.Designer.cs | 24 +++++++++--------- .../Properties/Resources.resx | 10 ++++---- .../Resources/control-record-green.png | Bin 0 -> 541 bytes ShareX.ScreenCaptureLib/Resources/test_32.png | Bin 215 -> 0 bytes .../ScrollingCaptureManager.cs | 22 +++++++++++++++- 8 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 ShareX.ScreenCaptureLib/Resources/control-record-green.png delete mode 100644 ShareX.ScreenCaptureLib/Resources/test_32.png diff --git a/ShareX.ScreenCaptureLib/Enums.cs b/ShareX.ScreenCaptureLib/Enums.cs index 20a9915e9..f7121828c 100644 --- a/ShareX.ScreenCaptureLib/Enums.cs +++ b/ShareX.ScreenCaptureLib/Enums.cs @@ -364,4 +364,11 @@ public enum ScreenRecordingStatus Stopped, Aborted } + + public enum ScrollingCaptureStatus + { + Failed, + PartiallySuccessful, + Successful + } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs index 2f00fda3a..17bed4ed2 100644 --- a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs +++ b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.Designer.cs @@ -21,8 +21,10 @@ private void InitializeComponent() this.btnOptions = new System.Windows.Forms.Button(); this.btnUpload = new System.Windows.Forms.Button(); this.lblResultSize = new System.Windows.Forms.Label(); + this.pbStatus = new System.Windows.Forms.PictureBox(); this.pOutput.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pbOutput)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pbStatus)).BeginInit(); this.SuspendLayout(); // // btnCapture @@ -84,17 +86,27 @@ private void InitializeComponent() // lblResultSize // this.lblResultSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.lblResultSize.Location = new System.Drawing.Point(872, 18); + this.lblResultSize.Location = new System.Drawing.Point(848, 18); this.lblResultSize.Name = "lblResultSize"; this.lblResultSize.Size = new System.Drawing.Size(108, 24); this.lblResultSize.TabIndex = 4; - this.lblResultSize.TextAlign = System.Drawing.ContentAlignment.BottomRight; + this.lblResultSize.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // pbStatus + // + this.pbStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.pbStatus.Location = new System.Drawing.Point(959, 23); + this.pbStatus.Name = "pbStatus"; + this.pbStatus.Size = new System.Drawing.Size(16, 16); + this.pbStatus.TabIndex = 5; + this.pbStatus.TabStop = false; // // ScrollingCaptureForm // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.ClientSize = new System.Drawing.Size(984, 661); + this.Controls.Add(this.pbStatus); this.Controls.Add(this.lblResultSize); this.Controls.Add(this.btnUpload); this.Controls.Add(this.btnOptions); @@ -111,6 +123,7 @@ private void InitializeComponent() this.pOutput.ResumeLayout(false); this.pOutput.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pbOutput)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pbStatus)).EndInit(); this.ResumeLayout(false); } @@ -123,5 +136,6 @@ private void InitializeComponent() private System.Windows.Forms.Button btnOptions; private System.Windows.Forms.Button btnUpload; private System.Windows.Forms.Label lblResultSize; + private System.Windows.Forms.PictureBox pbStatus; } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs index b8ccf2406..c8cef61ba 100644 --- a/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/ScrollingCaptureForm.cs @@ -24,6 +24,7 @@ #endregion License Information (GPL v3) using ShareX.HelpersLib; +using ShareX.ScreenCaptureLib.Properties; using System; using System.Drawing; using System.Threading; @@ -121,7 +122,20 @@ private async Task StartCapture() try { - await manager.StartCapture(); + ScrollingCaptureStatus status = await manager.StartCapture(); + + switch (status) + { + case ScrollingCaptureStatus.Failed: + pbStatus.Image = Resources.control_record; + break; + case ScrollingCaptureStatus.PartiallySuccessful: + pbStatus.Image = Resources.control_record_yellow; + break; + case ScrollingCaptureStatus.Successful: + pbStatus.Image = Resources.control_record_green; + break; + } } catch (Exception e) { diff --git a/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs b/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs index 5dcad78fb..d546dad3e 100644 --- a/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs +++ b/ShareX.ScreenCaptureLib/Properties/Resources.Designer.cs @@ -239,7 +239,7 @@ internal class Resources { /// internal static System.Drawing.Bitmap control_pause { get { - object obj = ResourceManager.GetObject("control-pause", resourceCulture); + object obj = ResourceManager.GetObject("control_pause", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } @@ -254,6 +254,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap control_record_green { + get { + object obj = ResourceManager.GetObject("control_record_green", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -864,7 +874,7 @@ internal class Resources { /// internal static System.Drawing.Bitmap keyboard_enter { get { - object obj = ResourceManager.GetObject("keyboard-enter", resourceCulture); + object obj = ResourceManager.GetObject("keyboard_enter", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } @@ -2209,16 +2219,6 @@ internal class Resources { } } - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap test_32 { - get { - object obj = ResourceManager.GetObject("test_32", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - /// /// Looks up a localized string similar to This window will close before opening the keybinds web page. Do you want to continue?. /// diff --git a/ShareX.ScreenCaptureLib/Properties/Resources.resx b/ShareX.ScreenCaptureLib/Properties/Resources.resx index 1ac56b962..63d47625e 100644 --- a/ShareX.ScreenCaptureLib/Properties/Resources.resx +++ b/ShareX.ScreenCaptureLib/Properties/Resources.resx @@ -367,9 +367,6 @@ Highlight - - ..\Resources\test_32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\cross.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -569,7 +566,7 @@ Pixelate - + ..\Resources\keyboard-enter.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -810,7 +807,7 @@ X: {4} Y: {5} ..\Resources\smiley-cool.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - + ..\Resources\control-pause.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -830,4 +827,7 @@ Would you like to save the changes before closing the image editor? ..\Resources\arrow-circle-315.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\control-record-green.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/Resources/control-record-green.png b/ShareX.ScreenCaptureLib/Resources/control-record-green.png new file mode 100644 index 0000000000000000000000000000000000000000..67f9b28861f437d8a823c6ca470bc4a53ec0c16e GIT binary patch literal 541 zcmV+&0^Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0kTO%K~y+T)soFi z8&MR+&*Y8cWJtB9AYG;Drg0roaNAW2(se1x+a`Zs5_A?&(lJ_;u(8ZWF7`5ftQpgn5Yd6xbL)+z`b!cP9*xIi_`W|a*L9JE zF@H}{>Gr!JzS`Tug@Win#2O3geA%)r*tQMRGGUw>*gx3E-tRr^=sU3cqjIVfj*L7Y zWQ$3ZC|=;9Gx&>k{~SHX#3b<$$}yNK!Dm!Sb;6O62T;~C#}@6-9vs;NEAjC>;MZ3w zAR$e4!jW+`K)*0M1I+WW%-vpm7K2nL92t2)$Xflw?va$hky68de~;tX@eSuF)d@!i zR|>v4Bi2ycTvP**W(yDH8A&4~p)sY$6Vv@M{FAs*6C0Pi!jW-v6W^Dsh;G?LnQ!8U f!HrG4_W=I@oITF4#N2+=00000NkvXXu0mjfy4U)p literal 0 HcmV?d00001 diff --git a/ShareX.ScreenCaptureLib/Resources/test_32.png b/ShareX.ScreenCaptureLib/Resources/test_32.png deleted file mode 100644 index d4dd37fe18a164b9278a84fa4857a1ab29f3db63..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 215 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dh+L6~vJ#O${~LCF%=h?3y^w370~qEv>0#LT=By}Z;C1rt33JwqdBmh3k`MIoLp zjv*HQd(RkhF(~jjU*x;@|5Tv(N|R|3jt{LfD$Mxgj2B$J#h4IRB@&>pz4w5x<^hLI zmdsv42KOiL=XVI>GMJEau0e=ZnWJ6Yt~*3YBmvE5@O1TaS?83{ F1OWL&Kf?e3 diff --git a/ShareX.ScreenCaptureLib/ScrollingCaptureManager.cs b/ShareX.ScreenCaptureLib/ScrollingCaptureManager.cs index 246a1d89e..df154c44d 100644 --- a/ShareX.ScreenCaptureLib/ScrollingCaptureManager.cs +++ b/ShareX.ScreenCaptureLib/ScrollingCaptureManager.cs @@ -43,6 +43,7 @@ internal class ScrollingCaptureManager : IDisposable private Bitmap lastScreenshot; private Bitmap previousScreenshot; private bool stopRequested; + private ScrollingCaptureStatus status; private int bestMatchCount, bestMatchIndex; private WindowInfo selectedWindow; private Rectangle selectedRectangle; @@ -78,12 +79,13 @@ private void Reset(bool keepResult = false) } } - public async Task StartCapture() + public async Task StartCapture() { if (!IsCapturing && selectedWindow != null && !selectedRectangle.IsEmpty) { IsCapturing = true; stopRequested = false; + status = ScrollingCaptureStatus.Failed; bestMatchCount = 0; bestMatchIndex = 0; Reset(); @@ -175,6 +177,8 @@ public async Task StartCapture() IsCapturing = false; } } + + return status; } public void StopCapture() @@ -223,6 +227,8 @@ private Bitmap CombineImages(Bitmap result, Bitmap currentImage) { if (result == null) { + status = ScrollingCaptureStatus.Successful; + return (Bitmap)currentImage.Clone(); } @@ -273,10 +279,13 @@ private Bitmap CombineImages(Bitmap result, Bitmap currentImage) result.UnlockBits(bdResult); currentImage.UnlockBits(bdCurrentImage); + bool bestGuess = false; + if (matchCount == 0 && bestMatchCount > 0) { matchCount = bestMatchCount; matchIndex = bestMatchIndex; + bestGuess = true; } if (matchCount > 0) @@ -304,10 +313,21 @@ private Bitmap CombineImages(Bitmap result, Bitmap currentImage) new Rectangle(0, matchIndex + 1, currentImage.Width, matchHeight), GraphicsUnit.Pixel); } + if (bestGuess) + { + status = ScrollingCaptureStatus.PartiallySuccessful; + } + else if (status != ScrollingCaptureStatus.PartiallySuccessful) + { + status = ScrollingCaptureStatus.Successful; + } + return newResult; } } + status = ScrollingCaptureStatus.Failed; + return null; } }