Allow dragging form while waiting for recording to start

This commit is contained in:
Jaex 2022-09-04 03:26:41 +03:00
parent aa434258c5
commit ee9639d960
4 changed files with 112 additions and 82 deletions

View file

@ -42,6 +42,8 @@ private void InitializeComponent()
resources.ApplyResources(this.lblTimer, "lblTimer");
this.lblTimer.Name = "lblTimer";
this.lblTimer.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lblTimer_MouseDown);
this.lblTimer.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lblTimer_MouseMove);
this.lblTimer.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lblTimer_MouseUp);
//
// timerRefresh
//

View file

@ -71,6 +71,8 @@ public Rectangle RecordRectangle
private Color borderColor = Color.Red;
private Rectangle borderRectangle;
private Rectangle borderRectangle0Based;
private bool dragging;
private Point initialLocation;
private static int lastIconStatus = -1;
private const int panelOffset = 3;
@ -272,10 +274,27 @@ private void btnAbort_MouseClick(object sender, MouseEventArgs e)
private void lblTimer_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && Status == ScreenRecordingStatus.Paused)
if (e.Button == MouseButtons.Left && (Status == ScreenRecordingStatus.Waiting || Status == ScreenRecordingStatus.Paused))
{
NativeMethods.ReleaseCapture();
NativeMethods.SendMessage(Handle, (uint)WindowsMessages.NCLBUTTONDOWN, (IntPtr)WindowHitTestRegions.HTCAPTION, IntPtr.Zero);
dragging = true;
initialLocation = e.Location;
}
}
private void lblTimer_MouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{
Location = new Point(Location.X + e.X - initialLocation.X, Location.Y + e.Y - initialLocation.Y);
Update();
}
}
private void lblTimer_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
dragging = false;
}
}
@ -323,6 +342,24 @@ public void AbortRecording()
StartStopRecording();
}
private void UpdateUI()
{
if (Status == ScreenRecordingStatus.Waiting || Status == ScreenRecordingStatus.Paused)
{
// TODO: Translate
btnPause.Text = "Resume";
lblTimer.Cursor = Cursors.SizeAll;
borderColor = Color.FromArgb(241, 196, 27);
Refresh();
}
else if (Status == ScreenRecordingStatus.Working || Status == ScreenRecordingStatus.Recording)
{
// TODO: Translate
btnPause.Text = "Pause";
lblTimer.Cursor = Cursors.Default;
}
}
public void ChangeState(ScreenRecordState state)
{
this.InvokeSafe(() =>
@ -341,17 +378,17 @@ public void ChangeState(ScreenRecordState state)
niTray.Text = trayTextBeforeStart.Truncate(63);
tsmiStart.Text = Resources.ScreenRecordForm_Start;
cmsMain.Enabled = true;
UpdateUI();
break;
case ScreenRecordState.AfterStart:
dragging = false;
Status = ScreenRecordingStatus.Working;
string trayTextAfterStart = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Click_tray_icon_to_stop_recording_;
niTray.Text = trayTextAfterStart.Truncate(63);
niTray.Icon = Resources.control_record.ToIcon();
tsmiStart.Text = Resources.ScreenRecordForm_Stop;
btnStart.Text = Resources.ScreenRecordForm_Stop;
// TODO: Translate
btnPause.Text = "Pause";
lblTimer.Cursor = Cursors.Default;
UpdateUI();
break;
case ScreenRecordState.AfterRecordingStart:
Status = ScreenRecordingStatus.Recording;
@ -359,14 +396,7 @@ public void ChangeState(ScreenRecordState state)
break;
case ScreenRecordState.RecordingEnd:
StopRecordingTimer();
if (Status == ScreenRecordingStatus.Paused)
{
// TODO: Translate
btnPause.Text = "Resume";
lblTimer.Cursor = Cursors.SizeAll;
borderColor = Color.FromArgb(241, 196, 27);
Refresh();
}
UpdateUI();
break;
case ScreenRecordState.Encoding:
Hide();

View file

@ -288,6 +288,15 @@
<metadata name="cmsMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>138, 17</value>
</metadata>
<data name="cmsMain.Size" type="System.Drawing.Size, System.Drawing">
<value>105, 48</value>
</data>
<data name="&gt;&gt;cmsMain.Name" xml:space="preserve">
<value>cmsMain</value>
</data>
<data name="&gt;&gt;cmsMain.Type" xml:space="preserve">
<value>System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="tsmiStart.Size" type="System.Drawing.Size, System.Drawing">
<value>104, 22</value>
</data>
@ -300,15 +309,6 @@
<data name="tsmiAbort.Text" xml:space="preserve">
<value>Abort</value>
</data>
<data name="cmsMain.Size" type="System.Drawing.Size, System.Drawing">
<value>105, 48</value>
</data>
<data name="&gt;&gt;cmsMain.Name" xml:space="preserve">
<value>cmsMain</value>
</data>
<data name="&gt;&gt;cmsMain.Type" xml:space="preserve">
<value>System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<metadata name="niTray.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>238, 17</value>
</metadata>

View file

@ -221,79 +221,77 @@ private static void StartRecording(ScreenRecordOutput outputType, TaskSettings t
FileHelpers.DeleteFile(tempPath);
}
while (recordForm.Status == ScreenRecordingStatus.Waiting || recordForm.Status == ScreenRecordingStatus.Paused)
while (!abortRequested && (recordForm.Status == ScreenRecordingStatus.Waiting || recordForm.Status == ScreenRecordingStatus.Paused))
{
if (!abortRequested)
recordForm.ChangeState(ScreenRecordState.BeforeStart);
if (recordForm.Status == ScreenRecordingStatus.Paused || !taskSettings.CaptureSettings.ScreenRecordAutoStart)
{
recordForm.ChangeState(ScreenRecordState.BeforeStart);
recordForm.RecordResetEvent.WaitOne();
}
else
{
int delay = (int)(taskSettings.CaptureSettings.ScreenRecordStartDelay * 1000);
if (recordForm.Status == ScreenRecordingStatus.Paused || !taskSettings.CaptureSettings.ScreenRecordAutoStart)
if (delay > 0)
{
recordForm.RecordResetEvent.WaitOne();
recordForm.InvokeSafe(() => recordForm.StartCountdown(delay));
recordForm.RecordResetEvent.WaitOne(delay);
}
else
}
if (recordForm.Status == ScreenRecordingStatus.Aborted)
{
abortRequested = true;
}
if (recordForm.Status == ScreenRecordingStatus.Waiting || recordForm.Status == ScreenRecordingStatus.Paused)
{
if (recordForm.Status == ScreenRecordingStatus.Paused && File.Exists(path))
{
int delay = (int)(taskSettings.CaptureSettings.ScreenRecordStartDelay * 1000);
if (delay > 0)
{
recordForm.InvokeSafe(() => recordForm.StartCountdown(delay));
recordForm.RecordResetEvent.WaitOne(delay);
}
FileHelpers.RenameFile(path, concatPath);
}
recordForm.ChangeState(ScreenRecordState.AfterStart);
captureRectangle = recordForm.RecordRectangle;
ScreenRecordingOptions options = new ScreenRecordingOptions()
{
IsRecording = true,
IsLossless = taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding,
FFmpeg = taskSettings.CaptureSettings.FFmpegOptions,
FPS = fps,
Duration = duration,
OutputPath = path,
CaptureArea = captureRectangle,
DrawCursor = taskSettings.CaptureSettings.ScreenRecordShowCursor
};
Screenshot screenshot = TaskHelpers.GetScreenshot(taskSettings);
screenshot.CaptureCursor = taskSettings.CaptureSettings.ScreenRecordShowCursor;
screenRecorder?.Dispose();
screenRecorder = new ScreenRecorder(ScreenRecordOutput.FFmpeg, options, screenshot, captureRectangle);
screenRecorder.RecordingStarted += ScreenRecorder_RecordingStarted;
screenRecorder.EncodingProgressChanged += ScreenRecorder_EncodingProgressChanged;
screenRecorder.StartRecording();
recordForm.ChangeState(ScreenRecordState.RecordingEnd);
if (recordForm.Status == ScreenRecordingStatus.Aborted)
{
abortRequested = true;
}
}
if (recordForm.Status == ScreenRecordingStatus.Waiting || recordForm.Status == ScreenRecordingStatus.Paused)
if (File.Exists(concatPath))
{
using (FFmpegCLIManager ffmpeg = new FFmpegCLIManager(taskSettings.CaptureSettings.FFmpegOptions.FFmpegPath))
{
if (recordForm.Status == ScreenRecordingStatus.Paused && File.Exists(path))
{
FileHelpers.RenameFile(path, concatPath);
}
captureRectangle = recordForm.RecordRectangle;
ScreenRecordingOptions options = new ScreenRecordingOptions()
{
IsRecording = true,
IsLossless = taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding,
FFmpeg = taskSettings.CaptureSettings.FFmpegOptions,
FPS = fps,
Duration = duration,
OutputPath = path,
CaptureArea = captureRectangle,
DrawCursor = taskSettings.CaptureSettings.ScreenRecordShowCursor
};
Screenshot screenshot = TaskHelpers.GetScreenshot(taskSettings);
screenshot.CaptureCursor = taskSettings.CaptureSettings.ScreenRecordShowCursor;
screenRecorder?.Dispose();
screenRecorder = new ScreenRecorder(ScreenRecordOutput.FFmpeg, options, screenshot, captureRectangle);
screenRecorder.RecordingStarted += ScreenRecorder_RecordingStarted;
screenRecorder.EncodingProgressChanged += ScreenRecorder_EncodingProgressChanged;
recordForm.ChangeState(ScreenRecordState.AfterStart);
screenRecorder.StartRecording();
recordForm.ChangeState(ScreenRecordState.RecordingEnd);
if (recordForm.Status == ScreenRecordingStatus.Aborted)
{
abortRequested = true;
}
}
if (File.Exists(concatPath))
{
using (FFmpegCLIManager ffmpeg = new FFmpegCLIManager(taskSettings.CaptureSettings.FFmpegOptions.FFmpegPath))
{
ffmpeg.ShowError = true;
ffmpeg.ConcatenateVideos(new string[] { concatPath, path }, tempPath, true);
FileHelpers.RenameFile(tempPath, path);
}
ffmpeg.ShowError = true;
ffmpeg.ConcatenateVideos(new string[] { concatPath, path }, tempPath, true);
FileHelpers.RenameFile(tempPath, path);
}
}
}