Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1265_HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/ZoomInChartMode.cs @ 16881

Last change on this file since 16881 was 13762, checked in by jkarder, 9 years ago

#1265: worked on visualization

  • added shortcut handling prototype
File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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;
23using System.Drawing;
24using System.Drawing.Drawing2D;
25using System.Windows.Forms;
26using HeuristicLab.Common.Resources;
27
28namespace HeuristicLab.Visualization {
29  public class ZoomInChartMode : ChartMode {
30    public override Image Image { get { return VSImageLibrary.ZoomIn; } }
31    public override string Text { get { return "Zoom &In"; } }
32    public override string ToolTipText { get { return "Zoom In"; } }
33    public override Cursor Cursor {
34      get { return cursor ?? (cursor = new Cursor(typeof(ChartControl), "Resources.ZoomIn.cur")); }
35    }
36
37    public ZoomInChartMode(ChartControl control) : base(control) {
38      globalShortcuts.Add(new Shortcut(Keys.Z, Keys.Control) {
39        DownAction = () => chartControl.SetTempChartMode(this),
40        UpAction = () => chartControl.ResetTempChartMode()
41      });
42    }
43
44    public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
45      try {
46        switch (e.Button) {
47          case MouseButtons.Left:
48            var lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X), Math.Max(e.Y, buttonDownPoint.Y));
49            var upperRight = new Point(Math.Max(e.X, buttonDownPoint.X), Math.Min(e.Y, buttonDownPoint.Y));
50            if ((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y))
51              chartControl.Chart.ZoomIn(lowerLeft, upperRight);
52            else chartControl.Chart.ZoomIn(buttonDownPoint);
53            break;
54          case MouseButtons.Middle:
55            chartControl.Chart.Unzoom();
56            break;
57        }
58      } finally {
59        base.HandleOnMouseUp(sender, e);
60      }
61    }
62
63    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
64      try {
65        switch (e.Button) {
66          case MouseButtons.Left:
67            chartControl.RefreshPicture();
68            using (var graphics = chartControl.CreatePictureGraphics())
69            using (var pen = new Pen(Color.Gray) { DashStyle = DashStyle.Dash }) {
70              graphics.DrawRectangle(pen,
71                Math.Min(e.X, buttonDownPoint.X),
72                Math.Min(e.Y, buttonDownPoint.Y),
73                Math.Abs(e.X - buttonDownPoint.X),
74                Math.Abs(e.Y - buttonDownPoint.Y));
75            }
76            break;
77        }
78      } finally {
79        chartControl.UpdatePicture();
80        base.HandleOnMouseMove(sender, e);
81      }
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.