예제 #1
0
파일: MainForm.cs 프로젝트: VladaCat/Paint
        private void OpenFileButton_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|PNG Image|*.png|JSON File|*.json";
            openFileDialog1.ShowDialog();

            if (openFileDialog1.FileName != "" && openFileDialog1.FileName != "openFileDialog1")
            {
                _bl.Clear();
                _currentBitmap       = new PaintBitmap(pictureBoxMain.Width, pictureBoxMain.Height);
                _bufferedBitmap      = _currentBitmap.Clone() as PaintBitmap;
                pictureBoxMain.Image = _currentBitmap.ToImage();
                Repaint();

                if (openFileDialog1.FilterIndex == 4)
                {
                    var strings = File.ReadAllText(openFileDialog1.FileName);

                    if (_bl.JsonOpen(strings, _currentBitmap))
                    {
                        Repaint();
                    }
                }
                else
                {
                    _currentBitmap       = (PaintBitmap)PaintImage.FromFile(openFileDialog1.FileName);
                    pictureBoxMain.Image = _currentBitmap.ToImage();
                    Repaint();
                }
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: albinatim/lab7
 private void SizeNumUpDown_ValueChanged(object sender, EventArgs e)
 {
     if (figures.Current.Data.R < (float)SizeNumUpDown.Value)
     {
         float left  = figures.Current.Data.Left;
         float right = figures.Current.Data.Right;
         float up    = figures.Current.Data.Up;
         float down  = figures.Current.Data.Down;
         if ((right + 1 <= PaintImage.Width) && (left - 1 >= 0) && (down + 1 <= PaintImage.Height) && (up - 1 >= 0))
         {
             Keys    key        = Keys.Add;
             Command command    = commands[key];
             Command newcommand = command.Clone();
             newcommand.Execute(figures.Current.Data);
             history.Push(newcommand);
             PaintImage.Refresh();
         }
     }
     else if (figures.Current.Data.R > (float)SizeNumUpDown.Value)
     {
         if (figures.Current.Data.R - 1 >= 15)
         {
             Keys    key        = Keys.Subtract;
             Command command    = commands[key];
             Command newcommand = command.Clone();
             newcommand.Execute(figures.Current.Data);
             history.Push(newcommand);
             PaintImage.Refresh();
         }
     }
 }
예제 #3
0
 private void Global_KeyDown(Keys keyData)
 {
     if (keyData == (Keys.Control | Keys.Z))
     {
         pictureBox.BackAction();
     }
     else if (keyData == (Keys.Control | Keys.C))
     {
         IPaintObject paintObject = pictureBox.CurrentPaintObject;
         if (paintObject is PaintImage)
         {
             PaintImage paintImage = (PaintImage)paintObject;
             Clipboard.SetImage(paintImage.Bitmap);
             System.Media.SystemSounds.Beep.Play();
         }
     }
     else if (keyData == (Keys.Control | Keys.V))
     {
         if (Clipboard.ContainsImage())
         {
             Image image = Clipboard.GetImage();
             pictureBox.InsertImage(new Bitmap(image, image.Size));
         }
     }
 }
예제 #4
0
        public void CloneTest()
        {
            Image      image       = new Bitmap(1, 1);
            PaintImage paintImage  = new PaintBitmap(image);
            PaintImage actualImage = paintImage.Clone() as PaintImage;

            Assert.AreNotSame(paintImage, actualImage);
            Image actuaPaintlImage = actualImage.ToImage();

            Assert.AreNotSame(actuaPaintlImage, image);
            Assert.AreEqual(1, actuaPaintlImage.Width);
            Assert.AreEqual(1, actuaPaintlImage.Height);
        }
예제 #5
0
        private void buttonCtrlC_Click(object sender, EventArgs e)
        {
            disableAllButtons();

            IPaintObject paintObject = pictureBox.CurrentPaintObject;

            if (paintObject != null && paintObject is PaintImage)
            {
                PaintImage paintImage = (PaintImage)paintObject;
                Clipboard.SetImage(paintImage.Bitmap);
                System.Media.SystemSounds.Beep.Play();
            }
        }
        private void ImageExplorer_Paint(object sender, PaintEventArgs e)
        {
            if (_CanvasGraphics == null)
            {
                return;
            }

            if (_Image != null)
            {
                _CanvasGraphics.Clear(this.BackColor);
                _CanvasGraphics.DrawImage(_Image, new RectangleF(0, 0, this.ClientSize.Width, this.ClientSize.Height), _ViewRegion, GraphicsUnit.Pixel);
                PaintImage?.Invoke(this, new PaintEventArgs(_CanvasGraphics, e.ClipRectangle));
            }

            e.Graphics.DrawImage(_Canvas, 0, 0);
        }
예제 #7
0
파일: Form1.cs 프로젝트: albinatim/lab7
        private void загрузитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string     filename = openFileDialog1.FileName;
                FileStream file     = new FileStream(filename, FileMode.Open);
                while (figures.Count != 0)
                {
                    figures.Delete();
                }

                figures.Load(file);
                figuresChanged();
                ColorBtn.BackColor = figures.Current.Data.pen.Color;
                PaintImage.Refresh();
                file.Close();
            }
        }
