示例#1
0
        private bool UpdatePositioning(bool onLoad = true)
        {
            var top    = onLoad ? UserSettings.All.StartupTop : Top;
            var left   = onLoad ? UserSettings.All.StartupLeft : Left;
            var width  = onLoad ? UserSettings.All.StartupWidth : Width;
            var height = onLoad ? UserSettings.All.StartupHeight : Height;
            var state  = onLoad ? UserSettings.All.StartupWindowState : WindowState;

            //If the position was never set, let it center on screen.
            if (double.IsNaN(top) && double.IsNaN(left))
            {
                return(false);
            }

            //The catch here is to get the closest monitor from current Top/Left point.
            var monitors = Monitor.AllMonitorsScaled(this.Scale());
            var closest  = monitors.FirstOrDefault(x => x.Bounds.Contains(new Point((int)left, (int)top))) ?? monitors.FirstOrDefault(x => x.IsPrimary);

            if (closest == null)
            {
                return(false);
            }

            //To much to the Left.
            if (closest.WorkingArea.Left > left + width - 100)
            {
                left = closest.WorkingArea.Left;
            }

            //Too much to the top.
            if (closest.WorkingArea.Top > top + height - 100)
            {
                top = closest.WorkingArea.Top;
            }

            //Too much to the right.
            if (closest.WorkingArea.Right < left + 100)
            {
                left = closest.WorkingArea.Right - width;
            }

            //Too much to the bottom.
            if (closest.WorkingArea.Bottom < top + 100)
            {
                top = closest.WorkingArea.Bottom - height;
            }

            Top         = top;
            Left        = left;
            Width       = width;
            Height      = height;
            WindowState = state;

            return(true);
        }
示例#2
0
        private void HyperlinkMove_Click(object sender, RoutedEventArgs e)
        {
            var monitor = Monitor.AllMonitorsScaled(this.Scale()).FirstOrDefault(f => f.IsPrimary);

            if (monitor == null)
            {
                //Uh-oh.
                return;
            }

            //Move all windows to the main monitor.
            foreach (var window in Application.Current.Windows.OfType <Window>().Where(w => w.GetType() != typeof(Troubleshoot)).OrderBy(o => o.Width).ThenBy(o => o.Height))
            {
                var top    = window.Top;
                var left   = window.Left;
                var width  = window.ActualWidth;
                var height = window.ActualHeight;

                //Pause any active recording...
                if (window is RecorderNew newRecorder)
                {
                    if (newRecorder.Stage == Stage.Recording)
                    {
                        newRecorder.RecordPause();
                    }

                    //I need to adjust to the Left/Top Bounds since the recorder ocupies the all windows.

                    top    = Canvas.GetTop(newRecorder.MainBorder) + newRecorder.Top;
                    left   = Canvas.GetLeft(newRecorder.MainBorder) + newRecorder.Left;
                    width  = newRecorder.MainBorder.ActualWidth;
                    height = newRecorder.MainBorder.ActualHeight;

                    if (monitor.Bounds.Top > top)
                    {
                        top = monitor.Bounds.Top;
                    }

                    if (monitor.Bounds.Left > left)
                    {
                        left = monitor.Bounds.Left;
                    }

                    if (monitor.Bounds.Bottom < top + height)
                    {
                        top = monitor.Bounds.Bottom - height;
                    }

                    if (monitor.Bounds.Right < left + width)
                    {
                        left = monitor.Bounds.Right - width;
                    }

                    Canvas.SetTop(newRecorder.MainBorder, top - newRecorder.Top);
                    Canvas.SetLeft(newRecorder.MainBorder, left - newRecorder.Left);

                    continue;
                }

                if (window is Recorder recorder)
                {
                    if (recorder.Stage == Stage.Recording)
                    {
                        recorder.RecordPause();
                    }
                }

                if (monitor.Bounds.Top > top)
                {
                    top = monitor.Bounds.Top;
                }

                if (monitor.Bounds.Left > left)
                {
                    left = monitor.Bounds.Left;
                }

                if (monitor.Bounds.Bottom < top + height)
                {
                    top = monitor.Bounds.Bottom - height;
                }

                if (monitor.Bounds.Right < left + width)
                {
                    left = monitor.Bounds.Right - width;
                }

                window.Top         = top;
                window.Left        = left;
                window.WindowState = WindowState.Normal;
                //window.Width = width;
                //window.Height = height;
            }

            DetectMonitors();
        }
