-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored DrawingContext and VisualBrush, added DrawingBrush (#10419)
Refactored DrawingContext and VisualBrush, added DrawingBrush
- Loading branch information
Showing
70 changed files
with
1,094 additions
and
945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Avalonia.Media.Immutable; | ||
using Avalonia.Rendering; | ||
using Avalonia.Rendering.Composition; | ||
using Avalonia.Rendering.Composition.Drawing; | ||
|
||
namespace Avalonia.Media | ||
{ | ||
/// <summary> | ||
/// Paints an area with an <see cref="Drawing"/>. | ||
/// </summary> | ||
public class DrawingBrush : TileBrush, ISceneBrush, IAffectsRender | ||
{ | ||
/// <summary> | ||
/// Defines the <see cref="Drawing"/> property. | ||
/// </summary> | ||
public static readonly StyledProperty<Drawing?> DrawingProperty = | ||
AvaloniaProperty.Register<DrawingBrush, Drawing?>(nameof(Drawing)); | ||
|
||
static DrawingBrush() | ||
{ | ||
AffectsRender<DrawingBrush>(DrawingProperty); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DrawingBrush"/> class. | ||
/// </summary> | ||
public DrawingBrush() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DrawingBrush"/> class. | ||
/// </summary> | ||
/// <param name="visual">The visual to draw.</param> | ||
public DrawingBrush(Drawing visual) | ||
{ | ||
Drawing = visual; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the visual to draw. | ||
/// </summary> | ||
public Drawing? Drawing | ||
{ | ||
get { return GetValue(DrawingProperty); } | ||
set { SetValue(DrawingProperty, value); } | ||
} | ||
|
||
ISceneBrushContent? ISceneBrush.CreateContent() | ||
{ | ||
if (Drawing == null) | ||
return null; | ||
|
||
|
||
var recorder = new CompositionDrawingContext(); | ||
recorder.BeginUpdate(null); | ||
Drawing?.Draw(recorder); | ||
var drawList = recorder.EndUpdate(); | ||
if (drawList == null) | ||
return null; | ||
|
||
return new CompositionDrawListSceneBrushContent(new ImmutableSceneBrush(this), drawList, | ||
drawList.CalculateBounds(), true); | ||
} | ||
} | ||
} |
Oops, something went wrong.