10 changed files with 207 additions and 31 deletions
@ -0,0 +1,29 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="VisualBrush.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
public class VisualBrush : Brush |
|||
{ |
|||
public static readonly PerspexProperty<IVisual> VisualProperty = |
|||
PerspexProperty.Register<VisualBrush, IVisual>("Visual"); |
|||
|
|||
public VisualBrush() |
|||
{ |
|||
} |
|||
|
|||
public VisualBrush(IVisual visual) |
|||
{ |
|||
this.Visual = visual; |
|||
} |
|||
|
|||
public IVisual Visual |
|||
{ |
|||
get { return this.GetValue(VisualProperty); } |
|||
set { this.SetValue(VisualProperty, value); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Disposable.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Direct2D1 |
|||
{ |
|||
using System; |
|||
|
|||
public class Disposable<T> : IDisposable where T : IDisposable |
|||
{ |
|||
private IDisposable extra; |
|||
|
|||
public Disposable(T inner) |
|||
{ |
|||
this.Inner = inner; |
|||
} |
|||
|
|||
public Disposable(T inner, IDisposable extra) |
|||
{ |
|||
this.Inner = inner; |
|||
this.extra = extra; |
|||
} |
|||
|
|||
public T Inner { get; } |
|||
|
|||
public static implicit operator T(Disposable<T> i) |
|||
{ |
|||
return i.Inner; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
this.Inner.Dispose(); |
|||
this.extra?.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="VisualBrushTests.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Direct2D1.RenderTests.Controls |
|||
{ |
|||
using Perspex.Controls; |
|||
using Perspex.Controls.Shapes; |
|||
using Perspex.Layout; |
|||
using Perspex.Media; |
|||
using Xunit; |
|||
|
|||
public class VisualBrushTests : TestBase |
|||
{ |
|||
public VisualBrushTests() |
|||
: base(@"Brushes\VisualBrush") |
|||
{ |
|||
} |
|||
|
|||
[Fact] |
|||
public void VisualBrush_Should_Draw_Visual() |
|||
{ |
|||
Decorator target = new Decorator |
|||
{ |
|||
Padding = new Thickness(8), |
|||
Width = 200, |
|||
Height = 200, |
|||
Child = new Rectangle |
|||
{ |
|||
Fill = new VisualBrush |
|||
{ |
|||
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…
Reference in new issue