Пример #1
0
        private void OnGraphCanvasLoaded(object sender, RoutedEventArgs e)
        {
            visualHost = new GraphVisualHost(this, this.graphControl, this.startupFile);
            visualHost.IsInRecordingMode = graphControl.IsInRecordingMode;
            graphCanvas.Children.Add(visualHost);
            graphControl.GraphControllerLoaded(this.Controller.Identifier);

            graphCanvas.KeyDown          += new KeyEventHandler(OnCanvasKeyDown);
            graphCanvas.KeyUp            += new KeyEventHandler(OnCanvasKeyUp);
            graphCanvas.MouseMove        += new MouseEventHandler(OnCanvasMouseMove);
            graphCanvas.MouseDown        += OnCanvasMouseButtonDown;
            graphCanvas.PreviewMouseDown += OnCanvasPreviewMouseDown;
            graphCanvas.MouseUp          += OnCanvasMouseButtonUp;

            //for libraryview
            graphCanvas.AllowDrop = true;
            graphCanvas.Drop     += new DragEventHandler(OnCanvasDrop);

            //for Zoom and Pan
            graphCanvas.MouseWheel += OnMouseWheel;

            //if (!string.IsNullOrEmpty(this.startupFile))
            //    this.visualHost.HandleZoomToFit();

            graphCanvas.Focus();
        }
Пример #2
0
        //Ctrl/Shift Pan Animation
        public ZoomAndPanAnimationHelper(double newOffsetX, double newOffsetY, GraphVisualHost visualHost, GraphControl graphControl)
        {
            mousePosition      = graphControl.canvasScrollViewer.TranslatePoint(GetMousePosition(), graphControl.CurrentGraphCanvas);
            this.currentCursor = graphControl.GetCursor();
            //System.Windows.Input.Mouse.OverrideCursor = System.Windows.Input.Cursors.None;

            staticGraphControl = graphControl;
            this.visualHost    = visualHost;
            staticScrollViewer = staticGraphControl.canvasScrollViewer;

            ZoomAndPanAnimationHelper.newOffsetX = newOffsetX;
            ZoomAndPanAnimationHelper.newOffsetY = newOffsetY;
            ZoomAndPanAnimationHelper.newScale   = double.MinValue;

            double offsetX = staticGraphControl.canvasScrollViewer.HorizontalOffset;
            double offsetY = staticGraphControl.canvasScrollViewer.VerticalOffset;

            double shiftX = newOffsetX - offsetX;
            double shiftY = newOffsetY - offsetY;

            if (Math.Abs(shiftX) < 0.01 &&
                Math.Abs(shiftY) < 0.01)
            {
                return;
            }

            DoubleAnimation xOffsetAnimation = new DoubleAnimation();

            xOffsetAnimation.From     = offsetX;
            xOffsetAnimation.To       = newOffsetX;
            xOffsetAnimation.Duration = TimeSpan.FromMilliseconds(Configurations.ShortAnimationTime);
            Storyboard.SetTarget(xOffsetAnimation, visualHost);
            Storyboard.SetTargetProperty(xOffsetAnimation, new PropertyPath("XOffset"));

            DoubleAnimation yOffsetAnimation = new DoubleAnimation();

            yOffsetAnimation.From     = offsetY;
            yOffsetAnimation.To       = newOffsetY;
            yOffsetAnimation.Duration = TimeSpan.FromMilliseconds(Configurations.ShortAnimationTime);
            Storyboard.SetTarget(yOffsetAnimation, visualHost);
            Storyboard.SetTargetProperty(yOffsetAnimation, new PropertyPath("YOffset"));

            zoomAndPanStoryboard = new Storyboard();
            zoomAndPanStoryboard.Children.Add(xOffsetAnimation);
            zoomAndPanStoryboard.Children.Add(yOffsetAnimation);
            zoomAndPanStoryboard.Completed += new EventHandler(OnAnimationCompleted);

            BeginAnimation();
        }
