OSDN Git Service

image
[psychlops/silverlight.git] / dev4 / psychlops / core / graphic / canvas.cs
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