Browse Source

Implemented DestinationRect with TileMode.Tile.

pull/111/head
Steven Kirk 11 years ago
parent
commit
fcf151e2ae
  1. 38
      src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs
  2. 39
      tests/Perspex.RenderTests/Media/VisualBrushTests.cs

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

@ -40,11 +40,31 @@ namespace Perspex.Direct2D1.Media
var transform = Matrix.CreateTranslation(-sourceRect.Position) *
Matrix.CreateScale(scale) *
Matrix.CreateTranslation(translate);
renderer.Render(visual, null, transform, destinationRect);
Rect drawRect;
if (brush.TileMode == TileMode.None)
{
drawRect = destinationRect;
}
else
{
drawRect = new Rect(0, 0, destinationRect.Width, destinationRect.Height);
}
renderer.Render(visual, null, transform, drawRect);
var result = new BitmapBrush(brt, brt.Bitmap);
result.ExtendModeX = ExtendMode.Wrap;
result.ExtendModeY = ExtendMode.Wrap;
if (brush.TileMode != TileMode.None)
{
result.Transform = SharpDX.Matrix3x2.Translation(
(float)destinationRect.X,
(float)destinationRect.Y);
}
this.PlatformBrush = result;
}
}
@ -68,12 +88,12 @@ namespace Perspex.Direct2D1.Media
Rect destinationRect,
Vector scale)
{
var x = destinationRect.X;
var y = destinationRect.Y;
var size = sourceRect.Size * scale;
if (brush.TileMode == TileMode.None)
{
var x = destinationRect.X;
var y = destinationRect.Y;
var size = sourceRect.Size * scale;
switch (brush.AlignmentX)
{
case AlignmentX.Center:
@ -93,9 +113,13 @@ namespace Perspex.Direct2D1.Media
y += destinationRect.Height - size.Height;
break;
}
}
return new Vector(x, y);
return new Vector(x, y);
}
else
{
return new Vector();
}
}
public override void Dispose()

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

@ -434,5 +434,44 @@ namespace Perspex.Direct2D1.RenderTests.Media
this.RenderToFile(target);
this.CompareImages();
}
[Fact]
public void VisualBrush_Tile_DestinationRect()
{
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 200,
Height = 200,
Child = new Rectangle
{
Fill = new VisualBrush
{
Stretch = Stretch.None,
TileMode = TileMode.Tile,
DestinationRect = new RelativeRect(0.25, 0.25, 0.5, 0.5, OriginUnit.Percent),
Visual = new Border
{
Width = 92,
Height = 92,
Background = Brushes.Red,
BorderBrush = Brushes.Black,
BorderThickness = 2,
Child = new TextBlock
{
Text = "Perspex",
FontSize = 12,
FontFamily = "Arial",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
}
}
}
}
};
this.RenderToFile(target);
this.CompareImages();
}
}
}

Loading…
Cancel
Save