mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Added StartSelectionAutomatically, StartCaptureAutomatically, ScrollTopBeforeCapture options to scrolling capture
This commit is contained in:
parent
9a4a64e10f
commit
1dbab850b5
5 changed files with 118 additions and 47 deletions
|
@ -149,8 +149,13 @@ public enum RegionShape
|
|||
|
||||
public enum ScrollingCaptureScrollMethod
|
||||
{
|
||||
[Description("Automatically try all methods until one works")]
|
||||
Automatic,
|
||||
[Description("Send scroll message to window or control")]
|
||||
SendMessageScroll,
|
||||
[Description("Simulate pressing \"Page down\" key")]
|
||||
KeyPressPageDown,
|
||||
[Description("Simulate mouse wheel scrolling")]
|
||||
MouseWheel
|
||||
}
|
||||
}
|
|
@ -33,6 +33,10 @@ 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.cbScrollTopBeforeCapture = new System.Windows.Forms.CheckBox();
|
||||
this.cbStartCaptureAutomatically = new System.Windows.Forms.CheckBox();
|
||||
this.cbRemoveDuplicates = new System.Windows.Forms.CheckBox();
|
||||
this.cbAutoDetectScrollEnd = new System.Windows.Forms.CheckBox();
|
||||
this.lblScrollMethod = new System.Windows.Forms.Label();
|
||||
this.cbScrollMethod = new System.Windows.Forms.ComboBox();
|
||||
this.tpOutput = new System.Windows.Forms.TabPage();
|
||||
|
@ -57,8 +61,6 @@ 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.cbAutoDetectScrollEnd = new System.Windows.Forms.CheckBox();
|
||||
this.cbRemoveDuplicates = new System.Windows.Forms.CheckBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nudScrollDelay)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nudMaximumScrollCount)).BeginInit();
|
||||
this.tcScrollingCapture.SuspendLayout();
|
||||
|
@ -97,7 +99,7 @@ private void InitializeComponent()
|
|||
// btnCapture
|
||||
//
|
||||
this.btnCapture.Enabled = false;
|
||||
this.btnCapture.Location = new System.Drawing.Point(16, 168);
|
||||
this.btnCapture.Location = new System.Drawing.Point(16, 216);
|
||||
this.btnCapture.Name = "btnCapture";
|
||||
this.btnCapture.Size = new System.Drawing.Size(152, 23);
|
||||
this.btnCapture.TabIndex = 2;
|
||||
|
@ -163,6 +165,8 @@ private void InitializeComponent()
|
|||
//
|
||||
// tpCapture
|
||||
//
|
||||
this.tpCapture.Controls.Add(this.cbScrollTopBeforeCapture);
|
||||
this.tpCapture.Controls.Add(this.cbStartCaptureAutomatically);
|
||||
this.tpCapture.Controls.Add(this.cbRemoveDuplicates);
|
||||
this.tpCapture.Controls.Add(this.cbAutoDetectScrollEnd);
|
||||
this.tpCapture.Controls.Add(this.lblScrollMethod);
|
||||
|
@ -182,6 +186,50 @@ private void InitializeComponent()
|
|||
this.tpCapture.Text = "Capture";
|
||||
this.tpCapture.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// cbScrollTopBeforeCapture
|
||||
//
|
||||
this.cbScrollTopBeforeCapture.AutoSize = true;
|
||||
this.cbScrollTopBeforeCapture.Location = new System.Drawing.Point(16, 144);
|
||||
this.cbScrollTopBeforeCapture.Name = "cbScrollTopBeforeCapture";
|
||||
this.cbScrollTopBeforeCapture.Size = new System.Drawing.Size(223, 17);
|
||||
this.cbScrollTopBeforeCapture.TabIndex = 12;
|
||||
this.cbScrollTopBeforeCapture.Text = "Attempt scrolling to the top before capture";
|
||||
this.cbScrollTopBeforeCapture.UseVisualStyleBackColor = true;
|
||||
this.cbScrollTopBeforeCapture.CheckedChanged += new System.EventHandler(this.cbScrollTopBeforeCapture_CheckedChanged);
|
||||
//
|
||||
// cbStartCaptureAutomatically
|
||||
//
|
||||
this.cbStartCaptureAutomatically.AutoSize = true;
|
||||
this.cbStartCaptureAutomatically.Location = new System.Drawing.Point(16, 120);
|
||||
this.cbStartCaptureAutomatically.Name = "cbStartCaptureAutomatically";
|
||||
this.cbStartCaptureAutomatically.Size = new System.Drawing.Size(213, 17);
|
||||
this.cbStartCaptureAutomatically.TabIndex = 11;
|
||||
this.cbStartCaptureAutomatically.Text = "Start capture immediately after selection";
|
||||
this.cbStartCaptureAutomatically.UseVisualStyleBackColor = true;
|
||||
this.cbStartCaptureAutomatically.CheckedChanged += new System.EventHandler(this.cbStartCaptureAutomatically_CheckedChanged);
|
||||
//
|
||||
// cbRemoveDuplicates
|
||||
//
|
||||
this.cbRemoveDuplicates.AutoSize = true;
|
||||
this.cbRemoveDuplicates.Location = new System.Drawing.Point(16, 192);
|
||||
this.cbRemoveDuplicates.Name = "cbRemoveDuplicates";
|
||||
this.cbRemoveDuplicates.Size = new System.Drawing.Size(117, 17);
|
||||
this.cbRemoveDuplicates.TabIndex = 10;
|
||||
this.cbRemoveDuplicates.Text = "Remove duplicates";
|
||||
this.cbRemoveDuplicates.UseVisualStyleBackColor = true;
|
||||
this.cbRemoveDuplicates.CheckedChanged += new System.EventHandler(this.cbRemoveDuplicates_CheckedChanged);
|
||||
//
|
||||
// cbAutoDetectScrollEnd
|
||||
//
|
||||
this.cbAutoDetectScrollEnd.AutoSize = true;
|
||||
this.cbAutoDetectScrollEnd.Location = new System.Drawing.Point(16, 168);
|
||||
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);
|
||||
//
|
||||
// lblScrollMethod
|
||||
//
|
||||
this.lblScrollMethod.AutoSize = true;
|
||||
|
@ -197,7 +245,7 @@ private void InitializeComponent()
|
|||
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.Size = new System.Drawing.Size(312, 21);
|
||||
this.cbScrollMethod.TabIndex = 7;
|
||||
this.cbScrollMethod.SelectedIndexChanged += new System.EventHandler(this.cbScrollMethod_SelectedIndexChanged);
|
||||
//
|
||||
|
@ -461,28 +509,6 @@ private void InitializeComponent()
|
|||
this.pbOutput.TabIndex = 0;
|
||||
this.pbOutput.TabStop = false;
|
||||
//
|
||||
// cbAutoDetectScrollEnd
|
||||
//
|
||||
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);
|
||||
//
|
||||
// cbRemoveDuplicates
|
||||
//
|
||||
this.cbRemoveDuplicates.AutoSize = true;
|
||||
this.cbRemoveDuplicates.Location = new System.Drawing.Point(16, 144);
|
||||
this.cbRemoveDuplicates.Name = "cbRemoveDuplicates";
|
||||
this.cbRemoveDuplicates.Size = new System.Drawing.Size(117, 17);
|
||||
this.cbRemoveDuplicates.TabIndex = 10;
|
||||
this.cbRemoveDuplicates.Text = "Remove duplicates";
|
||||
this.cbRemoveDuplicates.UseVisualStyleBackColor = true;
|
||||
this.cbRemoveDuplicates.CheckedChanged += new System.EventHandler(this.cbRemoveDuplicates_CheckedChanged);
|
||||
//
|
||||
// ScrollingCaptureForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
@ -553,5 +579,7 @@ private void InitializeComponent()
|
|||
private ComboBox cbScrollMethod;
|
||||
private CheckBox cbAutoDetectScrollEnd;
|
||||
private CheckBox cbRemoveDuplicates;
|
||||
private CheckBox cbStartCaptureAutomatically;
|
||||
private CheckBox cbScrollTopBeforeCapture;
|
||||
}
|
||||
}
|
|
@ -49,20 +49,28 @@ public partial class ScrollingCaptureForm : BaseForm
|
|||
private List<Image> images = new List<Image>();
|
||||
private int currentScrollCount;
|
||||
private bool isBusy;
|
||||
private bool firstCapture;
|
||||
|
||||
public ScrollingCaptureForm(ScrollingCaptureOptions options, bool startSelection = false)
|
||||
public ScrollingCaptureForm(ScrollingCaptureOptions options)
|
||||
{
|
||||
Options = options;
|
||||
InitializeComponent();
|
||||
cbScrollMethod.Items.AddRange(Enum.GetNames(typeof(ScrollingCaptureScrollMethod)));
|
||||
cbScrollMethod.Items.AddRange(Helpers.GetEnumDescriptions<ScrollingCaptureScrollMethod>());
|
||||
cbScrollMethod.SelectedIndex = (int)Options.ScrollMethod;
|
||||
nudScrollDelay.Value = Options.ScrollDelay;
|
||||
nudMaximumScrollCount.Value = Options.MaximumScrollCount;
|
||||
cbStartCaptureAutomatically.Checked = Options.StartCaptureAutomatically;
|
||||
cbScrollTopBeforeCapture.Checked = Options.ScrollTopBeforeCapture;
|
||||
cbAutoDetectScrollEnd.Checked = Options.AutoDetectScrollEnd;
|
||||
cbRemoveDuplicates.Checked = Options.RemoveDuplicates;
|
||||
|
||||
if (startSelection)
|
||||
if (Options.StartSelectionAutomatically)
|
||||
{
|
||||
if (Options.StartCaptureAutomatically)
|
||||
{
|
||||
WindowState = FormWindowState.Minimized;
|
||||
}
|
||||
|
||||
SelectHandle();
|
||||
}
|
||||
}
|
||||
|
@ -92,33 +100,38 @@ protected void OnProcessRequested(Image image)
|
|||
|
||||
private void btnSelectHandle_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectHandle(true);
|
||||
SelectHandle();
|
||||
}
|
||||
|
||||
private void SelectHandle(bool hideForm = false)
|
||||
private void SelectHandle()
|
||||
{
|
||||
if (hideForm) Hide();
|
||||
WindowState = FormWindowState.Minimized;
|
||||
SimpleWindowInfo simpleWindowInfo;
|
||||
|
||||
try
|
||||
{
|
||||
Thread.Sleep(250);
|
||||
simpleWindowInfo = GetWindowInfo();
|
||||
|
||||
if (simpleWindowInfo != null)
|
||||
{
|
||||
selectedWindow = new WindowInfo(simpleWindowInfo.Handle);
|
||||
lblControlText.Text = selectedWindow.ClassName ?? string.Empty;
|
||||
btnCapture.Enabled = true;
|
||||
|
||||
if (Options.StartCaptureAutomatically)
|
||||
{
|
||||
StartCapture();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
btnCapture.Enabled = false;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (hideForm) Show();
|
||||
}
|
||||
|
||||
if (simpleWindowInfo != null)
|
||||
{
|
||||
selectedWindow = new WindowInfo(simpleWindowInfo.Handle);
|
||||
lblControlText.Text = selectedWindow.ClassName ?? String.Empty;
|
||||
btnCapture.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
btnCapture.Enabled = false;
|
||||
if (!Options.StartCaptureAutomatically) this.ShowActivate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,7 +165,9 @@ private SimpleWindowInfo GetWindowInfo()
|
|||
|
||||
private void StartCapture()
|
||||
{
|
||||
WindowState = FormWindowState.Minimized;
|
||||
btnCapture.Enabled = false;
|
||||
firstCapture = true;
|
||||
Clean();
|
||||
selectedWindow.Activate();
|
||||
captureTimer.Interval = Options.ScrollDelay;
|
||||
|
@ -208,6 +223,13 @@ private void RemoveDuplicates()
|
|||
|
||||
private void captureTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (Options.ScrollTopBeforeCapture && firstCapture)
|
||||
{
|
||||
firstCapture = false;
|
||||
InputHelpers.SendKeyPress(VirtualKeyCode.HOME);
|
||||
Thread.Sleep(Options.ScrollDelay);
|
||||
}
|
||||
|
||||
Screenshot.CaptureCursor = false;
|
||||
Image image = Screenshot.CaptureRectangle(selectedWindow.Rectangle);
|
||||
|
||||
|
@ -225,6 +247,7 @@ private void captureTimer_Tick(object sender, EventArgs e)
|
|||
|
||||
switch (Options.ScrollMethod)
|
||||
{
|
||||
case ScrollingCaptureScrollMethod.Automatic:
|
||||
case ScrollingCaptureScrollMethod.SendMessageScroll:
|
||||
NativeMethods.SendMessage(selectedWindow.Handle, (int)WindowsMessages.VSCROLL, (int)ScrollBarCommands.SB_PAGEDOWN, 0);
|
||||
break;
|
||||
|
@ -253,6 +276,16 @@ private void nudMaximumScrollCount_ValueChanged(object sender, EventArgs e)
|
|||
Options.MaximumScrollCount = (int)nudMaximumScrollCount.Value;
|
||||
}
|
||||
|
||||
private void cbStartCaptureAutomatically_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Options.StartCaptureAutomatically = cbStartCaptureAutomatically.Checked;
|
||||
}
|
||||
|
||||
private void cbScrollTopBeforeCapture_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Options.ScrollTopBeforeCapture = cbScrollTopBeforeCapture.Checked;
|
||||
}
|
||||
|
||||
private void cbAutoDetectScrollEnd_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Options.AutoDetectScrollEnd = cbAutoDetectScrollEnd.Checked;
|
||||
|
@ -355,6 +388,7 @@ private void btnResetCombine_Click(object sender, EventArgs e)
|
|||
private void ResetCombine()
|
||||
{
|
||||
nudTrimLeft.Value = nudTrimTop.Value = nudTrimRight.Value = nudTrimBottom.Value = nudCombineVertical.Value = nudCombineLastVertical.Value = 0;
|
||||
Options.TrimLeftEdge = Options.TrimTopEdge = Options.TrimRightEdge = Options.TrimBottomEdge = Options.CombineAdjustmentVertical = Options.CombineAdjustmentLastVertical = 0;
|
||||
CombineAndPreviewImages();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,11 +33,15 @@ namespace ShareX
|
|||
{
|
||||
public class ScrollingCaptureOptions
|
||||
{
|
||||
public ScrollingCaptureScrollMethod ScrollMethod { get; set; } = ScrollingCaptureScrollMethod.SendMessageScroll;
|
||||
public ScrollingCaptureScrollMethod ScrollMethod { get; set; } = ScrollingCaptureScrollMethod.Automatic;
|
||||
public int ScrollDelay { get; set; } = 250;
|
||||
public int MaximumScrollCount { get; set; } = 20;
|
||||
public bool StartSelectionAutomatically { get; set; } = true;
|
||||
public bool StartCaptureAutomatically { get; set; } = false;
|
||||
public bool ScrollTopBeforeCapture { get; set; } = true;
|
||||
public bool AutoDetectScrollEnd { get; set; } = true;
|
||||
public bool RemoveDuplicates { get; set; } = true;
|
||||
|
||||
public int TrimLeftEdge { get; set; } = 0;
|
||||
public int TrimTopEdge { get; set; } = 0;
|
||||
public int TrimRightEdge { get; set; } = 0;
|
||||
|
|
|
@ -494,9 +494,9 @@ public static void OpenScrollingCapture(TaskSettings taskSettings = null)
|
|||
{
|
||||
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||
|
||||
ScrollingCaptureForm scrollingCaptureForm = new ScrollingCaptureForm(taskSettings.CaptureSettingsReference.ScrollingCaptureOptions, true);
|
||||
ScrollingCaptureForm scrollingCaptureForm = new ScrollingCaptureForm(taskSettings.CaptureSettingsReference.ScrollingCaptureOptions);
|
||||
scrollingCaptureForm.ProcessRequested += image => UploadManager.RunImageTask(image, taskSettings);
|
||||
scrollingCaptureForm.ShowActivate();
|
||||
scrollingCaptureForm.Show();
|
||||
}
|
||||
|
||||
public static void OpenAutoCapture()
|
||||
|
|
Loading…
Reference in a new issue