コード例 #1
0
ファイル: EditView.cs プロジェクト: instr3/WitnessVisualizer
 void SubmitCreatingNodes()
 {
     GraphEditManager.BeforePreformEdit(Graph, "Create Graph Elements");
     GraphManipulation.AddShape(Graph, CreatingNodes);
     ExitCreatingMode();
     EnterCreatingMode();
 }
コード例 #2
0
        private void RegularPolygonToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <object> menuItems = new List <object>()
            {
                null, null, null, regularTriangleToolStripMenuItem, regularSquareToolStripMenuItem, regularPentagonToolStripMenuItem, regularHexagonToolStripMenuItem
            };

            if (editView != null)
            {
                Graph graph = editView.Graph;
                int   edges = menuItems.IndexOf(sender);
                if (editView.SelectedObjects.Count > 0 && editView.SelectedObjects[0] is Edge edge)
                {
                    editView.GraphEditManager.BeforePreformEdit(editView.Graph, "Draw Regular Polygon");
                    GraphManipulation.TryAddShapeWithBaseSegment(graph, edge, GraphManipulation.CreateRegularPolygon(edges));
                    UpdateGraphDrawing();
                }
                else
                {
                    MessageBox.Show(Resources.Lang.Errors_NoEdge);
                }
            }
        }
