Esempio n. 1
0
        /// <summary>
        /// generate the path for the border
        /// </summary>
        /// <param name="paint">the paint object for the path</param>
        /// <returns>a skpath representing the border of the floating label entry</returns>
        private SKPath GeneratePath(SKPaint paint)
        {
            var path = new SKPath();

            Rectangle viewBounds = SkCanvasView.FromPixels(borderlessEntry.Bounds);

            var   strokeWidth = (float)SkCanvasView.FromPixels(new Point(0, paint.StrokeWidth)).Y;
            float arcHeight   = (float)viewBounds.Height + (float)strokeWidth;

            var textSize = SkCanvasView.FromPixels(new Size(
                                                       width: CalculateBounds.GetTextWidth(borderlessEntry.Placeholder, borderlessEntry.TitleFontSize),
                                                       height: CalculateBounds.GetTextHeight(borderlessEntry.Placeholder, borderlessEntry.TitleFontSize)));


            // move the point next to the placeholder label
            path.MoveTo(
                x: (float)viewBounds.X + (float)textSize.Width + 3,
                y: (float)viewBounds.Y);

            float xCurrent = path.LastPoint.X;
            float yCurrent = path.LastPoint.Y;

            // line above the entry
            path.LineTo((float)viewBounds.Width + (float)viewBounds.X, yCurrent);

            xCurrent = path.LastPoint.X;

            // draw the arc pointing down (right arc)
            path.ArcTo(
                oval: new SKRect(xCurrent - arcHeight / 2, yCurrent, xCurrent + arcHeight / 2, yCurrent + arcHeight),
                startAngle: -90,
                sweepAngle: 180,
                forceMoveTo: false);

            // draw the line below the entry
            path.LineTo((float)viewBounds.X, path.LastPoint.Y);

            xCurrent = path.LastPoint.X;
            yCurrent = path.LastPoint.Y;

            // draw the arc from below entry to above entry (left arc)
            path.ArcTo(
                oval: new SKRect(xCurrent - arcHeight / 2, yCurrent - arcHeight, xCurrent + arcHeight / 2, yCurrent),
                startAngle: 90,
                sweepAngle: 180,
                forceMoveTo: false);

            _borderPath      = path;
            _strokeDashStart = new DashedStroke(
                intervals: new float[] { 0, new SKPathMeasure(_borderPath).Length },
                phase: -0);

            _strokeDashEnd = new DashedStroke(
                intervals: new float[] { new SKPathMeasure(_borderPath).Length, new SKPathMeasure(_borderPath).Length },
                phase: -0);

            CreateShader();

            return(_borderPath);
        }
Esempio n. 2
0
        public void Dashed()
        {
            var p1     = new SPoint(0, 0);
            var p2     = new SPoint(10, 0);
            var p3     = new SPoint(20, 0);
            var p4     = new SPoint(30, 0);
            var s      = new PolyStroke(new SPoint[] { p1, p2, p3, p4 });
            var dashed = new DashedStroke(s, 2);

            Assert.AreEqual(2, dashed.Count());
            PointListsHelper.AssertPointPresence(dashed, new SPoint[] { p1, p3 });
        }
Esempio n. 3
0
        /// <summary>
        /// Draw the boarder
        /// </summary>
        /// <returns></returns>
        private async Task PlaceholderToTitleAsync()
        {
            _strokeDashStart = new DashedStroke(
                intervals: new float[] { 0, new SKPathMeasure(_borderPath).Length },
                phase: -0);

            _strokeDashEnd = new DashedStroke(
                intervals: new float[] { new SKPathMeasure(_borderPath).Length, new SKPathMeasure(_borderPath).Length },
                phase: -0);

            var anim = new DashedStrokeAnimation(
                from: _strokeDashStart,
                to: _strokeDashEnd,
                duration: ANIMATION_DURATION);

            await anim.Start((strokeDashToDraw) => SkCanvasView.InvalidateSurface());
        }