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
62 public static readonly Stroke null_line = new Stroke(Color.null_color, 0);
\r
63 public static readonly Stroke hair_line = new Stroke(Color.white, 1);
\r
66 public partial class Line : Shape
\r
68 public Point begin, end;
\r
71 get { return begin; }
\r
72 set { begin = value; }
\r
75 //public static Line[] this[int x] { get { return Array(x); } }
\r
76 //public static Line[,] this[int x, int y] { get { return Array(x, y); } }
\r
77 public static Line[] Array(int ind)
\r
79 Line[] l = new Line[ind];
\r
80 for(int i=0; i<ind; i++) { l[i] = new Line(); }
\r
83 public static Line[,] Array(int indx, int indy)
\r
85 Line[,] l = new Line[indx, indy];
\r
86 for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Line(); } }
\r
94 stroke = Stroke.hair_line;
\r
97 public Line(double x1, double y1, double x2, double y2)
\r
100 stroke = Stroke.hair_line;
\r
101 set(x1, y1, x2, y2);
\r
103 public Line(Point v1, Point v2)
\r
105 fill = Color.white;
\r
106 stroke = Stroke.hair_line;
\r
109 public Line set(double x1, double y1, double x2, double y2)
\r
115 public Line set(Point v1, Point v2)
\r
122 public Figure shift(Point p)
\r
128 public Figure centering(Point p)
\r
130 double h = width, v = height;
\r
131 begin.x = p.x - h / 2.0;
\r
132 begin.y = p.y - v / 2.0;
\r
133 end.x = begin.x + h;
\r
134 end.y = begin.y + v;
\r
138 public virtual void draw()
\r
140 Main.drawable.line(this);
\r
143 public double left { get { return begin.x < end.x ? begin.x : end.x; } }
\r
144 public double top { get { return begin.y < end.y ? begin.y : end.y; ; } }
\r
145 public double right { get { return begin.x > end.x ? begin.x : end.x; ; } }
\r
146 public double bottom { get { return begin.y > end.y ? begin.y : end.y; ; } }
\r
147 public double width { get { return Math.abs(begin.x - end.x); } }
\r
148 public double height { get { return Math.abs(begin.y - end.y); } }
\r
149 public double getLeft() { return left; }
\r
150 public double getTop() { return top; }
\r
151 public double getRight() { return right; }
\r
152 public double getBottom() { return bottom; }
\r
153 public double getWidth() { return width; }
\r
154 public double getHeight() { return height; }
\r
156 public Color fill { get; set; }
\r
157 public Stroke stroke { get; set; }
\r
160 public partial class Rectangle_
\r
162 public Point v1, v2;
\r
164 public double left { get { return v1.x; } }
\r
165 public double top { get { return v1.y; } }
\r
166 public double right { get { return v2.x; } }
\r
167 public double bottom { get { return v2.y; } }
\r
168 public double width { get { return Math.abs(v1.x - v2.x); } }
\r
169 public double height { get { return Math.abs(v1.y - v2.y); } }
\r
170 public double getLeft() { return left; }
\r
171 public double getTop() { return top; }
\r
172 public double getRight() { return right; }
\r
173 public double getBottom() { return bottom; }
\r
174 public double getWidth() { return width; }
\r
175 public double getHeight() { return height; }
\r
179 public Color fill { get; set; }
\r
180 public Stroke stroke { get; set; }
\r
182 public override string ToString()
\r
184 return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString();
\r
189 public partial class Rectangle : Shape
\r
191 public Point v1, v2;
\r
193 //public static Rectangle[] this[int x] { get { return Array(x); } }
\r
194 //public static Rectangle[,] this[int x, int y] { get { return Array(x, y); } }
\r
195 public static Rectangle[] Array(int ind)
\r
197 Rectangle[] l = new Rectangle[ind];
\r
198 for (int i = 0; i < ind; i++) { l[i] = new Rectangle(); }
\r
201 public static Rectangle[,] Array(int indx, int indy)
\r
203 Rectangle[,] l = new Rectangle[indx, indy];
\r
204 for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Rectangle(); } }
\r
211 fill = Color.white;
\r
212 stroke = Stroke.null_line;
\r
215 public Rectangle(double wid, double hei)
\r
217 fill = Color.white;
\r
218 stroke = Stroke.null_line;
\r
221 public Rectangle(Rectangle another)
\r
223 fill = Color.white;
\r
224 stroke = Stroke.null_line;
\r
228 public Rectangle set(double wid, double hei)
\r
231 v2.set(wid, hei, 0);
\r
234 Rectangle set(Point po1, Point po2) {
\r
239 public Rectangle set(double l, double t, double r, double b)
\r
245 public Rectangle set(Rectangle another)
\r
252 public Rectangle resize(double width, double height)
\r
255 set(width, height);
\r
264 set { double w = width, h = height; v1 = value; v2 = v1 + new Point(w,h); }
\r
266 public Rectangle move_to(Point p) { datum = p; return this; }
\r
267 public Rectangle move_to(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }
\r
268 public Rectangle locate(Point p) { datum = p; return this; }
\r
269 public Rectangle locate(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }
\r
271 public Figure shift(Point p)
\r
277 public Figure centering(Point p)
\r
279 double h = width, v = height;
\r
280 v1.x = p.x - h / 2.0;
\r
281 v1.y = p.y - v / 2.0;
\r
287 public virtual void draw()
\r
289 Main.drawable.rect(this);
\r
291 public bool include(double x, double y)
\r
293 return (top <= y) && (left <= x) && (bottom >= y) && (right >= x);
\r
295 public bool include(Point p)
\r
297 return (top <= p.y) && (left <= p.x) && (bottom >= p.y) && (right >= p.x);
\r
299 public bool include(Rectangle rect)
\r
301 return (top <= rect.top) && (left <= rect.left) && (bottom >= rect.bottom) && (right >= rect.right);
\r
304 public Rectangle alignLeft(double lef)
\r
306 return move_to(lef, getTop(), datum.z);
\r
308 public Rectangle alignTop(double to_)
\r
310 return move_to(getLeft(), to_, datum.z);
\r
312 public Rectangle alignRight(double rig)
\r
314 return move_to(rig - getWidth(), getTop(), datum.z);
\r
316 public Rectangle alignBottom(double bot)
\r
318 return move_to(getLeft(), bot - getHeight(), datum.z);
\r
321 public void clipped_by(Rectangle source)
\r
323 double t = top, l = left, b = bottom, r = right;
\r
324 if (top < source.top) { t = source.top; }
\r
325 if (left < source.left) { l = source.left; }
\r
326 if (bottom > source.bottom) { b = source.bottom; }
\r
327 if (right > source.right) { r = source.right; }
\r
330 public void clip(Rectangle target)
\r
332 double t = top, l = left, b = bottom, r = right;
\r
333 if (top < target.top) { t = target.top; }
\r
334 if (left < target.left) { l = target.left; }
\r
335 if (bottom > target.bottom) { b = target.bottom; }
\r
336 if (right > target.right) { r = target.right; }
\r
341 public double left { get { return v1.x; } }
\r
342 public double top { get { return v1.y; } }
\r
343 public double right { get { return v2.x; } }
\r
344 public double bottom { get { return v2.y; } }
\r
345 public double width { get { return Math.abs(v1.x - v2.x); } }
\r
346 public double height { get { return Math.abs(v1.y - v2.y); } }
\r
347 public Point center {
\r
348 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
349 set { centering(value); }
\r
351 public double getLeft() { return left; }
\r
352 public double getTop() { return top; }
\r
353 public double getRight() { return right; }
\r
354 public double getBottom() { return bottom; }
\r
355 public double getWidth() { return width; }
\r
356 public double getHeight() { return height; }
\r
357 public Point getCenter() { return center; }
\r
361 public Color fill { get; set; }
\r
362 public Stroke stroke { get; set; }
\r
364 public override string ToString()
\r
366 return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString();
\r
371 public partial class Ellipse : Shape
\r
373 public Point datum { get; set; }
\r
374 public double xdiameter, ydiameter;
\r
376 //public static Ellipse[] this[int x] { get { return Array(x); } }
\r
377 //public static Ellipse[,] this[int x, int y] { get { return Array(x, y); } }
\r
378 public static Ellipse[] Array(int ind)
\r
380 Ellipse[] l = new Ellipse[ind];
\r
381 for (int i = 0; i < ind; i++) { l[i] = new Ellipse(); }
\r
384 public static Ellipse[,] Array(int indx, int indy)
\r
386 Ellipse[,] l = new Ellipse[indx, indy];
\r
387 for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Ellipse(); } }
\r
393 fill = Color.white;
\r
394 stroke = Stroke.null_line;
\r
397 public Ellipse(double wid, double hei)
\r
399 fill = Color.white;
\r
400 stroke = Stroke.null_line;
\r
404 public Ellipse set(double wid, double hei)
\r
410 public Ellipse resize(double width, double height)
\r
413 set(width, height);
\r
417 public Figure shift(Point p)
\r
422 public Figure centering(Point p)
\r
428 public virtual void draw()
\r
430 Main.drawable.ellipse(this);
\r
433 public double left { get { return datum.x - xdiameter/2.0; } }
\r
434 public double top { get { return datum.y - ydiameter / 2.0; } }
\r
435 public double right { get { return datum.x + xdiameter / 2.0; } }
\r
436 public double bottom { get { return datum.y + ydiameter / 2.0; } }
\r
437 public double width { get { return Math.abs(xdiameter); } }
\r
438 public double height { get { return Math.abs(ydiameter); } }
\r
439 public Point center
\r
441 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
442 set { centering(value); }
\r
444 public double getLeft() { return left; }
\r
445 public double getTop() { return top; }
\r
446 public double getRight() { return right; }
\r
447 public double getBottom() { return bottom; }
\r
448 public double getWidth() { return width; }
\r
449 public double getHeight() { return height; }
\r
450 public Point getCenter() { return center; }
\r
452 public Color fill { get; set; }
\r
453 public Stroke stroke { get; set; }
\r
457 public partial class Polygon : Shape
\r
459 public Point datum { get; set; }
\r
460 public System.Collections.Generic.List<Point> vertices;
\r
464 fill = Color.white;
\r
465 stroke = Stroke.null_line;
\r
466 vertices = new System.Collections.Generic.List<Point>();
\r
468 public Polygon(double[] verts)
\r
470 fill = Color.white;
\r
471 stroke = Stroke.null_line;
\r
472 vertices = new System.Collections.Generic.List<Point>();
\r
473 for (int i=0; i < verts.Length; i+=2)
\r
475 vertices.Add(new Point(verts[i], verts[i+1]));
\r
479 public Polygon(Point[] verts)
\r
481 fill = Color.white;
\r
482 stroke = Stroke.null_line;
\r
483 vertices = new System.Collections.Generic.List<Point>();
\r
484 foreach (Point p in verts)
\r
490 public Polygon append(Point p) { vertices.Add(p); return this; }
\r
491 public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); }
\r
492 public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); }
\r
495 public Figure shift(Point p)
\r
500 public Figure centering(Point p)
\r
506 public virtual void draw()
\r
508 Main.drawable.polygon(this);
\r
511 public Color fill { get; set; }
\r
512 public Stroke stroke { get; set; }
\r