internal override HitTestResultBehavior HitTestPointInternal( HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters hitTestParameters) { if (_children.Count != 0) { double distanceAdjustment; RayHitTestParameters rayParams = Camera.RayFromViewportPoint( hitTestParameters.HitPoint, Viewport.Size, BBoxSubgraph, out distanceAdjustment); HitTestResultBehavior result = Visual3D.HitTestChildren(filterCallback, rayParams, this); return rayParams.RaiseCallback(resultCallback, filterCallback, result, distanceAdjustment); } return HitTestResultBehavior.Continue; }
/// <summary> /// Static helper used by ModelVisual3D and Viewport3DVisual to hit test /// against their children collections. /// </summary> internal static HitTestResultBehavior HitTestChildren( HitTestFilterCallback filterCallback, RayHitTestParameters rayParams, IVisual3DContainer container) { if (container != null) { int childrenCount = container.GetChildrenCount(); for (int i = childrenCount - 1; i >= 0; i--) { Visual3D child = container.GetChild(i); // Visuall3D.RayHitTest does not apply the Visual3D's Transform. We need to // transform into the content's space before hit testing. Transform3D transform = child.Transform; rayParams.PushVisualTransform(transform); // Perform the hit-test against the child. HitTestResultBehavior result = child.RayHitTest(filterCallback, rayParams); rayParams.PopTransform(transform); if (result == HitTestResultBehavior.Stop) { return HitTestResultBehavior.Stop; } } } return HitTestResultBehavior.Continue; }
public static HitTestResult HitTest(Visual reference, HitTestParameters hitTestParameters, bool ignoreDisabled, HitTestFilterCallback filterCallback) { HitTestResult hitTestResult = (HitTestResult)null; HitTestResultCallback resultCallback = (HitTestResultCallback)(hitItemsResult => { hitTestResult = hitItemsResult; return(HitTestResultBehavior.Stop); }); HitTestFilterCallback filterCallback1 = (HitTestFilterCallback)(hit => { UIElement uiElement = hit as UIElement; if (uiElement != null && (!uiElement.IsVisible || !uiElement.IsHitTestVisible || ignoreDisabled && !uiElement.IsEnabled)) { return(HitTestFilterBehavior.ContinueSkipSelfAndChildren); } HitTestFilterBehavior testFilterBehavior = HitTestFilterBehavior.Continue; if (filterCallback != null) { testFilterBehavior = filterCallback(hit); } return(testFilterBehavior); }); VisualTreeHelper.HitTest(reference, filterCallback1, resultCallback, hitTestParameters); return(hitTestResult); }
void RunHitTest(Visual reference, Point point, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback) { if (!Keyboard.IsKeyDown(Key.LeftAlt)) { hitTestElements.Clear(); skippedHitTestElements.Clear(); } VisualTreeHelper.HitTest(reference, filterCallback, resultCallback, new PointHitTestParameters(point)); }
internal HitTestResultBehavior RayHitTest( HitTestFilterCallback filterCallback, RayHitTestParameters rayParams) { if (DoesRayHitSubgraphBounds(rayParams)) { // // Determine if there is a special filter behavior defined for this // Visual. // HitTestFilterBehavior behavior = HitTestFilterBehavior.Continue; if (filterCallback != null) { behavior = filterCallback(this); if (HTFBInterpreter.SkipSubgraph(behavior)) return HitTestResultBehavior.Continue; if (HTFBInterpreter.Stop(behavior)) return HitTestResultBehavior.Stop; } // // Hit test against the children. // if (HTFBInterpreter.IncludeChildren(behavior)) { HitTestResultBehavior result = HitTestChildren(filterCallback, rayParams); if (result == HitTestResultBehavior.Stop) return HitTestResultBehavior.Stop; } // // Hit test against the content of this Visual. // if (HTFBInterpreter.DoHitTest(behavior)) { RayHitTestInternal(filterCallback, rayParams); } } return HitTestResultBehavior.Continue; }
internal HitTestResultBehavior HitTestPoint( HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters pointParams) { // we do not need parameter checks because they are done in HitTest() Geometry clip = VisualClip; // Before we continue hit-testing we check against the hit-test bounds for the sub-graph. // If the point is not with-in the hit-test bounds, the sub-graph can be skipped. if (_bboxSubgraph.Contains(pointParams.HitPoint) && ((null == clip) || clip.FillContains(pointParams.HitPoint))) // Check that the hit-point is with-in the clip. { // // Determine if there is a special filter behavior defined for this // Visual. // HitTestFilterBehavior filter = HitTestFilterBehavior.Continue; if (filterCallback != null) { filter = filterCallback(this); if (filter == HitTestFilterBehavior.ContinueSkipSelfAndChildren) { return HitTestResultBehavior.Continue; } if (filter == HitTestFilterBehavior.Stop) { return HitTestResultBehavior.Stop; } } // if there is a bitmap effect transform the point // Backup the hit point so that we can restore it later on. Point originalHitPoint = pointParams.HitPoint; Point hitPoint = originalHitPoint; if (CheckFlagsAnd(VisualFlags.NodeHasEffect)) { Effect imageEffect = EffectField.GetValue(this); if (imageEffect != null) { GeneralTransform effectHitTestInverse = imageEffect.EffectMapping.Inverse; // only do work if the transform isn't the identity transform if (effectHitTestInverse != Transform.Identity) { bool ok = false; // Convert to unit space Point? unitHitPoint = Effect.WorldToUnit(originalHitPoint, _bboxSubgraph); if (unitHitPoint != null) { Point transformedPt = new Point(); // Do the transform if (effectHitTestInverse.TryTransform(unitHitPoint.Value, out transformedPt)) { // Convert back to world space Point? worldSpace = Effect.UnitToWorld(transformedPt, _bboxSubgraph); if (worldSpace != null) { hitPoint = worldSpace.Value; ok = true; } } } if (!ok) { return HitTestResultBehavior.Continue; } } } else { Debug.Assert(BitmapEffectStateField.GetValue(this) != null); // BitmapEffects are deprecated so they no longer affect hit testing. } } // // Hit test against the children. // if (filter != HitTestFilterBehavior.ContinueSkipChildren) { int childCount = VisualChildrenCount; for (int i=childCount-1; i>=0; i--) { Visual child = GetVisualChild(i); if (child != null) { // Hit the scollClip bounds first, which are in the child's outer-space. Rect? scrollClip = ScrollableAreaClipField.GetValue(child); if (scrollClip.HasValue && !scrollClip.Value.Contains(hitPoint)) { // Skip child if the point is not within the ScrollableClip. continue; } // // Transform the hit-test point below offset and transform. // Point newHitPoint = hitPoint; // Apply the offset. newHitPoint = newHitPoint - child._offset; // If we have a transform, apply the transform. Transform childTransform = TransformField.GetValue(child); if (childTransform != null) { Matrix inv = childTransform.Value; // If we can't invert the transform, the child is not hitable. This makes sense since // the node's rendered content is degenerate, i.e. does not really take up any space. // Skip the child by continuing in the loop. if (!inv.HasInverse) { continue; } inv.Invert(); newHitPoint = newHitPoint * inv; } // Set the new hittesting point into the hittest params. pointParams.SetHitPoint(newHitPoint); // Perform the hit-test against the child. HitTestResultBehavior result = child.HitTestPoint(filterCallback, resultCallback, pointParams); // Restore the hit-test point. pointParams.SetHitPoint(originalHitPoint); if (result == HitTestResultBehavior.Stop) { return HitTestResultBehavior.Stop; } } } } // // Hit test against the content of this Visual. // if (filter != HitTestFilterBehavior.ContinueSkipSelf) { // set the transformed hit point pointParams.SetHitPoint(hitPoint); HitTestResultBehavior result = HitTestPointInternal(filterCallback, resultCallback, pointParams); // restore the hit point back to its original pointParams.SetHitPoint(originalHitPoint); if (result == HitTestResultBehavior.Stop) { return HitTestResultBehavior.Stop; } } } return HitTestResultBehavior.Continue; }
/// <summary> /// This method provides an internal extension point for Viewport3DVisual /// to grab the HitTestFilterCallback and ResultDelegate before it gets lost in the /// forward to HitTestCore. /// </summary> internal virtual HitTestResultBehavior HitTestPointInternal( HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, PointHitTestParameters hitTestParameters) { HitTestResult hitResult = HitTestCore(hitTestParameters); if (hitResult != null) { return resultCallback(hitResult); } return HitTestResultBehavior.Continue; }
public void HitTest(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters hitTestParameters) { }
internal HitTestResultBehavior RaiseCallback(HitTestResultCallback resultCallback, HitTestFilterCallback filterCallback, HitTestResultBehavior lastResult) { return RaiseCallback(resultCallback, filterCallback, lastResult, 0.0 /* distance adjustment */); }
public static void HitTest(System.Windows.Media.Media3D.Visual3D reference, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, System.Windows.Media.Media3D.HitTestParameters3D hitTestParameters) { Contract.Requires(reference != null); }
public static void HitTest(Visual reference, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters hitTestParameters) { Contract.Requires(reference != null); }
public IEnumerable<IElement> HitTest(IPoint point, double radius) { var canvas = this; var selectedElements = new List<DependencyObject>(); var elippse = new EllipseGeometry() { RadiusX = radius, RadiusY = radius, Center = new Point(point.X, point.Y) }; var hitTestParams = new GeometryHitTestParameters(elippse); var resultCallback = new HitTestResultCallback(result => HitTestResultBehavior.Continue); var filterCallback = new HitTestFilterCallback( element => { if (VisualTreeHelper.GetParent(element) == canvas) selectedElements.Add(element); return HitTestFilterBehavior.Continue; }); VisualTreeHelper.HitTest(canvas, filterCallback, resultCallback, hitTestParams); return selectedElements.Cast<IElement>(); }
public IEnumerable<IElement> HitTest(IRect rect) { var canvas = this; var r = new Rect(new Point(rect.X1, rect.Y1), new Point(rect.X2, rect.Y2)); var selectedElements = new List<DependencyObject>(); var rectangle = new RectangleGeometry(r, 0.0, 0.0); var hitTestParams = new GeometryHitTestParameters(rectangle); var resultCallback = new HitTestResultCallback(result => HitTestResultBehavior.Continue); var filterCallback = new HitTestFilterCallback( element => { if (VisualTreeHelper.GetParent(element) == canvas) selectedElements.Add(element); return HitTestFilterBehavior.Continue; }); VisualTreeHelper.HitTest(canvas, filterCallback, resultCallback, hitTestParams); return selectedElements.Cast<IElement>(); }
public HitTestFilterCallbackWrapper(HitTestFilterCallback filterCallback) { this._filterCallback = filterCallback; this._wrappedFilterCallback = new HitTestFilterCallback(this.OnFilterHitResult); }
private static void endCreation(Connection newConnection) { DesignArea designArea = newConnection.DesignArea; // Remove the mouse move and mouse up listeners designArea.MouseMove -= newConnection.creationMouseMoveListener; designArea.MouseUp -= newConnection.creationMouseUpListener; // Check if the mouse is currently intersecting with a input variable HitTestFilterCallback filterCallback = new HitTestFilterCallback(element => element == newConnection ? HitTestFilterBehavior.ContinueSkipSelfAndChildren : HitTestFilterBehavior.Continue); HitTestResultCallback resultCallback = new HitTestResultCallback(element => finalizeCreation(element, newConnection)); VisualTreeHelper.HitTest(designArea.Canvas, filterCallback, resultCallback, new PointHitTestParameters(newConnection.EndPoint)); }
internal HitTestResultBehavior RaiseCallback(HitTestResultCallback resultCallback, HitTestFilterCallback filterCallback, HitTestResultBehavior lastResult, double distanceAdjustment) { results.Sort(RayHitTestResult.CompareByDistanceToRayOrigin); for(int i = 0, count = results.Count; i < count; i++) { RayHitTestResult result = results[i]; result.SetDistanceToRayOrigin(result.DistanceToRayOrigin + distanceAdjustment); Viewport2DVisual3D viewport2DVisual3D = result.VisualHit as Viewport2DVisual3D; if (viewport2DVisual3D != null) { Point intersectionPoint; Visual viewport2DVisual3DChild = viewport2DVisual3D.Visual; if (viewport2DVisual3DChild != null) { if (Viewport2DVisual3D.GetIntersectionInfo(result, out intersectionPoint)) { // convert the resulting point to visual coordinates Point visualPoint = Viewport2DVisual3D.TextureCoordsToVisualCoords(intersectionPoint, viewport2DVisual3DChild); GeneralTransform gt = viewport2DVisual3DChild.TransformToOuterSpace().Inverse; Point pointOnChild; if (gt != null && gt.TryTransform(visualPoint, out pointOnChild)) { HitTestResultBehavior behavior2D = viewport2DVisual3DChild.HitTestPoint(filterCallback, resultCallback, new PointHitTestParameters(pointOnChild)); if (behavior2D == HitTestResultBehavior.Stop) { return HitTestResultBehavior.Stop; } } } } } HitTestResultBehavior behavior = resultCallback(results[i]); if (behavior == HitTestResultBehavior.Stop) { return HitTestResultBehavior.Stop; } } return lastResult; }
/// <summary> /// Initiate a hit test using delegates. /// </summary> internal void HitTest( HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters hitTestParameters) { if (resultCallback == null) { throw new ArgumentNullException("resultCallback"); } if (hitTestParameters == null) { throw new ArgumentNullException("hitTestParameters"); } VerifyAPIReadWrite(); Precompute(); PointHitTestParameters pointParams = hitTestParameters as PointHitTestParameters; if (pointParams != null) { // Because we call dynamic code during the hit testing walk we need to back up // the original hit point in case the user's delegate throws an exception so that // we can restore it. Point backupHitPoint = pointParams.HitPoint; try { HitTestPoint(filterCallback, resultCallback, pointParams); } catch { // If an exception occured, restore the user's hit point and rethrow. pointParams.SetHitPoint(backupHitPoint); throw; } finally { Debug.Assert(Point.Equals(pointParams.HitPoint, backupHitPoint), "Failed to restore user's hit point back to the original coordinate system."); } } else { GeometryHitTestParameters geometryParams = hitTestParameters as GeometryHitTestParameters; if (geometryParams != null) { // Because we call dynamic code during the hit testing walk we need to ensure // that if the user's delegate throws an exception we restore the original // transform on the hit test geometry. #if DEBUG // Internally we replace the hit geometry with a copy which is guaranteed to have // a MatrixTransform so we do not need to worry about null dereferences here. Matrix originalMatrix = geometryParams.InternalHitGeometry.Transform.Value; #endif // DEBUG try { HitTestGeometry(filterCallback, resultCallback, geometryParams); } catch { geometryParams.EmergencyRestoreOriginalTransform(); throw; } #if DEBUG finally { Debug.Assert(Matrix.Equals(geometryParams.InternalHitGeometry.Transform.Value, originalMatrix), "Failed to restore user's hit geometry back to the original coordinate system."); } #endif // DEBUG } else { // This should never happen, users can not extend the abstract HitTestParameters class. Invariant.Assert(false, String.Format(System.Globalization.CultureInfo.InvariantCulture, "'{0}' HitTestParameters are not supported on {1}.", hitTestParameters.GetType().Name, this.GetType().Name)); } } }
private IEnumerable<HitTestResult> GetHits(HitTestFilterCallback htrcb, Point position) { var results = new List<HitTestResult>(); HitTestResultCallback cb = delegate(HitTestResult result) { results.Add(result); return HitTestResultBehavior.Continue; }; VisualTreeHelper.HitTest(mainViewport, htrcb, cb, new PointHitTestParameters(position)); return results; }
internal HitTestResultBehavior HitTestGeometry( HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, GeometryHitTestParameters geometryParams) { // we do not need parameter checks because they are done in HitTest() Geometry clip = VisualClip; if (clip != null) { // HitTest with a Geometry and a clip should hit test with // the intersection of the geometry and the clip, not the entire geometry IntersectionDetail intersectionDetail = clip.FillContainsWithDetail(geometryParams.InternalHitGeometry); Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated); if (intersectionDetail == IntersectionDetail.Empty) { // bail out if there is a clip and this region is not inside return HitTestResultBehavior.Continue; } } // // Check if the geometry intersects with our hittest bounds. // If not, the Visual is not hit-testable at all. if (_bboxSubgraph.IntersectsWith(geometryParams.Bounds)) { // // Determine if there is a special filter behavior defined for this // Visual. // HitTestFilterBehavior filter = HitTestFilterBehavior.Continue; if (filterCallback != null) { filter = filterCallback(this); if (filter == HitTestFilterBehavior.ContinueSkipSelfAndChildren) { return HitTestResultBehavior.Continue; } if (filter == HitTestFilterBehavior.Stop) { return HitTestResultBehavior.Stop; } } // // Hit-test against the children. // int childCount = VisualChildrenCount; if (filter != HitTestFilterBehavior.ContinueSkipChildren) { for (int i=childCount-1; i>=0; i--) { Visual child = GetVisualChild(i); if (child != null) { // Hit the scollClip bounds first, which are in the child's outer-space. Rect? scrollClip = ScrollableAreaClipField.GetValue(child); if (scrollClip.HasValue) { // Hit-testing with a Geometry and a clip should hit test with // the intersection of the geometry and the clip, not the entire geometry RectangleGeometry rectClip = new RectangleGeometry(scrollClip.Value); IntersectionDetail intersectionDetail = rectClip.FillContainsWithDetail(geometryParams.InternalHitGeometry); Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated); if (intersectionDetail == IntersectionDetail.Empty) { // Skip child if there is a scrollable clip and this region is not inside it. continue; } } // Transform the geometry below offset and transform. Matrix inv = Matrix.Identity; inv.Translate(-child._offset.X, -child._offset.Y); Transform childTransform = TransformField.GetValue(child); if (childTransform != null) { Matrix m = childTransform.Value; // If we can't invert the transform, the child is not hitable. This makes sense since // the node's rendered content is degnerated, i.e. does not really take up any space. // Skipping the child by continuing the loop. if (!m.HasInverse) { continue; } // Inverse the transform. m.Invert(); // Multiply the inverse and the offset together. // inv = inv * m; MatrixUtil.MultiplyMatrix(ref inv, ref m); } // Push the transform on the geometry params. geometryParams.PushMatrix(ref inv); // Hit-Test against the children. HitTestResultBehavior result = child.HitTestGeometry(filterCallback, resultCallback, geometryParams); // Pop the transform from the geometry params. geometryParams.PopMatrix(); // Process the result. if (result == HitTestResultBehavior.Stop) { return HitTestResultBehavior.Stop; } } } } // // Hit-test against the content of the Visual. // if (filter != HitTestFilterBehavior.ContinueSkipSelf) { GeometryHitTestResult hitResult = HitTestCore(geometryParams); if (hitResult != null) { Debug.Assert(resultCallback != null); return resultCallback(hitResult); } } } return HitTestResultBehavior.Continue; }
/// <summary> /// Initiate a hit test using delegates. /// </summary> public static void HitTest( Visual3D reference, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters3D hitTestParameters) { CheckVisualReferenceArgument(reference); reference.HitTest(filterCallback, resultCallback, hitTestParameters); }
/// <summary> /// Re-exposes the Visual base class's corresponding VisualTreeHelper implementation as public method. /// </summary> new public void HitTest(HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters hitTestParameters) { base.HitTest(filterCallback, resultCallback, hitTestParameters); }
public static void HitTest (Visual visual, HitTestFilterCallback filter, HitTestResultCallback results, HitTestParameters parameters) { throw new NotImplementedException (); }
/// <summary> /// Initiate a hit test using delegates. /// </summary> internal void HitTest( HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback, HitTestParameters3D hitTestParameters) { if (resultCallback == null) { throw new ArgumentNullException("resultCallback"); } if (hitTestParameters == null) { throw new ArgumentNullException("hitTestParameters"); } VerifyAPIReadWrite(); RayHitTestParameters rayParams = hitTestParameters as RayHitTestParameters; if (rayParams != null) { // In case the user is reusing the same RayHitTestParameters rayParams.ClearResults(); HitTestResultBehavior result = RayHitTest(filterCallback, rayParams); rayParams.RaiseCallback(resultCallback, filterCallback, result); } else { // This should never happen, users can not extend the abstract HitTestParameters3D class. Invariant.Assert(false, String.Format(System.Globalization.CultureInfo.InvariantCulture, "'{0}' HitTestParameters3D are not supported on {1}.", hitTestParameters.GetType().Name, this.GetType().Name)); } }
public List<DependencyObject> HitTest(Visual visual, IPoint point, double radius) { var elements = new List<DependencyObject>(); var elippse = new EllipseGeometry() { RadiusX = radius, RadiusY = radius, Center = new Point(point.X, point.Y), }; var hitTestParams = new GeometryHitTestParameters(elippse); var resultCallback = new HitTestResultCallback(result => HitTestResultBehavior.Continue); var filterCallback = new HitTestFilterCallback( element => { elements.Add(element); return HitTestFilterBehavior.Continue; }); VisualTreeHelper.HitTest(visual, filterCallback, resultCallback, hitTestParams); return elements; }
internal HitTestResultBehavior HitTestChildren( HitTestFilterCallback filterCallback, RayHitTestParameters rayParams) { return HitTestChildren(filterCallback, rayParams, this); }
void RunHitTest(Visual reference, Point point, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback) { VisualTreeHelper.HitTest(reference, filterCallback, resultCallback, new PointHitTestParameters(point)); }
internal void RayHitTestInternal( HitTestFilterCallback filterCallback, RayHitTestParameters rayParams) { Model3D model = _visual3DModel; if (model != null) { // If our Model3D hit test intersects anything we should return "this" Visual3D // as the HitTestResult.VisualHit. rayParams.CurrentVisual = this; model.RayHitTest(rayParams); } }
internal static HitTestResult HitTest(Visual reference, Point point, bool ignoreDisabled, HitTestFilterCallback filterCallback) { return(HitTestHelper.HitTest(reference, (HitTestParameters) new PointHitTestParameters(point), ignoreDisabled, filterCallback)); }