Пример #1
0
        private Shape GetNewShapeBasedOnType(EditState state, float lineWidth, Color penColor)
        {
            Shape shape = null;
            Color color = Color.FromArgb(ShapeOpacity, penColor);

            switch (state)
            {
            case EditState.PEN:
                break;

            case EditState.CIRCLE:
                shape = new MyCircle(lineWidth, color, Point.Empty, Point.Empty);
                break;

            case EditState.RECTANGLE:
                shape = new MyRectangle(lineWidth, color, Point.Empty, Point.Empty);
                break;

            case EditState.ARROW:
                shape = new Arrow(color, Point.Empty, Point.Empty);
                Arrow temp = shape as Arrow;
                temp.ArrowWidth = ArrowSize;
                break;

            case EditState.LINE:
                shape = new Line(lineWidth, color, Point.Empty, Point.Empty);
                break;

            case EditState.CROP:
            case EditState.NONE:
            default:
                break;
            }
            return(shape);
        }
Пример #2
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);
                }
            }
        }