示例#3
0
        private bool UpdatePositioning(bool onLoad = true)
        {
            var top    = onLoad ? UserSettings.All.StartupTop : Top;
            var left   = onLoad ? UserSettings.All.StartupLeft : Left;
            var width  = onLoad ? UserSettings.All.StartupWidth : Width;
            var height = onLoad ? UserSettings.All.StartupHeight : Height;
            var state  = onLoad ? UserSettings.All.StartupWindowState : WindowState;

            //If the position was never set, let it center on screen.
            if (double.IsNaN(top) && double.IsNaN(left))
            {
                return(false);
            }

            //The catch here is to get the closest monitor from current Top/Left point.
            var monitors = Monitor.AllMonitorsScaled(this.Scale());
            var closest  = monitors.FirstOrDefault(x => x.Bounds.Contains(new Point((int)left, (int)top))) ?? monitors.FirstOrDefault(x => x.IsPrimary);

            if (closest == null)
            {
                return(false);
            }

            //To much to the Left.
            if (closest.WorkingArea.Left > left + width - 100)
            {
                left = closest.WorkingArea.Left;
            }

            //Too much to the top.
            if (closest.WorkingArea.Top > top + height - 100)
            {
                top = closest.WorkingArea.Top;
            }

            //Too much to the right.
            if (closest.WorkingArea.Right < left + 100)
            {
                left = closest.WorkingArea.Right - width;
            }

            //Too much to the bottom.
            if (closest.WorkingArea.Bottom < top + 100)
            {
                top = closest.WorkingArea.Bottom - height;
            }

            if (top > int.MaxValue || top < int.MinValue || left > int.MaxValue || left < int.MinValue ||
                width > int.MaxValue || width < int.MinValue || height > int.MaxValue || height < int.MinValue)
            {
                var desc = $"On load: {onLoad}\nScale: {this.Scale()}\n\n" +
                           $"Screen: {closest.AdapterName}\nBounds: {closest.Bounds}\n\nTopLeft: {top}x{left}\nWidthHeight: {width}x{height}\n\n" +
                           $"TopLeft Settings: {UserSettings.All.StartupTop}x{UserSettings.All.StartupLeft}\nWidthHeight Settings: {UserSettings.All.StartupWidth}x{UserSettings.All.StartupHeight}";
                LogWriter.Log("Wrong Startup window sizing", desc);
                return(false);
            }

            Top         = top;
            Left        = left;
            Width       = width;
            Height      = height;
            WindowState = state;

            return(true);
        }
