Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Viewport2dDeferredPanningProxy.cs @ 13757

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

#2283 added GUI and charts; fixed MCTS

File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows;
6using Microsoft.Research.DynamicDataDisplay.Common;
7
8namespace Microsoft.Research.DynamicDataDisplay
9{
10  internal sealed class Viewport2dDeferredPanningProxy : Viewport2D
11  {
12    private Viewport2D viewport;
13    internal Viewport2dDeferredPanningProxy(Viewport2D viewport)
14      : base(viewport.HostElement, viewport.Plotter2D)
15    {
16      viewport.PropertyChanged += viewport_PropertyChanged;
17      viewport.PanningStateChanged += viewport_PanningStateChanged;
18      this.viewport = viewport;
19    }
20
21    DataRect prevVisible;
22
23    private void viewport_PanningStateChanged(object sender, ValueChangedEventArgs<Viewport2DPanningState> e)
24    {
25      if (e.CurrentValue == Viewport2DPanningState.Panning && e.PreviousValue == Viewport2DPanningState.NotPanning)
26      {
27        prevVisible = Visible;
28      }
29      else if (e.CurrentValue == Viewport2DPanningState.NotPanning && e.PreviousValue == Viewport2DPanningState.Panning)
30      {
31        notMineEvent = true;
32        try
33        {
34          Visible = viewport.Visible;
35        }
36        finally { notMineEvent = false; }
37      }
38    }
39
40    protected override DataRect CoerceVisible(DataRect newVisible)
41    {
42      if (viewport == null)
43        return new DataRect(0, 0, 1, 1);
44
45      if (viewport.PanningState == Viewport2DPanningState.Panning)
46        return prevVisible;
47
48      return base.CoerceVisible(newVisible);
49    }
50
51    private bool notMineEvent = false;
52    private void viewport_PropertyChanged(object sender, ExtendedPropertyChangedEventArgs e)
53    {
54      notMineEvent = true;
55      try
56      {
57        RaisePropertyChanged(e);
58      }
59      finally
60      {
61        notMineEvent = false;
62      }
63    }
64
65    public override CoordinateTransform Transform
66    {
67      get
68      {
69        if (viewport.PanningState == Viewport2DPanningState.Panning)
70          return viewport.Transform.WithRects(prevVisible, viewport.Output);
71        return viewport.Transform;
72      }
73      set
74      {
75        base.Transform = value;
76      }
77    }
78
79    protected override void RaisePropertyChanged(ExtendedPropertyChangedEventArgs args, ChangeType changeType = ChangeType.None)
80    {
81      if (args.PropertyName == "Visible")
82      {
83        if (notMineEvent)
84        {
85          if (viewport.PanningState == Viewport2DPanningState.NotPanning)
86          {
87            base.RaisePropertyChanged(args);
88          }
89          else
90          {
91            // do nothing
92          }
93        }
94      }
95      else
96      {
97        base.RaisePropertyChanged(args);
98      }
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.