Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/MagnifyingGlass.xaml.cs @ 13401

Last change on this file since 13401 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 3.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows;
6using System.Windows.Controls;
7using System.Windows.Data;
8using System.Windows.Documents;
9using System.Windows.Input;
10using System.Windows.Media;
11using System.Windows.Media.Imaging;
12using System.Windows.Navigation;
13using System.Windows.Shapes;
14
15namespace 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}
Note: See TracBrowser for help on using the repository browser.