This commit is contained in:
Matthew Leibowitz 2016-06-04 10:11:26 +02:00
Родитель d53a1d8165
Коммит 69cf89c880
32 изменённых файлов: 228 добавлений и 65 удалений

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

@ -8,7 +8,7 @@ using System.Xml.Linq;
var TARGET = Argument ("t", Argument ("target", Argument ("Target", "Default")));
var NuGetSources = new [] { "https://www.nuget.org/api/v2/" };
var NuGetSources = new [] { "https://www.nuget.org/api/v2/", "https://www.myget.org/F/xamprojectci/api/v2" };
var NugetToolPath = GetToolPath ("../nuget.exe");
var XamarinComponentToolPath = GetToolPath ("../xamarin-component.exe");
var CakeToolPath = GetToolPath ("Cake.exe");

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

@ -912,6 +912,42 @@ namespace SkiaSharp
}
}
public static void CreatePdfSample (SKCanvas canvas, int width, int height)
{
canvas.Clear(SKColors.White);
using (var paint = new SKPaint ()) {
paint.TextSize = 24.0f;
paint.IsAntialias = true;
paint.Color = new SKColor (0x9C, 0xAF, 0xB7);
paint.StrokeWidth = 3;
paint.TextAlign = SKTextAlign.Center;
canvas.DrawText ("tap to open", width / 2f, 100f, paint);
}
using (var stream = new SKFileWStream (Path.Combine (WorkingDirectory, "document.pdf")))
using (var document = SKDocument.CreatePdf (stream))
using (var pdfCanvas = document.BeginPage (width, height))
using (var paint = new SKPaint ()) {
paint.TextSize = 64.0f;
paint.IsAntialias = true;
paint.Color = new SKColor (0x9C, 0xAF, 0xB7);
paint.IsStroke = true;
paint.StrokeWidth = 3;
paint.TextAlign = SKTextAlign.Center;
pdfCanvas.DrawText ("...PDF...", width / 2f, 100f, paint);
document.EndPage ();
document.Close ();
}
}
public static void CreatePdfSampleTapped ()
{
OpenFileDelegate?.Invoke ("document.pdf");
}
[Flags]
public enum Platform
@ -924,11 +960,12 @@ namespace SkiaSharp
All = 0xFFFF,
}
class Sample
public class Sample
{
public string Title { get; set; }
public Action <SKCanvas, int, int> Method { get; set; }
public Platform Platform { get; set; }
public string Title { get; internal set; }
public Action <SKCanvas, int, int> Method { get; internal set; }
public Platform Platform { get; internal set; }
public Action TapMethod { get; internal set; }
}
public static string [] SamplesForPlatform (Platform platform)
@ -936,13 +973,17 @@ namespace SkiaSharp
return sampleList.Where (s => 0 != (s.Platform & platform)).Select (s => s.Title).ToArray ();
}
public static Action <SKCanvas, int, int> MethodForSample (string title)
public static Sample GetSample (string title)
{
return sampleList.Where (s => s.Title == title).First ().Method;
return sampleList.Where (s => s.Title == title).First ();
}
public static string CustomFontPath { get; set; }
public static string WorkingDirectory { get; set; }
public static Action<string> OpenFileDelegate { get; set; }
static Sample [] sampleList = new Sample[] {
new Sample {Title="Xamagon", Method = DrawXamagon, Platform = Platform.All},
new Sample {Title="Text Sample", Method = TextSample, Platform = Platform.All},
@ -971,6 +1012,7 @@ namespace SkiaSharp
new Sample {Title="Magnifier Image Filter", Method = MagnifierImageFilter, Platform = Platform.All},
new Sample {Title="Chained Image Filter", Method = ChainedImageFilter, Platform = Platform.All},
new Sample {Title="Measure Text Sample", Method = MeasureTextSample, Platform = Platform.All},
new Sample {Title="Create PDF", Method = CreatePdfSample, Platform = Platform.All, TapMethod = CreatePdfSampleTapped},
};
}
}

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

