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 shader(ShaderField drawee);
\r
144 void msg(string s, double x, double y, Color c);
\r
149 public interface Figure
\r
151 Point datum { get; set; }
\r
152 Figure shift(Point p);
\r
153 Figure centering(Point p);
\r
156 public static class FigureExtention
\r
158 public static Point getDatum(this Figure target)
\r
160 return target.datum;
\r
162 public static Point setDatum(this Figure target, Point p)
\r
165 return target.datum;
\r
167 public static Figure shift(this Figure target, double x, double y, double z = 0.0)
\r
169 return target.shift(new Point(x, y, z));
\r
171 public static Figure centering(this Figure target)
\r
173 return target.centering(Main.drawable.getCenter());
\r
175 public static Figure centering(this Figure target, double x, double y, double z = 0.0)
\r
177 return target.centering(new Point(x, y, z));
\r
183 public interface PrimitiveFigure : Figure
\r
185 UIElement toNative();
\r
186 UIElement poolNative(Canvas c);
\r
190 public partial class Group : Internal.PrimitiveFigure
\r
192 System.Collections.Generic.List<Figure> list;
\r
193 System.Windows.Controls.Canvas cnvs;
\r
194 System.Windows.Media.TransformGroup trans;
\r
195 System.Windows.Media.TransformCollection transF;
\r
196 System.Windows.Media.RotateTransform rotateF;
\r
197 SimpleProcedure setRotation_;
\r
198 System.Windows.Media.ScaleTransform scaleF;
\r
199 SimpleProcedure setScaling_;
\r
200 System.Windows.Media.TranslateTransform translateF;
\r
204 public double rotation
\r
206 get { return rotation_; }
\r
207 set { rotation_ = value; rotateF.Dispatcher.BeginInvoke(setRotation_); }
\r
215 public Point scaling
\r
217 get { return scaling_; }
\r
218 set { scaling_ = value; scaleF.Dispatcher.BeginInvoke(setScaling_); }
\r
221 AppendFunc1 append_;
\r
225 setRotation_ = new SimpleProcedure(setRotation__);
\r
226 setScaling_ = new SimpleProcedure(setScaling__);
\r
227 append_ = new AppendFunc1(append__);
\r
228 list = new System.Collections.Generic.List<Figure>();
\r
231 while (!AsyncBool) { }
\r
234 public Group append(Internal.PrimitiveFigure fig)
\r
237 cnvs.Dispatcher.BeginInvoke(append_, fig);
\r
241 public Point datum { get; set; }
\r
242 public Figure shift(Point p)
\r
247 public Figure centering(Point p)
\r
254 Main.drawable.group(this);
\r
260 public partial class ShaderField : Internal.PrimitiveFigure
\r
262 public Point v1, v2;
\r
264 public ShaderField()
\r
268 public ShaderField(double wid, double hei)
\r
270 initialized = false;
\r
273 public ShaderField(Rectangle another)
\r
278 public ShaderField set(double wid, double hei)
\r
281 v2.set(wid, hei, 0);
\r
284 ShaderField set(Point po1, Point po2)
\r
290 public ShaderField set(double l, double t, double r, double b)
\r
296 public ShaderField set(ShaderField another)
\r
303 public ShaderField resize(double width, double height)
\r
306 set(width, height);
\r
315 set { double w = width, h = height; v1 = value; v2 = v1 + new Point(w,h); }
\r
317 public ShaderField move_to(Point p) { datum = p; return this; }
\r
318 public ShaderField move_to(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }
\r
319 public ShaderField locate(Point p) { datum = p; return this; }
\r
320 public ShaderField locate(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }
\r
322 public Figure shift(Point p)
\r
328 public Figure centering(Point p)
\r
330 double h = width, v = height;
\r
331 v1.x = p.x - h / 2.0;
\r
332 v1.y = p.y - v / 2.0;
\r
338 public virtual void draw()
\r
340 Main.drawable.shader(this);
\r
343 internal Action setParameters = initialize___;
\r
344 internal Action initialize__ = initialize___;
\r
345 private static void initialize___() {}
\r
346 internal bool initialized = false;
\r
348 public double left { get { return v1.x; } }
\r
349 public double top { get { return v1.y; } }
\r
350 public double right { get { return v2.x; } }
\r
351 public double bottom { get { return v2.y; } }
\r
352 public double width { get { return Math.abs(v1.x - v2.x); } }
\r
353 public double height { get { return Math.abs(v1.y - v2.y); } }
\r
354 public Point center
\r
356 get { return new Point((left + right) / 2, (top + bottom) / 2); }
\r
357 set { centering(value); }
\r
359 public double getLeft() { return left; }
\r
360 public double getTop() { return top; }
\r
361 public double getRight() { return right; }
\r
362 public double getBottom() { return bottom; }
\r
363 public double getWidth() { return width; }
\r
364 public double getHeight() { return height; }
\r
365 public Point getCenter() { return center; }
\r