Пример #1
0
        /// <summary>
        /// Event raised on mouse up in the ZoomAndPanControl.
        /// </summary>
        private void OnZoomPanMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (_mouseHandlingMode != ZoomPanMouseHandlingMode.None)
            {
                if (_mouseHandlingMode == ZoomPanMouseHandlingMode.Zooming)
                {
                    if (_mouseButtonDown == MouseButton.Left)
                    {
                        // Shift + left-click zooms in on the content.
                        ZoomIn(_origContentMouseDownPoint);
                    }
                    else if (_mouseButtonDown == MouseButton.Right)
                    {
                        // Shift + left-click zooms out from the content.
                        ZoomOut(_origContentMouseDownPoint);
                    }
                }
                else if (_mouseHandlingMode == ZoomPanMouseHandlingMode.DragZooming)
                {
                    // When drag-zooming has finished we zoom in on the rectangle that was highlighted by the user.
                    ApplyDragZoomRect();
                }

                zoomPanControl.ReleaseMouseCapture();
                _mouseHandlingMode = ZoomPanMouseHandlingMode.None;
                e.Handled          = true;
            }
        }
Пример #2
0
        public DrawingPage()
        {
            InitializeComponent();

            _saveXaml                = true;
            _wpfSettings             = new WpfDrawingSettings();
            _wpfSettings.CultureInfo = _wpfSettings.NeutralCultureInfo;

            _fileReader          = new FileSvgReader(_wpfSettings);
            _fileReader.SaveXaml = _saveXaml;
            _fileReader.SaveZaml = false;

            _mouseHandlingMode = ZoomPanMouseHandlingMode.None;

            string workDir = Path.Combine(Path.GetDirectoryName(
                                              System.Reflection.Assembly.GetExecutingAssembly().Location), TemporalDirName);

            _workingDir = new DirectoryInfo(workDir);

            _embeddedImages = new List <EmbeddedImageSerializerArgs>();

            _embeddedImageVisitor = new EmbeddedImageSerializerVisitor(true);
            _wpfSettings.Visitors.ImageVisitor = _embeddedImageVisitor;

            _embeddedImageVisitor.ImageCreated += OnEmbeddedImageCreated;

            this.Loaded      += OnPageLoaded;
            this.Unloaded    += OnPageUnloaded;
            this.SizeChanged += OnPageSizeChanged;
        }
Пример #3
0
        /// <summary>
        /// Event raised on mouse down in the ZoomAndPanControl.
        /// </summary>
        private void OnZoomPanMouseDown(object sender, MouseButtonEventArgs e)
        {
            zoomPanControl.Focus();
            Keyboard.Focus(zoomPanControl);

            _mouseButtonDown = e.ChangedButton;
            _origZoomAndPanControlMouseDownPoint = e.GetPosition(zoomPanControl);
            _origContentMouseDownPoint           = e.GetPosition(svgViewer);

            if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0 &&
                (e.ChangedButton == MouseButton.Left || e.ChangedButton == MouseButton.Right))
            {
                // Shift + left- or right-down initiates zooming mode.
                _mouseHandlingMode = ZoomPanMouseHandlingMode.Zooming;
            }
            else if (_mouseButtonDown == MouseButton.Left)
            {
                // Just a plain old left-down initiates panning mode.
                _mouseHandlingMode = ZoomPanMouseHandlingMode.Panning;
            }

            if (_mouseHandlingMode != ZoomPanMouseHandlingMode.None)
            {
                // Capture the mouse so that we eventually receive the mouse up event.
                zoomPanControl.CaptureMouse();
                e.Handled = true;
            }
        }
Пример #4
0
        public DrawingPage()
        {
            InitializeComponent();

            _saveXaml                = true;
            _wpfSettings             = new WpfDrawingSettings();
            _wpfSettings.CultureInfo = _wpfSettings.NeutralCultureInfo;

            _fileReader          = new FileSvgReader(_wpfSettings);
            _fileReader.SaveXaml = _saveXaml;
            _fileReader.SaveZaml = false;

            _mouseHandlingMode = ZoomPanMouseHandlingMode.SelectPoint;

            //string workDir = Path.Combine(Path.GetDirectoryName(
            //    System.Reflection.Assembly.GetExecutingAssembly().Location), TemporalDirName);
            string workDir = Path.Combine(Path.GetFullPath("..\\"), TemporalDirName);

            _workingDir = new DirectoryInfo(workDir);

            _embeddedImages = new List <EmbeddedImageSerializerArgs>();

            _embeddedImageVisitor = new EmbeddedImageSerializerVisitor(true);
            _wpfSettings.Visitors.ImageVisitor = _embeddedImageVisitor;

            _embeddedImageVisitor.ImageCreated += OnEmbeddedImageCreated;

            textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("XML");
            TextEditorOptions options = textEditor.Options;

            if (options != null)
            {
                //options.AllowScrollBelowDocument = true;
                options.EnableHyperlinks      = true;
                options.EnableEmailHyperlinks = true;
                options.EnableVirtualSpace    = false;
                options.HighlightCurrentLine  = true;
                options.ShowSpaces            = true;
                options.ShowTabs      = true;
                options.ShowEndOfLine = true;
            }

            textEditor.ShowLineNumbers = true;
            textEditor.WordWrap        = true;

            _foldingManager  = FoldingManager.Install(textEditor.TextArea);
            _foldingStrategy = new XmlFoldingStrategy();

            this.Loaded      += OnPageLoaded;
            this.Unloaded    += OnPageUnloaded;
            this.SizeChanged += OnPageSizeChanged;
        }
