Beispiel #1
0
        private double MeasureWrappedTextWidth(String s, TextBox box, TextBlock block)
        {
            if (s == null)
            {
                return(0);
            }
            TextBlock tb = this.MTB;

            if (tb == null)
            {
                tb       = new TextBlock();
                this.MTB = tb;
            }
            // make this TextBlock look like the TextBox
            tb.FontFamily    = box.FontFamily;
            tb.FontStretch   = box.FontStretch;
            tb.FontStyle     = box.FontStyle;
            tb.FontWeight    = box.FontWeight;
            tb.TextAlignment = box.TextAlignment;
            //tb.TextDecorations = box.TextDecorations;
            tb.TextWrapping = box.TextWrapping;
            // or like the TextBlock
            tb.MinWidth = block.MinWidth;
            tb.MaxWidth = block.MaxWidth;
            Part.SetTextAspectRatio(tb, Part.GetTextAspectRatio(block));
            // initial text
            tb.Text = s;
            return(NodePanel.MeasureWrappedTextWidth(tb, new Size(tb.MaxWidth, tb.MaxHeight)));
        }
Beispiel #2
0
        // Find the link data of the Link coming into this Node
        // and update the text fields about the arrowhead names.
        private void NodePanel_MouseEnter(object sender, MouseEventArgs e)
        {
            NodePanel np = sender as NodePanel;

            if (np == null)
            {
                return;
            }

            Node node = VisualTreeHelper.GetParent(np) as Node;

            if (node == null)
            {
                return;
            }

            Link link = node.LinksInto.FirstOrDefault();

            if (link == null)
            {
                return;
            }

            MyLinkData mld = link.Data as MyLinkData;

            if (mld == null)
            {
                return;
            }

            ToArrowheadName.Text   = "ToArrow = " + mld.ToArrow.ToString();
            FromArrowheadName.Text = "FromArrow = " + mld.FromArrow.ToString();
        }
Beispiel #3
0
    protected override void OnDrag()
    {
        NodePanel panel = Panel as NodePanel;

        if (panel != null)
        {
            panel.DragContainer(this);
        }
    }
Beispiel #4
0
 internal static FrameworkElement AsToolHandle(FrameworkElement elt)
 {
     if (NodePanel.GetFigure(elt) != NodeFigure.None)
     {
         return(elt);
     }
     else
     {
         return(null);
     }
 }
Beispiel #5
0
 public NodePanel(Rect _rect, Graph _graph, GraphEditor _graphEditor, GUISkin _editorSkin, FREditorSettings _settings)
 {
     firstNodeName = "";
     current       = this;
     //collectedNodes = _collectedNodes;
     rect        = _rect;
     position    = new Vector2(rect.x, rect.y);
     graph       = _graph;
     graphEditor = _graphEditor;
     editorSkin  = _editorSkin;
     settings    = _settings;
 }
Beispiel #6
0
 internal static FrameworkElement FindToolHandle(DependencyObject v)
 {
     if (v == null || v is Part)
     {
         return(null);
     }
     if (NodePanel.GetFigure(v) != NodeFigure.None)
     {
         return(v as FrameworkElement);
     }
     return(FindToolHandle(System.Windows.Media.VisualTreeHelper.GetParent(v)));
 }
Beispiel #7
0
        // Adds individual animations to the locationAnimation StoryBoard.
        private void AnimateNode(int key, NodePanel np, Duration duration)
        {
            if (key < 0)
            {
                return;
            }
            if (np == null)
            {
                return;
            }

            PointAnimationUsingKeyFrames locationAnimation = new PointAnimationUsingKeyFrames();
            double keyTime = 0.0;

            // Gets the LinearPointKeyFrames for the PointAnimationUsingKeyFrames.
            // Starts at key-1 to account for an initial KeyFrame.
            for (int i = key - 1; i < (key + NumberOfNodes - 1); i++)
            {
                LinearPointKeyFrame lpkf = new LinearPointKeyFrame();
                lpkf.KeyTime = TimeSpan.FromSeconds(keyTime);

                int nextNodeKeyInt = i + 1;
                if (nextNodeKeyInt >= (NumberOfNodes - 1))
                {
                    nextNodeKeyInt = nextNodeKeyInt % (NumberOfNodes - 1);
                }
                MyNodeData nextNodeData = myDiagram.Model.FindNodeByKey((nextNodeKeyInt)) as MyNodeData;
                if (nextNodeData == null || nextNodeData.Location == null)
                {
                    return;
                }
                lpkf.Value = nextNodeData.Location;
                locationAnimation.KeyFrames.Add(lpkf);

                // If duration equals TimeSpan.FromSeconds(NumberOfNodes - 1),
                // then keyTime increases by 1 with each iteration.
                keyTime += ((double)duration.TimeSpan.TotalSeconds) / (NumberOfNodes - 1);
            }

            LocationStoryBoard.Children.Add(locationAnimation);
            Storyboard.SetTarget(locationAnimation, np);
            Storyboard.SetTargetProperty(locationAnimation, new PropertyPath(Node.LocationProperty));
        }
