OSDN Git Service

flip ok
authorunknown <hskwk@.(none)>
Thu, 18 Mar 2010 22:11:40 +0000 (07:11 +0900)
committerunknown <hskwk@.(none)>
Thu, 18 Mar 2010 22:11:40 +0000 (07:11 +0900)
dev3/PsychlopsSilverlight3.csproj
dev3/psychlops/core/app/Class1.cs [deleted file]
dev3/psychlops/core/app/misc.cs [new file with mode: 0644]
dev3/psychlops/core/graphic/canvas.cs
test3/MainPage.xaml
test3/MainPage.xaml.cs
test3/PsychlopsMain.cs

index 1a4e533..362d30b 100644 (file)
@@ -51,7 +51,7 @@
   </ItemGroup>\r
   <ItemGroup>\r
     <Compile Include="Properties\AssemblyInfo.cs" />\r
-    <Compile Include="psychlops\core\app\Class1.cs" />\r
+    <Compile Include="psychlops\core\app\misc.cs" />\r
     <Compile Include="psychlops\core\device\hid.cs" />\r
     <Compile Include="psychlops\core\graphic\canvas.cs" />\r
     <Compile Include="psychlops\core\graphic\font.cs" />\r
diff --git a/dev3/psychlops/core/app/Class1.cs b/dev3/psychlops/core/app/Class1.cs
deleted file mode 100644 (file)
index d0069f7..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-\r
-\r
-namespace Psychlops\r
-{\r
-\r
-\r
-       public static class Main\r
-       {\r
-               public delegate void func();\r
-               public static Drawable drawable;\r
-       }\r
-\r
-\r
-}\r
diff --git a/dev3/psychlops/core/app/misc.cs b/dev3/psychlops/core/app/misc.cs
new file mode 100644 (file)
index 0000000..581af3d
--- /dev/null
@@ -0,0 +1,8 @@
+namespace Psychlops\r
+{\r
+\r
+       public static class Main\r
+       {\r
+               public static Drawable drawable;\r
+       }\r
+}\r
index 9653142..fcfd6e7 100644 (file)
@@ -15,14 +15,14 @@ namespace Psychlops
 \r
        public class Canvas : Drawable\r
        {\r
-               public static System.Windows.Controls.Image default_buffer_frame;\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
-               System.Windows.Controls.Image instance;\r
+               //WriteableBitmap buffer;\r
+               //System.Windows.Controls.Image instance;\r
                System.Windows.Controls.Canvas api_canvas;\r
                System.Windows.Controls.UserControl panel;\r
-               WriteableBitmap buffer;\r
                System.Windows.Shapes.Rectangle back_panel;\r
                System.Windows.Media.SolidColorBrush back_panel_color;\r
 \r
@@ -30,24 +30,25 @@ namespace Psychlops
                {\r
                        panel = default_panel;\r
                        api_canvas = default_api_canvas;\r
-                       instance = default_buffer_frame;\r
+                       //instance = default_buffer_frame;\r
                        initialize(wid, hei);\r
                }\r
-               public Canvas(int wid, int hei, System.Windows.Controls.Image target, System.Windows.Controls.Canvas apicnvs,  System.Windows.Controls.UserControl system)\r
+               public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs,  System.Windows.Controls.UserControl system)\r
                {\r
                        panel = system;\r
                        api_canvas = apicnvs;\r
-                       instance = target;\r
+                       //instance = target;\r
                        initialize(wid, hei);\r
                }\r
                protected void initialize(int wid, int hei)\r
                {\r
-                       instance.Width = wid;\r
-                       instance.Height = hei;\r
-                       instance.Source = buffer;\r
+                       //instance.Width = wid;\r
+                       //instance.Height = hei;\r
+                       //instance.Source = buffer;\r
+                       //buffer = new WriteableBitmap((int)instance.Width, (int)instance.Height);\r
+                       //default_buffer = buffer;\r
                        api_canvas.Width = wid;\r
                        api_canvas.Height = hei;\r
-                       buffer = new WriteableBitmap((int)instance.Width, (int)instance.Height);\r
                        api_canvas.MouseMove += Mouse.Canvas_MousePos;\r
                        api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
                        api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;\r
@@ -56,7 +57,6 @@ namespace Psychlops
                        panel.KeyUp += Keyboard.Canvas_KeyUp;\r
                        Mouse._prime = api_canvas;\r
                        Main.drawable = this;\r
-                       default_buffer = buffer;\r
 \r
                        back_panel = new System.Windows.Shapes.Rectangle();\r
                        back_panel.Width = wid;\r
@@ -66,12 +66,13 @@ namespace Psychlops
                }\r
                public Point getCenter()\r
                {\r
-                       return new Point(instance.Width/2.0, instance.Height/2.0, 0);\r
+                       return new Point(api_canvas.Width / 2.0, api_canvas.Height / 2.0, 0);\r
                }\r
 \r
                public void clear()\r
                {\r
-                       buffer.Clear(Color.black);\r
+                       //buffer.Clear(Color.black);\r
+                       clear(Color.black);\r
                }\r
                public void clear(Color col)\r
                {\r
@@ -83,9 +84,11 @@ namespace Psychlops
 \r
                public void pix(int x, int y, Color col)\r
                {\r
-                       buffer.SetPixel(x, y, col);\r
+                       //buffer.SetPixel(x, y, col);\r
                }\r
 \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
@@ -96,6 +99,7 @@ namespace Psychlops
                static System.Windows.Media.SolidColorBrush api_fill;\r
                static System.Windows.Media.SolidColorBrush api_stroke;\r
                static System.Windows.Media.TranslateTransform api_translation;\r
+               */\r
                protected static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;\r
                protected static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;\r
                protected static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;\r
@@ -114,6 +118,7 @@ namespace Psychlops
                        LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.TEXT_ALIGN_RIGHT, TextAlignment.Right);\r
                        LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.NOT_SPECIFIED, TextAlignment.Left);\r
 \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
