Exemplo n.º 1
0
        public void Swap(int indexA, int indexB)
        {
            ObjectDrawing Temp = _list[indexA];

            _list[indexA] = _list[indexB];
            _list[indexB] = Temp;
        }
Exemplo n.º 2
0
        private void ChooseObject()
        {
            switch (objectChoose)
            {
            case "pencil":
                Shape = new PenDrawing(color, penWidth);
                break;

            case "eraser":
                Shape = new EraserDrawing(penWidth);
                break;

            case "rectangle":
                Shape = new RectangleDrawing(color, penWidth);
                break;

            case "circle":
                Shape = new CircleDrawing(color, penWidth);
                break;

            case "star":
                Shape = new StarDrawing(color, penWidth);
                break;

            case "line":
                Shape = new LineDrawing(color, penWidth);
                break;

            case "triangle":
                Shape = new TriangleDrawing(color, penWidth);
                break;

            case "rhombus":
                Shape = new RhombusDrawing(color, penWidth);
                break;

            case "pentagon":
                Shape = new PentagonDrawing(color, penWidth);
                break;

            case "hexagon":
                Shape = new HexagonDrawing(color, penWidth);
                break;

            case "crop":
            {
                Shape  = new CropRectangle();
                isCrop = true;
            }
            break;

            default:
                objectChoose = "none";
                Shape        = new NoneShapeDrawing();
                break;
            }
        }
Exemplo n.º 3
0
 public bool isExist(ObjectDrawing shape)
 {
     for (int i = 0; i < _list.Count; i++)
     {
         if (shape.getColor() == _list[i].getColor() && shape.getMouseClick() == _list[i].getMouseClick())
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 4
0
 private void picPaint_MouseUp(object sender, MouseEventArgs e)
 {
     if (objectChoose == "pencil" || objectChoose == "eraser")
     {
         Shape  = null;
         status = DRAW_STATUS.COMPLETE;
     }
     if (Shape != null)
     {
         Shape.Mouse_Up(e);
     }
 }
Exemplo n.º 5
0
        // Paste the image on the clipboard, centering it on the selected area.
        private void Paste()
        {
            // Không làm gì hết nếu clipboard rỗng
            if (!Clipboard.ContainsImage())
            {
                return;
            }

            // Lấy ảnh từ Clipboard
            Image clipboard_image = Clipboard.GetImage();

            // Xác định vị trí đặt ảnh
            //int cx = selectedArea.X + (selectedArea.Width - clipboard_image.Width) / 2;
            //int cy = selectedArea.Y + (selectedArea.Height - clipboard_image.Height) / 2;
            //Rectangle dest_rect = new Rectangle(cx, cy, clipboard_image.Width, clipboard_image.Height);

            RectangleSelection dest_rect = new RectangleSelection();

            dest_rect._startPoint = new Point(5, 5);
            dest_rect._img        = clipboard_image;
            dest_rect._endPoint.X = dest_rect._startPoint.X + clipboard_image.Width;
            dest_rect._endPoint.Y = dest_rect._startPoint.Y + clipboard_image.Height;

            Shape = dest_rect;

            grapList._list.Add(dest_rect);


            // Copy hình ảnh mới vào vị trí
            //using (Graphics gr = Graphics.FromImage(clipboard_image))
            //{
            //   gr.DrawImage(clipboard_image, dest_rect);
            //}

            // Hiển thị hình
            //picPaint.Image = clipboard_image; ////////////////////////////////chỗ này đây
            picPaint.Refresh();
        }
Exemplo n.º 6
0
        private void picPaint_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //Neu da chon doi tuong
                if (objectChoose == "bucket")
                {
                    ;
                }
                //{
                //    //Shape = null;
                //    Shape = new BucketDrawing(doubleBuffer, fillImage, e.X, e.Y, current);


                //    grapList._list.Insert(grapList._list.Count, Shape);

                //    picPaint.Refresh();
                // }
                else
                if (objectChoose == "rectangle" || objectChoose == "circle" || objectChoose == "star" || objectChoose == "line" || objectChoose == "rhombus" || objectChoose == "triangle" || objectChoose == "pentagon" || objectChoose == "hexagon" || objectChoose == "crop")
                {
                    if (Shape != null && Shape.CheckLocation(e.Location) >= 0)
                    {
                        Shape.Mouse_Down(e);
                        status = DRAW_STATUS.INCOMPLETE;

                        if (Shape.CheckLocation(e.Location) == 0)
                        {
                            Cursor = Cursors.SizeAll;
                        }
                        if (Shape.CheckLocation(e.Location) > 0)
                        {
                            Cursor = Cursors.Cross;
                        }
                    }

                    else
                    {
                        if (objectChoose != "crop")
                        {
                            status = DRAW_STATUS.COMPLETE;
                            ChooseObject();
                            Shape.Mouse_Down(e);
                            grapList._list.Insert(grapList._list.Count, Shape);
                        }
                        else
                        {
                            if (isCrop == true)
                            {
                                if (grapList._list.Count != 0)
                                {
                                    grapList._list.RemoveAt(grapList._list.Count - 1);
                                }
                                picPaint.Refresh();
                            }

                            status = DRAW_STATUS.COMPLETE;
                            ChooseObject();
                            Shape.Mouse_Down(e);
                            grapList._list.Insert(grapList._list.Count, Shape);
                        }
                    }
                }
                else
                {
                    status = DRAW_STATUS.COMPLETE;
                    ChooseObject();
                    Shape.Mouse_Down(e);
                    grapList._list.Insert(grapList._list.Count, Shape);
                }
            }

            else
            {
                status = DRAW_STATUS.COMPLETE;
                Shape  = null;
            }
        }