Beispiel #8
0
        /// <summary>
        /// Show an <see cref="Adornment"/> with <see cref="ToolHandle"/>s at each end of the link's route,
        /// if the link is selected and visible.
        /// </summary>
        /// <param name="part"></param>
        /// <remarks>
        /// </remarks>
        public override void UpdateAdornments(Part part)
        {
            Link link = part as Link;

            if (link == null)
            {
                return;          // no Nodes
            }
            Adornment adornment = null;

            if (link.IsSelected)
            {
                FrameworkElement selelt = link.Path;
                if (selelt != null && Part.IsVisibleElement(selelt))
                {
                    adornment = link.GetAdornment(ToolCategory);
                    if (adornment == null)
                    {
                        Route route = link.Route;
                        if (route != null)
                        {
                            IList <Point> pts    = route.Points;
                            int           numpts = route.PointsCount;
                            if (pts != null && numpts > 2)
                            {
                                // This tool's Adornments consists of a LinkPanel containing two ToolHandles.
                                LinkPanel panel = new LinkPanel();
#if SILVERLIGHT
                                var h = new System.Windows.Shapes.Path();
#else
                                var h = new ToolHandle();
#endif
                                // of course you can customize the appearance of the shift handles here...
                                NodePanel.SetFigure(h, NodeFigure.Rectangle);
                                h.Width  = 6;
                                h.Height = 6;
                                h.Fill   = new SolidColorBrush(Colors.Orange);
                                LinkPanel.SetIndex(h, 0);
                                LinkPanel.SetFraction(h, 0.5);
                                if (pts[0].X == pts[1].X && pts[0].Y != pts[1].Y)
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.Horizontal);
                                    h.Cursor = System.Windows.Input.Cursors.SizeWE;
                                }
                                else if (pts[0].Y == pts[1].Y && pts[0].X != pts[1].X)
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.Vertical);
                                    h.Cursor = System.Windows.Input.Cursors.SizeNS;
                                }
                                else
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.All);
#if !SILVERLIGHT
                                    h.Cursor = System.Windows.Input.Cursors.SizeAll;
#endif
                                }
                                panel.Children.Add(h);

#if SILVERLIGHT
                                h = new System.Windows.Shapes.Path();
#else
                                h = new ToolHandle();
#endif
                                NodePanel.SetFigure(h, NodeFigure.Rectangle);
                                h.Width  = 6;
                                h.Height = 6;
                                h.Fill   = new SolidColorBrush(Colors.Orange);
                                LinkPanel.SetIndex(h, -1);
                                LinkPanel.SetFraction(h, 0.5);
                                SetReshapeBehavior(h, ReshapeBehavior.All);
                                if (pts[numpts - 1].X == pts[numpts - 2].X && pts[numpts - 1].Y != pts[numpts - 2].Y)
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.Horizontal);
                                    h.Cursor = System.Windows.Input.Cursors.SizeWE;
                                }
                                else if (pts[numpts - 1].Y == pts[numpts - 2].Y && pts[numpts - 1].X != pts[numpts - 2].X)
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.Vertical);
                                    h.Cursor = System.Windows.Input.Cursors.SizeNS;
                                }
                                else
                                {
                                    SetReshapeBehavior(h, ReshapeBehavior.All);
#if !SILVERLIGHT
                                    h.Cursor = System.Windows.Input.Cursors.SizeAll;
#endif
                                }
                                panel.Children.Add(h);

                                adornment = new Adornment();
                                adornment.AdornedElement = selelt;
                                adornment.Category       = ToolCategory;
                                adornment.Content        = panel; // just provide the FrameworkElement as the Content and as the Visual Child
                                adornment.LocationSpot   = Spot.TopLeft;
                            }
                        }
                    }
                    if (adornment != null)
                    {
                        Point loc = link.GetElementPoint(selelt, Spot.TopLeft);
                        adornment.Location      = loc;
                        adornment.RotationAngle = link.GetAngle(selelt);
                        adornment.Remeasure();
                    }
                }
            }
            link.SetAdornment(ToolCategory, adornment);
        }