Ejemplo n.º 1
0
 private void TreeView_NodeMouseClick_1(object sender, TreeNodeMouseClickEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         e.Node.Toggle();
     }
     else
     {
         if (e.Node.Level > 0)
         {
             e.Node.Checked = false;
             e.Node.Collapse(true);
             shapes.notifyAll(0, 0);
             return;
         }
         treeView.Shapes.First();
         for (int i = 0; i < e.Node.Index; i++)
         {
             treeView.Shapes.Next();
         }
         treeView.Shapes.Current().selectiveInvert();
         e.Node.Collapse(true);
         shapes.notifyAll(0, 0);
         PaintPanel.Refresh();
     }
 }
Ejemplo n.º 2
0
        private bool SelectShape(int x, int y)
        {
            Shape shape;

            for (shapes.Last(); !shapes.isEnd(); shapes.Prev())
            {
                shape = shapes.Current();
                if (shape.lookAtShape(x, y))
                {
                    if (shape.isSelected)
                    {
                        shape.isSelected = false;
                        shapes.Remove();
                        shapes.AddFirst(shape);
                    }
                    else
                    {
                        shape.isSelected = true;
                        shapes.Remove();
                        shapes.AddLast(shape);
                    }
                    PaintPanel.Refresh();
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        private void PaintPanel_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (!SelectShape(e.X, e.Y))
                {
                    if (shapeType == 1)
                    {
                        shapes.AddFirst(new Circle(e.X - GWidth / 2, e.Y - GHeight / 2, GWidth, GHeight));
                    }

                    else if (shapeType == 2)
                    {
                        shapes.AddFirst(new Rectangle(e.X, e.Y - GHeight, GWidth, GHeight));
                    }

                    else if (shapeType == 3)
                    {
                        shapes.AddFirst(new Triangle(e.X, e.Y, GWidth, GHeight));
                    }
                }
                CountLbl.Text = "Элементов: " + shapes.Count.ToString();
                shapes.notifyAll(0, 0);
                PaintPanel.Refresh();
            }
        }
Ejemplo n.º 4
0
        void DoCommand(ICommand command)
        {
            undoneCommands.Clear();
            command.Execute();
            doneCommands.Push(command);

            PaintPanel.Refresh();
        }
Ejemplo n.º 5
0
 private void unSelectAll()
 {
     for (shapes.First(); !shapes.isEnd(); shapes.Next())
     {
         shapes.Current().isSelected = false;
     }
     PaintPanel.Refresh();
 }
Ejemplo n.º 6
0
 private void PaintPanel_MouseMove(object sender, MouseEventArgs e)
 {
     if (down)
     {
         PaintPanel.Refresh();
         PaintPanel.Update();
     }
 }
Ejemplo n.º 7
0
 private void selectAll()
 {
     for (shapes.First(); !shapes.isEnd(); shapes.Next())
     {
         shapes.Current().isSelected = true;
     }
     PaintPanel.Refresh();
     shapes.notifyAll(0, 0);
 }
Ejemplo n.º 8
0
 void Undo()
 {
     if (doneCommands.Count > 0)
     {
         var command = doneCommands.Pop();
         command.Unexecute();
         undoneCommands.Push(command);
         PaintPanel.Refresh();
     }
 }
Ejemplo n.º 9
0
 void Redo()
 {
     if (undoneCommands.Count > 0)
     {
         var command = undoneCommands.Pop();
         command.Execute();
         doneCommands.Push(command);
         PaintPanel.Refresh();
     }
 }
Ejemplo n.º 10
0
 private void changeSizeSelectedShapes()
 {
     for (shapes.First(); !shapes.isEnd(); shapes.Next())
     {
         if (shapes.Current().isSelected == true)
         {
             shapes.Current().changeSize(GWidth, GHeight);
         }
     }
     PaintPanel.Refresh();
 }
Ejemplo n.º 11
0
 private void changeColorSelectedShapes()
 {
     colorSwitch.ShowDialog();
     for (shapes.First(); !shapes.isEnd(); shapes.Next())
     {
         if (shapes.Current().isSelected == true)
         {
             shapes.Current().color = colorSwitch.Color;
         }
     }
     PaintPanel.Refresh();
 }
Ejemplo n.º 12
0
        public Point OffsetPaintBox = Point.Empty; //сдвиг начала кординат полотна рисования

        private void PaintPanel_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Middle)
            {
                OffsetPaintBox.X = startPointOffset.X + (e.Location.X - startDrag.X);
                OffsetPaintBox.Y = startPointOffset.Y + (e.Location.Y - startDrag.Y);

                BeginCoordLbl.Text = $"Начало координат: {OffsetPaintBox.X}, {OffsetPaintBox.Y}";

                PaintPanel.Refresh();
            }
            CoordsLbl.Text      = $"x:{OffsetPaintBox.X + e.Location.X}, y:{OffsetPaintBox.Y + e.Location.Y}";
            FigureCountLbl.Text = $"Фигур: {FigureStorage.Count}";
        }
