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 Line set(double x1, double y1, double x2, double y2)
\r
83 public Line set(Point v1, Point v2)
\r
90 public Figure shift(Point p)
\r
96 public Figure centering(Point p)
\r
98 double h = width, v = height;
\r
99 begin.x = p.x - h / 2.0;
\r
100 begin.y = p.y - v / 2.0;
\r
101 end.x = begin.x + h;
\r
102 end.y = begin.y + v;
\r
106 public virtual void draw()
\r
108 Main.drawable.line(this);
\r
111 public double left { get { return begin.x < end.x ? begin.x : end.x; } }
\r
112 public double top { get { return begin.y < end.y ? begin.y : end.y; ; } }
\r
113 public double right { get { return begin.x > end.x ? begin.x : end.x; ; } }
\r
114 public double bottom { get { return begin.y > end.y ? begin.y : end.y; ; } }
\r
115 public double width { get { return Math.abs(begin.x - end.x); } }
\r
116 public double height { get { return Math.abs(begin.y - end.y); } }
\r
117 public double getLeft() { return left; }
\r
118 public double getTop() { return top; }
\r
119 public double getRight() { return right; }
\r
120 public double getBottom() { return bottom; }
\r
121 public double getWidth() { return width; }
\r
122 public double getHeight() { return height; }
\r
124 public Color fill { get; set; }
\r
125 public Stroke stroke { get; set; }
\r
129 public partial class Rectangle : Shape
\r
131 public Point v1, v2;
\r
137 public Rectangle(double wid, double hei)
\r
141 public Rectangle(Rectangle another)
\r
146 public Rectangle set(double wid, double hei)
\r
149 v2.set(wid, hei, 0);
\r
152 Rectangle set(Point po1, Point po2) {
\r
157 public Rectangle set(double l, double t, double r, double b)
\r
163 public Rectangle set(Rectangle another)
\r
170 public Rectangle resize(double width, double height)
\r
173 set(width, height);
\r
182 set { double w = width, h = height; v1 = value; v2 = v1 + new Point(w,h); }
\r
184 public Rectangle move_to(Point p) { datum = p; return this; }
\r
185 public Rectangle move_to(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }
\r
186 public Rectangle locate(Point p) { datum = p; return this; }
\r
187 public Rectangle locate(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }
\r
189 public Figure shift(Point p)
\r
195 public Figure centering(Point p)
\r
197 double h = width, v = height;
\r
198 v1.x = p.x - h / 2.0;
\r
199 v1.y = p.y - v / 2.0;
\r
205 public virtual void draw()
\r
207 Main.drawable.rect(this);
\r
209 public bool include(double x, double y)
\r
211 return (top <= y) && (left <= x) && (bottom >= y) && (right >= x);
\r
213 public bool include(Point p)
\r
215 return (top <= p.y) && (left <= p.x) && (bottom >= p.y) && (right >= p.x);
\r
217 public bool include(Rectangle rect)
\r
219 return (top <= rect.top) && (left <= rect.left) && (bottom >= rect.bottom) && (right >= rect.right);
\r
222 public Rectangle alignLeft(double lef)
\r
224 return move_to(lef, getTop(), datum.z);
\r
226 public Rectangle alignTop(double to_)
\r
228 return move_to(getLeft(), to_, datum.z);
\r
230 public Rectangle alignRight(double rig)
\r
232 return move_to(rig - getWidth(), getTop(), datum.z);
\r
234 public Rectangle alignBottom(double bot)
\r
236 return move_to(getLeft(), bot - getHeight(), datum.z);
\r
239 public void clipped_by(Rectangle source)
\r
241 double t = top, l = left, b = bottom, r = right;
\r
242 if (top < source.top) { t = source.top; }
\r
243 if (left < source.left) { l = source.left; }
\r
244 if (bottom > source.bottom) { b = source.bottom; }
\r
245 if (right > source.right) { r = source.right; }
\r
248 public void clip(Rectangle target)
\r
250 double t = top, l = left, b = bottom, r = right;
\r
251 if (top < target.top) { t = target.top; }
\r
252 if (left < target.left) { l = target.left; }
\r
253 if (bottom > target.bottom) { b = target.bottom; }
\r
254 if (right > target.right) { r = target.right; }
\r
259 public double left { get { return v1.x; } }
\r
260 public double top { get { return v1.y; } }
\r
261 public double right { get { return v2.x; } }
\r
262 public double bottom { get { return v2.y; } }
\r
263 public double width { get { return Math.abs(v1.x - v2.x); } }
\r
264 public double height { get { return Math.abs(v1.y - v2.y); } }
\r
265 public Point center {
\r
266 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
267 set { centering(value); }
\r
269 public double getLeft() { return left; }
\r
270 public double getTop() { return top; }
\r
271 public double getRight() { return right; }
\r
272 public double getBottom() { return bottom; }
\r
273 public double getWidth() { return width; }
\r
274 public double getHeight() { return height; }
\r
275 public Point getCenter() { return center; }
\r
279 public Color fill { get; set; }
\r
280 public Stroke stroke { get; set; }
\r
282 public override string ToString()
\r
284 return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString();
\r
289 public partial class Ellipse : Shape
\r
291 public Point datum { get; set; }
\r
292 public double xdiameter, ydiameter;
\r
298 public Ellipse(double wid, double hei)
\r
303 public Ellipse set(double wid, double hei)
\r
309 public Ellipse resize(double width, double height)
\r
312 set(width, height);
\r
316 public Figure shift(Point p)
\r
321 public Figure centering(Point p)
\r
327 public virtual void draw()
\r
329 Main.drawable.ellipse(this);
\r
332 public double left { get { return datum.x - xdiameter/2.0; } }
\r
333 public double top { get { return datum.y - ydiameter / 2.0; } }
\r
334 public double right { get { return datum.x + xdiameter / 2.0; } }
\r
335 public double bottom { get { return datum.y + ydiameter / 2.0; } }
\r
336 public double width { get { return Math.abs(xdiameter); } }
\r
337 public double height { get { return Math.abs(ydiameter); } }
\r
338 public Point center
\r
340 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
341 set { centering(value); }
\r
343 public double getLeft() { return left; }
\r
344 public double getTop() { return top; }
\r
345 public double getRight() { return right; }
\r
346 public double getBottom() { return bottom; }
\r
347 public double getWidth() { return width; }
\r
348 public double getHeight() { return height; }
\r
349 public Point getCenter() { return center; }
\r
351 public Color fill { get; set; }
\r
352 public Stroke stroke { get; set; }
\r
356 public partial class Polygon : Shape
\r
358 public Point datum { get; set; }
\r
359 public System.Collections.Generic.List<Point> vertices;
\r
363 vertices = new System.Collections.Generic.List<Point>();
\r
365 public Polygon(double[] verts)
\r
367 vertices = new System.Collections.Generic.List<Point>();
\r
368 for (int i=0; i < verts.Length; i+=2)
\r
370 vertices.Add(new Point(verts[i], verts[i+1]));
\r
374 public Polygon(Point[] verts)
\r
376 vertices = new System.Collections.Generic.List<Point>();
\r
377 foreach (Point p in verts)
\r
383 public Polygon append(Point p) { vertices.Add(p); return this; }
\r
384 public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); }
\r
385 public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); }
\r
388 public Figure shift(Point p)
\r
393 public Figure centering(Point p)
\r
399 public virtual void draw()
\r
401 Main.drawable.polygon(this);
\r
404 public Color fill { get; set; }
\r
405 public Stroke stroke { get; set; }
\r