예제 #1
0
 /// <summary>
 /// Closes this instance and frees resources.
 /// <para>
 /// After a call to this method, the canvas can no longer be used for drawing.
 /// </para>
 /// </summary>
 protected void Close()
 {
     if (_canvas != null)
     {
         _canvas.Dispose();
         _canvas = null;
     }
     if (_bitmap != null)
     {
         _bitmap.Dispose();
         _bitmap = null;
     }
     if (_path != null)
     {
         _path.Dispose();
         _path = null;
     }
     if (_strokePaint != null)
     {
         _strokePaint.Dispose();
         _strokePaint = null;
         _fillPaint.Dispose();
         _fillPaint = null;
         _textPaint.Dispose();
         _textPaint = null;
         _regularTypeface.Dispose();
         _regularTypeface = null;
         _boldTypeface.Dispose();
         _boldTypeface = null;
     }
 }
예제 #2
0
        private void SKCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs args)
        {
            var vm         = BindingContext as DiceRollerViewModel;
            var diceRoller = new DiceRollerViewModel();
            var diceRolls  = diceRoller.DicesValues(vm.Type, vm.Quantity);

            foreach (var diceRoll in diceRolls)
            {
                Debug.WriteLine($"{diceRoll.Key} => {diceRoll.Value / vm.Quantity}");
            }


            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            float minx  = diceRolls.Min(kv => kv.Value);
            float miny  = diceRolls.Min(kv => kv.Key);
            float maxx  = diceRolls.Max(kv => kv.Value);
            float maxy  = diceRolls.Max(kv => kv.Key);
            float sumx  = diceRolls.Sum(kv => kv.Value);
            float sizey = info.Height / (maxy - miny + 1);

            SKTypeface typeface = null;
            var        inFont   = AideDeJeu.Tools.Helpers.GetResourceStream("AideDeJeu.Pdf.LinLibertine_R.ttf");

            typeface = SKTypeface.FromStream(inFont);

            SKPaint strokePaint = new SKPaint()
            {
                Color       = new SKColor(0x9B, 0x1C, 0x47),
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 1,
            };
            SKPaint strokeFont = new SKPaint()
            {
                Color       = new SKColor(0x9B, 0x1C, 0x47),
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 1,
                TextSize    = sizey * 0.6f,
                Typeface    = typeface
            };

            canvas.Clear();
            foreach (var diceRoll in diceRolls)
            {
                float x = diceRoll.Value;
                float y = diceRoll.Key;
                canvas.DrawRect(new SKRect(0, ((y - miny) * sizey), x * info.Width / maxx, ((y - miny) * sizey) + sizey - 5), strokePaint);

                canvas.DrawText($"{y} => {x / sumx * 100:0.00}%", 10, ((y - miny) * sizey) + sizey * 0.6f, strokeFont);
            }

            typeface.Dispose();
            strokeFont.Dispose();
            strokePaint.Dispose();
        }
예제 #3
0
 public static void ResetSkia()
 {
     lock (_lock)
     {
         _typeface?.Dispose();
         _linePaint?.Dispose();
         _rectPaint?.Dispose();
         _textPaint?.Dispose();
         _typeface  = null;
         _linePaint = null;
         _rectPaint = null;
         _textPaint = null;
         _typeface  = SKTypeface.FromFile(_fontFile);
         _linePaint = new SKPaint()
         {
             Color       = Colors.White,
             Style       = SKPaintStyle.Stroke,
             StrokeCap   = SKStrokeCap.Square,
             StrokeJoin  = SKStrokeJoin.Bevel,
             StrokeWidth = (float)(2 * DisplayScale),
             IsAntialias = GameConfig.Instance.AntiAlias
         };
         _rectPaint = new SKPaint()
         {
             Color       = Colors.White,
             Style       = SKPaintStyle.StrokeAndFill,
             StrokeCap   = SKStrokeCap.Square,
             StrokeJoin  = SKStrokeJoin.Bevel,
             IsAntialias = GameConfig.Instance.AntiAlias
         };
         _textPaint = _textPaint ?? new SKPaint()
         {
             Color       = Colors.White,
             Typeface    = _typeface,
             TextSize    = (float)(12 * DisplayScale),
             IsStroke    = false,
             IsAntialias = GameConfig.Instance.AntiAlias
         };
     }
 }
예제 #4
0
 public void Dispose()
 {
     Font?.Dispose();
     Font = null;
     FontStream?.Dispose();
     FontStream = null;
     FontSource?.Dispose();
     FontSource = null;
     ImageBitmap?.Dispose();
     ImageBitmap = null;
     ImageData?.Dispose();
     ImageData = null;
 }
예제 #5
0
 void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         if (disposing)
         {
             if (skTypeface != null)
             {
                 skTypeface.Dispose();
                 skTypeface = null;
             }
         }
         disposedValue = true;
     }
 }
예제 #6
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_config != null)
                {
                    Toml.WriteFile(_config, "config.toml", _tomlSettings);
                    _config = null;
                }

                _waveIn?.StopRecording();
                _waveIn?.Dispose();
                _waveIn = null;

                _speechRecognizer?.Dispose();
                _speechRecognizer = null;

                _skFont?.Dispose();
                _skFont = null;

                _skStrokePaint?.Dispose();
                _skStrokePaint = null;

                _skFillPaint?.Dispose();
                _skFillPaint = null;

                _skScreenSurface?.Dispose();
                _skScreenSurface = null;

                _skScreenRenderTarget?.Dispose();
                _skScreenRenderTarget = null;

                _skContext?.Dispose();
                _skContext = null;

                _skInterface?.Dispose();
                _skInterface = null;

                _tkContext?.Dispose();
                _tkContext = null;

                _tkWindow?.Dispose();
                _tkWindow = null;
            }
        }