Screen region form will show countdown if recording have duration

This commit is contained in:
Jaex 2014-06-23 04:44:36 +03:00
parent 75357db19b
commit cdcef959c4
2 changed files with 44 additions and 15 deletions

View file

@ -160,7 +160,8 @@ public void StartRecording(TaskSettings TaskSettings)
string path = ""; string path = "";
regionForm = ScreenRegionForm.Start(captureRectangle, StopRecording); float duration = TaskSettings.CaptureSettings.ScreenRecordFixedDuration ? TaskSettings.CaptureSettings.ScreenRecordDuration : 0;
regionForm = ScreenRegionForm.Show(captureRectangle, StopRecording, duration);
TaskEx.Run(() => TaskEx.Run(() =>
{ {
@ -185,7 +186,7 @@ public void StartRecording(TaskSettings TaskSettings)
AVI = TaskSettings.CaptureSettings.AVIOptions, AVI = TaskSettings.CaptureSettings.AVIOptions,
ScreenRecordFPS = TaskSettings.CaptureSettings.ScreenRecordFPS, ScreenRecordFPS = TaskSettings.CaptureSettings.ScreenRecordFPS,
GIFFPS = TaskSettings.CaptureSettings.GIFFPS, GIFFPS = TaskSettings.CaptureSettings.GIFFPS,
Duration = TaskSettings.CaptureSettings.ScreenRecordFixedDuration ? TaskSettings.CaptureSettings.ScreenRecordDuration : 0, Duration = duration,
OutputPath = path, OutputPath = path,
CaptureArea = captureRectangle, CaptureArea = captureRectangle,
DrawCursor = TaskSettings.CaptureSettings.ShowCursor DrawCursor = TaskSettings.CaptureSettings.ShowCursor
@ -200,14 +201,14 @@ public void StartRecording(TaskSettings TaskSettings)
Thread.Sleep(delay); Thread.Sleep(delay);
} }
TrayIcon.Text = "ShareX - Click tray icon to stop recording.";
TrayIcon.Icon = Resources.control_record.ToIcon();
if (regionForm != null) if (regionForm != null)
{ {
this.InvokeSafe(() => regionForm.StartTimer()); this.InvokeSafe(() => regionForm.StartTimer());
} }
TrayIcon.Text = "ShareX - Click tray icon to stop recording.";
TrayIcon.Icon = Resources.control_record.ToIcon();
screenRecorder.StartRecording(); screenRecorder.StartRecording();
} }
finally finally

View file

@ -35,10 +35,13 @@ public partial class ScreenRegionForm : Form
{ {
public event Action StopRequested; 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 borderRectangle;
private Rectangle borderRectangle0Based; private Rectangle borderRectangle0Based;
private Stopwatch Timer;
public ScreenRegionForm(Rectangle regionRectangle) public ScreenRegionForm(Rectangle regionRectangle)
{ {
@ -55,6 +58,8 @@ public ScreenRegionForm(Rectangle regionRectangle)
region.Exclude(borderRectangle0Based.RectangleOffset(-1)); region.Exclude(borderRectangle0Based.RectangleOffset(-1));
region.Exclude(new Rectangle(0, pInfo.Location.Y, pInfo.Location.X, pInfo.Height)); region.Exclude(new Rectangle(0, pInfo.Location.Y, pInfo.Location.X, pInfo.Height));
Region = region; Region = region;
Timer = new Stopwatch();
} }
protected void OnStopRequested() 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()) if (captureRectangle != CaptureHelpers.GetScreenBounds())
{ {
ScreenRegionForm regionForm = new ScreenRegionForm(captureRectangle); ScreenRegionForm regionForm = new ScreenRegionForm(captureRectangle);
regionForm.StopRequested += stopRequested; regionForm.StopRequested += stopRequested;
if (duration > 0)
{
regionForm.IsCountdown = true;
regionForm.Countdown = TimeSpan.FromSeconds(duration);
}
regionForm.UpdateTimer();
regionForm.Show(); regionForm.Show();
return regionForm; return regionForm;
} }
@ -80,17 +91,37 @@ public static ScreenRegionForm Start(Rectangle captureRectangle, Action stopRequ
public void StartTimer() public void StartTimer()
{ {
this.color = Color.FromArgb(0, 255, 0); borderColor = Color.FromArgb(0, 255, 0);
Refresh(); Refresh();
Timer = Stopwatch.StartNew(); Timer.Start();
timerRefresh.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) protected override void OnPaint(PaintEventArgs e)
{ {
using (Pen pen1 = new Pen(Color.Black) { DashPattern = new float[] { 5, 5 } }) 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(pen1, borderRectangle0Based);
e.Graphics.DrawRectangleProper(pen2, borderRectangle0Based); e.Graphics.DrawRectangleProper(pen2, borderRectangle0Based);
@ -101,10 +132,7 @@ protected override void OnPaint(PaintEventArgs e)
private void timerRefresh_Tick(object sender, EventArgs e) private void timerRefresh_Tick(object sender, EventArgs e)
{ {
if (!IsDisposed) UpdateTimer();
{
lblTimer.Text = Timer.Elapsed.ToString("mm\\:ss\\:ff");
}
} }
private void btnStop_Click(object sender, EventArgs e) private void btnStop_Click(object sender, EventArgs e)