internal void OnLoaded(object sender, RoutedEventArgs e)
        {
            LayoutUtilities.RestoreWindowLocation(this, UserSettings.MainWindowLocation);

            // Both acetate layer and media capture should use the same Timer instance. The timer instancce is global in app manager and never destroyed.
            CompositionTarget.Rendering += OnRendering;
            this.Loaded -= OnLoaded;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            timer          = new DispatcherTimer();
            timer.Interval = timerInterval;
            timer.Tick    += timer_Tick;

            // MoveNext starts the timer
            MoveNext();
            LayoutUtilities.PositionWindowOnPrimaryWorkingArea(this, HorizontalAlignment.Center, VerticalAlignment.Center);
        }
Exemple #3
0
        private void PositionWindow()
        {
            _isRepositioning = true;   // suppress processing of LocationChanged events

            // Default tool position
            LayoutUtilities.PositionWindowOnPrimaryWorkingAreaWithOffsetIngnoringSystemDPI(this, HorizontalAlignment.Right, VerticalAlignment.Top, 0.0f, 100.0f);

            // Now, raise LocationChanged event to do final repositioning
            this.OnLocationChanged(new EventArgs());
        }
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            UserSettings.MainWindowLocation = LayoutUtilities.SaveWindowLocationToString(this);

            if (!MainWindowClosedBySystem)
            {
                e.Cancel = true;
                AppManager.TheBoss.CloseMainWindow();
            }
        }
