OSDN Git Service

enable
[psychlops/silverlight.git] / dev4 / psychlops / core / graphic / canvas.cs
index fdc3987..5b58b03 100644 (file)
@@ -9,11 +9,21 @@ using System.Windows.Media.Imaging;
 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
@@ -21,105 +31,61 @@ namespace Psychlops
                {\r
 //                     protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
                        internal Internal.PrimitiveFigure[] stack;\r
-                       internal int stackN;\r
+                       internal int stackN = 0;\r
                        internal Line[] lineStack;\r
-                       internal int lineStackN;\r
+                       internal int lineStackN = 0;\r
                        internal Rectangle[] rectStack;\r
-                       internal int rectStackN;\r
+                       internal int rectStackN = 0;\r
                        internal Ellipse[] ellipseStack;\r
-                       internal int ellipseStackN;\r
+                       internal int ellipseStackN = 0;\r
                        internal Polygon[] polygonStack;\r
-                       internal int polygonStackN;\r
+                       internal int polygonStackN = 0;\r
                        internal Letters[] lettersStack;\r
-                       internal int lettersStackN;\r
+                       internal int lettersStackN = 0;\r
                        internal Image[] imageStack;\r
-                       internal int imageStackN;\r
+                       internal int imageStackN = 0;\r
                        internal Group[] groupStack;\r
-                       internal int groupStackN;\r
-\r
+                       internal int groupStackN = 0;\r
 \r
                        public StackableDrawable()\r
                        {\r
-//                             stack = new System.Collections.Generic.Queue<Internal.PrimitiveFigure>();\r
-                               stack = new Internal.PrimitiveFigure[10000];\r
-                               lineStack = new Line[2000];\r
-                               rectStack = new Rectangle[2000];\r
-                               ellipseStack = new Ellipse[2000];\r
-                               polygonStack = new Polygon[1000];\r
-                               lettersStack = new Letters[1000];\r
-                               imageStack = new Image[100];\r
-                               groupStack = new Group[100];\r
-                               for (int i = 0; i < 2000; i++)\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
+                               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 < 1000; i++)\r
+                               for (int i = 0; i < CONST.COBJ_N; i++)\r
                                {\r
                                        polygonStack[i] = new Polygon();\r
                                        lettersStack[i] = new Letters();\r
                                }\r
-                               for (int i = 0; i < 100; i++)\r
+                               for (int i = 0; i < CONST.HOBJ_N; i++)\r
                                {\r
-                                       imageStack[i] = new Image(1, 1);\r
-                                       groupStack[i] = new Group();\r
+                                       imageStack[i] = new Image();\r
+//                                     groupStack[i] = new Group();\r
                                }\r
                        }\r
 \r
