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
64 public Line(double x1, double y1, double x2, double y2)
\r
66 set(x1, y1, x2, y2);
\r
68 public Line(Point v1, Point v2)
\r
72 public void set(double x1, double y1, double x2, double y2)
\r
77 public void set(Point v1, Point v2)
\r
83 public Figure shift(Point p)
\r
89 public Figure centering(Point p)
\r
91 double h = width, v = height;
\r
92 begin.x = p.x - h / 2.0;
\r
93 begin.y = p.y - v / 2.0;
\r
94 end.x = begin.x + h;
\r
95 end.y = begin.y + v;
\r
101 Main.drawable.line(this);
\r
104 public double left { get { return begin.x < end.x ? begin.x : end.x; } }
\r
105 public double top { get { return begin.y < end.y ? begin.y : end.y; ; } }
\r
106 public double right { get { return begin.x > end.x ? begin.x : end.x; ; } }
\r
107 public double bottom { get { return begin.y > end.y ? begin.y : end.y; ; } }
\r
108 public double width { get { return Math.abs(begin.x - end.x); } }
\r
109 public double height { get { return Math.abs(begin.y - end.y); } }
\r
111 public Color fill { get; set; }
\r
112 public Stroke stroke { get; set; }
\r
116 public partial class Rectangle : Shape
\r
118 public Point v1, v2;
\r
124 public Rectangle(double wid, double hei)
\r
129 public Rectangle set(double wid, double hei)
\r
132 v2.set(wid, hei, 0);
\r
136 public Figure shift(Point p)
\r
142 public Figure centering(Point p)
\r
144 double h = width, v = height;
\r
145 v1.x = p.x - h / 2.0;
\r
146 v1.y = p.y - v / 2.0;
\r
154 Main.drawable.rect(this);
\r
157 public double left { get { return v1.x; } }
\r
158 public double top { get { return v1.y; } }
\r
159 public double right { get { return v2.x; } }
\r
160 public double bottom { get { return v2.y; } }
\r
161 public double width { get { return Math.abs(v1.x - v2.x); } }
\r
162 public double height { get { return Math.abs(v1.y - v2.y); } }
\r
165 public Color fill { get; set; }
\r
166 public Stroke stroke { get; set; }
\r
171 public partial class Ellipse : Shape
\r
173 public Point datum;
\r
174 public double xdiameter, ydiameter;
\r
180 public Ellipse(double wid, double hei)
\r
185 public Ellipse set(double wid, double hei)
\r
191 public Figure shift(Point p)
\r
196 public Figure centering(Point p)
\r
204 Main.drawable.ellipse(this);
\r
207 public double left { get { return datum.x - xdiameter/2.0; } }
\r
208 public double top { get { return datum.y - ydiameter / 2.0; } }
\r
209 public double right { get { return datum.x + xdiameter / 2.0; } }
\r
210 public double bottom { get { return datum.y + ydiameter / 2.0; } }
\r
211 public double width { get { return Math.abs(xdiameter); } }
\r
212 public double height { get { return Math.abs(ydiameter); } }
\r
214 public Color fill { get; set; }
\r
215 public Stroke stroke { get; set; }
\r
219 public partial class Polygon : Shape
\r
221 public Point datum;
\r
222 public System.Collections.Generic.List<Point> vertices;
\r
226 vertices = new System.Collections.Generic.List<Point>();
\r
228 public Polygon(double[] verts)
\r
230 vertices = new System.Collections.Generic.List<Point>();
\r
231 for (int i=0; i < verts.Length; i+=2)
\r
233 vertices.Add(new Point(verts[i], verts[i+1]));
\r
237 public Polygon(Point[] verts)
\r
239 vertices = new System.Collections.Generic.List<Point>();
\r
240 foreach (Point p in verts)
\r
246 public Polygon append(Point p) { vertices.Add(p); return this; }
\r
247 public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); }
\r
248 public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); }
\r
251 public Figure shift(Point p)
\r
256 public Figure centering(Point p)
\r
264 Main.drawable.polygon(this);
\r
267 public Color fill { get; set; }
\r
268 public Stroke stroke { get; set; }
\r