ScrollingCaptureLightForm improvements

This commit is contained in:
Jaex 2023-02-25 20:00:08 +03:00
parent fb3cdcea72
commit 45b58a1b67
2 changed files with 36 additions and 19 deletions

View file

@ -144,6 +144,14 @@ public void Activate()
} }
} }
public void BringToFront()
{
if (IsHandleCreated)
{
SetWindowPos(SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
}
}
public void Restore() public void Restore()
{ {
if (IsHandleCreated) if (IsHandleCreated)

View file

@ -30,6 +30,7 @@ You should have received a copy of the GNU General Public License
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib namespace ShareX.ScreenCaptureLib
@ -40,7 +41,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, firstCapture; private bool isCapturing, scrollTop;
private int currentScrollCount; private int currentScrollCount;
private WindowInfo selectedWindow; private WindowInfo selectedWindow;
private Rectangle selectedRectangle; private Rectangle selectedRectangle;
@ -86,7 +87,9 @@ private void StartCapture()
if (!isCapturing) if (!isCapturing)
{ {
isCapturing = true; isCapturing = true;
firstCapture = true; scrollTop = true;
// TODO: Translate
btnCapture.Text = "Stop";
WindowState = FormWindowState.Minimized; WindowState = FormWindowState.Minimized;
Reset(); Reset();
selectedWindow.Activate(); selectedWindow.Activate();
@ -96,16 +99,20 @@ private void StartCapture()
} }
} }
private void StopCapture() private async Task StopCapture()
{ {
if (isCapturing) if (isCapturing)
{ {
tCapture.Stop(); tCapture.Stop();
// TODO: Translate
btnCapture.Text = "Capture...";
btnCapture.Enabled = false;
this.ForceActivate(); this.ForceActivate();
Result = CombineImages(images); Result = await CombineImagesAsync(images);
pbOutput.Image = Result; pbOutput.Image = Result;
btnCapture.Enabled = true;
isCapturing = false; isCapturing = false;
} }
} }
@ -148,13 +155,8 @@ private void SelectWindow()
WindowState = FormWindowState.Minimized; WindowState = FormWindowState.Minimized;
Thread.Sleep(250); Thread.Sleep(250);
SimpleWindowInfo simpleWindowInfo = RegionCaptureTasks.GetWindowInfo(new RegionCaptureOptions()); if (RegionCaptureTasks.GetRectangleRegion(out selectedRectangle, out selectedWindow, new RegionCaptureOptions()))
if (simpleWindowInfo != null)
{ {
selectedWindow = new WindowInfo(simpleWindowInfo.Handle);
selectedRectangle = simpleWindowInfo.Rectangle;
StartCapture(); StartCapture();
} }
else else
@ -163,6 +165,11 @@ private void SelectWindow()
} }
} }
private async Task<Bitmap> CombineImagesAsync(List<Bitmap> images)
{
return await Task.Run(() => CombineImages(images));
}
private Bitmap CombineImages(List<Bitmap> images) private Bitmap CombineImages(List<Bitmap> images)
{ {
Bitmap result = (Bitmap)images[0].Clone(); Bitmap result = (Bitmap)images[0].Clone();
@ -253,11 +260,11 @@ private Bitmap CombineImages(List<Bitmap> images)
return result; return result;
} }
private void btnCapture_Click(object sender, EventArgs e) private async void btnCapture_Click(object sender, EventArgs e)
{ {
if (isCapturing) if (isCapturing)
{ {
StopCapture(); await StopCapture();
} }
else else
{ {
@ -270,11 +277,11 @@ private void btnOptions_Click(object sender, EventArgs e)
} }
private void tCapture_Tick(object sender, EventArgs e) private async void tCapture_Tick(object sender, EventArgs e)
{ {
if (firstCapture) if (scrollTop)
{ {
firstCapture = false; scrollTop = false;
tCapture.Interval = Options.ScrollDelay; tCapture.Interval = Options.ScrollDelay;
InputHelpers.SendKeyPress(VirtualKeyCode.HOME); InputHelpers.SendKeyPress(VirtualKeyCode.HOME);
@ -293,11 +300,13 @@ private void tCapture_Tick(object sender, EventArgs e)
if (currentScrollCount == Options.MaximumScrollCount || (Options.AutoDetectScrollEnd && IsScrollReachedBottom(selectedWindow.Handle))) if (currentScrollCount == Options.MaximumScrollCount || (Options.AutoDetectScrollEnd && IsScrollReachedBottom(selectedWindow.Handle)))
{ {
StopCapture(); await StopCapture();
}
else
{
InputHelpers.SendMouseWheel(-120 * 2);
currentScrollCount++;
} }
InputHelpers.SendMouseWheel(-120 * 2);
currentScrollCount++;
} }
} }
} }