Ejemplo n.º 13
0
        private void ResultButton_Click(object sender, EventArgs e)
        {
            PaintPanel.Refresh();
            classes = new ClassesData[0];
            Random r = new Random();
            Point  p = pointlist.pointcollection[r.Next(0, pointlist.pointcollection.Length)].point;

            Array.Resize(ref classes, classes.Length + 1);
            classes[classes.Length - 1] = (new ClassesData(p.X, p.Y, Color.Black));
            p = pointlist.pointcollection[Calculate(pointlist, classes.First().center.point)].point;
            Array.Resize(ref classes, classes.Length + 1);
            classes[classes.Length - 1] = (new ClassesData(p.X, p.Y, Color.Black));
            for (int i = 0; i < pointlist.pointcollection.Length; i++)
            {
                int numCluster = Calculate(classes, pointlist.pointcollection[i].point);
                pointlist.pointcollection[i].color = colors[numCluster];
                classes[numCluster].ObjectClass.Add(pointlist.pointcollection[i]);
            }

            MaxPoint mp = NewCenter(classes);

            while (IsValidCenter(mp))
            {
                Array.Resize(ref classes, classes.Length + 1);
                classes[classes.Length - 1] = (new ClassesData(mp.point.X, mp.point.Y, Color.Black));
                for (int i = 0; i < pointlist.pointcollection.Length; i++)
                {
                    int numCluster = Calculate(classes, pointlist.pointcollection[i].point);
                    pointlist.pointcollection[i].color = colors[numCluster];
                    classes[numCluster].ObjectClass.Add(pointlist.pointcollection[i]);
                }
                mp = NewCenter(classes);
            }
            foreach (PointData pd in pointlist.pointcollection)
            {
                graph.DrawRectangle(new Pen(pd.color),
                                    pd.point.X, pd.point.Y, 1, 1);
            }
            for (int i = 0; i < classes.Length; i++)
            {
                Rectangle rect = new Rectangle(classes[i].center.point.X,
                                               classes[i].center.point.Y, 10, 10);

                graph.DrawRectangle(new Pen(classes[i].center.color),
                                    rect);
                graph.FillRectangle(Brushes.Black, rect);
            }
        }
Ejemplo n.º 14
0
 private void deleteSelectedShapes()
 {
     shapes.First();
     while (!shapes.isEnd())
     {
         if (shapes.Current().isSelected == true)
         {
             shapes.Remove();
         }
         else
         {
             shapes.Next();
         }
     }
     PaintPanel.Refresh();
 }
Ejemplo n.º 15
0
        private void treeViewObserver_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Level > 0)
            {
                e.Node.Checked = false;
                return;
            }
            var it = treeViewObserver.Figures.CreateIterator();

            for (int i = 0; i < e.Node.Index; i++)
            {
                it.Next();
            }
            DoCommand(new SelectFigureCommand(treeViewObserver.Figures, it.GetCurrent().Value, e.Node.Checked));
            PaintPanel.Refresh();
        }
Ejemplo n.º 16
0
 protected void RemoveSelectedFigures()
 {
     FigureStorage.First();
     while (!FigureStorage.EOL)
     {
         if (FigureStorage.Current().Selected)
         {
             FigureStorage.Remove();
         }
         else
         {
             FigureStorage.Next();
         }
     }
     PaintPanel.Refresh();
 }
Ejemplo n.º 17
0
        private void MoveShape(int dx, int dy, int bx, int by, bool isUp)
        {
            Shape shape;

            for (shapes.First(); !shapes.isEnd(); shapes.Next())
            {
                shape = shapes.Current();
                if (shape.isSelected == true)
                {
                    shape.Move(dx, dy);
                    if (shape.borderCheck(bx, by, isUp))
                    {
                        shape.Move(-dx, -dy);
                    }
                }
            }
            PaintPanel.Refresh();
        }
