Browse Source

Added clipping to VisualBrush.DestinationRect.

pull/111/head
Steven Kirk 11 years ago
parent
commit
b2b50090ba
  1. 4
      src/Perspex.SceneGraph/Rendering/RendererBase.cs
  2. 2
      src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs
  3. 38
      tests/Perspex.RenderTests/Media/VisualBrushTests.cs
  4. BIN
      tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_SourceRect_DestinationRect_Absolute.expected.png

4
src/Perspex.SceneGraph/Rendering/RendererBase.cs

@ -43,9 +43,11 @@ namespace Perspex.Rendering
/// <param name="visual">The visual to render.</param>
/// <param name="handle">An optional platform-specific handle.</param>
/// <param name="transform">The transform.</param>
public virtual void Render(IVisual visual, IPlatformHandle handle, Matrix transform)
/// <param name="clip">An optional clip rectangle.</param>
public virtual void Render(IVisual visual, IPlatformHandle handle, Matrix transform, Rect? clip = null)
{
using (var context = this.CreateDrawingContext(handle))
using (clip.HasValue ? context.PushClip(clip.Value) : null)
{
this.Render(visual, context, Matrix.Identity, transform);
}

2
src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs

@ -40,7 +40,7 @@ namespace Perspex.Direct2D1.Media
var transform = Matrix.CreateTranslation(-sourceRect.Position) *
Matrix.CreateScale(scale) *
Matrix.CreateTranslation(translate);
renderer.Render(visual, null, transform);
renderer.Render(visual, null, transform, destinationRect);
var result = new BitmapBrush(brt, brt.Bitmap);
this.PlatformBrush = result;

38
tests/Perspex.RenderTests/Media/VisualBrushTests.cs

@ -320,5 +320,43 @@ namespace Perspex.Direct2D1.RenderTests.Media
this.RenderToFile(target);
this.CompareImages();
}
[Fact]
public void VisualBrush_SourceRect_DestinationRect_Absolute()
{
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 200,
Height = 200,
Child = new Rectangle
{
Fill = new VisualBrush
{
SourceRect = new RelativeRect(40, 40, 100, 100, OriginUnit.Pixels),
DestinationRect = new RelativeRect(92, 92, 92, 92, OriginUnit.Pixels),
Visual = new Border
{
Width = 180,
Height = 180,
Background = Brushes.Red,
BorderBrush = Brushes.Black,
BorderThickness = 2,
Child = new Ellipse
{
Width = 100,
Height = 100,
Fill = Brushes.Yellow,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
}
}
}
}
};
this.RenderToFile(target);
this.CompareImages();
}
}
}

BIN
tests/TestFiles/Direct2D1/Media/VisualBrush/VisualBrush_SourceRect_DestinationRect_Absolute.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Loading…
Cancel
Save