Ejemplo n.º 1
0
        private void ToolChange_Click(object sender, EventArgs e)
        {
            selectedTool.BackColor = Color.FromArgb(38, 38, 38);
            selectedTool           = (Button)sender;
            selectedTool.BackColor = Color.FromArgb(25, 25, 25);

            switch (selectedTool.Name)
            {
            case "butBrush": tool = new BrushSetting(); break;

            case "butEraser": tool = new EraserSetting(); break;

            case "butFill": tool = new FillSetting(); break;

            case "butLine": tool = new LineSetting(); break;

            case "butRectangle": tool = new RectangleSetting(); break;

            case "butEllipse": tool = new EllipseSetting(); break;

            case "butPolygon": tool = new PolygonSetting(); break;

            case "butCrop": tool = new CropSetting(); break;
            }
            tool.InstallTools(panelTools);
            layers?.Update();
        }
Ejemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            selectedTool = butBrush;
            tool         = new BrushSetting();
            ToolChange_Click(selectedTool, null);

            activeKeys = new Dictionary <Keys, bool>
            {
                { Keys.Shift, false }
            };
        }
Ejemplo n.º 3
0
        private void Picture_MouseDown(object sender, MouseEventArgs e)
        {
            if (layers.Count == 0)
            {
                DialogResult dialogResult = MessageBox.Show("Отсуствуют слои", "Paint++", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (tool.Name != NameTool.Polygon && layers.Visible && e.Button == MouseButtons.Left)
            {
                layerHistory.Add(layers.SaveState());
            }

            prevPoint.X       = e.X;
            prevPoint.Y       = e.Y;
            mouseClickPoint.X = e.X;
            mouseClickPoint.Y = e.Y;

            pen          = tool.GetPen();
            pen.StartCap = LineCap.Round;
            pen.EndCap   = LineCap.Round;

            if (tool.Name == NameTool.Fill && e.Button == MouseButtons.Left && layers.Visible)
            {
                layers.CurrentBitmap.FiilArea(pen, new Point(e.X, e.Y));
            }
            if (tool.Name == NameTool.Polygon && layers.Visible)
            {
                PolygonSetting tempPolygon = (PolygonSetting)tool;
                if (tempPolygon.Image == null)
                {
                    tempPolygon.Image = new Bitmap(layers.Width, layers.Height);
                }

                if (e.Button == MouseButtons.Left)
                {
                    tempPolygon.AddPoint(new Point(e.X, e.Y));
                    if (tempPolygon.Points.Count > 1)
                    {
                        using (Graphics graph = Graphics.FromImage(tempPolygon.Image))
                        {
                            graph.DrawLines(new Pen(Color.Black), tempPolygon.Points.ToArray());
                        }
                    }
                }
                if (e.Button == MouseButtons.Right)
                {
                    layerHistory.Add(layers.SaveState());
                    if (tempPolygon.Points.Count > 1)
                    {
                        using (Graphics graph = Graphics.FromImage(layers.CurrentBitmap))
                        {
                            graph.FillPolygon(new SolidBrush(tempPolygon.FillColor), tempPolygon.Points.ToArray());
                            if (tempPolygon.Depth > 0)
                            {
                                graph.DrawPolygon(pen, tempPolygon.Points.ToArray());
                            }
                        }
                    }
                    tempPolygon.Points.Clear();
                    tempPolygon.Image = null;
                }
                tool = tempPolygon;
            }

            if (e.Button == MouseButtons.Left && !layers.Visible)
            {
                MessageBox.Show("Этот слой скрыт", "Paint++", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }