OSDN Git Service

321
authorunknown <hskwk@.(none)>
Fri, 12 Mar 2010 14:47:28 +0000 (23:47 +0900)
committerunknown <hskwk@.(none)>
Fri, 12 Mar 2010 14:47:28 +0000 (23:47 +0900)
dev3/psychlops/core/graphic/canvas.cs
dev3/psychlops/core/graphic/shape.cs
test3/MainPage.xaml
test3/MainPage.xaml.cs
test3/PsychlopsMain.cs [new file with mode: 0644]
test3/PsychlopsSilverlight3test.csproj

index 8dd4753..4414a24 100644 (file)
@@ -15,9 +15,9 @@ namespace Psychlops
 \r
        public class Canvas : Drawable\r
        {\r
-               public static System.Windows.Controls.Image default_instance;\r
+               public static System.Windows.Controls.Image default_buffer_frame;\r
                public static System.Windows.Controls.UserControl default_panel;\r
-               public static WriteableBitmap default_buffer; \r
+               public static WriteableBitmap default_buffer;\r
                System.Windows.Controls.Image instance;\r
                System.Windows.Controls.UserControl panel; \r
                WriteableBitmap buffer;\r
@@ -25,27 +25,20 @@ namespace Psychlops
                public Canvas(int wid, int hei)\r
                {\r
                        panel = default_panel;\r
-                       instance = default_instance;\r
-                       instance.Width = wid;\r
-                       instance.Height = hei;\r
-                       buffer = new WriteableBitmap((int)instance.Width, (int)instance.Height);\r
-                       instance.Source = buffer;\r
-                       instance.MouseMove += Mouse.Canvas_MousePos;\r
-                       instance.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
-                       instance.MouseLeftButtonUp += Mouse.Canvas_LUp;\r
-                       instance.MouseWheel += Mouse.Canvas_MouseWheel;\r
-                       Mouse._prime = instance;\r
-                       Main.drawable = this;\r
-                       default_buffer = buffer;\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.UserControl system)\r
                {\r
                        panel = system;\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
                        buffer = new WriteableBitmap((int)instance.Width, (int)instance.Height);\r
-                       instance = target;\r
                        instance.Source = buffer;\r
                        instance.MouseMove += Mouse.Canvas_MousePos;\r
                        instance.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
@@ -53,6 +46,7 @@ namespace Psychlops
                        instance.MouseWheel += Mouse.Canvas_MouseWheel;\r
                        Mouse._prime = instance;\r
                        Main.drawable = this;\r
+                       default_buffer = buffer;\r
                }\r
                public Point getCenter()\r
                {\r
@@ -73,6 +67,29 @@ namespace Psychlops
                        buffer.SetPixel(x, y, col);\r
                }\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
                public void line(Line drawee, Color col)\r
                {\r
@@ -80,7 +97,14 @@ namespace Psychlops
                }\r
                public void rect(Rectangle drawee, Color col)\r
                {\r
-                       buffer.DrawRectangle((int)drawee.v1.x, (int)drawee.v1.y, (int)drawee.v2.x, (int)drawee.v2.y, col);\r
+                       //buffer.DrawRectangle((int)drawee.v1.x, (int)drawee.v1.y, (int)drawee.v2.x, (int)drawee.v2.y, col);\r
+                       api_rect.Width = drawee.width;\r
+                       api_rect.Height = drawee.height;\r
+                       api_fill.Color = col;\r
+                       api_rect.Fill = api_fill;\r
+                       api_translation.X = drawee.left;\r
+                       api_translation.Y = drawee.top;\r
+                       buffer.Render(api_rect, api_translation);\r
                }\r
                public void ellipse(Ellipse drawee, Color col)\r
                {\r
@@ -103,9 +127,11 @@ namespace Psychlops
                }\r
 \r
 \r
+               public int frame;\r
                public void flip()\r
                {\r
                        buffer.Invalidate();\r
+                       frame++;\r
                }\r
        }\r
 \r
index 71f33cb..ffefeea 100644 (file)
@@ -121,6 +121,10 @@ namespace Psychlops{
                        Main.drawable.rect(this, Color.white);\r
                }\r
 \r
+               public double left   { get { return v1.x; } }\r
+               public double top    { get { return v1.y; } }\r
+               public double right  { get { return v2.x; } }\r
+               public double bottom { get { return v2.y; } }\r
                public double width { get { return Math.abs(v1.x - v2.x); } }\r
                public double height { get { return Math.abs(v1.y - v2.y); } }\r
 \r
index 1f1bbde..58409bd 100644 (file)
@@ -4,6 +4,6 @@
     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">\r
   <Grid x:Name="LayoutRoot">\r
