public static AdornerLayer GetAdornerLayer(IVisual visual) { return visual.GetVisualAncestors() .OfType<AdornerDecorator>() .FirstOrDefault() ?.AdornerLayer; }
/// <summary> /// Translates a point relative to this visual to coordinates that are relative to the specified visual. /// The visual and relativeTo should be descendants of the same root window /// </summary> /// <param name="visual">The visual.</param> /// <param name="point">The point value, as relative to this visual.</param> /// <param name="relativeTo">The visual to translate the given point into.</param> /// <returns>A point value, now relative to the target visual rather than this source element.</returns> public static Point TranslatePoint(this IVisual visual, Point point, IVisual relativeTo) { var pos = GetRootAndPosition(visual); var relToPos = GetRootAndPosition(relativeTo); return point - (relToPos.Item2 - pos.Item2); }
/// <summary> /// Renders the specified visual. /// </summary> /// <param name="visual">The visual to render.</param> /// /// <param name="context">The drawing context.</param> public static void Render(this DrawingContext context, IVisual visual) { var opacity = visual.Opacity; if (visual.IsVisible && opacity > 0) { var m = Matrix.CreateTranslation(visual.Bounds.Position); var renderTransform = Matrix.Identity; if (visual.RenderTransform != null) { var origin = visual.TransformOrigin.ToPixels(new Size(visual.Bounds.Width, visual.Bounds.Height)); var offset = Matrix.CreateTranslation(origin); renderTransform = (-offset)*visual.RenderTransform.Value*(offset); } m = renderTransform*m; using (context.PushPostTransform(m)) using (context.PushOpacity(opacity)) using (visual.ClipToBounds ? context.PushClip(new Rect(visual.Bounds.Size)) : default(DrawingContext.PushedState)) using (context.PushTransformContainer()) { visual.Render(context); foreach (var child in visual.VisualChildren.OrderBy(x => x.ZIndex)) { context.Render(child); } } } }
public void StartVisuals() { ParticleSystem ps = Instantiate(VFXPool.Instance.Sprays[SpellInformation.Elements[0].ToString()], StaffTransform.position, StaffTransform.rotation) as ParticleSystem; ps.transform.SetParent(StaffTransform); particleSystemAnchor = ps.GetComponent<IVisual>(); particleSystemAnchor.AuthorizeCollisionDetection(ref SpellInformation); }
/// <summary> /// Renders the specified visual with the specified transform and clip. /// </summary> /// <param name="visual">The visual to render.</param> /// <param name="handle">An optional platform-specific handle.</param> /// <param name="transform">The transform.</param> /// <param name="clip">An optional clip rectangle.</param> public virtual void Render(IVisual visual, IPlatformHandle handle, Matrix transform, Rect? clip = null) { using (var context = CreateDrawingContext(handle)) using (clip.HasValue ? context.PushClip(clip.Value) : null) { Render(visual, context, Matrix.Identity, transform); } }
private static bool IsHitTestVisible(IVisual visual) { var element = visual as IInputElement; return element != null && element.IsVisible && element.IsHitTestVisible && element.IsEnabledCore; }
/// <summary> /// Invalidates the render for the specified visual and raises <see cref="RenderNeeded"/>. /// </summary> /// <param name="visual">The visual.</param> public void InvalidateRender(IVisual visual) { if (!_renderQueued) { _renderNeeded.OnNext(Unit.Default); _renderQueued = true; } }
/// <summary> /// Renders the specified visual. /// </summary> /// <param name="visual">The visual to render.</param> /// <param name="handle">An optional platform-specific handle.</param> public virtual void Render(IVisual visual, IPlatformHandle handle) { using (var context = this.CreateDrawingContext(handle)) { this.Render(visual, context, Matrix.Identity, Matrix.Identity); } ++this.RenderCount; }
private static IVisual GetVisualParent(IVisual from, IVisual to) { var p1 = (from ?? to).VisualParent; var p2 = (to ?? from).VisualParent; if (p1 != null && p2 != null && p1 != p2) { throw new ArgumentException("Controls for PageSlide must have same parent."); } return p1; }
public Point GetPosition(IVisual relativeTo) { Point p = Position; IVisual v = relativeTo; while (v != null) { p -= v.Bounds.Position; v = v.VisualParent; } return p; }
/// <summary> /// Initializes a new instance of the Core class. /// </summary> public Core(IVisual visual) { this.visual = visual; physics = new Physics(this); FPS = defaultFPS; refreshTimer.Tick += (sender, e) => { if (visual.Visible) { lock (this) { visual.Refresh(); } } }; refreshTimer.Start(); physics.StartSimulation(FPS); }
/// <summary> /// Starts the animation. /// </summary> /// <param name="from"> /// The control that is being transitioned away from. May be null. /// </param> /// <param name="to"> /// The control that is being transitioned to. May be null. /// </param> /// <returns> /// A <see cref="Task"/> that tracks the progress of the animation. /// </returns> public async Task Start(IVisual from, IVisual to) { var tasks = new List<Task>(); if (to != null) { to.Opacity = 0; } if (from != null) { tasks.Add(Animate.Property( (IAvaloniaObject)from, Visual.OpacityProperty, from.Opacity, 0, LinearEasing.For<double>(), Duration).ToTask()); } if (to != null) { to.Opacity = 0; to.IsVisible = true; tasks.Add(Animate.Property( (IAvaloniaObject)to, Visual.OpacityProperty, 0, 1, LinearEasing.For<double>(), Duration).ToTask()); } await Task.WhenAll(tasks.ToArray()); if (from != null) { from.IsVisible = false; from.Opacity = 1; } if (to != null) { to.Opacity = 1; } }
/// <summary> /// Gets the root of the control's visual tree and the position of the control /// in the root's coordinate space. /// </summary> /// <param name="v">The visual.</param> /// <returns>A tuple containing the root and the position of the control.</returns> private static Tuple<IRenderRoot, Vector> GetRootAndPosition(IVisual v) { var result = new Vector(); while (!(v is IRenderRoot)) { result = new Vector(result.X + v.Bounds.X, result.Y + v.Bounds.Y); v = v.VisualParent; if (v == null) { throw new InvalidOperationException("Control is not attached to visual tree."); } } return Tuple.Create((IRenderRoot)v, result); }
private static void PrintVisualTree(IVisual visual, StringBuilder builder, int indent) { Control control = visual as Control; builder.Append(Indent(indent - 1)); if (indent > 0) { builder.Append(" +- "); } builder.Append(visual.GetType().Name); if (control != null) { builder.Append(" "); builder.AppendLine(control.Classes.ToString()); foreach (var property in AvaloniaPropertyRegistry.Instance.GetRegistered(control)) { var value = control.GetDiagnostic(property); if (value.Priority != BindingPriority.Unset) { builder.Append(Indent(indent)); builder.Append(" | "); builder.Append(value.Property.Name); builder.Append(" = "); builder.Append(value.Value ?? "(null)"); builder.Append(" ["); builder.Append(value.Priority); builder.AppendLine("]"); } } } else { builder.AppendLine(); } foreach (var child in visual.VisualChildren) { PrintVisualTree(child, builder, indent + 1); } }
public VisualTreeNode(IVisual visual) : base((Control)visual) { var host = visual as IVisualTreeHost; if (host?.Root == null) { Children = visual.VisualChildren.CreateDerivedCollection(x => new VisualTreeNode(x)); } else { Children = new ReactiveList<VisualTreeNode>(new[] { new VisualTreeNode(host.Root) }); } if (Control != null) { IsInTemplate = Control.TemplatedParent != null; } }
/// <summary> /// Starts the animation. /// </summary> /// <param name="from"> /// The control that is being transitioned away from. May be null. /// </param> /// <param name="to"> /// The control that is being transitioned to. May be null. /// </param> /// <param name="forward"> /// If true, the new page is slid in from the right, or if false from the left. /// </param> /// <returns> /// A <see cref="Task"/> that tracks the progress of the animation. /// </returns> public async Task Start(IVisual from, IVisual to, bool forward) { var tasks = new List<Task>(); var parent = GetVisualParent(from, to); var distance = parent.Bounds.Width; if (from != null) { var transform = new TranslateTransform(); from.RenderTransform = transform; tasks.Add(Animate.Property( transform, TranslateTransform.XProperty, 0.0, forward ? -distance : distance, LinearEasing.For<double>(), Duration).ToTask()); } if (to != null) { var transform = new TranslateTransform(); to.RenderTransform = transform; to.IsVisible = true; tasks.Add(Animate.Property( transform, TranslateTransform.XProperty, forward ? distance : -distance, 0.0, LinearEasing.For<double>(), Duration).ToTask()); } await Task.WhenAll(tasks.ToArray()); if (from != null) { from.IsVisible = false; } }
/// <summary> /// Renders the specified visual. /// </summary> /// <param name="visual">The visual to render.</param> /// <param name="context">The drawing context.</param> /// <param name="translation">The current translation.</param> /// <param name="transform">The current transform.</param> protected virtual void Render(IVisual visual, IDrawingContext context, Matrix translation, Matrix transform) { var opacity = visual.Opacity; if (visual.IsVisible && opacity > 0) { // Translate any existing transform into this controls coordinate system. Matrix offset = Matrix.CreateTranslation(visual.Bounds.Position); transform = offset * transform * -offset; // Update the current offset. translation *= Matrix.CreateTranslation(visual.Bounds.Position); // Apply the control's render transform, if any. if (visual.RenderTransform != null) { offset = Matrix.CreateTranslation(visual.TransformOrigin.ToPixels(visual.Bounds.Size)); transform *= -offset * visual.RenderTransform.Value * offset; } // Draw the control and its children. var m = transform * translation; var d = context.PushTransform(m); using (context.PushOpacity(opacity)) using (visual.ClipToBounds ? context.PushClip(visual.Bounds) : null) { visual.Render(context); d.Dispose(); foreach (var child in visual.VisualChildren.OrderBy(x => x.ZIndex)) { Render(child, context, translation, transform); } } } }
public static void RemoveDevTool(IVisual visual) { s_visualTreeRoots.Remove(visual.GetVisualRoot()); }
/// <summary> /// Called when the control's visual parent changes. /// </summary> /// <param name="oldParent">The old visual parent.</param> /// <param name="newParent">The new visual parent.</param> protected virtual void OnVisualParentChanged(IVisual oldParent, IVisual newParent) { RaisePropertyChanged(VisualParentProperty, oldParent, newParent, BindingPriority.LocalValue); }
public Point GetPosition(IVisual relativeTo) => _ev.GetPosition(relativeTo);
private IInteractive GetSource(IVisual hit) { return Captured ?? (hit as IInteractive) ?? hit.GetSelfAndVisualAncestors().OfType<IInteractive>().FirstOrDefault(); }
/// <inheritdoc/> public void RecalculateChildren(IVisual visual) => AddDirty(visual);
public Point GetPosition(IVisual relativeTo) { if (_rootVisual == null) { return(default);
/// <summary> /// Converts a point from screen to client coordinates. /// </summary> /// <param name="visual">The visual.</param> /// <param name="point">The point in screen coordinates.</param> /// <returns>The point in client coordinates.</returns> public static Point PointToClient(this IVisual visual, PixelPoint point) { var rootPoint = visual.VisualRoot.PointToClient(point); return(visual.VisualRoot.TranslatePoint(rootPoint, visual).Value); }
/// <summary> /// Gets the visual offset from the specified ancestor. /// </summary> /// <param name="ancestor">The ancestor visual.</param> /// <param name="visual">The visual.</param> /// <returns>The visual offset.</returns> private static Vector GetOffsetFrom(IVisual ancestor, IVisual visual) { var result = new Vector(); while (visual != ancestor) { result = new Vector(result.X + visual.Bounds.X, result.Y + visual.Bounds.Y); visual = visual.VisualParent; if (visual == null) { throw new ArgumentException("'visual' is not a descendent of 'ancestor'."); } } return result; }
public void N1() { Mock.Scene.Selected.Clear(); Mock.SetFocused(Mock.SampleFactory.Nodes[1]); // 1 Mock.SceneFacade.CollapseToFocused(); Assert.AreEqual(Mock.Scene.Graph.Count, 1); Mock.AreEquivalent(new IVisual[] { Mock.SampleFactory.Nodes[1] }, Mock.Scene.Graph); Mock.ProveShapes(Mock.Scene); var N1Expanded = new IVisual[] { Mock.SampleFactory.Nodes[1], // 1 Mock.SampleFactory.Nodes[2], // 2 Mock.SampleFactory.Nodes[3], // 3 Mock.SampleFactory.Nodes[4], // 4 Mock.SampleFactory.Edges[1], // [1->2] Mock.SampleFactory.Edges[2], // [4->3] Mock.SampleFactory.Edges[3], // [1->[4->3]] }; Mock.SceneFacade.Expand(false); Mock.AreEquivalent(N1Expanded, Mock.Scene.Graph); Mock.ProveShapes(Mock.Scene); Mock.Scene.Selected.Clear(); Mock.SetFocused(Mock.SampleFactory.Nodes[4]); // 4 Mock.SceneFacade.Expand(false); var N4Expanded = new IVisual[] { Mock.SampleFactory.Nodes[1], // 1 Mock.SampleFactory.Nodes[2], // 2 Mock.SampleFactory.Nodes[3], // 3 Mock.SampleFactory.Nodes[4], // 4 Mock.SampleFactory.Nodes[5], // 3 Mock.SampleFactory.Nodes[8], // 4 Mock.SampleFactory.Edges[1], // [1->2] Mock.SampleFactory.Edges[2], // [4->3] Mock.SampleFactory.Edges[3], // [1->[4->3]] Mock.SampleFactory.Edges[4], // [5->8] Mock.SampleFactory.Edges[8], //[[4->3]->[5->8]] }; Mock.AreEquivalent(N4Expanded, Mock.Scene.Graph); Mock.ProveShapes(Mock.Scene); Mock.Scene.Selected.Clear(); Mock.SetFocused(Mock.SampleFactory.Nodes[5]); Mock.SceneFacade.Expand(false); var N5Expanded = new IVisual[] { Mock.SampleFactory.Nodes[1], // 1 Mock.SampleFactory.Nodes[2], // 2 Mock.SampleFactory.Nodes[3], // 3 Mock.SampleFactory.Nodes[4], // 4 Mock.SampleFactory.Nodes[5], // 5 Mock.SampleFactory.Nodes[6], // 6 Mock.SampleFactory.Nodes[7], // 7 Mock.SampleFactory.Nodes[8], // 8 Mock.SampleFactory.Edges[1], // [1->2] Mock.SampleFactory.Edges[2], // [4->3] Mock.SampleFactory.Edges[3], // [1->[4->3]] Mock.SampleFactory.Edges[4], // [5->8] Mock.SampleFactory.Edges[5], // [5->6] Mock.SampleFactory.Edges[6], //[5->7] Mock.SampleFactory.Edges[8], //[[4->3]->[5->8]] }; Mock.AreEquivalent(N5Expanded, Mock.Scene.Graph); Mock.ProveShapes(Mock.Scene); var N5Collapsed = new IVisual[] { Mock.SampleFactory.Nodes[1], // 1 Mock.SampleFactory.Nodes[2], // 2 Mock.SampleFactory.Nodes[3], // 3 Mock.SampleFactory.Nodes[4], // 4 Mock.SampleFactory.Nodes[5], // 5 Mock.SampleFactory.Edges[1], // [1->2] Mock.SampleFactory.Edges[2], // [4->3] Mock.SampleFactory.Edges[3], // [1->[4->3]] }; Mock.SceneFacade.Collapse(); Mock.AreEquivalent(N5Collapsed, Mock.Scene.Graph); Mock.ProveShapes(Mock.Scene); Mock.SceneFacade.Expand(false); Mock.AreEquivalent(N5Expanded, Mock.Scene.Graph); Mock.ProveShapes(Mock.Scene); Mock.Scene.Selected.Clear(); Mock.SetFocused(Mock.SampleFactory.Nodes[8]); Mock.SceneFacade.Expand(false); Mock.AreEquivalent(FullExpanded, Mock.Scene.Graph); Mock.ProveShapes(Mock.Scene); Mock.SceneFacade.Collapse(); Mock.AreEquivalent(N5Expanded, Mock.Scene.Graph); Mock.ProveShapes(Mock.Scene); this.ReportSummary(); }
public void RenderToBuffer(IVisual visual, IntPtr pixels, int width, int height, int rowBytes) { throw new NotImplementedException(); }
IInputElement?GetNextCapture(IVisual parent) { return(parent as IInputElement ?? parent.FindAncestorOfType <IInputElement>()); }
internal static void SetDefaultVisual(IVisual visual) { _defaultVisual = visual; }
private static Point Position(IVisual v) { return(v.Bounds.Position); }
/// <summary> /// Sets the visual parent of the Visual. /// </summary> /// <param name="value">The visual parent.</param> private void SetVisualParent(Visual value) { if (_visualParent == value) { return; } var old = _visualParent; _visualParent = value; if (VisualRoot != null) { var e = new VisualTreeAttachmentEventArgs(VisualRoot); OnDetachedFromVisualTreeCore(e); } if (_visualParent is IRenderRoot || _visualParent?.IsAttachedToVisualTree == true) { var root = this.GetVisualAncestors().OfType<IRenderRoot>().FirstOrDefault(); var e = new VisualTreeAttachmentEventArgs(root); OnAttachedToVisualTreeCore(e); } OnVisualParentChanged(old, value); }
/// <summary> /// Converts a point from client to screen coordinates. /// </summary> /// <param name="visual">The visual.</param> /// <param name="point">The point in client coordinates.</param> /// <returns>The point in screen coordinates.</returns> public static PixelPoint PointToScreen(this IVisual visual, Point point) { var p = visual.TranslatePoint(point, visual.VisualRoot); return(visual.VisualRoot.PointToScreen(p.Value)); }
public Point GetPosition(IVisual relativeTo) { return Device.GetPosition(relativeTo); }
/// <summary> /// Sets the visual parent of the Visual. /// </summary> /// <param name="value">The visual parent.</param> private void SetVisualParent(Visual value) { if (_visualParent == value) { return; } var old = _visualParent; _visualParent = value; if (VisualRoot != null) { var e = new VisualTreeAttachmentEventArgs(VisualRoot); NotifyDetachedFromVisualTree(e); } if (_visualParent is IRenderRoot || _visualParent?.IsAttachedToVisualTree == true) { var root = this.GetVisualAncestors().OfType<IRenderRoot>().FirstOrDefault(); var e = new VisualTreeAttachmentEventArgs(root); NotifyAttachedToVisualTree(e); } RaisePropertyChanged(VisualParentProperty, old, value, BindingPriority.LocalValue); }
/// <summary> /// Renders the specified visual. /// </summary> /// <param name="visual">The visual to render.</param> /// <param name="context">The drawing context.</param> public static void Render(this DrawingContext context, IVisual visual) { context.Render(visual, visual.Bounds); }
public IVisual UpdateVisual(IRenderContext context, IVisual oldVisual) { return(CreateVisual(context)); }
/// <summary> /// Renders the specified visual. /// </summary> /// <param name="visual">The visual to render.</param> /// <param name="context">The drawing context.</param> /// <param name="clipRect"> /// The current clip rect, in coordinates relative to <paramref name="visual"/>. /// </param> private static void Render(this DrawingContext context, IVisual visual, Rect clipRect) { var opacity = visual.Opacity; var clipToBounds = visual.ClipToBounds; var bounds = new Rect(visual.Bounds.Size); if (visual.IsVisible && opacity > 0) { var m = Matrix.CreateTranslation(visual.Bounds.Position); var renderTransform = Matrix.Identity; if (visual.RenderTransform != null) { var origin = visual.RenderTransformOrigin.ToPixels(new Size(visual.Bounds.Width, visual.Bounds.Height)); var offset = Matrix.CreateTranslation(origin); renderTransform = (-offset) * visual.RenderTransform.Value * (offset); } m = renderTransform * m; if (clipToBounds) { clipRect = clipRect.Intersect(new Rect(visual.Bounds.Size)); } using (context.PushPostTransform(m)) using (context.PushOpacity(opacity)) using (clipToBounds ? context.PushClip(bounds) : default(DrawingContext.PushedState)) using (visual.Clip != null ? context.PushGeometryClip(visual.Clip) : default(DrawingContext.PushedState)) using (visual.OpacityMask != null ? context.PushOpacityMask(visual.OpacityMask, bounds) : default(DrawingContext.PushedState)) using (context.PushTransformContainer()) { visual.Render(context); #pragma warning disable 0618 var transformed = new TransformedBounds(bounds, new Rect(), context.CurrentContainerTransform); #pragma warning restore 0618 if (visual is Visual) { BoundsTracker.SetTransformedBounds((Visual)visual, transformed); } var lst = GetSortedVisualList(visual.VisualChildren); foreach (var child in lst) { var childBounds = GetTransformedBounds(child); if (!child.ClipToBounds || clipRect.Intersects(childBounds)) { var childClipRect = clipRect.Translate(-childBounds.Position); context.Render(child, childClipRect); } else { ClearTransformedBounds(child); } } ReturnListToPool(lst); } } if (!visual.IsVisible) { ClearTransformedBounds(visual); } }
/// <summary> /// Removes a visual child from the control; /// </summary> /// <param name="visual">The child to remove.</param> protected void RemoveVisualChild(IVisual visual) { Contract.Requires <ArgumentNullException>(visual != null); _visualChildren.Remove(visual); }
/// <summary> /// Renders an <see cref="IVisual"/> into the bitmap. /// </summary> /// <param name="visual">The visual to render.</param> /// <remarks> /// Before calling this method, ensure that <paramref name="visual"/> has been measured. /// </remarks> public void Render(IVisual visual) { this.PlatformImpl.Render(visual); }
public void Remove(IVisual element) { _items.Remove(element); }
public void AddDirty(IVisual visual) { }
public static bool BelongsToDevTool(IVisual visual) { return(s_visualTreeRoots.Contains(visual.GetVisualRoot())); }
public void RecalculateChildren(IVisual visual) => _recalculateChildren?.Add(visual);
private static Point Position(IVisual v) { return v.Bounds.Position; }
/// <summary> /// Gets the visuals at a point in the scene. /// </summary> /// <param name="p">The point.</param> /// <param name="root">The root of the subtree to search.</param> /// <param name="filter">A filter. May be null.</param> /// <returns>The visuals at the specified point.</returns> public IEnumerable <IVisual> HitTest(Point p, IVisual root, Func <IVisual, bool> filter) { var node = FindNode(root); return((node != null) ? new HitTestEnumerable(node, filter, p, Root) : Enumerable.Empty <IVisual>()); }
/// <summary> /// Ensures a visual child is not null and not already parented. /// </summary> /// <param name="c">The visual child.</param> private static void ValidateVisualChild(IVisual c) { if (c == null) { throw new ArgumentNullException("Cannot add null to VisualChildren."); } if (c.VisualParent != null) { throw new InvalidOperationException("The control already has a visual parent."); } }
/// <summary> /// Marks a visual as part of the DevTools, so it can be excluded from event tracking. /// </summary> /// <param name="visual">The visual whose root is to be marked.</param> public static void MarkAsDevTool(IVisual visual) { s_visualTreeRoots.Add(visual.GetVisualRoot()); }
public void Render(IVisual visual) { Renderer renderer = new Renderer(this.Surface); renderer.Render(visual, new PlatformHandle(IntPtr.Zero, "RTB")); }
public void Add(IVisual element) { _items.Add(element); }
/// <summary> /// Returns a transform that transforms the visual's coordinates into the coordinates /// of the specified <paramref name="visual"/>. /// </summary> /// <param name="visual">The visual to translate the coordinates to.</param> /// <returns> /// A <see cref="Matrix"/> containing the transform or null if the visuals don't share a /// common ancestor. /// </returns> public Matrix? TransformToVisual(IVisual visual) { var common = this.FindCommonVisualAncestor(visual); if (common != null) { var thisOffset = GetOffsetFrom(common, this); var thatOffset = GetOffsetFrom(common, visual); return Matrix.CreateTranslation(-thatOffset) * Matrix.CreateTranslation(thisOffset); } return null; }
/// <inheritdoc/> public bool Update(Scene scene, IVisual visual) { Contract.Requires <ArgumentNullException>(scene != null); Contract.Requires <ArgumentNullException>(visual != null); Dispatcher.UIThread.VerifyAccess(); if (!scene.Root.Visual.IsVisible) { throw new AvaloniaInternalException("Cannot update the scene for an invisible root visual."); } var node = (VisualNode)scene.FindNode(visual); if (visual == scene.Root.Visual) { UpdateSize(scene); } if (visual.VisualRoot != null) { if (visual.IsVisible) { // If the node isn't yet part of the scene, find the nearest ancestor that is. node = node ?? FindExistingAncestor(scene, visual); // We don't need to do anything if this part of the tree has already been fully // updated. if (node != null && !node.SubTreeUpdated) { // If the control we've been asked to update isn't part of the scene then // we're carrying out an add operation, so recurse and add all the // descendents too. var recurse = node.Visual != visual; using (var impl = new DeferredDrawingContextImpl(this, scene.Layers)) using (var context = new DrawingContext(impl)) { var clip = scene.Root.Visual.Bounds; if (node.Parent != null) { context.PushPostTransform(node.Parent.Transform); clip = node.Parent.ClipBounds; } using (context.PushTransformContainer()) { Update(context, scene, node, clip, recurse); } } return(true); } } else { if (node != null) { // The control has been hidden so remove it from its parent and deindex the // node and its descendents. ((VisualNode)node.Parent)?.RemoveChild(node); Deindex(scene, node); return(true); } } } else if (node != null) { // The control has been removed so remove it from its parent and deindex the // node and its descendents. var trim = FindFirstDeadAncestor(scene, node); ((VisualNode)trim.Parent).RemoveChild(trim); Deindex(scene, trim); return(true); } return(false); }
/// <summary> /// Ensures a visual child is not null. /// </summary> /// <param name="c">The visual child.</param> private static void ValidateLogicalChild(IVisual c) { if (c == null) { throw new ArgumentNullException("Cannot add null to VisualChildren."); } }
public static AdornerLayer?GetAdornerLayer(IVisual visual) { return(visual.FindAncestorOfType <VisualLayerManager>()?.AdornerLayer); }
private static int GetTabsCount(IVisual window) => window .GetVisualDescendants() .OfType <TabView>() .Count();
/// <inheritdoc/> public IEnumerable <IVisual> HitTest(Point p, IVisual root, Func <IVisual, bool> filter) { return(HitTest(root, p, filter)); }
public void AddVisualChild(IVisual visual) { VisualChildren.Add(visual); }
public IEnumerable <IVisual> HitTest(Point p, IVisual root, Func <IVisual, bool> filter) => null;
/// <summary> /// Attempts to bring a portion of the target visual into view by scrolling the content. /// </summary> /// <param name="target">The target visual.</param> /// <param name="targetRect">The portion of the target visual to bring into view.</param> /// <returns>True if the scroll offset was changed; otherwise false.</returns> public bool BringDescendentIntoView(IVisual target, Rect targetRect) { if (Child == null) { return false; } var transform = target.TransformToVisual(Child); if (transform == null) { return false; } var rect = targetRect * transform.Value; var offset = Offset; var result = false; if (rect.Bottom > offset.Y + Viewport.Height) { offset = offset.WithY((rect.Bottom - Viewport.Height) + Child.Margin.Top); result = true; } if (rect.Y < offset.Y) { offset = offset.WithY(rect.Y); result = true; } if (rect.Right > offset.X + Viewport.Width) { offset = offset.WithX((rect.Right - Viewport.Width) + Child.Margin.Left); result = true; } if (rect.X < offset.X) { offset = offset.WithX(rect.X); result = true; } if (result) { Offset = offset; } return result; }
/// <inheritdoc/> public void AddDirty(IVisual visual) { _dirty?.Add(visual); }