Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/FixedSizePrimitiveBase.cs @ 13045

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

#1265: merged changes from abeham

File size: 2.6 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;
24
25namespace HeuristicLab.Visualization {
26  public abstract class FixedSizePrimitiveBase : PrimitiveBase {
27    private PointD myPoint;
28    public virtual PointD Point {
29      get { return myPoint; }
30    }
31    private Size mySize;
32    public virtual Size Size {
33      get { return mySize; }
34    }
35
36    protected FixedSizePrimitiveBase(IChart chart, PointD point, Size size)
37      : base(chart) {
38      myPoint = point;
39      mySize = size;
40    }
41    protected FixedSizePrimitiveBase(IChart chart, PointD point, Size size, Pen pen, Brush brush)
42      : base(chart, pen, brush) {
43      myPoint = point;
44      mySize = size;
45    }
46
47    public virtual void SetPosition(PointD point) {
48      myPoint = point;
49      OnRedrawRequired();
50    }
51
52    public override void Move(Offset delta) {
53      SetPosition(Point + delta);
54    }
55
56    public override void Move(PointD point, Offset delta) {
57      Move(delta);
58    }
59
60    public override void SnapToGrid(IGrid grid) {
61      var bl = grid.GetBottomLeftGridPoint(Point);
62      var ur = grid.GetUpperRightGridPoint(Point);
63      var x = Math.Abs(bl.X - Point.X) <= Math.Abs(ur.X - Point.X) ? bl.X : ur.X;
64      var y = Math.Abs(bl.Y - Point.Y) <= Math.Abs(ur.Y - Point.Y) ? bl.Y : ur.Y;
65      SetPosition(new PointD(x, y));
66    }
67
68    public override void SnapToGrid(PointD point, IGrid grid) {
69      SnapToGrid(grid);
70    }
71
72    public override bool ContainsPoint(PointD point) {
73      SizeD size = Chart.TransformPixelToWorld(Size);
74      return (point.X >= Point.X - (size.Width / 2)) && (point.X <= Point.X + (size.Width / 2)) &&
75             (point.Y >= Point.Y - (size.Height / 2)) && (point.Y <= Point.Y + (size.Height / 2));
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.