/// <summary> /// DrawDrawing - /// Draw a Drawing by appending a sub-Drawing to the current Drawing. /// </summary> /// <param name="drawing"> The drawing to draw. </param> public override void DrawDrawing( Drawing drawing) { if (drawing != null) { drawing.WalkCurrentValue(this); } }
/// <summary> /// Determines whether or not a point exists in a Drawing /// </summary> /// <param name="drawing"> Drawing to hit-test</param> /// <param name="point"> Point to hit-test for </param> /// <returns> /// 'true' if the point exists within the drawing, 'false' otherwise /// </returns> internal static bool HitTestPoint(Drawing drawing, Point point) { if (drawing != null) { HitTestDrawingContextWalker ctx = new HitTestWithPointDrawingContextWalker(point); drawing.WalkCurrentValue(ctx); return ctx.IsHit; } else { return false; } }
/// <summary> /// Determines whether or not a point exists in a Drawing /// </summary> /// <param name="drawing"> Drawing to hit-test</param> /// <param name="point"> Point to hit-test for </param> /// <returns> /// 'true' if the point exists within the drawing, 'false' otherwise /// </returns> internal static bool HitTestPoint(Drawing drawing, Point point) { if (drawing != null) { HitTestDrawingContextWalker ctx = new HitTestWithPointDrawingContextWalker(point); drawing.WalkCurrentValue(ctx); return(ctx.IsHit); } else { return(false); } }
/// <summary> /// Hit-tests a Drawing against a PathGeometry /// </summary> /// <param name="drawing"> The drawing to hit test against </param> /// <param name="geometry"> The geometry (in local coordinate space) to hit test. </param> /// <returns> /// IntersectionDetail that describes the hit result /// </returns> internal static IntersectionDetail HitTestGeometry(Drawing drawing, PathGeometry geometry) { if (drawing != null) { HitTestDrawingContextWalker ctx = new HitTestWithGeometryDrawingContextWalker(geometry); drawing.WalkCurrentValue(ctx); return ctx.IntersectionDetail; } else { return IntersectionDetail.Empty; } }
/// <summary> /// Hit-tests a Drawing against a PathGeometry /// </summary> /// <param name="drawing"> The drawing to hit test against </param> /// <param name="geometry"> The geometry (in local coordinate space) to hit test. </param> /// <returns> /// IntersectionDetail that describes the hit result /// </returns> internal static IntersectionDetail HitTestGeometry(Drawing drawing, PathGeometry geometry) { if (drawing != null) { HitTestDrawingContextWalker ctx = new HitTestWithGeometryDrawingContextWalker(geometry); drawing.WalkCurrentValue(ctx); return(ctx.IntersectionDetail); } else { return(IntersectionDetail.Empty); } }
/// <summary> /// Calls methods on the DrawingContext that are equivalent to the /// Drawing with the Drawing's current value. /// </summary> internal override void WalkCurrentValue(DrawingContextWalker ctx) { int popCount = 0; // We avoid unneccessary ShouldStopWalking checks based on assumptions // about when ShouldStopWalking is set. Guard that assumption with an // assertion. // // ShouldStopWalking is currently only set during a hit-test walk after // an object has been hit. Because a DrawingGroup can't be hit until after // the first Drawing is tested, this method doesn't check ShouldStopWalking // until after the first child. // // We don't need to add this check to other Drawing subclasses for // the same reason -- if the Drawing being tested isn't a DrawingGroup, // they are always the 'first child'. // // If this assumption is ever broken then the ShouldStopWalking // check should be done on the first child -- including in the // WalkCurrentValue method of other Drawing subclasses. Debug.Assert(!ctx.ShouldStopWalking); // // Draw the transform property // // Avoid calling PushTransform if the base value is set to the default and // no animations have been set on the property. if (!IsBaseValueDefault(DrawingGroup.TransformProperty) || (null != AnimationStorage.GetStorage(this, DrawingGroup.TransformProperty))) { ctx.PushTransform(Transform); popCount++; } // // Draw the clip property // // Avoid calling PushClip if the base value is set to the default and // no animations have been set on the property. if (!IsBaseValueDefault(DrawingGroup.ClipGeometryProperty) || (null != AnimationStorage.GetStorage(this, DrawingGroup.ClipGeometryProperty))) { ctx.PushClip(ClipGeometry); popCount++; } // // Draw the opacity property // // Avoid calling PushOpacity if the base value is set to the default and // no animations have been set on the property. if (!IsBaseValueDefault(DrawingGroup.OpacityProperty) || (null != AnimationStorage.GetStorage(this, DrawingGroup.OpacityProperty))) { // Push the current value of the opacity property, which // is what Opacity returns. ctx.PushOpacity(Opacity); popCount++; } // Draw the opacity mask property // if (OpacityMask != null) { ctx.PushOpacityMask(OpacityMask); popCount++; } // // Draw the effect property // // Push the current value of the effect property, which // is what BitmapEffect returns. if (BitmapEffect != null) { // Disable warning about obsolete method. This code must remain active // until we can remove the public BitmapEffect APIs. #pragma warning disable 0618 ctx.PushEffect(BitmapEffect, BitmapEffectInput); #pragma warning restore 0618 popCount++; } // // Draw the Children collection // // Get the current value of the children collection DrawingCollection collection = Children; // Call Walk on each child if (collection != null) { for (int i = 0; i < collection.Count; i++) { Drawing drawing = collection.Internal_GetItem(i); if (drawing != null) { drawing.WalkCurrentValue(ctx); // Don't visit the remaining children if the previous // child caused us to stop walking. if (ctx.ShouldStopWalking) { break; } } } } // // Call Pop() for every Push // // Avoid placing this logic in a finally block because if an exception is // thrown, the Walk is simply aborted. There is no requirement to Walk // through Pop instructions when an exception is thrown. // for (int i = 0; i < popCount; i++) { ctx.Pop(); } }
/// <summary> /// DrawDrawing - /// Draw a Drawing by appending a sub-Drawing to the current Drawing. /// </summary> /// <param name="drawing"> The drawing to draw. </param> public override void DrawDrawing( Drawing drawing) { if (drawing != null) { drawing.WalkCurrentValue(this); } }