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, double c)
\r
24 drawee.draw( new Color(c) );
\r
26 public static void draw(this Shape drawee, Color c)
\r
28 Color tmp_col = drawee.fill;
\r
29 Stroke tmp_strk = drawee.stroke;
\r
31 drawee.stroke = new Stroke();
\r
33 drawee.fill = tmp_col;
\r
34 drawee.stroke = tmp_strk;
\r
36 public static void draw(this Shape drawee, Stroke strk)
\r
38 Color tmp_col = drawee.fill;
\r
39 Stroke tmp_strk = drawee.stroke;
\r
40 drawee.fill = new Color(0,0,1,1);
\r
41 drawee.stroke = strk;
\r
43 drawee.fill = tmp_col;
\r
44 drawee.stroke = tmp_strk;
\r
48 public partial struct Stroke
\r
50 public double thick;
\r
52 public Stroke(Color c, double t)
\r
57 public void set(Color c, double t)
\r
64 public partial class Line : Shape
\r
66 public Point begin, end;
\r
69 get { return begin; }
\r
70 set { begin = value; }
\r
73 public Line(double x1, double y1, double x2, double y2)
\r
75 set(x1, y1, x2, y2);
\r
77 public Line(Point v1, Point v2)
\r
81 public Line set(double x1, double y1, double x2, double y2)
\r
87 public Line set(Point v1, Point v2)
\r
94 public Figure shift(Point p)
\r
100 public Figure centering(Point p)
\r
102 double h = width, v = height;
\r
103 begin.x = p.x - h / 2.0;
\r
104 begin.y = p.y - v / 2.0;
\r
105 end.x = begin.x + h;
\r
106 end.y = begin.y + v;
\r
110 public virtual void draw()
\r
112 Main.drawable.line(this);
\r
115 public double left { get { return begin.x < end.x ? begin.x : end.x; } }
\r
116 public double top { get { return begin.y < end.y ? begin.y : end.y; ; } }
\r
117 public double right { get { return begin.x > end.x ? begin.x : end.x; ; } }
\r
118 public double bottom { get { return begin.y > end.y ? begin.y : end.y; ; } }
\r
119 public double width { get { return Math.abs(begin.x - end.x); } }
\r
120 public double height { get { return Math.abs(begin.y - end.y); } }
\r
121 public double getLeft() { return left; }
\r
122 public double getTop() { return top; }
\r
123 public double getRight() { return right; }
\r
124 public double getBottom() { return bottom; }
\r
125 public double getWidth() { return width; }
\r
126 public double getHeight() { return height; }
\r
128 public Color fill { get; set; }
\r
129 public Stroke stroke { get; set; }
\r
133 public partial class Rectangle : Shape
\r
135 public Point v1, v2;
\r
141 public Rectangle(double wid, double hei)
\r
145 public Rectangle(Rectangle another)
\r
150 public Rectangle set(double wid, double hei)
\r
153 v2.set(wid, hei, 0);
\r
156 Rectangle set(Point po1, Point po2) {
\r
161 public Rectangle set(double l, double t, double r, double b)
\r
167 public Rectangle set(Rectangle another)
\r
174 public Rectangle resize(double width, double height)
\r
177 set(width, height);
\r
186 set { double w = width, h = height; v1 = value; v2 = v1 + new Point(w,h); }
\r
188 public Rectangle move_to(Point p) { datum = p; return this; }
\r
189 public Rectangle move_to(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }
\r
190 public Rectangle locate(Point p) { datum = p; return this; }
\r
191 public Rectangle locate(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }
\r
193 public Figure shift(Point p)
\r
199 public Figure centering(Point p)
\r
201 double h = width, v = height;
\r
202 v1.x = p.x - h / 2.0;
\r
203 v1.y = p.y - v / 2.0;
\r
209 public virtual void draw()
\r
211 Main.drawable.rect(this);
\r
213 public bool include(double x, double y)
\r
215 return (top <= y) && (left <= x) && (bottom >= y) && (right >= x);
\r
217 public bool include(Point p)
\r
219 return (top <= p.y) && (left <= p.x) && (bottom >= p.y) && (right >= p.x);
\r
221 public bool include(Rectangle rect)
\r
223 return (top <= rect.top) && (left <= rect.left) && (bottom >= rect.bottom) && (right >= rect.right);
\r
226 public Rectangle alignLeft(double lef)
\r
228 return move_to(lef, getTop(), datum.z);
\r
230 public Rectangle alignTop(double to_)
\r
232 return move_to(getLeft(), to_, datum.z);
\r
234 public Rectangle alignRight(double rig)
\r
236 return move_to(rig - getWidth(), getTop(), datum.z);
\r
238 public Rectangle alignBottom(double bot)
\r
240 return move_to(getLeft(), bot - getHeight(), datum.z);
\r
243 public void clipped_by(Rectangle source)
\r
245 double t = top, l = left, b = bottom, r = right;
\r
246 if (top < source.top) { t = source.top; }
\r
247 if (left < source.left) { l = source.left; }
\r
248 if (bottom > source.bottom) { b = source.bottom; }
\r
249 if (right > source.right) { r = source.right; }
\r
252 public void clip(Rectangle target)
\r
254 double t = top, l = left, b = bottom, r = right;
\r
255 if (top < target.top) { t = target.top; }
\r
256 if (left < target.left) { l = target.left; }
\r
257 if (bottom > target.bottom) { b = target.bottom; }
\r
258 if (right > target.right) { r = target.right; }
\r
263 public double left { get { return v1.x; } }
\r
264 public double top { get { return v1.y; } }
\r
265 public double right { get { return v2.x; } }
\r
266 public double bottom { get { return v2.y; } }
\r
267 public double width { get { return Math.abs(v1.x - v2.x); } }
\r
268 public double height { get { return Math.abs(v1.y - v2.y); } }
\r
269 public Point center {
\r
270 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
271 set { centering(value); }
\r
273 public double getLeft() { return left; }
\r
274 public double getTop() { return top; }
\r
275 public double getRight() { return right; }
\r
276 public double getBottom() { return bottom; }
\r
277 public double getWidth() { return width; }
\r
278 public double getHeight() { return height; }
\r
279 public Point getCenter() { return center; }
\r
283 public Color fill { get; set; }
\r
284 public Stroke stroke { get; set; }
\r
286 public override string ToString()
\r
288 return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString();
\r
293 public partial class Ellipse : Shape
\r
295 public Point datum { get; set; }
\r
296 public double xdiameter, ydiameter;
\r
302 public Ellipse(double wid, double hei)
\r
307 public Ellipse set(double wid, double hei)
\r
313 public Ellipse resize(double width, double height)
\r
316 set(width, height);
\r
320 public Figure shift(Point p)
\r
325 public Figure centering(Point p)
\r
331 public virtual void draw()
\r
333 Main.drawable.ellipse(this);
\r
336 public double left { get { return datum.x - xdiameter/2.0; } }
\r
337 public double top { get { return datum.y - ydiameter / 2.0; } }
\r
338 public double right { get { return datum.x + xdiameter / 2.0; } }
\r
339 public double bottom { get { return datum.y + ydiameter / 2.0; } }
\r
340 public double width { get { return Math.abs(xdiameter); } }
\r
341 public double height { get { return Math.abs(ydiameter); } }
\r
342 public Point center
\r
344 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
345 set { centering(value); }
\r
347 public double getLeft() { return left; }
\r
348 public double getTop() { return top; }
\r
349 public double getRight() { return right; }
\r
350 public double getBottom() { return bottom; }
\r
351 public double getWidth() { return width; }
\r
352 public double getHeight() { return height; }
\r
353 public Point getCenter() { return center; }
\r
355 public Color fill { get; set; }
\r
356 public Stroke stroke { get; set; }
\r
360 public partial class Polygon : Shape
\r
362 public Point datum { get; set; }
\r
363 public System.Collections.Generic.List<Point> vertices;
\r
367 vertices = new System.Collections.Generic.List<Point>();
\r
369 public Polygon(double[] verts)
\r
371 vertices = new System.Collections.Generic.List<Point>();
\r
372 for (int i=0; i < verts.Length; i+=2)
\r
374 vertices.Add(new Point(verts[i], verts[i+1]));
\r
378 public Polygon(Point[] verts)
\r
380 vertices = new System.Collections.Generic.List<Point>();
\r
381 foreach (Point p in verts)
\r
387 public Polygon append(Point p) { vertices.Add(p); return this; }
\r
388 public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); }
\r
389 public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); }
\r
392 public Figure shift(Point p)
\r
397 public Figure centering(Point p)
\r
403 public virtual void draw()
\r
405 Main.drawable.polygon(this);
\r
408 public Color fill { get; set; }
\r
409 public Stroke stroke { get; set; }
\r