From: HOSOKAWA Kenchi Date: Thu, 5 Aug 2010 02:59:40 +0000 (+0900) Subject: 123 X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=bf316c025ef4a9eb346bcedbcf37dd18ed04c6f4;hp=08ee5e41fb9be4360175fc4c31941306cc9f39e8;p=psychlops%2Fsilverlight.git 123 --- diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index e8d2af8..d7388d3 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -134,6 +134,10 @@ namespace Psychlops internal int pointPoolN; internal SolidColorBrush[] brushPool; internal int brushPoolN; + + internal System.Windows.UIElement[] UIElementPool; + internal int UIElementPoolN; + internal System.Windows.Shapes.Line[] linePool; internal int linePoolN; internal System.Windows.Shapes.Rectangle[] rectPool; @@ -184,9 +188,9 @@ namespace Psychlops width_ = wid; height_ = hei; api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei); - //while(!AsyncInitBool) - //{ - //} + while(!AsyncInitBool) + { + } Mouse._prime = api_canvas; Main.drawable = this; Main.canvas = this; @@ -212,7 +216,7 @@ namespace Psychlops htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px"); htmlHost.SetStyleAttribute("margin", "2em auto auto auto"); - + UIElementPool = new System.Windows.UIElement[10000]; pointPool = new System.Windows.Point[10000]; brushPool = new SolidColorBrush[10000]; linePool = new System.Windows.Shapes.Line[10000]; @@ -233,19 +237,23 @@ namespace Psychlops polygonPool[i] = new System.Windows.Shapes.Polygon(); lettersPool[i] = new System.Windows.Controls.TextBlock(); } - /* imagePool = new System.Windows.Controls.Image[100]; for (int i = 0; i < 100; i++) { imagePool[i] = new System.Windows.Controls.Image(); } - * */ masterPool = new System.Windows.Controls.Canvas(); prevPool = new System.Windows.Controls.Canvas(); api_canvas.Children.Add(masterPool); //api_canvas.Children.Remove(Internal.Main.widgetStack); + for (int i = 0; i < 10000; i++) + { + masterPool.Children.Add(UIElementPool[i]); + } + + AsyncInitBool = true; } @@ -299,10 +307,8 @@ namespace Psychlops nextIntervalFrame = 1; chacked = 1; } - // pointPoolN = 0; - // brushPoolN = 0; - linePoolN = 0; - rectPoolN = 0; + //pointStackN = 0; + //brushStackN = 0; lineStackN = 0; rectStackN = 0; polygonStackN = 0; @@ -323,20 +329,102 @@ namespace Psychlops } public void executeFlip() { + #region version modifyNative + Line lineS; + Rectangle rectS; + Ellipse ellipseS; + Polygon polygonS; + Letters lettersS; + Image imageS; + System.Windows.Shapes.Line lineP; + System.Windows.Shapes.Rectangle rectP; + System.Windows.Shapes.Ellipse ellipseP; + System.Windows.Shapes.Polygon polygonP; + System.Windows.Controls.TextBlock lettersP; + System.Windows.Controls.Image imageP; + #endregion + lock (this) { nextIntervalFrame--; } + + var en = masterPool.Children.GetEnumerator(); + bool full = en.MoveNext(); + UIElementPoolN = 0; if (nextIntervalFrame <= 0) { if (chacked > 0) { - masterPool.Children.Clear(); + //masterPool.Children.Clear(); if (stackN > 0) { for (int i = 0; i < stackN - 2; i++) { - masterPool.Children.Add(stack[i].poolNative(this)); + UIElementPool[UIElementPoolN] = stack[i].poolNative(this); + UIElementPool[UIElementPoolN].Visibility = Visibility.Visible; + UIElementPoolN++; + + #region version modifyNative + /* + if (full == false) + { + masterPool.Children.Add(stack[i].poolNative(this)); + } + else + { + if( null != (rectS = stack[i] as Rectangle) ) + { + if ( null != (rectP = en.Current as System.Windows.Shapes.Rectangle) ) + { + rectS.modifyNative(rectP, this); + } + } + else if (null != (lineS = stack[i] as Line)) + { + if (null != (lineP = en.Current as System.Windows.Shapes.Line)) + { + lineS.modifyNative(lineP, this); + } + } + else if (null != (ellipseS = stack[i] as Ellipse)) + { + if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse)) + { + ellipseS.modifyNative(ellipseP, this); + } + } + else if (null != (polygonS = stack[i] as Polygon)) + { + if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon)) + { + polygonS.modifyNative(polygonP, this); + } + } + else if (null != (lettersS = stack[i] as Letters)) + { + if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock)) + { + lettersS.modifyNative(lettersP, this); + } + } + else if (null != (imageS = stack[i] as Image)) + { + if (null != (imageP = en.Current as System.Windows.Controls.Image)) + { + imageS.modifyNative(imageP, this); + } + } + full = en.MoveNext(); + } + * */ + #endregion + } + for (int i = stackN - 2; i < 10000; i++) + { + UIElementPool[UIElementPoolN] = rectPool[i]; + UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed; + UIElementPoolN++; } stackN = 0; } @@ -454,6 +542,18 @@ namespace Psychlops d.linePoolN++; return tmp; } + public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d) + { + tmp.X1 = begin.x; + tmp.Y1 = begin.y; + tmp.X2 = end.x; + tmp.Y2 = end.y; + if (stroke.thick == 0.0) tmp.Stroke = fill; + else stroke.apply(tmp); + System.Windows.Controls.Canvas.SetLeft(tmp, left); + System.Windows.Controls.Canvas.SetTop(tmp, top); + tmp.Visibility = Visibility.Visible; + } } partial class Rectangle @@ -502,6 +602,15 @@ namespace Psychlops d.rectPoolN++; return tmp; } + public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d) + { + tmp.Width = width; + tmp.Height = height; + tmp.Fill = fill; + System.Windows.Controls.Canvas.SetLeft(tmp, left); + System.Windows.Controls.Canvas.SetTop(tmp, top); + tmp.Visibility = Visibility.Visible; + } } partial class Ellipse @@ -548,6 +657,15 @@ namespace Psychlops d.ellipsePoolN++; return tmp; } + public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d) + { + tmp.Width = width; + tmp.Height = height; + tmp.Fill = fill; + System.Windows.Controls.Canvas.SetLeft(tmp, left); + System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); + tmp.Visibility = Visibility.Visible; + } } partial class Polygon @@ -603,6 +721,18 @@ namespace Psychlops d.polygonPoolN++; return tmp; } + public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d) + { + tmp.Fill = fill; + tmp.Points.Clear(); + foreach (var v in vertices) + { + tmp.Points.Add(v); + } + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + tmp.Visibility = Visibility.Visible; + } } @@ -689,6 +819,21 @@ namespace Psychlops d.lettersPoolN++; return tmp; } + public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d) + { + tmp.Text = str; + tmp.Width = 500; + tmp.Height = 500; + tmp.FontSize = font.size; + //tmp.FontFamily = , + tmp.FontStyle = FONT_STYLE_BRIDGE[font.style]; + tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight]; + tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align]; + tmp.Foreground = fill; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + tmp.Visibility = Visibility.Visible; + } } partial class Image @@ -755,10 +900,17 @@ namespace Psychlops System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); tmp.Visibility = Visibility.Visible; - d.rectPoolN++; - throw new Exception("Image.poolNative"); + d.imagePoolN++; return this; } + public void modifyNative(System.Windows.Controls.Image tmp, Canvas d) + { + throw new Exception("Image.modifyNative"); + tmp.Source = buffer; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + tmp.Visibility = Visibility.Visible; + } } diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs index c808b11..adff3c4 100644 --- a/test4/PsychlopsMain.cs +++ b/test4/PsychlopsMain.cs @@ -20,14 +20,15 @@ namespace PsychlopsSilverlight4test public void psychlops_main() { - throw new System.Exception("Speed"); //DotNumberS = new Psychlops.Widgets.Slider("test", new Interval(10, 500)); //Independent ind = new Independent(); cnvs = new Canvas(500, 500); - //Image img = new Image(20, 20); - //img.field(delegate(int x, int y) { return new Color(Math.sin(x + y)); }); + Image img = new Image(100, 100); + img.field(delegate(int x, int y) { return new Color(0.5 + 0.5 * Math.sin(x + y)); }); + Image img2 = new Image(100, 100); + img2.field(delegate(int x, int y) { return new Color(0.5 + 0.5 * Math.sin(x + y)); }); /* for (int x = 0; x < 20; x++) { @@ -42,11 +43,11 @@ namespace PsychlopsSilverlight4test //Declare background dots and target Rectangle[] BGDot = new Rectangle[2048]; for(int i=0; i<2048; i++){ - BGDot[i]=new Rectangle(); + BGDot[i]=new Rectangle(); } Rectangle[] Target= new Rectangle[10]; for(int i=0; i<10; i++){ - Target[i]=new Rectangle(); + Target[i]=new Rectangle(); } @@ -60,75 +61,73 @@ namespace PsychlopsSilverlight4test //Initialize positions of background dots for(int i=0; i<2048; i++){ - t=2.0*Math.PI*Math.random(1.0); - p=2.0*Math.PI*Math.random(1.0); - DotX[i]=t; - DotY[i]=p; - - x=BGRadii*Math.cos(t)*Math.cos(p); - y=BGRadii*Math.sin(t)*Math.cos(p); - BGDot[i].set(BGSize, BGSize); - BGDot[i].centering().shift(x,y); + t=2.0*Math.PI*Math.random(1.0); + p=2.0*Math.PI*Math.random(1.0); + DotX[i]=t; + DotY[i]=p; + + x=BGRadii*Math.cos(t)*Math.cos(p); + y=BGRadii*Math.sin(t)*Math.cos(p); + BGDot[i].set(BGSize, BGSize); + BGDot[i].centering().shift(x,y); } //Initialize positions of targets for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize); double COS, SIN; - + DotNumber = 100; //Main stimulus loop while(true){ - //Clear the main window - cnvs.clear(Color.black); - - - temp=Axis/360*2*Math.PI; - COS=Math.cos(temp); - SIN=Math.sin(temp); - - //Calculate positions of background dots and set them - for(int i=0; i