--- /dev/null
+using System;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Animation;\r
+using System.Windows.Media.Imaging;\r
+using System.Windows.Shapes;\r
+using System.Windows.Browser;\r
+\r
+using System.Collections.Generic;\r
+ \r
+\r
+\r
+namespace Psychlops\r
+{\r
+\r
+ internal static partial class CONST\r
+ {\r
+ internal static readonly Int32 MAX_OBJ_N = 1500;\r
+ internal static readonly Int32 MOBJ_N = 1000;\r
+ internal static readonly Int32 COBJ_N = 300;\r
+ internal static readonly Int32 HOBJ_N = 100;\r
+ }\r
+\r
+ namespace Templates\r
+ {\r
+\r
+ public class StackableDrawable : Drawable\r
+ {\r
+// protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
+ internal Internal.PrimitiveFigure[] stack;\r
+ internal int stackN = 0;\r
+ internal Line[] lineStack;\r
+ internal int lineStackN = 0;\r
+ internal Rectangle[] rectStack;\r
+ internal int rectStackN = 0;\r
+ internal ShaderField[] shaderStack;\r
+ internal int shaderStackN = 0;\r
+ internal Ellipse[] ellipseStack;\r
+ internal int ellipseStackN = 0;\r
+ internal Polygon[] polygonStack;\r
+ internal int polygonStackN = 0;\r
+ internal Letters[] lettersStack;\r
+ internal int lettersStackN = 0;\r
+ internal Image[] imageStack;\r
+ internal int imageStackN = 0;\r
+ internal Group[] groupStack;\r
+ internal int groupStackN = 0;\r
+\r
+ public StackableDrawable()\r
+ {\r
+ stack = new Internal.PrimitiveFigure[CONST.MAX_OBJ_N];\r
+ lineStack = new Line[CONST.MOBJ_N];\r
+ rectStack = new Rectangle[CONST.MOBJ_N];\r
+ ellipseStack = new Ellipse[CONST.MOBJ_N];\r
+ shaderStack = new ShaderField[CONST.COBJ_N];\r
+ polygonStack = new Polygon[CONST.COBJ_N];\r
+ lettersStack = new Letters[CONST.COBJ_N];\r
+ imageStack = new Image[CONST.HOBJ_N];\r
+ groupStack = new Group[CONST.HOBJ_N];\r
+ for (int i = 0; i < CONST.MOBJ_N; i++)\r
+ {\r
+ lineStack[i] = new Line(0,0,0,0);\r
+ rectStack[i] = new Rectangle();\r
+ ellipseStack[i] = new Ellipse();\r
+ }\r
+ for (int i = 0; i < CONST.COBJ_N; i++)\r
+ {\r
+ shaderStack[i] = new ShaderField();\r
+ polygonStack[i] = new Polygon();\r
+ lettersStack[i] = new Letters();\r
+ }\r
+ for (int i = 0; i < CONST.HOBJ_N; i++)\r
+ {\r
+ imageStack[i] = new Image();\r
+// groupStack[i] = new Group();\r
+ }\r
+\r
+\r
+ }\r
+\r
+ public void clear() { clear(Color.black); }\r
+ public virtual void clear(Color col) { } //rect(back_panel, col); }\r
+ public virtual void pix(int x, int y, Color col) { }\r
+ public virtual void line(Line drawee) { drawee.copyToStack(this); }\r
+ public virtual void rect(Rectangle drawee) { drawee.copyToStack(this); }\r
+ public virtual void ellipse(Ellipse drawee) { drawee.copyToStack(this); }\r
+ public virtual void oval(Ellipse drawee) { drawee.copyToStack(this); }\r
+ public virtual void polygon(Polygon drawee) { drawee.copyToStack(this); }\r
+ public virtual void letters(Letters drawee) { drawee.copyToStack(this); }\r
+ public virtual void image(Image drawee) { drawee.copyToStack(this); }\r
+ public virtual void group(Group drawee) { drawee.copyToStack(this); }\r
+ public virtual void shader(ShaderField drawee) { drawee.copyToStack(this); }\r
+\r
+ public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
+ public virtual void msg(string dstr, double x, double y, Color col)\r
+ {\r
+ var let = new Letters(dstr);\r
+ let.locate(x, y);\r
+ let.fill = col;\r
+ this.letters(let);\r
+ }\r
+ public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }\r
+ public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }\r
+\r
+ public virtual Point getCenter() { return new Point(0, 0, 0); }\r
+ }\r
+\r
+ }\r
+\r
+ public class Canvas : Templates.StackableDrawable\r
+ {\r
+ internal System.Windows.Controls.Canvas masterPool, prevPool;\r
+ internal System.Windows.Point[] pointPool;\r
+ internal int pointPoolN;\r
+ internal SolidColorBrush[] brushPool;\r
+ internal int brushPoolN;\r
+\r
+ internal System.Windows.Controls.Canvas[] UIElementPool;\r
+ internal int UIElementPoolN;\r
+ internal int lastVisibleN;\r
+\r
+ internal System.Windows.Shapes.Line[] linePool;\r
+ internal int linePoolN;\r
+ internal System.Windows.Shapes.Rectangle[] dummyRectPool;\r
+ internal System.Windows.Shapes.Rectangle[] rectPool;\r
+ internal int rectPoolN;\r
+ internal System.Windows.Shapes.Rectangle[] shaderPool;\r
+ internal int shaderPoolN;\r
+ internal System.Windows.Shapes.Ellipse[] ellipsePool;\r
+ internal int ellipsePoolN;\r
+ internal System.Windows.Shapes.Polygon[] polygonPool;\r
+ internal int polygonPoolN;\r
+ internal System.Windows.Controls.TextBlock[] lettersPool;\r
+ internal int lettersPoolN;\r
+ internal System.Windows.Controls.Image[] imagePool;\r
+ internal int imagePoolN;\r
+ internal Dictionary<int, bool> imagePoolT;\r
+ internal System.Windows.Controls.Canvas[] groupPool;\r
+ internal int groupPoolN;\r
+\r
+ #region initializer\r
+\r
+ Action flipexec;\r
+ public static IList<Action> initialize_at_canvas_initialize__ = new List<Action>();\r
+\r
+ public static System.Windows.Controls.UserControl default_panel;\r
+ public static System.Windows.Controls.Canvas default_api_canvas;\r
+ public static WriteableBitmap default_buffer;\r
+ internal System.Windows.Controls.Canvas api_canvas;\r
+ internal System.Windows.Controls.UserControl panel;\r
+ Rectangle back_panel;\r
+ double width_, height_;\r
+ Clock before;\r
+\r
+ public Canvas(int wid, int hei)\r
+ {\r
+ panel = default_panel;\r
+ api_canvas = default_api_canvas;\r
+ initialize(wid, hei);\r
+ }\r
+ public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs, System.Windows.Controls.UserControl system)\r
+ {\r
+ panel = system;\r
+ api_canvas = apicnvs;\r
+ initialize(wid, hei);\r
+ }\r
+\r
+ protected bool AsyncInitBool;\r
+ internal void beginInvoke(Action a) { api_canvas.Dispatcher.BeginInvoke(a); }\r
+ protected void initialize(int wid, int hei)\r
+ {\r
+ before = new Clock();\r
+ before.update();\r
+ var after = new Clock();\r
+ AsyncInitBool = false;\r
+ width_ = wid;\r
+ height_ = hei;\r
+ api_canvas.Dispatcher.BeginInvoke(new Action<int,int>(initialize__), wid, hei);\r
+ while (!AsyncInitBool)\r
+ {\r
+ after.update();\r
+ if ((after - before).at_msec() > 1000) break;\r
+ }\r
+ Mouse._prime = api_canvas;\r
+ Main.drawable = this;\r
+ Main.canvas = this;\r
+\r
+ back_panel = new Rectangle(wid, hei);\r
+\r
+ flipexec = new Action(executeFlip);\r
+ }\r
+ protected void initialize__(int wid, int hei)\r
+ {\r
+ api_canvas.Width = wid;\r
+ api_canvas.Height = hei+20;\r
+ api_canvas.MouseMove += Mouse.Canvas_MousePos;\r
+ api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
+ api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;\r
+ api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;\r
+ panel.KeyDown += Keyboard.Canvas_KeyDown;\r
+ panel.KeyUp += Keyboard.Canvas_KeyUp;\r
+\r
+ HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");\r
+ //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");\r
+ htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");\r
+ htmlHost.SetStyleAttribute("height", (hei).ToString() + "px");\r
+ htmlHost.SetStyleAttribute("margin", "2em auto auto auto");\r
+\r
+ pointPool = new System.Windows.Point[CONST.MOBJ_N];\r
+ brushPool = new SolidColorBrush[CONST.MOBJ_N];\r
+ linePool = new System.Windows.Shapes.Line[CONST.MOBJ_N];\r
+ rectPool = new System.Windows.Shapes.Rectangle[CONST.MOBJ_N];\r
+ ellipsePool = new System.Windows.Shapes.Ellipse[CONST.MOBJ_N];\r
+ for (int i = 0; i < CONST.MOBJ_N; i++)\r
+ {\r
+ pointPool[i] = new System.Windows.Point();\r
+ brushPool[i] = new SolidColorBrush();\r
+ linePool[i] = new System.Windows.Shapes.Line();\r
+ rectPool[i] = new System.Windows.Shapes.Rectangle();\r
+ ellipsePool[i] = new System.Windows.Shapes.Ellipse();\r
+ }\r
+ shaderPool = new System.Windows.Shapes.Rectangle[CONST.COBJ_N];\r
+ polygonPool = new System.Windows.Shapes.Polygon[CONST.COBJ_N];\r
+ lettersPool = new System.Windows.Controls.TextBlock[CONST.COBJ_N];\r
+ for (int i = 0; i < CONST.COBJ_N; i++)\r
+ {\r
+ shaderPool[i] = new System.Windows.Shapes.Rectangle();\r
+ polygonPool[i] = new System.Windows.Shapes.Polygon();\r
+ lettersPool[i] = new System.Windows.Controls.TextBlock();\r
+ }\r
+ imagePool = new System.Windows.Controls.Image[CONST.HOBJ_N];\r
+ imagePoolT = new Dictionary<int, bool>(CONST.HOBJ_N);\r
+ groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N];\r
+ for (int i = 0; i < CONST.HOBJ_N; i++)\r
+ {\r
+ imagePool[i] = new System.Windows.Controls.Image();\r
+ imagePoolT.Add(imagePool[i].GetHashCode(), false);\r
+ groupPool[i] = new System.Windows.Controls.Canvas();\r
+ }\r
+\r
+ masterPool = new System.Windows.Controls.Canvas();\r
+ prevPool = new System.Windows.Controls.Canvas();\r
+ api_canvas.Children.Add(masterPool);\r
+\r
+ //api_canvas.Children.Remove(Internal.Main.widgetStack);\r
+ Psychlops.Internal.Main.widgetStack = new StackPanel();\r
+ Psychlops.Internal.Main.widgetStack.Orientation = Orientation.Vertical;\r
+ Psychlops.Internal.Main.widgetStack.Height = hei;\r
+ api_canvas.Children.Add(Psychlops.Internal.Main.widgetStack);\r
+ Internal.Main.statusBar.Visibility = Visibility.Collapsed;\r
+\r
+\r
+ UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N];\r
+ dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N];\r
+ for (int i = 0; i < CONST.MAX_OBJ_N; i++)\r
+ {\r
+ UIElementPool[i] = new System.Windows.Controls.Canvas();\r
+ masterPool.Children.Add(UIElementPool[i]);\r
+ dummyRectPool[i] = new System.Windows.Shapes.Rectangle();\r
+ UIElementPool[i].Children.Add(dummyRectPool[i]);\r
+ dummyRectPool[i].Visibility = Visibility.Collapsed;\r
+ }\r
+\r
+ AsyncInitBool = true;\r
+\r
+ // initialize at Canvas initializing\r
+ //Figures.ShaderGabor.initialize__();\r
+ }\r
+\r
+ internal int findEmptyInPool(Dictionary<int, bool> pool)\r
+ {\r
+ /*\r
+ foreach( KeyValuePair<int, bool> elem in pool)\r
+ {\r
+ if(elem) \r
+ }*/\r
+ return 0;\r
+ }\r
+\r
+ #endregion\r
+\r
+ #region static initializer\r
+ /*\r
+ static Canvas()\r
+ {\r
+ }\r
+ */\r
+ #endregion\r
+\r
+\r
+ public override void clear(Color col)\r
+ {\r
+ back_panel.fill = col;\r
+ stackN = 0;\r
+ rect(back_panel);\r
+ }\r
+\r
+ int nextIntervalFrame = 1, chacked = 0;\r
+ public void flip(int n)\r
+ {\r
+ lock (this)\r
+ {\r
+ nextIntervalFrame = n;\r
+ chacked = 1;\r
+ }\r
+ //pointStackN = 0;\r
+ lineStackN = 0;\r
+ rectStackN = 0;\r
+ shaderStackN = 0;\r
+ polygonStackN = 0;\r
+ ellipseStackN = 0;\r
+ lettersStackN = 0;\r
+ imageStackN = 0;\r
+ groupStackN = 0;\r
+\r
+ UIElementPoolN = 0;\r
+ brushPoolN = 0;\r
+ /*\r
+ pointPoolN = 0;\r
+ brushPoolN = 0;\r
+ linePoolN = 0;\r
+ rectPoolN = 0;\r
+ ellipsePoolN = 0;\r
+ polygonPoolN = 0;\r
+ lettersPoolN = 0;\r
+ imagePoolN = 0;\r
+ groupPoolN = 0;\r
+ * */\r
+\r
+ //executeFlip();\r
+ Internal.Main.canvas_flag.WaitOne();\r
+ }\r
+ public void flip()\r
+ {\r
+ flip(1);\r
+ }\r
+\r
+\r
+ #region version modifyNative2\r
+ public void executeFlip()\r
+ {\r
+// Clock after = new Clock();\r
+// after.update();\r
+// AppState.statusBar = ((after - before).at_msec().ToString()) + " msec";\r
+\r
+ Line lineS;\r
+ ShaderField shaderS;\r
+ Rectangle rectS;\r
+ Ellipse ellipseS;\r
+ Polygon polygonS;\r
+ Letters lettersS;\r
+ Image imageS;\r
+ Group groupS;\r
+ System.Windows.Shapes.Line lineP;\r
+ System.Windows.Shapes.Rectangle rectP;\r
+ System.Windows.Shapes.Rectangle shaderP;\r
+ System.Windows.Shapes.Ellipse ellipseP;\r
+ System.Windows.Shapes.Polygon polygonP;\r
+ System.Windows.Controls.TextBlock lettersP;\r
+ System.Windows.Controls.Image imageP;\r
+ System.Windows.Controls.Canvas groupP;\r
+\r
+ lock (this)\r
+ {\r
+ nextIntervalFrame--;\r
+ }\r
+\r
+ var cnv = UIElementPool[0];\r
+ if (nextIntervalFrame <= 0)\r
+ {\r
+ if (chacked > 0)\r
+ {\r
+ if (stackN > 0)\r
+ {\r
+ for (int i = 0; i < stackN; i++)\r
+ {\r
+ if (null != (shaderS = stack[i] as ShaderField))\r
+ {\r
+ if (null != (shaderP = cnv.Children[0] as System.Windows.Shapes.Rectangle))\r
+ {\r
+ shaderS.modifyNative(shaderP, this);\r
+ }\r
+ else\r
+ {\r
+ cnv.Children.Clear();\r
+ cnv.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ }\r
+ else if( null != (rectS = stack[i] as Rectangle) )\r
+ {\r
+ if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle))\r
+ {\r
+ rectS.modifyNative(rectP, this);\r
+ }\r
+ else\r
+ {\r
+ cnv.Children.Clear();\r
+ cnv.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ }\r
+ else if (null != (lineS = stack[i] as Line))\r
+ {\r
+ if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line))\r
+ {\r
+ lineS.modifyNative(lineP, this);\r
+ }\r
+ else\r
+ {\r
+ cnv.Children.Clear();\r
+ cnv.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ }\r
+ else if (null != (ellipseS = stack[i] as Ellipse))\r
+ {\r
+ if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse))\r
+ {\r
+ ellipseS.modifyNative(ellipseP, this);\r
+ }\r
+ else\r
+ {\r
+ cnv.Children.Clear();\r
+ cnv.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ }\r
+ else if (null != (polygonS = stack[i] as Polygon))\r
+ {\r
+ if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon))\r
+ {\r
+ polygonS.modifyNative(polygonP, this);\r
+ }\r
+ else\r
+ {\r
+ cnv.Children.Clear();\r
+ cnv.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ }\r
+ else if (null != (lettersS = stack[i] as Letters))\r
+ {\r
+ if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock))\r
+ {\r
+ lettersS.modifyNative(lettersP, this);\r
+ }\r
+ else\r
+ {\r
+ cnv.Children.Clear();\r
+ cnv.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ }\r
+ else if (null != (imageS = stack[i] as Image))\r
+ {\r
+ if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image))\r
+ {\r
+ imageS.modifyNative(imageP, this);\r
+ }\r
+ else\r
+ {\r
+ cnv.Children.Clear();\r
+ cnv.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ }\r
+ else if (null != (groupS = stack[i] as Group))\r
+ {\r
+ if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas))\r
+ {\r
+ groupS.modifyNative(groupP, this);\r
+ }\r
+ else\r
+ {\r
+ cnv.Children.Clear();\r
+ cnv.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ }\r
+ cnv.Visibility = Visibility.Visible;\r
+ UIElementPoolN++;\r
+ cnv = UIElementPool[UIElementPoolN];\r
+ }\r
+ for (int i = UIElementPoolN; i < lastVisibleN; i++)\r
+ {\r
+ cnv = UIElementPool[i];\r
+ cnv.Visibility = Visibility.Collapsed;\r
+ }\r
+ lastVisibleN = UIElementPoolN;\r
+ stackN = 0;\r
+ }\r
+ lock (this)\r
+ {\r
+ chacked = 0;\r
+ }\r
+ Psychlops.Internal.Main.canvas_flag.Set();\r
+ }\r
+ }\r
+ System.Threading.Thread.Sleep(0);\r
+ }\r
+ #endregion\r
+\r
+\r
+\r
+ #region version modifyNative\r
+ /*\r
+ public void executeFlip()\r
+ {\r
+ Line lineS;\r
+ Rectangle rectS;\r
+ Ellipse ellipseS;\r
+ Polygon polygonS;\r
+ Letters lettersS;\r
+ Image imageS;\r
+ Group groupS;\r
+ System.Windows.Shapes.Line lineP;\r
+ System.Windows.Shapes.Rectangle rectP;\r
+ System.Windows.Shapes.Ellipse ellipseP;\r
+ System.Windows.Shapes.Polygon polygonP;\r
+ System.Windows.Controls.TextBlock lettersP;\r
+ System.Windows.Controls.Image imageP;\r
+ System.Windows.Controls.Canvas groupP;\r
+\r
+ lock (this)\r
+ {\r
+ nextIntervalFrame--;\r
+ }\r
+\r
+ var en = masterPool.Children.GetEnumerator();\r
+ bool full = en.MoveNext();\r
+ if (nextIntervalFrame <= 0)\r
+ {\r
+ if (chacked > 0)\r
+ {\r
+ //masterPool.Children.Clear();\r
+ if (stackN > 0)\r
+ {\r
+ for (int i = 0; i < stackN - 2; i++)\r
+ {\r
+ if (full == false)\r
+ {\r
+ masterPool.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ else\r
+ {\r
+ if( null != (rectS = stack[i] as Rectangle) )\r
+ {\r
+ if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle))\r
+ {\r
+ rectS.modifyNative(rectP, this);\r
+ }\r
+ }\r
+ else if (null != (lineS = stack[i] as Line))\r
+ {\r
+ if (null != (lineP = en.Current as System.Windows.Shapes.Line))\r
+ {\r
+ lineS.modifyNative(lineP, this);\r
+ }\r
+ }\r
+ else if (null != (ellipseS = stack[i] as Ellipse))\r
+ {\r
+ if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse))\r
+ {\r
+ ellipseS.modifyNative(ellipseP, this);\r
+ }\r
+ else\r
+ {\r
+ masterPool.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ }\r
+ else if (null != (polygonS = stack[i] as Polygon))\r
+ {\r
+ if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon))\r
+ {\r
+ polygonS.modifyNative(polygonP, this);\r
+ }\r
+ }\r
+ else if (null != (lettersS = stack[i] as Letters))\r
+ {\r
+ if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock))\r
+ {\r
+ lettersS.modifyNative(lettersP, this);\r
+ }\r
+ }\r
+ else if (null != (imageS = stack[i] as Image))\r
+ {\r
+ if (null != (imageP = en.Current as System.Windows.Controls.Image))\r
+ {\r
+ imageS.modifyNative(imageP, this);\r
+ }\r
+ }\r
+ else if (null != (groupS = stack[i] as Group))\r
+ {\r
+ if (null != (groupP = en.Current as System.Windows.Controls.Canvas))\r
+ {\r
+ groupS.modifyNative(groupP, this);\r
+ }\r
+ }\r
+ full = en.MoveNext();\r
+ }\r
+ }\r
+ stackN = 0;\r
+ }\r
+ lock (this)\r
+ {\r
+ chacked = 0;\r
+ }\r
+ Psychlops.Internal.Main.canvas_flag.Set();\r
+ }\r
+ }\r
+ System.Threading.Thread.Sleep(0);\r
+ }\r
+ * */\r
+ #endregion\r
+\r
+ #region version poolNative 2\r
+ /*\r
+ public void executeFlip()\r
+ {\r
+\r
+ lock (this)\r
+ {\r
+ nextIntervalFrame--;\r
+ }\r
+ UIElementPoolN = 0;\r
+ if (nextIntervalFrame <= 0)\r
+ {\r
+ if (chacked > 0)\r
+ {\r
+ //masterPool.Children.Clear();\r
+ if (stackN > 0)\r
+ {\r
+ for (int i = 0; i < stackN - 2; i++)\r
+ {\r
+ UIElementPool[UIElementPoolN] = stack[i].poolNative(this);\r
+ UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;\r
+ UIElementPoolN++;\r
+\r
+ }\r
+ for (int i = stackN - 2; i < 10000; i++)\r
+ {\r
+ UIElementPool[UIElementPoolN] = rectPool[i];\r
+ UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed;\r
+ UIElementPoolN++;\r
+ }\r
+ stackN = 0;\r
+ }\r
+ lock (this)\r
+ {\r
+ chacked = 0;\r
+ }\r
+ Psychlops.Internal.Main.canvas_flag.Set();\r
+ }\r
+ }\r
+ System.Threading.Thread.Sleep(0);\r
+ }\r
+ */\r
+ #endregion\r
+\r
+\r
+ #region Properties\r
+\r
+ public double width { get { return width_; } }\r
+ public double height { get { return height_; } }\r
+ public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }\r
+ public double getWidth() { return width; }\r
+ public double getHeight() { return height; }\r
+ public override Point getCenter() { return center; }\r
+ public double getHCenter() { return width / 2; }\r
+ public double getVCenter() { return height / 2; }\r
+ public double getRefreshRate() { return 60; }\r
+\r
+ #endregion\r
+\r
+\r
+ #region compatibitily trick\r
+\r
+ public enum Mode { window, fullscreen }\r
+ public static readonly Mode window = Mode.window, fullscreen = Mode.fullscreen;\r
+\r
+ public Canvas(int wid, int hei, Mode mod)\r
+ {\r
+ panel = default_panel;\r
+ api_canvas = default_api_canvas;\r
+ initialize(500, 500);\r
+ }\r
+ public Canvas(Mode mod)\r
+ : base()\r
+ {\r
+ panel = default_panel;\r
+ api_canvas = default_api_canvas;\r
+ initialize(500, 500);\r
+ }\r
+\r
+ public Canvas(int wid, int hei, Mode mod, Display.DisplayName name)\r
+ {\r
+ panel = default_panel;\r
+ api_canvas = default_api_canvas;\r
+ initialize(500, 500);\r
+ }\r
+ public Canvas(Mode mod, Display.DisplayName name)\r
+ : base()\r
+ {\r
+ panel = default_panel;\r
+ api_canvas = default_api_canvas;\r
+ initialize(500, 500);\r
+ }\r
+\r
+\r
+ public void showFPS(bool sw = true) { }\r
+ public void watchFPS(bool sw = true) { }\r
+\r
+\r
+ public void clear(double lum)\r
+ {\r
+ clear(new Color(lum));\r
+ }\r
+\r
+ #endregion\r
+\r
+\r
+ }\r
+\r
+\r
+\r
+ #region primitive tokenizer\r
+\r
+\r
+ #region primitive\r
+\r
+ partial struct Point\r
+ {\r
+ public static implicit operator System.Windows.Point(Point d)\r
+ {\r
+ return new System.Windows.Point(d.x, d.y);\r
+ }\r
+\r
+\r
+ public Point datum { get { return this; } set { this = value; } }\r
+ public Point shift(Point p) { this = this + p; return this; }\r
+ public Point centering(Point p) { this = p; return this; }\r
+ public Point getDatum() { return this; }\r
+ public Point setDatum(Point p) { this = p; return p; }\r
+ public Point shift(double x, double y, double z = 0.0) { return shift(new Point(x, y, z)); }\r
+ public Point centering() { return centering(Main.drawable.getCenter()); }\r
+ public Point centering(double x, double y, double z = 0.0) { return centering(new Point(x, y, z)); }\r
+ }\r
+\r
+ partial struct Color\r
+ {\r
+ public static implicit operator System.Windows.Media.Color(Color d)\r
+ {\r
+ return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));\r
+ }\r
+ public static implicit operator System.Windows.Media.SolidColorBrush(Color d)\r
+ {\r
+ return new SolidColorBrush { Color = d };\r
+ }\r
+ public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)\r
+ {\r
+ var tmp = d.brushPool[d.brushPoolN];\r
+ tmp.Color = this;\r
+ d.brushPoolN++;\r
+ return tmp;\r
+ }\r
+\r
+ }\r
+\r
+ partial struct Stroke\r
+ {\r
+ public void apply(System.Windows.Shapes.Shape target)\r
+ {\r
+ target.Stroke = this;\r
+ //target.StrokeDashArray\r
+ target.StrokeThickness = thick;\r
+ }\r
+ public static implicit operator SolidColorBrush(Stroke d)\r
+ {\r
+ return new SolidColorBrush { Color = d.color };\r
+ }\r
+ public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)\r
+ {\r
+ var tmp = d.brushPool[d.brushPoolN];\r
+ tmp.Color = this.color;\r
+ d.brushPoolN++;\r
+ return tmp;\r
+ }\r
+ }\r
+ \r
+ #endregion\r
+ \r
+ #region Line\r
+\r
+ partial class Line\r
+ {\r
+ public Line dup()\r
+ {\r
+ return (Line)MemberwiseClone();\r
+ }\r
+ public Line clone()\r
+ {\r
+ return (Line)MemberwiseClone();\r
+ }\r
+ public static implicit operator System.Windows.Shapes.Line(Line d)\r
+ {\r
+ var tmp = new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };\r
+ if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;\r
+ else d.stroke.apply(tmp);\r
+ return tmp;\r
+ }\r
+ public UIElement toNative() { return this; }\r
+\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.lineStack[d.lineStackN];\r
+ tmp.begin.x = begin.x;\r
+ tmp.begin.y = begin.y;\r
+ tmp.end.x = end.x;\r
+ tmp.end.y = end.y;\r
+ tmp.fill = fill;\r
+ tmp.stroke = stroke;\r
+ d.stack[d.stackN] = tmp;\r
+ d.lineStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.linePool[d.linePoolN];\r
+ tmp.X1 = begin.x;\r
+ tmp.Y1 = begin.y;\r
+ tmp.X2 = end.x;\r
+ tmp.Y2 = end.y;\r
+ if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);\r
+ else stroke.apply(tmp);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.linePoolN++;\r
+ return tmp;\r
+ }\r
+ public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d)\r
+ {\r
+ tmp.X1 = begin.x;\r
+ tmp.Y1 = begin.y;\r
+ tmp.X2 = end.x;\r
+ tmp.Y2 = end.y;\r
+ if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);\r
+ else stroke.apply(tmp);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ }\r
+ }\r
+ \r
+ #endregion\r
+ \r
+ #region Rectangle\r
+\r
+ partial class Rectangle\r
+ {\r
+ public Rectangle dup()\r
+ {\r
+ return (Rectangle)MemberwiseClone();\r
+ }\r
+ public Rectangle clone()\r
+ {\r
+ return (Rectangle)MemberwiseClone();\r
+ }\r
+ public static implicit operator System.Windows.Rect(Rectangle d)\r
+ {\r
+ return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);\r
+ }\r
+ public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)\r
+ {\r
+ var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };\r
+ d.stroke.apply(tmp);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, d.left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
+ return tmp;\r
+ }\r
+\r
+ public UIElement toNative() { return this; }\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.rectStack[d.rectStackN];\r
+ tmp.v1 = v1;\r
+ tmp.v2 = v2;\r
+ tmp.fill = fill;\r
+ d.stack[d.stackN] = tmp;\r
+ d.rectStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.rectPool[d.rectPoolN];\r
+ tmp.Width = width;\r
+ tmp.Height = height;\r
+ tmp.Fill = fill.getNativeFromStack(d);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.rectPoolN++;\r
+ return tmp;\r
+ }\r
+ public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)\r
+ {\r
+ tmp.Width = width;\r
+ tmp.Height = height;\r
+ tmp.Fill = fill.getNativeFromStack(d);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ }\r
+ }\r
+ \r
+ #endregion\r
+ \r
+ #region ShaderField\r
+\r
+ partial class ShaderField\r
+ {\r
+ public System.Windows.Media.Effects.Effect shader;\r
+ protected static System.Windows.Media.SolidColorBrush dummyfill = null;\r
+\r
+ protected static void initializeShader()\r
+ {\r
+ dummyfill = new SolidColorBrush(System.Windows.Media.Colors.Blue);\r
+ }\r
+\r
+ public UIElement toNative() { return null; }\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.shaderStack[d.shaderStackN];\r
+ tmp.initialize__ = initialize__;\r
+ tmp.setParameters = setParameters;\r
+ tmp.v1 = v1;\r
+ tmp.v2 = v2;\r
+ tmp.shader = shader;\r
+ d.stack[d.stackN] = tmp;\r
+ d.shaderStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.shaderPool[d.shaderPoolN];\r
+ tmp.Width = width;\r
+ tmp.Height = height;\r
+ if (!initialized) { initialize__(); }\r
+ setParameters();\r
+ tmp.Effect = shader;\r
+ tmp.Fill = dummyfill;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.shaderPoolN++;\r
+ return tmp;\r
+ }\r
+ public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)\r
+ {\r
+ tmp.Width = width;\r
+ tmp.Height = height;\r
+ if (!initialized) { initialize__(); }\r
+ setParameters();\r
+ tmp.Effect = shader;\r
+ tmp.Fill = dummyfill;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ }\r
+ }\r
+\r
+ #endregion\r
+\r
+ #region Ellipse\r
+\r
+ partial class Ellipse\r
+ {\r
+ public Ellipse dup()\r
+ {\r
+ return (Ellipse)MemberwiseClone();\r
+ }\r
+ public Ellipse clone()\r
+ {\r
+ return (Ellipse)MemberwiseClone();\r
+ }\r
+ public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)\r
+ {\r
+ var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };\r
+ d.stroke.apply(tmp);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, d.left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
+ return tmp;\r
+ }\r
+\r
+ public UIElement toNative() { return this; }\r
+\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.ellipseStack[d.ellipseStackN];\r
+ tmp.datum = datum;\r
+ tmp.xdiameter = xdiameter;\r
+ tmp.ydiameter = ydiameter;\r
+ tmp.fill = fill;\r
+ d.stack[d.stackN] = tmp;\r
+ d.ellipseStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.ellipsePool[d.ellipsePoolN];\r
+ tmp.Width = width;\r
+ tmp.Height = height;\r
+ tmp.Fill = fill.getNativeFromStack(d);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.ellipsePoolN++;\r
+ return tmp;\r
+ }\r
+ public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d)\r
+ {\r
+ tmp.Width = width;\r
+ tmp.Height = height;\r
+ tmp.Fill = fill.getNativeFromStack(d);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ }\r
+ }\r
+\r
+ #endregion\r
+\r
+ #region Polygon\r
+\r
+ partial class Polygon\r
+ {\r
+ public Polygon dup()\r
+ {\r
+ return (Polygon)MemberwiseClone();\r
+ }\r
+ public Polygon clone()\r
+ {\r
+ return (Polygon)MemberwiseClone();\r
+ }\r
+ public static implicit operator System.Windows.Shapes.Polygon(Polygon d)\r
+ {\r
+ var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };\r
+ d.stroke.apply(tmp);\r
+ foreach (Point p in d.vertices)\r
+ {\r
+ tmp.Points.Add(p);\r
+ }\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);\r
+ return tmp;\r
+ }\r
+ public UIElement toNative() { return this; }\r
+\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.polygonStack[d.polygonStackN];\r
+ tmp.datum = datum;\r
+ tmp.vertices.Clear();\r
+ foreach (var v in vertices)\r
+ {\r
+ tmp.vertices.Add(v);\r
+ }\r
+ tmp.fill = fill;\r
+ d.stack[d.stackN] = tmp;\r
+ d.polygonStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.polygonPool[d.polygonPoolN];\r
+ tmp.Fill = fill.getNativeFromStack(d);\r
+ tmp.Points.Clear();\r
+ foreach (var v in vertices)\r
+ {\r
+ tmp.Points.Add(v);\r
+ }\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.polygonPoolN++;\r
+ return tmp;\r
+ }\r
+ public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)\r
+ {\r
+ tmp.Fill = fill.getNativeFromStack(d);\r
+ tmp.Points.Clear();\r
+ foreach (var v in vertices)\r
+ {\r
+ tmp.Points.Add(v);\r
+ }\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+ tmp.Visibility = Visibility.Visible;\r
+ }\r
+\r
+ }\r
+ \r
+ #endregion\r
+\r
+ #region Letters\r
+\r
+ partial class Letters\r
+ {\r
+ #region static initializer\r
+ internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;\r
+ internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;\r
+ internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;\r
+ static Letters()\r
+ {\r
+ FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();\r
+ FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);\r
+ FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);\r
+ FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();\r
+ FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);\r
+ FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);\r
+ FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);\r
+ LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();\r
+ LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);\r
+ LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);\r
+ LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);\r
+ LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);\r
+ }\r
+ #endregion\r
+ public Letters dup()\r
+ {\r
+ return (Letters)MemberwiseClone();\r
+ }\r
+ public Letters clone()\r
+ {\r
+ return (Letters)MemberwiseClone();\r
+ }\r
+ public static implicit operator System.Windows.Controls.TextBlock(Letters d)\r
+ {\r
+ //var zapi_shape = new System.Windows.Documents.Glyphs();\r
+ var tmp = new System.Windows.Controls.TextBlock {\r
+ Text = d.str, Width = 500, Height = 500,\r
+ FontSize = d.font.size,\r
+ //tmp.FontFamily = ,\r
+ FontStyle = FONT_STYLE_BRIDGE[d.font.style],\r
+ FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],\r
+ TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],\r
+ Foreground = d.fill\r
+ };\r
+ double left = 0;\r
+ switch (d.align)\r
+ {\r
+ case Letters.HorizontalAlign.left: break;\r
+ case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;\r
+ case Letters.HorizontalAlign.right: left = tmp.Width; break;\r
+ }\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);\r
+ return tmp;\r
+ }\r
+ public UIElement toNative() { return this; }\r
+\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.lettersStack[d.lettersStackN];\r
+ tmp.str = str;\r
+ tmp.datum = datum;\r
+ tmp.fill = fill;\r
+ d.stack[d.stackN] = tmp;\r
+ d.lettersStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.lettersPool[d.lettersPoolN];\r
+ tmp.Text = str;\r
+ tmp.Width = 500;\r
+ tmp.Height = 500;\r
+ tmp.FontSize = font.size;\r
+ //tmp.FontFamily = ,\r
+ tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];\r
+ tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];\r
+ tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];\r
+ tmp.Foreground = fill.getNativeFromStack(d);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.lettersPoolN++;\r
+ return tmp;\r
+ }\r
+ public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d)\r
+ {\r
+ tmp.Text = str;\r
+ tmp.Width = 500;\r
+ tmp.Height = 500;\r
+ tmp.FontSize = font.size;\r
+ //tmp.FontFamily = ,\r
+ tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];\r
+ tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];\r
+ tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];\r
+ tmp.Foreground = fill.getNativeFromStack(d);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+ tmp.Visibility = Visibility.Visible;\r
+ }\r
+ }\r
+ \r
+ #endregion\r
+ \r
+ #region Image\r
+\r
+ partial class Image\r
+ {\r
+ internal void initialize__(int wid, int hei)\r
+ {\r
+ AsyncBool = false;\r
+ Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action<int,int>(create__), wid, hei);\r
+ while (!AsyncBool) { System.Threading.Thread.Sleep(10); }\r
+ }\r
+ internal void create__(int wid, int hei)\r
+ {\r
+ buffer = new WriteableBitmap(wid, hei);\r
+ AsyncBool = true;\r
+ }\r
+ internal void load__(string uri)\r
+ {\r
+ AsyncBool = false;\r
+ var ur = new System.Uri(uri, System.UriKind.RelativeOrAbsolute);\r
+ Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action<Uri>(load_), ur);\r
+ while (!AsyncBool) { System.Threading.Thread.Sleep(10); }\r
+ }\r
+ internal void load_(Uri uri)\r
+ {\r
+ var bitmap = new BitmapImage();\r
+ bitmap.CreateOptions = BitmapCreateOptions.None;\r
+ bitmap.UriSource = uri;\r
+ //try\r
+ //{\r
+ var wbm = new System.Windows.Media.Imaging.WriteableBitmap(bitmap);\r
+ buffer = wbm;\r
+ //}\r
+ //catch (Exception e)\r
+ //{\r
+ // buffer = new WriteableBitmap(64, 64);\r
+ // buffer.ForEach(bitmap_drawChecker);\r
+ //}\r
+ self_rect.set(buffer.PixelWidth, buffer.PixelHeight);\r
+ AsyncBool = true;\r
+ }\r
+ static System.Windows.Media.Color[] CHECKER_C;\r
+ static Image()\r
+ {\r
+ CHECKER_C = new System.Windows.Media.Color[2];\r
+ CHECKER_C[0] = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);\r
+ CHECKER_C[1] = System.Windows.Media.Color.FromArgb(128,128,128,128);\r
+ }\r
+ static System.Windows.Media.Color bitmap_drawChecker(int x, int y)\r
+ {\r
+ return ((x / 4) + (y / 4)) % 2 == 0 ? CHECKER_C[0] : CHECKER_C[1];\r
+ }\r
+ delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);\r
+ delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);\r
+ public void field__(System.Func<int, int, System.Windows.Media.Color> func)\r
+ {\r
+ Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);\r
+ //buffer.ForEach(func);\r
+ }\r
+ public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
+ {\r
+ Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);\r
+ //buffer.ForEach(func);\r
+ }\r
+ public void field___(System.Func<int, int, System.Windows.Media.Color> func)\r
+ {\r
+ buffer.ForEach(func);\r
+ }\r
+ public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
+ {\r
+ buffer.ForEach(func);\r
+ }\r
+\r
+ public Image clone()\r
+ {\r
+ return (Image)MemberwiseClone();\r
+ }\r
+ public static implicit operator System.Windows.Controls.Image(Image d)\r
+ {\r
+ var tmp = new System.Windows.Controls.Image();\r
+ tmp.Source = d.buffer;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);\r
+ return tmp;\r
+ }\r
+ public UIElement toNative() { return this; }\r
+\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.imageStack[d.imageStackN];\r
+ tmp.datum = datum;\r
+ tmp.buffer = buffer;\r
+ tmp.self_rect = self_rect;\r
+ d.stack[d.stackN] = tmp;\r
+ d.imageStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.imagePool[d.imagePoolN];\r
+ tmp.Source = buffer;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.imagePoolN++;\r
+ return tmp;\r
+ }\r
+ public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)\r
+ {\r
+ tmp.Source = buffer;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+ tmp.Visibility = Visibility.Visible;\r
+ }\r
+\r
+ }\r
+\r
+ #endregion\r
+\r
+ #region Group\r
+\r
+ partial class Group\r
+ {\r
+ internal void initialize__()\r
+ {\r
+ Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action(create__));\r
+ }\r
+ internal void create__()\r
+ {\r
+ cnvs = new System.Windows.Controls.Canvas();\r
+ trans = new System.Windows.Media.TransformGroup();\r
+ transF = new System.Windows.Media.TransformCollection();\r
+ rotateF = new System.Windows.Media.RotateTransform();\r
+ scaleF = new System.Windows.Media.ScaleTransform();\r
+ translateF = new System.Windows.Media.TranslateTransform();\r
+ transF.Add(rotateF);\r
+ transF.Add(scaleF);\r
+ transF.Add(translateF);\r
+ trans.Children = transF;\r
+ cnvs.RenderTransform = trans;\r
+ AsyncBool = true;\r
+ }\r
+ public Group clone()\r
+ {\r
+ return (Group)MemberwiseClone();\r
+ }\r
+\r
+ delegate void AppendFunc1(Internal.PrimitiveFigure func);\r
+ void append__(Internal.PrimitiveFigure fig)\r
+ {\r
+ fig.centering(0, 0);\r
+ UIElement e = fig.toNative();\r
+ cnvs.Children.Add(e);\r
+ System.Windows.Controls.Canvas.SetLeft(e, fig.datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(e, fig.datum.y);\r
+ }\r
+ delegate void SimpleProcedure();\r
+ void getRotation__() { rotation_ = rotateF.Angle; }\r
+ void setRotation__() { rotateF.Angle = rotation_; }\r
+ //void getTranslation__() { rotation_ = rotateF.Angle; }\r
+ void setTranslation__() { translateF.X = datum.x; translateF.Y = datum.y; }\r
+ void setScaling__() { scaleF.ScaleX = scaling_.x; scaleF.ScaleY = scaling_.y; }\r
+\r
+ public static implicit operator System.Windows.Controls.Canvas(Group d)\r
+ {\r
+ var tmp = d.cnvs;//new System.Windows.Controls.Canvas();\r
+ System.Windows.Controls.Canvas.SetLeft(d.cnvs, d.datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(d.cnvs, d.datum.y);\r
+ return tmp;\r
+ }\r
+ public UIElement toNative() { return this; }\r
+\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.groupStack[d.groupStackN];\r
+ tmp.datum = datum;\r
+ tmp.cnvs = cnvs;\r
+ d.stack[d.stackN] = tmp;\r
+ d.groupStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ //d.groupPool[d.groupPoolN] = cnvs;\r
+ //var tmp = d.groupPool[d.groupPoolN];\r
+ var tmp = cnvs;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+ tmp.Visibility = Visibility.Visible;\r
+ //d.groupPoolN++;\r
+ return tmp;\r
+ }\r
+ public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d)\r
+ {\r
+ d.groupPool[d.groupPoolN] = cnvs;\r
+ System.Windows.Controls.Canvas.SetLeft(cnvs, datum.x);\r
+ System.Windows.Controls.Canvas.SetTop(cnvs, datum.y);\r
+ tmp.Visibility = Visibility.Visible;\r
+ }\r
+\r
+ }\r
+ #endregion\r
+ \r
+ #endregion\r
+\r
+\r
+}
\ No newline at end of file