Ejemplo n.º 1
0
        private void DrawSocket(SKCanvas canvas, float radius)
        {
            canvas.Save();

            _paint.Style = SKPaintStyle.Fill;

            _paint.Color = BackgroundColor.ToBaseGradientColors(IsEnabled)[0];

            canvas.DrawCircle(0, 0, radius.Scale(0.70f), _paint);

            canvas.Save();

            canvas.Scale(1, -1);

            _textPaint.StrokeWidth = 2;

            _textPaint.Style = SKPaintStyle.StrokeAndFill;

            _textPaint.TextSize = radius.Scale(0.5f);

            _textPaint.Typeface = _typeface;

            _textPaint.Color = IndicatorsColor.ToSKColor();


            canvas.DrawText(Value.ToString("000."), new SKPoint(-radius.Scale(0.45f), radius.Scale(0.20f)), _textPaint);

            canvas.Restore();

            DrawStroke(radius);

            canvas.DrawCircle(0, 0, radius.Scale(0.70f), _paint);

            canvas.Restore();
        }
Ejemplo n.º 2
0
        private void DrawIndicators(SKCanvas canvas, float radius)
        {
            canvas.Save();

            var baseRadius = radius.Scale(0.75f);

            var size = radius.Scale(0.15f);


            _indicatorPaint.Style = SKPaintStyle.Stroke;

            _indicatorPaint.StrokeCap = SKStrokeCap.Round;

            _indicatorPaint.ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 0.5f, 0.5f, SKColors.Black);

            _indicatorPaint.StrokeWidth = radius.Scale(0.04f);


            for (int i = 0; i < 25; i++)
            {
                canvas.RotateDegrees(10);

                canvas.Save();

                canvas.RotateDegrees(230);

                canvas.Translate(0, baseRadius);

                _indicatorPaint.Color = i <= Value.Map(0, 99, 25, 0) ? BackgroundColor.ToBaseGradientColors(IsEnabled)[1] : IndicatorsColor.ToSKColor();

                canvas.DrawLine(0, 0, 0, size, _indicatorPaint);

                canvas.Restore();
            }


            canvas.Restore();
        }
Ejemplo n.º 3
0
    private void DrawIndicators(SKCanvas canvas, float radius)
    {
        var threashHold = radius.Scale(0.05f);

        var previousDirection = Direction;

        canvas.Save();

        var baseRadius = radius.Scale(0.80f);

        var size = radius.Scale(0.08f);

        _indicatorPath = SKPath.ParseSvgPathData($"M-{size} 0L0 {size}L{size} 0L-{size} 0Z");

        _indicatorPaint.ImageFilter = SKImageFilter.CreateDropShadow(0, 1, baseRadius.Scale(0.005f), baseRadius.Scale(0.005f), SKColors.Gray);


        // Top

        canvas.Save();

        var isForward = _position.Y > threashHold;

        _indicatorPaint.Color = isForward ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled);

        Direction = isForward ? Direction & (~JoystickDirection.None) | JoystickDirection.Forward : Direction & (~JoystickDirection.Forward);

        canvas.Translate(0, baseRadius);

        canvas.RotateDegrees(0);

        canvas.DrawPath(_indicatorPath, _indicatorPaint);

        canvas.Restore();

        // Rigth

        canvas.Save();

        var isRigth = _position.X > threashHold;

        _indicatorPaint.Color = isRigth ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled);

        Direction = isRigth ? Direction & (~JoystickDirection.None) | JoystickDirection.Right : Direction & (~JoystickDirection.Right);

        canvas.Translate(baseRadius, 0);

        canvas.RotateDegrees(-90);

        canvas.DrawPath(_indicatorPath, _indicatorPaint);

        canvas.Restore();

        // Backward

        canvas.Save();

        var isBackward = _position.Y < -threashHold;

        _indicatorPaint.Color = isBackward ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled);

        Direction = isBackward ? Direction & (~JoystickDirection.None) | JoystickDirection.Backward : Direction & (~JoystickDirection.Backward);

        canvas.Translate(0, -baseRadius);

        canvas.RotateDegrees(180);

        canvas.DrawPath(_indicatorPath, _indicatorPaint);

        canvas.Restore();


        // Left

        canvas.Save();

        var isLeft = _position.X < -threashHold;

        _indicatorPaint.Color = isLeft ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled);

        Direction = isLeft ? Direction & (~JoystickDirection.None) | JoystickDirection.Left : Direction & (~JoystickDirection.Left);

        canvas.Translate(-baseRadius, 0);

        canvas.RotateDegrees(90);

        canvas.DrawPath(_indicatorPath, _indicatorPaint);

        canvas.Restore();

        if (!isForward && !isBackward && !isRigth && !isLeft)
        {
            Direction = JoystickDirection.None;
        }

        if (Direction != previousDirection)
        {
            DigitalMoved?.Invoke(this, new EventArgs());
            Execute(Command);
        }

        canvas.Restore();
    }