1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 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 |
|
---|
22 | using System.Drawing;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using Netron.Diagramming.Core;
|
---|
25 |
|
---|
26 | namespace 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 |
|
---|
35 | public CustomPanTool(string toolName) : base(toolName) { }
|
---|
36 |
|
---|
37 | protected override void OnActivateTool() {
|
---|
38 | base.OnActivateTool();
|
---|
39 | Cursor = CursorPalette.Pan;
|
---|
40 | }
|
---|
41 |
|
---|
42 | #region IMouseListener Members
|
---|
43 | public bool MouseDown(MouseEventArgs e) {
|
---|
44 | this.previousMouseLocation = Point.Round(Controller.View.WorldToView(e.Location));
|
---|
45 | this.initialLocation = previousMouseLocation;
|
---|
46 | return true;
|
---|
47 | }
|
---|
48 |
|
---|
49 | public void MouseMove(MouseEventArgs e) {
|
---|
50 | Point currentLocation = Point.Round(Controller.View.WorldToView(e.Location));
|
---|
51 | if (!IsSuspended && IsActive) {
|
---|
52 | IDiagramControl control = Controller.ParentControl;
|
---|
53 | Point origin = Controller.View.Origin;
|
---|
54 |
|
---|
55 | Point offset = new Point(previousMouseLocation.X - currentLocation.X, previousMouseLocation.Y - currentLocation.Y);
|
---|
56 |
|
---|
57 | origin.Offset(offset);
|
---|
58 |
|
---|
59 | if (origin.X < 0) origin.X = 0;
|
---|
60 |
|
---|
61 |
|
---|
62 | if (origin.Y < 0) origin.Y = 0;
|
---|
63 |
|
---|
64 | control.AutoScrollPosition = origin;
|
---|
65 | Controller.View.Origin = origin;
|
---|
66 | previousMouseLocation = currentLocation;
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | public void MouseUp(MouseEventArgs e) {
|
---|
71 | //if (IsActive && !IsSuspended) this.previousMouseLocation = Point.Empty;
|
---|
72 | }
|
---|
73 | #endregion
|
---|
74 |
|
---|
75 | #region IKeyboardListener Members
|
---|
76 | public void KeyDown(KeyEventArgs e) {
|
---|
77 | if (e.KeyCode == Keys.Escape)
|
---|
78 | DeactivateTool();
|
---|
79 | else if (e.KeyCode == Keys.Space)
|
---|
80 | ActivateTool();
|
---|
81 | }
|
---|
82 |
|
---|
83 | public void KeyUp(KeyEventArgs e) {
|
---|
84 | if (e.KeyCode == Keys.Space)
|
---|
85 | DeactivateTool();
|
---|
86 | }
|
---|
87 |
|
---|
88 | public void KeyPress(KeyPressEventArgs e) { }
|
---|
89 | #endregion
|
---|
90 | }
|
---|
91 | }
|
---|