Esempio n. 1
0
 private void Delete_Click(object sender, EventArgs e)
 {
     shapes.Clear();
     shapes.ForEach(x => x.BoundingBoxs.Clear());
     index        = 0;
     currentIndex = -1;
     SrcPicBox.Refresh();
 }
Esempio n. 2
0
        private void SrcPicBox_MouseMove(object sender, MouseEventArgs e)
        {
            Point ptCurrent = new Point(e.X, e.Y);

            // If we "have the mouse", then we draw our lines.
            if (bHaveMouse)
            {
                // If we have drawn previously, draw again in
                // that spot to remove the lines.
                if (ptLast.X != -1)
                {
                    // Display Coordinates
                    lbCordinates.Text = "Coordinates  :  " + ptOriginal.X.ToString() + ", " +
                                        ptOriginal.Y.ToString() + " And " + e.X.ToString() + ", " + e.Y.ToString();
                }

                // Update last point.
                ptLast = ptCurrent;

                // Draw new lines.

                // e.X - rectCropArea.X;
                // normal
                if (e.X > ptOriginal.X && e.Y > ptOriginal.Y)
                {
                    rectCropArea.Width = e.X - ptOriginal.X;

                    // e.Y - rectCropArea.Height;
                    rectCropArea.Height = e.Y - ptOriginal.Y;
                }
                else if (e.X < ptOriginal.X && e.Y > ptOriginal.Y)
                {
                    rectCropArea.Width  = ptOriginal.X - e.X;
                    rectCropArea.Height = e.Y - ptOriginal.Y;
                    rectCropArea.X      = e.X;
                    rectCropArea.Y      = ptOriginal.Y;
                }
                else if (e.X > ptOriginal.X && e.Y < ptOriginal.Y)
                {
                    rectCropArea.Width  = e.X - ptOriginal.X;
                    rectCropArea.Height = ptOriginal.Y - e.Y;

                    rectCropArea.X = ptOriginal.X;
                    rectCropArea.Y = e.Y;
                }
                else
                {
                    rectCropArea.Width = ptOriginal.X - e.X;

                    // e.Y - rectCropArea.Height;
                    rectCropArea.Height = ptOriginal.Y - e.Y;
                    rectCropArea.X      = e.X;
                    rectCropArea.Y      = e.Y;
                }
                SrcPicBox.Refresh();
            }
        }
Esempio n. 3
0
        private void SrcPicBox_MouseDown(object sender, MouseEventArgs e)
        {
            // Make a note that we "have the mouse down".
            bHaveMouseDown = true;

            // Set current point
            var ptCurrent = new Point(e.X, e.Y);

            // Set "last point"
            ptLast.X = ptCurrent.X;
            ptLast.Y = ptCurrent.Y;

            // Has select shape
            if (bHaveSelect)
            {
                var currentShape = this.shapes.FirstOrDefault(x => x.Index == currentIndex);
                if (currentShape != null)
                {
                    var resizeBoxInside = this.FindResizeBoxInsidePoint(currentShape, ptCurrent);
                    // If inside resize
                    if (resizeBoxInside != null)
                    {
                        bHaveResize = true;

                        // Store the "starting point" for this rubber-band rectangle.
                        ptOriginal.X = currentShape.RectOriginal.X;
                        ptOriginal.Y = currentShape.RectOriginal.Y;

                        currentResizeType = resizeBoxInside.ResizeType;
                        this.UpdateCursor(currentResizeType);
                        return;
                    }
                }
            }

            //Check edit shape
            var shapeInside = this.FindShapeInPoint(ptCurrent);

            if (shapeInside != null)
            {
                // Make a note that we "have the resize".
                bHaveSelect = true;
                bHaveResize = false;

                // Set rectangle shape
                rectCropArea = shapeInside.RectOriginal;

                // Store the "starting point" for this rubber-band rectangle.
                ptOriginal.X = rectCropArea.X;
                ptOriginal.Y = rectCropArea.Y;

                // Draw resize boxs
                this.InitialResizeBox(shapeInside);

                currentIndex = shapeInside.Index;
            }
            else
            {
                bHaveSelect = false;
                bHaveResize = false;

                // Store the "starting point" for this rubber-band rectangle.
                ptOriginal.X = ptCurrent.X;
                ptOriginal.Y = ptCurrent.Y;

                // Clear resize list
                this.shapes.ForEach(x => x.BoundingBoxs.Clear());

                var currentShapeType = this.GetShapeTypeSelect();
                var shape            = new Shape()
                {
                    ShapeType = currentShapeType, POriginal = ptOriginal, RectOriginal = new Rectangle(ptOriginal, new Size {
                        Height = (currentShapeType == ShapeType.RectanleRotate) ? defaultHeight : 0
                    }), AngleRotate = 0, Index = index++
                };
                shapes.Add(shape);
                currentIndex = shape.Index;
            }

            SrcPicBox.Refresh();
        }
