OSDN Git Service

123
authorHOSOKAWA Kenchi <hskwk@inter7.jp>
Thu, 5 Aug 2010 02:59:40 +0000 (11:59 +0900)
committerHOSOKAWA Kenchi <hskwk@inter7.jp>
Thu, 5 Aug 2010 02:59:40 +0000 (11:59 +0900)
dev4/psychlops/core/graphic/canvas.cs
test4/PsychlopsMain.cs

index e8d2af8..d7388d3 100644 (file)
@@ -134,6 +134,10 @@ namespace Psychlops
                internal int pointPoolN;\r
                internal SolidColorBrush[] brushPool;\r
                internal int brushPoolN;\r
+\r
+               internal System.Windows.UIElement[] UIElementPool;\r
+               internal int UIElementPoolN;\r
+\r
                internal System.Windows.Shapes.Line[] linePool;\r
                internal int linePoolN;\r
                internal System.Windows.Shapes.Rectangle[] rectPool;\r
@@ -184,9 +188,9 @@ namespace Psychlops
                        width_ = wid;\r
                        height_ = hei;\r
                        api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);\r
-                       //while(!AsyncInitBool)\r
-                       //{\r
-                       //}\r
+                       while(!AsyncInitBool)\r
+                       {\r
+                       }\r
                        Mouse._prime = api_canvas;\r
                        Main.drawable = this;\r
                        Main.canvas = this;\r
@@ -212,7 +216,7 @@ namespace Psychlops
                        htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px");\r
                        htmlHost.SetStyleAttribute("margin", "2em auto auto auto");\r
 \r
-\r
+                       UIElementPool = new System.Windows.UIElement[10000];\r
                        pointPool = new System.Windows.Point[10000];\r
                        brushPool = new SolidColorBrush[10000];\r
                        linePool = new System.Windows.Shapes.Line[10000];\r
@@ -233,19 +237,23 @@ namespace Psychlops
                                polygonPool[i] = new System.Windows.Shapes.Polygon();\r
                                lettersPool[i] = new System.Windows.Controls.TextBlock();\r
                        }\r
-                       /*\r
                        imagePool = new System.Windows.Controls.Image[100];\r
                        for (int i = 0; i < 100; i++)\r
                        {\r
                                imagePool[i] = new System.Windows.Controls.Image();\r
                        }\r
-                        * */\r
 \r
                        masterPool = new System.Windows.Controls.Canvas();\r
                        prevPool = new System.Windows.Controls.Canvas();\r
                        api_canvas.Children.Add(masterPool);\r
                        //api_canvas.Children.Remove(Internal.Main.widgetStack);\r
 \r
+                       for (int i = 0; i < 10000; i++)\r
+                       {\r
+                               masterPool.Children.Add(UIElementPool[i]);\r
+                       }\r
+\r
+\r
                        AsyncInitBool = true;\r
                }\r
 \r
@@ -299,10 +307,8 @@ namespace Psychlops
                                nextIntervalFrame = 1;\r
                                chacked = 1;\r
                        }\r
-                       //                      pointPoolN = 0;\r
-                       //                      brushPoolN = 0;\r
-                       linePoolN = 0;\r
-                       rectPoolN = 0;\r
+                       //pointStackN = 0;\r
+                       //brushStackN = 0;\r
                        lineStackN = 0;\r
                        rectStackN = 0;\r
                        polygonStackN = 0;\r
@@ -323,20 +329,102 @@ namespace Psychlops
                }\r
                public void executeFlip()\r
                {\r
+                       #region version modifyNative\r
+                       Line lineS;\r
+                       Rectangle rectS;\r
+                       Ellipse ellipseS;\r
+                       Polygon polygonS;\r
+                       Letters lettersS;\r
+                       Image imageS;\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
+                       #endregion\r
+\r
                        lock (this)\r
                        {\r
                                nextIntervalFrame--;\r
                        }\r
+\r
+                       var en = masterPool.Children.GetEnumerator();\r
+                       bool full = en.MoveNext();\r
+                       UIElementPoolN = 0;\r
                        if (nextIntervalFrame <= 0)\r
                        {\r
                                if (chacked > 0)\r
                                {\r
-                                       masterPool.Children.Clear();\r
+                                       //masterPool.Children.Clear();\r
                                        if (stackN > 0)\r
                                        {\r
                                                for (int i = 0; i < stackN - 2; i++)\r
                                                {\r
-                                                       masterPool.Children.Add(stack[i].poolNative(this));\r
+                                                       UIElementPool[UIElementPoolN] = stack[i].poolNative(this);\r
+                                                       UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;\r
+                                                       UIElementPoolN++;\r
+\r
+                                                       #region version modifyNative\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
+                                                               }\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
+                                                               full = en.MoveNext();\r
+                                                       }\r
+                                                        * */\r
+                                                       #endregion\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
@@ -454,6 +542,18 @@ namespace Psychlops
                        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;\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
        partial class Rectangle\r
@@ -502,6 +602,15 @@ namespace Psychlops
                        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;\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
        partial class Ellipse\r
@@ -548,6 +657,15 @@ namespace Psychlops
                        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;\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
+               }\r
        }\r
 \r
        partial class Polygon\r
@@ -603,6 +721,18 @@ namespace Psychlops
                        d.polygonPoolN++;\r
                        return tmp;\r
                }\r