示例#4
0
        private void DetectMonitors()
        {
            var monitors  = Monitor.AllMonitorsScaled(this.Scale());
            var minLeft   = monitors.Min(m => m.Bounds.Left);
            var minTop    = monitors.Min(m => m.Bounds.Top);
            var maxRight  = monitors.Max(m => m.Bounds.Right);
            var maxBottom = monitors.Max(m => m.Bounds.Bottom);

            MainCanvas.Children.Clear();

            if (NowRadioButton.IsChecked == true)
            {
                foreach (var window in Application.Current.Windows.OfType <Window>().Where(w => w.GetType() != typeof(Troubleshoot) && w.IsVisible).OrderBy(o => o.Width).ThenBy(o => o.Height))
                {
                    var top    = window.Top;
                    var left   = window.Left;
                    var width  = window.ActualWidth;
                    var height = window.ActualHeight;
                    var title  = window.Title.Remove("ScreenToGif - ");

                    if (window is RecorderNew newRecorder)
                    {
                        top    = Canvas.GetTop(newRecorder.MainBorder) + newRecorder.Top;
                        left   = Canvas.GetLeft(newRecorder.MainBorder) + newRecorder.Left;
                        width  = newRecorder.MainBorder.ActualWidth;
                        height = newRecorder.MainBorder.ActualHeight;
                        title  = LocalizationHelper.Get("Recorder");
                    }

                    minLeft   = Math.Min(minLeft, left);
                    minTop    = Math.Min(minTop, top);
                    maxRight  = Math.Max(maxRight, left + width);
                    maxBottom = Math.Max(maxBottom, top + height);

                    var rect = new Border
                    {
                        BorderBrush     = TryFindResource("Element.Border.Required") as SolidColorBrush ?? Brushes.DarkBlue,
                        BorderThickness = new Thickness(3),
                        Background      = TryFindResource("Panel.Background.Level3") as SolidColorBrush ?? Brushes.WhiteSmoke,
                        Width           = width,
                        Height          = height,
                        Tag             = "C",
                        Child           = new Viewbox
                        {
                            Child = new TextBlock
                            {
                                VerticalAlignment = VerticalAlignment.Center,
                                Padding           = new Thickness(2),
                                Text       = title,
                                Foreground = TryFindResource("Element.Foreground") as SolidColorBrush ?? Brushes.Black,
                            }
                        }
                    };

                    MainCanvas.Children.Add(rect);

                    Canvas.SetLeft(rect, left);
                    Canvas.SetTop(rect, top);
                    Panel.SetZIndex(rect, MainCanvas.Children.Count + 1);
                }
            }
            else
            {
                #region Recorder position

                if (!double.IsNaN(UserSettings.All.RecorderTop) && !double.IsNaN(UserSettings.All.RecorderLeft))
                {
                    minLeft   = Math.Min(minLeft, UserSettings.All.RecorderLeft);
                    minTop    = Math.Min(minTop, UserSettings.All.RecorderTop);
                    maxRight  = Math.Max(maxRight, UserSettings.All.RecorderLeft + UserSettings.All.RecorderWidth);
                    maxBottom = Math.Max(maxBottom, UserSettings.All.RecorderTop + UserSettings.All.RecorderHeight);

                    var rect = new Border
                    {
                        BorderBrush     = new SolidColorBrush(Colors.DarkBlue),
                        BorderThickness = new Thickness(3),
                        Background      = new SolidColorBrush(Colors.WhiteSmoke),
                        Width           = UserSettings.All.RecorderWidth,
                        Height          = UserSettings.All.RecorderHeight,
                        Tag             = "N",
                        Child           = new Viewbox
                        {
                            Child = new TextBlock
                            {
                                VerticalAlignment = VerticalAlignment.Center,
                                Padding           = new Thickness(2),
                                Text = LocalizationHelper.Get("Recorder")
                            }
                        }
                    };

                    MainCanvas.Children.Add(rect);

                    Canvas.SetLeft(rect, UserSettings.All.RecorderLeft);
                    Canvas.SetTop(rect, UserSettings.All.RecorderTop);
                }

                if (!UserSettings.All.SelectedRegion.IsEmpty)
                {
                    minLeft   = Math.Min(minLeft, UserSettings.All.SelectedRegion.Left + SystemParameters.VirtualScreenLeft);
                    minTop    = Math.Min(minTop, UserSettings.All.SelectedRegion.Top + SystemParameters.VirtualScreenTop);
                    maxRight  = Math.Max(maxRight, UserSettings.All.SelectedRegion.Right + SystemParameters.VirtualScreenLeft);
                    maxBottom = Math.Max(maxBottom, UserSettings.All.SelectedRegion.Bottom + SystemParameters.VirtualScreenTop);

                    var rect = new Border
                    {
                        BorderBrush     = TryFindResource("Element.Border.Required") as SolidColorBrush ?? Brushes.DarkBlue,
                        BorderThickness = new Thickness(3),
                        Background      = TryFindResource("Panel.Background.Level3") as SolidColorBrush ?? Brushes.WhiteSmoke,
                        Width           = UserSettings.All.SelectedRegion.Width,
                        Height          = UserSettings.All.SelectedRegion.Height,
                        Tag             = "N",
                        Child           = new Viewbox
                        {
                            Child = new TextBlock
                            {
                                VerticalAlignment = VerticalAlignment.Center,
                                Padding           = new Thickness(2),
                                Text       = LocalizationHelper.Get("Recorder") + " 2",
                                Foreground = TryFindResource("Element.Foreground") as SolidColorBrush ?? Brushes.Black,
                            }
                        }
                    };

                    MainCanvas.Children.Add(rect);

                    Canvas.SetLeft(rect, UserSettings.All.SelectedRegion.Left + SystemParameters.VirtualScreenLeft);
                    Canvas.SetTop(rect, UserSettings.All.SelectedRegion.Top + SystemParameters.VirtualScreenTop);
                }

                #endregion

                if (!double.IsNaN(UserSettings.All.EditorTop) && !double.IsNaN(UserSettings.All.EditorLeft))
                {
                    minLeft   = Math.Min(minLeft, UserSettings.All.EditorLeft);
                    minTop    = Math.Min(minTop, UserSettings.All.EditorTop);
                    maxRight  = Math.Max(maxRight, UserSettings.All.EditorLeft + UserSettings.All.EditorWidth);
                    maxBottom = Math.Max(maxBottom, UserSettings.All.EditorTop + UserSettings.All.EditorHeight);

                    var rect = new Border
                    {
                        BorderBrush     = TryFindResource("Element.Border.Required") as SolidColorBrush ?? Brushes.DarkBlue,
                        BorderThickness = new Thickness(3),
                        Background      = TryFindResource("Panel.Background.Level3") as SolidColorBrush ?? Brushes.WhiteSmoke,
                        Width           = UserSettings.All.EditorWidth,
                        Height          = UserSettings.All.EditorHeight,
                        Tag             = "N",
                        Child           = new Viewbox
                        {
                            Child = new TextBlock
                            {
                                VerticalAlignment = VerticalAlignment.Center,
                                Padding           = new Thickness(2),
                                Text       = LocalizationHelper.Get("Editor"),
                                Foreground = TryFindResource("Element.Foreground") as SolidColorBrush ?? Brushes.Black,
                            }
                        }
                    };

                    MainCanvas.Children.Add(rect);

                    Canvas.SetLeft(rect, UserSettings.All.EditorLeft);
                    Canvas.SetTop(rect, UserSettings.All.EditorTop);
                }

                if (!double.IsNaN(UserSettings.All.StartupTop) && !double.IsNaN(UserSettings.All.StartupLeft))
                {
                    minLeft   = Math.Min(minLeft, UserSettings.All.StartupLeft);
                    minTop    = Math.Min(minTop, UserSettings.All.StartupTop);
                    maxRight  = Math.Max(maxRight, UserSettings.All.StartupLeft + UserSettings.All.StartupWidth);
                    maxBottom = Math.Max(maxBottom, UserSettings.All.StartupTop + UserSettings.All.StartupHeight);

                    var rect = new Border
                    {
                        BorderBrush     = TryFindResource("Element.Border.Required") as SolidColorBrush ?? Brushes.DarkBlue,
                        BorderThickness = new Thickness(3),
                        Background      = TryFindResource("Panel.Background.Level3") as SolidColorBrush ?? Brushes.WhiteSmoke,
                        Width           = UserSettings.All.StartupWidth,
                        Height          = UserSettings.All.StartupHeight,
                        Tag             = "N",
                        Child           = new Viewbox
                        {
                            Child = new TextBlock
                            {
                                VerticalAlignment = VerticalAlignment.Center,
                                Padding           = new Thickness(2),
                                Text       = (LocalizationHelper.Get("Title.StartUp") ?? "").Remove("ScreenToGif - "),
                                Foreground = TryFindResource("Element.Foreground") as SolidColorBrush ?? Brushes.Black,
                            }
                        }
                    };

                    MainCanvas.Children.Add(rect);

                    Canvas.SetLeft(rect, UserSettings.All.StartupLeft);
                    Canvas.SetTop(rect, UserSettings.All.StartupTop);
                }

                int index = 1;
                foreach (var border in MainCanvas.Children.OfType <Border>().OrderBy(o => o.ActualWidth).ThenBy(t => t.ActualHeight))
                {
                    Panel.SetZIndex(border, index++);
                }
            }

            CurrentTextBlock.IsEnabled = MainCanvas.Children.OfType <Border>().Count(c => (string)c.Tag == "C") > 0;
            NextTextBlock.IsEnabled    = MainCanvas.Children.OfType <Border>().Count(c => (string)c.Tag == "N") > 0;

            foreach (var monitor in monitors)
            {
                var rect = new Rectangle
                {
                    Stroke          = TryFindResource("Element.Foreground") as SolidColorBrush ?? Brushes.Black,
                    Fill            = monitor.IsPrimary ? TryFindResource("Element.Background.Checked") as SolidColorBrush ?? Brushes.LightBlue : TryFindResource("Element.Background.Hover") as SolidColorBrush ?? Brushes.LightGray,
                    Width           = monitor.Bounds.Width,
                    Height          = monitor.Bounds.Height,
                    StrokeThickness = 6,
                };

                MainCanvas.Children.Add(rect);

                Canvas.SetLeft(rect, monitor.Bounds.Left);
                Canvas.SetTop(rect, monitor.Bounds.Top);
                Panel.SetZIndex(rect, 1);
            }

            MainCanvas.SizeChanged += (args, o) => SetViewPort(MainCanvas, minLeft, maxRight, minTop, maxBottom);
            MainCanvas.Width        = Math.Abs(minLeft) + Math.Abs(maxRight);
            MainCanvas.Height       = Math.Abs(minTop) + Math.Abs(maxBottom);
        }