OSDN Git Service

image
authorunknown <hskwk@.(none)>
Tue, 17 Aug 2010 21:57:14 +0000 (06:57 +0900)
committerunknown <hskwk@.(none)>
Tue, 17 Aug 2010 21:57:14 +0000 (06:57 +0900)
dev4/psychlops/core/graphic/canvas.cs
dev4/psychlops/core/graphic/image.cs
dev4/psychlops/extention/standard/widget.cs
test4/MainPage.xaml.cs
test4/PsychlopsMain.cs
test4/PsychlopsSilverlight4test.csproj
test4/Resources/logo.png [new file with mode: 0644]
test4/TestPage.html

index c64f7f5..536bf48 100644 (file)
@@ -9,6 +9,8 @@ using System.Windows.Media.Imaging;
 using System.Windows.Shapes;\r
 using System.Windows.Browser;\r
 \r
+using System.Collections.Generic;\r
+\r
 \r
 \r
 namespace Psychlops\r
@@ -16,10 +18,10 @@ namespace Psychlops
 \r
        internal static partial class CONST\r
        {\r
-               internal static readonly uint MAX_OBJ_N = 1500;\r
-               internal static readonly uint MOBJ_N = 1000;\r
-               internal static readonly uint COBJ_N = 300;\r
-               internal static readonly uint HOBJ_N = 100;\r
+               internal static readonly Int32 MAX_OBJ_N = 1500;\r
+               internal static readonly Int32 MOBJ_N = 1000;\r
+               internal static readonly Int32 COBJ_N = 300;\r
+               internal static readonly Int32 HOBJ_N = 100;\r
        }\r
 \r
        namespace Templates\r
@@ -126,6 +128,7 @@ namespace Psychlops
                internal int lettersPoolN;\r
                internal System.Windows.Controls.Image[] imagePool;\r
                internal int imagePoolN;\r
+               internal Dictionary<int, bool> imagePoolT;\r
                internal System.Windows.Controls.Canvas[] groupPool;\r
                internal int groupPoolN;\r
 \r
@@ -138,8 +141,8 @@ namespace Psychlops
                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.Canvas api_canvas;\r
-               System.Windows.Controls.UserControl panel;\r
+               internal System.Windows.Controls.Canvas api_canvas;\r
+               internal System.Windows.Controls.UserControl panel;\r
                Rectangle back_panel;\r
                double width_, height_;\r
                Clock before;\r
@@ -216,21 +219,26 @@ namespace Psychlops
                                lettersPool[i] = new System.Windows.Controls.TextBlock();\r
                        }\r
                        imagePool = new System.Windows.Controls.Image[CONST.HOBJ_N];\r
+                       imagePoolT = new Dictionary<int, bool>(CONST.HOBJ_N);\r
                        groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N];\r
                        for (int i = 0; i < CONST.HOBJ_N; i++)\r
                        {\r
                                imagePool[i] = new System.Windows.Controls.Image();\r
+                               imagePoolT.Add(imagePool[i].GetHashCode(), false);\r
                                groupPool[i] = new System.Windows.Controls.Canvas();\r
                        }\r
 \r
                        masterPool = new System.Windows.Controls.Canvas();\r
                        prevPool = new System.Windows.Controls.Canvas();\r
                        api_canvas.Children.Add(masterPool);\r
+\r
                        //api_canvas.Children.Remove(Internal.Main.widgetStack);\r
                        Psychlops.Internal.Main.widgetStack = new StackPanel();\r
                        Psychlops.Internal.Main.widgetStack.Orientation = Orientation.Vertical;\r
                        Psychlops.Internal.Main.widgetStack.Height = hei;\r
                        api_canvas.Children.Add(Psychlops.Internal.Main.widgetStack);\r
+                       \r
+\r
 \r
                        UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N];\r
                        dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N];\r
@@ -247,6 +255,16 @@ namespace Psychlops
                        AsyncInitBool = true;\r
                }\r
 \r
