Beispiel #1
0
 void timer_Tick(object sender, EventArgs e)
 {
     agent.DoStep(50);
     PaintPanel.Children.Clear();
     PaintPanel.Children.Add(agent.GetAgentShape());
     PaintPanel.InvalidateVisual();
 }
Beispiel #2
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();
     }
 }
Beispiel #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();
            }
        }
Beispiel #4
0
        public MyForm()
        {
            InitializeComponent();
            Graphics g = PaintPanel.CreateGraphics();

            gl = new GraphicsLibrary(g.GetHdc());//new GraphicsLibrary(e.Graphics.GetHdc());
        }
Beispiel #5
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);
        }
Beispiel #6
0
 private void PaintPanel_MouseDown(object sender, MouseEventArgs e)
 {
     PaintPanel.Select();
     startDrag.X        = e.Location.X;
     startDrag.Y        = e.Location.Y;
     startPointOffset.X = OffsetPaintBox.X;
     startPointOffset.Y = OffsetPaintBox.Y;
 }
Beispiel #7
0
        void DoCommand(ICommand command)
        {
            undoneCommands.Clear();
            command.Execute();
            doneCommands.Push(command);

            PaintPanel.Refresh();
        }
Beispiel #8
0
 private void unSelectAll()
 {
     for (shapes.First(); !shapes.isEnd(); shapes.Next())
     {
         shapes.Current().isSelected = false;
     }
     PaintPanel.Refresh();
 }
Beispiel #9
0
 private void PaintPanel_MouseMove(object sender, MouseEventArgs e)
 {
     if (down)
     {
         PaintPanel.Refresh();
         PaintPanel.Update();
     }
 }
Beispiel #10
0
 private void selectAll()
 {
     for (shapes.First(); !shapes.isEnd(); shapes.Next())
     {
         shapes.Current().isSelected = true;
     }
     PaintPanel.Refresh();
     shapes.notifyAll(0, 0);
 }
Beispiel #11
0
 void Undo()
 {
     if (doneCommands.Count > 0)
     {
         var command = doneCommands.Pop();
         command.Unexecute();
         undoneCommands.Push(command);
         PaintPanel.Refresh();
     }
 }
Beispiel #12
0
 void Redo()
 {
     if (undoneCommands.Count > 0)
     {
         var command = undoneCommands.Pop();
         command.Execute();
         doneCommands.Push(command);
         PaintPanel.Refresh();
     }
 }
Beispiel #13
0
 private void changeSizeSelectedShapes()
 {
     for (shapes.First(); !shapes.isEnd(); shapes.Next())
     {
         if (shapes.Current().isSelected == true)
         {
             shapes.Current().changeSize(GWidth, GHeight);
         }
     }
     PaintPanel.Refresh();
 }
Beispiel #14
0
        public ZYTextImage()
        {
            myBorder    = new ZYTextBorder();
            intWidth    = 90;
            intHeight   = 90;
            m_temppanel = new PaintPanel();

            //加右键菜单选项
            contextMenu.Items.Clear();
            contextMenu.Items.Add("编辑图片");
            contextMenu.Items.Add("图片另存为...");
        }
Beispiel #15
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();
 }
Beispiel #16
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}";
        }
Beispiel #17
0
        public Form1()
        {
            InitializeComponent();
            Graphics g = PaintPanel.CreateGraphics();

            DoubleBuffered = true;
            bmp            = new Bitmap(PaintPanel.Width, PaintPanel.Height);
            line           = new LineDrawer(bmp);
            rectangle      = new RectangleDrawer(bmp);
            square         = new SquareDrawer(bmp);
            triangle       = new TriangleDrawer(bmp);
            ellipse        = new EllipseDrawer(bmp);
            circle         = new CircleDrawer(bmp);
        }
Beispiel #18
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);
            }
        }
Beispiel #19
0
 private void deleteSelectedShapes()
 {
     shapes.First();
     while (!shapes.isEnd())
     {
         if (shapes.Current().isSelected == true)
         {
             shapes.Remove();
         }
         else
         {
             shapes.Next();
         }
     }
     PaintPanel.Refresh();
 }
Beispiel #20
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();
        }
Beispiel #21
0
 protected void RemoveSelectedFigures()
 {
     FigureStorage.First();
     while (!FigureStorage.EOL)
     {
         if (FigureStorage.Current().Selected)
         {
             FigureStorage.Remove();
         }
         else
         {
             FigureStorage.Next();
         }
     }
     PaintPanel.Refresh();
 }
Beispiel #22
0
    public override void _Ready()
    {
        _network = (ClientNetwork)GetNode("/root/PaintNetwork");

        _landscapeLayout = LandscapeLayout();

        _currentLayout = _landscapeLayout;

        _colorPalette  = (ColorPalette)_currentLayout.ColorToolsContainer.GetNode("ColorPalette");
        _paintPanel    = (PaintPanel)_currentLayout.ColorPanelContainer.GetNode("PaintPanel");
        _messages      = (Messages)_currentLayout.MessagesContainer.GetNode("Messages");
        _paintControls = (PaintControls)_currentLayout.ColorToolsContainer.GetNode("PaintControls");

        _paintControls.Connect(nameof(PaintControls.SetBrushMode), _paintPanel, nameof(PaintPanel.SetBrushMode));
        _paintControls.Connect(nameof(PaintControls.SetBrushSize), _paintPanel, nameof(PaintPanel.SetBrushSize));
        _colorPalette.Connect(nameof(ColorPalette.SetColor), _paintPanel, nameof(PaintPanel.SetColor));
    }
Beispiel #23
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();
        }
Beispiel #24
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);
            }
        }
Beispiel #25
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();
 }
Beispiel #26
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();
 }
Beispiel #27
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);
        }
Beispiel #28
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);
 }
Beispiel #29
0
        private void buttonOpenPaintPanel_Click(object sender, EventArgs e)
        {
            var paintForm = new PaintPanel();

            paintForm.ShowDialog();
        }
Beispiel #30
0
 private void цветToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SetColorSelectedFigures();
     PaintPanel.Refresh();
 }