-    <Image x:Name="image" Width="640" Height="480"/>\r
+    <Image x:Name="main_buffer" Width="640" Height="480"/>\r
   </Grid>\r
 </UserControl>\r
index d06eb7a..b61a607 100644 (file)
@@ -6,12 +6,13 @@ namespace PsychlopsSilverlight3test
        {\r
                public System.ComponentModel.BackgroundWorker main_routine;\r
                public System.Windows.Controls.Image master;\r
+               public PsychlopsMain main;\r
                public MainPage()\r
                {\r
                        InitializeComponent();\r
-                       initialize();\r
                        // Show fps counter\r
-                       Canvas.default_instance = image;\r
+                       Canvas.default_buffer_frame = main_buffer;\r
+                       Canvas.default_panel = this;\r
                        System.Windows.Application.Current.Host.Settings.MaxFrameRate = 60;\r
                        System.Windows.Application.Current.Host.Settings.EnableFrameRateCounter = true;\r
                        System.Windows.Application.Current.Host.Settings.EnableCacheVisualization = true;\r
@@ -19,6 +20,10 @@ namespace PsychlopsSilverlight3test
                        //main_routine =  new System.ComponentModel.BackgroundWorker();\r
                        //main_routine.DoWork += new System.ComponentModel.DoWorkEventHandler(psychlops_main);\r
                        //main_routine.RunWorkerAsync();\r
+\r
+       \r
+                       main = new PsychlopsMain();\r
+                       main.initialize();\r
                }\r
                int background;\r
                private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs args)\r
@@ -35,30 +40,9 @@ namespace PsychlopsSilverlight3test
                {\r
                        frame++;\r
                        //Canvas.default_buffer.Invalidate();\r
-                       trial();\r
+                       main.each_frames();\r
                }\r
 \r
-               Canvas cnvs;\r
-               Image img;\r
-               int isize = 100;\r
-               double tfreq = 1;\r
-               public void initialize()\r
-               {\r
-                       cnvs = new Canvas(500, 500, image, this);\r
-                       img = new Image(isize*2, isize*2);\r
-                       cnvs.clear(Color.gray);\r
-               }\r
-               public void trial()\r
-               {\r
-                       cnvs.clear(new Color(Mouse.left.pressed() ? 1.0 : 0.5));\r
-                       img.field(\r
-                               (x, y) => new Color(.5 + Math.gaussian(Math.radius(x - isize, y - isize), isize / 8.0) * .5 * Math.sin(frame*2*Math.PI/tfreq/60 + x / 3.0))\r
-                                       );\r
-                       img.centering(Mouse.position);\r
-                       //img.shift(1,0);\r
-                       img.draw();\r
-                       cnvs.flip();\r
-               }\r
                /*\r
                Canvas cnvs;\r
                Rectangle[] rects;\r
diff --git a/test3/PsychlopsMain.cs b/test3/PsychlopsMain.cs
new file mode 100644 (file)
index 0000000..829afbd
--- /dev/null
@@ -0,0 +1,35 @@
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlight3test\r
+{\r
+       public class PsychlopsMain\r
+       {\r
+               Canvas cnvs;\r
+               Image img;\r
+               Rectangle fixation;\r
+               int isize = 100;\r
+               double tfreq = 1;\r
+\r
+               public void initialize()\r
+               {\r
+                       cnvs = new Canvas(500, 500);\r
+                       img = new Image(isize * 2, isize * 2);\r
+                       fixation = new Rectangle(10, 10);\r
+                       cnvs.clear(Color.gray);\r
+               }\r
+\r
+               public void each_frames()\r
+               {\r
+                       cnvs.clear(new Color(Mouse.left.pressed() ? 1.0 : 0.5));\r
+                       img.field(\r
+                               (x, y) => new Color(.5 + Math.gaussian(Math.radius(x - isize, y - isize), isize / 8.0) * .5 * Math.sin(cnvs.frame * 2 * Math.PI / tfreq / 60 + x / 3.0))\r
+                                       );\r
+                       img.centering(Mouse.position);\r
+                       //img.shift(1,0);\r
+                       img.draw();\r
+                       fixation.centering();\r
+                       fixation.draw(Color.red);\r
+                       cnvs.flip();\r
+               }\r
+       }\r
+}\r
index a2ef5ef..48a3682 100644 (file)
@@ -66,6 +66,7 @@
     <Compile Include="App.xaml.cs">\r
       <DependentUpon>App.xaml</DependentUpon>\r
     </Compile>\r
+    <Compile Include="PsychlopsMain.cs" />\r
     <Compile Include="MainPage.xaml.cs">\r
       <DependentUpon>MainPage.xaml</DependentUpon>\r
     </Compile>\r