コード例 #1
0
        private void UpdateCurrent(CanvasEventArgs canvasEventArgs)
        {
            current.Shape.Width  = Math.Abs(x1 - canvasEventArgs.X);
            current.Shape.Height = Math.Abs(y1 - canvasEventArgs.Y);

            current.Shape.Margin = ShapeUtils.GetMargin(
                Math.Min(x1, canvasEventArgs.X),
                Math.Min(y1, canvasEventArgs.Y)
                );

            if (canvasEventArgs.MouseState == MouseState.UP)
            {
                current.ShapeState = ShapeState.FINISHED;
            }
            else if (canvasEventArgs.MouseState == MouseState.MOVE)
            {
                current.ShapeState = ShapeState.DRAWING;
            }
        }
コード例 #2
0
ファイル: BezierTool.cs プロジェクト: CzarqR/ZS_tikzfix
        public DrawingShape GetShape(CanvasEventArgs a, TikzStyle style)
        {
            if (click == 0) // first click, draw a straight line
            {
                if (a.MouseState == MouseState.DOWN)
                {
                    //FIXME: small bug here, sometimes when a user clicks for the first time long line appears for a split second, noticeable but should not influence performance

                    firstPoint = a.Point;

                    bezier = new BezierSegment()
                    {
                        Point3 = a.Point.GetSystemPoint()
                    };
                    figure = new PathFigure();
                    figure.Segments.Add(bezier);
                    path = new ArrowPath();

                    path.SetStyle(style);
                    path.Margin = ShapeUtils.GetMargin(firstPoint.X, firstPoint.Y);

                    pf        = new PathFigure[] { figure };
                    path.Data = new PathGeometry(pf);

                    current = new DrawingShape(
                        new TikzBezier(path, style),
                        ShapeState.START
                        );
                }
                else if (a.MouseState == MouseState.MOVE)
                {
                    bezier.Point3 = GetPointWithoutMargin(firstPoint, a.Point);
                }
                else
                {
                    bezier.Point3 = GetPointWithoutMargin(firstPoint, a.Point);
                    click++;
                }

                return(current);
            }
            else if (click == 1) // second click, select first control point
            {
                if (a.MouseState == MouseState.DOWN)
                {
                    secondPointSelected = true;
                    bezier.Point1       = GetPointWithoutMargin(firstPoint, a.Point);
                }
                else if (a.MouseState == MouseState.MOVE)
                {
                    if (secondPointSelected)
                    {
                        bezier.Point1 = GetPointWithoutMargin(firstPoint, a.Point);
                    }
                }
                else
                {
                    bezier.Point1 = GetPointWithoutMargin(firstPoint, a.Point);
                    click++;
                }

                return(current);
            }
            else if (click == 2) // third click, select second control point
            {
                if (a.MouseState == MouseState.DOWN)
                {
                    thirdPointSelected = true;
                    bezier.Point2      = GetPointWithoutMargin(firstPoint, a.Point);
                }
                else if (a.MouseState == MouseState.MOVE)
                {
                    if (thirdPointSelected)
                    {
                        bezier.Point2 = GetPointWithoutMargin(firstPoint, a.Point);
                    }
                }
                else
                {
                    bezier.Point2      = GetPointWithoutMargin(firstPoint, a.Point);
                    current.ShapeState = ShapeState.FINISHED;
                    click = 0;
                    secondPointSelected = thirdPointSelected = false;
                }

                Canvas.SetLeft(current.TikzShape.Shape, 0);
                Canvas.SetTop(current.TikzShape.Shape, 0);

                return(current);
            }
            else
            {
                throw new Exception("Sth went wrong, bezier line should be drawn in 3 clicks");
            }
        }