committed by
GitHub
60 changed files with 926 additions and 210 deletions
@ -0,0 +1,89 @@ |
|||||
|
using System; |
||||
|
using System.Diagnostics; |
||||
|
using System.Drawing.Drawing2D; |
||||
|
using System.Security.Cryptography; |
||||
|
using Avalonia; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.LogicalTree; |
||||
|
using Avalonia.Media; |
||||
|
using Avalonia.Media.Imaging; |
||||
|
using Avalonia.Media.Immutable; |
||||
|
using Avalonia.Threading; |
||||
|
using Avalonia.Visuals.Media.Imaging; |
||||
|
|
||||
|
namespace RenderDemo.Pages |
||||
|
{ |
||||
|
public class PathMeasurementPage : Control |
||||
|
{ |
||||
|
static PathMeasurementPage() |
||||
|
{ |
||||
|
AffectsRender<PathMeasurementPage>(BoundsProperty); |
||||
|
} |
||||
|
|
||||
|
private RenderTargetBitmap _bitmap; |
||||
|
|
||||
|
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) |
||||
|
{ |
||||
|
_bitmap = new RenderTargetBitmap(new PixelSize(500, 500), new Vector(96, 96)); |
||||
|
base.OnAttachedToLogicalTree(e); |
||||
|
} |
||||
|
|
||||
|
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e) |
||||
|
{ |
||||
|
_bitmap.Dispose(); |
||||
|
_bitmap = null; |
||||
|
base.OnDetachedFromLogicalTree(e); |
||||
|
} |
||||
|
|
||||
|
readonly IPen strokePen = new ImmutablePen(Brushes.DarkBlue, 10d, null, PenLineCap.Round, PenLineJoin.Round); |
||||
|
readonly IPen strokePen1 = new ImmutablePen(Brushes.Purple, 10d, null, PenLineCap.Round, PenLineJoin.Round); |
||||
|
readonly IPen strokePen2 = new ImmutablePen(Brushes.Green, 10d, null, PenLineCap.Round, PenLineJoin.Round); |
||||
|
readonly IPen strokePen3 = new ImmutablePen(Brushes.LightBlue, 10d, null, PenLineCap.Round, PenLineJoin.Round); |
||||
|
readonly IPen strokePen4 = new ImmutablePen(Brushes.Red, 1d, null, PenLineCap.Round, PenLineJoin.Round); |
||||
|
|
||||
|
public override void Render(DrawingContext context) |
||||
|
{ |
||||
|
using (var ctxi = _bitmap.CreateDrawingContext(null)) |
||||
|
using (var bitmapCtx = new DrawingContext(ctxi, false)) |
||||
|
{ |
||||
|
ctxi.Clear(default); |
||||
|
|
||||
|
var basePath = new PathGeometry(); |
||||
|
|
||||
|
using (var basePathCtx = basePath.Open()) |
||||
|
{ |
||||
|
basePathCtx.BeginFigure(new Point(20, 20), false); |
||||
|
basePathCtx.LineTo(new Point(400, 50)); |
||||
|
basePathCtx.LineTo(new Point(80, 100)); |
||||
|
basePathCtx.LineTo(new Point(300, 150)); |
||||
|
basePathCtx.EndFigure(false); |
||||
|
} |
||||
|
|
||||
|
bitmapCtx.DrawGeometry(null, strokePen, basePath); |
||||
|
|
||||
|
|
||||
|
var length = basePath.PlatformImpl.ContourLength; |
||||
|
|
||||
|
if (basePath.PlatformImpl.TryGetSegment(length * 0.05, length * 0.2, true, out var dst1)) |
||||
|
bitmapCtx.DrawGeometry(null, strokePen1, dst1); |
||||
|
|
||||
|
if (basePath.PlatformImpl.TryGetSegment(length * 0.2, length * 0.8, true, out var dst2)) |
||||
|
bitmapCtx.DrawGeometry(null, strokePen2, dst2); |
||||
|
|
||||
|
if (basePath.PlatformImpl.TryGetSegment(length * 0.8, length * 0.95, true, out var dst3)) |
||||
|
bitmapCtx.DrawGeometry(null, strokePen3, dst3); |
||||
|
|
||||
|
var pathBounds = basePath.GetRenderBounds(strokePen); |
||||
|
|
||||
|
bitmapCtx.DrawRectangle(null, strokePen4, pathBounds); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
context.DrawImage(_bitmap, |
||||
|
new Rect(0, 0, 500, 500), |
||||
|
new Rect(0, 0, 500, 500)); |
||||
|
|
||||
|
base.Render(context); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
using Avalonia.Interactivity; |
||||
|
using Avalonia.VisualTree; |
||||
|
|
||||
|
namespace Avalonia.Input |
||||
|
{ |
||||
|
public class TappedEventArgs : RoutedEventArgs |
||||
|
{ |
||||
|
private readonly PointerEventArgs lastPointerEventArgs; |
||||
|
|
||||
|
public TappedEventArgs(RoutedEvent routedEvent, PointerEventArgs lastPointerEventArgs) |
||||
|
: base(routedEvent) |
||||
|
{ |
||||
|
this.lastPointerEventArgs = lastPointerEventArgs; |
||||
|
} |
||||
|
|
||||
|
public Point GetPosition(IVisual? relativeTo) => lastPointerEventArgs.GetPosition(relativeTo); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
Compat issues with assembly Avalonia.Visuals: |
||||
|
InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.PopBitmapBlendMode()' is present in the implementation but not in the contract. |
||||
|
InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Platform.IDrawingContextImpl.PushBitmapBlendMode(Avalonia.Visuals.Media.Imaging.BitmapBlendingMode)' is present in the implementation but not in the contract. |
||||
|
InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength' is present in the implementation but not in the contract. |
||||
|
InterfacesShouldHaveSameMembers : Interface member 'public System.Double Avalonia.Platform.IGeometryImpl.ContourLength.get()' is present in the implementation but not in the contract. |
||||
|
InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAndTangentAtDistance(System.Double, Avalonia.Point, Avalonia.Point)' is present in the implementation but not in the contract. |
||||
|
InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetPointAtDistance(System.Double, Avalonia.Point)' is present in the implementation but not in the contract. |
||||
|
InterfacesShouldHaveSameMembers : Interface member 'public System.Boolean Avalonia.Platform.IGeometryImpl.TryGetSegment(System.Double, System.Double, System.Boolean, Avalonia.Platform.IGeometryImpl)' is present in the implementation but not in the contract. |
||||
|
Total Issues: 7 |
||||
@ -0,0 +1,57 @@ |
|||||
|
namespace Avalonia.Visuals.Media.Imaging |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Controls the way the bitmaps are drawn together.
|
||||
|
/// </summary>
|
||||
|
public enum BitmapBlendingMode |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Source is placed over the destination.
|
||||
|
/// </summary>
|
||||
|
SourceOver, |
||||
|
/// <summary>
|
||||
|
/// Only the source will be present.
|
||||
|
/// </summary>
|
||||
|
Source, |
||||
|
/// <summary>
|
||||
|
/// Only the destination will be present.
|
||||
|
/// </summary>
|
||||
|
Destination, |
||||
|
/// <summary>
|
||||
|
/// Destination is placed over the source.
|
||||
|
/// </summary>
|
||||
|
DestinationOver, |
||||
|
/// <summary>
|
||||
|
/// The source that overlaps the destination, replaces the destination.
|
||||
|
/// </summary>
|
||||
|
SourceIn, |
||||
|
/// <summary>
|
||||
|
/// Destination which overlaps the source, replaces the source.
|
||||
|
/// </summary>
|
||||
|
DestinationIn, |
||||
|
/// <summary>
|
||||
|
/// Source is placed, where it falls outside of the destination.
|
||||
|
/// </summary>
|
||||
|
SourceOut, |
||||
|
/// <summary>
|
||||
|
/// Destination is placed, where it falls outside of the source.
|
||||
|
/// </summary>
|
||||
|
DestinationOut, |
||||
|
/// <summary>
|
||||
|
/// Source which overlaps the destination, replaces the destination.
|
||||
|
/// </summary>
|
||||
|
SourceAtop, |
||||
|
/// <summary>
|
||||
|
/// Destination which overlaps the source replaces the source.
|
||||
|
/// </summary>
|
||||
|
DestinationAtop, |
||||
|
/// <summary>
|
||||
|
/// The non-overlapping regions of source and destination are combined.
|
||||
|
/// </summary>
|
||||
|
Xor, |
||||
|
/// <summary>
|
||||
|
/// Display the sum of the source image and destination image.
|
||||
|
/// </summary>
|
||||
|
Plus, |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
using Avalonia.Platform; |
||||
|
using Avalonia.Visuals.Media.Imaging; |
||||
|
|
||||
|
namespace Avalonia.Rendering.SceneGraph |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// A node in the scene graph which represents an bitmap blending mode push or pop.
|
||||
|
/// </summary>
|
||||
|
internal class BitmapBlendModeNode : IDrawOperation |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="BitmapBlendModeNode"/> class that represents an
|
||||
|
/// <see cref="BitmapBlendingMode"/> push.
|
||||
|
/// </summary>
|
||||
|
/// <param name="bitmapBlend">The <see cref="BitmapBlendingMode"/> to push.</param>
|
||||
|
public BitmapBlendModeNode(BitmapBlendingMode bitmapBlend) |
||||
|
{ |
||||
|
BlendingMode = bitmapBlend; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="BitmapBlendNode"/> class that represents an
|
||||
|
/// <see cref="BitmapBlendingMode"/> pop.
|
||||
|
/// </summary>
|
||||
|
public BitmapBlendModeNode() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public Rect Bounds => Rect.Empty; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the BitmapBlend to be pushed or null if the operation represents a pop.
|
||||
|
/// </summary>
|
||||
|
public BitmapBlendingMode? BlendingMode { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public bool HitTest(Point p) => false; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Determines if this draw operation equals another.
|
||||
|
/// </summary>
|
||||
|
/// <param name="opacity">The opacity of the other draw operation.</param>
|
||||
|
/// <returns>True if the draw operations are the same, otherwise false.</returns>
|
||||
|
/// <remarks>
|
||||
|
/// The properties of the other draw operation are passed in as arguments to prevent
|
||||
|
/// allocation of a not-yet-constructed draw operation object.
|
||||
|
/// </remarks>
|
||||
|
public bool Equals(BitmapBlendingMode? blendingMode) => BlendingMode == blendingMode; |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public void Render(IDrawingContextImpl context) |
||||
|
{ |
||||
|
if (BlendingMode.HasValue) |
||||
|
{ |
||||
|
context.PushBitmapBlendMode(BlendingMode.Value); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
context.PopBitmapBlendMode(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue