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