-                       public void clear()\r
-                       {\r
-                               clear(Color.black);\r
-                       }\r
-                       public virtual void clear(Color col)\r
-                       {\r
-                               //rect(back_panel, col);\r
-                       }\r
-\r
-                       public virtual void pix(int x, int y, Color col)\r
-                       {\r
-                       }\r
-\r
-                       public virtual void line(Line drawee)\r
-                       {\r
-                               //                              stack.Enqueue(drawee.clone());\r
-                               drawee.copyToStack(this);\r
-                       }\r
-\r
-                       public virtual void rect(Rectangle drawee)\r
-                       {\r
-                               //stack.Enqueue(drawee.clone());\r
-//                             stack.Enqueue(drawee.copyToStack(this));\r
-                               drawee.copyToStack(this);\r
-                       }\r
-\r
-                       public virtual void ellipse(Ellipse drawee)\r
-                       {\r
-                               //                              stack.Enqueue(drawee.clone());\r
-                               drawee.copyToStack(this);\r
-                       }\r
-\r
-                       public virtual void polygon(Polygon drawee)\r
-                       {\r
-                               //                              stack.Enqueue(drawee.clone());\r
-                               drawee.copyToStack(this);\r
-                       }\r
-\r
-                       public virtual void letters(Letters drawee)\r
-                       {\r
-                               //                              stack.Enqueue(drawee.clone());\r
-                               drawee.copyToStack(this);\r
-                       }\r
-\r
-                       public virtual void image(Image drawee)\r
-                       {\r
-                               //                              stack.Enqueue(drawee.clone());\r
-                               drawee.copyToStack(this);\r
-                       }\r
-                       public virtual void group(Group drawee)\r
-                       {\r
-                               drawee.copyToStack(this);\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
 \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
@@ -139,7 +105,6 @@ namespace Psychlops
 \r
        public class Canvas : Templates.StackableDrawable\r
        {\r
-\r
                internal System.Windows.Controls.Canvas masterPool, prevPool;\r
                internal System.Windows.Point[] pointPool;\r
                internal int pointPoolN;\r
@@ -148,6 +113,7 @@ namespace Psychlops
 \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
@@ -162,6 +128,7 @@ namespace Psychlops
                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
@@ -171,14 +138,11 @@ namespace Psychlops
                internal delegate void SimpleProcedure();\r
                SimpleProcedure flipexec;\r
 \r
-               //public static System.Windows.Controls.Image default_buffer_frame;\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
-               //WriteableBitmap buffer;\r
-               //System.Windows.Controls.Image instance;\r
-               System.Windows.Controls.Canvas api_canvas;\r
-               System.Windows.Controls.UserControl panel;\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
@@ -201,12 +165,15 @@ namespace Psychlops
                {\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 TwoIntProcedure(initialize__), wid, hei);\r
-                       while(!AsyncInitBool)\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
@@ -215,7 +182,6 @@ namespace Psychlops
                        back_panel = new Rectangle(wid, hei);\r
 \r
                        flipexec = new SimpleProcedure(executeFlip);\r
-                       AppState.statusBar = "";\r
                }\r
                protected void initialize__(int wid, int hei)\r
                {\r
@@ -231,82 +197,81 @@ namespace Psychlops
                        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", (20+hei).ToString() + "px");\r
+                       htmlHost.SetStyleAttribute("height", (hei).ToString() + "px");\r
                        htmlHost.SetStyleAttribute("margin", "2em auto auto auto");\r
 \r
-                       UIElementPool = new System.Windows.Controls.Canvas[2000];\r
-                       pointPool = new System.Windows.Point[2000];\r
-                       brushPool = new SolidColorBrush[2000];\r
-                       linePool = new System.Windows.Shapes.Line[2000];\r
-                       rectPool = new System.Windows.Shapes.Rectangle[2000];\r
-                       dummyRectPool = new System.Windows.Shapes.Rectangle[2000];\r
-                       ellipsePool = new System.Windows.Shapes.Ellipse[2000];\r
-                       for (int i = 0; i < 2000; i++)\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
-                               UIElementPool[i] = new System.Windows.Controls.Canvas();\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
-                               dummyRectPool[i] = new System.Windows.Shapes.Rectangle();\r
                                ellipsePool[i] = new System.Windows.Shapes.Ellipse();\r
                        }\r
-                       polygonPool = new System.Windows.Shapes.Polygon[1000];\r
-                       lettersPool = new System.Windows.Controls.TextBlock[1000];\r
-                       for (int i = 0; i < 1000; i++)\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
                                polygonPool[i] = new System.Windows.Shapes.Polygon();\r
                                lettersPool[i] = new System.Windows.Controls.TextBlock();\r
                        }\r
-                       imagePool = new System.Windows.Controls.Image[100];\r
-                       groupPool = new System.Windows.Controls.Canvas[100];\r
-                       for (int i = 0; i < 100; i++)\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
-                       for (int i = 0; i < 2000; i++)\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
-\r
                        AsyncInitBool = true;\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 System.Windows.Shapes.Line api_line;\r
