OSDN Git Service

321
authorunknown <hskwk@.(none)>
Tue, 17 Aug 2010 11:07:41 +0000 (20:07 +0900)
committerunknown <hskwk@.(none)>
Tue, 17 Aug 2010 11:07:41 +0000 (20:07 +0900)
dev4/psychlops/core/device/clock.cs
dev4/psychlops/core/graphic/canvas.cs
dev4/psychlops/core/graphic/image.cs
dev4/psychlops/extention/math/solver.cs
dev4/psychlops/extention/standard/widget.cs
test4/MainPage.xaml.cs
test4/PsychlopsMain.cs

index bc52821..f4a3ebf 100644 (file)
@@ -34,6 +34,10 @@ namespace Psychlops
                {\r
                        return lhs.ticks != rhs.ticks;\r
                }\r
+               public override int GetHashCode()\r
+               {\r
+                       return ticks.GetHashCode();\r
+               }\r
                public static bool operator >(Clock lhs, Clock rhs)\r
                {\r
                        return lhs.ticks > rhs.ticks;\r
index fdc3987..c64f7f5 100644 (file)
@@ -14,6 +14,14 @@ using System.Windows.Browser;
 namespace Psychlops\r
 {\r
 \r
+       internal static partial class CONST\r
+       {\r
+               internal static readonly uint MAX_OBJ_N = 1500;\r
+               internal static readonly uint MOBJ_N = 1000;\r
+               internal static readonly uint COBJ_N = 300;\r
+               internal static readonly uint HOBJ_N = 100;\r
+       }\r
+\r
        namespace Templates\r
        {\r
 \r
@@ -40,86 +48,42 @@ namespace Psychlops
 \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
                                }\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 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 +103,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 +111,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
@@ -171,12 +135,9 @@ 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
                Rectangle back_panel;\r
@@ -234,33 +195,29 @@ namespace Psychlops
                        htmlHost.SetStyleAttribute("height", (20+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
+                       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
                                groupPool[i] = new System.Windows.Controls.Canvas();\r
@@ -270,11 +227,20 @@ namespace Psychlops
                        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 < 2000; i++)\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
+\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
@@ -285,28 +251,8 @@ namespace Psychlops
 \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 +274,6 @@ namespace Psychlops
                                chacked = 1;\r
                        }\r
                        //pointStackN = 0;\r
-                       //brushStackN = 0;\r
                        lineStackN = 0;\r
                        rectStackN = 0;\r
                        polygonStackN = 0;\r
@@ -337,6 +282,8 @@ namespace Psychlops
                        imageStackN = 0;\r
                        groupStackN = 0;\r
 \r
+                       UIElementPoolN = 0;\r
+                       brushPoolN = 0;\r
                        /*\r
                        pointPoolN = 0;\r
                        brushPoolN = 0;\r
@@ -385,113 +332,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
+                                                       }\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
-                                                               full = en.MoveNext();\r
-                                                               cnv = en.Current as System.Windows.Controls.Canvas;\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
@@ -700,6 +643,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,6 +665,13 @@ 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
        partial class Line\r
@@ -755,7 +713,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,7 +727,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
@@ -816,7 +774,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,7 +785,7 @@ 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
@@ -871,7 +829,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,7 +840,7 @@ 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
@@ -930,7 +888,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 +902,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
@@ -1033,7 +991,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,7 +1008,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
index 6d5f3f5..4c775ae 100644 (file)
@@ -71,6 +71,10 @@ namespace Psychlops{
                        //buffer.ForEach(func);\r
                }\r
 \r
+               public void load()\r
+               {\r
+               }\r
+\r
                public void draw()\r
                {\r
                        Main.drawable.image(this);\r
index e26365f..eca5c7a 100644 (file)
@@ -7,6 +7,10 @@ namespace Psychlops
 \r
        namespace Solver\r
        {\r
+               internal static class CONST\r
+               {\r
+                       public static readonly uint MAX_ARG = 5;\r
+               }\r
 \r
                \r
                static public class Constants\r
@@ -112,6 +116,10 @@ namespace Psychlops
 \r
                        public BinomialLikelihoodThread()\r
                        {\r
+                               itvl = new Interval[CONST.MAX_ARG];\r
+                               step = new double[CONST.MAX_ARG];\r
+                               champ = new double[CONST.MAX_ARG];\r
+                               data = new BernoulliProcess();\r
                        }\r
                        public void waitLoop()\r
                        {\r
@@ -237,6 +245,9 @@ namespace Psychlops
 \r
                        public BinomialLikelihood()\r
                        {\r
+                               itvl = new Interval[CONST.MAX_ARG];\r
+                               step = new double[CONST.MAX_ARG];\r
+                               champ = new double[CONST.MAX_ARG];\r
                                iteration = 2;\r
                        }\r
 \r
@@ -248,11 +259,8 @@ namespace Psychlops
 \r
                                BinomialLikelihoodThread[] l = new BinomialLikelihoodThread[4];\r
 \r
-                               double r, low, high;\r
                                for (int k = 0; k < iteration; k++)\r
                                {\r
-                                       champ_like = 0;\r
-\r
                                        begin_base(l);\r
                                        for (int i = 0; i < 4; i++)\r
                                        {\r
@@ -261,14 +269,6 @@ namespace Psychlops
                                                l[i].loop1();\r
                                        }\r
                                        end_base(l);\r
-\r
-                                       for (int j = 0; j < Constants.LIMIT; j++)\r
-                                       {\r
-                                               r = itvl[j].end.val - itvl[j].begin.val;\r
-                                               low = champ[j] - r / 8.0 < itvl[j].begin.val ? itvl[j].begin.val : champ[j] - r / 8.0;\r
-                                               high = champ[j] + r / 8.0 > itvl[j].end.val ? itvl[j].end.val : champ[j] + r / 8.0;\r
-                                               itvl[j] = new Interval(low, high);\r
-                                       }\r
                                }\r
                        }\r
                        public void begin(Constants.Func2 d_func)\r
@@ -277,11 +277,8 @@ namespace Psychlops
 \r
                                BinomialLikelihoodThread[] l = new BinomialLikelihoodThread[4];\r
 \r
-                               double r, low, high;\r
                                for (int k = 0; k < iteration; k++)\r
                                {\r
-                                       champ_like = 0;\r
-\r
                                        begin_base(l);\r
                                        for (int i = 0; i < 4; i++)\r
                                        {\r
@@ -290,14 +287,6 @@ namespace Psychlops
                                                l[i].loop2();\r
                                        }\r
                                        end_base(l);\r
-\r
-                                       for (int j = 0; j < Constants.LIMIT; j++)\r
-                                       {\r
-                                               r = itvl[j].end.val - itvl[j].begin.val;\r
-                                               low = champ[j] - r / 8.0 < itvl[j].begin.val ? itvl[j].begin.val : champ[j] - r / 8.0;\r
-                                               high = champ[j] + r / 8.0 > itvl[j].end.val ? itvl[j].end.val : champ[j] + r / 8.0;\r
-                                               itvl[j] = new Interval(low, high);\r
-                                       }\r
                                }\r
                        }\r
                        public void begin(Constants.Func3 d_func)\r
@@ -306,11 +295,8 @@ namespace Psychlops
 \r
                                BinomialLikelihoodThread[] l = new BinomialLikelihoodThread[4];\r
 \r
-                               double r, low, high;\r
                                for (int k = 0; k < iteration; k++)\r
                                {\r
-                                       champ_like = 0;\r
-\r
                                        begin_base(l);\r
                                        for(int i=0; i<4; i++) {\r
                                                l[i].data = data;\r
@@ -318,14 +304,6 @@ namespace Psychlops
                                                l[i].loop3();\r
                                        }\r
                                        end_base(l);\r
-\r
-                                       for (int j = 0; j < Constants.LIMIT; j++)\r
-                                       {\r
-                                               r = itvl[j].end.val - itvl[j].begin.val;\r
-                                               low  = champ[j]-r/8.0 < itvl[j].begin.val ? itvl[j].begin.val : champ[j]-r/8.0;\r
-                                               high = champ[j]+r/8.0 > itvl[j].end.val   ? itvl[j].end.val   : champ[j]+r/8.0;\r
-                                               itvl[j] = new Interval(low, high);\r
-                                       }\r
                                }\r
                        }\r
 \r
@@ -338,6 +316,8 @@ namespace Psychlops
 \r
                        void begin_base(BinomialLikelihoodThread[] l)\r
                        {\r
+                               champ_like = 0;\r
+\r
                                data.length = data.elems.GetLength(0);\r
                                for (int i = 0; i < data.elems.GetLength(0); i++)\r
                                {\r
@@ -373,6 +353,15 @@ namespace Psychlops
                                        }\r
                                }\r
 \r
+                               double r, low, high;\r
+                               for (int j = 0; j < Constants.LIMIT; j++)\r
+                               {\r
+                                       r = itvl[j].end.val - itvl[j].begin.val;\r
+                                       low = champ[j] - r / 8.0 < itvl[j].begin.val ? itvl[j].begin.val : champ[j] - r / 8.0;\r
+                                       high = champ[j] + r / 8.0 > itvl[j].end.val ? itvl[j].end.val : champ[j] + r / 8.0;\r
+                                       itvl[j] = new Interval(low, high);\r
+                               }\r
+\r
                        }\r
 \r
 \r
index 4fe21e7..9d5a71c 100644 (file)
@@ -79,33 +79,107 @@ namespace Psychlops
                        public WidgetRect& pushThis();\r
                };\r
                */\r
+               \r
                /*\r
                public class Slider\r
                {\r
+                       public string label;\r
                        public Rectangle outer;\r
+                       public Rectangle inner;\r
+                       public Stroke outer_strk;\r
+\r
+                       public Slider()\r
+                       {\r
+                               set(0, 0);\r
+                       }\r
+                       public Slider(double width, double height)\r
+                       {\r
+                               set(width, height);\r
+                       }\r
+                       public Slider set(double width, double height)\r
+                       {\r
+                               outer = new Rectangle(width, height);\r
+                               outer.fill = Color.gray;\r
+                               inner = new Rectangle();\r
+                               inner.fill = Color.blue;\r
+                               outer_strk = new Stroke();\r
+                               outer_strk.color = Color.white;\r
+                               outer_strk.thick = 1;\r
+                               return this;\r
+                       }\r
+                       public void checkClick()\r
+                       {\r
+                               if (outer.include(Mouse.position))\r
+                               {\r
+                                       outer.stroke = outer_strk;\r
+                               }\r
+                       }\r
                }\r
-               */\r
+                */\r
+\r
 \r
                public class Slider\r
                {\r
+                       public static Color bgcolor;\r
+\r
                        internal System.Windows.UIElement instance;\r
                        internal System.Windows.Controls.Slider uislider;\r
+                       internal System.Windows.Controls.TextBlock uilabel;\r
+                       internal System.Windows.Controls.TextBox uibox;\r
                        internal string label;\r
                        internal Interval range;\r
+                       internal SelfDelegate get_;\r
+                       internal SelfDelegate set_;\r
+                       internal double retval;\r
+                       internal bool setted_;\r
+\r
+                       static Slider()\r
+                       {\r
+                               bgcolor.set(.5,.5, .5, .3);\r
+                       }\r
 \r
-                       public Slider(string l, Interval r)\r
+                       public Slider(string l, Interval r, double initialvalue)\r
                        {\r
+                               retval = initialvalue;\r
                                range = r;\r
                                label = l;\r
+                               setted_ = false;\r
                                Psychlops.Widgets.Connector.stackSlider(this);\r
+                               get_ = new SelfDelegate(get__);\r
+                               set_ = new SelfDelegate(set__);\r
+                               while (!setted_) { System.Threading.Thread.Sleep(10); }\r
                        }\r
                        public static implicit operator double(Slider s)\r
                        {\r
                                return s.value;\r
                        }\r
-                       public double value {\r
-                               get { return uislider.Value; }\r
-                               set { if(uislider!=null) uislider.Dispatcher.BeginInvoke( new Action<System.Windows.Controls.Slider, double>(Connector.sliderSet) , uislider, value ); }\r
+\r
+                       public delegate void SelfDelegate(System.Windows.Controls.Slider s);\r
+                       public void get__(System.Windows.Controls.Slider s) { retval = s.Value; }\r
+                       public void set__(System.Windows.Controls.Slider s) { s.Value = retval; }\r
+\r
+                       public double getValue()\r
+                       {\r
+                               if (uislider != null) {\r
+                                       uislider.Dispatcher.BeginInvoke(get_, uislider);\r
+                                       return retval;\r
+                               } else {\r
+                                       return 0;\r
+                               }\r
+                       }\r
+                       public void setValue(double v)\r
+                       {\r
+                               if (uislider != null)\r
+                               {\r
+                                       retval = v;\r
+                                       uislider.Dispatcher.BeginInvoke(set_, uislider);\r
+                               }\r
+                       }\r
+\r
+                       public double value\r
+                       {\r
+                               get { return getValue(); }\r
+                               set { setValue(value); }\r
                        }\r
                        public bool changed { get; set; }\r
                }\r
@@ -178,7 +252,6 @@ namespace Psychlops
                }\r
 \r
 \r
-\r
                internal static class Connector\r
                {\r
                        internal delegate void VoidString(string s);\r
@@ -193,15 +266,22 @@ namespace Psychlops
                        }\r
                        static void stackSlider__(Slider ss)\r
                        {\r
-                               var holder = new System.Windows.Controls.Canvas { Width = 200 };\r
+                               var label = new System.Windows.Controls.TextBlock { Text = ss.label };\r
+                               label.Foreground = Color.white;\r
+                               System.Windows.Controls.Canvas.SetLeft(label, 3);\r
+                               System.Windows.Controls.Canvas.SetTop(label, 3);\r
+                               ss.uilabel = label;\r
+\r
+                               var holder = new System.Windows.Controls.Canvas { Width = 200, Height = 50 };\r
                                var val = new System.Windows.Controls.TextBox { Width = 100 };\r
                                System.Windows.Controls.Canvas.SetLeft(val, 100);\r
                                var slide = new System.Windows.Controls.Slider {\r
                                                Minimum = ss.range.begin.val, Maximum = ss.range.end.val,\r
                                                Name = ss.label,\r
+                                               Value = ss.retval,\r
                                                Tag = ss, Width = 200,\r
                                };\r
-                               System.Windows.Controls.Canvas.SetTop(slide, 25);\r
+                               System.Windows.Controls.Canvas.SetTop(slide, label.ActualHeight - 3);\r
                                var b = new System.Windows.Data.Binding {\r
                                                Path = new PropertyPath("Value"),\r
                                                Mode = System.Windows.Data.BindingMode.TwoWay,\r
@@ -209,30 +289,24 @@ namespace Psychlops
                                };\r
                                val.SetBinding(TextBox.TextProperty, b);\r
                                ss.uislider = slide;\r
-                               //var b2 = new System.Windows.Data.Binding\r
-                               //{\r
-                               //      Path = new PropertyPath("value"),\r
-                               //      Mode = System.Windows.Data.BindingMode.TwoWay,\r
-                               //      Source = ss,\r
-                               //};\r
-                               //val.SetBinding(System.Windows.Controls.Slider.ValueProperty, b2);\r
-                               var label = new System.Windows.Controls.TextBlock { Text = ss.label };\r
-                               System.Windows.Controls.Canvas.SetLeft(label, 3);\r
-                               System.Windows.Controls.Canvas.SetTop(label, 3);\r
+                               ss.uibox = val;\r
+                               val.Background = Color.null_color;\r
+                               val.BorderBrush = Color.null_color;\r
+                               val.Foreground = Color.white;\r
+\r
+                               holder.Background = Slider.bgcolor;\r
 \r
                                holder.Children.Add(label);\r
-                               holder.Children.Add(slide);\r
                                holder.Children.Add(val);\r
+                               holder.Children.Add(slide);\r
+                               holder.Height = label.ActualHeight + slide.ActualHeight + val.ActualHeight + 15;\r
                                ss.instance = holder;\r
                                Internal.Main.widgetStack.Children.Add(ss.instance);\r
+                               ss.setted_ = true;\r
                        }\r
-                       public static void sliderSet(System.Windows.Controls.Slider s, double v)\r
-                       {\r
-                               s.Value = v;\r
-                       }\r
-\r
                }\r
 \r
        }\r
 \r
