OSDN Git Service

shader
[psychlops/silverlight.git] / dev4 / psychlops / core / graphic / canvas.cs
index 4d65ec4..7f0267b 100644 (file)
@@ -36,6 +36,8 @@ namespace Psychlops
                        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
@@ -53,6 +55,7 @@ namespace Psychlops
                                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
@@ -65,6 +68,7 @@ namespace Psychlops
                                }\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
@@ -73,6 +77,8 @@ namespace Psychlops
                                        imageStack[i] = new Image();\r
 //                                     groupStack[i] = new Group();\r
                                }\r
+\r
+\r
                        }\r
 \r
                        public void clear() { clear(Color.black); }\r
@@ -86,6 +92,7 @@ namespace Psychlops
                        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
@@ -120,6 +127,8 @@ namespace Psychlops
                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
@@ -134,9 +143,8 @@ namespace Psychlops
 \r
                #region initializer\r
 \r
-               internal delegate void TwoIntProcedure(int x, int y);\r
-               internal delegate void SimpleProcedure();\r
-               SimpleProcedure flipexec;\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
@@ -161,6 +169,7 @@ namespace Psychlops
                }\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
@@ -169,7 +178,7 @@ namespace Psychlops
                        AsyncInitBool = false;\r
                        width_ = wid;\r
                        height_ = hei;\r
-                       api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);\r
+                       api_canvas.Dispatcher.BeginInvoke(new Action<int,int>(initialize__), wid, hei);\r
                        while (!AsyncInitBool)\r
                        {\r
                                after.update();\r
@@ -181,7 +190,7 @@ namespace Psychlops
 \r
                        back_panel = new Rectangle(wid, hei);\r
 \r
-                       flipexec = new SimpleProcedure(executeFlip);\r
+                       flipexec = new Action(executeFlip);\r
                }\r
                protected void initialize__(int wid, int hei)\r
                {\r
@@ -213,10 +222,12 @@ namespace Psychlops
                                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
@@ -254,6 +265,9 @@ namespace Psychlops
                        }\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
@@ -295,6 +309,7 @@ namespace Psychlops
                        //pointStackN = 0;\r
                        lineStackN = 0;\r
                        rectStackN = 0;\r
+                       shaderStackN = 0;\r
                        polygonStackN = 0;\r
                        ellipseStackN = 0;\r
                        lettersStackN = 0;\r
@@ -332,6 +347,7 @@ namespace Psychlops
 //                     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
@@ -340,6 +356,7 @@ namespace Psychlops
                        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
@@ -360,7 +377,19 @@ namespace Psychlops
                                        {\r
                                                for (int i = 0; i < stackN; i++)\r
                                                {\r
-                                                       if( null != (rectS = stack[i] as Rectangle) )\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
@@ -871,6 +900,62 @@ namespace Psychlops
        }\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
@@ -1114,7 +1199,7 @@ namespace Psychlops
                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
+                       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
@@ -1231,7 +1316,7 @@ namespace Psychlops
        {\r
                internal void initialize__()\r
                {\r
-                       Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.SimpleProcedure(create__));\r
+                       Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action(create__));\r
                }\r
                internal void create__()\r
                {\r