[12503] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Windows;
|
---|
| 6 | using System.Windows.Controls;
|
---|
| 7 | using System.Windows.Data;
|
---|
| 8 | using System.Windows.Documents;
|
---|
| 9 | using System.Windows.Input;
|
---|
| 10 | using System.Windows.Media;
|
---|
| 11 | using System.Windows.Media.Imaging;
|
---|
| 12 | using System.Windows.Navigation;
|
---|
| 13 | using System.Windows.Shapes;
|
---|
| 14 |
|
---|
| 15 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
| 16 | {
|
---|
| 17 | public partial class MagnifyingGlass : Grid, IPlotterElement
|
---|
| 18 | {
|
---|
| 19 | public MagnifyingGlass()
|
---|
| 20 | {
|
---|
| 21 | InitializeComponent();
|
---|
| 22 | Loaded += MagnifyingGlass_Loaded;
|
---|
| 23 |
|
---|
| 24 | whiteEllipse.Visibility = Visibility.Collapsed;
|
---|
| 25 | magnifierEllipse.Visibility = Visibility.Collapsed;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | private void MagnifyingGlass_Loaded(object sender, RoutedEventArgs e)
|
---|
| 29 | {
|
---|
| 30 | UpdateViewbox();
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | protected override void OnPreviewMouseWheel(MouseWheelEventArgs e)
|
---|
| 34 | {
|
---|
| 35 | Magnification += e.Delta / Mouse.MouseWheelDeltaForOneLine * 0.2;
|
---|
| 36 | e.Handled = false;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | private void plotter_PreviewMouseMove(object sender, MouseEventArgs e)
|
---|
| 40 | {
|
---|
| 41 | VisualBrush b = (VisualBrush)magnifierEllipse.Fill;
|
---|
| 42 | Point pos = e.GetPosition(plotter.ParallelCanvas);
|
---|
| 43 |
|
---|
| 44 | Point plotterPos = e.GetPosition(plotter);
|
---|
| 45 |
|
---|
| 46 | Rect viewBox = b.Viewbox;
|
---|
| 47 | double xoffset = viewBox.Width / 2.0;
|
---|
| 48 | double yoffset = viewBox.Height / 2.0;
|
---|
| 49 | viewBox.X = plotterPos.X - xoffset;
|
---|
| 50 | viewBox.Y = plotterPos.Y - yoffset;
|
---|
| 51 | b.Viewbox = viewBox;
|
---|
| 52 | Canvas.SetLeft(this, pos.X - Width / 2);
|
---|
| 53 | Canvas.SetTop(this, pos.Y - Height / 2);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | private double magnification = 2.0;
|
---|
| 57 | public double Magnification
|
---|
| 58 | {
|
---|
| 59 | get { return magnification; }
|
---|
| 60 | set
|
---|
| 61 | {
|
---|
| 62 | magnification = value;
|
---|
| 63 |
|
---|
| 64 | UpdateViewbox();
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | private void UpdateViewbox()
|
---|
| 69 | {
|
---|
| 70 | if (!IsLoaded)
|
---|
| 71 | return;
|
---|
| 72 |
|
---|
| 73 | VisualBrush b = (VisualBrush)magnifierEllipse.Fill;
|
---|
| 74 | Rect viewBox = b.Viewbox;
|
---|
| 75 | viewBox.Width = Width / magnification;
|
---|
| 76 | viewBox.Height = Height / magnification;
|
---|
| 77 | b.Viewbox = viewBox;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
|
---|
| 81 | {
|
---|
| 82 | base.OnPropertyChanged(e);
|
---|
| 83 |
|
---|
| 84 | if (e.Property == WidthProperty || e.Property == HeightProperty)
|
---|
| 85 | {
|
---|
| 86 | UpdateViewbox();
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | #region IPlotterElement Members
|
---|
| 91 |
|
---|
| 92 | Plotter plotter;
|
---|
| 93 | public void OnPlotterAttached(Plotter plotter)
|
---|
| 94 | {
|
---|
| 95 | this.plotter = plotter;
|
---|
| 96 | plotter.ParallelCanvas.Children.Add(this);
|
---|
| 97 | plotter.PreviewMouseMove += plotter_PreviewMouseMove;
|
---|
| 98 | plotter.MouseEnter += new MouseEventHandler(plotter_MouseEnter);
|
---|
| 99 | plotter.MouseLeave += new MouseEventHandler(plotter_MouseLeave);
|
---|
| 100 |
|
---|
| 101 | VisualBrush b = (VisualBrush)magnifierEllipse.Fill;
|
---|
| 102 | b.Visual = plotter.MainGrid;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | void plotter_MouseLeave(object sender, MouseEventArgs e)
|
---|
| 106 | {
|
---|
| 107 | whiteEllipse.Visibility = Visibility.Collapsed;
|
---|
| 108 | magnifierEllipse.Visibility = Visibility.Collapsed;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | void plotter_MouseEnter(object sender, MouseEventArgs e)
|
---|
| 112 | {
|
---|
| 113 | whiteEllipse.Visibility = Visibility.Visible;
|
---|
| 114 | magnifierEllipse.Visibility = Visibility.Visible;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | public void OnPlotterDetaching(Plotter plotter)
|
---|
| 118 | {
|
---|
| 119 | plotter.MouseEnter -= new MouseEventHandler(plotter_MouseEnter);
|
---|
| 120 | plotter.MouseLeave -= new MouseEventHandler(plotter_MouseLeave);
|
---|
| 121 |
|
---|
| 122 | plotter.PreviewMouseMove -= plotter_PreviewMouseMove;
|
---|
| 123 | plotter.ParallelCanvas.Children.Remove(this);
|
---|
| 124 | this.plotter = null;
|
---|
| 125 |
|
---|
| 126 | VisualBrush b = (VisualBrush)magnifierEllipse.Fill;
|
---|
| 127 | b.Visual = null;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | public Plotter Plotter
|
---|
| 131 | {
|
---|
| 132 | get { return plotter; ; }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | #endregion
|
---|
| 136 | }
|
---|
| 137 | }
|
---|