Exemplo n.º 7
0
        private void ChooseObject()
        {
            switch (objectChoose)
            {
            case "pencil":
                Shape = new PenDrawing(mtitleCurrentColor.BackColor, penWidth);
                break;

            case "eraser":
                Shape = new EraserDrawing(penWidth);
                break;

            case "rectangle":
                Shape = new RectangleDrawing(mtitleCurrentColor.BackColor, penWidth);
                break;

            case "circle":
                Shape = new CircleDrawing(mtitleCurrentColor.BackColor, penWidth);
                break;

            case "star":
                Shape = new StarDrawing(mtitleCurrentColor.BackColor, penWidth);
                break;

            case "line":
                Shape = new LineDrawing(mtitleCurrentColor.BackColor, penWidth);
                break;

            case "triangle":
                Shape = new TriangleDrawing(mtitleCurrentColor.BackColor, penWidth);
                break;

            case "rhombus":
                Shape = new RhombusDrawing(mtitleCurrentColor.BackColor, penWidth);
                break;

            case "pentagon":
                Shape = new PentagonDrawing(mtitleCurrentColor.BackColor, penWidth);
                break;

            case "hexagon":
                Shape = new HexagonDrawing(mtitleCurrentColor.BackColor, penWidth);
                break;

            case "crop":
            {
                Shape     = new CropRectangle();
                isCrop    = true;
                posOfCrop = grapList._list.Count;
            }
            break;

            case "select":
            {
                Shape    = new RectangleSelection(mtitleCurrentColor.BackColor, penWidth);
                isSelect = true;
            }
            break;

            default:
                objectChoose = "none";
                Shape        = new NoneShapeDrawing();
                break;
            }
        }
Exemplo n.º 8
0
        private void picPaint_MouseUp(object sender, MouseEventArgs e)
        {
            if (objectChoose == "pencil" || objectChoose == "eraser")
            {
                Shape = null;
                //status = DRAW_STATUS.COMPLETE;
            }
            if (Shape != null)
            {
                Shape.Mouse_Up(e);
            }
            if (objectChoose == "crop" || objectChoose == "select")
            {
                if (Shape._endPoint.X < 0)
                {
                    Shape._endPoint.X = 0;
                }
                if (Shape._endPoint.Y < 0)
                {
                    Shape._endPoint.Y = 0;
                }
                if (Shape._endPoint.X > fillImage.Size.Width)
                {
                    Shape._endPoint.X = fillImage.Size.Width;
                }
                if (Shape._endPoint.Y > fillImage.Size.Height)
                {
                    Shape._endPoint.Y = fillImage.Size.Height;
                }
            }
            if (objectChoose == "select" && isSelect == true)
            {
                //status = DRAW_STATUS.COMPLETE;


                int width  = Math.Abs(Shape._endPoint.X - Shape._startPoint.X);
                int height = Math.Abs(Shape._endPoint.Y - Shape._startPoint.Y);
                if (width != 0 && height != 0)
                {
                    if (Shape._startPoint.X > Shape._endPoint.X)
                    {
                        int temp = Shape._startPoint.X;
                        Shape._startPoint.X = Shape._endPoint.X;
                        Shape._endPoint.X   = temp;
                    }
                    if (Shape._startPoint.Y > Shape._endPoint.Y)
                    {
                        int temp = Shape._startPoint.Y;
                        Shape._startPoint.Y = Shape._endPoint.Y;
                        Shape._endPoint.Y   = temp;
                    }
                    ObjectDrawing t = Shape;
                    grapList.RemoveLast();
                    picPaint.Refresh();

                    Rectangle ROI = new Rectangle(Shape._startPoint.X, Shape._startPoint.Y, width, height);
                    (Shape as RectangleSelection)._img = CropImage(doubleBuffer, ROI);

                    selectedArea  = new Rectangle(0, 0, width, height); //Vị trí lấy hình cắt được gán vào HCN
                    _CopyCut._img = (Shape as RectangleSelection)._img; //Hình dc cắt

                    grapList._list.Insert(grapList._list.Count, t);


                    RectangleDrawing rec = new RectangleDrawing(Color.White, 1);
                    rec._startPoint  = Shape._startPoint;
                    rec._endPoint    = Shape._endPoint;
                    rec.isSelectRect = true;

                    grapList._list.Add(rec);

                    int Soluong = grapList._list.Count;

                    grapList.Swap(Soluong - 1, Soluong - 2);

                    isSelect = false;
                }
                picPaint.Refresh();
            }
        }
