2 using System.Windows;
\r
3 using System.Windows.Controls;
\r
4 using System.Windows.Documents;
\r
5 using System.Windows.Input;
\r
6 using System.Windows.Media;
\r
7 using System.Windows.Media.Animation;
\r
8 using System.Windows.Media.Imaging;
\r
9 using System.Windows.Shapes;
\r
13 namespace Psychlops{
\r
15 public interface Shape : Internal.PrimitiveFigure
\r
17 Color fill { get; set; }
\r
18 Stroke stroke { get; set; }
\r
20 public static class ShapeExtention
\r
22 public static void draw(this Shape drawee, Color c)
\r
24 Color tmp_col = drawee.fill;
\r
25 Stroke tmp_strk = drawee.stroke;
\r
27 drawee.stroke = new Stroke();
\r
29 drawee.fill = tmp_col;
\r
30 drawee.stroke = tmp_strk;
\r
32 public static void draw(this Shape drawee, Stroke strk)
\r
34 Color tmp_col = drawee.fill;
\r
35 Stroke tmp_strk = drawee.stroke;
\r
36 drawee.fill = new Color(0,0,1,1);
\r
37 drawee.stroke = strk;
\r
39 drawee.fill = tmp_col;
\r
40 drawee.stroke = tmp_strk;
\r
44 public partial struct Stroke
\r
46 public double thick;
\r
48 public Stroke(Color c, double t)
\r
53 public void set(Color c, double t)
\r
60 public partial class Line : Shape
\r
62 public Point begin, end;
\r
65 get { return begin; }
\r
66 set { begin = value; }
\r
69 public Line(double x1, double y1, double x2, double y2)
\r
71 set(x1, y1, x2, y2);
\r
73 public Line(Point v1, Point v2)
\r
77 public void set(double x1, double y1, double x2, double y2)
\r
82 public void set(Point v1, Point v2)
\r
88 public Figure shift(Point p)
\r
94 public Figure centering(Point p)
\r
96 double h = width, v = height;
\r
97 begin.x = p.x - h / 2.0;
\r
98 begin.y = p.y - v / 2.0;
\r
99 end.x = begin.x + h;
\r
100 end.y = begin.y + v;
\r
106 Main.drawable.line(this);
\r
109 public double left { get { return begin.x < end.x ? begin.x : end.x; } }
\r
110 public double top { get { return begin.y < end.y ? begin.y : end.y; ; } }
\r
111 public double right { get { return begin.x > end.x ? begin.x : end.x; ; } }
\r
112 public double bottom { get { return begin.y > end.y ? begin.y : end.y; ; } }
\r
113 public double width { get { return Math.abs(begin.x - end.x); } }
\r
114 public double height { get { return Math.abs(begin.y - end.y); } }
\r
115 public double getLeft() { return left; }
\r
116 public double getTop() { return top; }
\r
117 public double getRight() { return right; }
\r
118 public double getBottom() { return bottom; }
\r
119 public double getWidth() { return width; }
\r
120 public double getHeight() { return height; }
\r
122 public Color fill { get; set; }
\r
123 public Stroke stroke { get; set; }
\r
127 public partial class Rectangle : Shape
\r
129 public Point v1, v2;
\r
135 public Rectangle(double wid, double hei)
\r
139 public Rectangle(Rectangle another)
\r
144 public Rectangle set(double wid, double hei)
\r
147 v2.set(wid, hei, 0);
\r
150 Rectangle set(Point po1, Point po2) {
\r
155 public Rectangle set(double l, double t, double r, double b)
\r
161 public Rectangle set(Rectangle another)
\r
168 public Rectangle resize(double width, double height)
\r
171 set(width, height);
\r
180 set { double w = width, h = height; v1 = value; v2 = v1 + new Point(w,h); }
\r
182 public Rectangle move_to(Point p) { datum = p; return this; }
\r
183 public Rectangle move_to(double x, double y, double z) { datum = new Point(x, y, z); return this; }
\r
184 public Rectangle locate(Point p) { datum = p; return this; }
\r
185 public Rectangle locate(double x, double y, double z) { datum = new Point(x, y, z); return this; }
\r
187 public Figure shift(Point p)
\r
193 public Figure centering(Point p)
\r
195 double h = width, v = height;
\r
196 v1.x = p.x - h / 2.0;
\r
197 v1.y = p.y - v / 2.0;
\r
205 Main.drawable.rect(this);
\r
207 public bool include(double x, double y)
\r
209 return (top <= y) && (left <= x) && (bottom >= y) && (right >= x);
\r
211 public bool include(Point p)
\r
213 return (top <= p.y) && (left <= p.x) && (bottom >= p.y) && (right >= p.x);
\r
215 public bool include(Rectangle rect)
\r
217 return (top <= rect.top) && (left <= rect.left) && (bottom >= rect.bottom) && (right >= rect.right);
\r
220 public Rectangle alignLeft(double lef)
\r
222 return move_to(lef, getTop(), datum.z);
\r
224 public Rectangle alignTop(double to_)
\r
226 return move_to(getLeft(), to_, datum.z);
\r
228 public Rectangle alignRight(double rig)
\r
230 return move_to(rig - getWidth(), getTop(), datum.z);
\r
232 public Rectangle alignBottom(double bot)
\r
234 return move_to(getLeft(), bot - getHeight(), datum.z);
\r
237 public void clipped_by(Rectangle source)
\r
239 double t = top, l = left, b = bottom, r = right;
\r
240 if (top < source.top) { t = source.top; }
\r
241 if (left < source.left) { l = source.left; }
\r
242 if (bottom > source.bottom) { b = source.bottom; }
\r
243 if (right > source.right) { r = source.right; }
\r
246 public void clip(Rectangle target)
\r
248 double t = top, l = left, b = bottom, r = right;
\r
249 if (top < target.top) { t = target.top; }
\r
250 if (left < target.left) { l = target.left; }
\r
251 if (bottom > target.bottom) { b = target.bottom; }
\r
252 if (right > target.right) { r = target.right; }
\r
257 public double left { get { return v1.x; } }
\r
258 public double top { get { return v1.y; } }
\r
259 public double right { get { return v2.x; } }
\r
260 public double bottom { get { return v2.y; } }
\r
261 public double width { get { return Math.abs(v1.x - v2.x); } }
\r
262 public double height { get { return Math.abs(v1.y - v2.y); } }
\r
263 public Point center {
\r
264 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
265 set { centering(value); }
\r
267 public double getLeft() { return left; }
\r
268 public double getTop() { return top; }
\r
269 public double getRight() { return right; }
\r
270 public double getBottom() { return bottom; }
\r
271 public double getWidth() { return width; }
\r
272 public double getHeight() { return height; }
\r
273 public Point getCenter() { return center; }
\r
277 public Color fill { get; set; }
\r
278 public Stroke stroke { get; set; }
\r
280 public override string ToString()
\r
282 return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString();
\r
287 public partial class Ellipse : Shape
\r
289 public Point datum { get; set; }
\r
290 public double xdiameter, ydiameter;
\r
296 public Ellipse(double wid, double hei)
\r
301 public Ellipse set(double wid, double hei)
\r
307 public Figure shift(Point p)
\r
312 public Figure centering(Point p)
\r
320 Main.drawable.ellipse(this);
\r
323 public double left { get { return datum.x - xdiameter/2.0; } }
\r
324 public double top { get { return datum.y - ydiameter / 2.0; } }
\r
325 public double right { get { return datum.x + xdiameter / 2.0; } }
\r
326 public double bottom { get { return datum.y + ydiameter / 2.0; } }
\r
327 public double width { get { return Math.abs(xdiameter); } }
\r
328 public double height { get { return Math.abs(ydiameter); } }
\r
329 public Point center
\r
331 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
332 set { centering(value); }
\r
334 public double getLeft() { return left; }
\r
335 public double getTop() { return top; }
\r
336 public double getRight() { return right; }
\r
337 public double getBottom() { return bottom; }
\r
338 public double getWidth() { return width; }
\r
339 public double getHeight() { return height; }
\r
340 public Point getCenter() { return center; }
\r
342 public Color fill { get; set; }
\r
343 public Stroke stroke { get; set; }
\r
347 public partial class Polygon : Shape
\r
349 public Point datum { get; set; }
\r
350 public System.Collections.Generic.List<Point> vertices;
\r
354 vertices = new System.Collections.Generic.List<Point>();
\r
356 public Polygon(double[] verts)
\r
358 vertices = new System.Collections.Generic.List<Point>();
\r
359 for (int i=0; i < verts.Length; i+=2)
\r
361 vertices.Add(new Point(verts[i], verts[i+1]));
\r
365 public Polygon(Point[] verts)
\r
367 vertices = new System.Collections.Generic.List<Point>();
\r
368 foreach (Point p in verts)
\r
374 public Polygon append(Point p) { vertices.Add(p); return this; }
\r
375 public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); }
\r
376 public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); }
\r
379 public Figure shift(Point p)
\r
384 public Figure centering(Point p)
\r
392 Main.drawable.polygon(this);
\r
395 public Color fill { get; set; }
\r
396 public Stroke stroke { get; set; }
\r