Пример #5
0
        /// <summary>
        /// Event raised on mouse down in the ZoomPanControl.
        /// </summary>
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);

            switch (_pageMode)
            {
            case ZoomPanPageMode.Scrollable:
                var scrollablePage = this.GetScrollablePage();
                if (scrollablePage != null)
                {
                    scrollablePage.SaveZoom();
                }
                break;

            case ZoomPanPageMode.Infinite:
                var infinitePage = this.GetInfinitePage();
                if (infinitePage != null)
                {
                    infinitePage.SaveZoom();
                }
                break;
            }
            _mouseHandlingMode         = ZoomPanMouseHandlingMode.Panning;
            _origContentMouseDownPoint = e.GetPosition(_viewportCanvas);

            if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0)
            {
                // Shift + left- or right-down initiates zooming mode.
                _mouseHandlingMode       = ZoomPanMouseHandlingMode.DragZooming;
                _dragBorder.Visibility   = Visibility.Hidden;
                _sizingBorder.Visibility = Visibility.Visible;
                Canvas.SetLeft(_sizingBorder, _origContentMouseDownPoint.X);
                Canvas.SetTop(_sizingBorder, _origContentMouseDownPoint.Y);
                _sizingBorder.Width  = 0;
                _sizingBorder.Height = 0;
            }
            else
            {
                // Just a plain old left-down initiates panning mode.
                _mouseHandlingMode = ZoomPanMouseHandlingMode.Panning;
            }

            if (_mouseHandlingMode != ZoomPanMouseHandlingMode.None)
            {
                // Capture the mouse so that we eventually receive the mouse up event.
                _viewportCanvas.CaptureMouse();
                e.Handled = true;
            }
        }
Пример #6
0
        public InfiniteZoomPanPage()
        {
            InitializeComponent();

            _wpfSettings             = new WpfDrawingSettings();
            _wpfSettings.CultureInfo = _wpfSettings.NeutralCultureInfo;

            _fileReader          = new FileSvgReader(_wpfSettings);
            _fileReader.SaveXaml = false;
            _fileReader.SaveZaml = false;

            _mouseHandlingMode = ZoomPanMouseHandlingMode.None;

            this.Loaded      += OnPageLoaded;
            this.Unloaded    += OnPageUnloaded;
            this.SizeChanged += OnPageSizeChanged;
        }
Пример #7
0
        /// <summary>
        /// Event raised on mouse up in the ZoomPanControl.
        /// </summary>
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonUp(e);

            if (_mouseHandlingMode == ZoomPanMouseHandlingMode.DragZooming)
            {
                var zoomAndPanControl = GetZoomPanControl();
                var curContentPoint   = e.GetPosition(_viewportCanvas);
                var rect = GetClip(curContentPoint, _origContentMouseDownPoint, new Point(0, 0),
                                   new Point(_viewportCanvas.Width, _viewportCanvas.Height));
                zoomAndPanControl.AnimatedZoomTo(rect);
                _dragBorder.Visibility   = Visibility.Visible;
                _sizingBorder.Visibility = Visibility.Hidden;
            }
            _mouseHandlingMode = ZoomPanMouseHandlingMode.None;
            _viewportCanvas.ReleaseMouseCapture();
            e.Handled = true;
        }
