Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/ZoomInChartMode.cs @ 13076

Last change on this file since 13076 was 13076, checked in by jkarder, 8 years ago

#1265: implemented new chart mode concept

File size: 2.9 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;
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 ToolTip { get { return "Zoom In"; } }
32
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
39    public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
40      base.HandleOnMouseUp(sender, e);
41
42      switch (e.Button) {
43        case MouseButtons.Left:
44          var lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X), Math.Max(e.Y, buttonDownPoint.Y));
45          var upperRight = new Point(Math.Max(e.X, buttonDownPoint.X), Math.Min(e.Y, buttonDownPoint.Y));
46          if ((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y))
47            chartControl.Chart.ZoomIn(lowerLeft, upperRight);
48          else chartControl.Chart.ZoomIn(buttonDownPoint);
49          break;
50        case MouseButtons.Middle:
51          chartControl.Chart.Unzoom();
52          break;
53      }
54    }
55
56    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
57      base.HandleOnMouseMove(sender, e);
58
59      try {
60        switch (e.Button) {
61          case MouseButtons.Left:
62            chartControl.PictureBox.Refresh();
63            using (var graphics = chartControl.PictureBox.CreateGraphics())
64            using (var pen = new Pen(Color.Gray) { DashStyle = DashStyle.Dash }) {
65              graphics.DrawRectangle(pen,
66                Math.Min(e.X, buttonDownPoint.X),
67                Math.Min(e.Y, buttonDownPoint.Y),
68                Math.Abs(e.X - buttonDownPoint.X),
69                Math.Abs(e.Y - buttonDownPoint.Y));
70            }
71            break;
72        }
73      } finally {
74        previousLocation = e.Location;
75        chartControl.PictureBox.Update();
76      }
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.