diff options
Diffstat (limited to 'Software/Visual_Studio/SideChains/RealTimeGraphX.WPF/Components/GraphSurfaceComponentBase.cs')
| -rw-r--r-- | Software/Visual_Studio/SideChains/RealTimeGraphX.WPF/Components/GraphSurfaceComponentBase.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphX.WPF/Components/GraphSurfaceComponentBase.cs b/Software/Visual_Studio/SideChains/RealTimeGraphX.WPF/Components/GraphSurfaceComponentBase.cs new file mode 100644 index 000000000..e0cf424aa --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphX.WPF/Components/GraphSurfaceComponentBase.cs @@ -0,0 +1,75 @@ +using RealTimeGraphX.EventArguments; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace RealTimeGraphX +{ + /// <summary> + /// Represents an <see cref="IGraphSurfaceComponent"/> base class. + /// </summary> + /// <seealso cref="System.Windows.Controls.Control" /> + /// <seealso cref="RealTimeGraphX.IGraphSurfaceComponent" /> + public class GraphSurfaceComponentBase : Control, IGraphSurfaceComponent + { + /// <summary> + /// Gets or sets the surface. + /// </summary> + public IGraphSurface Surface + { + get { return (IGraphSurface)GetValue(SurfaceProperty); } + set { SetValue(SurfaceProperty, value); } + } + public static readonly DependencyProperty SurfaceProperty = + DependencyProperty.Register("Surface", typeof(IGraphSurface), typeof(GraphSurfaceComponentBase), new PropertyMetadata(null, (d, e) => (d as GraphSurfaceComponentBase).OnSurfaceChanged())); + + /// <summary> + /// Called when the <see cref="Surface"/> property has been changed. + /// </summary> + protected virtual void OnSurfaceChanged() + { + if (!this.IsInDesignMode() && Surface != null) + { + Surface.InputChanged -= Surface_InputChanged; + Surface.InputChanged += Surface_InputChanged; + + if (Surface.Input != null) + { + OnSurfacePainterChanged(Surface.Input); + } + } + } + + /// <summary> + /// Handles the InputChanged event of the Surface. + /// </summary> + /// <param name="sender">The source of the event.</param> + /// <param name="e">The <see cref="InputChangedEventArgs{IGraphRenderer}"/> instance containing the event data.</param> + private void Surface_InputChanged(object sender, InputChangedEventArgs<IGraphPainter> e) + { + OnSurfacePainterChanged(e.Input); + } + + /// <summary> + /// Called when surface painter has changed. + /// </summary> + /// <param name="painter">The painter.</param> + protected virtual void OnSurfacePainterChanged(IGraphPainter painter) + { + //Do Nothing.. + } + + /// <summary> + /// Invokes the specified method on the component dispatcher. + /// </summary> + /// <param name="action">The action.</param> + protected void InvokeUI(Action action) + { + Dispatcher.BeginInvoke(action); + } + } +} |
