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"); resources.ApplyResources(this.lblTimer, "lblTimer");
this.lblTimer.Name = "lblTimer"; this.lblTimer.Name = "lblTimer";
this.lblTimer.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lblTimer_MouseDown); 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 // timerRefresh
// //

View file

@ -71,6 +71,8 @@ public Rectangle RecordRectangle
private Color borderColor = Color.Red; private Color borderColor = Color.Red;
private Rectangle borderRectangle; private Rectangle borderRectangle;
private Rectangle borderRectangle0Based; private Rectangle borderRectangle0Based;
private bool dragging;
private Point initialLocation;
private static int lastIconStatus = -1; private static int lastIconStatus = -1;
private const int panelOffset = 3; 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) 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(); dragging = true;
NativeMethods.SendMessage(Handle, (uint)WindowsMessages.NCLBUTTONDOWN, (IntPtr)WindowHitTestRegions.HTCAPTION, IntPtr.Zero); 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(); 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) public void ChangeState(ScreenRecordState state)
{ {
this.InvokeSafe(() => this.InvokeSafe(() =>
@ -341,17 +378,17 @@ public void ChangeState(ScreenRecordState state)
niTray.Text = trayTextBeforeStart.Truncate(63); niTray.Text = trayTextBeforeStart.Truncate(63);
tsmiStart.Text = Resources.ScreenRecordForm_Start; tsmiStart.Text = Resources.ScreenRecordForm_Start;
cmsMain.Enabled = true; cmsMain.Enabled = true;
UpdateUI();
break; break;
case ScreenRecordState.AfterStart: case ScreenRecordState.AfterStart:
dragging = false;
Status = ScreenRecordingStatus.Working; Status = ScreenRecordingStatus.Working;
string trayTextAfterStart = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Click_tray_icon_to_stop_recording_; string trayTextAfterStart = "ShareX - " + Resources.ScreenRecordForm_StartRecording_Click_tray_icon_to_stop_recording_;
niTray.Text = trayTextAfterStart.Truncate(63); niTray.Text = trayTextAfterStart.Truncate(63);
niTray.Icon = Resources.control_record.ToIcon(); niTray.Icon = Resources.control_record.ToIcon();
tsmiStart.Text = Resources.ScreenRecordForm_Stop; tsmiStart.Text = Resources.ScreenRecordForm_Stop;
btnStart.Text = Resources.ScreenRecordForm_Stop; btnStart.Text = Resources.ScreenRecordForm_Stop;
// TODO: Translate UpdateUI();
btnPause.Text = "Pause";
lblTimer.Cursor = Cursors.Default;
break; break;
case ScreenRecordState.AfterRecordingStart: case ScreenRecordState.AfterRecordingStart:
Status = ScreenRecordingStatus.Recording; Status = ScreenRecordingStatus.Recording;
@ -359,14 +396,7 @@ public void ChangeState(ScreenRecordState state)
break; break;
case ScreenRecordState.RecordingEnd: case ScreenRecordState.RecordingEnd:
StopRecordingTimer(); StopRecordingTimer();
if (Status == ScreenRecordingStatus.Paused) UpdateUI();
{
// TODO: Translate
btnPause.Text = "Resume";
lblTimer.Cursor = Cursors.SizeAll;
borderColor = Color.FromArgb(241, 196, 27);
Refresh();
}
break; break;
case ScreenRecordState.Encoding: case ScreenRecordState.Encoding:
Hide(); 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"> <metadata name="cmsMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>138, 17</value> <value>138, 17</value>
</metadata> </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"> <data name="tsmiStart.Size" type="System.Drawing.Size, System.Drawing">
<value>104, 22</value> <value>104, 22</value>
</data> </data>
@ -300,15 +309,6 @@
<data name="tsmiAbort.Text" xml:space="preserve"> <data name="tsmiAbort.Text" xml:space="preserve">
<value>Abort</value> <value>Abort</value>
</data> </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"> <metadata name="niTray.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>238, 17</value> <value>238, 17</value>
</metadata> </metadata>

View file

@ -221,9 +221,7 @@ private static void StartRecording(ScreenRecordOutput outputType, TaskSettings t
FileHelpers.DeleteFile(tempPath); 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); recordForm.ChangeState(ScreenRecordState.BeforeStart);
@ -255,6 +253,8 @@ private static void StartRecording(ScreenRecordOutput outputType, TaskSettings t
FileHelpers.RenameFile(path, concatPath); FileHelpers.RenameFile(path, concatPath);
} }
recordForm.ChangeState(ScreenRecordState.AfterStart);
captureRectangle = recordForm.RecordRectangle; captureRectangle = recordForm.RecordRectangle;
ScreenRecordingOptions options = new ScreenRecordingOptions() ScreenRecordingOptions options = new ScreenRecordingOptions()
@ -276,7 +276,6 @@ private static void StartRecording(ScreenRecordOutput outputType, TaskSettings t
screenRecorder = new ScreenRecorder(ScreenRecordOutput.FFmpeg, options, screenshot, captureRectangle); screenRecorder = new ScreenRecorder(ScreenRecordOutput.FFmpeg, options, screenshot, captureRectangle);
screenRecorder.RecordingStarted += ScreenRecorder_RecordingStarted; screenRecorder.RecordingStarted += ScreenRecorder_RecordingStarted;
screenRecorder.EncodingProgressChanged += ScreenRecorder_EncodingProgressChanged; screenRecorder.EncodingProgressChanged += ScreenRecorder_EncodingProgressChanged;
recordForm.ChangeState(ScreenRecordState.AfterStart);
screenRecorder.StartRecording(); screenRecorder.StartRecording();
recordForm.ChangeState(ScreenRecordState.RecordingEnd); recordForm.ChangeState(ScreenRecordState.RecordingEnd);
@ -297,7 +296,6 @@ private static void StartRecording(ScreenRecordOutput outputType, TaskSettings t
} }
} }
} }
}
catch (Exception e) catch (Exception e)
{ {
DebugHelper.WriteException(e); DebugHelper.WriteException(e);