mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-05 20:54:31 +13:00
Screen region form will show countdown if recording have duration
This commit is contained in:
parent
75357db19b
commit
cdcef959c4
2 changed files with 44 additions and 15 deletions
|
@ -160,7 +160,8 @@ public void StartRecording(TaskSettings TaskSettings)
|
|||
|
||||
string path = "";
|
||||
|
||||
regionForm = ScreenRegionForm.Start(captureRectangle, StopRecording);
|
||||
float duration = TaskSettings.CaptureSettings.ScreenRecordFixedDuration ? TaskSettings.CaptureSettings.ScreenRecordDuration : 0;
|
||||
regionForm = ScreenRegionForm.Show(captureRectangle, StopRecording, duration);
|
||||
|
||||
TaskEx.Run(() =>
|
||||
{
|
||||
|
@ -185,7 +186,7 @@ public void StartRecording(TaskSettings TaskSettings)
|
|||
AVI = TaskSettings.CaptureSettings.AVIOptions,
|
||||
ScreenRecordFPS = TaskSettings.CaptureSettings.ScreenRecordFPS,
|
||||
GIFFPS = TaskSettings.CaptureSettings.GIFFPS,
|
||||
Duration = TaskSettings.CaptureSettings.ScreenRecordFixedDuration ? TaskSettings.CaptureSettings.ScreenRecordDuration : 0,
|
||||
Duration = duration,
|
||||
OutputPath = path,
|
||||
CaptureArea = captureRectangle,
|
||||
DrawCursor = TaskSettings.CaptureSettings.ShowCursor
|
||||
|
@ -200,14 +201,14 @@ public void StartRecording(TaskSettings TaskSettings)
|
|||
Thread.Sleep(delay);
|
||||
}
|
||||
|
||||
TrayIcon.Text = "ShareX - Click tray icon to stop recording.";
|
||||
TrayIcon.Icon = Resources.control_record.ToIcon();
|
||||
|
||||
if (regionForm != null)
|
||||
{
|
||||
this.InvokeSafe(() => regionForm.StartTimer());
|
||||
}
|
||||
|
||||
TrayIcon.Text = "ShareX - Click tray icon to stop recording.";
|
||||
TrayIcon.Icon = Resources.control_record.ToIcon();
|
||||
|
||||
screenRecorder.StartRecording();
|
||||
}
|
||||
finally
|
||||
|
|
|
@ -35,10 +35,13 @@ public partial class ScreenRegionForm : Form
|
|||
{
|
||||
public event Action StopRequested;
|
||||
|
||||
private Color color = Color.Red;
|
||||
public bool IsCountdown { get; set; }
|
||||
public TimeSpan Countdown { get; set; }
|
||||
public Stopwatch Timer { get; private set; }
|
||||
|
||||
private Color borderColor = Color.Red;
|
||||
private Rectangle borderRectangle;
|
||||
private Rectangle borderRectangle0Based;
|
||||
private Stopwatch Timer;
|
||||
|
||||
public ScreenRegionForm(Rectangle regionRectangle)
|
||||
{
|
||||
|
@ -55,6 +58,8 @@ public ScreenRegionForm(Rectangle regionRectangle)
|
|||
region.Exclude(borderRectangle0Based.RectangleOffset(-1));
|
||||
region.Exclude(new Rectangle(0, pInfo.Location.Y, pInfo.Location.X, pInfo.Height));
|
||||
Region = region;
|
||||
|
||||
Timer = new Stopwatch();
|
||||
}
|
||||
|
||||
protected void OnStopRequested()
|
||||
|
@ -65,12 +70,18 @@ protected void OnStopRequested()
|
|||
}
|
||||
}
|
||||
|
||||
public static ScreenRegionForm Start(Rectangle captureRectangle, Action stopRequested)
|
||||
public static ScreenRegionForm Show(Rectangle captureRectangle, Action stopRequested, float duration = 0)
|
||||
{
|
||||
if (captureRectangle != CaptureHelpers.GetScreenBounds())
|
||||
{
|
||||
ScreenRegionForm regionForm = new ScreenRegionForm(captureRectangle);
|
||||
regionForm.StopRequested += stopRequested;
|
||||
if (duration > 0)
|
||||
{
|
||||
regionForm.IsCountdown = true;
|
||||
regionForm.Countdown = TimeSpan.FromSeconds(duration);
|
||||
}
|
||||
regionForm.UpdateTimer();
|
||||
regionForm.Show();
|
||||
return regionForm;
|
||||
}
|
||||
|
@ -80,17 +91,37 @@ public static ScreenRegionForm Start(Rectangle captureRectangle, Action stopRequ
|
|||
|
||||
public void StartTimer()
|
||||
{
|
||||
this.color = Color.FromArgb(0, 255, 0);
|
||||
borderColor = Color.FromArgb(0, 255, 0);
|
||||
Refresh();
|
||||
|
||||
Timer = Stopwatch.StartNew();
|
||||
Timer.Start();
|
||||
timerRefresh.Start();
|
||||
}
|
||||
|
||||
private void UpdateTimer()
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
TimeSpan timer;
|
||||
|
||||
if (IsCountdown)
|
||||
{
|
||||
timer = Countdown - Timer.Elapsed;
|
||||
if (timer.Ticks < 0) timer = TimeSpan.Zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
timer = Timer.Elapsed;
|
||||
}
|
||||
|
||||
lblTimer.Text = timer.ToString("mm\\:ss\\:ff");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
using (Pen pen1 = new Pen(Color.Black) { DashPattern = new float[] { 5, 5 } })
|
||||
using (Pen pen2 = new Pen(color) { DashPattern = new float[] { 5, 5 }, DashOffset = 5 })
|
||||
using (Pen pen2 = new Pen(borderColor) { DashPattern = new float[] { 5, 5 }, DashOffset = 5 })
|
||||
{
|
||||
e.Graphics.DrawRectangleProper(pen1, borderRectangle0Based);
|
||||
e.Graphics.DrawRectangleProper(pen2, borderRectangle0Based);
|
||||
|
@ -101,10 +132,7 @@ protected override void OnPaint(PaintEventArgs e)
|
|||
|
||||
private void timerRefresh_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
lblTimer.Text = Timer.Elapsed.ToString("mm\\:ss\\:ff");
|
||||
}
|
||||
UpdateTimer();
|
||||
}
|
||||
|
||||
private void btnStop_Click(object sender, EventArgs e)
|
||||
|
|
Loading…
Reference in a new issue