Esempio n. 4
0
        private void SrcPicBox_MouseMove(object sender, MouseEventArgs e)
        {
            Point ptCurrent = new Point(e.X, e.Y);

            // If we "have the mouse", then we draw our lines.
            if (bHaveMouseDown)
            {
                // Find current shape
                var currentShape = shapes.FirstOrDefault(x => x.Index == currentIndex);
                if (bHaveSelect)
                {
                    if (currentShape != null)
                    {
                        rectCropArea = currentShape.RectOriginal;
                        if (bHaveResize)
                        {
                            if (currentShape.ShapeType == ShapeType.RectanleRotate)
                            {
                                Point ptCenter = new Point(currentShape.RectOriginal.X + currentShape.RectOriginal.Width / 2, currentShape.RectOriginal.Y + currentShape.RectOriginal.Height / 2);
                                var   dX       = ptCurrent.X - ptCenter.X;
                                var   dY       = ptCurrent.Y - ptCenter.Y;
                                int   distance = (int)Math.Sqrt(dX * dX + dY * dY);
                                if (distance > 0)
                                {
                                    double radianB = Math.Atan((double)dX / dY);
                                    var    alpha   = (float)(radianB * (180 / Math.PI));

                                    // Handle resize shape
                                    switch (currentResizeType)
                                    {
                                    case ResizeType.Left:
                                    case ResizeType.Right:
                                        rectCropArea.X     = ptCenter.X - distance;
                                        rectCropArea.Y     = ptCenter.Y - rectCropArea.Height / 2;
                                        rectCropArea.Width = distance * 2;

                                        currentShape.AngleRotate = 90 - alpha;
                                        break;

                                    case ResizeType.Top:
                                    case ResizeType.Bottom:
                                        rectCropArea.X      = ptCenter.X - rectCropArea.Width / 2;
                                        rectCropArea.Y      = ptCenter.Y - distance;
                                        rectCropArea.Height = distance * 2;

                                        currentShape.AngleRotate = -alpha;
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                // Handle resize shape
                                switch (currentResizeType)
                                {
                                case ResizeType.Left:
                                    if (rectCropArea.Width - (e.X - ptLast.X) >= minWidth)
                                    {
                                        rectCropArea.X     += e.X - ptLast.X;
                                        rectCropArea.Width -= e.X - ptLast.X;
                                        if (currentShape.ShapeType == ShapeType.Square || currentShape.ShapeType == ShapeType.Circle)
                                        {
                                            rectCropArea.Height = rectCropArea.Width;
                                        }
                                    }

                                    break;

                                case ResizeType.Top:
                                    if (rectCropArea.Height - (e.Y - ptLast.Y) >= minHeight)
                                    {
                                        rectCropArea.Y      += e.Y - ptLast.Y;
                                        rectCropArea.Height -= e.Y - ptLast.Y;
                                        if (currentShape.ShapeType == ShapeType.Square || currentShape.ShapeType == ShapeType.Circle)
                                        {
                                            rectCropArea.Width = rectCropArea.Height;
                                        }
                                    }
                                    break;

                                case ResizeType.Right:
                                    if (rectCropArea.Width + (e.X - ptLast.X) >= minWidth)
                                    {
                                        rectCropArea.Width += e.X - ptLast.X;
                                        if (currentShape.ShapeType == ShapeType.Square || currentShape.ShapeType == ShapeType.Circle)
                                        {
                                            rectCropArea.Height = rectCropArea.Width;
                                        }
                                    }
                                    break;

                                case ResizeType.Bottom:
                                    if (rectCropArea.Height + (e.Y - ptLast.Y) >= minHeight)
                                    {
                                        rectCropArea.Height += e.Y - ptLast.Y;
                                        if (currentShape.ShapeType == ShapeType.Square || currentShape.ShapeType == ShapeType.Circle)
                                        {
                                            rectCropArea.Width = rectCropArea.Height;
                                        }
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }

                            // Update shape
                            currentShape.PRotate      = ptCurrent;
                            currentShape.RectOriginal = rectCropArea;

                            // Draw resize boxs
                            this.InitialResizeBox(currentShape);
                        }
                        else
                        {
                            // Hanlder move shape
                            if (currentShape != null)
                            {
                                rectCropArea.X += e.X - ptLast.X;
                                rectCropArea.Y += e.Y - ptLast.Y;

                                // Update rectangle
                                currentShape.RectOriginal = rectCropArea;
                            }

                            if (currentShape.BoundingBoxs != null && currentShape.BoundingBoxs.Count > 0)
                            {
                                for (int i = 0; i < currentShape.BoundingBoxs.Count; i++)
                                {
                                    Rectangle rectTmp = currentShape.BoundingBoxs[i].RectOriginal;
                                    rectTmp.X += e.X - ptLast.X;
                                    rectTmp.Y += e.Y - ptLast.Y;
                                    currentShape.BoundingBoxs[i].RectOriginal = rectTmp;
                                }
                            }
                        }

                        // Update last point.
                        ptLast = ptCurrent;
                    }
                }
                else
                {
                    if (currentShape != null)
                    {
                        rectCropArea = currentShape.RectOriginal;

                        if (currentShape.ShapeType == ShapeType.RectanleRotate)
                        {
                            var    dX       = ptCurrent.X - ptOriginal.X;
                            var    dY       = ptCurrent.Y - ptOriginal.Y;
                            int    distance = (int)Math.Sqrt(dX * dX + dY * dY);
                            double radianB  = Math.Atan((double)dX / dY);
                            var    alpha    = (float)(radianB * (180 / Math.PI));

                            rectCropArea.X     = ptOriginal.X - distance;
                            rectCropArea.Y     = ptOriginal.Y - rectCropArea.Height / 2;
                            rectCropArea.Width = distance * 2;

                            currentShape.AngleRotate = 90 - alpha;
                            currentShape.PRotate     = ptCurrent;
                        }
                        else
                        {
                            // Draw shape
                            if (e.X > ptOriginal.X && e.Y > ptOriginal.Y)
                            {
                                rectCropArea.Width  = e.X - ptOriginal.X;
                                rectCropArea.Height = e.Y - ptOriginal.Y;
                            }
                            else if (e.X < ptOriginal.X && e.Y > ptOriginal.Y)
                            {
                                rectCropArea.Width  = ptOriginal.X - e.X;
                                rectCropArea.Height = e.Y - ptOriginal.Y;
                                rectCropArea.X      = e.X;
                                rectCropArea.Y      = ptOriginal.Y;
                            }
                            else if (e.X > ptOriginal.X && e.Y < ptOriginal.Y)
                            {
                                rectCropArea.Width  = e.X - ptOriginal.X;
                                rectCropArea.Height = ptOriginal.Y - e.Y;
                                rectCropArea.X      = ptOriginal.X;
                                rectCropArea.Y      = e.Y;
                            }
                            else
                            {
                                rectCropArea.Width  = ptOriginal.X - e.X;
                                rectCropArea.Height = ptOriginal.Y - e.Y;
                                rectCropArea.X      = e.X;
                                rectCropArea.Y      = e.Y;
                            }

                            if (currentShape.ShapeType == ShapeType.Square || currentShape.ShapeType == ShapeType.Circle)
                            {
                                rectCropArea.Width  = Math.Max(rectCropArea.Width, rectCropArea.Height);
                                rectCropArea.Height = Math.Max(rectCropArea.Width, rectCropArea.Height);
                            }
                        }

                        // Update rectangle
                        currentShape.RectOriginal = rectCropArea;

                        // Update last point.
                        ptLast = ptCurrent;
                    }
                }

                SrcPicBox.Refresh();
            }
            else
            {
                if (bHaveSelect)
                {
                    //Update cusor
                    var resizeBoxInside = this.FindResizeBoxInsidePoint(this.shapes.FirstOrDefault(x => x.Index == currentIndex), ptCurrent);
                    if (resizeBoxInside != null)
                    {
                        this.UpdateCursor(resizeBoxInside.ResizeType);
                        return;
                    }
                }

                var shapeInside = this.FindShapeInPoint(ptCurrent);
                if (shapeInside != null)
                {
                    this.Cursor = Cursors.SizeAll;
                }
                else
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
Esempio n. 5
0
        private void SrcPicBox_MouseMove(object sender, MouseEventArgs e)
        {
            //Point ptCurrentNormalised = new Point((int)(e.X / ratio), (int)(e.Y / ratio));

            // If we "have the mouse", then we draw our lines.
            if (bHaveMouse)
            {
                // Update last point.
                if (_rectangleStatus == RectangleStatus.Moving)
                {
                    MoveRect(e.Location);
                }
                else if (_rectangleStatus == RectangleStatus.Resizing)
                {
                    ResizeRect(e.Location);
                }
                else
                {
                    ptLast = ptCurrent;
                    InitRectCropArea(new Point(e.X, e.Y), ptOriginal);
                }
                SrcPicBox.Refresh();
            }
            else
            {
                if (rectCropArea != null)
                {
                    if
                    (
                        (e.X >= (rectCropArea.X + _resizeArea)) &&
                        (e.X <= (rectCropArea.X + rectCropArea.Width - _resizeArea)) &&
                        (e.Y >= (rectCropArea.Y + _resizeArea)) &&
                        (e.Y <= (rectCropArea.Y + rectCropArea.Height - _resizeArea))
                    )
                    {
                        _rectangleStatus = RectangleStatus.Moving;
                        this.Cursor      = Cursors.Hand;
                        _currentLine     = 0;
                    }
                    else if
                    (
                        (e.X >= (rectCropArea.X + _resizeArea)) &&
                        (e.Y >= (rectCropArea.Y - _resizeArea)) &&
                        (e.X <= (rectCropArea.X + rectCropArea.Width - _resizeArea)) &&
                        (e.Y <= (rectCropArea.Y + _resizeArea))
                    )
                    {
                        _rectangleStatus = RectangleStatus.Resizing;
                        this.Cursor      = Cursors.SizeNS;
                        _currentLine     = 2;
                    }
                    else if
                    (
                        (e.X >= (rectCropArea.X - _resizeArea)) &&
                        (e.Y >= (rectCropArea.Y + _resizeArea)) &&
                        (e.X <= (rectCropArea.X + _resizeArea)) &&
                        (e.Y <= (rectCropArea.Y + rectCropArea.Height - _resizeArea))
                    )
                    {
                        _rectangleStatus = RectangleStatus.Resizing;
                        this.Cursor      = Cursors.SizeWE;
                        _currentLine     = 8;
                    }
                    else if
                    (
                        (e.X >= (rectCropArea.X + _resizeArea)) &&
                        (e.Y >= (rectCropArea.Y + rectCropArea.Height - _resizeArea)) &&
                        (e.X <= (rectCropArea.X + rectCropArea.Width - _resizeArea)) &&
                        (e.Y <= (rectCropArea.Y + rectCropArea.Height + _resizeArea))
                    )
                    {
                        _rectangleStatus = RectangleStatus.Resizing;
                        this.Cursor      = Cursors.SizeNS;
                        _currentLine     = 6;
                    }
                    else if
                    (
                        (e.X >= (rectCropArea.X + rectCropArea.Width - _resizeArea)) &&
                        (e.Y >= (rectCropArea.Y + _resizeArea)) &&
                        (e.X <= (rectCropArea.X + rectCropArea.Width + _resizeArea)) &&
                        (e.Y <= (rectCropArea.Y + rectCropArea.Height - _resizeArea))
                    )
                    {
                        _rectangleStatus = RectangleStatus.Resizing;
                        this.Cursor      = Cursors.SizeWE;
                        _currentLine     = 4;
                    }
                    else if
                    (
                        (e.X >= (rectCropArea.X - _resizeArea)) &&
                        (e.Y >= (rectCropArea.Y - _resizeArea)) &&
                        (e.X <= (rectCropArea.X + _resizeArea)) &&
                        (e.Y <= (rectCropArea.Y + _resizeArea))
                    )
                    {
                        _rectangleStatus = RectangleStatus.Resizing;
                        this.Cursor      = Cursors.SizeNWSE;
                        _currentLine     = 1;
                    }
                    else if
                    (
                        (e.X >= (rectCropArea.X + rectCropArea.Width - _resizeArea)) &&
                        (e.Y >= (rectCropArea.Y - _resizeArea)) &&
                        (e.X <= (rectCropArea.X + rectCropArea.Width + _resizeArea)) &&
                        (e.Y <= (rectCropArea.Y + _resizeArea))
                    )
                    {
                        _rectangleStatus = RectangleStatus.Resizing;
                        this.Cursor      = Cursors.SizeNESW;
                        _currentLine     = 3;
                    }
                    else if
                    (
                        (e.X >= (rectCropArea.X + rectCropArea.Width - _resizeArea)) &&
                        (e.Y >= (rectCropArea.Y + rectCropArea.Height - _resizeArea)) &&
                        (e.X <= (rectCropArea.X + rectCropArea.Width + _resizeArea)) &&
                        (e.Y <= (rectCropArea.Y + rectCropArea.Height + _resizeArea))
                    )
                    {
                        _rectangleStatus = RectangleStatus.Resizing;
                        this.Cursor      = Cursors.SizeNWSE;
                        _currentLine     = 5;
                    }
                    else if
                    (
                        (e.X >= (rectCropArea.X - _resizeArea)) &&
                        (e.Y >= (rectCropArea.Y + rectCropArea.Height - _resizeArea)) &&
                        (e.X <= (rectCropArea.X + _resizeArea)) &&
                        (e.Y <= (rectCropArea.Y + rectCropArea.Height + _resizeArea))
                    )
                    {
                        _rectangleStatus = RectangleStatus.Resizing;
                        this.Cursor      = Cursors.SizeNESW;
                        _currentLine     = 7;
                    }
                    else
                    {
                        _rectangleStatus = RectangleStatus.Creating;
                        this.Cursor      = Cursors.Default;
                        _currentLine     = 0;
                    }
                }
            }
        }