Ejemplo n.º 1
0
        /// <overloads>
        /// Initializes a new instance of the <see cref="WpfDrawingSettings"/> class.
        /// </overloads>
        /// <summary>
        /// Initializes a new instance of the <see cref="WpfDrawingSettings"/> class
        /// with the default parameters and settings.
        /// </summary>
        public WpfDrawingSettings()
        {
            _defaultFontName = "Arial";
            _textAsGeometry  = false;
            _optimizePath    = true;
            _includeRuntime  = true;
            _neutralCulture  = CultureInfo.GetCultureInfo("en-us");
            _culture         = CultureInfo.GetCultureInfo("en-us");

            _pixelWidth  = -1;
            _pixelHeight = -1;

            _ensureViewboxSize     = false;
            _ensureViewboxPosition = true;
            _ignoreRootViewbox     = false;
            _wpfVisitors           = new WpfVisitors();
            _properties            = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            _fontSynch       = new object();
            _fontLocations   = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            _fontFamilyNames = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            _fontFamilyMap   = new Dictionary <string, IList <FontFamily> >(StringComparer.OrdinalIgnoreCase);
            _cssVariables    = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            _dpiScale = DpiUtilities.GetSystemScale();
        }
        public static Tuple <double, double, double, double> GetWorkingAreaInSystemScale(Window window)
        {
            var dpiScale    = DpiUtilities.GetSystemScale();
            var workingArea = GetWorkingArea(window);

            return(new Tuple <double, double, double, double>(workingArea.Item1 / dpiScale.X,
                                                              workingArea.Item2 / dpiScale.Y,
                                                              workingArea.Item3 / dpiScale.X,
                                                              workingArea.Item4 / dpiScale.Y));
        }
        public static void PositionWindowOnScreen(Window window, System.Windows.Forms.Screen screen, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment)
        {
            var workingArea = screen.WorkingArea;
            var dpiScale    = DpiUtilities.GetSystemScale();

            double workingLeft   = workingArea.Left / dpiScale.X;
            double workingWidth  = workingArea.Width / dpiScale.X;
            double workingTop    = workingArea.Top / dpiScale.Y;
            double workingHeight = workingArea.Height / dpiScale.Y;

            PositionWindow(window, workingLeft, workingTop, workingWidth, workingHeight, horizontalAlignment, verticalAlignment);
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates an Image object containing a screen shot of a specific window
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static Bitmap CaptureWindowRegion(IntPtr hWnd, int x, int y, int width, int height)
        {
            Bitmap bmCapture = null;
            var    dpiScale  = DpiUtilities.GetSystemScale();

            if (width > 0 && height > 0)
            {
                IntPtr ptrWindowDc = NativeMethods.GetWindowDC(hWnd);
                bmCapture = new Bitmap(width, height,
                                       System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                bmCapture.MakeTransparent();
                Graphics g      = Graphics.FromImage(bmCapture);
                IntPtr   hdcPtr = g.GetHdc();

                NativeMethods.BitBlt(hdcPtr, 0, 0, width, height, ptrWindowDc, x,
                                     y, NativeMethods.TernaryRasterOperations.SRCCOPY | NativeMethods.TernaryRasterOperations.CAPTUREBLT);
                bmCapture.SetResolution((float)(96.0 * dpiScale.X), (float)(96.0 * dpiScale.Y));

                g.ReleaseHdc();
                NativeMethods.ReleaseDC(IntPtr.Zero, ptrWindowDc);
                g.Dispose();
            }
            return(bmCapture);
        }