@ -25,6 +25,18 @@ namespace Skia.Forms.Demo.Droid
}
SkiaSharp.Demos.CustomFontPath = fontPath;
var dir = Path.Combine(ExternalCacheDir.AbsolutePath, "SkiaSharp.Demos");
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
SkiaSharp.Demos.WorkingDirectory = dir;
SkiaSharp.Demos.OpenFileDelegate = path =>
{
var file = new Java.IO.File (Path.Combine (dir, path));
var uri = Android.Net.Uri.FromFile (file);
StartActivity (new Intent (Intent.ActionView, uri));
};
base.OnCreate (bundle);

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

@ -8,11 +8,14 @@ namespace Skia.Forms.Demo.Droid
public class NativeSkiaView : View
{
private Bitmap bitmap;
SkiaView skiaView;
readonly SkiaView skiaView;
readonly ISkiaViewController iskiaView;
public NativeSkiaView (Android.Content.Context context, SkiaView skiaView) : base (context)
{
this.skiaView = skiaView;
this.iskiaView = skiaView;
this.Click += OnTapped;
}
protected override void OnDraw (Android.Graphics.Canvas canvas)
@ -31,7 +34,7 @@ namespace Skia.Forms.Demo.Droid
using (var surface = SKSurface.Create (canvas.Width, canvas.Height, SKColorType.Rgba_8888, SKAlphaType.Premul, bitmap.LockPixels (), canvas.Width * 4)) {
var skcanvas = surface.Canvas;
skcanvas.Scale (((float)canvas.Width)/(float)skiaView.Width, ((float)canvas.Height)/(float)skiaView.Height);
(skiaView as ISkiaViewController).SendDraw (skcanvas);
iskiaView.SendDraw (skcanvas);
}
}
finally {
@ -40,6 +43,11 @@ namespace Skia.Forms.Demo.Droid
canvas.DrawBitmap (bitmap, 0, 0, null);
}
void OnTapped(object sender, EventArgs e)
{
iskiaView.SendTap ();
}
}
}

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

@ -26,3 +26,5 @@ using Android.App;
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
[assembly: UsesPermission (Android.Manifest.Permission.ReadExternalStorage)]
[assembly: UsesPermission (Android.Manifest.Permission.WriteExternalStorage)]

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

@ -46,7 +46,7 @@
<Private>True</Private>
</Reference>
<Reference Include="SkiaSharp, Version=1.49.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SkiaSharp.1.49.3.0-beta\lib\MonoAndroid\SkiaSharp.dll</HintPath>
<HintPath>..\packages\SkiaSharp.1.49.4.0-beta\lib\MonoAndroid\SkiaSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />

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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SkiaSharp" version="1.49.3.0-beta" targetFramework="monoandroid60" />
<package id="SkiaSharp" version="1.49.4.0-beta" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" />

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

@ -7,6 +7,7 @@ namespace Skia.Forms.Demo
public interface ISkiaViewController : IViewController
{
void SendDraw (SKCanvas canvas);
void SendTap ();
}
}

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

@ -28,7 +28,7 @@ namespace Skia.Forms.Demo
listView.SelectedItem = null;
navPage.PushAsync (new ContentPage {
Content = new SkiaView (SkiaSharp.Demos.MethodForSample (e.SelectedItem.ToString ())),
Content = new SkiaView (SkiaSharp.Demos.GetSample (e.SelectedItem.ToString ())),
});
};
}

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

@ -33,7 +33,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="SkiaSharp, Version=1.49.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\SkiaSharp.1.49.3.0-beta\lib\portable-net45+xamarinmac+xamarinios+monotouch+monoandroid+win8+wpa81+wp8+xamarin.watchos+xamarin.tvos\SkiaSharp.dll</HintPath>
<HintPath>packages\SkiaSharp.1.49.4.0-beta\lib\portable-net45+xamarinmac+xamarinios+monotouch+monoandroid+win8+wpa81+wp8+xamarin.watchos+xamarin.tvos\SkiaSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">

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

