Merge remote-tracking branch 'refs/remotes/aosoft/master'
This commit is contained in:
Коммит
ed0606e830
38
LICENSE
38
LICENSE
|
@ -1,3 +1,29 @@
|
|||
Xamarin.Forms for Windows Forms
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Yasuhiro Taniuchi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
--------
|
||||
Xamarin SDK
|
||||
|
||||
The MIT License (MIT)
|
||||
|
@ -23,3 +49,15 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
--------
|
||||
SkiaSharp
|
||||
|
||||
Copyright (c) 2015-2016 Xamarin, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
Xamarin.Forms.WinForms
|
||||
====
|
||||
|
||||
Copyright (c) .NET Foundation Contributors / TAN-Y
|
||||
Copyright (c) Yasuhiro Taniuchi
|
||||
Copyright (c) .NET Foundation Contributors
|
||||
Copyright (c) 2015-2016 Xamarin, Inc.
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#if false
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
|
||||
// アセンブリに関連付けられている情報を変更するには、
|
||||
// これらの属性値を変更してください。
|
||||
[assembly: AssemblyTitle("SkiaSharp.Views.Forms.WinForms")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("SkiaSharp.Views.Forms.WinForms")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから
|
||||
// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、
|
||||
// その型の ComVisible 属性を true に設定してください。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります
|
||||
[assembly: Guid("dc2d61aa-3749-485b-a6bb-343e738211a8")]
|
||||
|
||||
// アセンブリのバージョン情報は次の 4 つの値で構成されています:
|
||||
//
|
||||
// メジャー バージョン
|
||||
// マイナー バージョン
|
||||
// ビルド番号
|
||||
// Revision
|
||||
//
|
||||
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
|
||||
// 以下のように '*' を使用します:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.0.0.0")]
|
||||
#endif
|
|
@ -0,0 +1,14 @@
|
|||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.WinForms;
|
||||
|
||||
using SKFormsView = SkiaSharp.Views.Forms.SKCanvasView;
|
||||
using SKNativeView = SkiaSharp.Views.Desktop.SKControl;
|
||||
|
||||
[assembly: ExportRenderer(typeof(SKFormsView), typeof(SkiaSharp.Views.Forms.SKCanvasViewRenderer))]
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
public class SKCanvasViewRenderer : SKCanvasViewRendererBase<SKFormsView, SKNativeView>
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.WinForms;
|
||||
|
||||
using SKFormsView = SkiaSharp.Views.Forms.SKGLView;
|
||||
using SKNativeView = SkiaSharp.Views.Desktop.SKGLControl;
|
||||
|
||||
[assembly: ExportRenderer(typeof(SKFormsView), typeof(SkiaSharp.Views.Forms.SKGLViewRenderer))]
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
public class SKGLViewRenderer : SKGLViewRendererBase<SKFormsView, SKNativeView>
|
||||
{
|
||||
protected override void SetupRenderLoop(bool oneShot)
|
||||
{
|
||||
if (oneShot)
|
||||
{
|
||||
Control.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
internal class SKTouchHandler
|
||||
{
|
||||
private Action<SKTouchEventArgs> onTouchAction;
|
||||
private Func<float, float> scalePixels;
|
||||
|
||||
public SKTouchHandler(Action<SKTouchEventArgs> onTouchAction, Func<float, float> scalePixels)
|
||||
{
|
||||
this.onTouchAction = onTouchAction;
|
||||
this.scalePixels = scalePixels;
|
||||
}
|
||||
|
||||
public void SetEnabled(Control view, bool enableTouchEvents)
|
||||
{
|
||||
if (view != null)
|
||||
{
|
||||
//view.PointerEntered -= OnPointerEntered;
|
||||
//view.PointerExited -= OnPointerExited;
|
||||
view.MouseDown -= OnPointerPressed;
|
||||
view.MouseMove -= OnPointerMoved;
|
||||
view.MouseUp -= OnPointerReleased;
|
||||
//view.PointerCanceled -= OnPointerCancelled;
|
||||
if (enableTouchEvents)
|
||||
{
|
||||
//view.PointerEntered += OnPointerEntered;
|
||||
//view.PointerExited += OnPointerExited;
|
||||
view.MouseDown += OnPointerPressed;
|
||||
view.MouseMove += OnPointerMoved;
|
||||
view.MouseUp += OnPointerReleased;
|
||||
//view.PointerCanceled += OnPointerCancelled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Detach(Control view)
|
||||
{
|
||||
// clean the view
|
||||
SetEnabled(view, false);
|
||||
|
||||
// remove references
|
||||
onTouchAction = null;
|
||||
scalePixels = null;
|
||||
}
|
||||
|
||||
private void OnPointerEntered(object sender, MouseEventArgs args)
|
||||
{
|
||||
CommonHandler(sender, SKTouchAction.Entered, args);
|
||||
}
|
||||
|
||||
private void OnPointerExited(object sender, MouseEventArgs args)
|
||||
{
|
||||
CommonHandler(sender, SKTouchAction.Exited, args);
|
||||
}
|
||||
|
||||
private void OnPointerPressed(object sender, MouseEventArgs args)
|
||||
{
|
||||
CommonHandler(sender, SKTouchAction.Pressed, args);
|
||||
|
||||
var view = sender as Control;
|
||||
//view.CapturePointer(args.Pointer);
|
||||
}
|
||||
|
||||
private void OnPointerMoved(object sender, MouseEventArgs args)
|
||||
{
|
||||
CommonHandler(sender, SKTouchAction.Moved, args);
|
||||
}
|
||||
|
||||
private void OnPointerReleased(object sender, MouseEventArgs args)
|
||||
{
|
||||
CommonHandler(sender, SKTouchAction.Released, args);
|
||||
}
|
||||
|
||||
private void OnPointerCancelled(object sender, MouseEventArgs args)
|
||||
{
|
||||
CommonHandler(sender, SKTouchAction.Cancelled, args);
|
||||
}
|
||||
|
||||
private bool CommonHandler(object sender, SKTouchAction touchActionType, MouseEventArgs evt)
|
||||
{
|
||||
if (onTouchAction == null || scalePixels == null)
|
||||
return false;
|
||||
|
||||
var view = sender as Control;
|
||||
|
||||
var id = 0L;// evt.Pointer.PointerId;
|
||||
|
||||
var windowsPoint = evt.Location;
|
||||
var skPoint = new SKPoint(scalePixels((float)windowsPoint.X), scalePixels((float)windowsPoint.Y));
|
||||
|
||||
var mouse = GetMouseButton(evt.Button);
|
||||
var device = SKTouchDeviceType.Mouse;// GetTouchDevice(evt);
|
||||
|
||||
var args = new SKTouchEventArgs(id, touchActionType, mouse, device, skPoint, false/*evt.Pointer.IsInContact*/);
|
||||
onTouchAction(args);
|
||||
return args.Handled;
|
||||
}
|
||||
/*
|
||||
private static SKTouchDeviceType GetTouchDevice(PointerRoutedEventArgs evt)
|
||||
{
|
||||
var device = SKTouchDeviceType.Touch;
|
||||
switch (evt.Pointer.PointerDeviceType)
|
||||
{
|
||||
case PointerDeviceType.Pen:
|
||||
device = SKTouchDeviceType.Pen;
|
||||
break;
|
||||
case PointerDeviceType.Mouse:
|
||||
device = SKTouchDeviceType.Mouse;
|
||||
break;
|
||||
case PointerDeviceType.Touch:
|
||||
device = SKTouchDeviceType.Touch;
|
||||
break;
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
*/
|
||||
private static SKMouseButton GetMouseButton(MouseButtons btns)
|
||||
{
|
||||
var mouse = SKMouseButton.Unknown;
|
||||
|
||||
// this is mainly for touch
|
||||
if (btns.HasFlag(MouseButtons.Left))
|
||||
{
|
||||
mouse = SKMouseButton.Left;
|
||||
}
|
||||
else if (btns.HasFlag(MouseButtons.Middle))
|
||||
{
|
||||
mouse = SKMouseButton.Middle;
|
||||
}
|
||||
else if (btns.HasFlag(MouseButtons.Right))
|
||||
{
|
||||
mouse = SKMouseButton.Right;
|
||||
}
|
||||
|
||||
return mouse;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.props" Condition="Exists('..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{DC2D61AA-3749-485B-A6BB-343E738211A8}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SkiaSharp.Views.Forms.WinForms</RootNamespace>
|
||||
<AssemblyName>SkiaSharp.Views.Forms</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenTK.2.0.0\lib\net20\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OpenTK.GLControl, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenTK.GLControl.1.1.2349.61993\lib\NET40\OpenTK.GLControl.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp, Version=1.59.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.1.59.3\lib\net45\SkiaSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp.Views.Desktop, Version=1.59.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.Views.1.59.3\lib\net45\SkiaSharp.Views.Desktop.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp.Views.WPF, Version=1.59.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.Views.1.59.3\lib\net45\SkiaSharp.Views.WPF.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.5.0.91635\lib\netstandard1.0\Xamarin.Forms.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.5.0.91635\lib\netstandard1.0\Xamarin.Forms.Platform.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Xaml, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Xamarin.Forms.2.5.0.91635\lib\netstandard1.0\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SKCanvasViewRenderer.cs" />
|
||||
<Compile Include="SKGLViewRenderer.cs" />
|
||||
<Compile Include="SKTouchHandler.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Xamarin.Forms.Platform.WinForms\Xamarin.Forms.Platform.WinForms.csproj">
|
||||
<Project>{563d7c2e-14e2-47ec-95e4-4ea0bba75c18}</Project>
|
||||
<Name>Xamarin.Forms.Platform.WinForms</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\SkiaSharp\source\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Native.Shared\SkiaSharp.Views.Forms.Native.Shared.projitems" Label="Shared" />
|
||||
<Import Project="..\SkiaSharp\source\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Shared\SkiaSharp.Views.Forms.Shared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>このプロジェクトは、このコンピューター上にない NuGet パッケージを参照しています。それらのパッケージをダウンロードするには、[NuGet パッケージの復元] を使用します。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。見つからないファイルは {0} です。</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\SkiaSharp.1.59.3\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.1.59.3\build\net45\SkiaSharp.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.targets')" />
|
||||
<Import Project="..\packages\SkiaSharp.1.59.3\build\net45\SkiaSharp.targets" Condition="Exists('..\packages\SkiaSharp.1.59.3\build\net45\SkiaSharp.targets')" />
|
||||
</Project>
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="OpenTK" publicKeyToken="bad199fe84eb3df4" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="OpenTK" version="2.0.0" targetFramework="net452" />
|
||||
<package id="OpenTK.GLControl" version="1.1.2349.61993" targetFramework="net452" />
|
||||
<package id="SkiaSharp" version="1.59.3" targetFramework="net461" />
|
||||
<package id="SkiaSharp.Views" version="1.59.3" targetFramework="net461" />
|
||||
<package id="Xamarin.Forms" version="2.5.0.91635" targetFramework="net461" />
|
||||
</packages>
|
|
@ -0,0 +1,182 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
using SKFormsView = SkiaSharp.Views.Forms.SKCanvasView;
|
||||
|
||||
#if __ANDROID__
|
||||
using Xamarin.Forms.Platform.Android;
|
||||
using SKNativeView = SkiaSharp.Views.Android.SKCanvasView;
|
||||
using SKNativePaintSurfaceEventArgs = SkiaSharp.Views.Android.SKPaintSurfaceEventArgs;
|
||||
#elif __IOS__
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
using SKNativeView = SkiaSharp.Views.iOS.SKCanvasView;
|
||||
using SKNativePaintSurfaceEventArgs = SkiaSharp.Views.iOS.SKPaintSurfaceEventArgs;
|
||||
#elif WINDOWS_UWP
|
||||
using Windows.Graphics.Display;
|
||||
using Xamarin.Forms.Platform.UWP;
|
||||
using SKNativeView = SkiaSharp.Views.UWP.SKXamlCanvas;
|
||||
using SKNativePaintSurfaceEventArgs = SkiaSharp.Views.UWP.SKPaintSurfaceEventArgs;
|
||||
#elif __MACOS__
|
||||
using Xamarin.Forms.Platform.MacOS;
|
||||
using SKNativeView = SkiaSharp.Views.Mac.SKCanvasView;
|
||||
using SKNativePaintSurfaceEventArgs = SkiaSharp.Views.Mac.SKPaintSurfaceEventArgs;
|
||||
#else
|
||||
using Xamarin.Forms.Platform.WinForms;
|
||||
using SKNativeView = SkiaSharp.Views.Desktop.SKControl;
|
||||
using SKNativePaintSurfaceEventArgs = SkiaSharp.Views.Desktop.SKPaintSurfaceEventArgs;
|
||||
#endif
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
public abstract class SKCanvasViewRendererBase<TFormsView, TNativeView> : ViewRenderer<TFormsView, TNativeView>
|
||||
where TFormsView : SKFormsView
|
||||
where TNativeView : SKNativeView
|
||||
{
|
||||
private readonly SKTouchHandler touchHandler;
|
||||
|
||||
public SKCanvasViewRendererBase()
|
||||
{
|
||||
#if __ANDROID__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
coord => Element.IgnorePixelScaling ? (float)Context.FromPixels(coord) : coord);
|
||||
#elif __IOS__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
coord => Element.IgnorePixelScaling ? coord : coord * Control.ContentScaleFactor);
|
||||
#elif __MACOS__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
coord => Element.IgnorePixelScaling ? coord : coord * Control.Window.BackingScaleFactor);
|
||||
#elif WINDOWS_UWP
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
coord => Element.IgnorePixelScaling ? coord : (float)(coord * Control.Dpi));
|
||||
#else
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
//coord => Element.IgnorePixelScaling ? coord : (float)(coord * Control.Dpi));
|
||||
coord => coord);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if __IOS__
|
||||
protected void SetDisablesUserInteraction(bool disablesUserInteraction)
|
||||
{
|
||||
touchHandler.DisablesUserInteraction = disablesUserInteraction;
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<TFormsView> e)
|
||||
{
|
||||
if (e.OldElement != null)
|
||||
{
|
||||
var oldController = (ISKCanvasViewController)e.OldElement;
|
||||
|
||||
// unsubscribe from events
|
||||
oldController.SurfaceInvalidated -= OnSurfaceInvalidated;
|
||||
oldController.GetCanvasSize -= OnGetCanvasSize;
|
||||
}
|
||||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
var newController = (ISKCanvasViewController)e.NewElement;
|
||||
|
||||
// create the native view
|
||||
if (Control == null)
|
||||
{
|
||||
var view = CreateNativeControl();
|
||||
view.PaintSurface += OnPaintSurface;
|
||||
SetNativeControl(view);
|
||||
}
|
||||
|
||||
// set the initial values
|
||||
touchHandler.SetEnabled(Control, e.NewElement.EnableTouchEvents);
|
||||
//Control.IgnorePixelScaling = e.NewElement.IgnorePixelScaling;
|
||||
|
||||
// subscribe to events from the user
|
||||
newController.SurfaceInvalidated += OnSurfaceInvalidated;
|
||||
newController.GetCanvasSize += OnGetCanvasSize;
|
||||
|
||||
// paint for the first time
|
||||
OnSurfaceInvalidated(newController, EventArgs.Empty);
|
||||
}
|
||||
|
||||
base.OnElementChanged(e);
|
||||
}
|
||||
|
||||
#if __ANDROID__
|
||||
protected override TNativeView CreateNativeControl()
|
||||
{
|
||||
return (TNativeView)Activator.CreateInstance(typeof(TNativeView), new[] { Context });
|
||||
}
|
||||
#else
|
||||
protected virtual TNativeView CreateNativeControl()
|
||||
{
|
||||
return (TNativeView)Activator.CreateInstance(typeof(TNativeView));
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
|
||||
/*if (e.PropertyName == SKFormsView.IgnorePixelScalingProperty.PropertyName)
|
||||
{
|
||||
Control.IgnorePixelScaling = Element.IgnorePixelScaling;
|
||||
}
|
||||
else*/ if (e.PropertyName == SKFormsView.EnableTouchEventsProperty.PropertyName)
|
||||
{
|
||||
touchHandler.SetEnabled(Control, Element.EnableTouchEvents);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
// detach all events before disposing
|
||||
var controller = (ISKCanvasViewController)Element;
|
||||
if (controller != null)
|
||||
{
|
||||
controller.SurfaceInvalidated -= OnSurfaceInvalidated;
|
||||
controller.GetCanvasSize -= OnGetCanvasSize;
|
||||
}
|
||||
|
||||
var control = Control;
|
||||
if (control != null)
|
||||
{
|
||||
control.PaintSurface -= OnPaintSurface;
|
||||
}
|
||||
|
||||
// detach, regardless of state
|
||||
touchHandler.Detach(control);
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void OnPaintSurface(object sender, SKNativePaintSurfaceEventArgs e)
|
||||
{
|
||||
var controller = Element as ISKCanvasViewController;
|
||||
|
||||
// the control is being repainted, let the user know
|
||||
controller?.OnPaintSurface(new SKPaintSurfaceEventArgs(e.Surface, e.Info));
|
||||
}
|
||||
|
||||
private void OnSurfaceInvalidated(object sender, EventArgs eventArgs)
|
||||
{
|
||||
// repaint the native control
|
||||
#if __IOS__
|
||||
Control.SetNeedsDisplay();
|
||||
#elif __MACOS__
|
||||
Control.NeedsDisplay = true;
|
||||
#else
|
||||
Control.Invalidate();
|
||||
#endif
|
||||
}
|
||||
|
||||
// the user asked for the size
|
||||
private void OnGetCanvasSize(object sender, GetPropertyValueEventArgs<SKSize> e)
|
||||
{
|
||||
e.Value = Control?.CanvasSize ?? SKSize.Empty;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,215 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using Xamarin.Forms;
|
||||
|
||||
using SKFormsView = SkiaSharp.Views.Forms.SKGLView;
|
||||
|
||||
#if __ANDROID__
|
||||
using Xamarin.Forms.Platform.Android;
|
||||
using SKNativeView = SkiaSharp.Views.Android.SKGLSurfaceView;
|
||||
using SKNativePaintGLSurfaceEventArgs = SkiaSharp.Views.Android.SKPaintGLSurfaceEventArgs;
|
||||
#elif __IOS__
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
using SKNativeView = SkiaSharp.Views.iOS.SKGLView;
|
||||
using SKNativePaintGLSurfaceEventArgs = SkiaSharp.Views.iOS.SKPaintGLSurfaceEventArgs;
|
||||
#elif WINDOWS_UWP
|
||||
using Xamarin.Forms.Platform.UWP;
|
||||
using SKNativeView = SkiaSharp.Views.UWP.SKSwapChainPanel;
|
||||
using SKNativePaintGLSurfaceEventArgs = SkiaSharp.Views.UWP.SKPaintGLSurfaceEventArgs;
|
||||
#elif __MACOS__
|
||||
using Xamarin.Forms.Platform.MacOS;
|
||||
using SKNativeView = SkiaSharp.Views.Mac.SKGLView;
|
||||
using SKNativePaintGLSurfaceEventArgs = SkiaSharp.Views.Mac.SKPaintGLSurfaceEventArgs;
|
||||
#else
|
||||
using Xamarin.Forms.Platform.WinForms;
|
||||
using SKNativeView = SkiaSharp.Views.Desktop.SKGLControl;
|
||||
using SKNativePaintGLSurfaceEventArgs = SkiaSharp.Views.Desktop.SKPaintGLSurfaceEventArgs;
|
||||
#endif
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
public abstract class SKGLViewRendererBase<TFormsView, TNativeView> : ViewRenderer<TFormsView, TNativeView>
|
||||
where TFormsView : SKFormsView
|
||||
where TNativeView : SKNativeView
|
||||
{
|
||||
private readonly SKTouchHandler touchHandler;
|
||||
|
||||
public SKGLViewRendererBase()
|
||||
{
|
||||
#if __ANDROID__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKGLViewController)Element).OnTouch(args),
|
||||
coord => coord);
|
||||
#elif __IOS__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKGLViewController)Element).OnTouch(args),
|
||||
coord => coord * Control.ContentScaleFactor);
|
||||
#elif __MACOS__
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKGLViewController)Element).OnTouch(args),
|
||||
coord => coord * Control.Window.BackingScaleFactor);
|
||||
#elif WINDOWS_UWP
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKGLViewController)Element).OnTouch(args),
|
||||
coord => (float)(coord * Control.ContentsScale));
|
||||
#else
|
||||
touchHandler = new SKTouchHandler(
|
||||
args => ((ISKCanvasViewController)Element).OnTouch(args),
|
||||
//coord => Element.IgnorePixelScaling ? coord : (float)(coord * Control.Dpi));
|
||||
coord => coord);
|
||||
#endif
|
||||
}
|
||||
|
||||
public GRContext GRContext => Control.GRContext;
|
||||
|
||||
#if __IOS__
|
||||
protected void SetDisablesUserInteraction(bool disablesUserInteraction)
|
||||
{
|
||||
touchHandler.DisablesUserInteraction = disablesUserInteraction;
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<TFormsView> e)
|
||||
{
|
||||
if (e.OldElement != null)
|
||||
{
|
||||
var oldController = (ISKGLViewController)e.OldElement;
|
||||
|
||||
// unsubscribe from events
|
||||
oldController.SurfaceInvalidated -= OnSurfaceInvalidated;
|
||||
oldController.GetCanvasSize -= OnGetCanvasSize;
|
||||
oldController.GetGRContext -= OnGetGRContext;
|
||||
}
|
||||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
var newController = (ISKGLViewController)e.NewElement;
|
||||
|
||||
// create the native view
|
||||
if (Control == null)
|
||||
{
|
||||
var view = CreateNativeControl();
|
||||
#if __ANDROID__
|
||||
view.SetRenderer(new Renderer(newController));
|
||||
#else
|
||||
view.PaintSurface += OnPaintSurface;
|
||||
#endif
|
||||
SetNativeControl(view);
|
||||
}
|
||||
|
||||
touchHandler.SetEnabled(Control, e.NewElement.EnableTouchEvents);
|
||||
|
||||
// subscribe to events from the user
|
||||
newController.SurfaceInvalidated += OnSurfaceInvalidated;
|
||||
newController.GetCanvasSize += OnGetCanvasSize;
|
||||
newController.GetGRContext += OnGetGRContext;
|
||||
|
||||
// start the rendering
|
||||
SetupRenderLoop(false);
|
||||
}
|
||||
|
||||
base.OnElementChanged(e);
|
||||
}
|
||||
|
||||
#if __ANDROID__
|
||||
protected override TNativeView CreateNativeControl()
|
||||
{
|
||||
return (TNativeView)Activator.CreateInstance(typeof(TNativeView), new[] { Context });
|
||||
}
|
||||
#else
|
||||
protected virtual TNativeView CreateNativeControl()
|
||||
{
|
||||
return (TNativeView)Activator.CreateInstance(typeof(TNativeView));
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
|
||||
// refresh the render loop
|
||||
if (e.PropertyName == SKFormsView.HasRenderLoopProperty.PropertyName)
|
||||
{
|
||||
SetupRenderLoop(false);
|
||||
}
|
||||
else if (e.PropertyName == SKFormsView.EnableTouchEventsProperty.PropertyName)
|
||||
{
|
||||
touchHandler.SetEnabled(Control, Element.EnableTouchEvents);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
// detach all events before disposing
|
||||
var controller = (ISKGLViewController)Element;
|
||||
if (controller != null)
|
||||
{
|
||||
controller.SurfaceInvalidated -= OnSurfaceInvalidated;
|
||||
}
|
||||
|
||||
var control = Control;
|
||||
if (control != null)
|
||||
{
|
||||
#if __ANDROID__
|
||||
control.SetRenderer(null);
|
||||
#else
|
||||
control.PaintSurface -= OnPaintSurface;
|
||||
#endif
|
||||
}
|
||||
|
||||
// detach, regardless of state
|
||||
touchHandler.Detach(control);
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
protected abstract void SetupRenderLoop(bool oneShot);
|
||||
|
||||
// the user asked to repaint
|
||||
private void OnSurfaceInvalidated(object sender, EventArgs eventArgs)
|
||||
{
|
||||
// if we aren't in a loop, then refresh once
|
||||
if (!Element.HasRenderLoop)
|
||||
{
|
||||
SetupRenderLoop(true);
|
||||
}
|
||||
}
|
||||
|
||||
// the user asked for the size
|
||||
private void OnGetCanvasSize(object sender, GetPropertyValueEventArgs<SKSize> e)
|
||||
{
|
||||
e.Value = Control?.CanvasSize ?? SKSize.Empty;
|
||||
}
|
||||
|
||||
// the user asked for the current GRContext
|
||||
private void OnGetGRContext(object sender, GetPropertyValueEventArgs<GRContext> e)
|
||||
{
|
||||
e.Value = Control?.GRContext;
|
||||
}
|
||||
|
||||
private void OnPaintSurface(object sender, SKNativePaintGLSurfaceEventArgs e)
|
||||
{
|
||||
var controller = Element as ISKGLViewController;
|
||||
|
||||
// the control is being repainted, let the user know
|
||||
controller?.OnPaintSurface(new SKPaintGLSurfaceEventArgs(e.Surface, e.RenderTarget));
|
||||
}
|
||||
|
||||
#if __ANDROID__
|
||||
private class Renderer : SKNativeView.ISKRenderer
|
||||
{
|
||||
private readonly ISKGLViewController controller;
|
||||
|
||||
public Renderer(ISKGLViewController controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public void OnDrawFrame(SKSurface surface, GRBackendRenderTargetDesc renderTarget)
|
||||
{
|
||||
controller.OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>cebd25fd-dd4f-4d5f-b809-d50d02176f41</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>SkiaSharp.Views.Forms.Native.Shared</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)SKCanvasViewRendererBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)SKGLViewRendererBase.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>cebd25fd-dd4f-4d5f-b809-d50d02176f41</ProjectGuid>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props')" />
|
||||
<PropertyGroup />
|
||||
<Import Project="SkiaSharp.Views.Forms.Native.Shared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets')" />
|
||||
</Project>
|
|
@ -0,0 +1,68 @@
|
|||
using Xamarin.Forms;
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static Point ToFormsPoint(this SKPointI point)
|
||||
{
|
||||
return new Point(point.X, point.Y);
|
||||
}
|
||||
|
||||
public static Point ToFormsPoint(this SKPoint point)
|
||||
{
|
||||
return new Point(point.X, point.Y);
|
||||
}
|
||||
|
||||
public static SKPoint ToSKPoint(this Point point)
|
||||
{
|
||||
return new SKPoint((float)point.X, (float)point.Y);
|
||||
}
|
||||
|
||||
// Xamarin.Forms.Point
|
||||
|
||||
public static Size ToFormsSize(this SKSizeI size)
|
||||
{
|
||||
return new Size(size.Width, size.Height);
|
||||
}
|
||||
|
||||
public static Size ToFormsSize(this SKSize size)
|
||||
{
|
||||
return new Size(size.Width, size.Height);
|
||||
}
|
||||
|
||||
public static SKSize ToSKSize(this Size size)
|
||||
{
|
||||
return new SKSize((float)size.Width, (float)size.Height);
|
||||
}
|
||||
|
||||
// Xamarin.Forms.Size
|
||||
|
||||
public static Rectangle ToFormsRect(this SKRectI rect)
|
||||
{
|
||||
return new Rectangle(rect.Left, rect.Top, rect.Width, rect.Height);
|
||||
}
|
||||
|
||||
public static Rectangle ToFormsRect(this SKRect rect)
|
||||
{
|
||||
return new Rectangle(rect.Left, rect.Top, rect.Width, rect.Height);
|
||||
}
|
||||
|
||||
public static SKRect ToSKRect(this Rectangle rect)
|
||||
{
|
||||
return new SKRect((float)rect.Left, (float)rect.Top, (float)rect.Right, (float)rect.Bottom);
|
||||
}
|
||||
|
||||
// Xamarin.Forms.Color
|
||||
|
||||
public static Color ToFormsColor(this SKColor color)
|
||||
{
|
||||
return new Color(color.Red / 255.0, color.Green / 255.0, color.Blue / 255.0, color.Alpha / 255.0);
|
||||
}
|
||||
|
||||
public static SKColor ToSKColor(this Color color)
|
||||
{
|
||||
return new SKColor((byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255), (byte)(color.A * 255));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by Cake.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyTitle("SkiaSharp.Views.Forms")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("SkiaSharp.Views.Forms")]
|
||||
[assembly: AssemblyVersion("1.59.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.59.3.0")]
|
||||
[assembly: AssemblyInformationalVersion("1.59.3.0-{GIT_SHA}")]
|
||||
[assembly: AssemblyCopyright("Xamarin Inc.")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
internal class GetPropertyValueEventArgs<T> : EventArgs
|
||||
{
|
||||
public T Value { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
using System;
|
||||
using Xamarin.Forms;
|
||||
|
||||
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), false);
|
||||
|
||||
public static readonly BindableProperty EnableTouchEventsProperty =
|
||||
BindableProperty.Create(nameof(EnableTouchEvents), typeof(bool), typeof(SKCanvasView), false);
|
||||
|
||||
// the user can subscribe to repaint
|
||||
public event EventHandler<SKPaintSurfaceEventArgs> PaintSurface;
|
||||
|
||||
// the user can subscribe to touch events
|
||||
public event EventHandler<SKTouchEventArgs> Touch;
|
||||
|
||||
// the native listens to this event
|
||||
private event EventHandler SurfaceInvalidated;
|
||||
private event EventHandler<GetPropertyValueEventArgs<SKSize>> GetCanvasSize;
|
||||
|
||||
// the user asks the for the size
|
||||
public SKSize CanvasSize
|
||||
{
|
||||
get
|
||||
{
|
||||
// send a mesage to the native view
|
||||
var args = new GetPropertyValueEventArgs<SKSize>();
|
||||
GetCanvasSize?.Invoke(this, args);
|
||||
return args.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IgnorePixelScaling
|
||||
{
|
||||
get { return (bool)GetValue(IgnorePixelScalingProperty); }
|
||||
set { SetValue(IgnorePixelScalingProperty, value); }
|
||||
}
|
||||
|
||||
public bool EnableTouchEvents
|
||||
{
|
||||
get { return (bool)GetValue(EnableTouchEventsProperty); }
|
||||
set { SetValue(EnableTouchEventsProperty, value); }
|
||||
}
|
||||
|
||||
// the user asks to repaint
|
||||
public void InvalidateSurface()
|
||||
{
|
||||
// send a mesage to the native view
|
||||
SurfaceInvalidated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
// the native view tells the user to repaint
|
||||
protected virtual void OnPaintSurface(SKPaintSurfaceEventArgs e)
|
||||
{
|
||||
PaintSurface?.Invoke(this, e);
|
||||
}
|
||||
|
||||
// the native view responds to a touch
|
||||
protected virtual void OnTouch(SKTouchEventArgs e)
|
||||
{
|
||||
Touch?.Invoke(this, e);
|
||||
}
|
||||
|
||||
// ISKViewController implementation
|
||||
|
||||
event EventHandler ISKCanvasViewController.SurfaceInvalidated
|
||||
{
|
||||
add { SurfaceInvalidated += value; }
|
||||
remove { SurfaceInvalidated -= value; }
|
||||
}
|
||||
|
||||
event EventHandler<GetPropertyValueEventArgs<SKSize>> ISKCanvasViewController.GetCanvasSize
|
||||
{
|
||||
add { GetCanvasSize += value; }
|
||||
remove { GetCanvasSize -= value; }
|
||||
}
|
||||
|
||||
void ISKCanvasViewController.OnPaintSurface(SKPaintSurfaceEventArgs e)
|
||||
{
|
||||
OnPaintSurface(e);
|
||||
}
|
||||
|
||||
void ISKCanvasViewController.OnTouch(SKTouchEventArgs e)
|
||||
{
|
||||
OnTouch(e);
|
||||
}
|
||||
|
||||
protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
|
||||
{
|
||||
return new SizeRequest(new Size(40.0, 40.0));
|
||||
}
|
||||
}
|
||||
|
||||
internal interface ISKCanvasViewController : IViewController
|
||||
{
|
||||
// the native listens to this event
|
||||
event EventHandler SurfaceInvalidated;
|
||||
event EventHandler<GetPropertyValueEventArgs<SKSize>> GetCanvasSize;
|
||||
|
||||
// the native view tells the user to repaint
|
||||
void OnPaintSurface(SKPaintSurfaceEventArgs e);
|
||||
|
||||
// the native view responds to a touch
|
||||
void OnTouch(SKTouchEventArgs e);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
using System;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
[RenderWith(typeof(SKGLViewRenderer))]
|
||||
public class SKGLView : View, ISKGLViewController
|
||||
{
|
||||
public static readonly BindableProperty HasRenderLoopProperty =
|
||||
BindableProperty.Create(nameof(HasRenderLoop), typeof(bool), typeof(SKGLView), false);
|
||||
|
||||
public static readonly BindableProperty EnableTouchEventsProperty =
|
||||
BindableProperty.Create(nameof(EnableTouchEvents), typeof(bool), typeof(SKGLView), false);
|
||||
|
||||
public bool HasRenderLoop
|
||||
{
|
||||
get { return (bool)GetValue(HasRenderLoopProperty); }
|
||||
set { SetValue(HasRenderLoopProperty, value); }
|
||||
}
|
||||
|
||||
public bool EnableTouchEvents
|
||||
{
|
||||
get { return (bool)GetValue(EnableTouchEventsProperty); }
|
||||
set { SetValue(EnableTouchEventsProperty, value); }
|
||||
}
|
||||
|
||||
// the user can subscribe to repaint
|
||||
public event EventHandler<SKPaintGLSurfaceEventArgs> PaintSurface;
|
||||
|
||||
// the user can subscribe to touch events
|
||||
public event EventHandler<SKTouchEventArgs> Touch;
|
||||
|
||||
// the native listens to this event
|
||||
private event EventHandler SurfaceInvalidated;
|
||||
private event EventHandler<GetPropertyValueEventArgs<SKSize>> GetCanvasSize;
|
||||
private event EventHandler<GetPropertyValueEventArgs<GRContext>> GetGRContext;
|
||||
|
||||
// the user asks the for the size
|
||||
public SKSize CanvasSize
|
||||
{
|
||||
get
|
||||
{
|
||||
// send a mesage to the native view
|
||||
var args = new GetPropertyValueEventArgs<SKSize>();
|
||||
GetCanvasSize?.Invoke(this, args);
|
||||
return args.Value;
|
||||
}
|
||||
}
|
||||
|
||||
// the user asks the for the current GRContext
|
||||
public GRContext GRContext
|
||||
{
|
||||
get
|
||||
{
|
||||
// send a mesage to the native view
|
||||
var args = new GetPropertyValueEventArgs<GRContext>();
|
||||
GetGRContext?.Invoke(this, args);
|
||||
return args.Value;
|
||||
}
|
||||
}
|
||||
|
||||
// the user asks to repaint
|
||||
public void InvalidateSurface()
|
||||
{
|
||||
// send a mesage to the native view
|
||||
SurfaceInvalidated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
// the native view tells the user to repaint
|
||||
protected virtual void OnPaintSurface(SKPaintGLSurfaceEventArgs e)
|
||||
{
|
||||
PaintSurface?.Invoke(this, e);
|
||||
}
|
||||
|
||||
// the native view responds to a touch
|
||||
protected virtual void OnTouch(SKTouchEventArgs e)
|
||||
{
|
||||
Touch?.Invoke(this, e);
|
||||
}
|
||||
|
||||
// ISKViewController implementation
|
||||
|
||||
event EventHandler ISKGLViewController.SurfaceInvalidated
|
||||
{
|
||||
add { SurfaceInvalidated += value; }
|
||||
remove { SurfaceInvalidated -= value; }
|
||||
}
|
||||
|
||||
event EventHandler<GetPropertyValueEventArgs<SKSize>> ISKGLViewController.GetCanvasSize
|
||||
{
|
||||
add { GetCanvasSize += value; }
|
||||
remove { GetCanvasSize -= value; }
|
||||
}
|
||||
|
||||
event EventHandler<GetPropertyValueEventArgs<GRContext>> ISKGLViewController.GetGRContext
|
||||
{
|
||||
add { GetGRContext += value; }
|
||||
remove { GetGRContext -= value; }
|
||||
}
|
||||
|
||||
void ISKGLViewController.OnPaintSurface(SKPaintGLSurfaceEventArgs e)
|
||||
{
|
||||
OnPaintSurface(e);
|
||||
}
|
||||
|
||||
void ISKGLViewController.OnTouch(SKTouchEventArgs e)
|
||||
{
|
||||
OnTouch(e);
|
||||
}
|
||||
|
||||
protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
|
||||
{
|
||||
return new SizeRequest(new Size(40.0, 40.0));
|
||||
}
|
||||
}
|
||||
|
||||
internal interface ISKGLViewController : IViewController
|
||||
{
|
||||
// the native listens to this event
|
||||
event EventHandler SurfaceInvalidated;
|
||||
event EventHandler<GetPropertyValueEventArgs<SKSize>> GetCanvasSize;
|
||||
event EventHandler<GetPropertyValueEventArgs<GRContext>> GetGRContext;
|
||||
|
||||
// the native view tells the user to repaint
|
||||
void OnPaintSurface(SKPaintGLSurfaceEventArgs e);
|
||||
|
||||
// the native view responds to a touch
|
||||
void OnTouch(SKTouchEventArgs e);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
public sealed class SKImageImageSource : ImageSource
|
||||
{
|
||||
public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(Image), typeof(SKImage), typeof(SKImageImageSource), default(SKImage));
|
||||
|
||||
public SKImage Image
|
||||
{
|
||||
get { return (SKImage)GetValue(ImageProperty); }
|
||||
set { SetValue(ImageProperty, value); }
|
||||
}
|
||||
|
||||
public override Task<bool> Cancel()
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
public static implicit operator SKImageImageSource(SKImage image)
|
||||
{
|
||||
return new SKImageImageSource
|
||||
{
|
||||
Image = image
|
||||
};
|
||||
}
|
||||
|
||||
public static implicit operator SKImage(SKImageImageSource source)
|
||||
{
|
||||
return source?.Image;
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
if (propertyName == ImageProperty.PropertyName)
|
||||
OnSourceChanged();
|
||||
base.OnPropertyChanged(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SKBitmapImageSource : ImageSource
|
||||
{
|
||||
public static readonly BindableProperty BitmapProperty = BindableProperty.Create(nameof(Bitmap), typeof(SKBitmap), typeof(SKBitmapImageSource), default(SKBitmap));
|
||||
|
||||
public SKBitmap Bitmap
|
||||
{
|
||||
get { return (SKBitmap)GetValue(BitmapProperty); }
|
||||
set { SetValue(BitmapProperty, value); }
|
||||
}
|
||||
|
||||
public override Task<bool> Cancel()
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
public static implicit operator SKBitmapImageSource(SKBitmap bitmap)
|
||||
{
|
||||
return new SKBitmapImageSource
|
||||
{
|
||||
Bitmap = bitmap
|
||||
};
|
||||
}
|
||||
|
||||
public static implicit operator SKBitmap(SKBitmapImageSource source)
|
||||
{
|
||||
return source?.Bitmap;
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
if (propertyName == BitmapProperty.PropertyName)
|
||||
OnSourceChanged();
|
||||
base.OnPropertyChanged(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SKPixmapImageSource : ImageSource
|
||||
{
|
||||
public static readonly BindableProperty PixmapProperty = BindableProperty.Create(nameof(Pixmap), typeof(SKPixmap), typeof(SKPixmapImageSource), default(SKPixmap));
|
||||
|
||||
public SKPixmap Pixmap
|
||||
{
|
||||
get { return (SKPixmap)GetValue(PixmapProperty); }
|
||||
set { SetValue(PixmapProperty, value); }
|
||||
}
|
||||
|
||||
public override Task<bool> Cancel()
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
public static implicit operator SKPixmapImageSource(SKPixmap pixmap)
|
||||
{
|
||||
return new SKPixmapImageSource
|
||||
{
|
||||
Pixmap = pixmap
|
||||
};
|
||||
}
|
||||
|
||||
public static implicit operator SKPixmap(SKPixmapImageSource source)
|
||||
{
|
||||
return source?.Pixmap;
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
if (propertyName == PixmapProperty.PropertyName)
|
||||
OnSourceChanged();
|
||||
base.OnPropertyChanged(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SKPictureImageSource : ImageSource
|
||||
{
|
||||
public static readonly BindableProperty PictureProperty = BindableProperty.Create(nameof(Picture), typeof(SKPicture), typeof(SKPictureImageSource), default(SKPicture));
|
||||
|
||||
public static readonly BindableProperty DimensionsProperty = BindableProperty.Create(nameof(Dimensions), typeof(SKSizeI), typeof(SKPictureImageSource), default(SKSizeI));
|
||||
|
||||
public SKPicture Picture
|
||||
{
|
||||
get { return (SKPicture)GetValue(PictureProperty); }
|
||||
set { SetValue(PictureProperty, value); }
|
||||
}
|
||||
|
||||
public SKSizeI Dimensions
|
||||
{
|
||||
get { return (SKSizeI)GetValue(DimensionsProperty); }
|
||||
set { SetValue(DimensionsProperty, value); }
|
||||
}
|
||||
|
||||
public override Task<bool> Cancel()
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
public static explicit operator SKPicture(SKPictureImageSource source)
|
||||
{
|
||||
return source?.Picture;
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
if (propertyName == PictureProperty.PropertyName)
|
||||
OnSourceChanged();
|
||||
base.OnPropertyChanged(propertyName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
public class SKPaintGLSurfaceEventArgs : EventArgs
|
||||
{
|
||||
public SKPaintGLSurfaceEventArgs(SKSurface surface, GRBackendRenderTargetDesc renderTarget)
|
||||
{
|
||||
Surface = surface;
|
||||
RenderTarget = renderTarget;
|
||||
}
|
||||
|
||||
public SKSurface Surface { get; private set; }
|
||||
|
||||
public GRBackendRenderTargetDesc RenderTarget { get; private set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
public class SKPaintSurfaceEventArgs : EventArgs
|
||||
{
|
||||
public SKPaintSurfaceEventArgs(SKSurface surface, SKImageInfo info)
|
||||
{
|
||||
Surface = surface;
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public SKSurface Surface { get; private set; }
|
||||
|
||||
public SKImageInfo Info { get; private set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
public class SKTouchEventArgs : EventArgs
|
||||
{
|
||||
public SKTouchEventArgs(long id, SKTouchAction type, SKPoint location, bool inContact)
|
||||
: this(id, type, SKMouseButton.Left, SKTouchDeviceType.Touch, location, inContact)
|
||||
{
|
||||
}
|
||||
|
||||
public SKTouchEventArgs(long id, SKTouchAction type, SKMouseButton mouseButton, SKTouchDeviceType deviceType, SKPoint location, bool inContact)
|
||||
{
|
||||
Id = id;
|
||||
ActionType = type;
|
||||
DeviceType = deviceType;
|
||||
MouseButton = mouseButton;
|
||||
Location = location;
|
||||
InContact = inContact;
|
||||
}
|
||||
|
||||
public bool Handled { get; set; }
|
||||
|
||||
public long Id { get; private set; }
|
||||
|
||||
public SKTouchAction ActionType { get; private set; }
|
||||
|
||||
public SKTouchDeviceType DeviceType { get; private set; }
|
||||
|
||||
public SKMouseButton MouseButton { get; private set; }
|
||||
|
||||
public SKPoint Location { get; private set; }
|
||||
|
||||
public bool InContact { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{ActionType={ActionType}, DeviceType={DeviceType}, Handled={Handled}, Id={Id}, InContact={InContact}, Location={Location}, MouseButton={MouseButton}}}";
|
||||
}
|
||||
}
|
||||
|
||||
public enum SKTouchAction
|
||||
{
|
||||
Entered,
|
||||
Pressed,
|
||||
Moved,
|
||||
Released,
|
||||
Cancelled,
|
||||
Exited,
|
||||
}
|
||||
|
||||
public enum SKTouchDeviceType
|
||||
{
|
||||
Touch,
|
||||
Mouse,
|
||||
Pen
|
||||
}
|
||||
|
||||
public enum SKMouseButton
|
||||
{
|
||||
Unknown,
|
||||
|
||||
Left,
|
||||
Middle,
|
||||
Right
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>314fb505-9858-4e03-b799-91b0ba627d05</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>SkiaSharp.Views.Forms</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Extensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Properties\SkiaSharpViewsFormsAssemblyInfo.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)SKGLView.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)SKPaintGLSurfaceEventArgs.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)SKPaintSurfaceEventArgs.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)SKCanvasView.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RendererTypes.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)SKImageSource.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)SKTouchEventArgs.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>314fb505-9858-4e03-b799-91b0ba627d05</ProjectGuid>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props')" />
|
||||
<PropertyGroup />
|
||||
<Import Project="SkiaSharp.Views.Forms.Shared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets')" />
|
||||
</Project>
|
|
@ -1,6 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="OpenTK" publicKeyToken="bad199fe84eb3df4" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
|
@ -1,8 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Xamarin.Forms.ControlGallery.WinForms.Page1">
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:skia="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms"
|
||||
x:Class="Xamarin.Forms.ControlGallery.WinForms.Page1">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
|
@ -18,36 +19,24 @@
|
|||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Label
|
||||
<skia:SKGLView
|
||||
x:Name="skiaView"
|
||||
Grid.Column="0" Grid.Row="0"
|
||||
HorizontalTextAlignment="Start"
|
||||
VerticalTextAlignment="Start"
|
||||
Text="LeftTop"/>
|
||||
<Label
|
||||
Grid.Column="1" Grid.Row="0"
|
||||
HorizontalTextAlignment="Center"
|
||||
VerticalTextAlignment="Start"
|
||||
Text="CenterTop"/>
|
||||
<Label
|
||||
Grid.ColumnSpan="2"
|
||||
Grid.RowSpan="2"
|
||||
PaintSurface="SKCanvasView_PaintSurface"/>
|
||||
<Slider
|
||||
x:Name="sliderAngle"
|
||||
Grid.Column="2" Grid.Row="0"
|
||||
HorizontalTextAlignment="End"
|
||||
VerticalTextAlignment="Start"
|
||||
Text="RightTop"/>
|
||||
<Label
|
||||
Grid.Column="0" Grid.Row="1"
|
||||
HorizontalTextAlignment="Start"
|
||||
VerticalTextAlignment="Center"
|
||||
Text="LeftCenter"/>
|
||||
<Label
|
||||
Grid.Column="1" Grid.Row="1"
|
||||
HorizontalTextAlignment="Center"
|
||||
VerticalTextAlignment="Center"
|
||||
Text="CenterCenter"/>
|
||||
Minimum="0.0"
|
||||
Maximum="360.0"
|
||||
Value="0.0"
|
||||
ValueChanged="sliderAngle_ValueChanged"/>
|
||||
<Label
|
||||
Grid.Column="2" Grid.Row="1"
|
||||
HorizontalTextAlignment="End"
|
||||
VerticalTextAlignment="Center"
|
||||
Text="RightCenter"/>
|
||||
Text="{Binding Source={x:Reference sliderAngle}, Path=Value}"/>
|
||||
<Label
|
||||
Grid.Column="0" Grid.Row="2"
|
||||
HorizontalTextAlignment="Start"
|
||||
|
@ -84,11 +73,11 @@
|
|||
Increment="1"
|
||||
Maximum="100"
|
||||
Value="45"/>
|
||||
<WebView
|
||||
<!--<WebView
|
||||
Grid.Column="1"
|
||||
Grid.ColumnSpan="2"
|
||||
Grid.Row="4"
|
||||
Source="www.google.com"/>
|
||||
Source="www.google.com"/>-->
|
||||
<Label
|
||||
Grid.Column="0" Grid.Row="5"
|
||||
Text="{Binding Source={x:Reference entry}, Path=Text}"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using SkiaSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -20,5 +21,33 @@ namespace Xamarin.Forms.ControlGallery.WinForms
|
|||
{
|
||||
System.Windows.Forms.MessageBox.Show("Clicked!");
|
||||
}
|
||||
|
||||
private void SKCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintGLSurfaceEventArgs e)
|
||||
{
|
||||
var w = (float)e.RenderTarget.Size.Width / 2;
|
||||
var h = (float)e.RenderTarget.Size.Height / 2;
|
||||
var r = w < h ? w : h;
|
||||
|
||||
var angle = 3.14159 * sliderAngle.Value / 180.0;
|
||||
var len = new SKPoint((float)Math.Cos(angle) * r, (float)Math.Sin(angle) * r);
|
||||
|
||||
e.Surface.Canvas.Clear(SKColors.White);
|
||||
using (var p = new SKPaint())
|
||||
using (var shader = SKShader.CreateLinearGradient(
|
||||
new SKPoint(w + len.X, h + len.Y),
|
||||
new SKPoint(w - len.X, h - len.Y),
|
||||
new[] { SKColors.Red, SKColors.Lime },
|
||||
new[] { 0.0f, 1.0f },
|
||||
SKShaderTileMode.Clamp))
|
||||
{
|
||||
p.Shader = shader;
|
||||
e.Surface.Canvas.DrawCircle(w, h, r, p);
|
||||
}
|
||||
}
|
||||
|
||||
private void sliderAngle_ValueChanged(object sender, ValueChangedEventArgs e)
|
||||
{
|
||||
skiaView.InvalidateSurface();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ namespace Xamarin.Forms.ControlGallery.WinForms
|
|||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
OpenTK.Toolkit.Init();
|
||||
|
||||
System.Windows.Forms.Application.EnableVisualStyles();
|
||||
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
|
|
|
@ -35,6 +35,21 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenTK.2.0.0\lib\net20\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OpenTK.GLControl, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenTK.GLControl.1.1.2349.61993\lib\NET40\OpenTK.GLControl.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp, Version=1.59.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.1.59.3\lib\net45\SkiaSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp.Views.Desktop, Version=1.59.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.Views.1.59.3\lib\net45\SkiaSharp.Views.Desktop.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SkiaSharp.Views.WPF, Version=1.59.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SkiaSharp.Views.1.59.3\lib\net45\SkiaSharp.Views.WPF.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
|
@ -72,6 +87,7 @@
|
|||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
|
@ -87,6 +103,10 @@
|
|||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SkiaSharp.Views.Forms.WinForms\SkiaSharp.Views.Forms.WinForms.csproj">
|
||||
<Project>{dc2d61aa-3749-485b-a6bb-343e738211a8}</Project>
|
||||
<Name>SkiaSharp.Views.Forms.WinForms</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Xamarin.Forms.Platform.WinForms\Xamarin.Forms.Platform.WinForms.csproj">
|
||||
<Project>{cd51aedc-e33d-4620-a9c6-9683891ef615}</Project>
|
||||
<Name>Xamarin.Forms.Platform.WinForms</Name>
|
||||
|
@ -104,6 +124,8 @@
|
|||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\SkiaSharp.1.59.3\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.1.59.3\build\net45\SkiaSharp.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.5.0.91635\build\netstandard1.0\Xamarin.Forms.targets')" />
|
||||
<Import Project="..\packages\SkiaSharp.1.59.3\build\net45\SkiaSharp.targets" Condition="Exists('..\packages\SkiaSharp.1.59.3\build\net45\SkiaSharp.targets')" />
|
||||
</Project>
|
|
@ -1,4 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="OpenTK" version="2.0.0" targetFramework="net452" />
|
||||
<package id="OpenTK.GLControl" version="1.1.2349.61993" targetFramework="net452" />
|
||||
<package id="SkiaSharp" version="1.59.3" targetFramework="net452" />
|
||||
<package id="SkiaSharp.Views" version="1.59.3" targetFramework="net452" />
|
||||
<package id="Xamarin.Forms" version="2.5.0.91635" targetFramework="net452" />
|
||||
</packages>
|
|
@ -14,7 +14,12 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
Control.Click += OnClick;
|
||||
if (Control == null)
|
||||
{
|
||||
SetNativeControl(new System.Windows.Forms.Button());
|
||||
Control.Click += OnClick;
|
||||
}
|
||||
|
||||
UpdateText(Control);
|
||||
UpdateTextColor(Control);
|
||||
UpdateFont(Control);
|
||||
|
|
|
@ -18,9 +18,14 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
if (Control == null)
|
||||
{
|
||||
SetNativeControl(new System.Windows.Forms.TextBox());
|
||||
Control.TextChanged += OnTextChanged;
|
||||
}
|
||||
|
||||
Control.Multiline = true;
|
||||
Control.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
Control.TextChanged += OnTextChanged;
|
||||
|
||||
UpdateText();
|
||||
UpdateTextColor();
|
||||
|
|
|
@ -18,8 +18,13 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
if (Control == null)
|
||||
{
|
||||
SetNativeControl(new System.Windows.Forms.TextBox());
|
||||
Control.TextChanged += OnTextChanged;
|
||||
}
|
||||
|
||||
Control.Multiline = false;
|
||||
Control.TextChanged += OnTextChanged;
|
||||
|
||||
UpdateText();
|
||||
UpdateTextColor();
|
||||
|
|
|
@ -18,6 +18,11 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
if (Control == null)
|
||||
{
|
||||
SetNativeControl(new System.Windows.Forms.Label());
|
||||
}
|
||||
|
||||
UpdateText(Control);
|
||||
UpdateTextColor(Control);
|
||||
UpdateAlign(Control);
|
||||
|
@ -106,7 +111,7 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
{
|
||||
nativeElement.Font = new System.Drawing.Font(
|
||||
label.FontFamily,
|
||||
(float)label.FontSize,
|
||||
Math.Max((float)label.FontSize, 1.0f),
|
||||
label.FontAttributes.ToWindowsFontStyle());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,22 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
{
|
||||
public class LayoutRenderer : ViewRenderer<Layout, System.Windows.Forms.Panel>
|
||||
{
|
||||
public LayoutRenderer()
|
||||
/*-----------------------------------------------------------------*/
|
||||
#region Event Handler
|
||||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Layout> e)
|
||||
{
|
||||
base.OnElementChanged(e);
|
||||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
if (Control == null)
|
||||
{
|
||||
SetNativeControl(new System.Windows.Forms.Panel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -19,9 +19,14 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
}
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
if (Control == null)
|
||||
{
|
||||
SetNativeControl(new System.Windows.Forms.ComboBox());
|
||||
Control.SelectedIndexChanged += OnSelectedIndexChanged;
|
||||
}
|
||||
|
||||
e.NewElement.Items.AddCollectionChangedEvent(OnCollectionChanged);
|
||||
Control.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
Control.SelectedIndexChanged += OnSelectedIndexChanged;
|
||||
|
||||
UpdateItems();
|
||||
UpdateSelectedIndex();
|
||||
|
|
|
@ -14,7 +14,12 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
Control.ValueChanged += OnValueChanged;
|
||||
if (Control == null)
|
||||
{
|
||||
SetNativeControl(new System.Windows.Forms.TrackBar());
|
||||
Control.ValueChanged += OnValueChanged;
|
||||
}
|
||||
|
||||
Control.TickFrequency = 0;
|
||||
|
||||
UpdateValue();
|
||||
|
|
|
@ -14,7 +14,12 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
Control.CheckedChanged += OnCheckedChanged;
|
||||
if (Control == null)
|
||||
{
|
||||
SetNativeControl(new System.Windows.Forms.CheckBox());
|
||||
Control.CheckedChanged += OnCheckedChanged;
|
||||
}
|
||||
|
||||
UpdateToggle();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
public class ViewRenderer<TElement, TNativeElement> :
|
||||
VisualElementRenderer<TElement, TNativeElement>
|
||||
where TElement : View
|
||||
where TNativeElement : Control, new()
|
||||
where TNativeElement : Control
|
||||
{
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<TElement> e)
|
||||
{
|
||||
|
@ -13,13 +13,6 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
if (Control == null)
|
||||
{
|
||||
var control = new TNativeElement();
|
||||
control.Anchor = AnchorStyles.Left | AnchorStyles.Top;
|
||||
control.SetBounds(0, 0, 0, 0, BoundsSpecified.All);
|
||||
SetNativeControl(control);
|
||||
}
|
||||
UpdateBackgroundColor();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,14 +15,34 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
{
|
||||
VisualElementTracker<TElement, TNativeElement> _tracker;
|
||||
readonly VisualElementRendererCollection _children = new VisualElementRendererCollection();
|
||||
bool _disposedValue = false;
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
foreach (var item in _children)
|
||||
{
|
||||
item?.Dispose();
|
||||
}
|
||||
_children.Clear();
|
||||
}
|
||||
|
||||
_disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*~VisualElementRenderer()
|
||||
{
|
||||
Dispose(false);
|
||||
}*/
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var item in _children)
|
||||
{
|
||||
item?.Dispose();
|
||||
}
|
||||
_children.Clear();
|
||||
Dispose(true);
|
||||
//GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected VisualElementTracker<TElement, TNativeElement> Tracker
|
||||
|
@ -104,6 +124,8 @@ namespace Xamarin.Forms.Platform.WinForms
|
|||
|
||||
//Control.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
//Control.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
Control.Anchor = AnchorStyles.Left | AnchorStyles.Top;
|
||||
Control.SetBounds(0, 0, 0, 0, BoundsSpecified.All);
|
||||
|
||||
if (Element == null)
|
||||
throw new InvalidOperationException(
|
||||
|
|
|
@ -1,13 +1,27 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.15
|
||||
VisualStudioVersion = 15.0.27130.2010
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Forms.Platform.WinForms", "Xamarin.Forms.Platform.WinForms\Xamarin.Forms.Platform.WinForms.csproj", "{563D7C2E-14E2-47EC-95E4-4EA0BBA75C18}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Forms.ControlGallery.WinForms", "Xamarin.Forms.ControlGallery.WinForms\Xamarin.Forms.ControlGallery.WinForms.csproj", "{63390A59-21A4-42AC-B3E0-18B65DDDD87A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.Views.Forms.WinForms", "SkiaSharp.Views.Forms.WinForms\SkiaSharp.Views.Forms.WinForms.csproj", "{DC2D61AA-3749-485B-A6BB-343E738211A8}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SkiaSharp", "SkiaSharp", "{51B3B764-9726-4919-9D00-0D797ECE00DD}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SkiaSharp.Views.Forms.Native.Shared", "SkiaSharp\source\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Native.Shared\SkiaSharp.Views.Forms.Native.Shared.shproj", "{CEBD25FD-DD4F-4D5F-B809-D50D02176F41}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SkiaSharp.Views.Forms.Shared", "SkiaSharp\source\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Shared\SkiaSharp.Views.Forms.Shared.shproj", "{314FB505-9858-4E03-B799-91B0BA627D05}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
SkiaSharp\source\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Shared\SkiaSharp.Views.Forms.Shared.projitems*{314fb505-9858-4e03-b799-91b0ba627d05}*SharedItemsImports = 13
|
||||
SkiaSharp\source\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Native.Shared\SkiaSharp.Views.Forms.Native.Shared.projitems*{cebd25fd-dd4f-4d5f-b809-d50d02176f41}*SharedItemsImports = 13
|
||||
SkiaSharp\source\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Native.Shared\SkiaSharp.Views.Forms.Native.Shared.projitems*{dc2d61aa-3749-485b-a6bb-343e738211a8}*SharedItemsImports = 4
|
||||
SkiaSharp\source\SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Shared\SkiaSharp.Views.Forms.Shared.projitems*{dc2d61aa-3749-485b-a6bb-343e738211a8}*SharedItemsImports = 4
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
|
@ -21,8 +35,19 @@ Global
|
|||
{63390A59-21A4-42AC-B3E0-18B65DDDD87A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{63390A59-21A4-42AC-B3E0-18B65DDDD87A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{63390A59-21A4-42AC-B3E0-18B65DDDD87A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DC2D61AA-3749-485B-A6BB-343E738211A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DC2D61AA-3749-485B-A6BB-343E738211A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DC2D61AA-3749-485B-A6BB-343E738211A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC2D61AA-3749-485B-A6BB-343E738211A8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{CEBD25FD-DD4F-4D5F-B809-D50D02176F41} = {51B3B764-9726-4919-9D00-0D797ECE00DD}
|
||||
{314FB505-9858-4E03-B799-91B0BA627D05} = {51B3B764-9726-4919-9D00-0D797ECE00DD}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E3CCA848-AD6D-4679-9B85-F01E11D83F10}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
Загрузка…
Ссылка в новой задаче