-               static System.Windows.Shapes.Path api_curve;\r
-               static System.Windows.Shapes.Rectangle api_rect;\r
-               static System.Windows.Shapes.Ellipse api_ellipse;\r
-               static System.Windows.Shapes.Polygon api_polygon;\r
-               static System.Windows.Shapes.Polyline api_polyline;\r
-               static System.Windows.Media.Color api_color;\r
-               static System.Windows.Media.SolidColorBrush api_fill;\r
-               static System.Windows.Media.SolidColorBrush api_stroke;\r
-               static System.Windows.Media.TranslateTransform api_translation;\r
                static Canvas()\r
                {\r
-                       api_line = new System.Windows.Shapes.Line();\r
-                       api_curve    = new System.Windows.Shapes.Path();\r
-                       api_rect     = new System.Windows.Shapes.Rectangle();\r
-                       api_ellipse  = new System.Windows.Shapes.Ellipse();\r
-                       api_polygon  = new System.Windows.Shapes.Polygon();\r
-                       api_polyline = new System.Windows.Shapes.Polyline();\r
-                       api_color       = new System.Windows.Media.Color();\r
-                       api_fill        = new System.Windows.Media.SolidColorBrush();\r
-                       api_stroke      = new System.Windows.Media.SolidColorBrush();\r
-                       api_translation = new System.Windows.Media.TranslateTransform();\r
                }\r
                */\r
                #endregion\r
@@ -328,7 +293,6 @@ namespace Psychlops
                                chacked = 1;\r
                        }\r
                        //pointStackN = 0;\r
-                       //brushStackN = 0;\r
                        lineStackN = 0;\r
                        rectStackN = 0;\r
                        polygonStackN = 0;\r
@@ -337,6 +301,8 @@ namespace Psychlops
                        imageStackN = 0;\r
                        groupStackN = 0;\r
 \r
