From 9c74c34383be3e1a053acda4a639d4b0c16a31f4 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 23 Sep 2014 19:04:27 +0200 Subject: [PATCH] Clip controls. Messes up the treeview item expanded arrows... Probably related to the previous problem with rendering and rotate transforms. --- Perspex.Direct2D1/Media/DrawingContext.cs | 15 +++++++++++++++ Perspex.Direct2D1/Renderer.cs | 1 + Perspex.SceneGraph/Media/IDrawingContext.cs | 7 +++++++ TestApplication/Program.cs | 4 ++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Perspex.Direct2D1/Media/DrawingContext.cs b/Perspex.Direct2D1/Media/DrawingContext.cs index 298b09de8d..31a9f7604a 100644 --- a/Perspex.Direct2D1/Media/DrawingContext.cs +++ b/Perspex.Direct2D1/Media/DrawingContext.cs @@ -171,6 +171,21 @@ namespace Perspex.Direct2D1.Media } } + /// + /// Pushes a clip rectange. + /// + /// The clip rectangle. + /// A disposable used to undo the clip rectangle. + public IDisposable PushClip(Rect clip) + { + this.renderTarget.PushAxisAlignedClip(clip.ToSharpDX(), AntialiasMode.PerPrimitive); + + return Disposable.Create(() => + { + this.renderTarget.PopAxisAlignedClip(); + }); + } + /// /// Pushes a matrix transformation. /// diff --git a/Perspex.Direct2D1/Renderer.cs b/Perspex.Direct2D1/Renderer.cs index d019af47b2..3454f87941 100644 --- a/Perspex.Direct2D1/Renderer.cs +++ b/Perspex.Direct2D1/Renderer.cs @@ -135,6 +135,7 @@ namespace Perspex.Direct2D1 transform *= Matrix.Translation(visual.Bounds.Position); + using (context.PushClip(visual.Bounds)) using (context.PushTransform(transform)) { visual.Render(context); diff --git a/Perspex.SceneGraph/Media/IDrawingContext.cs b/Perspex.SceneGraph/Media/IDrawingContext.cs index 0336fcbc94..38d98b6b43 100644 --- a/Perspex.SceneGraph/Media/IDrawingContext.cs +++ b/Perspex.SceneGraph/Media/IDrawingContext.cs @@ -56,6 +56,13 @@ namespace Perspex.Media /// The rectangle bounds. void FillRectange(Brush brush, Rect rect); + /// + /// Pushes a clip rectange. + /// + /// The clip rectangle. + /// A disposable used to undo the clip rectangle. + IDisposable PushClip(Rect clip); + /// /// Pushes a matrix transformation. /// diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index e7f869f077..2447fda627 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -83,8 +83,8 @@ namespace TestApplication static void Main(string[] args) { - LogManager.Enable(new TestLogger()); - LogManager.Instance.LogLayoutMessages = true; + //LogManager.Enable(new TestLogger()); + //LogManager.Instance.LogLayoutMessages = true; App application = new App {