예제 #8
0
파일: Form1.cs 프로젝트: albinatim/lab7
 private void button2_Click(object sender, EventArgs e)
 {
     if (colorDialog1.ShowDialog() == DialogResult.OK)
     {
         ColorBtn.BackColor = colorDialog1.Color;
         if (figures.Count != 0)
         {
             figures.Current.Data.pen.Color = colorDialog1.Color;
             if (figures.Current.Data.GetType() == new Storage().GetType())
             {
                 int  t = 1;
                 Node n = figures.Current.Data.GetHead();
                 while (t <= figures.Current.Data.GetCount())
                 {
                     n.Data.pen.Color = colorDialog1.Color;
                     //PaintImage.Refresh();
                     t++; n = n.Next;
                 }
             }
             PaintImage.Refresh();
         }
     }
 }
예제 #9
0
파일: Form1.cs 프로젝트: albinatim/lab7
 private void button1_Click(object sender, EventArgs e)
 {
     if (figures.Current.Data.GetType() == new Storage().GetType())
     {
         Keys    key        = Keys.U;
         Command command    = commands[key];
         Command newcommand = command.Clone();
         newcommand.Execute(figures.Current.Data);
         //history.Push(newcommand);
         figuresChanged();
         PaintImage.Refresh();
     }
     else
     {
         if (figures.Count != 0)
         {
             int m = 1; Node nd = figures.Head;
             int k = 0;
             while (m <= figures.Count)
             {
                 if (nd.Chosen == true)
                 {
                     k++;
                 }
                 m++; nd = nd.Next;
             }
             if (k > 0)
             {
                 Storage Group = new Storage();
                 Node    node  = figures.Head;
                 int     t     = 1;
                 while (t <= figures.Count)
                 {
                     if (node.Chosen == true)
                     {
                         Group.Add(node.Data);
                     }
                     t++;
                     node = node.Next;
                 }
                 t = 1;
                 Node n = Group.Head;
                 Group.Left = n.Data.Left; Group.Up = n.Data.Up; Group.Right = n.Data.Right; Group.Down = n.Data.Down;
                 while (t <= Group.Count)
                 {
                     if (n.Data.Right > Group.Right)
                     {
                         Group.Right = n.Data.Right;
                     }
                     if (n.Data.Down > Group.Down)
                     {
                         Group.Down = n.Data.Down;
                     }
                     if (n.Data.Left < Group.Left)
                     {
                         Group.Left = n.Data.Left;
                     }
                     if (n.Data.Up < Group.Up)
                     {
                         Group.Up = n.Data.Up;
                     }
                     t++; n = n.Next;
                 }
                 t       = 1; n = Group.Head;
                 Group.X = Group.Left + (Group.Right - Group.Left) / 2;
                 Group.Y = Group.Up + (Group.Down - Group.Up) / 2;
                 if (Group.X - Group.Left >= Group.Y - Group.Up)
                 {
                     Group.R = Group.X - Group.Left;
                 }
                 else
                 {
                     Group.R = Group.Y - Group.Up;
                 }
                 Keys    key        = Keys.G;
                 Command command    = commands[key];
                 Command newcommand = command.Clone();
                 newcommand.Execute(Group);
                 history.Push(newcommand);
                 PaintImage.Refresh();
                 //figures.DeleteChosen();
                 figuresChanged();
                 PaintImage.Refresh();
             }
         }
     }
 }
