Пример #1
0
    /// <inheritdoc cref="IPaint{TDrawingContext}.InitializeTask(TDrawingContext)" />
    public override void InitializeTask(SkiaSharpDrawingContext drawingContext)
    {
        skiaPaint ??= new SKPaint();

        var size   = GetDrawRectangleSize(drawingContext);
        var center = new SKPoint(size.Location.X + _center.X * size.Width, size.Location.Y + _center.Y * size.Height);
        var r      = size.Location.X + size.Width > size.Location.Y + size.Height
            ? size.Location.Y + size.Height
            : size.Location.X + size.Width;

        r *= _radius;

        skiaPaint.Shader = SKShader.CreateRadialGradient(
            center,
            r,
            _gradientStops,
            _colorPos,
            _tileMode);

        skiaPaint.IsAntialias = IsAntialias;
        skiaPaint.IsStroke    = true;
        skiaPaint.StrokeWidth = StrokeThickness;
        skiaPaint.StrokeCap   = StrokeCap;
        skiaPaint.StrokeJoin  = StrokeJoin;
        skiaPaint.StrokeMiter = StrokeMiter;
        skiaPaint.Style       = IsStroke ? SKPaintStyle.Stroke : SKPaintStyle.Fill;
        if (FontFamily != null)
        {
            skiaPaint.Typeface = GetTypeFaceFromFontFamily();
        }

        if (PathEffect is not null)
        {
            PathEffect.CreateEffect(drawingContext);
            skiaPaint.PathEffect = PathEffect.SKPathEffect;
        }

        if (ImageFilter is not null)
        {
            ImageFilter.CreateFilter(drawingContext);
            skiaPaint.ImageFilter = ImageFilter.SKImageFilter;
        }

        var clip = GetClipRectangle(drawingContext.MotionCanvas);

        if (clip != LvcRectangle.Empty)
        {
            _ = drawingContext.Canvas.Save();
            drawingContext.Canvas.ClipRect(new SKRect(clip.X, clip.Y, clip.X + clip.Width, clip.Y + clip.Height));
            _drawingContext = drawingContext;
        }

        drawingContext.Paint     = skiaPaint;
        drawingContext.PaintTask = this;
    }
Пример #2
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public override void Dispose()
        {
            if (PathEffect is not null)
            {
                PathEffect.Dispose();
            }

            if (_drawingContext is not null && GetClipRectangle(_drawingContext.MotionCanvas) != RectangleF.Empty)
            {
                _drawingContext.Canvas.Restore();
                _drawingContext = null;
            }

            base.Dispose();
        }
Пример #3
0
 private void Awake()
 {
     _gameloopManager  = GetComponent <GameloopManager>();
     _daytimeManager   = GetComponent <DaytimeManager>();
     _planeManager     = GetComponent <PlaneManager>();
     _airportManager   = GetComponent <AirportManager>();
     _upgradeManager   = GetComponent <UpgradeManager>();
     _camera           = Camera.main;
     _cameraController = _camera.GetComponent <CameraController>();
     StoreCamera();
     _unlockButton.gameObject.SetActive(_cameraController.lockRotation);
     _lockButton.gameObject.SetActive(!_cameraController.lockRotation);
     _pathEffect    = new PathEffect(_pathTessellation);
     _preserveColor = _preserveAlphaPanel.color;
 }
 /// <inheritdoc cref="IPaintTask{TDrawingContext}.CloneTask" />
 public override IPaintTask <SkiaSharpDrawingContext> CloneTask()
 {
     return(new RadialGradientPaintTask(_gradientStops, _center, _radius, _colorPos, _tileMode)
     {
         Style = Style,
         IsStroke = IsStroke,
         IsFill = IsFill,
         Color = Color,
         IsAntialias = IsAntialias,
         StrokeThickness = StrokeThickness,
         StrokeCap = StrokeCap,
         StrokeJoin = StrokeJoin,
         StrokeMiter = StrokeMiter,
         PathEffect = PathEffect?.Clone(),
         ImageFilter = ImageFilter?.Clone()
     });
 }
