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