Пример #1
0
        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            Rectangle borderRectangle = this.ClientRectangle;

            //borderRectangle.Inflate(-10, -10);
            ControlPaint.DrawBorder(e.Graphics, borderRectangle, Color.Red, 3, ButtonBorderStyle.Dashed,
                                    Color.Red, 3, ButtonBorderStyle.Dashed,
                                    Color.Red, 3, ButtonBorderStyle.Dashed,
                                    Color.Red, 3, ButtonBorderStyle.Dashed);
            if (optionsForm.Visible == false)
            {
                DrawTextForAnnotationDialog(e.Graphics);
            }
            if (currentState == CurrentState.STATE_EDITING)
            {
                //Draw already drawn shapes
                Graphics g        = e.Graphics;
                Point    cursorPt = this.PointToClient(Cursor.Position);
                switch (editState)
                {
                case EditState.NONE:
                    break;

                case EditState.CROP:
                    GenerateGridLinesFromPoint(cursorPt, out HorzGridLine, out VertGridLine);
                    break;

                case EditState.PEN:
                    if (penPoints.Count == 0)
                    {
                        break;
                    }
                    penPoints.Add(cursorPt);
                    Color color = Color.FromArgb(ShapeOpacity, DrawingColor);
                    MyPen pen   = new MyPen(PenSize, color);
                    pen.SetDrawPoints(penPoints);
                    pen.Draw(g);
                    break;

                case EditState.CIRCLE:
                case EditState.RECTANGLE:
                case EditState.ARROW:
                case EditState.LINE:
                    if (!FirstEditPointDone)
                    {
                        break;
                    }
                    Shape temp = GetNewShapeBasedOnType(editState, PenSize, DrawingColor);
                    temp.StartPoint = FirstEditPoint;
                    temp.EndPoint   = cursorPt;
                    temp.Draw(g);
                    break;

                case EditState.TEXT:
                    if (!FirstEditPointDone)
                    {
                        break;
                    }
                    Point start = FirstEditPoint;
                    Point end   = cursorPt;
                    Utility.NormalizePts(ref start, ref end);
                    MyRectangle rect = new MyRectangle(1.0f, Color.Black, start, end);
                    rect.Draw(g);
                    break;

                case EditState.SELECTION:
                    if (SelectedShape == null || !selectionPoint.HasValue)
                    {
                        break;
                    }
                    SelectedShape.AdjustPoints(selectionPoint.Value, leftDistance, topDistance);
                    SelectedShape.Draw(g);
                    break;

                default:
                    break;
                }

                foreach (var shape in drawObjects)
                {
                    shape.Draw(g);
                }

                //draw GridLines if in Cropping mode
                if (editState == EditState.CROP)
                {
                    if (FirstEditPointDone)
                    {
                        Line horzLine, vertLine;
                        GenerateGridLinesFromPoint(FirstEditPoint, out horzLine, out vertLine);
                        horzLine.Draw(g);
                        vertLine.Draw(g);
                    }
                    HorzGridLine.Draw(g);
                    VertGridLine.Draw(g);
                }
            }
        }
Пример #2
0
        private void MainForm_MouseUp(object sender, MouseEventArgs e)
        {
            //We are handling mouse up for left click only as of now
            if (e.Button != System.Windows.Forms.MouseButtons.Left)
            {
                return;
            }

            if (currentState == CurrentState.STATE_EDITING)
            {
                Point cursorPt = this.PointToClient(Cursor.Position);
                switch (editState)
                {
                case EditState.NONE:
                    break;

                case EditState.RECTANGLE:
                case EditState.CIRCLE:
                case EditState.ARROW:
                case EditState.LINE:
                    if (FirstEditPoint != SecondEditPoint)
                    {
                        SecondEditPoint = cursorPt;
                        Shape temp = GetNewShapeBasedOnType(editState, PenSize, DrawingColor);
                        temp.StartPoint = FirstEditPoint;
                        temp.EndPoint   = SecondEditPoint;
                        drawObjects.Add(temp);
                    }
                    FirstEditPoint     = Point.Empty;
                    SecondEditPoint    = Point.Empty;
                    FirstEditPointDone = false;
                    break;

                case EditState.CROP:
                    SecondEditPoint = cursorPt;
                    if (FirstEditPoint != SecondEditPoint)
                    {
                        GenerateCropBitmapAndOverlay(FirstEditPoint, SecondEditPoint);
                    }
                    FirstEditPoint     = Point.Empty;
                    SecondEditPoint    = Point.Empty;
                    FirstEditPointDone = false;
                    optionsForm.SetUIState(EditState.ARROW);
                    break;

                case EditState.PEN:
                    if (penPoints.Count != 0)
                    {
                        MyPen pen = new MyPen(PenSize, Color.FromArgb(ShapeOpacity, DrawingColor));
                        pen.SetDrawPoints(penPoints);
                        drawObjects.Add(pen);
                    }
                    penPoints.Clear();
                    break;

                case EditState.TEXT:
                    if (FirstEditPoint == SecondEditPoint)
                    {
                        SecondEditPoint.X = cursorPt.X + 100;
                        SecondEditPoint.Y = cursorPt.Y + 30;
                    }
                    else
                    {
                        SecondEditPoint = cursorPt;
                    }
                    Point firstHit  = this.PointToClient(FirstEditPoint);
                    Point secondHit = this.PointToClient(SecondEditPoint);
                    Utility.NormalizePts(ref firstHit, ref secondHit);
                    textBox1.SetBounds(firstHit.X, firstHit.Y, secondHit.X - firstHit.X, secondHit.Y - firstHit.Y);
                    this.textBox1.Visible = true;
                    textBox1.Font         = txtFont;
                    textBox1.ForeColor    = Color.FromArgb(ShapeOpacity, DrawingColor);
                    textBox1.Focus();

                    FirstEditPointDone = false;
                    break;

                case EditState.SELECTION:
                    if (SelectedShape != null && selectedShapeIndex != -1)
                    {
                        drawObjects[selectedShapeIndex] = SelectedShape;
                        //SelectedShape = null;
                        //selectedShapeIndex = -1;
                    }
                    break;

                default:
                    break;
                }
            }
            Invalidate();
        }