Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/Navigation/TouchPadScroll.cs @ 13398

Last change on this file since 13398 was 12503, checked in by aballeit, 10 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.7 KB
Line 
1using System;
2using System.Windows;
3using System.Windows.Input;
4using System.Windows.Interop;
5
6
7namespace Microsoft.Research.DynamicDataDisplay.Navigation
8{
9    /// <summary>This class allows convenient navigation around viewport using touchpad on
10    /// some notebooks</summary>
11  public sealed class TouchpadScroll : NavigationBase {
12    public TouchpadScroll() {
13      Loaded += OnLoaded;
14    }
15
16    private void OnLoaded(object sender, RoutedEventArgs e) {
17      WindowInteropHelper helper = new WindowInteropHelper(Window.GetWindow(this));
18      HwndSource source = HwndSource.FromHwnd(helper.Handle);
19      source.AddHook(OnMessageAppeared);
20    }
21
22    private IntPtr OnMessageAppeared(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
23      if (msg == WindowsMessages.WM_MOUSEWHEEL) {
24        Point mousePos = MessagesHelper.GetMousePosFromLParam(lParam);
25        mousePos = TranslatePoint(mousePos, this);
26
27        if (Viewport.Output.Contains(mousePos)) {
28          MouseWheelZoom(MessagesHelper.GetMousePosFromLParam(lParam), MessagesHelper.GetWheelDataFromWParam(wParam));
29          handled = true;
30        }
31      }
32      return IntPtr.Zero;
33    }
34
35    double wheelZoomSpeed = 1.2;
36    public double WheelZoomSpeed {
37      get { return wheelZoomSpeed; }
38      set { wheelZoomSpeed = value; }
39    }
40
41    private void MouseWheelZoom(Point mousePos, int wheelRotationDelta) {
42      Point zoomTo = mousePos.ScreenToData(Viewport.Transform);
43
44      double zoomSpeed = Math.Abs(wheelRotationDelta / Mouse.MouseWheelDeltaForOneLine);
45      zoomSpeed *= wheelZoomSpeed;
46      if (wheelRotationDelta < 0) {
47        zoomSpeed = 1 / zoomSpeed;
48      }
49      Viewport.Visible = Viewport.Visible.Zoom(zoomTo, zoomSpeed);
50    }
51  }
52}
Note: See TracBrowser for help on using the repository browser.