2 using System.Windows;
\r
7 public static class StaticFunctions
\r
9 public static T[] NewArray<T>(int x)
\r
13 for (int i = 0; i < x; i++)
\r
19 public static T[,] NewArray<T>(int x, int y)
\r
22 T[,] t = new T[x,y];
\r
23 for (int i = 0; i < x; i++)
\r
25 for (int j = 0; j < x; j++)
\r
32 public static T[,,] NewArray<T>(int x, int y, int z)
\r
35 T[,,] t = new T[x, y, z];
\r
36 for (int i = 0; i < x; i++)
\r
38 for (int j = 0; j < y; j++)
\r
40 for (int k = 0; k < z; k++)
\r
42 t[i, j, k] = new T();
\r
50 public partial struct Point
\r
52 public double x, y, z;
\r
53 public Point(double dx, double dy, double dz = 0.0)
\r
59 public Point set(double dx, double dy, double dz = 0.0)
\r
67 public static Point operator +(Point lhs, Point rhs)
\r
69 return new Point(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);
\r
71 public static Point operator -(Point lhs, Point rhs)
\r
73 return new Point(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);
\r
75 public override string ToString()
\r
77 return "X:"+ x.ToString() + " Y:"+ y.ToString() + " Z:"+ z.ToString();
\r
82 public partial struct Color
\r
84 public double r, g, b, a;
\r
85 public Color(double lum)
\r
90 public Color(double red, double green, double blue, double alpha = 1.0)
\r
97 public void set(double lum)
\r
102 public void set(double red, double green, double blue, double alpha = 1.0)
\r
110 public override string ToString()
\r
112 return "R:" + r.ToString() + " G:" + g.ToString() + " B:" + b.ToString() + " A:" + a.ToString();
\r
115 public static readonly Color
\r
116 black = new Color(0, 0, 0, 1),
\r
117 red = new Color(1, 0, 0, 1),
\r
118 green = new Color(0, 1, 0, 1),
\r
119 blue = new Color(0, 0, 1, 1),
\r
120 yellow = new Color(1, 1, 0, 1),
\r
121 magenta = new Color(1, 0, 1, 1),
\r
122 cyan = new Color(0, 1, 1, 1),
\r
123 gray = new Color(.5, .5, .5, 1),
\r
124 white = new Color(1, 1, 1, 1),
\r
125 null_color = new Color(0, 0, 0, 0),
\r
126 transparent = new Color(0, 0, 0, 0);
\r
131 public interface Drawable
\r
134 void clear(Color col);
\r
135 void pix(int x, int y, Color col);
\r
136 void line(Line drawee);
\r
137 void rect(Rectangle drawee);
\r
138 void ellipse(Ellipse drawee);
\r
139 void polygon(Polygon drawee);
\r
140 void letters(Letters drawee);
\r
141 void image(Image drawee);
\r
142 void group(Group drawee);
\r
143 void msg(string s, double x, double y, Color c);
\r
148 public interface Figure
\r
150 Point datum { get; set; }
\r
151 Figure shift(Point p);
\r
152 Figure centering(Point p);
\r
155 public static class FigureExtention
\r
157 public static Point getDatum(this Figure target)
\r
159 return target.datum;
\r
161 public static Point setDatum(this Figure target, Point p)
\r
164 return target.datum;
\r
166 public static Figure shift(this Figure target, double x, double y, double z = 0.0)
\r
168 return target.shift(new Point(x, y, z));
\r
170 public static Figure centering(this Figure target)
\r
172 return target.centering(Main.drawable.getCenter());
\r
174 public static Figure centering(this Figure target, double x, double y, double z = 0.0)
\r
176 return target.centering(new Point(x, y, z));
\r
182 public interface PrimitiveFigure : Figure
\r
184 UIElement toNative();
\r
185 UIElement poolNative(Canvas c);
\r
189 public partial class Group : Internal.PrimitiveFigure
\r
191 System.Collections.Generic.List<Figure> list;
\r
192 System.Windows.Controls.Canvas cnvs;
\r
193 System.Windows.Media.TransformGroup trans;
\r
194 System.Windows.Media.TransformCollection transF;
\r
195 System.Windows.Media.RotateTransform rotateF;
\r
196 SimpleProcedure setRotation_;
\r
197 System.Windows.Media.ScaleTransform scaleF;
\r
198 SimpleProcedure setScaling_;
\r
199 System.Windows.Media.TranslateTransform translateF;
\r
203 public double rotation
\r
205 get { return rotation_; }
\r
206 set { rotation_ = value; rotateF.Dispatcher.BeginInvoke(setRotation_); }
\r
214 public Point scaling
\r
216 get { return scaling_; }
\r
217 set { scaling_ = value; scaleF.Dispatcher.BeginInvoke(setScaling_); }
\r
220 AppendFunc1 append_;
\r
224 setRotation_ = new SimpleProcedure(setRotation__);
\r
225 setScaling_ = new SimpleProcedure(setScaling__);
\r
226 append_ = new AppendFunc1(append__);
\r
227 list = new System.Collections.Generic.List<Figure>();
\r
230 while (!AsyncBool) { }
\r
233 public Group append(Internal.PrimitiveFigure fig)
\r
236 cnvs.Dispatcher.BeginInvoke(append_, fig);
\r
240 public Point datum { get; set; }
\r
241 public Figure shift(Point p)
\r
246 public Figure centering(Point p)
\r
253 Main.drawable.group(this);
\r