From 94b1057685e4a1f32adfecb0882f15200e745a43 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 17 Dec 2014 03:49:30 +0100 Subject: [PATCH] Tidied up the render routine. --- Windows/Perspex.Direct2D1/Renderer.cs | 31 ++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Windows/Perspex.Direct2D1/Renderer.cs b/Windows/Perspex.Direct2D1/Renderer.cs index 873078cb5c..d36bcd2ade 100644 --- a/Windows/Perspex.Direct2D1/Renderer.cs +++ b/Windows/Perspex.Direct2D1/Renderer.cs @@ -100,7 +100,7 @@ namespace Perspex.Direct2D1 { using (DrawingContext context = new DrawingContext(this.renderTarget, this.DirectWriteFactory)) { - this.Render(visual, context, Matrix.Identity, Matrix.Identity, new Vector()); + this.Render(visual, context, Matrix.Identity, Matrix.Identity); } ++this.RenderCount; @@ -130,29 +130,26 @@ namespace Perspex.Direct2D1 /// /// The visual to render. /// The drawing context. - private void Render(IVisual visual, DrawingContext context, Matrix translation, Matrix transform, Vector transformOffset) + private void Render(IVisual visual, DrawingContext context, Matrix translation, Matrix transform) { if (visual.IsVisible && visual.Opacity > 0) { - if (!transform.IsIdentity) - { - transformOffset += visual.Bounds.Position; - } + // Translate an existing transform into this controls coordinate system. + Matrix offset = Matrix.Translation(visual.Bounds.Position); + transform = offset * transform * -offset; + + // Update the current offset. + translation *= Matrix.Translation(visual.Bounds.Position); + // Apply the control's render transform, if any. if (visual.RenderTransform != null) { - transform *= visual.RenderTransform.Value; - transformOffset -= visual.TransformOrigin.ToPixels(visual.Bounds.Size); + offset = Matrix.Translation(visual.TransformOrigin.ToPixels(visual.Bounds.Size)); + transform *= -offset * visual.RenderTransform.Value * offset; } - translation *= Matrix.Translation(visual.Bounds.Position); - - Matrix m = - Matrix.Translation(transformOffset) * - transform * - -Matrix.Translation(transformOffset) * - translation; - + // Draw the control and its children. + Matrix m = transform * translation; using (visual.ClipToBounds ? context.PushClip(visual.Bounds * m) : null) { using (context.PushTransform(m)) @@ -162,7 +159,7 @@ namespace Perspex.Direct2D1 foreach (var child in visual.VisualChildren) { - this.Render(child, context, translation, transform, transformOffset); + this.Render(child, context, translation, transform); } } }