+               public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)\r
+               {\r
+                       tmp.Fill = fill;\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(d.rectPool[d.rectPoolN], datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
 \r
        }\r
        \r
@@ -689,6 +819,21 @@ namespace Psychlops
                        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;\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
        }\r
 \r
        partial class Image\r
@@ -755,10 +900,17 @@ namespace Psychlops
                        System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
                        System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);\r
                        tmp.Visibility = Visibility.Visible;\r
-                       d.rectPoolN++;\r
-                       throw new Exception("Image.poolNative");\r
+                       d.imagePoolN++;\r
                        return this;\r
                }\r
+               public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)\r
+               {\r
+                       throw new Exception("Image.modifyNative");\r
+                       tmp.Source = buffer;\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
 \r
        }\r
 \r
index c808b11..adff3c4 100644 (file)
@@ -20,14 +20,15 @@ namespace PsychlopsSilverlight4test
 \r
                public void psychlops_main()\r
                {\r
-                       throw new System.Exception("Speed");\r
                        //DotNumberS = new Psychlops.Widgets.Slider("test", new Interval(10, 500));\r
                        //Independent ind = new Independent();\r
 \r
                        cnvs = new Canvas(500, 500);\r
 \r
-                       //Image img = new Image(20, 20);\r
-                       //img.field(delegate(int x, int y) { return new Color(Math.sin(x + y)); });\r
+                       Image img = new Image(100, 100);\r
+                       img.field(delegate(int x, int y) { return new Color(0.5 + 0.5 * Math.sin(x + y)); });\r
+                       Image img2 = new Image(100, 100);\r
+                       img2.field(delegate(int x, int y) { return new Color(0.5 + 0.5 * Math.sin(x + y)); });\r
                        /*\r
                        for (int x = 0; x < 20; x++)\r
                        {\r
@@ -42,11 +43,11 @@ namespace PsychlopsSilverlight4test
                        //Declare background dots and target\r
                        Rectangle[] BGDot = new Rectangle[2048];\r
                        for(int i=0; i<2048; i++){\r
-                       BGDot[i]=new Rectangle();\r
+                               BGDot[i]=new Rectangle();\r
                        }\r
                        Rectangle[] Target= new Rectangle[10];\r
                        for(int i=0; i<10; i++){\r
-                       Target[i]=new Rectangle();\r
+                               Target[i]=new Rectangle();\r
                        }\r
 \r
 \r
@@ -60,75 +61,73 @@ namespace PsychlopsSilverlight4test
 \r
                        //Initialize positions of background dots\r
                        for(int i=0; i<2048; i++){\r
-                       t=2.0*Math.PI*Math.random(1.0);\r
-                       p=2.0*Math.PI*Math.random(1.0);\r
-                       DotX[i]=t;\r
-                       DotY[i]=p;\r
-\r
-                       x=BGRadii*Math.cos(t)*Math.cos(p);\r
-                       y=BGRadii*Math.sin(t)*Math.cos(p);\r
-                       BGDot[i].set(BGSize, BGSize);\r
-                       BGDot[i].centering().shift(x,y);\r
+                               t=2.0*Math.PI*Math.random(1.0);\r
+                               p=2.0*Math.PI*Math.random(1.0);\r
+                               DotX[i]=t;\r
+                               DotY[i]=p;\r
+\r
+                               x=BGRadii*Math.cos(t)*Math.cos(p);\r
+                               y=BGRadii*Math.sin(t)*Math.cos(p);\r
+                               BGDot[i].set(BGSize, BGSize);\r
+                               BGDot[i].centering().shift(x,y);\r
                        }\r
 \r
                        //Initialize positions of targets\r
                        for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);\r
 \r
                        double COS, SIN;\r
-\r
+                       DotNumber = 100;\r
                        //Main stimulus loop\r
                        while(true){\r
-                       //Clear the main window\r
-                       cnvs.clear(Color.black);\r
-\r
-\r
-                       temp=Axis/360*2*Math.PI;\r
-                       COS=Math.cos(temp);\r
-                       SIN=Math.sin(temp);\r
-\r
-                       //Calculate positions of background dots and set them\r
-                       for(int i=0; i<DotNumber; i++){\r
-                       //Calculate in polar coordinate\r
-                       t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;\r
-                       p=DotY[i];\r
-\r
-                       //Save current position\r
-                       DotX[i]=t;\r
-\r
-                       //Convert to Decartes coordinate\r
-                       x=BGRadii*Math.cos(t)*Math.cos(p);\r
-                       y=BGRadii*Math.sin(t)*Math.cos(p);\r
-                       z=BGRadii*Math.sin(p);\r
-                       xx=x;\r
-                       yy=SIN*y+COS*z;\r
-\r
-                       //Set Dotsize and Draw them\r
-                       BGDot[i].set(BGSize, BGSize);\r
-                       BGDot[i].centering().shift(xx,yy);\r
-                       BGDot[i].draw( Color.blue);\r
-                       }\r
-\r
-                       //Calculate positions of targets and set them\r
-                       temp=Rotate*2*Math.PI/360.0;\r
-                       cnvs.msg(TargetNumber.ToString(), 0, 30);\r
-                       for (int i = 0; i < 5; i++)\r
-                       {\r
-                               cnvs.msg(i.ToString(), 50+50*i, 30);\r
-                               t = 2.0 * Math.PI/TargetNumber;\r
-                               x = 10.0 * i;//TargetEcce*Math.cos(i*t+temp);\r
-                               y = 10.0 * i;//TargetEcce*Math.sin(i*t+temp);\r
-                               Target[i].centering().shift(x,y);\r
-                               Target[i].fill = Color.yellow;\r
-                               Target[i].draw();\r
-                       }\r
-\r
-                       //img.centering().draw();\r
-                       //Reflect drawing at the next frame;\r
-                       cnvs.flip();\r
-               }\r
-\r
+                               //Clear the main window\r
+                               cnvs.clear(Color.green);\r
+\r
+\r
+                               temp=Axis/360*2*Math.PI;\r
+                               COS=Math.cos(temp);\r
+                               SIN=Math.sin(temp);\r
+\r
+                               //Calculate positions of background dots and set them\r
+                               for(int i=0; i<DotNumber; i++){\r
+                                       //Calculate in polar coordinate\r
+                                       t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;\r
+                                       p=DotY[i];\r
+\r
+                                       //Save current position\r
+                                       DotX[i]=t;\r
+\r
+                                       //Convert to Decartes coordinate\r
+                                       x=BGRadii*Math.cos(t)*Math.cos(p);\r
+                                       y=BGRadii*Math.sin(t)*Math.cos(p);\r
+                                       z=BGRadii*Math.sin(p);\r
+                                       xx=x;\r
+                                       yy=SIN*y+COS*z;\r
+\r
+                                       //Set Dotsize and Draw them\r
+                                       BGDot[i].set(BGSize, BGSize);\r
+                                       BGDot[i].centering().shift(xx,yy);\r
+                                       BGDot[i].draw( Color.blue);\r
+                               }\r
 \r
+                               //Calculate positions of targets and set them\r
+                               temp=Rotate*2*Math.PI/360.0;\r
+                               cnvs.msg(TargetNumber.ToString(), 0, 30);\r
+                               for (int i = 0; i < 5; i++)\r
+                               {\r
+                                       cnvs.msg(i.ToString(), 50+50*i, 30);\r
+                                       t = 2.0 * Math.PI/TargetNumber;\r
+                                       x = 10.0 * i;//TargetEcce*Math.cos(i*t+temp);\r
+                                       y = 10.0 * i;//TargetEcce*Math.sin(i*t+temp);\r
+                                       Target[i].centering().shift(x,y);\r
+                                       Target[i].fill = Color.yellow;\r
+                                       Target[i].draw();\r
+                               }\r
 \r
+                               img.centering().draw();\r
+                               img2.centering().draw();\r
+                               //Reflect drawing at the next frame;\r
+                               cnvs.flip();\r
+                       }\r
                }\r
        }\r
 \r