|
|
|
@ -44,95 +44,99 @@ namespace Avalonia.Rendering |
|
|
|
|
|
|
|
public static void Render(DrawingContext context, Visual visual, Rect clipRect) |
|
|
|
{ |
|
|
|
var opacity = visual.Opacity; |
|
|
|
var clipToBounds = visual.ClipToBounds; |
|
|
|
var bounds = new Rect(visual.Bounds.Size); |
|
|
|
var currentRenderOptions = default(RenderOptions); |
|
|
|
var platformContext = context as PlatformDrawingContext; |
|
|
|
|
|
|
|
if (visual.IsVisible && opacity > 0) |
|
|
|
try |
|
|
|
{ |
|
|
|
var m = Matrix.CreateTranslation(visual.Bounds.Position); |
|
|
|
|
|
|
|
var renderTransform = Matrix.Identity; |
|
|
|
|
|
|
|
// this should be calculated BEFORE renderTransform
|
|
|
|
if (visual.HasMirrorTransform) |
|
|
|
if (platformContext != null) |
|
|
|
{ |
|
|
|
var mirrorMatrix = new Matrix(-1.0, 0.0, 0.0, 1.0, visual.Bounds.Width, 0); |
|
|
|
renderTransform *= mirrorMatrix; |
|
|
|
} |
|
|
|
currentRenderOptions = platformContext.RenderOptions; |
|
|
|
|
|
|
|
if (visual.RenderTransform != null) |
|
|
|
{ |
|
|
|
var origin = visual.RenderTransformOrigin.ToPixels(new Size(visual.Bounds.Width, visual.Bounds.Height)); |
|
|
|
var offset = Matrix.CreateTranslation(origin); |
|
|
|
var finalTransform = (-offset) * visual.RenderTransform.Value * (offset); |
|
|
|
renderTransform *= finalTransform; |
|
|
|
platformContext.RenderOptions = visual.RenderOptions.MergeWith(platformContext.RenderOptions); |
|
|
|
} |
|
|
|
|
|
|
|
m = renderTransform * m; |
|
|
|
var opacity = visual.Opacity; |
|
|
|
var clipToBounds = visual.ClipToBounds; |
|
|
|
var bounds = new Rect(visual.Bounds.Size); |
|
|
|
|
|
|
|
if (clipToBounds) |
|
|
|
if (visual.IsVisible && opacity > 0) |
|
|
|
{ |
|
|
|
var m = Matrix.CreateTranslation(visual.Bounds.Position); |
|
|
|
|
|
|
|
var renderTransform = Matrix.Identity; |
|
|
|
|
|
|
|
// this should be calculated BEFORE renderTransform
|
|
|
|
if (visual.HasMirrorTransform) |
|
|
|
{ |
|
|
|
var mirrorMatrix = new Matrix(-1.0, 0.0, 0.0, 1.0, visual.Bounds.Width, 0); |
|
|
|
renderTransform *= mirrorMatrix; |
|
|
|
} |
|
|
|
|
|
|
|
if (visual.RenderTransform != null) |
|
|
|
{ |
|
|
|
clipRect = new Rect(visual.Bounds.Size); |
|
|
|
var origin = visual.RenderTransformOrigin.ToPixels(new Size(visual.Bounds.Width, visual.Bounds.Height)); |
|
|
|
var offset = Matrix.CreateTranslation(origin); |
|
|
|
var finalTransform = (-offset) * visual.RenderTransform.Value * (offset); |
|
|
|
renderTransform *= finalTransform; |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
m = renderTransform * m; |
|
|
|
|
|
|
|
if (clipToBounds) |
|
|
|
{ |
|
|
|
clipRect = clipRect.Intersect(new Rect(visual.Bounds.Size)); |
|
|
|
if (visual.RenderTransform != null) |
|
|
|
{ |
|
|
|
clipRect = new Rect(visual.Bounds.Size); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
clipRect = clipRect.Intersect(new Rect(visual.Bounds.Size)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
using (context.PushTransform(m)) |
|
|
|
using (context.PushOpacity(opacity, bounds)) |
|
|
|
using (clipToBounds |
|
|
|
using (context.PushTransform(m)) |
|
|
|
using (context.PushOpacity(opacity, bounds)) |
|
|
|
using (clipToBounds |
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
|
|
|
? visual is IVisualWithRoundRectClip roundClipVisual |
|
|
|
? context.PushClip(new RoundedRect(bounds, roundClipVisual.ClipToBoundsRadius)) |
|
|
|
: context.PushClip(bounds) |
|
|
|
: default) |
|
|
|
? visual is IVisualWithRoundRectClip roundClipVisual |
|
|
|
? context.PushClip(new RoundedRect(bounds, roundClipVisual.ClipToBoundsRadius)) |
|
|
|
: context.PushClip(bounds) |
|
|
|
: default) |
|
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
|
|
|
|
using (visual.Clip != null ? context.PushGeometryClip(visual.Clip) : default) |
|
|
|
using (visual.OpacityMask != null ? context.PushOpacityMask(visual.OpacityMask, bounds) : default) |
|
|
|
using (context.PushTransform(Matrix.Identity)) |
|
|
|
{ |
|
|
|
var currentRenderOptions = default(RenderOptions); |
|
|
|
|
|
|
|
var platformContext = context as PlatformDrawingContext; |
|
|
|
|
|
|
|
if(platformContext != null) |
|
|
|
using (visual.Clip != null ? context.PushGeometryClip(visual.Clip) : default) |
|
|
|
using (visual.OpacityMask != null ? context.PushOpacityMask(visual.OpacityMask, bounds) : default) |
|
|
|
using (context.PushTransform(Matrix.Identity)) |
|
|
|
{ |
|
|
|
currentRenderOptions = platformContext.RenderOptions; |
|
|
|
visual.Render(context); |
|
|
|
|
|
|
|
platformContext.RenderOptions = visual.RenderOptions.MergeWith(platformContext.RenderOptions); |
|
|
|
} |
|
|
|
|
|
|
|
visual.Render(context); |
|
|
|
|
|
|
|
var childrenEnumerable = visual.HasNonUniformZIndexChildren |
|
|
|
? visual.VisualChildren.OrderBy(x => x, ZIndexComparer.Instance) |
|
|
|
: (IEnumerable<Visual>)visual.VisualChildren; |
|
|
|
|
|
|
|
foreach (var child in childrenEnumerable) |
|
|
|
{ |
|
|
|
var childBounds = GetTransformedBounds(child); |
|
|
|
var childrenEnumerable = visual.HasNonUniformZIndexChildren |
|
|
|
? visual.VisualChildren.OrderBy(x => x, ZIndexComparer.Instance) |
|
|
|
: (IEnumerable<Visual>)visual.VisualChildren; |
|
|
|
|
|
|
|
if (!child.ClipToBounds || clipRect.Intersects(childBounds)) |
|
|
|
foreach (var child in childrenEnumerable) |
|
|
|
{ |
|
|
|
var childClipRect = child.RenderTransform == null |
|
|
|
? clipRect.Translate(-childBounds.Position) |
|
|
|
: clipRect; |
|
|
|
Render(context, child, childClipRect); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(platformContext != null) |
|
|
|
{ |
|
|
|
platformContext.RenderOptions = currentRenderOptions; |
|
|
|
var childBounds = GetTransformedBounds(child); |
|
|
|
|
|
|
|
if (!child.ClipToBounds || clipRect.Intersects(childBounds)) |
|
|
|
{ |
|
|
|
var childClipRect = child.RenderTransform == null |
|
|
|
? clipRect.Translate(-childBounds.Position) |
|
|
|
: clipRect; |
|
|
|
Render(context, child, childClipRect); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
if (platformContext != null) |
|
|
|
{ |
|
|
|
platformContext.RenderOptions = currentRenderOptions; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|