Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Charting/3.3/Primitives/PrimitiveBase.cs @ 1835

Last change on this file since 1835 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 5.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Collections.Generic;
24using System.Text;
25using System.Drawing;
26using System.Windows.Forms;
27
28namespace HeuristicLab.Charting {
29  public abstract class PrimitiveBase : IPrimitive {
30    private IChart myChart;
31    public IChart Chart {
32      get { return myChart; }
33    }
34    private IGroup myGroup;
35    public IGroup Group {
36      get { return myGroup; }
37      set { myGroup = value; }
38    }
39
40    private Pen myPen;
41    public virtual Pen Pen {
42      get { return myPen; }
43      set {
44        myPen = value;
45        OnUpdate();
46      }
47    }
48    private Brush myBrush;
49    public virtual Brush Brush {
50      get { return myBrush; }
51      set {
52        myBrush = value;
53        OnUpdate();
54      }
55    }
56
57    private bool myUpdateEnabled;
58    public bool UpdateEnabled {
59      get { return myUpdateEnabled; }
60      set { myUpdateEnabled = value; }
61    }
62
63    private bool mySelected;
64    public virtual bool Selected {
65      get { return mySelected; }
66      set {
67        mySelected = value;
68        OnUpdate();
69      }
70    }
71
72    private string myToolTipText;
73    public string ToolTipText {
74      get { return myToolTipText; }
75      set { myToolTipText = value; }
76    }
77
78    private object myTag;
79    public object Tag {
80      get { return myTag; }
81      set { myTag = value; }
82    }
83
84    protected PrimitiveBase(IChart chart) {
85      myChart = chart;
86      myGroup = null;
87      myPen = Pens.Black;
88      myBrush = Brushes.White;
89      myUpdateEnabled = true;
90      mySelected = false;
91      myToolTipText = null;
92      myTag = null;
93    }
94    protected PrimitiveBase(IChart chart, Pen pen, Brush brush)
95      : this(chart) {
96      myPen = pen;
97      myBrush = brush;
98    }
99
100    public abstract void Move(Offset delta);
101    public void Move(double dx, double dy) {
102      Move(new Offset(dx, dy));
103    }
104
105    public abstract bool ContainsPoint(PointD point);
106    public bool ContainsPoint(double x, double y) {
107      return ContainsPoint(new PointD(x, y));
108    }
109
110    public virtual Cursor GetCursor(PointD point) {
111      return null;
112    }
113    public Cursor GetCursor(double x, double y) {
114      return GetCursor(new PointD(x, y));
115    }
116    public virtual string GetToolTipText(PointD point) {
117      return ToolTipText;
118    }
119    public string GetToolTipText(double x, double y) {
120      return GetToolTipText(new PointD(x, y));
121    }
122
123    public void OneLayerUp() {
124      Group.OneLayerUp(this);
125    }
126    public void OneLayerDown() {
127      Group.OneLayerDown(this);
128    }
129    public void IntoForeground() {
130      Group.IntoForeground(this);
131    }
132    public void IntoBackground() {
133      Group.IntoBackground(this);
134    }
135
136    public virtual void MouseClick(PointD point, MouseButtons button) {
137      if (button == MouseButtons.Left) {
138        Selected = true;
139      }
140    }
141    public void MouseClick(double x, double y, MouseButtons button) {
142      MouseClick(new PointD(x, y), button);
143    }
144    public virtual void MouseDoubleClick(PointD point, MouseButtons button) {
145    }
146    public void MouseDoubleClick(double x, double y, MouseButtons button) {
147      MouseDoubleClick(new PointD(x, y), button);
148    }
149    public virtual void MouseMove(PointD point, Offset offset) {
150    }
151    public void MouseMove(double x, double y, double dx, double dy) {
152      MouseMove(new PointD(x, y), new Offset(dx, dy));
153    }
154    public virtual void MouseDrag(PointD point, Offset offset, MouseButtons button) {
155      if (button == MouseButtons.Left) {
156        Move(offset);
157      }
158    }
159    public void MouseDrag(double x, double y, double dx, double dy, MouseButtons button) {
160      MouseDrag(new PointD(x, y), new Offset(dx, dy), button);
161    }
162
163    public virtual void PreDraw(Graphics graphics) {
164    }
165    public virtual void Draw(Graphics graphics) {
166    }
167    public virtual void PostDraw(Graphics graphics) {
168    }
169
170    public event EventHandler Update;
171    public void EnforceUpdate() {
172      if (Update != null) {
173        Update(this, new EventArgs());
174      }
175    }
176    protected virtual void OnUpdate() {
177      if ((UpdateEnabled) && (Update != null)) {
178        Update(this, new EventArgs());
179      }
180    }
181  }
182}
Note: See TracBrowser for help on using the repository browser.