1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows;
|
---|
6 | using Microsoft.Research.DynamicDataDisplay.Common.Auxiliary;
|
---|
7 | using System.Windows.Threading;
|
---|
8 | using System.Diagnostics;
|
---|
9 |
|
---|
10 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
11 | {
|
---|
12 | public partial class Viewport2D
|
---|
13 | {
|
---|
14 | #region IsContentBoundsHost attached property
|
---|
15 |
|
---|
16 | public static bool GetIsContentBoundsHost(DependencyObject obj)
|
---|
17 | {
|
---|
18 | return (bool)obj.GetValue(IsContentBoundsHostProperty);
|
---|
19 | }
|
---|
20 |
|
---|
21 | public static void SetIsContentBoundsHost(DependencyObject obj, bool value)
|
---|
22 | {
|
---|
23 | obj.SetValue(IsContentBoundsHostProperty, value);
|
---|
24 | }
|
---|
25 |
|
---|
26 | public static readonly DependencyProperty IsContentBoundsHostProperty = DependencyProperty.RegisterAttached(
|
---|
27 | "IsContentBoundsHost",
|
---|
28 | typeof(bool),
|
---|
29 | typeof(Viewport2D),
|
---|
30 | new FrameworkPropertyMetadata(true, OnIsContentBoundsChanged));
|
---|
31 |
|
---|
32 | private static void OnIsContentBoundsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
---|
33 | {
|
---|
34 | IPlotterElement plotterElement = d as IPlotterElement;
|
---|
35 | if (plotterElement != null && plotterElement.Plotter != null)
|
---|
36 | {
|
---|
37 | Plotter2D plotter2d = (Plotter2D)plotterElement.Plotter;
|
---|
38 | plotter2d.Viewport.UpdateContentBoundsHosts();
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | #endregion
|
---|
43 |
|
---|
44 | #region ContentBounds attached property
|
---|
45 |
|
---|
46 | public static DataRect GetContentBounds(DependencyObject obj)
|
---|
47 | {
|
---|
48 | return (DataRect)obj.GetValue(ContentBoundsProperty);
|
---|
49 | }
|
---|
50 |
|
---|
51 | public static void SetContentBounds(DependencyObject obj, DataRect value)
|
---|
52 | {
|
---|
53 | obj.SetValue(ContentBoundsProperty, value);
|
---|
54 | }
|
---|
55 |
|
---|
56 | public static readonly DependencyProperty ContentBoundsProperty = DependencyProperty.RegisterAttached(
|
---|
57 | "ContentBounds",
|
---|
58 | typeof(DataRect),
|
---|
59 | typeof(Viewport2D),
|
---|
60 | new FrameworkPropertyMetadata(DataRect.Empty, OnContentBoundsChanged, CoerceContentBounds));
|
---|
61 |
|
---|
62 | private static object CoerceContentBounds(DependencyObject d, object value)
|
---|
63 | {
|
---|
64 | DataRect prevBounds = GetContentBounds(d);
|
---|
65 | DataRect currBounds = (DataRect)value;
|
---|
66 |
|
---|
67 | bool approximateComparanceAllowed = GetUsesApproximateContentBoundsComparison(d);
|
---|
68 |
|
---|
69 | bool areClose = approximateComparanceAllowed && currBounds.IsCloseTo(prevBounds, 0.005);
|
---|
70 | if (areClose)
|
---|
71 | return DependencyProperty.UnsetValue;
|
---|
72 | else
|
---|
73 | return value;
|
---|
74 | }
|
---|
75 |
|
---|
76 | private static void OnContentBoundsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
---|
77 | {
|
---|
78 | IPlotterElement element = d as IPlotterElement;
|
---|
79 | if (element != null)
|
---|
80 | {
|
---|
81 | FrameworkElement frElement = element as FrameworkElement;
|
---|
82 | if (frElement != null)
|
---|
83 | {
|
---|
84 | frElement.RaiseEvent(new RoutedEventArgs(ContentBoundsChangedEvent));
|
---|
85 | }
|
---|
86 |
|
---|
87 | Plotter2D plotter2d = element.Plotter as Plotter2D;
|
---|
88 | if (plotter2d != null)
|
---|
89 | {
|
---|
90 | plotter2d.Viewport.UpdateContentBoundsHosts();
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | public static readonly RoutedEvent ContentBoundsChangedEvent = EventManager.RegisterRoutedEvent(
|
---|
96 | "ContentBoundsChanged",
|
---|
97 | RoutingStrategy.Direct,
|
---|
98 | typeof(RoutedEventHandler),
|
---|
99 | typeof(Viewport2D));
|
---|
100 |
|
---|
101 | #endregion
|
---|
102 |
|
---|
103 | #region UsesApproximateContentBoundsComparison
|
---|
104 |
|
---|
105 | /// <summary>
|
---|
106 | /// Gets a value indicating whether approximate content bounds comparison will be used while deciding whether to updating Viewport2D.ContentBounds
|
---|
107 | /// attached dependency property or not.
|
---|
108 | /// Approximate content bounds comparison can make Viewport's Visible to changed less frequent, but it can lead to
|
---|
109 | /// some bugs if content bounds are large but visible area is not compared to them.
|
---|
110 | /// </summary>
|
---|
111 | /// <value>
|
---|
112 | /// <c>true</c> if approximate content bounds comparison is used while deciding whether to set new value of content bounds, or not; otherwise, <c>false</c>.
|
---|
113 | /// </value>
|
---|
114 | public static bool GetUsesApproximateContentBoundsComparison(DependencyObject obj)
|
---|
115 | {
|
---|
116 | return (bool)obj.GetValue(UsesApproximateContentBoundsComparisonProperty);
|
---|
117 | }
|
---|
118 |
|
---|
119 | /// <summary>
|
---|
120 | /// Sets a value indicating whether approximate content bounds comparison will be used while deciding whether to updating Viewport2D.ContentBounds
|
---|
121 | /// attached dependency property or not.
|
---|
122 | /// Approximate content bounds comparison can make Viewport's Visible to changed less frequent, but it can lead to
|
---|
123 | /// some bugs if content bounds are large but visible area is not compared to them.
|
---|
124 | /// </summary>
|
---|
125 | /// <value>
|
---|
126 | /// <c>true</c> if approximate content bounds comparison is used while deciding whether to set new value of content bounds, or not; otherwise, <c>false</c>.
|
---|
127 | /// </value>
|
---|
128 | public static void SetUsesApproximateContentBoundsComparison(DependencyObject obj, bool value)
|
---|
129 | {
|
---|
130 | obj.SetValue(UsesApproximateContentBoundsComparisonProperty, value);
|
---|
131 | }
|
---|
132 |
|
---|
133 | public static readonly DependencyProperty UsesApproximateContentBoundsComparisonProperty = DependencyProperty.RegisterAttached(
|
---|
134 | "UsesApproximateContentBoundsComparison",
|
---|
135 | typeof(bool),
|
---|
136 | typeof(Viewport2D),
|
---|
137 | new FrameworkPropertyMetadata(true, OnUsesApproximateContentBoundsComparisonChanged));
|
---|
138 |
|
---|
139 | private static void OnUsesApproximateContentBoundsComparisonChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
---|
140 | {
|
---|
141 | IPlotterElement element = d as IPlotterElement;
|
---|
142 | if (element != null)
|
---|
143 | {
|
---|
144 | Plotter2D plotter2d = element.Plotter as Plotter2D;
|
---|
145 | if (plotter2d != null)
|
---|
146 | {
|
---|
147 | plotter2d.Viewport.UpdateVisible();
|
---|
148 | }
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | #endregion // end of UsesApproximateContentBoundsComparison
|
---|
153 |
|
---|
154 | #region UseDeferredPanning attached property
|
---|
155 |
|
---|
156 | public static bool GetUseDeferredPanning(DependencyObject obj)
|
---|
157 | {
|
---|
158 | return (bool)obj.GetValue(UseDeferredPanningProperty);
|
---|
159 | }
|
---|
160 |
|
---|
161 | public static void SetUseDeferredPanning(DependencyObject obj, bool value)
|
---|
162 | {
|
---|
163 | obj.SetValue(UseDeferredPanningProperty, value);
|
---|
164 | }
|
---|
165 |
|
---|
166 | public static readonly DependencyProperty UseDeferredPanningProperty = DependencyProperty.RegisterAttached(
|
---|
167 | "UseDeferredPanning",
|
---|
168 | typeof(bool),
|
---|
169 | typeof(Viewport2D),
|
---|
170 | new FrameworkPropertyMetadata(false));
|
---|
171 |
|
---|
172 | #endregion // end of UseDeferredPanning attached property
|
---|
173 | }
|
---|
174 | }
|
---|