using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace Psychlops{ public interface Shape : Internal.PrimitiveFigure { Color fill { get; set; } Stroke stroke { get; set; } } public static class ShapeExtention { public static void draw(this Shape drawee, Color c) { Color tmp_col = drawee.fill; Stroke tmp_strk = drawee.stroke; drawee.fill = c; drawee.stroke = new Stroke(); drawee.draw(); drawee.fill = tmp_col; drawee.stroke = tmp_strk; } public static void draw(this Shape drawee, Stroke strk) { Color tmp_col = drawee.fill; Stroke tmp_strk = drawee.stroke; drawee.fill = new Color(0,0,1,1); drawee.stroke = strk; drawee.draw(); drawee.fill = tmp_col; drawee.stroke = tmp_strk; } } public partial struct Stroke { public double thick; public Color color; public Stroke(Color c, double t) { color = c; thick = t; } public void set(Color c, double t) { color = c; thick = t; } } public partial class Line : Shape { public Point begin, end; public Line(double x1, double y1, double x2, double y2) { set(x1, y1, x2, y2); } public Line(Point v1, Point v2) { set(v1, v2); } public void set(double x1, double y1, double x2, double y2) { begin.set(x1, y1); end.set(x2, y2); } public void set(Point v1, Point v2) { begin = v1; end = v2; } public Figure shift(Point p) { begin += p; end += p; return this; } public Figure centering(Point p) { double h = width, v = height; begin.x = p.x - h / 2.0; begin.y = p.y - v / 2.0; end.x = begin.x + h; end.y = begin.y + v; return this; } public void draw() { Main.drawable.line(this); } public double left { get { return begin.x < end.x ? begin.x : end.x; } } public double top { get { return begin.y < end.y ? begin.y : end.y; ; } } public double right { get { return begin.x > end.x ? begin.x : end.x; ; } } public double bottom { get { return begin.y > end.y ? begin.y : end.y; ; } } public double width { get { return Math.abs(begin.x - end.x); } } public double height { get { return Math.abs(begin.y - end.y); } } public Color fill { get; set; } public Stroke stroke { get; set; } } public partial class Rectangle : Shape { public Point v1, v2; public Rectangle() { set(0,0); } public Rectangle(double wid, double hei) { set(wid, hei); } public Rectangle set(double wid, double hei) { v1.set(0, 0, 0); v2.set(wid, hei, 0); return this; } public Figure shift(Point p) { v1 += p; v2 += p; return this; } public Figure centering(Point p) { double h = width, v = height; v1.x = p.x - h / 2.0; v1.y = p.y - v / 2.0; v2.x = v1.x + h; v2.y = v1.y + v; return this; } public void draw() { Main.drawable.rect(this); } public double left { get { return v1.x; } } public double top { get { return v1.y; } } public double right { get { return v2.x; } } public double bottom { get { return v2.y; } } public double width { get { return Math.abs(v1.x - v2.x); } } public double height { get { return Math.abs(v1.y - v2.y); } } public Color fill { get; set; } public Stroke stroke { get; set; } public override string ToString() { return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString(); } } public partial class Ellipse : Shape { public Point datum; public double xdiameter, ydiameter; public Ellipse() { set(0,0); } public Ellipse(double wid, double hei) { set(wid, hei); } public Ellipse set(double wid, double hei) { xdiameter = wid; ydiameter = hei; return this; } public Figure shift(Point p) { datum += p; return this; } public Figure centering(Point p) { datum = p; return this; } public void draw() { Main.drawable.ellipse(this); } public double left { get { return datum.x - xdiameter/2.0; } } public double top { get { return datum.y - ydiameter / 2.0; } } public double right { get { return datum.x + xdiameter / 2.0; } } public double bottom { get { return datum.y + ydiameter / 2.0; } } public double width { get { return Math.abs(xdiameter); } } public double height { get { return Math.abs(ydiameter); } } public Color fill { get; set; } public Stroke stroke { get; set; } } public partial class Polygon : Shape { public Point datum; public System.Collections.Generic.List vertices; public Polygon() { vertices = new System.Collections.Generic.List(); } public Polygon(double[] verts) { vertices = new System.Collections.Generic.List(); for (int i=0; i < verts.Length; i+=2) { vertices.Add(new Point(verts[i], verts[i+1])); } } public Polygon(Point[] verts) { vertices = new System.Collections.Generic.List(); foreach (Point p in verts) { vertices.Add(p); } } public Polygon append(Point p) { vertices.Add(p); return this; } public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); } public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); } public Figure shift(Point p) { datum += p; return this; } public Figure centering(Point p) { datum = p; return this; } public void draw() { Main.drawable.polygon(this); } public Color fill { get; set; } public Stroke stroke { get; set; } } }