@@ -124,7 +129,9 @@ namespace Psychlops
                        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
 \r
                public void line(Line drawee, Color col)\r
                {\r
@@ -238,16 +245,14 @@ namespace Psychlops
                public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }\r
 \r
 \r
-               public int frame;\r
                public void flip()\r
                {\r
-                       buffer.Invalidate();\r
-                       frame++;\r
+                       //buffer.Invalidate();\r
                }\r
 \r
                public double width { get { return api_canvas.Width; } }\r
                public double height { get { return api_canvas.Height; } }\r
-       }\r
 \r
+       }\r
 \r
 }
\ No newline at end of file
index 39b6ab9..1aef993 100644 (file)
@@ -2,8 +2,9 @@
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" \r
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\r
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" \r
-    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" x:Name="LayoutMain">\r
-  <Canvas x:Name="LayoutRoot">\r
-    <Image x:Name="main_buffer" Width="640" Height="480"/>\r
-  </Canvas>\r
+    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">\r
+    <StackPanel x:Name="TotalRoot" HorizontalAlignment="Center" VerticalAlignment="Center">\r
+        <Canvas x:Name="LayoutRoot"></Canvas>\r
+        <!--<Image x:Name="main_buffer" Width="640" Height="480"/>-->\r
+    </StackPanel>\r
 </UserControl>\r
index 89df586..dcfdd2d 100644 (file)
@@ -4,14 +4,17 @@ namespace PsychlopsSilverlight3test
 {\r
        public partial class MainPage : System.Windows.Controls.UserControl\r
        {\r
-               public System.ComponentModel.BackgroundWorker main_routine;\r
+               System.Collections.Generic.IEnumerator<int> main_routine;\r
                public System.Windows.Controls.Image master;\r
                public PsychlopsMain main;\r
+#if DEBUG\r
+               public System.Windows.Controls.TextBlock DebugConsole;\r
+#endif\r
                public MainPage()\r
                {\r
                        InitializeComponent();\r
                        // Show fps counter\r
-                       Canvas.default_buffer_frame = main_buffer;\r
+                       //Canvas.default_buffer_frame = main_buffer;\r
                        Canvas.default_api_canvas = LayoutRoot;\r
                        Canvas.default_panel = this;\r
                        this.IsTabStop = true;\r
@@ -25,51 +28,31 @@ namespace PsychlopsSilverlight3test
                        //main_routine.DoWork += new System.ComponentModel.DoWorkEventHandler(psychlops_main);\r
                        //main_routine.RunWorkerAsync();\r
 \r
-       \r
                        main = new PsychlopsMain();\r
-                       main.initialize();\r
+                       //main.initialize();\r
+                       //main_routine = new System.Threading.Thread(ThreadTest2);\r
+                       //main_routine.Start();\r
+                       main_routine = main.psychlops_main();\r
+#if DEBUG\r
+                       DebugConsole = new System.Windows.Controls.TextBlock();\r
+                       TotalRoot.Children.Add(DebugConsole);\r
+#endif\r
                }\r
-               protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e)\r
-               {\r
+               protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e) {\r
                        this.Focus();\r
                }\r
-               int background;\r
-               private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs args)\r
-               {\r
-                       while (true)\r
-                       {\r
-                               System.Threading.Thread.Sleep(10);\r
-                               background++;\r
-                       }\r
-               }\r
 \r