Пример #3
0
        public ExtendedPreview(String text, double width, double height, GraphControl graphControl, GraphVisualHost visualHost)
        {
            InitializeComponent();

            this.graphControl          = graphControl;
            this.visualHost            = visualHost;
            this.InternalTextBox.Text  = text;
            this.Focusable             = true;
            this.IsEnabled             = true;
            PreviewPanel.Focusable     = true;
            PreviewPanel.IsEnabled     = true;
            InternalTextBox.Focusable  = true;
            InternalTextBox.IsEnabled  = true;
            InternalTextBox.IsReadOnly = true;

            InternalTextBox.FontFamily = new FontFamily(Configurations.Font);
            InternalTextBox.FontWeight = FontWeights.Normal;
            InternalTextBox.FontSize   = Configurations.InfoBubbleText;

            FormattedText formattedText = new FormattedText(text,
                                                            Configurations.culture,
                                                            FlowDirection.LeftToRight,
                                                            Configurations.TypeFace,
                                                            Configurations.InfoBubbleText,
                                                            Configurations.PreviewBubbleExtendedTextColor);

            double textWidth = formattedText.WidthIncludingTrailingWhitespace + 2 * Configurations.InfoBubbleMargin + Configurations.PreviewBubbleExtendedScrollBarWidth;

            double extendedPreviewWidth;

            // the minimum width should allow the first value to be shown in one line
            if (text.Contains(','))
            {
                double        minimumTextWidth  = double.MinValue;
                string        tempText          = text.Substring(0, text.IndexOf(','));
                FormattedText tempFormattedText = new FormattedText(tempText,
                                                                    Configurations.culture,
                                                                    FlowDirection.LeftToRight,
                                                                    Configurations.TypeFace,
                                                                    Configurations.InfoBubbleText,
                                                                    Configurations.PreviewBubbleExtendedTextColor);
                minimumTextWidth = tempFormattedText.WidthIncludingTrailingWhitespace + 2 * Configurations.InfoBubbleMargin + Configurations.PreviewBubbleExtendedScrollBarWidth + 3;

                extendedPreviewWidth = Math.Max(width, minimumTextWidth);
            }
            else // if there is only one data member, need to fit in it
            {
                extendedPreviewWidth = Math.Max(width, textWidth);
            }

            //leave space for scrollbar and radial menu
            this.InternalTextBox.Width = extendedPreviewWidth - Configurations.PreviewBubbleExtendedScrollBarWidth;

            if (height > 0)
            {
                InternalTextBox.Height = height;
            }

            if (textWidth <= InternalTextBox.Width)
            {
                InternalTextBox.TextAlignment = TextAlignment.Center;
                InternalTextBox.Padding       = new Thickness(Configurations.PreviewBubbleExtendedScrollBarWidth, Configurations.InfoBubbleMargin,
                                                              0, Configurations.InfoBubbleMargin);
            }
            else
            {
                InternalTextBox.MaxHeight    = Configurations.InfoBubbleMaxHeight;
                InternalTextBox.TextWrapping = TextWrapping.Wrap;
                InternalTextBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
                InternalTextBox.Padding = new Thickness(Configurations.InfoBubbleMargin, Configurations.InfoBubbleMargin, 0, Configurations.InfoBubbleMargin);
            }
        }
Пример #4
0
        //Zoom to Fit Animation
        public ZoomAndPanAnimationHelper(double newOffsetX, double newOffsetY, double newScale, GraphVisualHost visualHost, GraphControl graphControl, bool captureMouse)
        {
            staticGraphControl = graphControl;
            this.visualHost    = visualHost;
            staticScrollViewer = staticGraphControl.canvasScrollViewer;

            ZoomAndPanAnimationHelper.newOffsetX = newOffsetX;
            ZoomAndPanAnimationHelper.newOffsetY = newOffsetY;
            ZoomAndPanAnimationHelper.newScale   = newScale;

            double offsetX = staticGraphControl.canvasScrollViewer.HorizontalOffset;
            double offsetY = staticGraphControl.canvasScrollViewer.VerticalOffset;
            double scale   = staticGraphControl.scaleTransform.ScaleX;

            double shiftX      = newOffsetX - offsetX;
            double shiftY      = newOffsetY - offsetY;
            double scaleChange = newScale - scale;

            if (captureMouse)
            {
                Point mousePositionOnScreen = GetMousePosition();
                mousePosition = new Point((mousePositionOnScreen.X + offsetX) / scale,
                                          (mousePositionOnScreen.Y + offsetY) / scale);

                this.currentCursor = staticGraphControl.GetCursor();
                //System.Windows.Input.Mouse.OverrideCursor = System.Windows.Input.Cursors.None;
            }

            if (Math.Abs(shiftX) < 0.05 &&
                Math.Abs(shiftY) < 1 &&
                Math.Abs(scaleChange) < 1)
            {
                return;
            }

            zoomAndPanStoryboard = new Storyboard();

            if (Math.Abs(shiftX) >= 0.05)
            {
                DoubleAnimation scaleAnimation = new DoubleAnimation();
                scaleAnimation.From     = scale;
                scaleAnimation.To       = newScale;
                scaleAnimation.Duration = TimeSpan.FromMilliseconds(Configurations.ShortAnimationTime);
                Storyboard.SetTarget(scaleAnimation, visualHost);
                Storyboard.SetTargetProperty(scaleAnimation, new PropertyPath("Scale"));
                zoomAndPanStoryboard.Children.Add(scaleAnimation);
            }

            if (Math.Abs(shiftX) >= 1)
            {
                DoubleAnimation xOffsetAnimation = new DoubleAnimation();
                xOffsetAnimation.From     = offsetX;
                xOffsetAnimation.To       = newOffsetX;
                xOffsetAnimation.Duration = TimeSpan.FromMilliseconds(Configurations.ShortAnimationTime);
                Storyboard.SetTarget(xOffsetAnimation, visualHost);
                Storyboard.SetTargetProperty(xOffsetAnimation, new PropertyPath("XOffset"));
                zoomAndPanStoryboard.Children.Add(xOffsetAnimation);
            }

            if (Math.Abs(shiftY) >= 1)
            {
                DoubleAnimation yOffsetAnimation = new DoubleAnimation();
                yOffsetAnimation.From     = offsetY;
                yOffsetAnimation.To       = newOffsetY;
                yOffsetAnimation.Duration = TimeSpan.FromMilliseconds(Configurations.ShortAnimationTime);
                Storyboard.SetTarget(yOffsetAnimation, visualHost);
                Storyboard.SetTargetProperty(yOffsetAnimation, new PropertyPath("YOffset"));
                zoomAndPanStoryboard.Children.Add(yOffsetAnimation);
            }

            zoomAndPanStoryboard.Completed += new EventHandler(OnAnimationCompleted);

            BeginAnimation();
        }