Ejemplo n.º 1
0
        private void ShowCanvasContextMenu(object state)
        {
            Thread.Sleep(300);

            // put it on the UI thread to execute.
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (!_mouseMovedWhileRMBDown)
                {
                    CanvasContextMenu contextMenu = new CanvasContextMenu(_typeManager, MessageSender, Navigator, _currentMousePosition);
                    ContextMenuService.SetContextMenu(this, contextMenu);

                    contextMenu.IsOpen           = true;
                    contextMenu.HorizontalOffset = _currentMousePosition.X;
                    contextMenu.VerticalOffset   = _currentMousePosition.Y + 30;
                }
            });
        }
Ejemplo n.º 2
0
 public async Task OnMouseUp(MouseEventArgs e)
 {
     MouseDown = false;
     if (e.Button == 2)
     {
         RectSelection.Create = false;
         if (!e.CtrlKey && RectSelection.Width <= 0 && RectSelection.Height <= 0)
         {
             if (ObjectClicked.Right)
             {
                 ObjectClicked.Right = false;
                 ObjectContextMenu.Open(e.ClientX, e.ClientY);
             }
             else
             {
                 if (GraphMode == GraphMode.Algorithm)
                 {
                     AlgorithmContextMenu.Open(e.ClientX, e.ClientY);
                 }
                 else
                 {
                     CanvasContextMenu.Open(e.ClientX, e.ClientY);
                     origin[0] = e.ClientX;
                     origin[1] = e.ClientY;
                     if (ActiveGraph.Nodes.Any() || ActiveGraph.Edges.Any())
                     {
                         await ActiveGraphChanged.InvokeAsync(new Graph());
                     }
                 }
             }
         }
         else
         {
             bool aNodesChanged = false;
             bool aEdgesChanged = false;
             foreach (Node node in Graph.Nodes)
             {
                 if (node.Xaxis <= RectSelection.X + RectSelection.Width &&
                     node.Xaxis >= RectSelection.X &&
                     node.Yaxis <= RectSelection.Y + RectSelection.Height &&
                     node.Yaxis >= RectSelection.Y)
                 {
                     if (!ActiveGraph.Nodes.Contains(node))
                     {
                         ActiveGraph.Nodes.Add(node);
                         aNodesChanged = true;
                     }
                 }
                 else if (ActiveGraph.Nodes.Remove(node))
                 {
                     aNodesChanged = true;
                 }
             }
             foreach (Edge edge in Graph.Edges)
             {
                 ShowEdge showEdge = new ShowEdge(edge);
                 var      x        = 0.25 * edge.Head.Xaxis + 0.5 * showEdge.CurvePoint[0] + 0.25 * edge.Tail.Xaxis;
                 var      y        = 0.25 * edge.Head.Yaxis + 0.5 * showEdge.CurvePoint[1] + 0.25 * edge.Tail.Yaxis;
                 if (x <= RectSelection.X + RectSelection.Width &&
                     x >= RectSelection.X &&
                     y <= RectSelection.Y + RectSelection.Height &&
                     y >= RectSelection.Y)
                 {
                     if (!ActiveGraph.Edges.Contains(edge))
                     {
                         ActiveGraph.Edges.Add(edge);
                         aEdgesChanged = true;
                     }
                 }
                 else if (ActiveGraph.Edges.Remove(edge))
                 {
                     aEdgesChanged = true;
                 }
             }
             if (aNodesChanged || aEdgesChanged)
             {
                 await ActiveGraphChanged.InvokeAsync(ActiveGraph);
             }
         }
         RectSelection = new RectSelection();
         return;
     }
     if (ObjectClicked.Left)
     {
         ObjectClicked.Left = false;
         if (GraphMode == GraphMode.InsertNode)
         {
             SvgClass = "pointer";
         }
         else
         {
             SvgClass = "grab";
         }
     }
     else if (!e.CtrlKey && !ActiveGraph.Nodes.Any() && !ActiveGraph.Nodes.Any() && GraphMode == GraphMode.InsertNode)
     {
         NodeService.AddNode(Graph.Nodes, Options.Default, e.ClientX * SVGControl.Scale + SVGControl.Xaxis, e.ClientY * SVGControl.Scale + SVGControl.Yaxis);
     }
     else if (ActiveGraph.Nodes.Any() || ActiveGraph.Edges.Any())
     {
         await ActiveGraphChanged.InvokeAsync(new Graph());
     }
     if (SVGControl.Pan)
     {
         SVGControl.Pan      = false;
         SvgClass            = "grab";
         SVGControl.OldXaxis = SVGControl.Xaxis;
         SVGControl.OldYaxis = SVGControl.Yaxis;
     }
 }