Merge remote-tracking branch 'refs/remotes/aosoft/master'
This commit is contained in:
Коммит
af6dbf3f24
|
@ -0,0 +1,131 @@
|
|||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Xamarin.Forms.Platform.WinForms
|
||||
{
|
||||
public class OpenGLViewRenderer : ViewRenderer<OpenGLView, GLControl>
|
||||
{
|
||||
private Timer _timer;
|
||||
private Action<Rectangle> _action;
|
||||
private bool _hasRenderLoop;
|
||||
private bool _disposed;
|
||||
|
||||
public Action<Rectangle> Action
|
||||
{
|
||||
get { return _action; }
|
||||
set { _action = value; }
|
||||
}
|
||||
|
||||
public bool HasRenderLoop
|
||||
{
|
||||
get { return _hasRenderLoop; }
|
||||
set { _hasRenderLoop = value; }
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed && disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
if (Element != null)
|
||||
((IOpenGlViewController)Element).DisplayRequested -= Render;
|
||||
|
||||
var glControl = Control;
|
||||
if (glControl != null)
|
||||
glControl.Paint -= OnPaint;
|
||||
|
||||
if (_timer != null)
|
||||
_timer.Tick -= OnTick;
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<OpenGLView> e)
|
||||
{
|
||||
if (e.OldElement != null)
|
||||
((IOpenGlViewController)e.OldElement).DisplayRequested -= Render;
|
||||
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
var glControl = new GLControl(new GraphicsMode(32, 24), 2, 0, GraphicsContextFlags.Default);
|
||||
glControl.MakeCurrent();
|
||||
glControl.Dock = DockStyle.Fill;
|
||||
|
||||
glControl.Paint += OnPaint;
|
||||
|
||||
SetNativeControl(glControl);
|
||||
|
||||
_timer = new Timer();
|
||||
_timer.Interval = 16;
|
||||
_timer.Tick += OnTick;
|
||||
_timer.Start();
|
||||
|
||||
((IOpenGlViewController)e.NewElement).DisplayRequested += Render;
|
||||
|
||||
SetRenderMode();
|
||||
SetupRenderAction();
|
||||
}
|
||||
|
||||
base.OnElementChanged(e);
|
||||
}
|
||||
|
||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
|
||||
if (e.PropertyName == OpenGLView.HasRenderLoopProperty.PropertyName)
|
||||
{
|
||||
SetRenderMode();
|
||||
SetupRenderAction();
|
||||
}
|
||||
}
|
||||
|
||||
public void Render(object sender, EventArgs eventArgs)
|
||||
{
|
||||
if (HasRenderLoop)
|
||||
return;
|
||||
|
||||
SetupRenderAction();
|
||||
}
|
||||
|
||||
private void SetRenderMode()
|
||||
{
|
||||
HasRenderLoop = Element.HasRenderLoop;
|
||||
}
|
||||
|
||||
private void SetupRenderAction()
|
||||
{
|
||||
var model = Element;
|
||||
var onDisplay = model.OnDisplay;
|
||||
|
||||
Action = onDisplay;
|
||||
}
|
||||
|
||||
private void OnPaint(object sender, PaintEventArgs e)
|
||||
{
|
||||
var glControl = Control;
|
||||
|
||||
if (glControl == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
glControl.MakeCurrent();
|
||||
Action.Invoke(new Rectangle(0, 0, glControl.Width, glControl.Height));
|
||||
glControl.SwapBuffers();
|
||||
}
|
||||
|
||||
private void OnTick(object sender, EventArgs e)
|
||||
{
|
||||
if (!HasRenderLoop)
|
||||
return;
|
||||
|
||||
Control?.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,6 +33,12 @@
|
|||
<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="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
|
@ -64,6 +70,7 @@
|
|||
<Compile Include="Renderers\EditorRenderer.cs" />
|
||||
<Compile Include="Renderers\LabelRenderer.cs" />
|
||||
<Compile Include="Renderers\LayoutRenderer.cs" />
|
||||
<Compile Include="Renderers\OpenGLViewRenderer.cs" />
|
||||
<Compile Include="Renderers\PageRenderer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Renderers\PickerRenderer.cs" />
|
||||
|
@ -91,6 +98,8 @@
|
|||
<Compile Include="WinFormsTicker.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
|
|
@ -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>
|
|
@ -1,4 +1,6 @@
|
|||
<?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="Xamarin.Forms" version="2.5.0.91635" targetFramework="net452" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче