Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Core / CSharp / System / Windows / Media / DrawingServices.cs / 1 / DrawingServices.cs
//---------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // Description: Implements services for Drawings including walking, bounding, // and hit-testing. // // History: // // 2004/11/19 : timothyc - Created it. // //--------------------------------------------------------------------------- using System.Diagnostics; using System.Windows.Media.Animation; namespace System.Windows.Media { ////// Implements services for Drawings including walking, bounding, and /// hit-testing. /// internal static class DrawingServices { ////// Determines whether or not a point exists in a Drawing /// /// Drawing to hit-test /// Point to hit-test for ////// 'true' if the point exists within the drawing, 'false' otherwise /// 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; } } ////// Hit-tests a Drawing against a PathGeometry /// /// The drawing to hit test against /// The geometry (in local coordinate space) to hit test. ////// IntersectionDetail that describes the hit result /// 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; } } ////// Converts a RenderData content representation into a DrawingGroup /// content representation. /// /// The RenderData to convert ////// A new DrawingGroup representation that is functionally equivalent to the /// passed-in RenderData. /// internal static DrawingGroup DrawingGroupFromRenderData(RenderData renderData) { // // Create & open a new DrawingGroup // DrawingGroup drawingGroup = new DrawingGroup(); DrawingContext dc = drawingGroup.Open(); // // Create a DrawingGroup from the RenderData by walking // the RenderData & having it forward it's base value's // and animations to DrawingGroup // // // The Drawing tree we're about to produce should not be an inheritance context, // since that would place all mutable Freezables in the render data into shared // state, which would in turn case them to lose their inheritance context entirely. // This is controlled by setting "CanBeInheritanceContext" to false on the // DrawingContext which will then be applied to all new objects it creates. // DrawingDrawingContext ddc = dc as DrawingDrawingContext; if (ddc != null) { ddc.CanBeInheritanceContext = false; } DrawingContextDrawingContextWalker walker = new DrawingContextDrawingContextWalker(dc); renderData.BaseValueDrawingContextWalk(walker); // // Close the DrawingContext & return the new DrawingGroup // dc.Close(); return drawingGroup; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // Description: Implements services for Drawings including walking, bounding, // and hit-testing. // // History: // // 2004/11/19 : timothyc - Created it. // //--------------------------------------------------------------------------- using System.Diagnostics; using System.Windows.Media.Animation; namespace System.Windows.Media { ////// Implements services for Drawings including walking, bounding, and /// hit-testing. /// internal static class DrawingServices { ////// Determines whether or not a point exists in a Drawing /// /// Drawing to hit-test /// Point to hit-test for ////// 'true' if the point exists within the drawing, 'false' otherwise /// 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; } } ////// Hit-tests a Drawing against a PathGeometry /// /// The drawing to hit test against /// The geometry (in local coordinate space) to hit test. ////// IntersectionDetail that describes the hit result /// 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; } } ////// Converts a RenderData content representation into a DrawingGroup /// content representation. /// /// The RenderData to convert ////// A new DrawingGroup representation that is functionally equivalent to the /// passed-in RenderData. /// internal static DrawingGroup DrawingGroupFromRenderData(RenderData renderData) { // // Create & open a new DrawingGroup // DrawingGroup drawingGroup = new DrawingGroup(); DrawingContext dc = drawingGroup.Open(); // // Create a DrawingGroup from the RenderData by walking // the RenderData & having it forward it's base value's // and animations to DrawingGroup // // // The Drawing tree we're about to produce should not be an inheritance context, // since that would place all mutable Freezables in the render data into shared // state, which would in turn case them to lose their inheritance context entirely. // This is controlled by setting "CanBeInheritanceContext" to false on the // DrawingContext which will then be applied to all new objects it creates. // DrawingDrawingContext ddc = dc as DrawingDrawingContext; if (ddc != null) { ddc.CanBeInheritanceContext = false; } DrawingContextDrawingContextWalker walker = new DrawingContextDrawingContextWalker(dc); renderData.BaseValueDrawingContextWalk(walker); // // Close the DrawingContext & return the new DrawingGroup // dc.Close(); return drawingGroup; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PeerNearMe.cs
- SiteMapNodeCollection.cs
- BitmapEffectvisualstate.cs
- SamlConstants.cs
- SafeNativeMethods.cs
- PartitionResolver.cs
- PbrsForward.cs
- ButtonFlatAdapter.cs
- HotSpotCollection.cs
- NullableConverter.cs
- NumberAction.cs
- DesigntimeLicenseContext.cs
- DeclaredTypeValidatorAttribute.cs
- TypeElement.cs
- CapabilitiesRule.cs
- InputGestureCollection.cs
- SecurityContext.cs
- HandlerFactoryCache.cs
- BindingsSection.cs
- Boolean.cs
- WmpBitmapEncoder.cs
- BasicExpandProvider.cs
- MSAAWinEventWrap.cs
- BufferedWebEventProvider.cs
- TemplateLookupAction.cs
- DesignerVerbCollection.cs
- DataGridRowAutomationPeer.cs
- ConfigurationManagerHelperFactory.cs
- NativeCppClassAttribute.cs
- OdbcErrorCollection.cs
- XamlSerializer.cs
- DataContractSerializerOperationBehavior.cs
- LogArchiveSnapshot.cs
- XmlAttributes.cs
- Popup.cs
- RealizationContext.cs
- CompiledIdentityConstraint.cs
- IdentifierCollection.cs
- PolyLineSegment.cs
- RtType.cs
- StyleTypedPropertyAttribute.cs
- FontStretchConverter.cs
- coordinatorscratchpad.cs
- OptimalBreakSession.cs
- AtomMaterializerLog.cs
- Executor.cs
- Executor.cs
- DBNull.cs
- DayRenderEvent.cs
- NullableDecimalAverageAggregationOperator.cs
- DataGridCommandEventArgs.cs
- UriSection.cs
- NavigatorInput.cs
- SmtpCommands.cs
- StringConcat.cs
- Trace.cs
- WindowsTab.cs
- SafeReadContext.cs
- FileNotFoundException.cs
- XmlComment.cs
- ClientScriptItemCollection.cs
- FontWeight.cs
- parserscommon.cs
- AppSettingsExpressionEditor.cs
- SemanticAnalyzer.cs
- SoapTransportImporter.cs
- DupHandleConnectionReader.cs
- PngBitmapEncoder.cs
- ZipFileInfoCollection.cs
- TextDocumentView.cs
- AssertUtility.cs
- BuildManagerHost.cs
- COM2ColorConverter.cs
- KeyValueConfigurationCollection.cs
- XmlSchemaSubstitutionGroup.cs
- SafeArchiveContext.cs
- WasEndpointConfigContainer.cs
- SecurityChannelFactory.cs
- StrongNamePublicKeyBlob.cs
- Compilation.cs
- ColorContext.cs
- XmlNamedNodeMap.cs
- SapiInterop.cs
- SerialPinChanges.cs
- DataTableClearEvent.cs
- SqlConnectionManager.cs
- DesignerActionService.cs
- ClientSideProviderDescription.cs
- AnonymousIdentificationModule.cs
- AppliedDeviceFiltersEditor.cs
- AuthenticatedStream.cs
- SecurityDocument.cs
- ZipQueryOperator.cs
- InvokeMethodActivityDesigner.cs
- Preprocessor.cs
- Point3DValueSerializer.cs
- ElementHostPropertyMap.cs
- NamedObject.cs
- ListViewItem.cs
- XmlQueryRuntime.cs