|
22 | 22 |
|
23 | 23 | using DpiScale = SharpVectors.Runtime.DpiScale;
|
24 | 24 | using DpiUtilities = SharpVectors.Runtime.DpiUtilities;
|
| 25 | +using System.Linq; |
25 | 26 |
|
26 | 27 | namespace WpfTestSvgControl
|
27 | 28 | {
|
@@ -124,6 +125,8 @@ public partial class DrawingPage : Page
|
124 | 125 | private FoldingManager _foldingManager;
|
125 | 126 | private XmlFoldingStrategy _foldingStrategy;
|
126 | 127 |
|
| 128 | + private IList<Color> _colors; |
| 129 | + |
127 | 130 | #endregion
|
128 | 131 |
|
129 | 132 | #region Constructors and Destructor
|
@@ -180,7 +183,14 @@ public DrawingPage()
|
180 | 183 | this.Unloaded += OnPageUnloaded;
|
181 | 184 | this.SizeChanged += OnPageSizeChanged;
|
182 | 185 |
|
183 |
| -// svgViewer.Hits += OnDrawingHits; |
| 186 | + // svgViewer.Hits += OnDrawingHits; |
| 187 | + |
| 188 | + var colors = from System.Reflection.PropertyInfo property in typeof(Colors).GetProperties() |
| 189 | + orderby property.Name |
| 190 | + //orderby ((Color)property.GetValue(null, null)).ToString() |
| 191 | + select (Color)property.GetValue(null, null); |
| 192 | + |
| 193 | + _colors = colors.ToList(); |
184 | 194 | }
|
185 | 195 |
|
186 | 196 | //private void OnDrawingHits(object sender, SvgDrawingHitArgs args)
|
@@ -483,6 +493,56 @@ protected DrawingGroup WrapDrawing(DrawingGroup currentDrawing)
|
483 | 493 | return currentDrawing;
|
484 | 494 | }
|
485 | 495 |
|
| 496 | + System.Windows.Media.DrawingVisual _drawingVisual = null; |
| 497 | + |
| 498 | + |
| 499 | + private void DrawDebugHitList(IList<Drawing> drawings, IList<WpfHitPath> hitPaths) |
| 500 | + { |
| 501 | + if (drawings == null) |
| 502 | + { |
| 503 | + return; |
| 504 | + } |
| 505 | + Trace.WriteLine(string.Format("Debug List Count: {0}, {1}", drawings.Count, hitPaths.Count)); |
| 506 | +// var hitDrawings = new DrawingGroup(); |
| 507 | + |
| 508 | + _drawingVisual = new System.Windows.Media.DrawingVisual(); |
| 509 | + DrawingContext drawingContext = _drawingVisual.RenderOpen(); |
| 510 | + |
| 511 | + //drawingContext.PushOpacity(0.5); |
| 512 | + |
| 513 | + for (int i = 0; i < drawings.Count; i++) |
| 514 | + { |
| 515 | + var drawing = drawings[i]; |
| 516 | + var boundsDrawing = new GeometryDrawing(null, |
| 517 | + new Pen(Brushes.Green, 2), new RectangleGeometry(drawing.Bounds)); |
| 518 | + //hitDrawings.Children.Add(boundsDrawing); |
| 519 | + if (drawings.Count == hitPaths.Count) |
| 520 | + { |
| 521 | + var hitPath = hitPaths[i]; |
| 522 | + drawingContext.PushTransform(hitPath.GetTransform(_drawingDocument, drawing)); |
| 523 | + } |
| 524 | + else |
| 525 | + { |
| 526 | + drawingContext.PushTransform((Transform)svgViewer.DisplayTransform.Inverse); |
| 527 | + } |
| 528 | + //TransformGroup transforms = new TransformGroup(); |
| 529 | + //transforms.Children.Add((Transform)svgViewer.DisplayTransform.Inverse); |
| 530 | + //transforms.Children.Add(new MatrixTransform(1, 0, 0, 1, -107.61384, -0.044941)); |
| 531 | + //transforms.Children.Add(new MatrixTransform(1, 0, 0, 1, 118.57143, -70)); |
| 532 | + //drawingContext.PushTransform(transforms); |
| 533 | + // drawingContext.DrawDrawing(hitDrawings); |
| 534 | + drawingContext.DrawDrawing(boundsDrawing); |
| 535 | + |
| 536 | + // drawingContext.Pop(); |
| 537 | + drawingContext.Pop(); |
| 538 | + } |
| 539 | + |
| 540 | + drawingContext.Close(); |
| 541 | + |
| 542 | + svgViewer.HostVisual.Children.Add(_drawingVisual); |
| 543 | + //svgViewer.HostVisual.Children.Insert(0, drawingVisual); |
| 544 | + } |
| 545 | + |
486 | 546 | public Task<bool> LoadDocumentAsync(string svgFilePath)
|
487 | 547 | {
|
488 | 548 | if (_isLoadingDrawing || string.IsNullOrWhiteSpace(svgFilePath))
|
@@ -928,9 +988,18 @@ private void OnZoomPanMouseUp(object sender, MouseButtonEventArgs e)
|
928 | 988 | {
|
929 | 989 | if (_drawingDocument != null)
|
930 | 990 | {
|
| 991 | + if (_drawingVisual != null) |
| 992 | + { |
| 993 | + svgViewer.HostVisual.Children.Remove(_drawingVisual); |
| 994 | + _drawingVisual = null; |
| 995 | + } |
| 996 | + |
931 | 997 | Point point = e.GetPosition(svgViewer);
|
932 | 998 | _drawingDocument.DisplayTransform = svgViewer.DisplayTransform;
|
933 | 999 | var hitResult = _drawingDocument.HitTest(point);
|
| 1000 | + |
| 1001 | + DrawDebugHitList(_drawingDocument.HitList, _drawingDocument.HitPaths); //TODO:Testing |
| 1002 | + |
934 | 1003 | if (hitResult != null && hitResult.IsHit)
|
935 | 1004 | {
|
936 | 1005 | var selecteElement = hitResult.Element;
|
|
0 commit comments