|
|
|
@ -10,7 +10,6 @@ using Avalonia.Collections; |
|
|
|
using Avalonia.Data; |
|
|
|
using Avalonia.Logging; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Platform; |
|
|
|
using Avalonia.Rendering; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
|
|
|
|
@ -20,10 +19,10 @@ namespace Avalonia |
|
|
|
/// Base class for controls that provides rendering and related visual properties.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// The <see cref="Visual"/> class acts as a node in the Avalonia scene graph and holds
|
|
|
|
/// all the information needed for an <see cref="IRenderTarget"/> to render the control.
|
|
|
|
/// To traverse the scene graph (aka Visual Tree), use the extension methods defined
|
|
|
|
/// in <see cref="VisualExtensions"/>.
|
|
|
|
/// The <see cref="Visual"/> class represents elements that have a visual on-screen
|
|
|
|
/// representation and stores all the information needed for an
|
|
|
|
/// <see cref="IRenderer"/> to render the control. To traverse the visual tree, use the
|
|
|
|
/// extension methods defined in <see cref="VisualExtensions"/>.
|
|
|
|
/// </remarks>
|
|
|
|
public class Visual : Animatable, IVisual |
|
|
|
{ |
|
|
|
@ -88,6 +87,7 @@ namespace Avalonia |
|
|
|
AvaloniaProperty.Register<Visual, int>(nameof(ZIndex)); |
|
|
|
|
|
|
|
private Rect _bounds; |
|
|
|
private IRenderRoot _visualRoot; |
|
|
|
private IVisual _visualParent; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -95,7 +95,12 @@ namespace Avalonia |
|
|
|
/// </summary>
|
|
|
|
static Visual() |
|
|
|
{ |
|
|
|
AffectsRender(BoundsProperty, IsVisibleProperty, OpacityProperty); |
|
|
|
AffectsRender( |
|
|
|
BoundsProperty, |
|
|
|
ClipProperty, |
|
|
|
ClipToBoundsProperty, |
|
|
|
IsVisibleProperty, |
|
|
|
OpacityProperty); |
|
|
|
RenderTransformProperty.Changed.Subscribe(RenderTransformChanged); |
|
|
|
} |
|
|
|
|
|
|
|
@ -122,7 +127,7 @@ namespace Avalonia |
|
|
|
public event EventHandler<VisualTreeAttachmentEventArgs> DetachedFromVisualTree; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the bounds of the scene graph node relative to its parent.
|
|
|
|
/// Gets the bounds of the control relative to its parent.
|
|
|
|
/// </summary>
|
|
|
|
public Rect Bounds |
|
|
|
{ |
|
|
|
@ -131,7 +136,7 @@ namespace Avalonia |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a value indicating whether the scene graph node should be clipped to its bounds.
|
|
|
|
/// Gets a value indicating whether the control should be clipped to its bounds.
|
|
|
|
/// </summary>
|
|
|
|
public bool ClipToBounds |
|
|
|
{ |
|
|
|
@ -149,7 +154,7 @@ namespace Avalonia |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a value indicating whether this scene graph node and all its parents are visible.
|
|
|
|
/// Gets a value indicating whether this control and all its parents are visible.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsEffectivelyVisible |
|
|
|
{ |
|
|
|
@ -157,7 +162,7 @@ namespace Avalonia |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a value indicating whether this scene graph node is visible.
|
|
|
|
/// Gets a value indicating whether this control is visible.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsVisible |
|
|
|
{ |
|
|
|
@ -166,7 +171,7 @@ namespace Avalonia |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the opacity of the scene graph node.
|
|
|
|
/// Gets the opacity of the control.
|
|
|
|
/// </summary>
|
|
|
|
public double Opacity |
|
|
|
{ |
|
|
|
@ -174,9 +179,8 @@ namespace Avalonia |
|
|
|
set { SetValue(OpacityProperty, value); } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the opacity mask of the scene graph node.
|
|
|
|
/// Gets the opacity mask of the control.
|
|
|
|
/// </summary>
|
|
|
|
public IBrush OpacityMask |
|
|
|
{ |
|
|
|
@ -185,7 +189,7 @@ namespace Avalonia |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the render transform of the scene graph node.
|
|
|
|
/// Gets the render transform of the control.
|
|
|
|
/// </summary>
|
|
|
|
public Transform RenderTransform |
|
|
|
{ |
|
|
|
@ -194,7 +198,7 @@ namespace Avalonia |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the transform origin of the scene graph node.
|
|
|
|
/// Gets the transform origin of the control.
|
|
|
|
/// </summary>
|
|
|
|
public RelativePoint RenderTransformOrigin |
|
|
|
{ |
|
|
|
@ -203,7 +207,7 @@ namespace Avalonia |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the Z index of the node.
|
|
|
|
/// Gets the Z index of the control.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// Controls with a higher <see cref="ZIndex"/> will appear in front of controls with
|
|
|
|
@ -217,7 +221,7 @@ namespace Avalonia |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the control's visual children.
|
|
|
|
/// Gets the control's child visuals.
|
|
|
|
/// </summary>
|
|
|
|
protected IAvaloniaList<IVisual> VisualChildren |
|
|
|
{ |
|
|
|
@ -228,24 +232,20 @@ namespace Avalonia |
|
|
|
/// <summary>
|
|
|
|
/// Gets the root of the visual tree, if the control is attached to a visual tree.
|
|
|
|
/// </summary>
|
|
|
|
protected IRenderRoot VisualRoot |
|
|
|
{ |
|
|
|
get; |
|
|
|
private set; |
|
|
|
} |
|
|
|
protected IRenderRoot VisualRoot => _visualRoot ?? (this as IRenderRoot); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a value indicating whether this scene graph node is attached to a visual root.
|
|
|
|
/// Gets a value indicating whether this control is attached to a visual root.
|
|
|
|
/// </summary>
|
|
|
|
bool IVisual.IsAttachedToVisualTree => VisualRoot != null; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the scene graph node's child nodes.
|
|
|
|
/// Gets the control's child controls.
|
|
|
|
/// </summary>
|
|
|
|
IAvaloniaReadOnlyList<IVisual> IVisual.VisualChildren => VisualChildren; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the scene graph node's parent node.
|
|
|
|
/// Gets the control's parent visual.
|
|
|
|
/// </summary>
|
|
|
|
IVisual IVisual.VisualParent => _visualParent; |
|
|
|
|
|
|
|
@ -321,7 +321,7 @@ namespace Avalonia |
|
|
|
{ |
|
|
|
Logger.Verbose(LogArea.Visual, this, "Attached to visual tree"); |
|
|
|
|
|
|
|
VisualRoot = e.Root; |
|
|
|
_visualRoot = e.Root; |
|
|
|
|
|
|
|
if (RenderTransform != null) |
|
|
|
{ |
|
|
|
@ -329,6 +329,7 @@ namespace Avalonia |
|
|
|
} |
|
|
|
|
|
|
|
OnAttachedToVisualTree(e); |
|
|
|
InvalidateVisual(); |
|
|
|
|
|
|
|
if (VisualChildren != null) |
|
|
|
{ |
|
|
|
@ -348,7 +349,7 @@ namespace Avalonia |
|
|
|
{ |
|
|
|
Logger.Verbose(LogArea.Visual, this, "Detached from visual tree"); |
|
|
|
|
|
|
|
VisualRoot = null; |
|
|
|
_visualRoot = null; |
|
|
|
|
|
|
|
if (RenderTransform != null) |
|
|
|
{ |
|
|
|
@ -356,6 +357,7 @@ namespace Avalonia |
|
|
|
} |
|
|
|
|
|
|
|
OnDetachedFromVisualTree(e); |
|
|
|
e.Root?.Renderer?.AddDirty(this); |
|
|
|
|
|
|
|
if (VisualChildren != null) |
|
|
|
{ |
|
|
|
@ -492,11 +494,11 @@ namespace Avalonia |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var old = _visualParent; |
|
|
|
_visualParent = value; |
|
|
|
|
|
|
|
if (VisualRoot != null) |
|
|
|
if (_visualRoot != null) |
|
|
|
{ |
|
|
|
var e = new VisualTreeAttachmentEventArgs(old, VisualRoot); |
|
|
|
OnDetachedFromVisualTreeCore(e); |
|
|
|
|