Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1265_HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/PrimitiveBase.cs @ 17717

Last change on this file since 17717 was 13717, checked in by bburlacu, 9 years ago

#1265: Updated license year to 2016.

File size: 2.9 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.Windows.Forms;
25
26namespace HeuristicLab.Visualization {
27  public abstract class PrimitiveBase : IPrimitive {
28    private readonly IChart chart;
29    public IChart Chart {
30      get { return chart; }
31    }
32
33    private Pen pen;
34    public virtual Pen Pen {
35      get { return pen; }
36      set {
37        pen = value;
38        OnRedrawRequired();
39      }
40    }
41    private Brush brush;
42    public virtual Brush Brush {
43      get { return brush; }
44      set {
45        brush = value;
46        OnRedrawRequired();
47      }
48    }
49
50    public string ToolTipText { get; set; }
51
52    public object Tag { get; set; }
53
54    protected bool SuppressEvents { get; set; }
55
56    private bool selected;
57    public virtual bool Selected {
58      get { return selected; }
59      set {
60        if (selected == value) return;
61        selected = value;
62        OnRedrawRequired();
63      }
64    }
65
66    protected PrimitiveBase(IChart chart)
67      : this(chart, Pens.Black, Brushes.White) {
68    }
69    protected PrimitiveBase(IChart chart, Pen pen, Brush brush) {
70      this.chart = chart;
71      this.pen = pen;
72      this.brush = brush;
73      selected = false;
74      ToolTipText = null;
75      Tag = null;
76    }
77
78    public abstract void Move(Offset delta);
79    public abstract void Move(PointD point, Offset delta);
80
81    public abstract void SnapToGrid(IGrid grid);
82    public abstract void SnapToGrid(PointD point, IGrid grid);
83
84    public abstract bool ContainsPoint(PointD point);
85
86    public virtual Cursor GetCursor(PointD point) {
87      return null;
88    }
89
90    public virtual string GetToolTipText(PointD point) {
91      return ToolTipText;
92    }
93
94    public virtual void PreDraw(Graphics graphics) { }
95    public virtual void Draw(Graphics graphics) { }
96    public virtual void PostDraw(Graphics graphics) { }
97
98    public event EventHandler RedrawRequired;
99    protected virtual void OnRedrawRequired() {
100      var handler = RedrawRequired;
101      if (!SuppressEvents && handler != null) handler(this, EventArgs.Empty);
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.