-}
\ No newline at end of file
+}\r
+\r
index 685c460..0889ace 100644 (file)
@@ -38,7 +38,7 @@ namespace PsychlopsSilverlight4test
                        //main_routine = main.psychlops_main();\r
 \r
                        Psychlops.Internal.Main.statusBar = AppStatusBar;\r
-                       Psychlops.Internal.Main.widgetStack = Controller;\r
+                       //Psychlops.Internal.Main.widgetStack = Controller;\r
                        AppStatusBar.Text = "Now starting Psychlops environment... please wait a minute";\r
                }\r
                protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e) {\r
index e7b6754..2794969 100644 (file)
@@ -1,4 +1,4 @@
-/*using Psychlops;\r
+using Psychlops;\r
 \r
 namespace PsychlopsSilverlight4test\r
 {\r
@@ -14,12 +14,19 @@ namespace PsychlopsSilverlight4test
                double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;\r
 \r
                //Set Background Initial Value\r
-               double DotNumber = 50, thetaSpeed = 3.0, Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
+               double Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
+               Psychlops.Widgets.Slider thetaSpeed, DotNumber;\r
+\r
+\r
 \r
                public void psychlops_main()\r
-               {\r
+               {       \r
                        cnvs = new Canvas(500, 500);\r
 \r
+                       Interval rng = new Interval();\r
+                       thetaSpeed = new Psychlops.Widgets.Slider("Label" , -10 <= rng <= 10,   3.0);\r
+                       DotNumber  = new Psychlops.Widgets.Slider("DotNum",   0 <= rng <= 100, 50.0);\r
+\r
                        //Declare background dots and target\r
                        Rectangle[] BGDot = new Rectangle[2048];\r
                        for(int i=0; i<2048; i++){\r
@@ -56,11 +63,11 @@ namespace PsychlopsSilverlight4test
                        for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);\r
 \r
                        double COS, SIN;\r
-                       DotNumber = 200;\r
+                       //DotNumber = 200;\r
                        //Main stimulus loop\r
                        while(true){\r
                                //Clear the main window\r
-                               cnvs.clear(Color.green);\r
+                               cnvs.clear();\r
 \r
 \r
                                temp=Axis/360*2*Math.PI;\r
@@ -108,7 +115,8 @@ namespace PsychlopsSilverlight4test
        }\r
 \r
 }\r
-*/\r
+\r
+\r
 \r
 /*using Psychlops;\r
 \r
@@ -156,10 +164,10 @@ namespace PsychlopsSilverlight4test
 \r
 }\r
 \r
-*/\r
 \r
 \r
 \r
+/*\r
 using Psychlops;\r
 \r
 namespace Psychlops\r
@@ -224,7 +232,7 @@ namespace PsychlopsSilverlight4test
                        shape = poly;\r
 \r
                        var rng = new Interval();\r
-                       var slider = new Psychlops.Widgets.Slider("tesrt", 0 <= rng <= 5);\r
+                       var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);\r
 \r
                        dots = new RandomDots();\r
 \r
@@ -241,36 +249,37 @@ namespace PsychlopsSilverlight4test
                                {\r
                                        fixation.centering().shift(100, 100);\r
                                        fixation.draw(new Stroke(Color.blue, 3));\r
-                               }*/\r
+                               }* /\r
 \r