@ -6,11 +6,11 @@ namespace Skia.Forms.Demo
{
public class SkiaView : View, ISkiaViewController
{
Action <SKCanvas, int, int> onDrawCallback;
Demos.Sample sample;
public SkiaView (Action <SKCanvas, int, int> onDrawCallback)
public SkiaView (Demos.Sample sample)
{
this.onDrawCallback = onDrawCallback;
this.sample = sample;
}
void ISkiaViewController.SendDraw (SKCanvas canvas)
@ -18,9 +18,14 @@ namespace Skia.Forms.Demo
Draw (canvas);
}
void ISkiaViewController.SendTap ()
{
sample?.TapMethod?.Invoke ();
}
protected virtual void Draw (SKCanvas canvas)
{
onDrawCallback (canvas, (int)Width, (int)Height);
sample?.Method?.Invoke (canvas, (int)Width, (int)Height);
}
}
}

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

@ -1,5 +1,7 @@
using System.IO;
using System;
using System.IO;
using Windows.ApplicationModel;
using Windows.Storage;
namespace Skia.Forms.Demo.UWP
{
@ -10,6 +12,13 @@ namespace Skia.Forms.Demo.UWP
// set up resource paths
string fontName = "content-font.ttf";
SkiaSharp.Demos.CustomFontPath = Path.Combine (Package.Current.InstalledLocation.Path, "Assets", fontName);
SkiaSharp.Demos.WorkingDirectory = ApplicationData.Current.LocalFolder.Path;
SkiaSharp.Demos.OpenFileDelegate =
async name =>
{
var file = await ApplicationData.Current.LocalFolder.GetFileAsync(name);
await Windows.System.Launcher.LaunchFileAsync(file);
};
this.InitializeComponent ();

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

@ -5,6 +5,7 @@ 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;
@ -19,6 +20,7 @@ namespace Skia.Forms.Demo.UWP
{
this.skiaView = skiaView;
this.SizeChanged += OnSizeChanged;
this.Tapped += OnTapped;
}
private void UpdateBitmap()
@ -71,5 +73,10 @@ namespace Skia.Forms.Demo.UWP
{
UpdateBitmap ();
}
private void OnTapped(object sender, TappedRoutedEventArgs e)
{
skiaView.SendTap();
}
}
}

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

@ -4,7 +4,7 @@
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
</PropertyGroup>
<ImportGroup>
<Import Project="$(NuGetPackageRoot)\SkiaSharp\1.49.3-beta\build\uap10.0\SkiaSharp.targets" Condition="Exists('$(NuGetPackageRoot)\SkiaSharp\1.49.3-beta\build\uap10.0\SkiaSharp.targets')" />
<Import Project="$(NuGetPackageRoot)\SkiaSharp\1.49.4-beta\build\uap10.0\SkiaSharp.targets" Condition="Exists('$(NuGetPackageRoot)\SkiaSharp\1.49.4-beta\build\uap10.0\SkiaSharp.targets')" />
<Import Project="$(NuGetPackageRoot)\Xamarin.Forms\2.3.0.38-pre2\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('$(NuGetPackageRoot)\Xamarin.Forms\2.3.0.38-pre2\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
</ImportGroup>
</Project>

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

