csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.9 KiB
68 lines
1.9 KiB
using System;
|
|
using Avalonia.Platform;
|
|
using Avalonia.Rendering.Composition;
|
|
using Avalonia.Rendering.Composition.Server;
|
|
using Avalonia.Rendering.Composition.Transport;
|
|
using Avalonia.Rendering.SceneGraph;
|
|
|
|
namespace Avalonia.Controls;
|
|
|
|
class CompositionBorderVisual : CompositionDrawListVisual
|
|
{
|
|
private CornerRadius _cornerRadius;
|
|
private bool _cornerRadiusChanged;
|
|
|
|
public CompositionBorderVisual(Compositor compositor, Visual visual) : base(compositor,
|
|
new ServerBorderVisual(compositor.Server, visual), visual)
|
|
{
|
|
}
|
|
|
|
public CornerRadius CornerRadius
|
|
{
|
|
get => _cornerRadius;
|
|
set
|
|
{
|
|
if (_cornerRadius != value)
|
|
{
|
|
_cornerRadiusChanged = true;
|
|
_cornerRadius = value;
|
|
RegisterForSerialization();
|
|
}
|
|
}
|
|
}
|
|
|
|
private protected override void SerializeChangesCore(BatchStreamWriter writer)
|
|
{
|
|
base.SerializeChangesCore(writer);
|
|
writer.Write(_cornerRadiusChanged);
|
|
if (_cornerRadiusChanged)
|
|
writer.Write(_cornerRadius);
|
|
}
|
|
|
|
class ServerBorderVisual : ServerCompositionDrawListVisual
|
|
{
|
|
private CornerRadius _cornerRadius;
|
|
public ServerBorderVisual(ServerCompositor compositor, Visual v) : base(compositor, v)
|
|
{
|
|
}
|
|
|
|
protected override void DeserializeChangesCore(BatchStreamReader reader, TimeSpan committedAt)
|
|
{
|
|
base.DeserializeChangesCore(reader, committedAt);
|
|
if (reader.Read<bool>())
|
|
_cornerRadius = reader.Read<CornerRadius>();
|
|
}
|
|
|
|
|
|
protected override void PushClipToBounds(IDrawingContextImpl canvas)
|
|
{
|
|
var clipRect = new Rect(new Size(Size.X, Size.Y));
|
|
if (_cornerRadius == default)
|
|
canvas.PushClip(clipRect);
|
|
else
|
|
canvas.PushClip(new RoundedRect(clipRect, _cornerRadius));
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|