Example #1
0
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            var skiaDrawingSurface = new SkiaDrawingSurface(surface.Canvas);

            int requiredHeight = chordDiagramRenderer.GetRequiredHeight(skiaDrawingSurface);

            if (this.SkiaCanvas.Height < requiredHeight)
            {
                // this.CanvasView.HeightRequest = requiredHeight;
            }

            // work out the width we need for our diagram
            var diagramRequiredWidth = chordDiagramRenderer.GetRequiredWidthPerChord();
            var canvasWidth          = info.Width;

            var chordsPerRow = canvasWidth / diagramRequiredWidth;

            if (chordsPerRow > 10)
            {
                chordsPerRow = 10;
            }
            chordDiagramRenderer.ChordsPerRow = (int)chordsPerRow - 1;

            float scaleFactor = (float)canvasWidth / (float)(diagramRequiredWidth * chordsPerRow);

            if (scaleFactor < 1.5)
            {
                scaleFactor = 1.5f;
            }

            skiaDrawingSurface.SetScale((float)scaleFactor);

            canvas.Clear();

            chordDiagramRenderer.Render(skiaDrawingSurface);
        }
Example #2
0
        public override void Render(DrawingContext context)
        {
            base.Render(context);

            if (ChordDefinition != null)
            {
                _diagramRenderer.CurrentChordDiagrams = ViewModels.MainViewModel.GuitarModel.GetChordDiagramsByGroup(ChordDefinition.ChordGroup.ToString());
            }

            context.Custom(_customDrawingOp);

            //Dispatcher.UIThread.InvokeAsync(InvalidateVisual, DispatcherPriority.Background);

            var diagramWidth = _diagramRenderer.GetRequiredWidthPerChord() * _diagramRenderer.ChordsPerRow;

            if (this.Width != diagramWidth)
            {
                this.Width = diagramWidth;
            }
            if (this.Height != 500)
            {
                this.Height = 500;
            }
        }