コード例 #1
0
        void DrawLine(CGPoint pt1, CGPoint pt2, UIColor color)
        {
            UIGraphics.BeginImageContext(Frame.Size);

            using (var g = UIGraphics.GetCurrentContext())
            {
                Layer.RenderInContext(g);

                var path = new CGPath();

                path.AddLines(new CGPoint[] { pt1, pt2 });

                g.SetLineWidth(3);
                color.SetStroke();

                g.AddPath(path);
                g.DrawPath(CGPathDrawingMode.Stroke);

                Image = UIGraphics.GetImageFromCurrentImageContext();
            }

            UIGraphics.EndImageContext();

            LineDrawn?.Invoke(this, EventArgs.Empty);
        }
コード例 #2
0
        private void SketchCanvasPointerMoved(object sender, global::Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed == false)
            {
                return;
            }

            var newPoint = e.GetCurrentPoint(this).Position;

            var line = new Line()
            {
                X1 = oldPoint.X,
                Y1 = oldPoint.Y,
                X2 = newPoint.X,
                Y2 = newPoint.Y,
                StrokeThickness = 2.0,
                Stroke          = brush
            };

            oldPoint = newPoint;

            Children.Add(line);

            LineDrawn?.Invoke(this, EventArgs.Empty);
        }
コード例 #3
0
 void FinishedDrawingSegment()
 {
     if (lineSegments.Count < Positions.Count - 1)
     {
         SegmentDrawn?.Invoke();
         Vector3 nextSegmentStart = lineSegments[lineSegments.Count - 1].end;
         AddSegment(nextSegmentStart, nextSegmentStart);
         currentSegmentDirection = Positions[lineSegments.Count] - lineSegments[lineSegments.Count - 1].start;
         currentSegmentDirection.Normalize();
     }
     else
     {
         LineDrawn?.Invoke();
         drawingLine = false;
     }
 }
コード例 #4
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            switch (e.ActionMasked)
            {
            case MotionEventActions.Down:
            {
                int id = e.GetPointerId(0);

                var start = new MotionEvent.PointerCoords();
                e.GetPointerCoords(id, start);
                coords.Add(id, start);

                return(true);
            }

            case MotionEventActions.PointerDown:
            {
                int id = e.GetPointerId(e.ActionIndex);

                var start = new MotionEvent.PointerCoords();
                e.GetPointerCoords(id, start);
                coords.Add(id, start);

                return(true);
            }

            case MotionEventActions.Move:
            {
                for (int index = 0; index < e.PointerCount; index++)
                {
                    var id = e.GetPointerId(index);

                    float x = e.GetX(index);
                    float y = e.GetY(index);

                    drawCanvas.DrawLine(coords[id].X, coords[id].Y, x, y, paint);

                    coords[id].X = x;
                    coords[id].Y = y;

                    LineDrawn?.Invoke(this, EventArgs.Empty);
                }

                Invalidate();

                return(true);
            }

            case MotionEventActions.PointerUp:
            {
                int id = e.GetPointerId(e.ActionIndex);
                coords.Remove(id);
                return(true);
            }

            case MotionEventActions.Up:
            {
                int id = e.GetPointerId(0);
                coords.Remove(id);
                return(true);
            }

            default:
                return(false);
            }
        }
コード例 #5
0
ファイル: DrawingToolsVM.cs プロジェクト: apokrovskyi/KPInt
 private void ChangeLine(ColorLine line)
 {
     DrawnLine = line;
     LineDrawn?.Invoke();
 }