Exemple #5
0
        private void Window_LocationChanged(object sender, EventArgs e)
        {
            if (!_isRepositioning)
            {
                // Position was changed by Windows, e.g. due to screen resizing or app reloading
                // Snap to screen boundaries
                _isRepositioning = true;
                var scale = LayoutUtilities.GetDpiScale(this);
                scale = DpiUtilities.GetSystemScale();
                scale = SystemScale;
                var screen = System.Windows.Forms.Screen.FromPoint(new System.Drawing.Point((int)Left, (int)Top));
                Left = Math.Min(Math.Max(Left, screen.WorkingArea.Left / scale.X), screen.WorkingArea.Right / scale.X - ActualWidth);
                Top  = Math.Min(Math.Max(Top, screen.WorkingArea.Top / scale.Y), screen.WorkingArea.Bottom / scale.Y - ActualHeight);

                // Make sure docking state is correct
                var dockState = ToolsDockState(scale, screen);
                Trace.WriteLine("Window position changed, new position: (" + Left + ", " + Top + "), Current dock state:" + _currentDockState + ", Dock state for position:" + dockState);
                if (dockState != _currentDockState)
                {
                    // Adjust tool window position to match the old dock state
                    switch (_currentDockState)
                    {
                    case DockState.Top:
                        Top = screen.WorkingArea.Top / scale.Y;
                        break;

                    case DockState.Left:
                        Left = screen.WorkingArea.Left / scale.X;
                        break;

                    case DockState.Right:
                        Left = screen.WorkingArea.Right / scale.X - ActualWidth;
                        break;

                    case DockState.Bottom:
                        Top = screen.WorkingArea.Bottom / scale.Y - ActualHeight;
                        break;

                    case DockState.Middle:
                        Left = (screen.WorkingArea.Left + screen.WorkingArea.Right) / 2 / scale.X - ActualWidth / 2;
                        Top  = (screen.WorkingArea.Top + screen.WorkingArea.Bottom) / 2 / scale.Y - ActualHeight / 2;
                        break;
                    }
                    Trace.WriteLine("Adjusted dockState:" + _currentDockState + ", adjusted position: (" + Left + ", " + Top + ")");
                }
                _isRepositioning = false;

                Settings.Default.ToolDocking  = _currentDockState.ToString();
                Settings.Default.ToolPosition = new System.Drawing.Point((int)Left, (int)Top);
                Settings.Default.Save();
            }
        }
        private void Window_MouseMove(object sender, MouseEventArgs e)
        {
            if (_dragging && e.LeftButton == MouseButtonState.Pressed)
            {
                // Get the current mouse position
                Point  mousePos = e.GetPosition(null);
                Vector diff     = mousePos - _startPoint;

                // Snap to screen boundaries
                _isRepositioning = true;
                var scale = LayoutUtilities.GetDpiScale(this);
                scale = DpiUtilities.GetSystemScale();
                scale = SystemScale;
                //scale = new DpiScale();
                var screen = System.Windows.Forms.Screen.FromPoint(System.Windows.Forms.Control.MousePosition);
                System.Diagnostics.Debug.WriteLine("Screen.Left = " + screen.WorkingArea.Left.ToString());
                Left = Math.Min(Math.Max(Left + diff.X, screen.WorkingArea.Left / scale.X), screen.WorkingArea.Right / scale.X - ActualWidth);
                Top  = Math.Min(Math.Max(Top + diff.Y, screen.WorkingArea.Top / scale.Y), screen.WorkingArea.Bottom / scale.Y - ActualHeight);

                var dockState = ToolsDockState(scale, screen);
                if (dockState == DockState.Left || dockState == DockState.Right)
                {
                    if (dockState == DockState.Right && StackContainer.Orientation != Orientation.Vertical)
                    {
                        // Adjust for snapping to the right
                        Left          += ActualWidth - ActualHeight;
                        _startPoint.X -= ActualWidth - ActualHeight;
                    }
                }
                else
                {
                    if (_currentDockState == DockState.Right && StackContainer.Orientation != Orientation.Horizontal)
                    {
                        // Adjust for snapping from the right
                        Left          += ActualWidth - ActualHeight;
                        _startPoint.X -= ActualWidth - ActualHeight;
                    }
                }
                _isRepositioning = false;
                AdjustOrientation(dockState);
                _currentDockState = dockState;
            }
        }
        private void PositionWindow()
        {
            _isRepositioning = true;   // suppress processing of LocationChanged events
            if (Enum.TryParse(Settings.Default.ToolDocking, out _currentDockState))
            {
                // Restore last tool position
                var upperLeft = Settings.Default.ToolPosition;
                Left = upperLeft.X;
                Top  = upperLeft.Y;
                AdjustOrientation(_currentDockState);
            }
            else
            {
                // Default tool position
                LayoutUtilities.PositionWindowOnPrimaryWorkingArea(this, HorizontalAlignment.Center, VerticalAlignment.Top);
                _currentDockState = DockState.Top;
            }
            _isRepositioning = false;

            // Now, raise LocationChanged event to do final repositioning
            this.OnLocationChanged(new EventArgs());
        }
        private readonly double ThresholdToMaximize = .9; // If we are filling more than this percentage, just maximize.

        private void OptimizeSizeAndPosition(double contentWidth, double contentHeight)
        {
            if (WindowState == WindowState.Maximized)
            {
                // If Maximized, don't change...
                return;
            }

            //
            // Estimate Chrome requirements
            //

            double estimatedChromeHeight = CaptionBarHeight
                                           + contentGrid.Margin.Top + contentGrid.Margin.Bottom
                                           + 12.0; // A little buffer for padding and to be safe

            double estimatedChromeWidth = contentGrid.Margin.Left
                                          + contentGrid.Margin.Right
                                          + 8.0; // A little padding for the sides and to be safe

            //
            // Estimate Window dimensions required for unscaled content
            //

            double estimatedWindowWidth  = contentWidth + estimatedChromeWidth;
            double estimatedWindowHeight = contentHeight + estimatedChromeHeight;

            //
            // Decide the best window size given the content and available working area
            //

            var workingArea = LayoutUtilities.GetWorkingAreaInVirtualPixels(this);

            if ((estimatedWindowWidth > workingArea.Item3 * ThresholdToMaximize) ||
                (estimatedWindowHeight > workingArea.Item4 * ThresholdToMaximize))
            {
                WindowState = WindowState.Maximized;
            }
            else
            {
                if (estimatedWindowHeight <= this.Height && estimatedWindowWidth <= this.Width)
                {
                    // Just quit if the window size isn't increasing...
                    return;
                }

                if (Application.Current != null)
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                               new Action(delegate()
                    {
                        WindowState = WindowState.Normal;

                        if (estimatedWindowHeight > this.Height)
                        {
                            this.Height = estimatedWindowHeight;
                        }

                        if (estimatedWindowWidth > this.Width)
                        {
                            this.Width = estimatedWindowWidth;
                        }

                        LayoutUtilities.PositionWindowInsideCanvas(this, workingArea.Item1, workingArea.Item2, workingArea.Item3, workingArea.Item4);
                    })
                                                               );
                }
            }
        }