Ejemplo n.º 18
0
        private void RandomButton_Click(object sender, EventArgs e)
        {
            PaintPanel.Refresh();
            Random r = new Random();

            graph     = PaintPanel.CreateGraphics();
            pointlist = new PointList(Convert.ToInt32(PointsLabel.Text));
            classes   = new ClassesData[0];
            for (int i = 0; i < pointlist.pointcollection.Length; i++)
            {
                Point p = new Point(r.Next(1, 200), r.Next(1, 300));
                pointlist.pointcollection[i] = (new PointData(p.X, p.Y, Color.Red));
            }
            foreach (PointData pd in pointlist.pointcollection)
            {
                graph.DrawRectangle(new Pen(pd.color),
                                    pd.point.X, pd.point.Y, 2, 2);
            }
        }
Ejemplo n.º 19
0
 public void setSticky()
 {
     for (shapes.First(); !shapes.isEnd(); shapes.Next())
     {
         if (shapes.Current().isSelected)
         {
             if (shapes.Current().isSticky == false)
             {
                 shapes.Current().isSticky = true;
             }
             else
             {
                 shapes.Current().isSticky = false;
                 shapes.Current().RemoveAllObserver();
             }
         }
     }
     shapes.notifyAll(0, 0);
     PaintPanel.Refresh();
 }
Ejemplo n.º 20
0
 public void shapesUngroup()
 {
     for (shapes.First(); !shapes.isEnd();)
     {
         if (shapes.Current().isSelected&& shapes.Current() is GroupedShapes)
         {
             var groupElem = shapes.Current().getGroupElem();
             shapes.Remove(shapes.Current());
             for (groupElem.First(); !groupElem.isEnd(); groupElem.Next())
             {
                 shapes.AddFirst(groupElem.Current());
             }
         }
         else
         {
             shapes.Next();
         }
     }
     CountLbl.Text = "Элементов: " + shapes.Count.ToString();
     shapes.notifyAll(0, 0);
     PaintPanel.Refresh();
 }
Ejemplo n.º 21
0
        public void shapesToGroup()
        {
            GroupedShapes group = new GroupedShapes();

            for (shapes.First(); !shapes.isEnd();)
            {
                if (shapes.Current().isSelected)
                {
                    shapes.Current().Unselect();
                    group.Add(shapes.Current());
                    shapes.Remove(shapes.Current());
                }
                else
                {
                    shapes.Next();
                }
            }
            group.Select();
            shapes.AddLast(group);
            CountLbl.Text = "Элементов: " + shapes.Count.ToString();
            PaintPanel.Refresh();
            shapes.notifyAll(0, 0);
        }
Ejemplo n.º 22
0
 private void deleteSelectedShapes()
 {
     shapes.First();
     while (!shapes.isEnd())
     {
         if (shapes.Current().isSelected == true)
         {
             if (shapes.Current().isSticky)
             {
                 shapes.Current().isSticky = false;
                 shapes.Current().RemoveAllObserver();
             }
             shapes.Remove();
         }
         else
         {
             shapes.Next();
         }
     }
     CountLbl.Text = "Элементов: " + shapes.Count.ToString();
     PaintPanel.Refresh();
     shapes.notifyAll(0, 0);
 }
Ejemplo n.º 23
0
 private void удалитьВыделенныеToolStripMenuItem_Click(object sender, EventArgs e)
 {
     DoCommand(new RemoveSelectedFiguresCommand(FigureStorage));
     PaintPanel.Refresh();
 }
Ejemplo n.º 24
0
 private void цветToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SetColorSelectedFigures();
     PaintPanel.Refresh();
 }
Ejemplo n.º 25
0
 private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
 {
     LoadFigures();
     PaintPanel.Refresh();
 }
Ejemplo n.º 26
0
 private void LoadFormFileBtn_Click(object sender, EventArgs e)
 {
     LoadFigures(factory);
     PaintPanel.Refresh();
 }
Ejemplo n.º 27
0
 private void MainForm_Resize(object sender, EventArgs e)
 {
     PaintPanel.Refresh();
 }