Пример #8
0
        /// <summary>
        /// Event raised on mouse move in the ZoomAndPanControl.
        /// </summary>
        private void OnZoomPanMouseMove(object sender, MouseEventArgs e)
        {
            if (_mouseHandlingMode == ZoomPanMouseHandlingMode.Panning)
            {
                // The user is left-dragging the mouse.
                // Pan the viewport by the appropriate amount.
                Point  curContentMousePoint = e.GetPosition(svgViewer);
                Vector dragOffset           = curContentMousePoint - _origContentMouseDownPoint;

                zoomPanControl.ContentOffsetX -= dragOffset.X;
                zoomPanControl.ContentOffsetY -= dragOffset.Y;

                e.Handled = true;
            }
            else if (_mouseHandlingMode == ZoomPanMouseHandlingMode.Zooming)
            {
                Point  curZoomAndPanControlMousePoint = e.GetPosition(zoomPanControl);
                Vector dragOffset    = curZoomAndPanControlMousePoint - _origZoomAndPanControlMouseDownPoint;
                double dragThreshold = 10;
                if (_mouseButtonDown == MouseButton.Left &&
                    (Math.Abs(dragOffset.X) > dragThreshold ||
                     Math.Abs(dragOffset.Y) > dragThreshold))
                {
                    // When Shift + left-down zooming mode and the user drags beyond the drag threshold,
                    // initiate drag zooming mode where the user can drag out a rectangle to select the area
                    // to zoom in on.
                    _mouseHandlingMode = ZoomPanMouseHandlingMode.DragZooming;

                    Point curContentMousePoint = e.GetPosition(svgViewer);
                    InitDragZoomRect(_origContentMouseDownPoint, curContentMousePoint);
                }

                e.Handled = true;
            }
            else if (_mouseHandlingMode == ZoomPanMouseHandlingMode.DragZooming)
            {
                // When in drag zooming mode continously update the position of the rectangle
                // that the user is dragging out.
                Point curContentMousePoint = e.GetPosition(svgViewer);
                SetDragZoomRect(_origContentMouseDownPoint, curContentMousePoint);

                e.Handled = true;
            }
        }
Пример #9
0
        /// <summary>
        /// Event raised on mouse up in the ZoomAndPanControl.
        /// </summary>
        private void OnZoomPanMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (_mouseHandlingMode == ZoomPanMouseHandlingMode.SelectPoint ||
                _mouseHandlingMode == ZoomPanMouseHandlingMode.SelectRectangle)
            {
                if (_drawingDocument != null)
                {
                    //_drawingDocument.DisplayTransform = (Transform)(new MatrixTransform(1, 0, 0, 1, -20, -180).Inverse);
                    //_drawingDocument.DisplayTransform = svgViewer.DisplayTransform;
                    //_drawingDocument.DisplayTransform = (Transform)svgViewer.DisplayTransform.Inverse;
                    Trace.WriteLine("Zoom-ContentOffsetX: " + zoomPanControl.ContentOffsetX);
                    Trace.WriteLine("Zoom-ContentOffsetY: " + zoomPanControl.ContentOffsetY);
                    Trace.WriteLine("Zoom-ContentScale: " + zoomPanControl.ContentScale);

                    var bounds = new Rect(0, 0, 0, 0);

                    var rootDiagram = _drawingDocument.Drawing.Children[0] as DrawingGroup;
                    if (rootDiagram != null)
                    {
//                        bounds = rootDiagram.ClipGeometry.Bounds;
                        bounds = rootDiagram.Bounds;
                    }

                    Trace.WriteLine("Zoom-Bound: " + bounds);
                    Trace.WriteLine("Drawing-Transform: " + _drawingDocument.Drawing.Transform);

                    var point = e.GetPosition(svgViewer);
                    // Retrieve the coordinate of the mouse position.
                    //var point = e.GetPosition((UIElement)sender);

                    //point.Offset(bounds.Left, bounds.Right);

                    var hitResult = _drawingDocument.HitTest(point);
                    if (hitResult != null && hitResult.IsHit)
                    {
                        var selecteElement = hitResult.Element;
                        if (selecteElement != null)
                        {
                            textEditor.Text = selecteElement.OuterXml;
                        }
                        else
                        {
                            textEditor.Text = string.Empty;
                        }

                        var selectedDrawing = hitResult.Drawing;
                        if (selectedDrawing != null)
                        {
                            elementImage.Source = new DrawingImage(selectedDrawing);
                        }
                        else
                        {
                            elementImage.Source = null;
                        }
                    }
                    else
                    {
                        textEditor.Text     = string.Empty;
                        elementImage.Source = null;
                    }
                }
            }
            else
            {
                if (_mouseHandlingMode != ZoomPanMouseHandlingMode.None)
                {
                    if (_mouseHandlingMode == ZoomPanMouseHandlingMode.Zooming)
                    {
                        if (_mouseButtonDown == MouseButton.Left)
                        {
                            // Shift + left-click zooms in on the content.
                            ZoomIn(_origContentMouseDownPoint);
                        }
                        else if (_mouseButtonDown == MouseButton.Right)
                        {
                            // Shift + left-click zooms out from the content.
                            ZoomOut(_origContentMouseDownPoint);
                        }
                    }
                    else if (_mouseHandlingMode == ZoomPanMouseHandlingMode.DragZooming)
                    {
                        // When drag-zooming has finished we zoom in on the rectangle that was highlighted by the user.
                        ApplyDragZoomRect();
                    }

                    zoomPanControl.ReleaseMouseCapture();
                    _mouseHandlingMode = ZoomPanMouseHandlingMode.None;
                    e.Handled          = true;
                }

                //if (zoomPanControl != null && _canvasCursor != null)
                //{
                //    zoomPanControl.Cursor = _canvasCursor;
                //}
            }
        }