+                       UIElementPoolN = 0;\r
+                       brushPoolN = 0;\r
                        /*\r
                        pointPoolN = 0;\r
                        brushPoolN = 0;\r
@@ -361,9 +327,9 @@ namespace Psychlops
                #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
+//                     Clock after = new Clock();\r
+//                     after.update();\r
+//                     AppState.statusBar = ((after - before).at_msec().ToString()) + " msec";\r
 \r
                        Line lineS;\r
                        Rectangle rectS;\r
@@ -385,113 +351,109 @@ namespace Psychlops
                                nextIntervalFrame--;\r
                        }\r
 \r
-\r
-\r
-                       var en = masterPool.Children.GetEnumerator();\r
-                       bool full = en.MoveNext();\r
-                       var cnv = en.Current as System.Windows.Controls.Canvas;\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 - 2; i++)\r
+                                               for (int i = 0; i < stackN; i++)\r
                                                {\r
-                                                       if (full == false)\r
+                                                       if( null != (rectS = stack[i] as Rectangle) )\r
                                                        {\r
-                                                               break;\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\r
+                                                       else if (null != (lineS = stack[i] as Line))\r
                                                        {\r
-                                                               if( null != (rectS = stack[i] as Rectangle) )\r
+                                                               if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line))\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
+                                                                       lineS.modifyNative(lineP, this);\r
                                                                }\r
-                                                               else if (null != (lineS = stack[i] as Line))\r
+                                                               else\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
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
                                                                }\r
-                                                               else if (null != (ellipseS = stack[i] as Ellipse))\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
-                                                                       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
+                                                                       ellipseS.modifyNative(ellipseP, this);\r
                                                                }\r
-                                                               else if (null != (polygonS = stack[i] as Polygon))\r
+                                                               else\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
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
                                                                }\r
-                                                               else if (null != (lettersS = stack[i] as Letters))\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
-                                                                       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
+                                                                       polygonS.modifyNative(polygonP, this);\r
                                                                }\r
-                                                               else if (null != (imageS = stack[i] as Image))\r
+                                                               else\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
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
                                                                }\r
-                                                               else if (null != (groupS = stack[i] as Group))\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
-                                                                       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
+                                                                       lettersS.modifyNative(lettersP, this);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
                                                                }\r
-                                                               full = en.MoveNext();\r
-                                                               cnv = en.Current as System.Windows.Controls.Canvas;\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
@@ -505,6 +467,8 @@ namespace Psychlops
                }\r
                #endregion\r
 \r
+\r
+\r
                #region version modifyNative\r
                /*\r
                public void executeFlip()\r
@@ -676,12 +640,46 @@ namespace Psychlops
                #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) : 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
@@ -700,6 +698,14 @@ namespace Psychlops
                {\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
@@ -714,7 +720,18 @@ namespace Psychlops
                {\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
@@ -755,7 +772,7 @@ namespace Psychlops
                        tmp.Y1 = begin.y;\r
                        tmp.X2 = end.x;\r
                        tmp.Y2 = end.y;\r
-                       if (stroke.thick == 0.0) tmp.Stroke = fill;\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
@@ -769,13 +786,17 @@ namespace Psychlops
                        tmp.Y1 = begin.y;\r
                        tmp.X2 = end.x;\r
                        tmp.Y2 = end.y;\r
-                       if (stroke.thick == 0.0) tmp.Stroke = fill;\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
@@ -816,7 +837,7 @@ namespace Psychlops
                        var tmp = d.rectPool[d.rectPoolN];\r
                        tmp.Width = width;\r
                        tmp.Height = height;\r
-                       tmp.Fill = fill;\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
@@ -827,12 +848,16 @@ namespace Psychlops
                {\r
                        tmp.Width = width;\r
                        tmp.Height = height;\r
-                       tmp.Fill = fill;\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 Ellipse\r
 \r
        partial class Ellipse\r
        {\r
@@ -871,7 +896,7 @@ namespace Psychlops
                        var tmp = d.ellipsePool[d.ellipsePoolN];\r
                        tmp.Width = width;\r
                        tmp.Height = height;\r
-                       tmp.Fill = fill;\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
@@ -882,13 +907,17 @@ namespace Psychlops
                {\r
                        tmp.Width = width;\r
                        tmp.Height = height;\r
-                       tmp.Fill = fill;\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
@@ -930,7 +959,7 @@ namespace Psychlops
                public UIElement poolNative(Canvas d)\r
                {\r
                        var tmp = d.polygonPool[d.polygonPoolN];\r
-                       tmp.Fill = fill;\r
+                       tmp.Fill = fill.getNativeFromStack(d);\r
                        tmp.Points.Clear();\r
                        foreach (var v in vertices)\r
                        {\r
@@ -944,7 +973,7 @@ namespace Psychlops
                }\r
                public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)\r
                {\r
-                       tmp.Fill = fill;\r
+                       tmp.Fill = fill.getNativeFromStack(d);\r
                        tmp.Points.Clear();\r
                        foreach (var v in vertices)\r
                        {\r
@@ -956,7 +985,11 @@ namespace Psychlops
                }\r
 \r
        }\r
-       \r
+               \r
+       #endregion\r
+\r
+       #region Letters\r
+\r
        partial class Letters\r
        {\r
                #region static initializer\r
@@ -1033,7 +1066,7 @@ namespace Psychlops
                        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;\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
@@ -1050,25 +1083,66 @@ namespace Psychlops
                        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;\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 Canvas.TwoIntProcedure(create__), wid, hei);\r
-                       //buffer = new WriteableBitmap(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
@@ -1134,6 +1208,9 @@ namespace Psychlops
 \r
        }\r
 \r
+       #endregion\r
+\r
+       #region Group\r
 \r
        partial class Group\r
        {\r
@@ -1215,6 +1292,7 @@ namespace Psychlops
                }\r
 \r
        }\r
+       #endregion\r
        \r
        #endregion\r
 \r