38 changed files with 248 additions and 225 deletions
@ -0,0 +1,62 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Perspex.Platform; |
||||
|
using Perspex.Rendering; |
||||
|
|
||||
|
namespace Perspex.Controls.Platform |
||||
|
{ |
||||
|
public interface ITopLevelRenderer |
||||
|
{ |
||||
|
void Attach(TopLevel topLevel); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
class DefaultTopLevelRenderer : ITopLevelRenderer |
||||
|
{ |
||||
|
|
||||
|
public void Attach(TopLevel topLevel) |
||||
|
{ |
||||
|
var resources = new List<IDisposable>(); |
||||
|
var initialClientSize = topLevel.PlatformImpl.ClientSize; |
||||
|
|
||||
|
|
||||
|
var queueManager = ((IRenderRoot)topLevel).RenderQueueManager; |
||||
|
|
||||
|
if (queueManager == null) |
||||
|
return; |
||||
|
|
||||
|
var platformRender = PerspexLocator.Current.GetService<IPlatformRenderInterface>(); |
||||
|
if(platformRender == null) |
||||
|
return; |
||||
|
|
||||
|
var viewport = platformRender |
||||
|
.CreateRenderer(topLevel.PlatformImpl.Handle, initialClientSize.Width, initialClientSize.Height); |
||||
|
resources.Add(viewport); |
||||
|
|
||||
|
|
||||
|
resources.Add(topLevel.GetObservable(TopLevel.ClientSizeProperty).Subscribe(clientSize => |
||||
|
{ |
||||
|
viewport.Resize((int) clientSize.Width, (int) clientSize.Height); |
||||
|
})); |
||||
|
resources.Add(queueManager.RenderNeeded.Subscribe(_ |
||||
|
=> topLevel.PlatformImpl.Invalidate(new Rect(topLevel.ClientSize)))); |
||||
|
|
||||
|
topLevel.PlatformImpl.Paint = rect => |
||||
|
{ |
||||
|
viewport.Render(topLevel); |
||||
|
queueManager.RenderFinished(); |
||||
|
}; |
||||
|
|
||||
|
topLevel.Closed += delegate |
||||
|
{ |
||||
|
foreach (var disposable in resources) |
||||
|
disposable.Dispose(); |
||||
|
resources.Clear(); |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
// Copyright (c) The Perspex Project. All rights reserved.
|
||||
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
||||
|
|
||||
|
using System; |
||||
|
using Perspex.Media; |
||||
|
|
||||
|
namespace Perspex.Platform |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Defines a render target
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// The interface used for obtaining drawing context from surfaces you can render on.
|
||||
|
/// </remarks>
|
||||
|
public interface IRenderTarget : IDisposable |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Creates an <see cref="IDrawingContext"/> for a rendering session.
|
||||
|
/// </summary>
|
||||
|
IDrawingContext CreateDrawingContext(); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Resizes the rendered viewport.
|
||||
|
/// </summary>
|
||||
|
/// <param name="width">The new width.</param>
|
||||
|
/// <param name="height">The new height.</param>
|
||||
|
void Resize(int width, int height); |
||||
|
} |
||||
|
} |
||||
@ -1,38 +0,0 @@ |
|||||
// Copyright (c) The Perspex Project. All rights reserved.
|
|
||||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
||||
|
|
||||
using System; |
|
||||
|
|
||||
namespace Perspex.Platform |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Defines a renderer.
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// The interface used to render <see cref="IVisual"/>s. You will usually want to inherit from
|
|
||||
/// <see cref="Perspex.Rendering.RendererBase"/> rather than implementing the whole interface
|
|
||||
/// as RenderBase has a default implementation for the non-platform specific parts of a
|
|
||||
/// renderer.
|
|
||||
/// </remarks>
|
|
||||
public interface IRenderer : IDisposable |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Gets the number of times <see cref="Render"/> has been called.
|
|
||||
/// </summary>
|
|
||||
int RenderCount { get; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Renders the specified visual.
|
|
||||
/// </summary>
|
|
||||
/// <param name="visual">The visual to render.</param>
|
|
||||
/// <param name="handle">An optional platform-specific handle.</param>
|
|
||||
void Render(IVisual visual, IPlatformHandle handle); |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Resizes the rendered viewport.
|
|
||||
/// </summary>
|
|
||||
/// <param name="width">The new width.</param>
|
|
||||
/// <param name="height">The new height.</param>
|
|
||||
void Resize(int width, int height); |
|
||||
} |
|
||||
} |
|
||||
Binary file not shown.
Loading…
Reference in new issue