Exemple #1
0
        private void MainCanvas_DoubleClick(object sender, EventArgs e)
        {
            var x = (int)((mouseDownPoint.X - MainCanvas.AutoScrollPosition.X) / Zoom);
            var y = (int)((mouseDownPoint.Y - MainCanvas.AutoScrollPosition.Y) / Zoom);

            for (int i = BoundingItemes.Count - 1; i >= 0; i--)
            {
                BoundingItem bitem = BoundingItemes[i];
                if (bitem.HitTest(x, y))
                {
                    if (bitem.Target is Shape)
                    {
                        currentBoundingItem = bitem;
                        var shape = (Shape)bitem.Target;
                        var args  = new ShapeMouseEventArgs
                        {
                            BoundingItem = bitem, X = x, Y = y, Button = MouseButtons.Left, Sender = this
                        };
                        shape.OnDoubleClick(args);
                        if (args.Redraw)
                        {
                            Refresh();
                        }
                    }

                    return;
                }
            }
        }
Exemple #2
0
        private void MainCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (EditMode == EditMode.DrawRelation)
            {
                mouseCurrentPoint = new Point(e.X, e.Y);
                MainCanvas.Refresh();
            }
            else if (EditMode == EditMode.Normal)
            {
                var x = (int)((e.X - MainCanvas.AutoScrollPosition.X) / Zoom);
                var y = (int)((e.Y - MainCanvas.AutoScrollPosition.Y) / Zoom);

                if (e.Button != MouseButtons.None)
                {
                    if (currentBoundingItem == null)
                    {
                        if (isPanning)
                        {
                            int dx = mouseDownPoint.X - e.X;
                            int dy = mouseDownPoint.Y - e.Y;

                            var newPos = new Point(mouseDownAutoscrollPoint.X + dx, mouseDownAutoscrollPoint.Y + dy);
                            MainCanvas.AutoScrollPosition = newPos;
                            Cursor = Cursors.SizeAll;
                        }
                    }
                    else
                    {
                        var shape = (Shape)currentBoundingItem.Target;
                        var args  = new ShapeMouseEventArgs
                        {
                            BoundingItem = currentBoundingItem,
                            X            = x,
                            Y            = y,
                            Button       = e.Button,
                            Sender       = this,
                            GridSize     = GridSize,
                            SnapToGrid   = SnapToGrid
                        };
                        shape.OnMouseMove(args);
                        if (args.Redraw)
                        {
                            MainCanvas.Refresh();
                        }
                    }
                }
                else
                {
                    for (int i = BoundingItemes.Count - 1; i >= 0; i--)
                    {
                        BoundingItem bitem = BoundingItemes[i];
                        if (bitem.HitTest(x, y))
                        {
                            if (bitem.Target is Shape)
                            {
                                var shape = (Shape)bitem.Target;
                                var args  = new ShapeMouseEventArgs
                                {
                                    BoundingItem = bitem, X = x, Y = y, Button = e.Button, Sender = this
                                };
                                shape.OnMouseMove(args);
                                if (args.Redraw)
                                {
                                    MainCanvas.Refresh();
                                }
                            }

                            return;
                        }
                    }
                }
            }
        }
Exemple #3
0
        private void MainCanvas_MouseDown(object sender, MouseEventArgs e)
        {
            EndInput();
            var x = (int)((e.X - MainCanvas.AutoScrollPosition.X) / Zoom);
            var y = (int)((e.Y - MainCanvas.AutoScrollPosition.Y) / Zoom);

            if (EditMode == EditMode.BeginDrawRelation)
            {
                mouseDownPoint = new Point(e.X, e.Y);
                EditMode       = EditMode.DrawRelation;
                relationStart  = null;

                for (int i = BoundingItemes.Count - 1; i >= 0; i--)
                {
                    BoundingItem bitem = BoundingItemes[i];
                    if (bitem.HitTest(x, y))
                    {
                        if (bitem.Target is Shape)
                        {
                            relationStart = bitem.Target as Shape;
                        }
                    }
                }
            }
            else if (EditMode == EditMode.Normal)
            {
                mouseDownPoint           = new Point(e.X, e.Y);
                mouseDownAutoscrollPoint = new Point(-MainCanvas.AutoScrollPosition.X, -MainCanvas.AutoScrollPosition.Y);

                for (int i = BoundingItemes.Count - 1; i >= 0; i--)
                {
                    BoundingItem bitem = BoundingItemes[i];
                    if (bitem.HitTest(x, y))
                    {
                        if (bitem.Target is Shape)
                        {
                            currentBoundingItem = bitem;
                            var shape = (Shape)bitem.Target;
                            currentShape = shape;
                            var args = new ShapeMouseEventArgs
                            {
                                BoundingItem = bitem,
                                X            = x,
                                Y            = y,
                                Button       = e.Button,
                                Sender       = this,
                                GridSize     = GridSize,
                                SnapToGrid   = SnapToGrid
                            };
                            shape.OnMouseDown(args);
                            if (args.Redraw)
                            {
                                Refresh();
                            }
                        }

                        return;
                    }
                }
                isPanning = true;
            }
        }
Exemple #4
0
        private void MainCanvas_MouseUp(object sender, MouseEventArgs e)
        {
            var x = (int)((e.X - MainCanvas.AutoScrollPosition.X) / Zoom);
            var y = (int)((e.Y - MainCanvas.AutoScrollPosition.Y) / Zoom);

            if (EditMode == EditMode.DrawRelation)
            {
                relationEnd = null;


                for (int i = BoundingItemes.Count - 1; i >= 0; i--)
                {
                    BoundingItem bitem = BoundingItemes[i];
                    if (bitem.HitTest(x, y))
                    {
                        if (bitem.Target is Shape)
                        {
                            relationEnd = bitem.Target as Shape;
                        }
                    }
                }

                endDrawRelation(relationStart, relationEnd);

                //end drawing
                EditMode = EditMode.Normal;
                MainCanvas.Refresh();
            }
            else if (EditMode == EditMode.Normal)
            {
                Cursor = Cursors.Default;
                currentBoundingItem = null;
                isPanning           = false;
                for (int i = BoundingItemes.Count - 1; i >= 0; i--)
                {
                    BoundingItem bitem = BoundingItemes[i];
                    if (bitem.HitTest(x, y))
                    {
                        if (bitem.Target is Shape)
                        {
                            var shape = (Shape)bitem.Target;
                            var args  = new ShapeMouseEventArgs
                            {
                                BoundingItem = bitem,
                                X            = x,
                                Y            = y,
                                Button       = e.Button,
                                Sender       = this,
                                GridSize     = GridSize,
                                SnapToGrid   = SnapToGrid
                            };
                            shape.OnMouseUp(args);
                            if (args.Redraw)
                            {
                                Refresh();
                            }
                        }

                        return;
                    }
                }
            }
        }