+               internal int findEmptyInPool(Dictionary<int, bool> pool)\r
+               {\r
+                       /*\r
+                       foreach( KeyValuePair<int, bool> elem in pool)\r
+                       {\r
+                               if(elem) \r
+                       }*/\r
+                       return 0;\r
+               }\r
+\r
                #endregion\r
 \r
                #region static initializer\r
@@ -625,6 +643,9 @@ namespace Psychlops
 \r
        #region primitive tokenizer\r
 \r
+\r
+       #region primitive\r
+\r
        partial struct Point\r
        {\r
                public static implicit operator System.Windows.Point(Point d)\r
@@ -673,6 +694,10 @@ namespace Psychlops
                        return tmp;\r
                }\r
        }\r
+       \r
+       #endregion\r
+       \r
+       #region Line\r
 \r
        partial class Line\r
        {\r
@@ -734,6 +759,10 @@ namespace Psychlops
                        tmp.Visibility = Visibility.Visible;\r
                }\r
        }\r
+       \r
+       #endregion\r
+               \r
+       #region Rectangle\r
 \r
        partial class Rectangle\r
        {\r
@@ -791,6 +820,10 @@ namespace Psychlops
                        tmp.Visibility = Visibility.Visible;\r
                }\r
        }\r
+       \r
+       #endregion\r
+\r
+       #region Ellipse\r
 \r
        partial class Ellipse\r
        {\r
@@ -847,6 +880,10 @@ namespace Psychlops
                }\r
        }\r
 \r
+       #endregion\r
+\r
+       #region Polygon\r
+\r
        partial class Polygon\r
        {\r
                public Polygon dup()\r
@@ -914,7 +951,11 @@ namespace Psychlops
                }\r
 \r
        }\r
-       \r
+               \r
+       #endregion\r
+\r
+       #region Letters\r
+\r
        partial class Letters\r
        {\r
                #region static initializer\r
@@ -1014,19 +1055,60 @@ namespace Psychlops
                        tmp.Visibility = Visibility.Visible;\r
                }\r
        }\r
+       \r
+       #endregion\r
+       \r
+       #region Image\r
 \r
        partial class Image\r
        {\r
                internal void initialize__(int wid, int hei)\r
                {\r
+                       AsyncBool = false;\r
                        Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei);\r
-                       //buffer = new WriteableBitmap(wid, hei);\r
+                       while (!AsyncBool) { System.Threading.Thread.Sleep(10); }\r
                }\r
                internal void create__(int wid, int hei)\r
                {\r
                        buffer = new WriteableBitmap(wid, hei);\r
                        AsyncBool = true;\r
                }\r
+               internal void load__(string uri)\r
+               {\r
+                       AsyncBool = false;\r
+                       var ur = new System.Uri(uri,  System.UriKind.RelativeOrAbsolute);\r
+                       Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action<Uri>(load_), ur);\r
+                       while (!AsyncBool) { System.Threading.Thread.Sleep(10); }\r
+               }\r
+               internal void load_(Uri uri)\r
+               {\r
+                       var bitmap = new BitmapImage();\r
+                       bitmap.CreateOptions = BitmapCreateOptions.None;\r
+                       bitmap.UriSource = uri;\r
+                       try\r
+                       {\r
+                               var wbm = new System.Windows.Media.Imaging.WriteableBitmap(bitmap);\r
+                               buffer = wbm;\r
+                       }\r
+                       catch (Exception e)\r
+                       {\r
+                               buffer = new WriteableBitmap(64, 64);\r
+                               buffer.ForEach(bitmap_drawChecker);\r
+                       }\r
+                       self_rect.set(buffer.PixelWidth, buffer.PixelHeight);\r
+                       AsyncBool = true;\r
+               }\r
+               static System.Windows.Media.Color[] CHECKER_C;\r
+               static Image()\r
+               {\r
+                       CHECKER_C = new System.Windows.Media.Color[2];\r
+                       CHECKER_C[0] = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);\r
+                       CHECKER_C[1] = System.Windows.Media.Color.FromArgb(128,128,128,128);\r
+               }\r
+               static System.Windows.Media.Color bitmap_drawChecker(int x, int y)\r
+               {\r
+                       return ((x / 4) + (y / 4)) % 2 == 0 ? CHECKER_C[0] : CHECKER_C[1];\r
+               }\r
                delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);\r
                delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);\r
                public void field__(System.Func<int, int, System.Windows.Media.Color> func)\r
