Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemRefactoring/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/HeuristicLab.Netron-3.0.2672.12446/CustomTools/CustomPanTool.cs @ 13331

Last change on this file since 13331 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Drawing;
23using System.Windows.Forms;
24using Netron.Diagramming.Core;
25
26namespace HeuristicLab.Netron.CustomTools {
27  public class CustomPanTool : AbstractTool, IMouseListener, IKeyboardListener {
28    public const string ToolName = "Custom Pan Tool";
29
30    private Point initialLocation = Point.Empty;
31    private Point previousMouseLocation = Point.Empty;
32
33    public CustomPanTool() : base(ToolName) { }
34    public CustomPanTool(string toolName) : base(toolName) { }
35
36    protected override void OnActivateTool() {
37      base.OnActivateTool();
38      Cursor = CursorPalette.Pan;
39    }
40
41    #region IMouseListener Members
42    public bool MouseDown(MouseEventArgs e) {
43      this.previousMouseLocation = Point.Round(Controller.View.WorldToView(e.Location));
44      this.initialLocation = previousMouseLocation;
45      return true;
46    }
47
48    public void MouseMove(MouseEventArgs e) {
49      Point currentLocation = Point.Round(Controller.View.WorldToView(e.Location));
50      if (!IsSuspended && IsActive) {
51        IDiagramControl control = Controller.ParentControl;
52        Point origin = Controller.View.Origin;
53        Point offset = new Point(previousMouseLocation.X - currentLocation.X, previousMouseLocation.Y - currentLocation.Y);
54        origin.Offset(offset);
55
56        if (origin.X < 0) origin.X = 0;
57        if (origin.Y < 0) origin.Y = 0;
58
59        control.AutoScrollPosition = origin;
60        Controller.View.Origin = origin;
61        previousMouseLocation = currentLocation;
62      }
63    }
64
65    public void MouseUp(MouseEventArgs e) { }
66    #endregion
67
68    #region IKeyboardListener Members
69    public void KeyDown(KeyEventArgs e) {
70      if (e.KeyCode == Keys.Escape)
71        DeactivateTool();
72    }
73
74    public void KeyUp(KeyEventArgs e) { }
75
76    public void KeyPress(KeyPressEventArgs e) { }
77    #endregion
78  }
79}
Note: See TracBrowser for help on using the repository browser.