コード例 #3
0
ファイル: EditView.cs プロジェクト: instr3/WitnessVisualizer
        internal bool MouseDown(int x, int y, MouseButtons button, bool ctrlKey, bool altKey, bool shiftKey) // Return true if copy operation is performed
        {
            bool copyPerformed = false;

            if (IsCreatingMode)
            {
                if (button == MouseButtons.Left) // Add
                {
                    Node addNode;
                    if (HoveredObjects.Count > 0 && HoveredObjects[0] is Node node)
                    {
                        if (CreatingNodes.Contains(node))
                        {
                            if (CreatingNodes.Last() == node)
                            {
                                CreatingNodes.RemoveAt(CreatingNodes.Count - 1);
                            }
                            else if (CreatingNodes.First() == node)
                            {
                                AddToCreatingNodes(node);
                                SubmitCreatingNodes();
                            }
                            return(false);
                        }
                        addNode = node;
                    }
                    else
                    {
                        Vector pos = new Vector(x, y).MapFromScreen(Scale, Origin);
                        addNode = new Node(pos.X, pos.Y);
                    }
                    AddToCreatingNodes(addNode);
                    return(false);
                }
                else if (button == MouseButtons.Right) // Exit
                {
                    SubmitCreatingNodes();
                    return(false);
                }
            }
            if (altKey && PasteMode && SampleDecorator != null) // Create and paste
            {
                GraphEditManager.BeforePreformEdit(Graph, "Create Graph Elements");
                Vector pos     = new Vector(x, y).MapFromScreen(Scale, Origin);
                Node   addNode = new Node(pos.X, pos.Y);
                addNode.Hidden    = true;
                addNode.Decorator = SampleDecorator.Clone() as Decorator;
                if (!shiftKey && addNode.Decorator is TransformableDecorator transformableDecorator)
                {
                    transformableDecorator.ExtraScale = (1 - Graph.MetaData.EdgeWidth) / Graph.MetaData.EdgeWidth;
                }
                GraphManipulation.AddShape(Graph, new List <Node>()
                {
                    addNode
                });
            }
            else if (HoveredObjects.Count > 0 && button != MouseButtons.Middle)
            {
                List <GraphElement> objectToKeep = new List <GraphElement>();
                if (ctrlKey || shiftKey)
                {
                    foreach (GraphElement selectedObject in SelectedObjects)
                    {
                        if (shiftKey || !HoveredObjects.Contains(selectedObject))
                        {
                            objectToKeep.Add(selectedObject);
                        }
                    }
                }
                foreach (GraphElement havoredObject in HoveredObjects)
                {
                    if (!SelectedObjects.Contains(havoredObject))
                    {
                        objectToKeep.Add(havoredObject);
                    }
                }
                SelectedObjects.Clear();
                if (ColorPaintingMode) // Paint mode
                {
                    foreach (GraphElement element in objectToKeep)
                    {
                        Color TryApplyColor(Color oldColor, Color newColor, string hint)
                        {
                            if (oldColor != newColor)
                            {
                                GraphEditManager.BeforePreformEdit(Graph, string.Format(Resources.Lang.Undo_Paint, hint, newColor.ToString()));
                            }
                            return(newColor);
                        }

                        if (element is Node)
                        {
                            if (element.Decorator is PuzzleGraph.Decorators.StartDecorator startDecorator)
                            {
                                if (button == MouseButtons.Right) // Color picking
                                {
                                    PaintingModeControl.Color = startDecorator.Color;
                                }
                                else // Apply color
                                {
                                    startDecorator.Color = TryApplyColor(startDecorator.Color, PaintingModeControl.Color, "start point");
                                }
                            }
                            else if (element.Decorator is PuzzleGraph.Decorators.EndDecorator endDecorator)
                            {
                                if (button == MouseButtons.Right) // Color picking
                                {
                                    PaintingModeControl.Color = endDecorator.Color;
                                }
                                else // Apply color
                                {
                                    endDecorator.Color = TryApplyColor(endDecorator.Color, PaintingModeControl.Color, "end point");
                                }
                            }
                        }
                        else if (element is Face face)
                        {
                            if (button == MouseButtons.Right) // Color picking
                            {
                                PaintingModeControl.Color = face.GraphElementColor;
                            }
                            else // Apply color
                            {
                                face.GraphElementColor = TryApplyColor(face.GraphElementColor, PaintingModeControl.Color, "face");
                            }
                        }
                        else if (element is Edge edge)
                        {
                            if (button == MouseButtons.Right) // Color picking
                            {
                                PaintingModeControl.Color = edge.GraphElementColor;
                            }
                            else // Apply color
                            {
                                edge.GraphElementColor = TryApplyColor(edge.GraphElementColor, PaintingModeControl.Color, "edge");
                            }
                        }
                    }
                }
                else if (button == MouseButtons.Right) // Copy
                {
                    if (objectToKeep.Count > 0)
                    {
                        if (ctrlKey && objectToKeep[0].Decorator is PuzzleGraph.Decorators.CombinedDecorator combinedDecorator) // Combine mode
                        {
                            ChooseSampleDecorator(combinedDecorator.Second, true);
                            objectToKeep[0].Decorator = combinedDecorator.First;
                        }
                        else
                        {
                            ChooseSampleDecorator(objectToKeep[0].Decorator, true);
                        }

                        copyPerformed = true;
                    }
                }
                else
                {
                    if (!PasteMode) // Selection mode
                    {
                        SelectedObjects.AddRange(objectToKeep);
                        if (shiftKey)
                        {
                            nodesToMove = new List <Node>();
                            foreach (GraphElement element in SelectedObjects)
                            {
                                if (element is Node selectedNode)
                                {
                                    nodesToMove.Add(selectedNode);
                                }
                                else if (element is Edge selectedEdge)
                                {
                                    nodesToMove.Add(selectedEdge.Start);
                                    nodesToMove.Add(selectedEdge.End);
                                }
                                else if (element is Face selectedFace)
                                {
                                    nodesToMove.AddRange(selectedFace.Nodes);
                                }
                            }
                            if (nodesToMove.Count > 0)
                            {
                                GraphEditManager.BeforePreformEdit(Graph, "Move Nodes");
                                ElementMoveStartPosition = new Vector(x, y);
                            }
                        }
                        else
                        {
                            ElementMoveStartPosition = null;
                        }
                    }
                    else // Paste mode
                    {
                        foreach (GraphElement element in objectToKeep)
                        {
                            if (ctrlKey && element.Decorator != null) // Combine mode
                            {
                                CombineDecorators(SampleDecorator, element);
                            }
                            else
                            {
                                ApplyDecoratorToObject(SampleDecorator, element);
                            }
                        }
                    }
                }
                HoveredObjects.Clear();
                if (SelectedObjects.Count > 0)
                {
                    TetrisIndexToTemplateView(SelectedObjects[0].Decorator);
                }
            }
            else
            {
                mouseDownPosition = new Vector(x, y);
                IsDragging        = true;
            }
            return(copyPerformed);
        }