private void radialMenuitem_Click(object sender, RoutedEventArgs e) { var item = sender as RadialMenuItem; if (item != null) { var bBox = new Rect(); if (item.Name.Contains("Align")) { bBox = Node.GetBoundingBoxOfNodes(HostCanvas.SelectedNodes.ToList()); } switch (item.Name) { case "MenuNew": HostCanvas.NewFile(); break; case "MenuOpen": HostCanvas.OpenFile(); break; case "MenuSave": HostCanvas.SaveFile(); break; case "MenuSettings": var window = new Settings(); window.VplPropertyGrid.SelectedObject = HostCanvas.Theme; window.Show(); break; case "MenuZoomToFit": //Reset canvas to center var error = 1; //List<Node> nodeList = new List<Node>(); //foreach (var children in HostCanvas.Children) //{ // if (children is Border) // { // Node n = (children as Border).Child as Node; // if (n!= null) // { // //n.Left += n.Left -40000; // //n.Top += n.Top - 40000; // nodeList.Add(n); // } // } //} //HostCanvas.UpdateLayout(); ////Get the mouse location from SizableParent perspective translated actual vplcontrol //var relative = HostCanvas.SizableParent.TranslatePoint(System.Windows.Input.Mouse.GetPosition(HostCanvas.SizableParent as IInputElement), this); ////Vplcontrol had been translated by matrix during zoom so we need to use it to locate the node on screen //bBox = Node.GetBoundingBoxOfNodes(nodeList); //var transformation = HostCanvas.TranslateTransform; //var pp = System.Windows.Input.Mouse.GetPosition(HostCanvas.SizableParent as IInputElement); //var bbTop = (relative.Y - transformation.Y) - (bBox.Y); //var bbLeft = (relative.X - transformation.X) - (bBox.X) ; //foreach (var node in nodeList) //{ // node.Top += node.Top - bbTop; // node.Left += node.Left - bbLeft; //} //Transaling to UI dimensions var parent = HostCanvas.SizableParent; var CenterOfUI = new Point(parent.ActualWidth / 2, parent.ActualHeight / 2); var relative = parent.TranslatePoint(CenterOfUI, HostCanvas); bBox = Node.GetBoundingBoxOfNodes(HostCanvas.NodeCollection.ToList()); var translation = HostCanvas.TranslateTransform; var origin = new Point(HostCanvas.TranslateTransform.X, HostCanvas.TranslateTransform.Y); HostCanvas.TranslateTransform.X = relative.X - (bBox.X + bBox.Width / 2); HostCanvas.TranslateTransform.Y = relative.Y - (bBox.Y + bBox.Height / 2); HostCanvas.UpdateLayout(); ////var transform = HostCanvas.RenderTransform as MatrixTransform; ////var matrix = transform.Value; ////matrix.Scale(4, 4); ////transform.Matrix = matrix; //var transform = HostCanvas.RenderTransform as MatrixTransform; //transform.Matrix = new System.Windows.Media.Matrix(); break; case "MenuAlign": InitializeAlignMenuItems(); Items = alignMenuItems; break; case "MenuGroup": HostCanvas.GroupNodes(); break; case "MenuHelp": break; case "AlignLeft": foreach (var node in HostCanvas.SelectedNodes) { node.Left = bBox.Left; } break; case "AlignHCenter": foreach (var node in HostCanvas.SelectedNodes) { node.Left = bBox.Right - bBox.Width / 2 - node.ActualWidth / 2; } break; case "AlignRight": foreach (var node in HostCanvas.SelectedNodes) { node.Left = bBox.Right - node.ActualWidth; } break; case "AlignTop": foreach (var node in HostCanvas.SelectedNodes) { node.Top = bBox.Top; } break; case "AlignVCenter": foreach (var node in HostCanvas.SelectedNodes) { node.Top = bBox.Bottom - bBox.Height / 2 - node.ActualHeight / 2; } break; case "AlignBottom": foreach (var node in HostCanvas.SelectedNodes) { node.Top = bBox.Bottom - node.ActualHeight; } break; case "AlignArrangeH": break; case "AlignArrangeV": break; case "AlignBack": Items = mainMenuItems; break; default: throw new NotImplementedException(); } if (item.Name != "MenuAlign" && item.Name != "AlignBack") { Close(); } } }
private void radialMenuitem_Click(object sender, RoutedEventArgs e) { var item = sender as RadialMenuItem; if (item != null) { var bBox = new Rect(); if (item.Name.Contains("Align")) { bBox = Node.GetBoundingBoxOfNodes(HostCanvas.SelectedNodes.ToList()); } switch (item.Name) { case "MenuNew": HostCanvas.NewFile(); break; case "MenuOpen": HostCanvas.OpenFile(); break; case "MenuSave": HostCanvas.SaveFile(); break; case "MenuSettings": var window = new Settings(); window.VplPropertyGrid.SelectedObject = HostCanvas.Theme; window.Show(); break; case "MenuZoomToFit": // fit pan bBox = Node.GetBoundingBoxOfNodes(HostCanvas.NodeCollection.ToList()); var deltaX = bBox.Left + bBox.Width / 2 - HostCanvas.ActualWidth / 2; var deltaY = bBox.Top + bBox.Height / 2 - HostCanvas.ActualHeight / 2; foreach (var node in HostCanvas.NodeCollection) { node.Left -= deltaX; node.Top -= deltaY; } HostCanvas.Refresh(); // fit scale bBox = Node.GetBoundingBoxOfNodes(HostCanvas.NodeCollection.ToList()); var ratioX = bBox.Width / HostCanvas.ActualWidth; var ratioY = bBox.Height / HostCanvas.ActualHeight; var ratio = Math.Max(ratioX, ratioY); //ratio =Math.Ceiling(ratio*10)/10-1; ratio -= 1; if (ratio < 0) { // HostCanvas.DoZoomIn(new Point(HostCanvas.ActualWidth/2, HostCanvas.ActualHeight/2), // Math.Abs(ratio)); } HostCanvas.Refresh(); // fit pan bBox = Node.GetBoundingBoxOfNodes(HostCanvas.NodeCollection.ToList()); deltaX = bBox.Left + bBox.Width / 2 - HostCanvas.ActualWidth / 2; deltaY = bBox.Top + bBox.Height / 2 - HostCanvas.ActualHeight / 2; foreach (var node in HostCanvas.NodeCollection) { node.Left -= deltaX; node.Top -= deltaY; } HostCanvas.Refresh(); break; case "MenuAlign": InitializeAlignMenuItems(); Items = alignMenuItems; break; case "MenuGroup": HostCanvas.GroupNodes(); break; case "MenuHelp": break; case "AlignLeft": foreach (var node in HostCanvas.SelectedNodes) { node.Left = bBox.Left; } break; case "AlignHCenter": foreach (var node in HostCanvas.SelectedNodes) { node.Left = bBox.Right - bBox.Width / 2 - node.ActualWidth / 2; } break; case "AlignRight": foreach (var node in HostCanvas.SelectedNodes) { node.Left = bBox.Right - node.ActualWidth; } break; case "AlignTop": foreach (var node in HostCanvas.SelectedNodes) { node.Top = bBox.Top; } break; case "AlignVCenter": foreach (var node in HostCanvas.SelectedNodes) { node.Top = bBox.Bottom - bBox.Height / 2 - node.ActualHeight / 2; } break; case "AlignBottom": foreach (var node in HostCanvas.SelectedNodes) { node.Top = bBox.Bottom - node.ActualHeight; } break; case "AlignArrangeH": break; case "AlignArrangeV": break; case "AlignBack": Items = mainMenuItems; break; default: throw new NotImplementedException(); } if (item.Name != "MenuAlign" && item.Name != "AlignBack") { Close(); } } }