예제 #10
0
파일: Form1.cs 프로젝트: albinatim/lab7
 private void RotationTrBar_Scroll(object sender, EventArgs e)
 {
     if (BeginAngle < RotationTrBar.Value)
     {
         int k = RotationTrBar.Value - BeginAngle;
         BeginAngle = RotationTrBar.Value;
         for (int i = 0; i < k; i++)
         {
             if (figures.Current.Data.GetType() != new Circle().GetType())
             {
                 Keys    key     = Keys.R;
                 Command command = commands[key];
                 Star    s       = new Star();
                 s.Angle       = figures.Current.Data.Angle;
                 s.NumOfAngles = figures.Current.Data.NumOfAngles;
                 s.X           = figures.Current.Data.X;
                 s.Y           = figures.Current.Data.Y;
                 s.R           = figures.Current.Data.R;
                 s.Left        = figures.Current.Data.Left;
                 s.Right       = figures.Current.Data.Right;
                 s.Up          = figures.Current.Data.Up;
                 s.Down        = figures.Current.Data.Down;
                 if (key == Keys.R)
                 {
                     s.Rotate(-1);
                 }
                 else
                 {
                     s.Rotate(1);
                 }
                 float left = s.Left, right = s.Right, up = s.Up, down = s.Down;
                 if ((left >= 0) && (right <= PaintImage.Width) && (up >= 0) && (down <= PaintImage.Height))
                 {
                     Command newcommand = command.Clone();
                     newcommand.Execute(figures.Current.Data);
                     history.Push(newcommand);
                     PaintImage.Refresh();
                 }
             }
         }
     }
     else
     {
         int k = BeginAngle - RotationTrBar.Value;
         BeginAngle = RotationTrBar.Value;
         for (int i = 0; i < k; i++)
         {
             if (figures.Current.Data.GetType() != new Circle().GetType())
             {
                 Keys    key     = Keys.T;
                 Command command = commands[key];
                 Star    s       = new Star();
                 s.Angle       = figures.Current.Data.Angle;
                 s.NumOfAngles = figures.Current.Data.NumOfAngles;
                 s.X           = figures.Current.Data.X;
                 s.Y           = figures.Current.Data.Y;
                 s.R           = figures.Current.Data.R;
                 s.Left        = figures.Current.Data.Left;
                 s.Right       = figures.Current.Data.Right;
                 s.Up          = figures.Current.Data.Up;
                 s.Down        = figures.Current.Data.Down;
                 if (key == Keys.R)
                 {
                     s.Rotate(-1);
                 }
                 else
                 {
                     s.Rotate(1);
                 }
                 float left = s.Left, right = s.Right, up = s.Up, down = s.Down;
                 if ((left >= 0) && (right <= PaintImage.Width) && (up >= 0) && (down <= PaintImage.Height))
                 {
                     Command newcommand = command.Clone();
                     newcommand.Execute(figures.Current.Data);
                     history.Push(newcommand);
                     PaintImage.Refresh();
                 }
             }
         }
     }
 }
예제 #11
0
파일: Form1.cs 프로젝트: albinatim/lab7
        private void PaintImage_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (figures.Count != 0)
                {
                    Node n = figures.Head;
                    int  t = 1;
                    while (t <= figures.Count)
                    {
                        if ((e.X - n.Data.X) * (e.X - n.Data.X) + (e.Y - n.Data.Y) * (e.Y - n.Data.Y) <= (n.Data.R * n.Data.R))
                        {
                            if (n.Chosen == false)
                            {
                                n.Chosen = true;
                            }
                            else
                            {
                                n.Chosen = false;
                            }
                            PaintImage.Refresh();
                        }
                        t++;
                        n = n.Next;
                    }
                }
            }

            if (e.Button == MouseButtons.Left)
            {
                Keys    key     = Keys.LButton;
                Command command = commands[key];

                if (CircleRB.Checked)
                {
                    Circle c = new Circle(e.X, e.Y, (float)SizeNumUpDown.Value);
                    if ((c.X + c.R <= PaintImage.Width) && (c.X - c.R >= 0) && (c.Y + c.R <= PaintImage.Height) && (c.Y - c.R >= 0))
                    {
                        c.pen.Color = ColorBtn.BackColor;
                        Command newcommand = command.Clone();
                        newcommand.Execute(c);
                        //history.Push(newcommand);
                        figuresChanged();
                        PaintImage.Refresh();
                    }
                }
                if (StarRB.Checked)
                {
                    if (AnglesNumUpDown.Value < 5)
                    {
                        AnglesNumUpDown.Value = 5;
                    }
                    if (AnglesNumUpDown.Value % 2 == 0)
                    {
                        AnglesNumUpDown.Value--;
                    }
                    Star s = new Star(e.X, e.Y, (float)SizeNumUpDown.Value, (int)AnglesNumUpDown.Value, RotationTrBar.Value);
                    if ((s.Right <= PaintImage.Width) && (s.Left >= 0) && (s.Down <= PaintImage.Height) && (s.Up >= 0))

                    {
                        s.pen.Color = ColorBtn.BackColor;
                        Command newcommand = command.Clone();
                        newcommand.Execute(s);
                        //history.Push(newcommand);
                        figuresChanged();
                        PaintImage.Refresh();
                    }
                }
                if (PolygonRB.Checked)
                {
                    if (AnglesNumUpDown.Value < 3)
                    {
                        AnglesNumUpDown.Value = 3;
                    }
                    Polygon p = new Polygon(e.X, e.Y, (int)AnglesNumUpDown.Value, RotationTrBar.Value, (float)SizeNumUpDown.Value);
                    if ((p.Right <= PaintImage.Width) && (p.Left >= 0) && (p.Down <= PaintImage.Height) && (p.Up >= 0))

                    {
                        p.pen.Color = ColorBtn.BackColor;
                        Command newcommand = command.Clone();
                        newcommand.Execute(p);
                        //history.Push(newcommand);
                        figuresChanged();
                        PaintImage.Refresh();
                    }
                }
            }
        }
