|
|
@@ -14,61 +14,74 @@ namespace Perspex.Rendering
|
|
|
/// <remarks>
|
|
|
/// This class provides implements the platform-independent parts of <see cref="IRenderer"/>.
|
|
|
/// </remarks>
|
|
|
- public abstract class RendererBase : IRenderer
|
|
|
+ public static class RendererMixin
|
|
|
{
|
|
|
/// <summary>
|
|
|
- /// Gets the number of times <see cref="Render(IVisual, IPlatformHandle)"/> has been called.
|
|
|
+ /// Renders the specified visual.
|
|
|
/// </summary>
|
|
|
- public int RenderCount
|
|
|
+ /// <param name="renderer">IRenderer instance</param>
|
|
|
+ /// <param name="visual">The visual to render.</param>
|
|
|
+ /// <param name="target">An optional platform-specific handle.</param>
|
|
|
+ public static void Render(this IRenderer renderer, IVisual visual, IPlatformHandle target)
|
|
|
{
|
|
|
- get;
|
|
|
- private set;
|
|
|
+ using (var ctx = renderer.CreateDrawingContext(target))
|
|
|
+ ctx.Render(visual);
|
|
|
}
|
|
|
|
|
|
- public abstract void Dispose();
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// Renders the specified visual.
|
|
|
/// </summary>
|
|
|
+ /// <param name="renderer">IRenderer instance</param>
|
|
|
+ /// <param name="target">An optional platform-specific handle.</param>
|
|
|
/// <param name="visual">The visual to render.</param>
|
|
|
- /// <param name="handle">An optional platform-specific handle.</param>
|
|
|
- public virtual void Render(IVisual visual, IPlatformHandle handle)
|
|
|
+ /// <param name="translation">The current translation.</param>
|
|
|
+ /// <param name="transform">The current transform.</param>
|
|
|
+ public static void Render(this IRenderer renderer, IVisual visual, IPlatformHandle target, Matrix translation, Matrix transform)
|
|
|
{
|
|
|
- Render(visual, handle, Matrix.Identity);
|
|
|
- ++RenderCount;
|
|
|
+ using (var ctx = renderer.CreateDrawingContext(target))
|
|
|
+ ctx.Render(visual, translation, transform);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Renders the specified visual with the specified transform and clip.
|
|
|
/// </summary>
|
|
|
+ /// <param name="renderer">IRenderer instance</param>
|
|
|
+ /// <param name="target">An optional platform-specific handle.</param>
|
|
|
/// <param name="visual">The visual to render.</param>
|
|
|
- /// <param name="handle">An optional platform-specific handle.</param>
|
|
|
/// <param name="transform">The transform.</param>
|
|
|
/// <param name="clip">An optional clip rectangle.</param>
|
|
|
- public virtual void Render(IVisual visual, IPlatformHandle handle, Matrix transform, Rect? clip = null)
|
|
|
+ public static void Render(this IRenderer renderer, IVisual visual, IPlatformHandle target, Matrix transform, Rect? clip = null)
|
|
|
{
|
|
|
- using (var context = CreateDrawingContext(handle))
|
|
|
- using (clip.HasValue ? context.PushClip(clip.Value) : null)
|
|
|
- {
|
|
|
- Render(visual, context, Matrix.Identity, transform);
|
|
|
- }
|
|
|
+ using (var context = renderer.CreateDrawingContext(target))
|
|
|
+ context.Render(visual, transform, clip);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Resizes the rendered viewport.
|
|
|
+ /// Renders the specified visual.
|
|
|
/// </summary>
|
|
|
- /// <param name="width">The new width.</param>
|
|
|
- /// <param name="height">The new height.</param>
|
|
|
- public abstract void Resize(int width, int height);
|
|
|
+ /// <param name="visual">The visual to render.</param>
|
|
|
+ ///
|
|
|
+ /// <param name="context">The drawing context.</param>
|
|
|
+ public static void Render(this IDrawingContext context, IVisual visual)
|
|
|
+ {
|
|
|
+ context.Render(visual, Matrix.Identity);
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
- /// When overriden by a derived class creates an <see cref="IDrawingContext"/> for a
|
|
|
- /// rendering session.
|
|
|
+ /// Renders the specified visual with the specified transform and clip.
|
|
|
/// </summary>
|
|
|
- /// <param name="handle">The handle to use to create the context.</param>
|
|
|
- /// <returns>An <see cref="IDrawingContext"/>.</returns>
|
|
|
- protected abstract IDrawingContext CreateDrawingContext(IPlatformHandle handle);
|
|
|
-
|
|
|
+ /// <param name="visual">The visual to render.</param>
|
|
|
+ /// <param name="context">The drawing context.</param>
|
|
|
+ /// <param name="transform">The transform.</param>
|
|
|
+ /// <param name="clip">An optional clip rectangle.</param>
|
|
|
+ public static void Render(this IDrawingContext context, IVisual visual, Matrix transform, Rect? clip = null)
|
|
|
+ {
|
|
|
+ using (clip.HasValue ? context.PushClip(clip.Value) : null)
|
|
|
+ {
|
|
|
+ context.Render(visual, Matrix.Identity, transform);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Renders the specified visual.
|
|
|
/// </summary>
|
|
|
@@ -76,7 +89,7 @@ namespace Perspex.Rendering
|
|
|
/// <param name="context">The drawing context.</param>
|
|
|
/// <param name="translation">The current translation.</param>
|
|
|
/// <param name="transform">The current transform.</param>
|
|
|
- protected virtual void Render(IVisual visual, IDrawingContext context, Matrix translation, Matrix transform)
|
|
|
+ public static void Render(this IDrawingContext context, IVisual visual, Matrix translation, Matrix transform)
|
|
|
{
|
|
|
var opacity = visual.Opacity;
|
|
|
|
|
|
@@ -108,7 +121,7 @@ namespace Perspex.Rendering
|
|
|
|
|
|
foreach (var child in visual.VisualChildren.OrderBy(x => x.ZIndex))
|
|
|
{
|
|
|
- Render(child, context, translation, transform);
|
|
|
+ context.Render(child, translation, transform);
|
|
|
}
|
|
|
}
|
|
|
}
|