-               int frame;\r
+               int nextIntervalFrame = 1;\r
                private void CompositionTarget_Rendering(object sender, System.EventArgs e)\r
                {\r
-                       frame++;\r
-                       //Canvas.default_buffer.Invalidate();\r
-                       main.each_frames();\r
+                       nextIntervalFrame--;\r
+                       if (nextIntervalFrame<=0)\r
+                       {\r
+                               main_routine.MoveNext();\r
+                               nextIntervalFrame = main_routine.Current;\r
+                       }\r
                }\r
 \r
-               /*\r
-               Canvas cnvs;\r
-               Rectangle[] rects;\r
-               double tfreq = 1;\r
-\r
-               public void initialize()\r
-               {\r
-                       cnvs = new Canvas(500, 500, image, this);\r
-                       rects = new Rectangle[100];\r
-                       for (int i = 0; i < rects.Length; i++) { rects[i] = new Rectangle(10,10); }\r
-                       cnvs.clear(Color.gray);\r
-               }\r
-               public void trial()\r
-               {\r
-                       cnvs.clear(new Color(Mouse.left.pressed() ? 1.0 : 0.5));\r
-                       foreach (Rectangle rect in rects) { rect.centering().shift(background,0).draw(); }\r
-                       cnvs.flip();\r
-               }\r
-               */\r
        }\r
 }\r
 \r
index 64db8ce..fabaa51 100644 (file)
@@ -11,8 +11,9 @@ namespace PsychlopsSilverlight3test
                Color col;\r
                int isize = 100;\r
                double tfreq = 1;\r
+               int frames;\r
 \r
-               public void initialize()\r
+               public System.Collections.Generic.IEnumerator<int> psychlops_main()\r
                {\r
                        cnvs = new Canvas(500, 500);\r
                        img = new Image(isize * 2, isize * 2);\r
@@ -20,27 +21,31 @@ namespace PsychlopsSilverlight3test
                        var poly = new Letters("日本語");\r
                        shape = poly;\r
                        cnvs.clear(Color.gray);\r
-               }\r
 \r
-               public void each_frames()\r
-               {\r
-                       cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.25));\r
-                       col.set(Math.random(1.0));\r
+                       while(true) {\r
+                               frames++;\r
+                               \r
+                               cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.25));\r
+                               col.set(Math.random(1.0));\r
 \r
-                       fixation.centering();\r
-                       fixation.draw(Color.red);\r
+                               fixation.centering();\r
+                               fixation.draw(Color.red);\r
 \r
-                       Figures.drawGabor(ref img, 20, 10, 1, 0, cnvs.frame * 2.0 * Math.PI / tfreq / 60);\r
-                       //Figures.drawGaussian(ref img, 20, 1);\r
-                       //Figures.drawGrating(10, 1, 2, cnvs.frame * 2.0 * Math.PI / tfreq / 60);\r
-                       img.centering(Mouse.position);\r
-                       img.draw();\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(10, 1, 2, cnvs.frame * 2.0 * Math.PI / tfreq / 60);\r
+                               img.centering(Mouse.position);\r
+                               img.draw();\r
 \r
-                       shape.centering(Mouse.position);\r
-                       shape.draw(Color.red);\r
-                       if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
+                               shape.centering(Mouse.position);\r
+                               shape.draw(Color.red);\r
+                               if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
 \r
-                       cnvs.flip();\r
+                               cnvs.var(frames, 10, 20);\r
+\r
+                               yield return 3;\r
+                       }\r
                }\r
        }\r
+\r
 }\r