예제 #1
0
        private bool UpdatePositioning(bool startup = false)
        {
            var top  = UserSettings.All.RecorderTop;
            var left = UserSettings.All.RecorderLeft;

            //If the position was never set.
            if (double.IsNaN(top) || double.IsNaN(left))
            {
                //Let it center on screen when the window is loading.
                if (startup)
                {
                    return(false);
                }

                //Let the code below decide where to position the screen.
                top  = 0;
                left = 0;
            }

            //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 System.Windows.Point((int)left, (int)top))) ?? monitors.FirstOrDefault(x => x.IsPrimary) ?? monitors.FirstOrDefault();

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

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

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

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

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

            Top  = UserSettings.All.RecorderTop = top;
            Left = UserSettings.All.RecorderLeft = left;

            return(true);
        }
예제 #2
0
        private bool UpdatePositioning()
        {
            if (UserSettings.All.RecorderLeft > -0.77 && UserSettings.All.RecorderLeft < -0.75)
            {
                return(false);
            }

            //The catch here is to get the closest monitor from current Top/Left point.
            var monitors = Monitor.AllMonitorsScaled(_scale);
            var closest  = monitors.FirstOrDefault(x => x.Bounds.Contains(new System.Windows.Point((int)UserSettings.All.RecorderLeft, (int)UserSettings.All.RecorderTop))) ?? monitors.FirstOrDefault(x => x.IsPrimary);

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

            //Too much to the right.
            if (closest.WorkingArea.Left + (UserSettings.All.RecorderLeft + UserSettings.All.RecorderWidth) < 120)
            {
                UserSettings.All.RecorderLeft = SystemParameters.WorkArea.Left;
            }

            //Too much to the top.
            if (closest.WorkingArea.Top + (UserSettings.All.RecorderTop + UserSettings.All.RecorderHeight) < 120)
            {
                UserSettings.All.RecorderTop = SystemParameters.WorkArea.Top;
            }

            //Too much to the right.
            if (UserSettings.All.RecorderWidth + UserSettings.All.RecorderLeft - closest.WorkingArea.Right > 120)
            {
                UserSettings.All.RecorderLeft = SystemParameters.WorkArea.Right - UserSettings.All.RecorderWidth;
            }

            //Too much to the bottom.
            if (UserSettings.All.RecorderHeight + UserSettings.All.RecorderTop - closest.WorkingArea.Bottom > 120)
            {
                UserSettings.All.RecorderTop = SystemParameters.WorkArea.Bottom - UserSettings.All.RecorderHeight;
            }

            return(true);
        }