예제 #12
0
파일: Form1.cs 프로젝트: albinatim/lab7
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            Keys   key    = e.KeyCode;
            Random rand   = new Random();
            float  r      = rand.Next(20, 80);
            float  y      = rand.Next((int)r, PaintImage.Height - (int)r);
            float  x      = rand.Next((int)r, PaintImage.Width - (int)r);
            int    angles = rand.Next(3, 20);
            int    rays   = 2 * rand.Next(2, 7) + 1;
            float  rotate = rand.Next(360);

            if (commands.ContainsKey(key))
            {
                Command command = commands[key];
                if (key == Keys.D1)
                {
                    Circle c = new Circle(x, y, r);
                    c.pen.Color = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));

                    Command newcommand = command.Clone();
                    newcommand.Execute(c);

                    ColorBtn.BackColor = figures.Current.Data.pen.Color;
                    //history.Push(newcommand);
                    figuresChanged();
                    PaintImage.Refresh();
                }
                else if (key == Keys.D2)
                {
                    Polygon p = new Polygon(x, y, angles, rotate, r);
                    p.pen.Color = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));

                    Command newcommand = command.Clone();
                    newcommand.Execute(p);

                    ColorBtn.BackColor = figures.Current.Data.pen.Color;
                    //history.Push(newcommand);
                    figuresChanged();
                    PaintImage.Refresh();
                }
                else if (key == Keys.D3)
                {
                    Star s = new Star(x, y, r, rays, rotate);
                    s.pen.Color = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));

                    Command newcommand = command.Clone();
                    newcommand.Execute(s);

                    ColorBtn.BackColor = figures.Current.Data.pen.Color;
                    //history.Push(newcommand);
                    figuresChanged();
                    PaintImage.Refresh();
                }

                else if (key == Keys.Left)
                {
                    float tmpx = figures.Current.Data.Left;
                    if (tmpx - (float)SpeedNumUpDown.Value >= 0)
                    {
                        command.DX = -(float)SpeedNumUpDown.Value;
                        Command newcommand = command.Clone();
                        newcommand.Execute(figures.Current.Data);
                        history.Push(newcommand);
                        PaintImage.Refresh();
                    }
                }
                else if (key == Keys.Right)
                {
                    float tmpx = figures.Current.Data.Right;
                    if (tmpx + (float)SpeedNumUpDown.Value <= PaintImage.Width)
                    {
                        command.DX = (float)SpeedNumUpDown.Value;
                        Command newcommand = command.Clone();
                        newcommand.Execute(figures.Current.Data);
                        history.Push(newcommand);
                        PaintImage.Refresh();
                    }
                }
                else if (key == Keys.Up)
                {
                    float tmpy = figures.Current.Data.Up;
                    if (tmpy - (float)SpeedNumUpDown.Value >= 0)
                    {
                        command.DY = -(float)SpeedNumUpDown.Value;
                        Command newcommand = command.Clone();
                        newcommand.Execute(figures.Current.Data);
                        history.Push(newcommand);
                        PaintImage.Refresh();
                    }
                }
                else if (key == Keys.Down)
                {
                    float tmpy = figures.Current.Data.Down;

                    if (tmpy + (float)SpeedNumUpDown.Value <= PaintImage.Height)
                    {
                        command.DY = (float)SpeedNumUpDown.Value;
                        Command newcommand = command.Clone();
                        newcommand.Execute(figures.Current.Data);
                        history.Push(newcommand);
                        PaintImage.Refresh();
                    }
                }
                else if (key == Keys.Add)
                {
                    float left  = figures.Current.Data.Left;
                    float right = figures.Current.Data.Right;
                    float up    = figures.Current.Data.Up;
                    float down  = figures.Current.Data.Down;
                    if ((right + 1 <= PaintImage.Width) && (left - 1 >= 0) && (down + 1 <= PaintImage.Height) && (up - 1 >= 0))
                    {
                        Command newcommand = command.Clone();
                        newcommand.Execute(figures.Current.Data);
                        history.Push(newcommand);
                        PaintImage.Refresh();
                    }
                }
                else if (key == Keys.Subtract)
                {
                    if (figures.Current.Data.R - 1 >= 15)
                    {
                        Command newcommand = command.Clone();
                        newcommand.Execute(figures.Current.Data);
                        history.Push(newcommand);
                        PaintImage.Refresh();
                    }
                }
                else if ((key == Keys.R) || (key == Keys.T))
                {
                    if (figures.Current.Data.GetType() != new Circle().GetType())
                    {
                        Star s = new Star(); Star s1 = new Star();
                        s.Angle       = figures.Current.Data.Angle; s1.Angle = s.Angle;
                        s.NumOfAngles = figures.Current.Data.NumOfAngles; s1.NumOfAngles = s.NumOfAngles;
                        s.X           = figures.Current.Data.X; s1.X = s.X;
                        s.Y           = figures.Current.Data.Y; s1.Y = s.Y;
                        s.R           = (figures.Current.Data.Right - figures.Current.Data.Left) / 2; s1.R = (figures.Current.Data.Down - figures.Current.Data.Up) / 2;
                        s.Left        = figures.Current.Data.Left;
                        s.Right       = figures.Current.Data.Right;
                        s.Up          = figures.Current.Data.Up;
                        s.Down        = figures.Current.Data.Down;
                        if (key == Keys.R)
                        {
                            s.Rotate(-1); s1.Rotate(-1);
                        }
                        else
                        {
                            s.Rotate(1); s1.Rotate(1);
                        }
                        float left = s.Left, right = s.Right;
                        float up1 = s1.Up, down1 = s1.Down;
                        if ((left >= 0) && (right <= PaintImage.Width) && (up1 >= 0) && (down1 <= PaintImage.Height))
                        {
                            Command newcommand = command.Clone();
                            newcommand.Execute(figures.Current.Data);
                            history.Push(newcommand);
                            PaintImage.Refresh();
                        }
                    }
                }
                else if ((key == Keys.N) || (key == Keys.P))
                {
                    Command newcommand = command.Clone();
                    newcommand.Execute(figures.Current.Data);
                    ColorBtn.BackColor = figures.Current.Data.pen.Color;
                    //history.Push(newcommand);
                    PaintImage.Refresh();
                }

                else if (key == Keys.Delete)
                {
                    Command newcommand = command.Clone();
                    newcommand.Execute(figures.Current.Data);
                    history.Push(newcommand);
                    figuresChanged();
                    PaintImage.Refresh();
                    if (figures.Count == 0)
                    {
                        labelX.Text           = "";
                        labelY.Text           = "";
                        SizeNumUpDown.Value   = SizeNumUpDown.Minimum;
                        AnglesNumUpDown.Value = AnglesNumUpDown.Minimum;
                        RotationTrBar.Value   = RotationTrBar.Minimum;
                    }
                }
                else if ((key != Keys.LButton) && (key != Keys.G) && (key != Keys.U))
                {
                    Command newcommand = command.Clone();
                    newcommand.Execute(figures.Current.Data);
                    history.Push(newcommand);
                    PaintImage.Refresh();
                }
            }
            if (key == Keys.Z && history.Count != 0)
            {
                Command lastcommand = history.Peek();
                lastcommand.Unexecute();
                lastcommand = null;
                history.Pop();
                figuresChanged();
                PaintImage.Refresh();
            }
        }