void Capture(object obj) { Point pt = GetMousePosition(); CurWindow = new WindowInfo(ScreenCapture.WindowFromPoint(new System.Drawing.Point((int)pt.X, (int)pt.Y))); Dispatcher.Invoke(() => { if (LastWindow == null || !CurWindow.Handle.Equals(LastWindow.Handle)) { if (CurWindow.Handle != WindowHandle && CurWindow.Rect.Width <= Screen.FromHandle(CurWindow.Handle).Bounds.Width&& // don't capture dual window desktop Overlay != null) { // WPF Windows use DPI Aware pixes for the desktop - adjust for raw pixels var dpiRatio = (double)WindowUtilities.GetDpiRatio(CurWindow.Handle); Overlay.Left = CurWindow.Rect.X / dpiRatio; Overlay.Top = CurWindow.Rect.Y / dpiRatio; Overlay.Width = CurWindow.Rect.Width / dpiRatio; Overlay.Height = CurWindow.Rect.Height / dpiRatio; Overlay.SetWindowText($"{(int) Overlay.Width}x{(int) Overlay.Height}"); } } LastWindow = CurWindow; }); }
/// <summary> /// Restyles the current editor with configuration settings /// from the mmApp.Configuration object (or Model.Configuration /// from an addin). /// </summary> public void RestyleEditor() { try { // determine if we want to rescale the editor fontsize // based on DPI Screen Size var dpiRatio = WindowUtilities.GetDpiRatio(Window); AceEditor.settheme( mmApp.Configuration.EditorTheme, mmApp.Configuration.EditorFont, mmApp.Configuration.EditorFontSize * dpiRatio, mmApp.Configuration.EditorWrapText, mmApp.Configuration.EditorHighlightActiveLine, mmApp.Configuration.EditorShowLineNumbers); if (EditorSyntax == "markdown" || this.EditorSyntax == "text") { AceEditor.enablespellchecking(!mmApp.Configuration.EditorEnableSpellcheck, mmApp.Configuration.EditorDictionary); } else { // always disable for non-markdown text AceEditor.enablespellchecking(true, mmApp.Configuration.EditorDictionary); } } catch { } }
/// <summary> /// Gets a JSON string of all the settings that are exported to the /// ACE Editor instance when styling the editor. /// /// This object is passed down to ACE which can then uses these settings /// to update the editor styling in `setEditorStyle` and also with /// a few additional settings. /// </summary> /// <returns>JSON string of all settings set by the editor</returns> public static string GetJsonStyleInfo() { // determine if we want to rescale the editor fontsize // based on DPI Screen Size decimal dpiRatio = 1; try { dpiRatio = WindowUtilities.GetDpiRatio(mmApp.Model.Window); } catch { } var fontSize = mmApp.Configuration.Editor.FontSize * ((decimal)mmApp.Configuration.Editor.ZoomLevel / 100) * dpiRatio; var config = mmApp.Configuration; // CenteredModeMaxWidth is rendered based on Centered Mode only int maxWidth = config.Editor.CenteredModeMaxWidth; if (!config.Editor.CenteredMode) { maxWidth = 0; // 0 means stretch full width } var style = new { Theme = config.EditorTheme, FontSize = (int)fontSize, MaxWidth = maxWidth * dpiRatio, config.Editor.Font, config.Editor.LineHeight, config.Editor.Padding, config.Editor.HighlightActiveLine, config.Editor.WrapText, config.Editor.ShowLineNumbers, config.Editor.ShowInvisibles, config.Editor.ShowPrintMargin, config.Editor.PrintMargin, config.Editor.WrapMargin, config.Editor.KeyboardHandler, config.Editor.EnableBulletAutoCompletion, config.Editor.TabSize, config.Editor.UseSoftTabs, config.PreviewSyncMode, RightToLeft = config.Editor.EnableRightToLeft, config.Editor.ClickableLinks, LinefeedMode = (config.Editor.LinefeedMode == Configuration.LinefeedModes.CrLf ? "windows" : "unix") }; var settings = new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), }; var json = JsonConvert.SerializeObject(style, settings); return(json); }
/// <summary> /// Restyles the current editor with configuration settings /// from the mmApp.Configuration object (or Model.Configuration /// from an addin). /// </summary> /// <param name="forceSync">Forces higher priority on this operation - use when editor initializes at first</param> public void RestyleEditor(bool forceSync = false) { if (AceEditor == null) { return; } Window.Dispatcher.InvokeAsync(() => { try { // determine if we want to rescale the editor fontsize // based on DPI Screen Size decimal dpiRatio = 1; try { dpiRatio = WindowUtilities.GetDpiRatio(Window); } catch { } AceEditor.settheme( mmApp.Configuration.EditorTheme, mmApp.Configuration.EditorFont, mmApp.Configuration.EditorFontSize * dpiRatio, mmApp.Configuration.EditorWrapText, mmApp.Configuration.EditorHighlightActiveLine, mmApp.Configuration.EditorKeyboardHandler); if (EditorSyntax == "markdown" || this.EditorSyntax == "text") { AceEditor.enablespellchecking(!mmApp.Configuration.EditorEnableSpellcheck, mmApp.Configuration.EditorDictionary); } else { // always disable for non-markdown text AceEditor.enablespellchecking(true, mmApp.Configuration.EditorDictionary); } } catch { } }, forceSync ? System.Windows.Threading.DispatcherPriority.Send : System.Windows.Threading.DispatcherPriority.ApplicationIdle); }
/// <summary> /// Restyles the current editor with configuration settings /// from the mmApp.Configuration object (or Model.Configuration /// from an addin). /// </summary> public void RestyleEditor() { if (AceEditor == null) { return; } try { // determine if we want to rescale the editor fontsize // based on DPI Screen Size decimal dpiRatio = 1; try { var window = VisualTreeHelper.GetParent(WebBrowser); while (!(window is Window)) { window = VisualTreeHelper.GetParent(window); } dpiRatio = WindowUtilities.GetDpiRatio(window as Window); } catch { } AceEditor.settheme( mmApp.Configuration.EditorTheme, mmApp.Configuration.EditorFont, mmApp.Configuration.EditorFontSize * dpiRatio, mmApp.Configuration.EditorWrapText, mmApp.Configuration.EditorHighlightActiveLine, mmApp.Configuration.EditorShowLineNumbers, mmApp.Configuration.EditorKeyboardHandler); if (EditorSyntax == "markdown" || this.EditorSyntax == "text") { AceEditor.enablespellchecking(!mmApp.Configuration.EditorEnableSpellcheck, mmApp.Configuration.EditorDictionary); } else { // always disable for non-markdown text AceEditor.enablespellchecking(true, mmApp.Configuration.EditorDictionary); } } catch { } }
public void SetDesktop(bool includeCursor = false) { var handle = ScreenCapture.GetDesktopWindow(); Bitmap = ScreenCapture.CaptureWindowBitmap(handle); if (includeCursor) { var MousePointerInfo = ScreenCapture.GetMousePointerInfo(); ScreenCapture.DrawMousePointer(MousePointerInfo, Bitmap); } var dpiRatio = (double)WindowUtilities.GetDpiRatio(handle); Left = 0; Top = 0; Width = Bitmap.Width / dpiRatio; Height = Bitmap.Height / dpiRatio; DesktopImage.Source = ScreenCapture.BitmapToBitmapSource(Bitmap); }
/// <summary> /// Restyles the current editor with configuration settings /// from the mmApp.Configuration object (or Model.Configuration /// from an addin). /// </summary> public void RestyleEditor() { if (AceEditor == null) { return; } try { // determine if we want to rescale the editor fontsize // based on DPI Screen Size decimal dpiRatio = 1; try { var window = VisualTreeHelper.GetParent(WebBrowser); while (!(window is Window)) { window = VisualTreeHelper.GetParent(window); } dpiRatio = WindowUtilities.GetDpiRatio(window as Window); } catch { } AceEditor.SetEditorStyling(); if (EditorSyntax == "markdown" || this.EditorSyntax == "text") { AceEditor.EnableSpellChecking(!mmApp.Configuration.Editor.EnableSpellcheck, mmApp.Configuration.Editor.Dictionary); } else { // always disable for non-markdown text AceEditor.EnableSpellChecking(false, mmApp.Configuration.Editor.Dictionary); } } catch { } }
private void ButtonWindowResize_Click(object sender, RoutedEventArgs e) { var model = Window.Model; var size = ((MenuItem)sender).Header as string; var tokens = size.Split('x'); Window.Width = double.Parse(tokens[0].Trim()); Window.Height = double.Parse(tokens[1].Trim()); if (model.ActiveEditor?.EditorPreviewPane != null) { var width = model.ActiveEditor.EditorPreviewPane.ActualWidth; if (width < 2000 && width > 800) { model.ActiveEditor.EditorPreviewPane.EditorWebBrowserEditorColumn.Width = GridLengthHelper.Star; if (model.Configuration.IsPreviewVisible) { model.ActiveEditor.EditorPreviewPane.EditorWebBrowserPreviewColumn.Width = new GridLength(width * 0.45); } } else if (width > 2000) { Window.ShowLeftSidebar(); if (model.ActiveEditor.EditorPreviewPane.EditorWebBrowserPreviewColumn.Width.Value < 750 && model.Configuration.IsPreviewVisible) { model.ActiveEditor.EditorPreviewPane.EditorWebBrowserPreviewColumn.Width = new GridLength(750); } } else if (width <= 900) { Window.ShowLeftSidebar(hide: true); WindowUtilities.DoEvents(); width = model.ActiveEditor.EditorPreviewPane.ActualWidth; model.ActiveEditor.EditorPreviewPane.EditorWebBrowserEditorColumn.Width = GridLengthHelper.Star; if (model.Configuration.IsPreviewVisible) { model.ActiveEditor.EditorPreviewPane.EditorWebBrowserPreviewColumn.Width = new GridLength(width * 0.45); } } } var screen = Screen.FromHandle(Window.Hwnd); var ratio = (double)WindowUtilities.GetDpiRatio(Window.Hwnd); var windowWidth = screen.Bounds.Width * ratio; var windowHeight = screen.Bounds.Height * ratio; if (windowWidth < Window.Width || windowHeight < Window.Height) { Window.Top = screen.Bounds.Y * ratio; Window.Left = screen.Bounds.X * ratio; Window.Width = windowWidth - 20; Window.Height = windowHeight - 40; } if (windowWidth < Window.Width + Window.Left || windowHeight < Window.Height + Window.Top) { WindowUtilities.CenterWindow(Window); } }