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
161 public partial class Rectangle : Shape
\r
163 public Point v1, v2;
\r
165 //public static Rectangle[] this[int x] { get { return Array(x); } }
\r
166 //public static Rectangle[,] this[int x, int y] { get { return Array(x, y); } }
\r
167 public static Rectangle[] Array(int ind)
\r
169 Rectangle[] l = new Rectangle[ind];
\r
170 for (int i = 0; i < ind; i++) { l[i] = new Rectangle(); }
\r
173 public static Rectangle[,] Array(int indx, int indy)
\r
175 Rectangle[,] l = new Rectangle[indx, indy];
\r
176 for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Rectangle(); } }
\r
183 fill = Color.white;
\r
184 stroke = Stroke.null_line;
\r
187 public Rectangle(double wid, double hei)
\r
189 fill = Color.white;
\r
190 stroke = Stroke.null_line;
\r
193 public Rectangle(Rectangle another)
\r
195 fill = Color.white;
\r
196 stroke = Stroke.null_line;
\r
200 public Rectangle set(double wid, double hei)
\r
203 v2.set(wid, hei, 0);
\r
206 Rectangle set(Point po1, Point po2) {
\r
211 public Rectangle set(double l, double t, double r, double b)
\r
217 public Rectangle set(Rectangle another)
\r
224 public Rectangle resize(double width, double height)
\r
227 set(width, height);
\r
236 set { double w = width, h = height; v1 = value; v2 = v1 + new Point(w,h); }
\r
238 public Rectangle move_to(Point p) { datum = p; return this; }
\r
239 public Rectangle move_to(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }
\r
240 public Rectangle locate(Point p) { datum = p; return this; }
\r
241 public Rectangle locate(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }
\r
243 public Figure shift(Point p)
\r
249 public Figure centering(Point p)
\r
251 double h = width, v = height;
\r
252 v1.x = p.x - h / 2.0;
\r
253 v1.y = p.y - v / 2.0;
\r
259 public virtual void draw()
\r
261 Main.drawable.rect(this);
\r
263 public bool include(double x, double y)
\r
265 return (top <= y) && (left <= x) && (bottom >= y) && (right >= x);
\r
267 public bool include(Point p)
\r
269 return (top <= p.y) && (left <= p.x) && (bottom >= p.y) && (right >= p.x);
\r
271 public bool include(Rectangle rect)
\r
273 return (top <= rect.top) && (left <= rect.left) && (bottom >= rect.bottom) && (right >= rect.right);
\r
276 public Rectangle alignLeft(double lef)
\r
278 return move_to(lef, getTop(), datum.z);
\r
280 public Rectangle alignTop(double to_)
\r
282 return move_to(getLeft(), to_, datum.z);
\r
284 public Rectangle alignRight(double rig)
\r
286 return move_to(rig - getWidth(), getTop(), datum.z);
\r
288 public Rectangle alignBottom(double bot)
\r
290 return move_to(getLeft(), bot - getHeight(), datum.z);
\r
293 public void clipped_by(Rectangle source)
\r
295 double t = top, l = left, b = bottom, r = right;
\r
296 if (top < source.top) { t = source.top; }
\r
297 if (left < source.left) { l = source.left; }
\r
298 if (bottom > source.bottom) { b = source.bottom; }
\r
299 if (right > source.right) { r = source.right; }
\r
302 public void clip(Rectangle target)
\r
304 double t = top, l = left, b = bottom, r = right;
\r
305 if (top < target.top) { t = target.top; }
\r
306 if (left < target.left) { l = target.left; }
\r
307 if (bottom > target.bottom) { b = target.bottom; }
\r
308 if (right > target.right) { r = target.right; }
\r
313 public double left { get { return v1.x; } }
\r
314 public double top { get { return v1.y; } }
\r
315 public double right { get { return v2.x; } }
\r
316 public double bottom { get { return v2.y; } }
\r
317 public double width { get { return Math.abs(v1.x - v2.x); } }
\r
318 public double height { get { return Math.abs(v1.y - v2.y); } }
\r
319 public Point center {
\r
320 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
321 set { centering(value); }
\r
323 public double getLeft() { return left; }
\r
324 public double getTop() { return top; }
\r
325 public double getRight() { return right; }
\r
326 public double getBottom() { return bottom; }
\r
327 public double getWidth() { return width; }
\r
328 public double getHeight() { return height; }
\r
329 public Point getCenter() { return center; }
\r
333 public Color fill { get; set; }
\r
334 public Stroke stroke { get; set; }
\r
336 public override string ToString()
\r
338 return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString();
\r
343 public partial class Ellipse : Shape
\r
345 public Point datum { get; set; }
\r
346 public double xdiameter, ydiameter;
\r
348 //public static Ellipse[] this[int x] { get { return Array(x); } }
\r
349 //public static Ellipse[,] this[int x, int y] { get { return Array(x, y); } }
\r
350 public static Ellipse[] Array(int ind)
\r
352 Ellipse[] l = new Ellipse[ind];
\r
353 for (int i = 0; i < ind; i++) { l[i] = new Ellipse(); }
\r
356 public static Ellipse[,] Array(int indx, int indy)
\r
358 Ellipse[,] l = new Ellipse[indx, indy];
\r
359 for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Ellipse(); } }
\r
365 fill = Color.white;
\r
366 stroke = Stroke.null_line;
\r
369 public Ellipse(double wid, double hei)
\r
371 fill = Color.white;
\r
372 stroke = Stroke.null_line;
\r
376 public Ellipse set(double wid, double hei)
\r
382 public Ellipse resize(double width, double height)
\r
385 set(width, height);
\r
389 public Figure shift(Point p)
\r
394 public Figure centering(Point p)
\r
400 public virtual void draw()
\r
402 Main.drawable.ellipse(this);
\r
405 public double left { get { return datum.x - xdiameter/2.0; } }
\r
406 public double top { get { return datum.y - ydiameter / 2.0; } }
\r
407 public double right { get { return datum.x + xdiameter / 2.0; } }
\r
408 public double bottom { get { return datum.y + ydiameter / 2.0; } }
\r
409 public double width { get { return Math.abs(xdiameter); } }
\r
410 public double height { get { return Math.abs(ydiameter); } }
\r
411 public Point center
\r
413 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
414 set { centering(value); }
\r
416 public double getLeft() { return left; }
\r
417 public double getTop() { return top; }
\r
418 public double getRight() { return right; }
\r
419 public double getBottom() { return bottom; }
\r
420 public double getWidth() { return width; }
\r
421 public double getHeight() { return height; }
\r
422 public Point getCenter() { return center; }
\r
424 public Color fill { get; set; }
\r
425 public Stroke stroke { get; set; }
\r
429 public partial class Polygon : Shape
\r
431 public Point datum { get; set; }
\r
432 public System.Collections.Generic.List<Point> vertices;
\r
436 fill = Color.white;
\r
437 stroke = Stroke.null_line;
\r
438 vertices = new System.Collections.Generic.List<Point>();
\r
440 public Polygon(double[] verts)
\r
442 fill = Color.white;
\r
443 stroke = Stroke.null_line;
\r
444 vertices = new System.Collections.Generic.List<Point>();
\r
445 for (int i=0; i < verts.Length; i+=2)
\r
447 vertices.Add(new Point(verts[i], verts[i+1]));
\r
451 public Polygon(Point[] verts)
\r
453 fill = Color.white;
\r
454 stroke = Stroke.null_line;
\r
455 vertices = new System.Collections.Generic.List<Point>();
\r
456 foreach (Point p in verts)
\r
462 public Polygon append(Point p) { vertices.Add(p); return this; }
\r
463 public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); }
\r
464 public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); }
\r
467 public Figure shift(Point p)
\r
472 public Figure centering(Point p)
\r
478 public virtual void draw()
\r
480 Main.drawable.polygon(this);
\r
483 public Color fill { get; set; }
\r
484 public Stroke stroke { get; set; }
\r