mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
ScrollingCaptureLightForm improvements
This commit is contained in:
parent
a1f881032b
commit
f2e412e46f
3 changed files with 58 additions and 70 deletions
|
@ -15,11 +15,9 @@ partial class ScrollingCaptureLightForm
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.btnCapture = new System.Windows.Forms.Button();
|
this.btnCapture = new System.Windows.Forms.Button();
|
||||||
this.pOutput = new System.Windows.Forms.Panel();
|
this.pOutput = new System.Windows.Forms.Panel();
|
||||||
this.pbOutput = new System.Windows.Forms.PictureBox();
|
this.pbOutput = new System.Windows.Forms.PictureBox();
|
||||||
this.tCapture = new System.Windows.Forms.Timer(this.components);
|
|
||||||
this.btnOptions = new System.Windows.Forms.Button();
|
this.btnOptions = new System.Windows.Forms.Button();
|
||||||
this.btnUpload = new System.Windows.Forms.Button();
|
this.btnUpload = new System.Windows.Forms.Button();
|
||||||
this.pOutput.SuspendLayout();
|
this.pOutput.SuspendLayout();
|
||||||
|
@ -61,10 +59,6 @@ private void InitializeComponent()
|
||||||
this.pbOutput.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pbOutput_MouseMove);
|
this.pbOutput.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pbOutput_MouseMove);
|
||||||
this.pbOutput.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pbOutput_MouseUp);
|
this.pbOutput.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pbOutput_MouseUp);
|
||||||
//
|
//
|
||||||
// tCapture
|
|
||||||
//
|
|
||||||
this.tCapture.Tick += new System.EventHandler(this.tCapture_Tick);
|
|
||||||
//
|
|
||||||
// btnOptions
|
// btnOptions
|
||||||
//
|
//
|
||||||
this.btnOptions.Location = new System.Drawing.Point(344, 8);
|
this.btnOptions.Location = new System.Drawing.Point(344, 8);
|
||||||
|
@ -100,6 +94,7 @@ private void InitializeComponent()
|
||||||
this.Name = "ScrollingCaptureLightForm";
|
this.Name = "ScrollingCaptureLightForm";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "ShareX - Scrolling capture";
|
this.Text = "ShareX - Scrolling capture";
|
||||||
|
this.Load += new System.EventHandler(this.ScrollingCaptureLightForm_Load);
|
||||||
this.pOutput.ResumeLayout(false);
|
this.pOutput.ResumeLayout(false);
|
||||||
this.pOutput.PerformLayout();
|
this.pOutput.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbOutput)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbOutput)).EndInit();
|
||||||
|
@ -112,7 +107,6 @@ private void InitializeComponent()
|
||||||
private System.Windows.Forms.Button btnCapture;
|
private System.Windows.Forms.Button btnCapture;
|
||||||
private System.Windows.Forms.Panel pOutput;
|
private System.Windows.Forms.Panel pOutput;
|
||||||
private System.Windows.Forms.PictureBox pbOutput;
|
private System.Windows.Forms.PictureBox pbOutput;
|
||||||
private System.Windows.Forms.Timer tCapture;
|
|
||||||
private System.Windows.Forms.Button btnOptions;
|
private System.Windows.Forms.Button btnOptions;
|
||||||
private System.Windows.Forms.Button btnUpload;
|
private System.Windows.Forms.Button btnUpload;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public partial class ScrollingCaptureLightForm : Form
|
||||||
public Bitmap Result { get; private set; }
|
public Bitmap Result { get; private set; }
|
||||||
|
|
||||||
private List<Bitmap> images = new List<Bitmap>();
|
private List<Bitmap> images = new List<Bitmap>();
|
||||||
private bool isCapturing, scrollTop;
|
private bool isCapturing, stopRequested;
|
||||||
private int currentScrollCount, bestMatchCount, bestMatchIndex;
|
private int currentScrollCount, bestMatchCount, bestMatchIndex;
|
||||||
private WindowInfo selectedWindow;
|
private WindowInfo selectedWindow;
|
||||||
private Rectangle selectedRectangle;
|
private Rectangle selectedRectangle;
|
||||||
|
@ -55,18 +55,13 @@ public ScrollingCaptureLightForm(ScrollingCaptureOptions options)
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ShareXResources.ApplyTheme(this);
|
ShareXResources.ApplyTheme(this);
|
||||||
|
|
||||||
SelectWindow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (components != null)
|
components?.Dispose();
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
@ -105,12 +100,12 @@ private void ResetPictureBox()
|
||||||
temp?.Dispose();
|
temp?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartCapture()
|
private async Task StartCapture()
|
||||||
{
|
{
|
||||||
if (!isCapturing)
|
if (!isCapturing)
|
||||||
{
|
{
|
||||||
isCapturing = true;
|
isCapturing = true;
|
||||||
scrollTop = true;
|
stopRequested = false;
|
||||||
bestMatchCount = 0;
|
bestMatchCount = 0;
|
||||||
bestMatchIndex = 0;
|
bestMatchIndex = 0;
|
||||||
|
|
||||||
|
@ -120,25 +115,59 @@ private void StartCapture()
|
||||||
Reset();
|
Reset();
|
||||||
selectedWindow.Activate();
|
selectedWindow.Activate();
|
||||||
|
|
||||||
tCapture.Interval = Options.StartDelay;
|
await Task.Delay(Options.StartDelay);
|
||||||
tCapture.Start();
|
await CaptureJob();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StopCapture()
|
private void StopCapture()
|
||||||
{
|
{
|
||||||
if (isCapturing)
|
stopRequested = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EndCapture()
|
||||||
|
{
|
||||||
|
// TODO: Translate
|
||||||
|
btnCapture.Text = "Capture...";
|
||||||
|
btnUpload.Enabled = Result != null;
|
||||||
|
pbOutput.Image = Result;
|
||||||
|
this.ForceActivate();
|
||||||
|
|
||||||
|
isCapturing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task CaptureJob()
|
||||||
|
{
|
||||||
|
InputHelpers.SendKeyPress(VirtualKeyCode.HOME);
|
||||||
|
NativeMethods.SendMessage(selectedWindow.Handle, (int)WindowsMessages.VSCROLL, (int)ScrollBarCommands.SB_TOP, 0);
|
||||||
|
|
||||||
|
do
|
||||||
{
|
{
|
||||||
tCapture.Stop();
|
await Task.Delay(Options.ScrollDelay);
|
||||||
|
|
||||||
// TODO: Translate
|
Screenshot screenshot = new Screenshot()
|
||||||
btnCapture.Text = "Capture...";
|
{
|
||||||
btnUpload.Enabled = Result != null;
|
CaptureCursor = false
|
||||||
pbOutput.Image = Result;
|
};
|
||||||
this.ForceActivate();
|
|
||||||
|
|
||||||
isCapturing = false;
|
Bitmap bmp = screenshot.CaptureRectangle(selectedRectangle);
|
||||||
|
|
||||||
|
if (bmp != null)
|
||||||
|
{
|
||||||
|
images.Add(bmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
InputHelpers.SendMouseWheel(-120 * 2);
|
||||||
|
currentScrollCount++;
|
||||||
|
|
||||||
|
if (images.Count > 0)
|
||||||
|
{
|
||||||
|
Result = await CombineImagesAsync(Result, images[images.Count - 1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while (!stopRequested && currentScrollCount <= Options.MaximumScrollCount && !IsScrollReachedBottom(selectedWindow.Handle));
|
||||||
|
|
||||||
|
EndCapture();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsScrollReachedBottom(IntPtr handle)
|
private bool IsScrollReachedBottom(IntPtr handle)
|
||||||
|
@ -174,14 +203,14 @@ private bool IsLastTwoImagesSame()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SelectWindow()
|
private async Task SelectWindow()
|
||||||
{
|
{
|
||||||
WindowState = FormWindowState.Minimized;
|
WindowState = FormWindowState.Minimized;
|
||||||
Thread.Sleep(250);
|
Thread.Sleep(250);
|
||||||
|
|
||||||
if (RegionCaptureTasks.GetRectangleRegion(out selectedRectangle, out selectedWindow, new RegionCaptureOptions()))
|
if (RegionCaptureTasks.GetRectangleRegion(out selectedRectangle, out selectedWindow, new RegionCaptureOptions()))
|
||||||
{
|
{
|
||||||
StartCapture();
|
await StartCapture();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -297,7 +326,12 @@ protected void OnUploadRequested(Bitmap bmp)
|
||||||
UploadRequested?.Invoke(bmp);
|
UploadRequested?.Invoke(bmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnCapture_Click(object sender, EventArgs e)
|
private async void ScrollingCaptureLightForm_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await SelectWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void btnCapture_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (isCapturing)
|
if (isCapturing)
|
||||||
{
|
{
|
||||||
|
@ -305,7 +339,7 @@ private void btnCapture_Click(object sender, EventArgs e)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SelectWindow();
|
await SelectWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,42 +379,5 @@ private void pbOutput_MouseUp(object sender, MouseEventArgs e)
|
||||||
pOutput.Cursor = Cursors.Default;
|
pOutput.Cursor = Cursors.Default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void tCapture_Tick(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (scrollTop)
|
|
||||||
{
|
|
||||||
scrollTop = false;
|
|
||||||
tCapture.Interval = Options.ScrollDelay;
|
|
||||||
|
|
||||||
InputHelpers.SendKeyPress(VirtualKeyCode.HOME);
|
|
||||||
NativeMethods.SendMessage(selectedWindow.Handle, (int)WindowsMessages.VSCROLL, (int)ScrollBarCommands.SB_TOP, 0);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Screenshot screenshot = new Screenshot() { CaptureCursor = false };
|
|
||||||
Bitmap bmp = screenshot.CaptureRectangle(selectedRectangle);
|
|
||||||
|
|
||||||
if (bmp != null)
|
|
||||||
{
|
|
||||||
images.Add(bmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (images.Count > 0)
|
|
||||||
{
|
|
||||||
Result = await CombineImagesAsync(Result, images[images.Count - 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentScrollCount == Options.MaximumScrollCount || (Options.AutoDetectScrollEnd && IsScrollReachedBottom(selectedWindow.Handle)))
|
|
||||||
{
|
|
||||||
StopCapture();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
InputHelpers.SendMouseWheel(-120 * 2);
|
|
||||||
currentScrollCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -117,9 +117,6 @@
|
||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<metadata name="tCapture.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>17, 17</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>59</value>
|
<value>59</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|
Loading…
Reference in a new issue