Beispiel #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);
        }
Beispiel #2
0
        private async void SKCanvasView_OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;

            canvas.Clear(SKColors.Black);
            var point = _complex.ToPoint(time, this.Width / 2 + 100, this.Height / 2);

            _path.Insert(0, point);

            canvas.DrawPoints(SKPointMode.Polygon, _path.ToArray(), new SKPaint()
            {
                Color       = SKColors.White,
                StrokeWidth = 5,

                StrokeJoin           = SKStrokeJoin.Round,
                FilterQuality        = SKFilterQuality.High,
                StrokeCap            = SKStrokeCap.Round,
                IsAntialias          = true,
                HintingLevel         = SKPaintHinting.NoHinting,
                Style                = SKPaintStyle.Fill,
                DeviceKerningEnabled = true
            });



            time += (2f * Math.PI) / Count;
            if (time > 2f * Math.PI)
            {
                time = 0;
                _path.Clear();
            }
            await Task.Delay(1);

            SkCanvasView.InvalidateSurface();
        }
        private void SkCanvasView_OnTouch(object sender, SKTouchEventArgs e)
        {
            // to fix the UWP touch bevaior
            if (Device.RuntimePlatform == Device.UWP)
            {
                // avoid mouse over touch events
                if (!e.InContact)
                {
                    return;
                }
            }

            _lastTouchPoint = e.Location;

            var canvasSize = SkCanvasView.CanvasSize;

            // Check for each touch point XY position to be inside Canvas
            // Ignore any Touch event ocurred outside the Canvas region
            if ((e.Location.X > 0 && e.Location.X < canvasSize.Width) &&
                (e.Location.Y > 0 && e.Location.Y < canvasSize.Height))
            {
                e.Handled = true;

                // update the Canvas as you wish
                SkCanvasView.InvalidateSurface();
            }
        }
Beispiel #4
0
        private async void PickImageEffectButton_Clicked(object sender, EventArgs e)
        {
            var selection = await DisplayActionSheet("Pick an Image Effect", null, "Cancel", imageEffectsList.ToArray());

            if (selection != null && selection != "Cancel")
            {
                selectedImageEffect  = selection;
                EffectNameLabel.Text = $"{selectedImageEffect}";
                SkCanvasView.InvalidateSurface();
            }
        }
        private async void PickShapeToDrawButton_Clicked(object sender, EventArgs e)
        {
            var selection = await DisplayActionSheet("Pick a Shape", null, "Cancel", shapesList.ToArray());

            if (selection != null && selection != "Cancel")
            {
                selectedShape = selection;
                DrawingShapeNameLabel.Text = $"Drawing {selectedShape}";
                SkCanvasView.InvalidateSurface();
            }
        }
Beispiel #6
0
        private void SetPointerRingPosition(double xPositionUnits, double yPositionUnits)
        {
            var xPosition = SkCanvasView.CanvasSize.Width
                            * xPositionUnits; // Calculate actual X Position
            var yPosition = SkCanvasView.CanvasSize.Height
                            * yPositionUnits; // Calculate actual Y Position

            // Update as last touch Position on Canvas
            _lastTouchPoint = new SKPoint(Convert.ToSingle(xPosition), Convert.ToSingle(yPosition));
            SkCanvasView.InvalidateSurface();
        }
        private void SkCanvasView_Touch(object sender, SkiaSharp.Views.Forms.SKTouchEventArgs e)
        {
            if (e.ActionType == SkiaSharp.Views.Forms.SKTouchAction.Pressed)
            {
                _lastTouchPoint = e.Location;
                e.Handled       = true;
            }

            _lastTouchPoint = e.Location;

            SkCanvasView.InvalidateSurface();
        }
        protected override void OnAppearing()
        {
            if (!start)
            {
                StartThreads();

                XplatUIMine.GetInstance().Keyboard = new Keyboard(Entry);
                start = true;
            }

            SkCanvasView.InvalidateSurface();

            base.OnAppearing();
        }
Beispiel #9
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());
        }
Beispiel #10
0
        private void SkCanvasView_OnTouch(object sender, SKTouchEventArgs e)
        {
            _lastTouchPoint = e.Location;

            var canvasSize = SkCanvasView.CanvasSize;

            // Check for each touch point XY position to be inside Canvas
            // Ignore any Touch event ocurred outside the Canvas region
            if ((e.Location.X > 0 && e.Location.X < canvasSize.Width) &&
                (e.Location.Y > 0 && e.Location.Y < canvasSize.Height))
            {
                e.Handled = true;

                // update the Canvas as you wish
                SkCanvasView.InvalidateSurface();
            }
        }
        const double cycleTime = 1000; // in milliseconds

        private void InitAnimation()
        {
            pageIsActive = true;
            stopwatch.Start();

            Device.StartTimer(TimeSpan.FromMilliseconds(33), () =>
            {
                // calculate t for current tick with regards to cycletime
                t = (float)(stopwatch.Elapsed.TotalMilliseconds % cycleTime / cycleTime);
                SkCanvasView.InvalidateSurface();

                if (!pageIsActive)
                {
                    stopwatch.Stop();
                }
                return(pageIsActive);
            });
        }