OSDN Git Service

123
[psychlops/silverlight.git] / dev4 / psychlops / core / graphic / canvas.cs
index 0adfc4e..ccdf1a2 100644 (file)
@@ -19,11 +19,26 @@ namespace Psychlops
 \r
                public class StackableDrawable : Drawable\r
                {\r
-                       protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
+//                     protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
+                       internal Internal.PrimitiveFigure[] stack;\r
+                       internal int stackN;\r
+                       internal Line[] lineStack;\r
+                       internal int lineStackN;\r
+                       internal Rectangle[] rectStack;\r
+                       internal int rectStackN;\r
+\r
 \r
                        public StackableDrawable()\r
                        {\r
-                               stack = new System.Collections.Generic.Queue<Internal.PrimitiveFigure>();\r
+//                             stack = new System.Collections.Generic.Queue<Internal.PrimitiveFigure>();\r
+                               stack = new Internal.PrimitiveFigure[40000];\r
+                               lineStack = new Line[10000];\r
+                               rectStack = new Rectangle[10000];\r
+                               for (int i = 0; i < 10000; i++)\r
+                               {\r
+                                       lineStack[i] = new Line(0,0,0,0);\r
+                                       rectStack[i] = new Rectangle();\r
+                               }\r
                        }\r
 \r
                        public void clear()\r
@@ -41,32 +56,34 @@ namespace Psychlops
 \r
                        public virtual void line(Line drawee)\r
                        {\r
-                               stack.Enqueue(drawee.clone());\r
+//                             stack.Enqueue(drawee.clone());\r
                        }\r
 \r
                        public virtual void rect(Rectangle drawee)\r
                        {\r
-                               stack.Enqueue(drawee.clone());\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
+//                             stack.Enqueue(drawee.clone());\r
                        }\r
 \r
                        public virtual void polygon(Polygon drawee)\r
                        {\r
-                               stack.Enqueue(drawee.clone());\r
+//                             stack.Enqueue(drawee.clone());\r
                        }\r
 \r
                        public virtual void letters(Letters drawee)\r
                        {\r
-                               stack.Enqueue(drawee.clone());\r
+//                             stack.Enqueue(drawee.clone());\r
                        }\r
 \r
                        public virtual void image(Image drawee)\r
                        {\r
-                               stack.Enqueue(drawee.clone());\r
+//                             stack.Enqueue(drawee.clone());\r
                        }\r
 \r
                        public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
@@ -88,6 +105,16 @@ namespace Psychlops
        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
+               internal SolidColorBrush[] brushPool;\r
+               internal int brushPoolN;\r
+               internal System.Windows.Shapes.Line[] linePool;\r
+               internal int linePoolN;\r
+               internal System.Windows.Shapes.Rectangle[] rectPool;\r
+               internal int rectPoolN;\r
+\r
                #region initializer\r
 \r
                internal delegate void TwoIntProcedure(int x, int y);\r
@@ -119,7 +146,6 @@ namespace Psychlops
                }\r
                protected void initialize(int wid, int hei)\r
                {\r
-\r
                        width_ = wid;\r
                        height_ = hei;\r
                        api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);\r
@@ -144,9 +170,31 @@ namespace Psychlops
 \r
                        HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");\r
                        //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");\r
-                       htmlHost.SetStyleAttribute("width", (200+wid).ToString()+"px");\r
+                       htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");\r
                        htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px");\r
                        htmlHost.SetStyleAttribute("margin", "2em auto auto auto");\r
+\r
+\r
+                       pointPool = new System.Windows.Point[10000];\r
+                       brushPool = new SolidColorBrush[10000];\r
+                       linePool = new System.Windows.Shapes.Line[10000];\r
+                       rectPool = new System.Windows.Shapes.Rectangle[10000];\r
+                       for (int i = 0; i < 10000; 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
+                       }\r
+                       for (int i = 0; i < 300; i++)\r
+                       {\r
+                               api_canvas.Children.Add(rectStack[i].poolNative(this));\r
+                               api_canvas.Children.Add(rectStack[i].poolNative(this));\r
+                       }\r
+\r
+                       masterPool = new System.Windows.Controls.Canvas();\r
+                       prevPool = new System.Windows.Controls.Canvas();\r
+//                     masterPool.Children.Add()\r
                }\r
 \r
                #endregion\r
@@ -183,6 +231,8 @@ namespace Psychlops
                public override void clear(Color col)\r
                {\r
                        back_panel.fill = col;\r
+//                     stack.Clear();\r
+                       stackN = 0;\r
                        rect(back_panel);\r
                }\r
 \r
@@ -197,6 +247,12 @@ namespace Psychlops
                                nextIntervalFrame = 1;\r
                                chacked = 1;\r
                        }\r
