public void RunLoop() { if (Control == null) { throw new ArgumentException("Control cannot be null on loop start"); } if (frameRate == null) { frameRate = new FrameRate(); } frameRate.Start(); while (NextFrame()) { frameRate.StartFrame(); if (PreProcess != null) { PreProcess(this, new EventArgs()); } if (ProcessFrame != null) { ProcessFrame(this, new EventArgs()); } if (PostProcess != null) { PostProcess(this, new EventArgs()); } frameRate.EndFrame(); } frameRate.Stop(); }
internal virtual void StartCapture() { FrameRate.Start(HasFixedDelay(), GetFixedDelay()); HasImpreciseCapture = false; if (UserSettings.All.ForceGarbageCollection) { GarbageTimer.Start(); } lock (UserSettings.Lock) { //Starts the capture. _captureToken = new CancellationTokenSource(); Task.Run(() => PrepareCaptureLoop(GetCaptureInterval()), _captureToken.Token); } }
/// <summary> /// Method that starts or pauses the recording /// </summary> private async void RecordPause() { switch (Stage) { case Stage.Stopped: #region To Record _capture = new Timer { Interval = 1000 / FpsIntegerUpDown.Value }; _snapDelay = null; Project = new ProjectInfo().CreateProjectFolder(); _keyList.Clear(); FrameCount = 0; await Task.Factory.StartNew(UpdateScreenDpi); #region Sizing if (UserSettings.All.FullScreenMode) { _size = new Size((int)_sizeScreen.X, (int)_sizeScreen.Y); } else { _size = new Size((int)Math.Round((Width - Constants.HorizontalOffset) * _scale), (int)Math.Round((Height - Constants.VerticalOffset) * _scale)); } #endregion HeightIntegerBox.IsEnabled = false; WidthIntegerBox.IsEnabled = false; FpsIntegerUpDown.IsEnabled = false; IsRecording = true; Topmost = true; FrameRate.Start(_capture.Interval); UnregisterEvents(); #region Start if (UserSettings.All.UsePreStart) { Title = $"Screen To Gif ({FindResource("Recorder.PreStart")} {UserSettings.All.PreStartValue}s)"; RecordPauseButton.IsEnabled = false; Stage = Stage.PreStarting; _preStartCount = UserSettings.All.PreStartValue - 1; _preStartTimer.Start(); } else { if (UserSettings.All.ShowCursor) { #region If Show Cursor if (!UserSettings.All.FullScreenMode) { if (UserSettings.All.AsyncRecording) { _capture.Tick += CursorAsync_Elapsed; } else { _capture.Tick += Cursor_Elapsed; } _capture.Start(); } else { _capture.Tick += FullCursor_Elapsed; _capture.Start(); } Stage = Stage.Recording; AutoFitButtons(); #endregion } else { #region If Not if (!UserSettings.All.FullScreenMode) { if (UserSettings.All.AsyncRecording) { _capture.Tick += NormalAsync_Elapsed; } else { _capture.Tick += Normal_Elapsed; } _capture.Start(); } else { _capture.Tick += Full_Elapsed; _capture.Start(); } Stage = Stage.Recording; AutoFitButtons(); #endregion } } break; #endregion #endregion case Stage.Recording: #region To Pause Stage = Stage.Paused; Title = FindResource("Recorder.Paused").ToString(); DiscardButton.BeginStoryboard(FindResource("ShowDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); _capture.Stop(); FrameRate.Stop(); break; #endregion case Stage.Paused: #region To Record Again Stage = Stage.Recording; Title = "Screen To Gif"; DiscardButton.BeginStoryboard(FindResource("HideDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); FrameRate.Start(_capture.Interval); _capture.Start(); break; #endregion } }
/// <summary> /// Method that starts or pauses the recording /// </summary> private void RecordPause() { Extras.CreateTemp(_pathTemp); switch (Stage) { case Stage.Stopped: #region To Record _capture = new Timer { Interval = 1000 / (int)FpsNumericUpDown.Value }; _snapDelay = null; ListFrames = new List <FrameInfo>(); HeightTextBox.IsEnabled = false; WidthTextBox.IsEnabled = false; FpsNumericUpDown.IsEnabled = false; IsRecording = true; Topmost = true; FrameRate.Start(_capture.Interval); #region Start if (!Settings.Default.Snapshot) { #region Normal Recording _capture.Tick += Normal_Elapsed; //Normal_Elapsed(null, null); _capture.Start(); Stage = Stage.Recording; AutoFitButtons(); #endregion } else { #region SnapShot Recording Stage = Stage.Snapping; //Title = "Board Recorder - " + Properties.Resources.Con_SnapshotMode; AutoFitButtons(); #endregion } break; #endregion #endregion case Stage.Recording: #region To Pause Stage = Stage.Paused; Title = FindResource("Recorder.Paused").ToString(); AutoFitButtons(); _capture.Stop(); FrameRate.Stop(); break; #endregion case Stage.Paused: #region To Record Again Stage = Stage.Recording; Title = "Board Recorder"; AutoFitButtons(); FrameRate.Start(_capture.Interval); _capture.Start(); break; #endregion case Stage.Snapping: #region Take Screenshot (All possibles types) _snapDelay = Settings.Default.SnapshotDefaultDelay; Normal_Elapsed(null, null); break; #endregion } }
/// <summary> /// Method that starts or pauses the recording /// </summary> private void RecordPause() { switch (Stage) { case Stage.Stopped: #region To Record _capture = new Timer { Interval = 1000 / FpsNumericUpDown.Value }; _snapDelay = null; Project = new ProjectInfo().CreateProjectFolder(); HeightIntegerBox.IsEnabled = false; WidthIntegerBox.IsEnabled = false; FpsNumericUpDown.IsEnabled = false; IsRecording = true; Topmost = true; FrameRate.Start(_capture.Interval); #region Start //if (!Settings.Default.Snapshot) //{ #region Normal Recording _capture.Tick += Normal_Elapsed; //Normal_Elapsed(null, null); _capture.Start(); Stage = Stage.Recording; AutoFitButtons(); #endregion //} //else //{ // #region SnapShot Recording // Stage = Stage.Snapping; // //Title = "Board Recorder - " + Properties.Resources.Con_SnapshotMode; // AutoFitButtons(); // #endregion //} break; #endregion #endregion case Stage.Recording: #region To Pause Stage = Stage.Paused; Title = FindResource("Recorder.Paused").ToString(); AutoFitButtons(); _capture.Stop(); FrameRate.Stop(); break; #endregion case Stage.Paused: #region To Record Again Stage = Stage.Recording; Title = FindResource("Board.Title") as string; AutoFitButtons(); FrameRate.Start(_capture.Interval); _capture.Start(); break; #endregion case Stage.Snapping: #region Take Screenshot (All possibles types) _snapDelay = UserSettings.All.SnapshotDefaultDelay; Normal_Elapsed(null, null); break; #endregion } }
/// <summary> /// Method that starts or pauses the recording /// </summary> internal async void RecordPause() { try { switch (Stage) { case Stage.Stopped: #region To Record _captureTimer = new Timer { Interval = 1000 / FpsIntegerUpDown.Value }; Project = new ProjectInfo().CreateProjectFolder(ProjectByType.ScreenRecorder); _keyList.Clear(); FrameCount = 0; await Task.Factory.StartNew(UpdateScreenDpi); PrepareNewCapture(); HeightIntegerBox.IsEnabled = false; WidthIntegerBox.IsEnabled = false; FpsIntegerUpDown.IsEnabled = false; IsRecording = true; Topmost = true; FrameRate.Start(_captureTimer.Interval); UnregisterEvents(); #region Start if (UserSettings.All.UsePreStart) { Title = $"ScreenToGif ({LocalizationHelper.Get("Recorder.PreStart")} {UserSettings.All.PreStartValue}s)"; RecordPauseButton.IsEnabled = false; Stage = Stage.PreStarting; _preStartCount = UserSettings.All.PreStartValue - 1; _preStartTimer.Start(); } else { if (UserSettings.All.ShowCursor) { #region If Show Cursor if (UserSettings.All.AsyncRecording) { _captureTimer.Tick += CursorAsync_Elapsed; } else { _captureTimer.Tick += Cursor_Elapsed; } _captureTimer.Start(); Stage = Stage.Recording; AutoFitButtons(); #endregion } else { #region If Not if (UserSettings.All.AsyncRecording) { _captureTimer.Tick += NormalAsync_Elapsed; } else { _captureTimer.Tick += Normal_Elapsed; } _captureTimer.Start(); Stage = Stage.Recording; AutoFitButtons(); #endregion } } break; #endregion #endregion case Stage.Recording: #region To Pause _captureTimer.Stop(); FrameRate.Stop(); Stage = Stage.Paused; Title = LocalizationHelper.Get("Recorder.Paused"); DiscardButton.BeginStoryboard(FindResource("ShowDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); break; #endregion case Stage.Paused: #region To Record Again Stage = Stage.Recording; Title = "ScreenToGif"; DiscardButton.BeginStoryboard(FindResource("HideDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); FrameRate.Start(_captureTimer.Interval); _captureTimer.Start(); break; #endregion } } catch (Exception e) { LogWriter.Log(e, "Impossible to start the recording."); ErrorDialog.Ok(Title, LocalizationHelper.Get("S.Recorder.Warning.StartPauseNotPossible"), e.Message, e); } }
/// <summary> /// Method that starts or pauses the recording /// </summary> private void RecordPause() { Extras.CreateTemp(_pathTemp); switch (Stage) { case Stage.Stopped: #region To Record _capture = new Timer { Interval = 1000 / FpsNumericUpDown.Value }; _snapDelay = null; ListFrames = new List <FrameInfo>(); #region If Fullscreen if (Settings.Default.FullScreen) { _bt = new Bitmap((int)_sizeScreen.X, (int)_sizeScreen.Y); HideWindowAndShowTrayIcon(); } else { _bt = new Bitmap((int)((Width - 18) * _dpi), (int)((Height - 69) * _dpi)); } #endregion _gr = Graphics.FromImage(_bt); HeightTextBox.IsEnabled = false; WidthTextBox.IsEnabled = false; FpsNumericUpDown.IsEnabled = false; IsRecording(true); Topmost = true; _size = new System.Drawing.Size(_bt.Size.Width, _bt.Size.Height); FrameRate.Start(_capture.Interval); #region Start if (Settings.Default.PreStart) { Title = "Screen To Gif (2 " + Properties.Resources.TitleSecondsToGo; RecordPauseButton.IsEnabled = false; Stage = Stage.PreStarting; _preStartCount = 1; //Reset timer to 2 seconds, 1 second to trigger the timer so 1 + 1 = 2 _preStartTimer.Start(); } else { if (Settings.Default.ShowCursor) { #region If Show Cursor if (!Settings.Default.Snapshot) { #region Normal Recording if (!Settings.Default.FullScreen) { //To start recording right away, I call the tick before starting the timer, //because the first tick will only occur after the delay. _capture.Tick += Cursor_Elapsed; //Cursor_Elapsed(null, null); _capture.Start(); } else { _capture.Tick += FullCursor_Elapsed; //FullCursor_Elapsed(null, null); _capture.Start(); } Stage = Stage.Recording; RecordPauseButton.Text = Properties.Resources.Pause; RecordPauseButton.Content = (Canvas)FindResource("Vector.Pause"); RecordPauseButton.HorizontalContentAlignment = HorizontalAlignment.Left; AutoFitButtons(); #endregion } else { #region SnapShot Recording //Set to Snapshot Mode, change the text of the record button to "Snap" and //every press of the button, takes a screenshot Stage = Stage.Snapping; RecordPauseButton.Content = (Canvas)FindResource("Vector.Camera.Old"); RecordPauseButton.Text = Properties.Resources.btnSnap; RecordPauseButton.HorizontalContentAlignment = HorizontalAlignment.Left; Title = "Screen To Gif - " + Properties.Resources.Con_SnapshotMode; AutoFitButtons(); #endregion } #endregion } else { #region If Not if (!Settings.Default.Snapshot) { #region Normal Recording _actHook.OnMouseActivity += MouseHookTarget; if (!Settings.Default.FullScreen) { _capture.Tick += Normal_Elapsed; //Normal_Elapsed(null, null); _capture.Start(); } else { _capture.Tick += Full_Elapsed; //Full_Elapsed(null, null); _capture.Start(); } Stage = Stage.Recording; RecordPauseButton.Text = Properties.Resources.Pause; RecordPauseButton.Content = (Canvas)FindResource("Vector.Pause"); RecordPauseButton.HorizontalContentAlignment = HorizontalAlignment.Left; AutoFitButtons(); #endregion } else { #region SnapShot Recording Stage = Stage.Snapping; RecordPauseButton.Content = (Canvas)FindResource("Vector.Camera.Old"); RecordPauseButton.Text = Properties.Resources.btnSnap; RecordPauseButton.HorizontalContentAlignment = HorizontalAlignment.Left; Title = "Screen To Gif - " + Properties.Resources.Con_SnapshotMode; AutoFitButtons(); #endregion } #endregion } } break; #endregion #endregion case Stage.Recording: #region To Pause Stage = Stage.Paused; RecordPauseButton.Text = Properties.Resources.btnRecordPause_Continue; RecordPauseButton.Content = (Canvas)FindResource("Vector.Record.Dark"); RecordPauseButton.HorizontalContentAlignment = HorizontalAlignment.Left; Title = Properties.Resources.TitlePaused; AutoFitButtons(); _capture.Stop(); //ModifyCaptureTimerAndChangeTrayIconVisibility(false); FrameRate.Stop(); break; #endregion case Stage.Paused: #region To Record Again Stage = Stage.Recording; RecordPauseButton.Text = Properties.Resources.Pause; RecordPauseButton.Content = (Canvas)FindResource("Vector.Pause"); RecordPauseButton.HorizontalContentAlignment = HorizontalAlignment.Left; Title = Properties.Resources.TitleRecording; AutoFitButtons(); FrameRate.Start(_capture.Interval); _capture.Start(); break; //ModifyCaptureTimerAndChangeTrayIconVisibility(true); #endregion case Stage.Snapping: #region Take Screenshot (All possibles types) _snapDelay = Settings.Default.SnapshotDefaultDelay; if (Settings.Default.ShowCursor) { if (Settings.Default.FullScreen) { FullCursor_Elapsed(null, null); } else { Cursor_Elapsed(null, null); } } else { if (Settings.Default.FullScreen) { Full_Elapsed(null, null); } else { Normal_Elapsed(null, null); } } break; #endregion } }
/// <summary> /// Method that starts or pauses the recording /// </summary> private async void RecordPause() { Extras.CreateTemp(_pathTemp); switch (Stage) { case Stage.Stopped: #region To Record _capture = new Timer { Interval = 1000 / FpsIntegerUpDown.Value }; _snapDelay = null; ListFrames = new List <FrameInfo>(); FrameCount = 0; await Task.Factory.StartNew(UpdateScreenDpi); #region If Fullscreen if (Settings.Default.FullScreen) { _size = new Size((int)_sizeScreen.X, (int)_sizeScreen.Y); //TODO: Hide the top of the window, add a little drag component, position this window at the bottom. } else { _size = new Size((int)((Width - Constants.HorizontalOffset) * _scale), (int)((Height - Constants.VerticalOffset) * _scale)); } #endregion HeightIntegerBox.IsEnabled = false; WidthIntegerBox.IsEnabled = false; FpsIntegerUpDown.IsEnabled = false; IsRecording = true; Topmost = true; FrameRate.Start(_capture.Interval); UnregisterEvents(); #region Start if (Settings.Default.PreStart) { Title = $"Screen To Gif ({FindResource("Recorder.PreStart")} 2s)"; RecordPauseButton.IsEnabled = false; Stage = Stage.PreStarting; _preStartCount = 1; //Reset timer to 2 seconds, 1 second to trigger the timer so 1 + 1 = 2 _preStartTimer.Start(); } else { if (Settings.Default.ShowCursor) { #region If Show Cursor if (!Settings.Default.FullScreen) { if (Settings.Default.AsyncRecording) { _capture.Tick += CursorAsync_Elapsed; } else { _capture.Tick += Cursor_Elapsed; } _capture.Start(); } else { _capture.Tick += FullCursor_Elapsed; _capture.Start(); } Stage = Stage.Recording; AutoFitButtons(); #endregion } else { #region If Not if (!Settings.Default.FullScreen) { if (Settings.Default.AsyncRecording) { _capture.Tick += NormalAsync_Elapsed; } else { _capture.Tick += Normal_Elapsed; } _capture.Start(); } else { _capture.Tick += Full_Elapsed; _capture.Start(); } Stage = Stage.Recording; AutoFitButtons(); #endregion } } break; #endregion #endregion case Stage.Recording: #region To Pause Stage = Stage.Paused; Title = FindResource("Recorder.Paused").ToString(); DiscardButton.BeginStoryboard(FindResource("ShowDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); _capture.Stop(); FrameRate.Stop(); break; #endregion case Stage.Paused: #region To Record Again Stage = Stage.Recording; Title = "Screen To Gif"; DiscardButton.BeginStoryboard(FindResource("HideDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); FrameRate.Start(_capture.Interval); _capture.Start(); break; #endregion } }
/// <summary> /// Method that starts or pauses the recording /// </summary> internal async void RecordPause() { switch (Stage) { case Stage.Stopped: _capture = new Timer { Interval = 1000 / FpsIntegerUpDown.Value }; _keyList.Clear(); FrameCount = 0; await Task.Factory.StartNew(UpdateScreenDpi); //Sizing. _size = new Size((int)Math.Round((Width - Constants.HorizontalOffset) * _scale), (int)Math.Round((Height - Constants.VerticalOffset) * _scale)); Project = new ProjectInfo(new Int32Rect { Height = (int)_size.Height, Width = (int)_size.Width }); HeightIntegerBox.IsEnabled = false; WidthIntegerBox.IsEnabled = false; FpsIntegerUpDown.IsEnabled = false; IsRecording = true; Topmost = true; FrameRate.Start(_capture.Interval); UnregisterEvents(); _capture.Tick += Normal_Elapsed; _capture.Start(); Stage = Stage.Recording; AutoFitButtons(); break; case Stage.Recording: Stage = Stage.Paused; Title = FindResource("Recorder.Paused").ToString(); DiscardButton.BeginStoryboard(FindResource("ShowDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); _capture.Stop(); FrameRate.Stop(); break; case Stage.Paused: Stage = Stage.Recording; Title = "Screen To Gif"; DiscardButton.BeginStoryboard(FindResource("HideDiscardStoryboard") as Storyboard, HandoffBehavior.Compose); AutoFitButtons(); FrameRate.Start(_capture.Interval); _capture.Start(); break; } }