16 changed files with 134 additions and 176 deletions
@ -1,14 +1,59 @@ |
|||
using System; |
|||
using Avalonia.Cairo.Media.Imaging; |
|||
using Avalonia.Media; |
|||
using Avalonia.Platform; |
|||
using Avalonia.Rendering.Utilities; |
|||
using Gdk; |
|||
using global::Cairo; |
|||
|
|||
namespace Avalonia.Cairo.Media |
|||
{ |
|||
public class ImageBrushImpl : BrushImpl |
|||
{ |
|||
public ImageBrushImpl(Avalonia.Media.ImageBrush brush, Size destinationSize) |
|||
{ |
|||
this.PlatformBrush = TileBrushes.CreateTileBrush(brush, destinationSize); |
|||
} |
|||
} |
|||
public ImageBrushImpl( |
|||
ITileBrush brush, |
|||
IBitmapImpl bitmap, |
|||
Size targetSize) |
|||
{ |
|||
var calc = new TileBrushCalculator(brush, new Size(bitmap.PixelWidth, bitmap.PixelHeight), targetSize); |
|||
|
|||
using (var intermediate = new ImageSurface(Format.ARGB32, (int)calc.IntermediateSize.Width, (int)calc.IntermediateSize.Height)) |
|||
{ |
|||
using (var context = new RenderTarget(intermediate).CreateDrawingContext(null)) |
|||
{ |
|||
var rect = new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight); |
|||
|
|||
context.Clear(Colors.Transparent); |
|||
context.PushClip(calc.IntermediateClip); |
|||
context.Transform = calc.IntermediateTransform; |
|||
context.DrawImage(bitmap, 1, rect, rect); |
|||
context.PopClip(); |
|||
} |
|||
|
|||
var result = new SurfacePattern(intermediate); |
|||
|
|||
if ((brush.TileMode & TileMode.FlipXY) != 0) |
|||
{ |
|||
// TODO: Currently always FlipXY as that's all cairo supports natively.
|
|||
// Support separate FlipX and FlipY by drawing flipped images to intermediate
|
|||
// surface.
|
|||
result.Extend = Extend.Reflect; |
|||
} |
|||
else |
|||
{ |
|||
result.Extend = Extend.Repeat; |
|||
} |
|||
|
|||
if (brush.TileMode != TileMode.None) |
|||
{ |
|||
var matrix = result.Matrix; |
|||
matrix.InitTranslate(-calc.DestinationRect.X, -calc.DestinationRect.Y); |
|||
result.Matrix = matrix; |
|||
} |
|||
|
|||
PlatformBrush = result; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
@ -1,55 +0,0 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using Cairo; |
|||
using Avalonia.Cairo.Media.Imaging; |
|||
using Avalonia.Layout; |
|||
using Avalonia.Media; |
|||
using Avalonia.Platform; |
|||
using Avalonia.Rendering; |
|||
using Avalonia.RenderHelpers; |
|||
|
|||
namespace Avalonia.Cairo.Media |
|||
{ |
|||
internal static class TileBrushes |
|||
{ |
|||
public static SurfacePattern CreateTileBrush(TileBrush brush, Size targetSize) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
//// var helper = new TileBrushImplHelper(brush, targetSize);
|
|||
//// if (!helper.IsValid)
|
|||
//// return null;
|
|||
|
|||
////using (var intermediate = new ImageSurface(Format.ARGB32, (int)helper.IntermediateSize.Width, (int)helper.IntermediateSize.Height))
|
|||
//// using (var ctx = new RenderTarget(intermediate).CreateDrawingContext())
|
|||
//// {
|
|||
//// helper.DrawIntermediate(new Avalonia.Media.DrawingContext(ctx));
|
|||
|
|||
//// var result = new SurfacePattern(intermediate);
|
|||
|
|||
//// if ((brush.TileMode & TileMode.FlipXY) != 0)
|
|||
//// {
|
|||
//// // TODO: Currently always FlipXY as that's all cairo supports natively.
|
|||
//// // Support separate FlipX and FlipY by drawing flipped images to intermediate
|
|||
//// // surface.
|
|||
//// result.Extend = Extend.Reflect;
|
|||
//// }
|
|||
//// else
|
|||
//// {
|
|||
//// result.Extend = Extend.Repeat;
|
|||
//// }
|
|||
|
|||
//// if (brush.TileMode != TileMode.None)
|
|||
//// {
|
|||
//// var matrix = result.Matrix;
|
|||
//// matrix.InitTranslate(-helper.DestinationRect.X, -helper.DestinationRect.Y);
|
|||
//// result.Matrix = matrix;
|
|||
//// }
|
|||
|
|||
//// return result;
|
|||
//// }
|
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
using System; |
|||
using global::Cairo; |
|||
|
|||
namespace Avalonia.Cairo.Media |
|||
{ |
|||
public class VisualBrushImpl : BrushImpl |
|||
{ |
|||
public VisualBrushImpl(Avalonia.Media.VisualBrush brush, Size destinationSize) |
|||
{ |
|||
this.PlatformBrush = TileBrushes.CreateTileBrush(brush, destinationSize); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
Before Width: | Height: | Size: 373 B After Width: | Height: | Size: 692 B |
|
After Width: | Height: | Size: 7.8 KiB |
Loading…
Reference in new issue