Updated the UWP Forms sample to use the new forms

This commit is contained in:
Matthew Leibowitz 2016-09-16 01:14:13 +02:00
Родитель 3d2ef0b5cc
Коммит 30da89d922
5 изменённых файлов: 6 добавлений и 110 удалений

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

@ -1,82 +0,0 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Graphics.Display;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using SkiaSharp;
namespace Skia.Forms.Demo.UWP
{
public partial class NativeSkiaView : Canvas
{
ISkiaViewController skiaView;
public NativeSkiaView (SkiaView skiaView)
{
this.skiaView = skiaView;
this.SizeChanged += OnSizeChanged;
this.Tapped += OnTapped;
}
private void UpdateBitmap()
{
var resolutionScale = DisplayInformation.GetForCurrentView ().ResolutionScale;
var screenScale = (float)resolutionScale / 100.0f;
var width = (int)(ActualWidth * screenScale);
var height = (int)(ActualHeight * screenScale);
if (width == 0 || height == 0)
return;
IntPtr buff = Marshal.AllocCoTaskMem (width * height * 4);
try {
using (var surface = SKSurface.Create (width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, buff, width * 4)) {
var skcanvas = surface.Canvas;
skcanvas.Scale (screenScale, screenScale);
using (new SKAutoCanvasRestore (skcanvas, true)) {
skiaView.SendDraw (skcanvas);
}
}
var pixels = new byte[width * height * 4];
Marshal.Copy (buff, pixels, 0, pixels.Length);
var bitmap = new WriteableBitmap (width, height);
var stream = bitmap.PixelBuffer.AsStream ();
stream.Seek (0, SeekOrigin.Begin);
stream.Write (pixels, 0, pixels.Length);
bitmap.Invalidate ();
var b = bitmap;
Background = new ImageBrush {
ImageSource = b,
AlignmentX = AlignmentX.Center,
AlignmentY = AlignmentY.Center,
Stretch = Stretch.Fill
};
} finally {
if (buff != IntPtr.Zero) {
Marshal.FreeCoTaskMem (buff);
}
}
}
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
UpdateBitmap ();
}
private void OnTapped(object sender, TappedRoutedEventArgs e)
{
skiaView.SendTap();
}
}
}

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

@ -104,9 +104,7 @@
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="NativeSkiaView.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SkiaViewRenderer.cs" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">

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

@ -5,6 +5,7 @@
</PropertyGroup>
<ImportGroup>
<Import Project="$(NuGetPackageRoot)\SkiaSharp\1.54.1\build\uap10.0\SkiaSharp.targets" Condition="Exists('$(NuGetPackageRoot)\SkiaSharp\1.54.1\build\uap10.0\SkiaSharp.targets')" />
<Import Project="$(NuGetPackageRoot)\Xamarin.Forms\2.3.0.46-pre3\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('$(NuGetPackageRoot)\Xamarin.Forms\2.3.0.46-pre3\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
<Import Project="$(NuGetPackageRoot)\SkiaSharp.Views\1.54.1-beta1\build\uap10.0\SkiaSharp.Views.targets" Condition="Exists('$(NuGetPackageRoot)\SkiaSharp.Views\1.54.1-beta1\build\uap10.0\SkiaSharp.Views.targets')" />
<Import Project="$(NuGetPackageRoot)\Xamarin.Forms\2.3.0.49\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('$(NuGetPackageRoot)\Xamarin.Forms\2.3.0.49\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
</ImportGroup>
</Project>

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

@ -1,22 +0,0 @@
using Xamarin.Forms.Platform.UWP;
[assembly: ExportRenderer (typeof(Skia.Forms.Demo.SkiaView), typeof(Skia.Forms.Demo.UWP.SkiaViewRenderer))]
namespace Skia.Forms.Demo.UWP
{
public class SkiaViewRenderer : ViewRenderer<SkiaView, NativeSkiaView>
{
public SkiaViewRenderer ()
{
}
protected override void OnElementChanged (ElementChangedEventArgs<SkiaView> e)
{
base.OnElementChanged(e);
if (Control == null && Element != null) {
SetNativeControl (new NativeSkiaView (Element));
}
}
}
}

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

@ -1,8 +1,9 @@
{
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"SkiaSharp": "1.54.1",
"Xamarin.Forms": "2.3.0.46-pre3"
"SkiaSharp.Views.Forms": "1.54.1-beta1",
"Xamarin.Forms": "2.3.0.49"
},
"frameworks": {
"uap10.0": {}