From 8d02b5d184f6209f65920c2e63bba907e2221f75 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 7 Aug 2010 00:11:02 +0900 Subject: [PATCH] 123 --- dev4/psychlops/core/graphic/canvas.cs | 143 +++++++++++++++++++++++----- dev4/psychlops/core/graphic/module.cs | 40 ++++++++ dev4/psychlops/extention/standard/widget.cs | 68 +++++++++++++ test4/MainPage.xaml | 2 +- test4/MainPage.xaml.cs | 3 +- test4/PsychlopsMain.cs | 50 +++------- 6 files changed, 243 insertions(+), 63 deletions(-) diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index d7388d3..282d67a 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -109,6 +109,10 @@ namespace Psychlops // stack.Enqueue(drawee.clone()); drawee.copyToStack(this); } + public virtual void group(Group drawee) + { + drawee.copyToStack(this); + } public void msg(string str, double x, double y) { msg(str, x, y, Color.white); } public virtual void msg(string dstr, double x, double y, Color col) @@ -198,6 +202,7 @@ namespace Psychlops back_panel = new Rectangle(wid, hei); flipexec = new SimpleProcedure(executeFlip); + AppState.statusBar = ""; } protected void initialize__(int wid, int hei) { @@ -248,10 +253,12 @@ namespace Psychlops 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; @@ -327,9 +334,9 @@ namespace Psychlops Internal.Main.canvas_flag.WaitOne(); } + #region version modifyNative public void executeFlip() { - #region version modifyNative Line lineS; Rectangle rectS; Ellipse ellipseS; @@ -342,7 +349,6 @@ namespace Psychlops System.Windows.Shapes.Polygon polygonP; System.Windows.Controls.TextBlock lettersP; System.Windows.Controls.Image imageP; - #endregion lock (this) { @@ -351,7 +357,6 @@ namespace Psychlops var en = masterPool.Children.GetEnumerator(); bool full = en.MoveNext(); - UIElementPoolN = 0; if (nextIntervalFrame <= 0) { if (chacked > 0) @@ -361,12 +366,6 @@ namespace Psychlops { for (int i = 0; i < stackN - 2; i++) { - 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)); @@ -375,7 +374,7 @@ namespace Psychlops { if( null != (rectS = stack[i] as Rectangle) ) { - if ( null != (rectP = en.Current as System.Windows.Shapes.Rectangle) ) + if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle)) { rectS.modifyNative(rectP, this); } @@ -417,8 +416,43 @@ namespace Psychlops } full = en.MoveNext(); } - * */ - #endregion + } + stackN = 0; + } + lock (this) + { + chacked = 0; + } + Psychlops.Internal.Main.canvas_flag.Set(); + } + } + System.Threading.Thread.Sleep(0); + } + #endregion + + /* + #region version poolNative 2 + public void executeFlip() + { + + lock (this) + { + nextIntervalFrame--; + } + UIElementPoolN = 0; + if (nextIntervalFrame <= 0) + { + if (chacked > 0) + { + //masterPool.Children.Clear(); + if (stackN > 0) + { + for (int i = 0; i < stackN - 2; i++) + { + UIElementPool[UIElementPoolN] = stack[i].poolNative(this); + UIElementPool[UIElementPoolN].Visibility = Visibility.Visible; + UIElementPoolN++; + } for (int i = stackN - 2; i < 10000; i++) { @@ -437,7 +471,8 @@ namespace Psychlops } System.Threading.Thread.Sleep(0); } - + #endregion + */ #region Properties @@ -652,7 +687,7 @@ namespace Psychlops tmp.Height = height; tmp.Fill = fill; System.Windows.Controls.Canvas.SetLeft(tmp, left); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); + System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; d.ellipsePoolN++; return tmp; @@ -663,7 +698,7 @@ namespace Psychlops tmp.Height = height; tmp.Fill = fill; System.Windows.Controls.Canvas.SetLeft(tmp, left); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); + System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; } } @@ -716,7 +751,7 @@ namespace Psychlops tmp.Points.Add(v); } System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; d.polygonPoolN++; return tmp; @@ -730,7 +765,7 @@ namespace Psychlops tmp.Points.Add(v); } System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; } @@ -814,7 +849,7 @@ namespace Psychlops 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); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; d.lettersPoolN++; return tmp; @@ -831,7 +866,7 @@ namespace Psychlops 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); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; } } @@ -898,22 +933,86 @@ namespace Psychlops var tmp = d.imagePool[d.imagePoolN]; tmp.Source = buffer; System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; 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); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; } } + + partial class Group + { + internal void initialize__() + { + Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.SimpleProcedure(create__)); + } + internal void create__() + { + cnvs = new System.Windows.Controls.Canvas(); + AsyncBool = true; + } + delegate void AppendFunc1(System.Func
func); + public void append__(Shape fig) + { + } + + public Group clone() + { + return (Group)MemberwiseClone(); + } + + public static implicit operator System.Windows.Controls.Canvas(Group d) + { + var tmp = new System.Windows.Controls.Canvas(); +/* foreach (var item in list) + { + tmp.Children.Add(d.); + } + System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y); +*/ return tmp; + } + public UIElement toNative() { return this; } + + public void copyToStack(Templates.StackableDrawable d) + { +/* var tmp = d.imageStack[d.imageStackN]; + tmp.datum = datum; + tmp.buffer = buffer; + tmp.self_rect = self_rect; + d.stack[d.stackN] = tmp; + d.imageStackN++; + d.stackN++; +*/ } + public UIElement poolNative(Canvas d) + { +/* var tmp = d.imagePool[d.imagePoolN]; + tmp.Source = buffer; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); + tmp.Visibility = Visibility.Visible; + d.imagePoolN++; +*/ return this; + } + public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d) + { +/* tmp.Source = buffer; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); + tmp.Visibility = Visibility.Visible; +*/ } + + } + #endregion diff --git a/dev4/psychlops/core/graphic/module.cs b/dev4/psychlops/core/graphic/module.cs index 85c49aa..a53a41a 100644 --- a/dev4/psychlops/core/graphic/module.cs +++ b/dev4/psychlops/core/graphic/module.cs @@ -96,6 +96,7 @@ namespace Psychlops void polygon(Polygon drawee); void letters(Letters drawee); void image(Image drawee); + void group(Group drawee); void msg(string s, double x, double y, Color c); } @@ -141,4 +142,43 @@ namespace Psychlops UIElement poolNative(Canvas c); } } + + public partial class Group : Internal.PrimitiveFigure + { + System.Collections.Generic.List
list; + System.Windows.Controls.Canvas cnvs; + bool AsyncBool; + public double rotation; + Point axis, scaling; + + public Group() + { + list = new System.Collections.Generic.List
(); + AsyncBool = false; + initialize__(); + while (!AsyncBool) { } + } + public Group append(Figure fig) + { + list.Add(fig); + return this; + } + + public Point datum { get; set; } + public Figure shift(Point p) + { + datum = datum + p; + return this; + } + public Figure centering(Point p) + { + datum = p; + return this; + } + public void draw() + { + Main.drawable.group(this); + } + } + } \ No newline at end of file diff --git a/dev4/psychlops/extention/standard/widget.cs b/dev4/psychlops/extention/standard/widget.cs index 49c7848..4fe21e7 100644 --- a/dev4/psychlops/extention/standard/widget.cs +++ b/dev4/psychlops/extention/standard/widget.cs @@ -15,8 +15,76 @@ using System.Windows.Browser; namespace Psychlops { + /* + class Widget : public Figure { + public: + class Event { + public: + }; + }; + * */ + namespace Widgets { + /* + struct Theme { + static bool initialized__; + static Image default_button, default_horiz_grad; + enum TYPE_TAG { NORMAL, ALERT }; + public: + Color normal_foreground[2], active_foreground[2]; + Color normal_background[2], active_background[2], over_background[2]; + Stroke normal_stroke[2], active_stroke[2]; + Image button_back, *horiz_grad; + + static Theme current; + static void initialize(); + }; + * */ + + /* + class WidgetRect : Widget + { + protected: + HumanInterfaceDevice::ButtonStateHolder mleft; + bool pushed_; + + public: + //Theme *theme; + //Theme::TYPE_TAG theme_type; + public Rectangle area; + public Letters label; + + public abstract WidgetRect(); + public virtual const Point getDatum() const; + public virtual WidgetRect& setDatum(const Point&); + public virtual WidgetRect& centering(const Point&); + public double getWidth() const; + public double getHeight() const; + public double getLeft() const; + public double getTop() const; + public double getRight() const; + public double getBottom() const; + public WidgetRect& alignLeft(const double lef); + public WidgetRect& alignTop(const double to_); + public WidgetRect& alignRight(const double rig); + public WidgetRect& alignBottom(const double bot); + + public virtual WidgetRect& set(double wid, double hei); + public virtual WidgetRect& set(std::wstring name); + public virtual WidgetRect& set(std::wstring name, double hei); + public virtual WidgetRect& setLabel(std::wstring s); + public virtual WidgetRect& draw(Drawable &target = *Drawable::prime); + public bool pushed(); + public WidgetRect& pushThis(); + }; + */ + /* + public class Slider + { + public Rectangle outer; + } + */ public class Slider { diff --git a/test4/MainPage.xaml b/test4/MainPage.xaml index 284d270..1cc8030 100644 --- a/test4/MainPage.xaml +++ b/test4/MainPage.xaml @@ -13,6 +13,6 @@ - Status OK + Loading... diff --git a/test4/MainPage.xaml.cs b/test4/MainPage.xaml.cs index 036c20d..a53999f 100644 --- a/test4/MainPage.xaml.cs +++ b/test4/MainPage.xaml.cs @@ -30,6 +30,7 @@ namespace PsychlopsSilverlight4test //main_routine.RunWorkerAsync(); main = new PsychlopsMain(); +// Psychlops.AppState.statusBar. Psychlops.Internal.Main.routine = new System.Threading.Thread(main.psychlops_main); Psychlops.Internal.Main.routine.Start(); //main.initialize(); @@ -37,7 +38,7 @@ namespace PsychlopsSilverlight4test Psychlops.Internal.Main.statusBar = AppStatusBar; Psychlops.Internal.Main.widgetStack = Controller; - AppStatusBar.Text = System.Windows.Application.Current.Host.Settings.EnableGPUAcceleration.ToString(); + AppStatusBar.Text = "Now starting Psychlops environment... please wait a minute"; } protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e) { this.Focus(); diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs index 3fd2ba9..d33eb14 100644 --- a/test4/PsychlopsMain.cs +++ b/test4/PsychlopsMain.cs @@ -1,17 +1,13 @@ - -/* -using Psychlops; +using Psychlops; namespace PsychlopsSilverlight4test { - public class PsychlopsMain { - Canvas cnvs; + Psychlops.Canvas cnvs; int i; - object xxx; double x, y, z, t, p, temp, xx, yy; //Set Target Initial Value @@ -19,29 +15,11 @@ namespace PsychlopsSilverlight4test //Set Background Initial Value double DotNumber = 50, thetaSpeed = 3.0, Axis = 0.0, BGRadii = 150, BGSize = 5.0; - Psychlops.Widgets.Slider DotNumberS; public void psychlops_main() { - //DotNumberS = new Psychlops.Widgets.Slider("test", new Interval(10, 500)); - //Independent ind = new Independent(); - cnvs = new Canvas(500, 500); - 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++) - { - for (int y = 0; y < 20; y++) - { -// img.pix(x, y, new Color(Math.sin(x + y))); - } - } - - //Declare background dots and target Rectangle[] BGDot = new Rectangle[2048]; for(int i=0; i<2048; i++){ @@ -78,7 +56,7 @@ namespace PsychlopsSilverlight4test for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize); double COS, SIN; - DotNumber = 100; + DotNumber = 200; //Main stimulus loop while(true){ //Clear the main window @@ -108,25 +86,21 @@ namespace PsychlopsSilverlight4test //Set Dotsize and Draw them BGDot[i].set(BGSize, BGSize); BGDot[i].centering().shift(xx,yy); - BGDot[i].draw( Color.blue); + BGDot[i].draw( Color.blue ); } //Calculate positions of targets and set them temp=Rotate*2*Math.PI/360.0; - cnvs.msg(TargetNumber.ToString(), 0, 30); for (int i = 0; i < 5; i++) { - cnvs.msg(i.ToString(), 50+50*i, 30); t = 2.0 * Math.PI/TargetNumber; - x = 10.0 * i;//TargetEcce*Math.cos(i*t+temp); - y = 10.0 * i;//TargetEcce*Math.sin(i*t+temp); + x = TargetEcce*Math.cos(i*t+temp); + y = TargetEcce*Math.sin(i*t+temp); Target[i].centering().shift(x,y); Target[i].fill = Color.yellow; Target[i].draw(); } - img.centering().draw(); - img2.centering().draw(); //Reflect drawing at the next frame; cnvs.flip(); } @@ -135,7 +109,6 @@ namespace PsychlopsSilverlight4test } - /* using Psychlops; @@ -183,11 +156,10 @@ namespace PsychlopsSilverlight4test } - - * - * */ +*/ +/* using Psychlops; namespace Psychlops @@ -216,7 +188,6 @@ namespace Psychlops - namespace PsychlopsSilverlight4test { @@ -265,7 +236,7 @@ namespace PsychlopsSilverlight4test //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60); //Figures.drawGaussian(ref img, 20, 1); - Figures.drawGrating(ref img, 30, 30, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60); + Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60); img.centering(Mouse.position); img.draw(); @@ -273,7 +244,7 @@ namespace PsychlopsSilverlight4test shape.draw(); if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100); - cnvs.var(frames, 20, 20); + cnvs.var(frames, 0, 20); slider.value = frames / 100.0; fixation.shift(100, 100); @@ -291,3 +262,4 @@ namespace PsychlopsSilverlight4test } } +*/ -- 2.11.0