@@ -1092,6 +1174,9 @@ namespace Psychlops
 \r
        }\r
 \r
+       #endregion\r
+\r
+       #region Group\r
 \r
        partial class Group\r
        {\r
@@ -1173,6 +1258,7 @@ namespace Psychlops
                }\r
 \r
        }\r
+       #endregion\r
        \r
        #endregion\r
 \r
index 4c775ae..f4c48d9 100644 (file)
@@ -21,12 +21,23 @@ namespace Psychlops{
                public Rectangle self_rect;\r
                protected bool AsyncBool;\r
 \r
+               public Image(string uri)\r
+               {\r
+                       self_rect = new Rectangle();\r
+                       load__(uri);\r
+               }\r
+\r
                public Image(int wid, int hei)\r
                {\r
-                       AsyncBool = false;\r
+                       self_rect = new Rectangle(wid, hei);\r
                        initialize__(wid, hei);\r
+               }\r
+\r
+               public Image set(int wid, int hei)\r
+               {\r
                        self_rect = new Rectangle(wid, hei);\r
-                       while (!AsyncBool) { }\r
+                       initialize__(wid, hei);\r
+                       return this;\r
                }\r
 \r
                public Figure shift(Point p)\r
@@ -53,26 +64,23 @@ namespace Psychlops{
                public void field(System.Func<int, int, System.Windows.Media.Color> func)\r
                {\r
                        field__(func);\r
-                       //buffer.ForEach(func);\r
                }\r
                public void field(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
                {\r
                        field__(func);\r
-                       //buffer.ForEach(func);\r
                }\r
                public void each(System.Func<int, int, System.Windows.Media.Color> func)\r
                {\r
                        field__(func);\r
-                       //buffer.ForEach(func);\r
                }\r
                public void each(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
                {\r
                        field__(func);\r
-                       //buffer.ForEach(func);\r
                }\r
 \r
-               public void load()\r
+               public void load(string uri)\r
                {\r
+                       load__(uri);\r
                }\r
 \r
                public void draw()\r
index 9d5a71c..20cbfa3 100644 (file)
@@ -8,6 +8,7 @@ using System.Windows.Media.Animation;
 using System.Windows.Media.Imaging;\r
 using System.Windows.Shapes;\r
 using System.Windows.Browser;\r
+using System.Windows.Data;\r
 \r
 \r
 \r
@@ -256,8 +257,30 @@ namespace Psychlops
                {\r
                        internal delegate void VoidString(string s);\r
                        internal delegate void VoidStringObject(String s, System.Object o);\r
-                       \r
 \r
+                       public class Double02fFormatter : IValueConverter\r
+                       {\r
+                               public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)\r
+                               {\r
+                                       string formatString = parameter as string;\r
+                                       if (!string.IsNullOrEmpty(formatString))\r
+                                       {\r
+                                               return string.Format(culture, formatString, value);\r
+                                       }\r
+                                       return string.Format("{0, -8:F}", value);\r
+                               }\r
+                               public object ConvertBack(object val, Type targetType, object parameter, System.Globalization.CultureInfo culture)\r
+                               {\r
+                                       string str = val.ToString();\r
+                                       double result;\r
+                                       var objCultureInfo = new System.Globalization.CultureInfo("en-US");\r
+                                       if (Double.TryParse(str, System.Globalization.NumberStyles.Number, objCultureInfo, out result))\r
+                                       {\r
+                                               return result;\r
+                                       }\r
+                                       return val;\r
+                               }\r
+                       }\r
 \r
                        delegate void StackSlider_(Slider s);\r
                        internal static void stackSlider(Slider s)\r
@@ -286,6 +309,7 @@ namespace Psychlops
                                                Path = new PropertyPath("Value"),\r
                                                Mode = System.Windows.Data.BindingMode.TwoWay,\r
                                                Source = slide,\r
+                                               Converter = new Double02fFormatter()\r
                                };\r
                                val.SetBinding(TextBox.TextProperty, b);\r
                                ss.uislider = slide;\r
@@ -293,6 +317,7 @@ namespace Psychlops
                                val.Background = Color.null_color;\r
                                val.BorderBrush = Color.null_color;\r
                                val.Foreground = Color.white;\r
+                               val.TextAlignment = TextAlignment.Right;\r
 \r
                                holder.Background = Slider.bgcolor;\r
 \r
index 0889ace..cfe5cf5 100644 (file)
@@ -40,6 +40,15 @@ namespace PsychlopsSilverlight4test
                        Psychlops.Internal.Main.statusBar = AppStatusBar;\r
                        //Psychlops.Internal.Main.widgetStack = Controller;\r
                        AppStatusBar.Text = "Now starting Psychlops environment... please wait a minute";\r
+\r
+\r
+                       var ur = new System.Uri("Resources/logo.png", System.UriKind.RelativeOrAbsolute);\r
+                       var bitmap = new System.Windows.Media.Imaging.BitmapImage(ur);\r
+                       var img = new System.Windows.Controls.Image();\r
+                       img.Source = bitmap;\r
+                       System.Windows.Controls.Canvas.SetLeft(img, 100);\r
+                       System.Windows.Controls.Canvas.SetTop(img, 100);\r
+                       LayoutRoot.Children.Add(img);\r
                }\r
                protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e) {\r
                        this.Focus();\r
index 2794969..b93f0d8 100644 (file)
@@ -16,15 +16,19 @@ namespace PsychlopsSilverlight4test
                //Set Background Initial Value\r
                double Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
                Psychlops.Widgets.Slider thetaSpeed, DotNumber;\r
+               Image img;\r
 \r
 \r
 \r
                public void psychlops_main()\r
-               {       \r
+               {\r
                        cnvs = new Canvas(500, 500);\r
 \r
+\r
+                       img = new Image("Resources/logo.png");\r
+\r
                        Interval rng = new Interval();\r
-                       thetaSpeed = new Psychlops.Widgets.Slider("Label" , -10 <= rng <= 10,   3.0);\r
+                       thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);\r
                        DotNumber  = new Psychlops.Widgets.Slider("DotNum",   0 <= rng <= 100, 50.0);\r
 \r
                        //Declare background dots and target\r
@@ -108,6 +112,11 @@ namespace PsychlopsSilverlight4test
                                        Target[i].draw();\r
                                }\r
 \r
+                               img.centering(Mouse.position).draw();\r
+\r
+                               cnvs.var(Mouse.position.x, 100, 100);\r
+                               cnvs.var(Mouse.position.y, 100, 140);\r
+\r
                                //Reflect drawing at the next frame;\r
                                cnvs.flip();\r
                        }\r
index 5b49ffc..2d534ea 100644 (file)
     <None Include="Properties\AppManifest.xml" />\r
   </ItemGroup>\r
   <ItemGroup>\r
+    <Resource Include="Resources\logo.png" />\r
     <Content Include="TestPage.html" />\r
   </ItemGroup>\r
   <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />\r
diff --git a/test4/Resources/logo.png b/test4/Resources/logo.png
new file mode 100644 (file)
index 0000000..ebdc130
Binary files /dev/null and b/test4/Resources/logo.png differ
index 1bcd588..23aee1f 100644 (file)
 \r
     <form id="form1" runat="server" style="height:60%">\r
     <div id="silverlightControlHost">\r
-        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="90%" height="80%">\r
+        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">\r
                  <param name="source" value="Bin/Debug/PsychlopsSilverlight4test.xap"/>\r
                  <param name="onError" value="onSilverlightError" />\r
                  <param name="background" value="white" />\r
                  <param name="minRuntimeVersion" value="3.0.40624.0" />\r
                  <param name="autoUpgrade" value="true" />\r
                  <param name="enableHtmlAccess" value="true" />\r
-                 <param name="enableGPUAcceleration" value="true" />\r
+                 <param name="enableGPUAcceleration" value="false" />\r
                  <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">\r
                          <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Microsoft Silverlight を入手" style="border-style:none"/>\r
                  </a>\r