+++ /dev/null
-using System;\r
-using System.Windows;\r
-\r
-\r
-namespace Psychlops\r
-{\r
- public static class StaticFunctions\r
- {\r
- public static T[] NewArray<T>(int x)\r
- where T : new()\r
- {\r
- T[] t = new T[x];\r
- for (int i = 0; i < x; i++)\r
- {\r
- t[i] = new T();\r
- }\r
- return t;\r
- }\r
- public static T[,] NewArray<T>(int x, int y)\r
- where T : new()\r
- {\r
- T[,] t = new T[x,y];\r
- for (int i = 0; i < x; i++)\r
- {\r
- for (int j = 0; j < x; j++)\r
- {\r
- t[i,j] = new T();\r
- }\r
- }\r
- return t;\r
- }\r
- public static T[,,] NewArray<T>(int x, int y, int z)\r
- where T : new()\r
- {\r
- T[,,] t = new T[x, y, z];\r
- for (int i = 0; i < x; i++)\r
- {\r
- for (int j = 0; j < y; j++)\r
- {\r
- for (int k = 0; k < z; k++)\r
- {\r
- t[i, j, k] = new T();\r
- }\r
- }\r
- }\r
- return t;\r
- }\r
- }\r
-\r
- public partial struct Point\r
- {\r
- public double x, y, z;\r
- public Point(double dx, double dy, double dz = 0.0)\r
- {\r
- x = dx;\r
- y = dy;\r
- z = dz;\r
- }\r
- public Point set(double dx, double dy, double dz = 0.0)\r
- {\r
- x = dx;\r
- y = dy;\r
- z = dz;\r
- return this;\r
- }\r
-\r
- public static Point operator +(Point lhs, Point rhs)\r
- {\r
- return new Point(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);\r
- }\r
- public static Point operator -(Point lhs, Point rhs)\r
- {\r
- return new Point(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);\r
- }\r
- public override string ToString()\r
- {\r
- return "X:"+ x.ToString() + " Y:"+ y.ToString() + " Z:"+ z.ToString();\r
- }\r
- }\r
-\r
-\r
- public partial struct Color\r
- {\r
- public double r, g, b, a;\r
- public Color(double lum)\r
- {\r
- r = g = b = lum;\r
- a = 1.0;\r
- }\r
- public Color(double red, double green, double blue, double alpha = 1.0)\r
- {\r
- r = red;\r
- g = green;\r
- b = blue;\r
- a = alpha;\r
- }\r
- public void set(double lum)\r
- {\r
- r = g = b = lum;\r
- a = 1.0;\r
- }\r
- public void set(double red, double green, double blue, double alpha = 1.0)\r
- {\r
- r = red;\r
- g = green;\r
- b = blue;\r
- a = alpha;\r
- }\r
-\r
- public override string ToString()\r
- {\r
- return "R:" + r.ToString() + " G:" + g.ToString() + " B:" + b.ToString() + " A:" + a.ToString();\r
- }\r
-\r
- public static readonly Color\r
- black = new Color(0, 0, 0, 1),\r
- red = new Color(1, 0, 0, 1),\r
- green = new Color(0, 1, 0, 1),\r
- blue = new Color(0, 0, 1, 1),\r
- yellow = new Color(1, 1, 0, 1),\r
- magenta = new Color(1, 0, 1, 1),\r
- cyan = new Color(0, 1, 1, 1),\r
- gray = new Color(.5, .5, .5, 1),\r
- white = new Color(1, 1, 1, 1),\r
- null_color = new Color(0, 0, 0, 0),\r
- transparent = new Color(0, 0, 0, 0);\r
-\r
- }\r
-\r
-\r
- public interface Drawable\r
- {\r
- Point getCenter();\r
- void clear(Color col);\r
- void pix(int x, int y, Color col);\r
- void line(Line drawee);\r
- void rect(Rectangle drawee);\r
- void ellipse(Ellipse drawee);\r
- void polygon(Polygon drawee);\r
- void letters(Letters drawee);\r
- void image(Image drawee);\r
- void group(Group drawee);\r
- void shader(ShaderField drawee);\r
- void msg(string s, double x, double y, Color c);\r
- }\r
-\r
-\r
-\r
- public interface Figure\r
- {\r
- Point datum { get; set; }\r
- Figure shift(Point p);\r
- Figure centering(Point p);\r
- void draw();\r
- }\r
- public static class FigureExtention\r
- {\r
- public static Point getDatum(this Figure target)\r
- {\r
- return target.datum;\r
- }\r
- public static Point setDatum(this Figure target, Point p)\r
- {\r
- target.datum = p;\r
- return target.datum;\r
- }\r
- public static Figure shift(this Figure target, double x, double y, double z = 0.0)\r
- {\r
- return target.shift(new Point(x, y, z));\r
- }\r
- public static Figure centering(this Figure target)\r
- {\r
- return target.centering(Main.drawable.getCenter());\r
- }\r
- public static Figure centering(this Figure target, double x, double y, double z = 0.0)\r
- {\r
- return target.centering(new Point(x, y, z));\r
- }\r
- }\r
-\r
- namespace Internal\r
- {\r
- public interface PrimitiveFigure : Figure\r
- {\r
- UIElement toNative();\r
- UIElement poolNative(Canvas c);\r
- }\r
- }\r
-\r
- public partial class Group : Internal.PrimitiveFigure\r
- {\r
- System.Collections.Generic.List<Figure> list;\r
- System.Windows.Controls.Canvas cnvs;\r
- System.Windows.Media.TransformGroup trans;\r
- System.Windows.Media.TransformCollection transF;\r
- System.Windows.Media.RotateTransform rotateF;\r
- SimpleProcedure setRotation_;\r
- System.Windows.Media.ScaleTransform scaleF;\r
- SimpleProcedure setScaling_;\r
- System.Windows.Media.TranslateTransform translateF;\r
-\r
- bool AsyncBool;\r
- double rotation_;\r
- public double rotation\r
- {\r
- get { return rotation_; }\r
- set { rotation_ = value; rotateF.Dispatcher.BeginInvoke(setRotation_); }\r
- } \r
- public Point axis\r
- {\r
- get;\r
- set;\r
- }\r
- Point scaling_;\r
- public Point scaling\r
- {\r
- get { return scaling_; }\r
- set { scaling_ = value; scaleF.Dispatcher.BeginInvoke(setScaling_); }\r
- }\r
-\r
- AppendFunc1 append_;\r
-\r
- public Group()\r
- {\r
- setRotation_ = new SimpleProcedure(setRotation__);\r
- setScaling_ = new SimpleProcedure(setScaling__);\r
- append_ = new AppendFunc1(append__);\r
- list = new System.Collections.Generic.List<Figure>();\r
- AsyncBool = false;\r
- initialize__();\r
- while (!AsyncBool) { }\r
- }\r
-\r
- public Group append(Internal.PrimitiveFigure fig)\r
- {\r
- list.Add(fig);\r
- cnvs.Dispatcher.BeginInvoke(append_, fig);\r
- return this;\r
- }\r
-\r
- public Point datum { get; set; }\r
- public Figure shift(Point p)\r
- {\r
- datum = datum + p;\r
- return this;\r
- }\r
- public Figure centering(Point p)\r
- {\r
- datum = p;\r
- return this;\r
- }\r
- public void draw()\r
- {\r
- Main.drawable.group(this);\r
- }\r
- }\r
-\r
-\r
-\r
- public partial class ShaderField : Internal.PrimitiveFigure\r
- {\r
- public Point v1, v2;\r
- \r
- public ShaderField()\r
- {\r
- set(0,0);\r
- }\r
- public ShaderField(double wid, double hei)\r
- {\r
- initialized = false;\r
- set(wid, hei);\r
- }\r
- public ShaderField(Rectangle another)\r
- {\r
- v1 = another.v1;\r
- v2 = another.v2;\r
- }\r
- public ShaderField set(double wid, double hei)\r
- {\r
- v1.set(0, 0, 0);\r
- v2.set(wid, hei, 0);\r
- return this;\r
- }\r
- ShaderField set(Point po1, Point po2)\r
- {\r
- v1 = po1;\r
- v2 = po2;\r
- return this;\r
- }\r
- public ShaderField set(double l, double t, double r, double b)\r
- {\r
- v1.set(l, t, 0);\r
- v2.set(r, b, 0);\r
- return this;\r
- }\r
- public ShaderField set(ShaderField another)\r
- {\r
- v1 = another.v1;\r
- v2 = another.v2;\r
- return this;\r
- }\r
-\r
- public ShaderField resize(double width, double height)\r
- {\r
- Point po = center;\r
- set(width, height);\r
- centering(po);\r
- return this;\r
- }\r
-\r
-\r
- public Point datum\r
- {\r
- get { return v1; }\r
- set { double w = width, h = height; v1 = value; v2 = v1 + new Point(w,h); }\r
- }\r
- public ShaderField move_to(Point p) { datum = p; return this; }\r
- public ShaderField move_to(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }\r
- public ShaderField locate(Point p) { datum = p; return this; }\r
- public ShaderField locate(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }\r
-\r
- public Figure shift(Point p)\r
- {\r
- v1 += p;\r
- v2 += p;\r
- return this;\r
- }\r
- public Figure centering(Point p)\r
- {\r
- double h = width, v = height;\r
- v1.x = p.x - h / 2.0;\r
- v1.y = p.y - v / 2.0;\r
- v2.x = v1.x + h;\r
- v2.y = v1.y + v;\r
- return this;\r
- }\r
-\r
- public virtual void draw()\r
- {\r
- Main.drawable.shader(this);\r
- }\r
-\r
- internal Action setParameters = initialize___;\r
- internal Action initialize__ = initialize___;\r
- private static void initialize___() {}\r
- internal bool initialized = false;\r
-\r
- public double left { get { return v1.x; } }\r
- public double top { get { return v1.y; } }\r
- public double right { get { return v2.x; } }\r
- public double bottom { get { return v2.y; } }\r
- public double width { get { return Math.abs(v1.x - v2.x); } }\r
- public double height { get { return Math.abs(v1.y - v2.y); } }\r
- public Point center\r
- {\r
- get { return new Point((left + right) / 2, (top + bottom) / 2); }\r
- set { centering(value); }\r
- }\r
- public double getLeft() { return left; }\r
- public double getTop() { return top; }\r
- public double getRight() { return right; }\r
- public double getBottom() { return bottom; }\r
- public double getWidth() { return width; }\r
- public double getHeight() { return height; }\r
- public Point getCenter() { return center; }\r
- }\r
-\r
-}
\ No newline at end of file