Exemplo n.º 9
0
        private void picPaint_MouseDown(object sender, MouseEventArgs e)
        {
            if (Shape is RectangleSelection)
            {
                (Shape as RectangleSelection).isSelectDone = true;
            }
            isSaved = false;
            if (e.Button == MouseButtons.Left)
            {
                //Neu da chon doi tuong
                if (objectChoose == "bucket")
                {
                    //Shape = null;
                    if (isCropRectDraw == true)
                    {
                        grapList._list.RemoveAt(posOfCrop);
                        isCropRectDraw = false;
                        isCrop         = false;
                    }

                    // them 1 nonShape de ko hien handlepoint khi su dung bucket
                    //ObjectDrawing clear = new NoneShapeDrawing();
                    //grapList._posINCOMPLETE = grapList._list.Count;
                    //grapList._list.Insert(grapList._list.Count, clear);
                    //picPaint.Refresh();

                    Shape = new BucketDrawing(doubleBuffer, e.X, e.Y, mtitleCurrentColor.BackColor);

                    if (!grapList.isExist(Shape))
                    {
                        grapList._listBucketFill.Insert(grapList._listBucketFill.Count, grapList._list.Count);
                        grapList._list.Insert(grapList._list.Count, Shape);
                    }

                    picPaint.Refresh();
                }
                else if (objectChoose == "rectangle" || objectChoose == "circle" || objectChoose == "star" ||
                         objectChoose == "line" || objectChoose == "rhombus" || objectChoose == "triangle" ||
                         objectChoose == "pentagon" || objectChoose == "hexagon" || objectChoose == "crop" || objectChoose == "select")
                {
                    if (Shape != null && Shape.CheckLocation(e.Location) >= 0)
                    {
                        Shape.Mouse_Down(e);
                        //status = DRAW_STATUS.INCOMPLETE;

                        if (Shape.CheckLocation(e.Location) == 0)
                        {
                            Cursor = Cursors.SizeAll;
                        }
                        if (Shape.CheckLocation(e.Location) > 0)
                        {
                            Cursor = Cursors.Cross;
                        }
                    }

                    else
                    {
                        if (isCropRectDraw == true)
                        {
                            grapList._list.RemoveAt(posOfCrop);
                            isCropRectDraw = false;
                            isCrop         = false;
                        }

                        if (objectChoose == "crop")
                        {
                            isCropRectDraw = true;
                        }


                        //status = DRAW_STATUS.COMPLETE;
                        ChooseObject();
                        Shape.Mouse_Down(e);

                        grapList._list.Insert(grapList._list.Count, Shape);
                        grapList._posINCOMPLETE = grapList._list.Count - 1;
                    }
                }
                else
                {
                    if (isCropRectDraw == true)
                    {
                        grapList._list.RemoveAt(posOfCrop);
                        isCrop = false;
                    }
                    //status = DRAW_STATUS.COMPLETE;
                    ChooseObject();
                    Shape.Mouse_Down(e);
                    if (objectChoose != "none")
                    {
                        grapList._list.Insert(grapList._list.Count, Shape);
                        grapList._posINCOMPLETE = grapList._list.Count - 1;
                    }
                }
            }

            else
            {
                //status = DRAW_STATUS.COMPLETE;
                Shape = null;
            }
        }