Added a way to disable raster canvas scaling to Forms views

This commit is contained in:
Matthew Leibowitz 2016-11-12 03:05:42 +02:00
Родитель 129a3ec77f
Коммит a05232a36f
3 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using Android.Content;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
@ -29,6 +30,7 @@ namespace SkiaSharp.Views.Forms
// create the native view
var view = new InternalView(Context, newController);
view.IgnorePixelScaling = e.NewElement.IgnorePixelScaling;
SetNativeControl(view);
// subscribe to events from the user
@ -42,6 +44,16 @@ namespace SkiaSharp.Views.Forms
base.OnElementChanged(e);
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == nameof(SKFormsView.IgnorePixelScaling))
{
Control.IgnorePixelScaling = Element.IgnorePixelScaling;
}
}
protected override void Dispose(bool disposing)
{
// detach all events before disposing

Просмотреть файл

@ -6,6 +6,9 @@ namespace SkiaSharp.Views.Forms
[RenderWith(typeof(SKCanvasViewRenderer))]
public class SKCanvasView : View, ISKCanvasViewController
{
public static readonly BindableProperty IgnorePixelScalingProperty =
BindableProperty.Create(nameof(IgnorePixelScaling), typeof(bool), typeof(SKCanvasView), default(bool));
// the user can subscribe to repaint
public event EventHandler<SKPaintSurfaceEventArgs> PaintSurface;
@ -25,6 +28,12 @@ namespace SkiaSharp.Views.Forms
}
}
public bool IgnorePixelScaling
{
get { return (bool)GetValue(IgnorePixelScalingProperty); }
set { SetValue(IgnorePixelScalingProperty, value); }
}
// the user asks to repaint
public void InvalidateSurface()
{

Просмотреть файл

@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
@ -28,6 +29,7 @@ namespace SkiaSharp.Views.Forms
// create the native view
var view = new InternalView(newController);
view.IgnorePixelScaling = e.NewElement.IgnorePixelScaling;
SetNativeControl(view);
// subscribe to events from the user
@ -41,6 +43,16 @@ namespace SkiaSharp.Views.Forms
base.OnElementChanged(e);
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == nameof(SKFormsView.IgnorePixelScaling))
{
Control.IgnorePixelScaling = Element.IgnorePixelScaling;
}
}
protected override void Dispose(bool disposing)
{
// detach all events before disposing