+//                     pointPoolN = 0;\r
+//                     brushPoolN = 0;\r
+//                     linePoolN = 0;\r
+                       rectPoolN = 0;\r
+                       lineStackN = 0;\r
+                       rectStackN = 0;\r
                        Internal.Main.canvas_flag.WaitOne();\r
                }\r
                public void executeFlip()\r
@@ -207,25 +263,39 @@ namespace Psychlops
                        }\r
                        if (nextIntervalFrame <= 0)\r
                        {\r
+                               var rr = new Random();\r
                                //Psychlops.AppState.statusBar = chacked.ToString();\r
                                if (chacked > 0)\r
                                {\r
-                                       var tmp = new System.Windows.Controls.Canvas();\r
-                                       if (stack.Count > 0)\r
+               //                      prevPool.Children.Clear();\r
+               //                      var tmp = new System.Windows.Controls.Canvas();\r
+//                                     if (stack.Count > 0)\r
+                                       if (stackN > 0)\r
                                        {\r
-                                               foreach (Internal.PrimitiveFigure f in stack)\r
+                                               //foreach (UIElement e in api_canvas.Children)\r
+                                               //{\r
+                                               //}\r
+//                                             foreach (Internal.PrimitiveFigure f in stack)\r
+                                               for (int i = 0; i < stackN - 2; i++)\r
                                                {\r
-                                                       tmp.Children.Add(f.toNative());\r
+                                                       //                                                      tmp.Children.Add(f.toNative());\r
+//                                                     tmp.Children.Add(f.poolNative(this));\r
+               //                                      tmp.Children.Add(stack[i].poolNative(this));\r
+                                                       System.Windows.Controls.Canvas.SetLeft(api_canvas.Children[i + 1], rectStack[i].left);\r
+                                                       api_canvas.Children[0] = api_canvas.Children[0];\r
                                                }\r
+                                               stackN = 0;\r
+\r
                                        }\r
-                                       api_canvas.Children.Clear();\r
-                                       api_canvas.Children.Add(tmp);\r
-                                       stack.Clear();\r
+               //                      api_canvas.Children.Clear();\r
+               //                      api_canvas.Children.Add(tmp);\r
+//                                     stack.Clear();\r
                                        lock (this)\r
                                        {\r
                                                chacked = 0;\r
                                        }\r
                                        Psychlops.Internal.Main.canvas_flag.Set();\r
+               //                      prevPool = tmp;\r
                                }\r
                        }\r
                        System.Threading.Thread.Sleep(0);\r
@@ -304,6 +374,22 @@ namespace Psychlops
                        return tmp;\r
                }\r
                public UIElement toNative() { return this; }\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;\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
        }\r
 \r
        partial class Rectangle\r
@@ -316,6 +402,16 @@ namespace Psychlops
                {\r
                        return (Rectangle)MemberwiseClone();\r
                }\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 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
@@ -329,6 +425,19 @@ namespace Psychlops
                        return tmp;\r
                }\r
                public UIElement toNative() { return this; }\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;\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
        }\r
 \r
        partial class Ellipse\r
@@ -350,6 +459,20 @@ namespace Psychlops
                        return tmp;\r
                }\r
                public UIElement toNative() { return this; }\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;\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                       System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
+                       tmp.Visibility = Visibility.Visible;\r
+                       d.rectPoolN++;\r
+*/\r
+                       return this;\r
+               }\r
        }\r
 \r
        partial class Polygon\r
@@ -375,6 +498,21 @@ namespace Psychlops
                        return tmp;\r
                }\r
                public UIElement toNative() { return this; }\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;\r
+                                               System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                                               System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
+                                               tmp.Visibility = Visibility.Visible;\r
+                                               d.rectPoolN++;\r
+*/\r
+                       return this;\r
+               }\r
+\r
        }\r
        \r
        partial class Letters\r
@@ -431,6 +569,20 @@ namespace Psychlops
                        return tmp;\r
                }\r
                public UIElement toNative() { return this; }\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;\r
+                                               System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                                               System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
+                                               tmp.Visibility = Visibility.Visible;\r
+                                               d.rectPoolN++;\r
+*/\r
+                       return this;\r
+               }\r
        }\r
 \r
        partial class Image\r
@@ -478,6 +630,21 @@ namespace Psychlops
                        return tmp;\r
                }\r
                public UIElement toNative() { return this; }\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;\r
+                                               System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                                               System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
+                                               tmp.Visibility = Visibility.Visible;\r
+                                               d.rectPoolN++;\r
+*/\r
+                       return this;\r
+               }\r
+\r
        }\r
 \r
        #endregion\r