bool TryGetInvertedTransform(CompositionVisual visual, out Matrix matrix) { var m = visual.TryGetServerGlobalTransform(); if (m == null) { matrix = default; return(false); } var m33 = MatrixUtils.ToMatrix(m.Value); return(m33.TryInvert(out matrix)); }
/// <summary> /// Attempts to transform a point to a particular CompositionVisual coordinate space /// </summary> /// <returns></returns> public Point?TryTransformToVisual(CompositionVisual visual, Point point) { if (visual.Root != this) { return(null); } var v = visual; var m = Matrix.Identity; while (v != null) { if (!TryGetInvertedTransform(v, out var cm)) { return(null); } m = m * cm; v = v.Parent; } return(point * m); }
void HitTestCore(CompositionVisual visual, Point globalPoint, PooledList <CompositionVisual> result, Func <IVisual, bool>?filter) { if (visual.Visible == false) { return; } if (!TryTransformTo(visual, globalPoint, out var point)) { return; } if (visual.ClipToBounds && (point.X < 0 || point.Y < 0 || point.X > visual.Size.X || point.Y > visual.Size.Y)) { return; } if (visual.Clip?.FillContains(point) == false) { return; } // Inspect children if (visual is CompositionContainerVisual cv) { for (var c = cv.Children.Count - 1; c >= 0; c--) { var ch = cv.Children[c]; HitTestCore(ch, globalPoint, result, filter); } } // Hit-test the current node if (visual.HitTest(point, filter)) { result.Add(visual); } }
partial void OnRemoved(CompositionVisual item) => item.Parent = null;
partial void OnAdded(CompositionVisual item) => item.Parent = _owner;
public void InsertAtBottom(CompositionVisual newChild) => Insert(0, newChild);
public void InsertAtTop(CompositionVisual newChild) => Insert(_list.Count, newChild);
internal CompositionVisualCollection(CompositionVisual parent, ServerCompositionVisualCollection server) : base(parent.Compositor, server) { _owner = parent; InitializeDefaults(); }