Пример #5
0
        public void SetDashedStroke(double dashWidth, double dashGap)
        {
            _dirty = true;
            if (dashWidth <= 0 || dashGap <= 0)
            {
                _strokePathEffect = null;
            }
            else
            {
                _strokePathEffect = new DashPathEffect(new float[]
                {
                    (int)(dashWidth * _density),
                    (int)(dashGap * _density)
                }, 0);
            }

            InvalidateSelf();
        }
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            var dashedLine = (DashedLine)Element;

            _paint = new Paint();
            _paint.SetStyle(Paint.Style.Stroke);
            _paint.StrokeWidth = dashedLine.LineWidth;
            _paint.Color       = dashedLine.Color.ToAndroid();

            _effects = new DashPathEffect(new float[] { 20, 20, 20, 20 }, 0);
            _paint.SetPathEffect(_effects);

            _path = new Path();
            _path.MoveTo(0, 0);
            _path.LineTo(this.MeasuredWidth, 0);
            canvas.DrawPath(_path, _paint);
        }
Пример #7
0
        /// <inheritdoc cref="IPaintTask{TDrawingContext}.CloneTask" />
        public override IPaintTask <SkiaSharpDrawingContext> CloneTask()
        {
            var clone = new SolidColorPaintTask
            {
                Style           = Style,
                IsStroke        = IsStroke,
                IsFill          = IsFill,
                Color           = Color,
                IsAntialias     = IsAntialias,
                StrokeThickness = StrokeThickness,
                StrokeCap       = StrokeCap,
                StrokeJoin      = StrokeJoin,
                StrokeMiter     = StrokeMiter,
                PathEffect      = PathEffect?.Clone(),
                ImageFilter     = ImageFilter?.Clone()
            };

            return(clone);
        }
Пример #8
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                if (_clipPath != null)
                {
                    _clipPath.Dispose();
                    _clipPath = null;
                }

                if (_strokePathEffect != null)
                {
                    _strokePathEffect.Dispose();
                    _strokePathEffect = null;
                }

                if (_gradientProvider != null)
                {
                    _gradientProvider.Dispose();
                    _gradientProvider = null;
                }

                if (_strokeGradientProvider != null)
                {
                    _strokeGradientProvider.Dispose();
                    _strokeGradientProvider = null;
                }

                _pathProvider = null;
            }

            DisposeBorder(disposing);

            base.Dispose(disposing);
        }
Пример #9
0
        /// <inheritdoc cref="IPaint{TDrawingContext}.InitializeTask(TDrawingContext)" />
        public override void InitializeTask(SkiaSharpDrawingContext drawingContext)
        {
            skiaPaint ??= new SKPaint();

            skiaPaint.Color       = Color;
            skiaPaint.IsAntialias = IsAntialias;
            skiaPaint.IsStroke    = IsStroke;
            skiaPaint.StrokeCap   = StrokeCap;
            skiaPaint.StrokeJoin  = StrokeJoin;
            skiaPaint.StrokeMiter = StrokeMiter;
            skiaPaint.StrokeWidth = StrokeThickness;
            skiaPaint.Style       = IsStroke ? SKPaintStyle.Stroke : SKPaintStyle.Fill;
            if (FontFamily != null)
            {
                skiaPaint.Typeface = GetTypeFaceFromFontFamily();
            }

            if (PathEffect is not null)
            {
                PathEffect.CreateEffect(drawingContext);
                skiaPaint.PathEffect = PathEffect.SKPathEffect;
            }

            if (ImageFilter is not null)
            {
                ImageFilter.CreateFilter(drawingContext);
                skiaPaint.ImageFilter = ImageFilter.SKImageFilter;
            }

            var clip = GetClipRectangle(drawingContext.MotionCanvas);

            if (clip != LvcRectangle.Empty)
            {
                _ = drawingContext.Canvas.Save();
                drawingContext.Canvas.ClipRect(new SKRect(clip.X, clip.Y, clip.X + clip.Width, clip.Y + clip.Height));
                _drawingContext = drawingContext;
            }

            drawingContext.Paint     = skiaPaint;
            drawingContext.PaintTask = this;
        }
Пример #10
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public override void Dispose()
        {
            if (FontFamily != null && skiaPaint != null)
            {
                skiaPaint.Typeface.Dispose();
            }
            if (PathEffect is not null)
            {
                PathEffect.Dispose();
            }
            if (ImageFilter is not null)
            {
                ImageFilter.Dispose();
            }

            if (_drawingContext is not null && GetClipRectangle(_drawingContext.MotionCanvas) != LvcRectangle.Empty)
            {
                _drawingContext.Canvas.Restore();
                _drawingContext = null;
            }

            base.Dispose();
        }
        /// <inheritdoc cref="PathEffect" />
        public override PathEffect InterpolateFrom(PathEffect from, float progress)
        {
            var fromDashEffect = (DashPathEffect)from;

            return(new DashPathEffect(_dashArray, fromDashEffect._phase + progress * (_phase - 0)));
        }