|
|
@ -31,7 +31,7 @@ namespace Perspex.Direct2D1.Media |
|
|
var sourceSize = layoutable.Bounds.Size; |
|
|
var sourceSize = layoutable.Bounds.Size; |
|
|
var destinationRect = brush.DestinationRect.ToPixels(destinationSize); |
|
|
var destinationRect = brush.DestinationRect.ToPixels(destinationSize); |
|
|
var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceSize); |
|
|
var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceSize); |
|
|
var translate = new Rect(destinationSize).CenterIn(new Rect(sourceSize * scale)).Position; |
|
|
var translate = CalculateTranslate(brush, destinationRect.Size, sourceSize * scale); |
|
|
|
|
|
|
|
|
using (var brt = new BitmapRenderTarget( |
|
|
using (var brt = new BitmapRenderTarget( |
|
|
target, |
|
|
target, |
|
|
@ -44,6 +44,34 @@ namespace Perspex.Direct2D1.Media |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Vector CalculateTranslate(VisualBrush brush, Size destinationSize, Size sourceSize) |
|
|
|
|
|
{ |
|
|
|
|
|
double x = 0; |
|
|
|
|
|
double y = 0; |
|
|
|
|
|
|
|
|
|
|
|
switch (brush.AlignmentX) |
|
|
|
|
|
{ |
|
|
|
|
|
case AlignmentX.Center: |
|
|
|
|
|
x = (destinationSize.Width - sourceSize.Width) / 2; |
|
|
|
|
|
break; |
|
|
|
|
|
case AlignmentX.Right: |
|
|
|
|
|
x = destinationSize.Width - sourceSize.Width; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (brush.AlignmentY) |
|
|
|
|
|
{ |
|
|
|
|
|
case AlignmentY.Center: |
|
|
|
|
|
y = (destinationSize.Height - sourceSize.Height) / 2; |
|
|
|
|
|
break; |
|
|
|
|
|
case AlignmentY.Bottom: |
|
|
|
|
|
y = destinationSize.Height - sourceSize.Height; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new Vector(x, y); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public override void Dispose() |
|
|
public override void Dispose() |
|
|
{ |
|
|
{ |
|
|
((BitmapBrush)this.PlatformBrush).Bitmap.Dispose(); |
|
|
((BitmapBrush)this.PlatformBrush).Bitmap.Dispose(); |
|
|
|