@ -1,7 +1,7 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"SkiaSharp": "1.49.3-beta",
"SkiaSharp": "1.49.4-beta",
"Xamarin.Forms": "2.3.0.38-pre2"
},
"frameworks": {

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

@ -16,6 +16,23 @@ namespace Skia.Forms.Demo.iOS
// set up resource paths
string fontName = "content-font.ttf";
SkiaSharp.Demos.CustomFontPath = NSBundle.MainBundle.PathForResource (Path.GetFileNameWithoutExtension (fontName), Path.GetExtension (fontName));
var dir = Path.Combine (Path.GetTempPath (), "SkiaSharp.Demos", Path.GetRandomFileName ());
if (!Directory.Exists (dir))
{
Directory.CreateDirectory (dir);
}
SkiaSharp.Demos.WorkingDirectory = dir;
SkiaSharp.Demos.OpenFileDelegate = path =>
{
var nav = Xamarin.Forms.Platform.iOS.Platform.GetRenderer (Xamarin.Forms.Application.Current.MainPage) as UINavigationController;
var vc = nav.VisibleViewController;
var resourceToOpen = NSUrl.FromFilename (Path.Combine (dir, path));
var controller = UIDocumentInteractionController.FromUrl (resourceToOpen);
if (!controller.PresentOpenInMenu (vc.View.Bounds, vc.View, true))
{
new UIAlertView ("SkiaSharp", "Unable to open file.", null, "OK").Show ();
}
};
global::Xamarin.Forms.Forms.Init ();

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

@ -14,6 +14,8 @@ namespace Skia.Forms.Demo.iOS
public NativeSkiaView (SkiaView skiaView)
{
this.skiaView = skiaView;
AddGestureRecognizer (new UITapGestureRecognizer (OnTapped));
}
public override void Draw (CGRect rect)
@ -49,6 +51,11 @@ namespace Skia.Forms.Demo.iOS
}
}
void OnTapped ()
{
skiaView.SendTap ();
}
public override void LayoutSubviews ()
{
base.LayoutSubviews ();

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

@ -79,7 +79,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="SkiaSharp, Version=1.49.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SkiaSharp.1.49.3.0-beta\lib\XamariniOS\SkiaSharp.dll</HintPath>
<HintPath>..\packages\SkiaSharp.1.49.4.0-beta\lib\XamariniOS\SkiaSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />

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

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SkiaSharp" version="1.49.3.0-beta" targetFramework="xamarinios10" />
<package id="SkiaSharp" version="1.49.4.0-beta" targetFramework="xamarinios10" />
<package id="Xamarin.Forms" version="2.3.0.38-pre2" targetFramework="xamarinios10" />
</packages>

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

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SkiaSharp" version="1.49.3.0-beta" targetFramework="portable45-net45+win8+wp8" />
<package id="SkiaSharp" version="1.49.4.0-beta" targetFramework="portable45-net45+win8+wp8" />
<package id="Xamarin.Forms" version="2.3.0.38-pre2" targetFramework="portable45-net45+win8+wp8" />
</packages>

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

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="14F27" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9060"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
</dependencies>
<scenes>
<!--Application-->
@ -80,12 +81,15 @@
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" customClass="ViewController" sceneMemberID="viewController">
<view key="view" id="m2S-Jp-Qdl" customClass="SkiaView">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<customView key="view" id="QUA-QF-Q3f">
<rect key="frame" x="0.0" y="0.0" width="450" height="300"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<view translatesAutoresizingMaskIntoConstraints="NO" id="m2S-Jp-Qdl" customClass="SkiaView">
<rect key="frame" x="0.0" y="0.0" width="450" height="300"/>
</view>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="mnJ-8z-WRI">
<rect key="frame" x="258" y="17" width="205" height="26"/>
<rect key="frame" x="228" y="17" width="205" height="26"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="3Ya-mE-NFc"/>
<constraint firstAttribute="height" constant="21" id="PW1-2o-QII"/>
@ -101,10 +105,14 @@
</popUpButton>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="mnJ-8z-WRI" secondAttribute="trailing" constant="20" id="FIZ-dO-bNg"/>
<constraint firstAttribute="bottom" secondItem="mnJ-8z-WRI" secondAttribute="bottom" constant="20" id="qdr-cp-9Is"/>
<constraint firstAttribute="bottom" secondItem="mnJ-8z-WRI" secondAttribute="bottom" constant="20" id="A3L-Bb-rlF"/>
<constraint firstAttribute="trailing" secondItem="mnJ-8z-WRI" secondAttribute="trailing" constant="20" id="DYI-UX-Zkb"/>
<constraint firstAttribute="bottom" secondItem="m2S-Jp-Qdl" secondAttribute="bottom" id="Gw9-r7-0Df"/>
<constraint firstItem="m2S-Jp-Qdl" firstAttribute="top" secondItem="QUA-QF-Q3f" secondAttribute="top" id="Uut-tC-oBU"/>
<constraint firstItem="m2S-Jp-Qdl" firstAttribute="leading" secondItem="QUA-QF-Q3f" secondAttribute="leading" id="Xcr-Wg-5ia"/>
<constraint firstAttribute="trailing" secondItem="m2S-Jp-Qdl" secondAttribute="trailing" id="rZp-9d-Lpb"/>
</constraints>
</view>
</customView>
<connections>
<outlet property="PopUpButton" destination="mnJ-8z-WRI" id="mEQ-lK-fod"/>
<outlet property="SkiaView" destination="m2S-Jp-Qdl" id="8ta-WW-AHG"/>

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

@ -10,17 +10,18 @@ namespace Skia.OSX.Demo
{
public partial class SkiaView : NSView
{
Action <SKCanvas, int, int> onDrawCallback;
Demos.Sample sample;
public SkiaView (IntPtr handle) : base (handle)
{
AddGestureRecognizer (new NSClickGestureRecognizer (OnClicked));
}
public override void DrawRect (CoreGraphics.CGRect dirtyRect)
{
base.DrawRect (dirtyRect);
if (onDrawCallback == null)
if (sample == null)
return;
// Just not that sharp using the scale pixel scale only
@ -37,7 +38,7 @@ namespace Skia.OSX.Demo
skcanvas.Scale (screenScale, screenScale);
onDrawCallback (skcanvas, (int)Bounds.Width, (int)Bounds.Height);
Sample?.Method (skcanvas, (int)Bounds.Width, (int)Bounds.Height);
}
using (var colorSpace = CoreGraphics.CGColorSpace.CreateDeviceRGB ()) {
@ -56,12 +57,17 @@ namespace Skia.OSX.Demo
}
}
public Action<SKCanvas, int, int> OnDrawCallback {
void OnClicked ()
{
Sample?.TapMethod?.Invoke ();
}
public Demos.Sample Sample {
get {
return onDrawCallback;
return sample;
}
set {
onDrawCallback = value;
sample = value;
SetNeedsDisplayInRect (Bounds);
}
}

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

@ -19,15 +19,28 @@ namespace Skia.OSX.Demo
// set up resource paths
string fontName = "content-font.ttf";
SkiaSharp.Demos.CustomFontPath = NSBundle.MainBundle.PathForResource (Path.GetFileNameWithoutExtension (fontName), Path.GetExtension (fontName));
var dir = Path.Combine (Path.GetTempPath (), "SkiaSharp.Demos", Path.GetRandomFileName ());
if (!Directory.Exists (dir))
{
Directory.CreateDirectory (dir);
}
SkiaSharp.Demos.WorkingDirectory = dir;
SkiaSharp.Demos.OpenFileDelegate = path =>
{
if (!NSWorkspace.SharedWorkspace.OpenFile (Path.Combine (dir, path)))
{
NSAlert.WithMessage ("SkiaSharp", "OK", null, null, "Unable to open file.").RunSheetModal (View.Window);
}
};
PopUpButton.AddItems (SkiaSharp.Demos.SamplesForPlatform (SkiaSharp.Demos.Platform.OSX));
PopUpButton.SelectItem (0);
SkiaView.OnDrawCallback = SkiaSharp.Demos.MethodForSample (PopUpButton.SelectedItem.Title);
SkiaView.Sample = SkiaSharp.Demos.GetSample (PopUpButton.SelectedItem.Title);
}
partial void PopUpButtonAction (NSObject sender)
{
SkiaView.OnDrawCallback = SkiaSharp.Demos.MethodForSample (PopUpButton.SelectedItem.Title);
SkiaView.Sample = SkiaSharp.Demos.GetSample (PopUpButton.SelectedItem.Title);
}
public override NSObject RepresentedObject {

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

@ -29,6 +29,13 @@ namespace Skia.UWP.Demo
string fontName = "content-font.ttf";
var install = Windows.ApplicationModel.Package.Current.InstalledLocation;
SkiaSharp.Demos.CustomFontPath = Path.Combine(install.Path, fontName);
SkiaSharp.Demos.WorkingDirectory = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
SkiaSharp.Demos.OpenFileDelegate =
async name =>
{
var file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(name);
await Windows.System.Launcher.LaunchFileAsync(file);
};
var items = SkiaSharp.Demos.SamplesForPlatform(SkiaSharp.Demos.Platform.UWP);
foreach (var item in items)
@ -36,9 +43,9 @@ namespace Skia.UWP.Demo
comboBox.Items.Add(item);
}
comboBox.SelectionChanged += (sender, e) =>
comboBox.SelectionChanged += async (sender, e) =>
{
skiaView.OnDrawCallback = SkiaSharp.Demos.MethodForSample((string)comboBox.SelectedItem);
skiaView.Sample = SkiaSharp.Demos.GetSample((string)comboBox.SelectedItem);
};
comboBox.SelectedIndex = 0;

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

@ -4,6 +4,6 @@
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
</PropertyGroup>
<ImportGroup>
<Import Project="$(NuGetPackageRoot)\SkiaSharp\1.49.3-beta\build\uap10.0\SkiaSharp.targets" Condition="Exists('$(NuGetPackageRoot)\SkiaSharp\1.49.3-beta\build\uap10.0\SkiaSharp.targets')" />
<Import Project="$(NuGetPackageRoot)\SkiaSharp\1.49.4-beta\build\uap10.0\SkiaSharp.targets" Condition="Exists('$(NuGetPackageRoot)\SkiaSharp\1.49.4-beta\build\uap10.0\SkiaSharp.targets')" />
</ImportGroup>
</Project>

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

@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
@ -14,18 +15,16 @@ namespace Skia.WindowsDesktop.Demo
{
public partial class SkiaView : Canvas
{
private Action<SKCanvas, int, int> onDrawCallback;
private Demos.Sample sample;
public SkiaView()
{
SizeChanged += OnSizeChanged;
Tapped += OnTapped;
}
private void UpdateBitmap()
{
if (onDrawCallback == null)
return;
var resolutionScale = DisplayInformation.GetForCurrentView().ResolutionScale;
var screenScale = (float)resolutionScale / 100.0f;
var width = (int)(ActualWidth * screenScale);
@ -44,7 +43,7 @@ namespace Skia.WindowsDesktop.Demo
skcanvas.Scale(screenScale, screenScale);
onDrawCallback(skcanvas, (int)ActualWidth, (int)ActualHeight);
sample?.Method(skcanvas, (int)ActualWidth, (int)ActualHeight);
}
var pixels = new byte[width * height * 4];
@ -81,12 +80,17 @@ namespace Skia.WindowsDesktop.Demo
UpdateBitmap();
}
public Action<SKCanvas, int, int> OnDrawCallback
private void OnTapped(object sender, TappedRoutedEventArgs e)
{
get { return onDrawCallback; }
sample?.TapMethod?.Invoke();
}
public Demos.Sample Sample
{
get { return sample; }
set
{
onDrawCallback = value;
sample = value;
UpdateBitmap();
}
}

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

@ -4,7 +4,7 @@
"Microsoft.ApplicationInsights.PersistenceChannel": "1.0.0",
"Microsoft.ApplicationInsights.WindowsApps": "1.0.0",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0",
"SkiaSharp": "1.49.3-beta"
"SkiaSharp": "1.49.4-beta"
},
"frameworks": {
"uap10.0": {}

1
samples/Skia.WindowsDesktop.Demo/Form1.Designer.cs сгенерированный
Просмотреть файл

@ -48,7 +48,6 @@
this.skiaView.Dock = System.Windows.Forms.DockStyle.Fill;
this.skiaView.Location = new System.Drawing.Point(0, 0);
this.skiaView.Name = "skiaView";
this.skiaView.OnDrawCallback = null;
this.skiaView.Size = new System.Drawing.Size(778, 544);
this.skiaView.TabIndex = 1;
this.skiaView.Text = "skiaView";

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

@ -14,7 +14,17 @@ namespace Skia.WindowsDesktop.Demo
private void Form1_Load(object sender, EventArgs e)
{
string fontName = "content-font.ttf";
SkiaSharp.Demos.CustomFontPath = Path.Combine(typeof(Form1).Assembly.Location, "Content", fontName);
var dir = Path.Combine(Path.GetTempPath(), "SkiaSharp.Demos", Path.GetRandomFileName());
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
SkiaSharp.Demos.CustomFontPath = Path.Combine(Path.GetDirectoryName (typeof(Form1).Assembly.Location), "Content", fontName);
SkiaSharp.Demos.WorkingDirectory = dir;
SkiaSharp.Demos.OpenFileDelegate = path =>
{
System.Diagnostics.Process.Start(Path.Combine(dir, path));
};
comboBox.Items.AddRange(SkiaSharp.Demos.SamplesForPlatform(SkiaSharp.Demos.Platform.WindowsDesktop));
comboBox.SelectedIndex = 0;
@ -22,7 +32,7 @@ namespace Skia.WindowsDesktop.Demo
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
skiaView.OnDrawCallback = SkiaSharp.Demos.MethodForSample((string)comboBox.SelectedItem);
skiaView.Sample = SkiaSharp.Demos.GetSample((string)comboBox.SelectedItem);
}
}
}

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

@ -87,7 +87,7 @@
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="SkiaSharp, Version=1.49.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\SkiaSharp.1.49.3.0-beta\lib\net45\SkiaSharp.dll</HintPath>
<HintPath>packages\SkiaSharp.1.49.4.0-beta\lib\net45\SkiaSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
@ -133,11 +133,11 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages\SkiaSharp.1.49.3.0-beta\build\net45\SkiaSharp.targets" Condition="Exists('packages\SkiaSharp.1.49.3.0-beta\build\net45\SkiaSharp.targets')" />
<Import Project="packages\SkiaSharp.1.49.4.0-beta\build\net45\SkiaSharp.targets" Condition="Exists('packages\SkiaSharp.1.49.4.0-beta\build\net45\SkiaSharp.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\SkiaSharp.1.49.3.0-beta\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\SkiaSharp.1.49.3.0-beta\build\net45\SkiaSharp.targets'))" />
<Error Condition="!Exists('packages\SkiaSharp.1.49.4.0-beta\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\SkiaSharp.1.49.4.0-beta\build\net45\SkiaSharp.targets'))" />
</Target>
</Project>

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

@ -9,7 +9,7 @@ namespace Skia.WindowsDesktop.Demo
{
public partial class SkiaView : Control
{
private Action<SKCanvas, int, int> onDrawCallback;
private Demos.Sample sample;
public SkiaView()
{
@ -20,7 +20,7 @@ namespace Skia.WindowsDesktop.Demo
{
base.OnPaint(e);
if (onDrawCallback == null)
if (sample == null)
return;
var width = Width;
@ -32,7 +32,7 @@ namespace Skia.WindowsDesktop.Demo
using (var surface = SKSurface.Create(width, height, SKColorType.N_32, SKAlphaType.Premul, data.Scan0, width * 4))
{
var skcanvas = surface.Canvas;
onDrawCallback(skcanvas, width, height);
sample.Method(skcanvas, width, height);
}
bitmap.UnlockBits(data);
@ -46,12 +46,18 @@ namespace Skia.WindowsDesktop.Demo
Invalidate();
}
public Action<SKCanvas, int, int> OnDrawCallback
protected override void OnMouseClick(MouseEventArgs e)
{
get { return onDrawCallback; }
base.OnMouseClick(e);
sample?.TapMethod?.Invoke();
}
public Demos.Sample Sample
{
get { return sample; }
set
{
onDrawCallback = value;
sample = value;
Invalidate();
}
}

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

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SkiaSharp" version="1.49.3.0-beta" targetFramework="net45" />
<package id="SkiaSharp" version="1.49.4.0-beta" targetFramework="net45" />
</packages>