protected bool ShowModalWindow(IPanel panel, IPanel parent) { var dialog = panel as Gtk.Dialog; if (dialog != null) { dialog.TransientFor = ((Bin)parent).Toplevel as Window; dialog.Response += HandleModalWindowResponse; dialog.Center(); panel.OnLoad(); } else { ExternalWindow modalWindow = new ExternalWindow(); modalWindow.Resizable = false; modalWindow.DefaultWidth = (panel as Gtk.Bin).WidthRequest; modalWindow.DefaultHeight = (panel as Gtk.Bin).HeightRequest; modalWindow.Title = panel.Title; modalWindow.Modal = true; modalWindow.TransientFor = ((Bin)parent).Toplevel as Window; modalWindow.DeleteEvent += HandleModalWindowDeleteEvent; Widget widget = panel as Gtk.Widget; modalWindow.Add(widget); modalWindow.SetPosition(WindowPosition.CenterOnParent); modalWindow.ShowAll(); panel.OnLoad(); } return(true); }
private void tbCaptureDesktop_Click(object sender, RoutedEventArgs e) { this.Hide(); ExternalWindow?.Hide(); WindowUtilities.DoEvents(); var screen = Screen.FromHandle(WindowHandle); var img = ScreenCapture.CaptureWindow(screen.Bounds); ImageCaptured.Source = ScreenCapture.ImageToBitmapSource(img); CapturedBitmap?.Dispose(); CapturedBitmap = new Bitmap(img); StatusText.Text = $"Desktop captured Image: {CapturedBitmap.Width}x{CapturedBitmap.Height}"; ExternalWindow?.Show(); this.Topmost = true; this.Show(); WindowUtilities.DoEvents(); ScreenCaptureForm_SizeChanged(this, null); }
/// <summary> /// Detach the specified widget to an external window or re-attach it again to its previous container. /// </summary> /// <param name="widgetToDetach">Widget to detach.</param> /// <param name="windowTitle">Window title.</param> /// <param name="widgetWhereReattach">Widget where reattach.</param> /// <param name="func">Function executed detaching and attaching by the view in order to do specific work as /// hiding widgets</param> public void Detach(Widget widgetToDetach, string windowTitle, Widget widgetWhereReattach, Function func) { if (externalWindow == null) { Log.Debug("Detaching widget"); externalWindow = new ExternalWindow(); externalWindow.Title = windowTitle; int window_width = widgetToDetach.Allocation.Width; int window_height = widgetToDetach.Allocation.Height; externalWindow.SetDefaultSize(window_width, window_height); externalWindow.DeleteEvent += (o, args) => Detach(widgetToDetach, windowTitle, widgetWhereReattach, func); externalWindow.Show(); widgetToDetach.Reparent(externalWindow.Box); // Hack to reposition widget window in widget for OSX externalWindow.Resize(window_width + 10, window_height); } else { Log.Debug("Attaching widget again"); widgetToDetach.Reparent(widgetWhereReattach); externalWindow.Destroy(); externalWindow = null; } func.Invoke(); }
private void tbSave_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(SaveFolder)) { SaveFolder = Path.GetTempPath(); } SaveFileDialog sd = new SaveFileDialog { Filter = "png files (*.png)|*.png|jpg files (*.jpg)|*.jpg", FilterIndex = 1, FileName = "", CheckFileExists = false, OverwritePrompt = false, AutoUpgradeEnabled = true, CheckPathExists = true, InitialDirectory = SaveFolder, RestoreDirectory = true }; var result = sd.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return; } SavedImageFile = sd.FileName; try { CapturedBitmap?.Save(SavedImageFile); } catch (Exception ex) { Cancelled = true; StatusText.Text = "Error saving image: " + ex.Message; return; } if (!string.IsNullOrEmpty(ResultFilePath)) { File.WriteAllText(ResultFilePath, SavedImageFile); } Cancelled = false; if (AutoClose) { Close(); } ExternalWindow?.Show(); ExternalWindow?.Activate(); if (WindowState != WindowState.Maximized && WindowState != WindowState.Minimized) { ScreenCaptureConfiguration.Current.WindowWidth = this.Width; ScreenCaptureConfiguration.Current.WindowHeight = this.Width; } }
internal void StopCapture(bool cancelCapture = false) { if (!IsMouseClickCapturing) { return; } CaptureTimer.Dispose(); IsMouseClickCapturing = false; Overlay?.Close(); WindowUtilities.DoEvents(); //Point pt = GetMousePosition(); //CurWindow = new WindowInfo(ScreenCapture.WindowFromPoint(new System.Drawing.Point((int)pt.X, (int)pt.Y))); Desktop.Topmost = true; Desktop.Activate(); WindowUtilities.DoEvents(); if (LastWindow != null) { var img = ScreenCapture.CaptureWindow(CurWindow.Rect); CapturedBitmap = new Bitmap(img); //CapturedBitmap = ScreenCapture.CaptureWindowBitmap(CurWindow.Handle) as Bitmap; Desktop.Close(); if (CapturedBitmap != null) { ImageCaptured.Source = ScreenCapture.BitmapToBitmapSource(CapturedBitmap); StatusText.Text = "Image capture from Screen: " + $"{CapturedBitmap.Width}x{CapturedBitmap.Height}"; ScreenCaptureForm_SizeChanged(this, null); } else { StatusText.Text = "Image capture failed."; } } //Desktop.Topmost = false; Desktop?.Close(); if (ExternalWindow != null) { ExternalWindow.Show(); ExternalWindow.Activate(); } if (cancelCapture) { CancelCapture(); } else { Show(); Activate(); } }
void StartCapture() { Hide(); ExternalWindow?.Hide(); StatusImageSize.Text = ""; // make sure windows actually hides before we wait WindowUtilities.DoEvents(); // Display counter IsPreviewCapturing = true; Cancelled = false; ScreenOverlayCounter counterForm = null; if (CaptureDelaySeconds > 0) { counterForm = new ScreenOverlayCounter(); counterForm.Show(); counterForm.Topmost = true; counterForm.SetWindowText("1"); } else { DoScreenCapture(); return; } var secs = 1; var dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += (p, a) => { Dispatcher.Invoke(() => { secs++; if (secs > CaptureDelaySeconds) { dispatcherTimer.Stop(); counterForm?.Close(); DoScreenCapture(); } counterForm?.SetWindowText(secs.ToString()); }); }; if (CaptureDelaySeconds == 0) { dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1); } else { dispatcherTimer.Interval = new TimeSpan(0, 0, 1); } dispatcherTimer.Start(); }
private void CancelCapture() { if (!string.IsNullOrEmpty(ResultFilePath)) { File.WriteAllText(ResultFilePath, "Cancelled"); } Cancelled = true; Close(); ExternalWindow?.Activate(); }
private static async void SetGlowingForActiveWindow() { await Task.Delay(2500); var hWnd = User32.GetForegroundWindow(); var appHandles = Application.Current.Windows .OfType <Window>() .Select(x => PresentationSource.FromVisual(x) as HwndSource) .Where(x => x != null) .Select(x => x.Handle) .ToArray(); if (appHandles.All(x => x != hWnd)) { var external = new ExternalWindow(hWnd); var chrome = new WindowChrome(); chrome.Attach(external); } }
private void CancelCapture(bool dontCloseForm = false) { if (!string.IsNullOrEmpty(ResultFilePath)) { File.WriteAllText(ResultFilePath, "Cancelled"); } Cancelled = true; if (!dontCloseForm) { Close(); ExternalWindow?.Activate(); } else { Show(); Activate(); } }
private void HandleMetroChromeClicked(object sender, RoutedEventArgs e) { #if NETFRAMEWORK var viewModel = (WindowViewModel)this.WindowsListView.SelectedItem; if (viewModel == null) { MessageBox.Show(App.Current.MainWindow, Properties.Resources.ExternalChromeSample_SelectTargetWindow, Properties.Resources.AppName, MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } var externalWindow = new ExternalWindow(viewModel.Handle); if (this._metroChrome == null) { this._metroChrome = new WindowChrome(); } this._metroChrome.Attach(externalWindow); #else MessageBox.Show(App.Current.MainWindow, Properties.Resources.ExternalChromeSample_SupportOnlyDotNetFramework, Properties.Resources.AppName, MessageBoxButton.OK, MessageBoxImage.Exclamation); #endif }
Notebook CreateNewWindow(Notebook source, Widget page, int x, int y) { ExternalWindow window; EventBox box; Notebook notebook; window = new ExternalWindow(); if (page == timeline) { window.Title = Catalog.GetString("Timeline"); } else if (page == dashboardhpaned) { window.Title = Catalog.GetString("Analysis dashboard"); } else if (page == playspositionviewer1) { window.Title = Catalog.GetString("Zonal tags viewer"); } notebook = new Notebook(); notebook.ShowTabs = false; notebook.CanFocus = false; //notebook.Group = source.Group; window.Add(notebook); window.SetDefaultSize(page.Allocation.Width, page.Allocation.Height); window.Move(x, y); window.ShowAll(); activeWindows.Add(window); window.DeleteEvent += (o, args) => { Widget pa = notebook.CurrentPageWidget; activeWindows.Remove(window); notebook.Remove(pa); source.AppendPage(pa, null); SetTabProps(pa, source.NPages == 0); notebook.Destroy(); }; return(notebook); }
public void DetachPlayer() { bool isPlaying = ViewModel.VideoPlayer.Playing; /* Pause the player here to prevent the sink drawing while the windows * are beeing changed */ ViewModel.VideoPlayer.Pause(); if (!detachedPlayer) { Log.Debug("Detaching player"); ExternalWindow playerWindow = new ExternalWindow(); this.playerWindow = playerWindow; playerWindow.Title = Constants.SOFTWARE_NAME; int player_width = playercapturer.Allocation.Width; int player_height = playercapturer.Allocation.Height; playerWindow.SetDefaultSize(player_width, player_height); playerWindow.DeleteEvent += (o, args) => DetachPlayer(); playerWindow.Show(); playercapturer.Reparent(playerWindow.Box); // Hack to reposition video window in widget for OSX playerWindow.Resize(player_width + 10, player_height); videowidgetsbox.Visible = false; playsSelection.ExpandTabs = true; } else { Log.Debug("Attaching player again"); videowidgetsbox.Visible = true; playercapturer.Reparent(this.videowidgetsbox); playerWindow.Destroy(); playsSelection.ExpandTabs = false; } if (isPlaying) { ViewModel.VideoPlayer.Play(); } detachedPlayer = !detachedPlayer; playercapturer.AttachPlayer(detachedPlayer); }
void StartCapture() { Hide(); ExternalWindow?.Hide(); StatusImageSize.Text = ""; // make sure windows actually hides before we wait WindowUtilities.DoEvents(); // Display counter if (CaptureDelaySeconds > 0) { IsPreviewCapturing = true; Cancelled = false; var counterForm = new ScreenOverlayCounter(); try { counterForm.Show(); counterForm.Topmost = true; counterForm.SetWindowText("1"); for (int i = CaptureDelaySeconds; i > 0; i--) { counterForm.SetWindowText(i.ToString()); WindowUtilities.DoEvents(); for (int j = 0; j < 100; j++) { Thread.Sleep(10); WindowUtilities.DoEvents(); } if (Cancelled) { CancelCapture(true); return; } } } finally { counterForm.Close(); IsPreviewCapturing = false; Cancelled = true; } } IsMouseClickCapturing = true; Desktop = new ScreenOverlayDesktop(this); Desktop.SetDesktop(IncludeCursor); Desktop.Show(); WindowUtilities.DoEvents(); Overlay = new ScreenClickOverlay(this) { Width = 0, Height = 0 }; Overlay.Show(); LastWindow = null; CaptureTimer = new Timer(Capture, null, 0, 200); }
private void tbSave_Click(object sender, RoutedEventArgs e) { if (CapturedBitmap == null) { return; } if (string.IsNullOrEmpty(SaveFolder)) { SaveFolder = Path.GetTempPath(); } var link = FileSaver.SaveBitmapAndLinkInEditor(CapturedBitmap, noEditorEmbedding: true); if (link == null) { StatusBar.ShowStatusError("Failed to save the active image."); return; } SavedImageFile = link; ////var sd = new SaveFileDialog ////{ //// Filter = "png files (*.png)|*.png|jpg files (*.jpg)|*.jpg", //// FilterIndex = 1, //// FileName = "", //// CheckFileExists = false, //// OverwritePrompt = false, //// AutoUpgradeEnabled = true, //// CheckPathExists = true, //// InitialDirectory = SaveFolder, //// RestoreDirectory = true ////}; ////var result = sd.ShowDialog(); ////if (result != System.Windows.Forms.DialogResult.OK) //// return; ////var ext = Path.GetExtension(sd.FileName); ////SavedImageFile = sd.FileName; ////try ////{ //// if (ext == ".jpg" || ext == "jpeg") //// mmImageUtils.SaveJpeg(CapturedBitmap, SavedImageFile, //// mmApp.Configuration.Images.JpegImageCompressionLevel); //// else //// CapturedBitmap.Save(SavedImageFile); //// if (ext == ".png" || ext == ".jpeg" || ext == ".jpg") //// mmFileUtils.OptimizeImage(sd.FileName); // async ////} ////catch (Exception ex) ////{ //// Cancelled = true; //// StatusBar.ShowStatusError("Error saving image: " + ex.Message); //// return; ////} if (!string.IsNullOrEmpty(ResultFilePath)) { File.WriteAllText(ResultFilePath, SavedImageFile); } Cancelled = false; if (AutoClose) { Close(); } ExternalWindow?.Show(); ExternalWindow?.Activate(); if (WindowState != WindowState.Maximized && WindowState != WindowState.Minimized) { ScreenCaptureConfiguration.Current.WindowWidth = this.Width; ScreenCaptureConfiguration.Current.WindowHeight = this.Width; } }