Ejemplo n.º 1
0
Archivo: Form1.cs Proyecto: pasibun/Dep
        public Shape DrawShape(int x, int y, Size size)
        {
            if (drawRectangle)
            {
                RectangleShape rectangleShape = new RectangleShape(this, new Point(x, y), size, commandIndex, false, new List <Label>(), 0);
                rectangleShape.DrawShape(x, y, size.Width, size.Height, redPen);
                drawnShapes.Add(rectangleShape);
                drawRectangle = true;
                rec.InsertInUndoRedoForDraw(rectangleShape, x, y, size.Width, size.Height);
                commandIndex++;
                return(rectangleShape);
            }
            if (drawEllipse)
            {
                EllipseShape ellipseShape = new EllipseShape(this, new Point(x, y), size, commandIndex, false, new List <Label>(), 0);
                ellipseShape.DrawShape(x, y, size.Width, size.Height, redPen);
                drawnShapes.Add(ellipseShape);
                drawEllipse = true;
                rec.InsertInUndoRedoForDraw(ellipseShape, x, y, size.Width, size.Height);
                commandIndex++;
                return(ellipseShape);
            }
            movedObject   = false;
            resizedObject = false;

            return(null);
        }
Ejemplo n.º 2
0
Archivo: Form1.cs Proyecto: pasibun/Dep
        private void SelectShape(MouseEventArgs e)
        {
            Point[] pt = { new Point(e.X, e.Y) };

            for (int i = 0; i < drawnShapes.Count; ++i)
            {
                if (drawnShapes[i].Contains(pt[0].X, pt[0].Y))
                {
                    selectedShape = i;

                    oldWidth  = drawnShapes[selectedShape].Width;
                    oldHeight = drawnShapes[selectedShape].Height;

                    oldLocationX = drawnShapes[i].X;
                    oldLocationY = drawnShapes[i].Y;

                    Refresh();

                    if (drawnShapes[i] is RectangleShape)
                    {
                        drawnShapes[i] = new RectangleShape(this, new Point(drawnShapes[i].X, drawnShapes[i].Y), new Size(drawnShapes[i].Width, drawnShapes[i].Height), drawnShapes[i].ShapeId, drawnShapes[i].InGroup, drawnShapes[i].OrnamentList, drawnShapes[i].ShapeIndex);
                    }
                    else
                    {
                        drawnShapes[i] = new EllipseShape(this, new Point(drawnShapes[i].X, drawnShapes[i].Y), new Size(drawnShapes[i].Width, drawnShapes[i].Height), drawnShapes[i].ShapeId, drawnShapes[i].InGroup, drawnShapes[i].OrnamentList, drawnShapes[i].ShapeIndex);
                    }

                    drawnShapes[i].DrawShape(drawnShapes[i].X, drawnShapes[i].Y, drawnShapes[i].Width, drawnShapes[i].Height, bluePen);

                    if (comp != null && !resize.Checked && !moveCheckBox.Checked && newGroup)
                    {
                        leaf = new Leaf(drawnShapes[i]);
                        comp.AddSubordinate(leaf);
                        drawnShapes[i].InGroup = true;
                        if (drawnShapes[i].OrnamentList.Count != 0)
                        {
                            int countOrn = drawnShapes[i].OrnamentList.Count;
                            comp.compositeSize = comp.compositeSize + countOrn;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
Archivo: Form1.cs Proyecto: pasibun/Dep
        protected override void OnMouseMove(MouseEventArgs e)
        {
            Point[] pt = { new Point(e.X, e.Y) };

            for (int i = 0; i < drawnShapes.Count; ++i)
            {
                inRect = drawnShapes[i].Contains(pt[0].X, pt[0].Y);

                if (selectedShape > -1)
                {
                    if (mouseDown && inRect && !resize.Checked && moveCheckBox.Checked)
                    {
                        MoveShape(drawnShapes, selectedShape, e, true);
                        canAddCircle = true;
                    }
                    else if (!mouseDown && canAddCircle)
                    {
                        int newx;
                        int newy;
                        newx           = drawnShapes[selectedShape].X;
                        newy           = drawnShapes[selectedShape].Y;
                        deltaLocationX = newx - oldLocationX;
                        deltaLocationY = newy - oldLocationY;
                        canAddCircle   = false;

                        // drawnShapes[selectedShape].MoveOrnaments(deltaLocationX, deltaLocationY, 0, 0, true);

                        rec.InsertInUndoRedoForMove(drawnShapes[selectedShape], deltaLocationX, deltaLocationY);
                    }
                    //Make sure the drawings that arent selected dont get lost.
                    else if (!inRect)
                    {
                        if (drawnShapes[i] is RectangleShape)
                        {
                            drawnShapes[i] = new RectangleShape(this, new Point(drawnShapes[i].X, drawnShapes[i].Y),
                                                                new Size(drawnShapes[i].Width, drawnShapes[i].Height), drawnShapes[i].ShapeId,
                                                                drawnShapes[i].InGroup, drawnShapes[i].OrnamentList, drawnShapes[i].ShapeIndex);
                        }
                        else
                        {
                            drawnShapes[i] = new EllipseShape(this, new Point(drawnShapes[i].X, drawnShapes[i].Y),
                                                              new Size(drawnShapes[i].Width, drawnShapes[i].Height), drawnShapes[i].ShapeId,
                                                              drawnShapes[i].InGroup, drawnShapes[i].OrnamentList, drawnShapes[i].ShapeIndex);
                        }

                        drawnShapes[i].DrawShape(drawnShapes[i].X, drawnShapes[i].Y, drawnShapes[i].Width, drawnShapes[i].Height, redPen);
                    }
                    //resize when mouse is down.
                    if (resize.Checked && !moveCheckBox.Checked)
                    {
                        if (mouseDown)
                        {
                            ResizeShape(drawnShapes, selectedShape, e, true);
                            canAddToList = true;
                        }
                        else if (!mouseDown && canAddToList)
                        {
                            int newWidth  = drawnShapes[selectedShape].Width;
                            int newHeight = drawnShapes[selectedShape].Height;
                            deltaWidth  = newWidth - oldWidth;
                            deltaHeight = newHeight - oldHeight;

                            canAddToList = false;

                            rec.InsertInUndoRedoForResize(drawnShapes[selectedShape], deltaWidth, deltaHeight);
                        }
                    }
                }
            }
        }