-                               fixation.centering();\r
+                               fixation.centering().shift(slider, 0);\r
                                fixation.draw(Color.red);\r
 \r
                                //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);\r
                                //Figures.drawGaussian(ref img, 20, 1);\r
                                //Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
-                               img.centering(Mouse.position);\r
-                               img.draw();\r
-                               //g.centering(Mouse.position).draw();\r
-                               //g.rotation += 1;\r
+                               //img.centering(Mouse.position);\r
+                               //img.draw();\r
+                               g.centering(Mouse.position).draw();\r
+                               g.rotation += 1;\r
 \r
                                shape.centering(Mouse.position).shift(100, 0);\r
                                shape.draw();\r
                                if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
 \r
                                cnvs.var(frames, 0, 20);\r
-                               slider.value = frames / 100.0;\r
+                               //slider.value = frames / 100.0;\r
 \r
                                /*if (frames % 2 != 0)\r
                                {\r
                                        fixation.shift(100, 100);\r
                                        fixation.draw(new Stroke(Color.green, 3));\r
-                               }*/\r
+                               }* /\r
 \r
                                for (int i = 0; i < dots.cood.Length; i++)\r
                                {\r
                                        dots.cood[i].set(Math.random(500), Math.random(500));\r
                                }\r
+                               cnvs.var((double)slider, 200, 200);\r
                                dots.draw();\r
 \r
                                cnvs.flip();\r
@@ -279,3 +288,45 @@ namespace PsychlopsSilverlight4test
        }\r
 }\r
 \r
+**/\r
+\r
+\r
+/*\r
+\r
+using Psychlops;\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+               Canvas cnvs;\r
+               Rectangle[] rect;\r
+               int n;\r
+\r
+               public void psychlops_main()\r
+               {\r
+                       n = 1;\r
+                       cnvs = new Canvas(500, 500);\r
+                       rect = new Rectangle[n];\r
+                       for (int i = 0; i < n; i++)\r
+                       {\r
+                               rect[i] = new Rectangle(10, 10);\r
+                               rect[i].fill = Color.red;\r
+                       }\r
+                       Interval rng = new Interval();\r
+                       var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);\r
+\r
+                       while (true)\r
+                       {\r
+                               cnvs.clear();\r
+                               for (int i = 0; i < n; i++)\r
+                               {\r
+                                       rect[i].centering().shift(slider * i*3, i*3).draw();\r
+                               }\r
+                               cnvs.flip();\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+*/
\ No newline at end of file