OSDN Git Service

536bf4844315c50ff9743ef6f123bfe0baad7f6f
[psychlops/silverlight.git] / dev4 / psychlops / core / graphic / canvas.cs
1 using System;\r
2 using System.Windows;\r
3 using System.Windows.Controls;\r
4 using System.Windows.Documents;\r
5 using System.Windows.Input;\r
6 using System.Windows.Media;\r
7 using System.Windows.Media.Animation;\r
8 using System.Windows.Media.Imaging;\r
9 using System.Windows.Shapes;\r
10 using System.Windows.Browser;\r
11 \r
12 using System.Collections.Generic;\r
13 \r
14 \r
15 \r
16 namespace Psychlops\r
17 {\r
18 \r
19         internal static partial class CONST\r
20         {\r
21                 internal static readonly Int32 MAX_OBJ_N = 1500;\r
22                 internal static readonly Int32 MOBJ_N = 1000;\r
23                 internal static readonly Int32 COBJ_N = 300;\r
24                 internal static readonly Int32 HOBJ_N = 100;\r
25         }\r
26 \r
27         namespace Templates\r
28         {\r
29 \r
30                 public class StackableDrawable : Drawable\r
31                 {\r
32 //                      protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
33                         internal Internal.PrimitiveFigure[] stack;\r
34                         internal int stackN;\r
35                         internal Line[] lineStack;\r
36                         internal int lineStackN;\r
37                         internal Rectangle[] rectStack;\r
38                         internal int rectStackN;\r
39                         internal Ellipse[] ellipseStack;\r
40                         internal int ellipseStackN;\r
41                         internal Polygon[] polygonStack;\r
42                         internal int polygonStackN;\r
43                         internal Letters[] lettersStack;\r
44                         internal int lettersStackN;\r
45                         internal Image[] imageStack;\r
46                         internal int imageStackN;\r
47                         internal Group[] groupStack;\r
48                         internal int groupStackN;\r
49 \r
50 \r
51                         public StackableDrawable()\r
52                         {\r
53                                 stack = new Internal.PrimitiveFigure[CONST.MAX_OBJ_N];\r
54                                 lineStack = new Line[CONST.MOBJ_N];\r
55                                 rectStack = new Rectangle[CONST.MOBJ_N];\r
56                                 ellipseStack = new Ellipse[CONST.MOBJ_N];\r
57                                 polygonStack = new Polygon[CONST.COBJ_N];\r
58                                 lettersStack = new Letters[CONST.COBJ_N];\r
59                                 imageStack = new Image[CONST.HOBJ_N];\r
60                                 groupStack = new Group[CONST.HOBJ_N];\r
61                                 for (int i = 0; i < CONST.MOBJ_N; i++)\r
62                                 {\r
63                                         lineStack[i] = new Line(0,0,0,0);\r
64                                         rectStack[i] = new Rectangle();\r
65                                         ellipseStack[i] = new Ellipse();\r
66                                 }\r
67                                 for (int i = 0; i < CONST.COBJ_N; i++)\r
68                                 {\r
69                                         polygonStack[i] = new Polygon();\r
70                                         lettersStack[i] = new Letters();\r
71                                 }\r
72                                 for (int i = 0; i < CONST.HOBJ_N; i++)\r
73                                 {\r
74                                         imageStack[i] = new Image(1, 1);\r
75                                         groupStack[i] = new Group();\r
76                                 }\r
77                         }\r
78 \r
79                         public void clear() { clear(Color.black); }\r
80                         public virtual void clear(Color col) { } //rect(back_panel, col); }\r
81                         public virtual void pix(int x, int y, Color col) { }\r
82                         public virtual void line(Line drawee) { drawee.copyToStack(this); }\r
83                         public virtual void rect(Rectangle drawee) { drawee.copyToStack(this); }\r
84                         public virtual void ellipse(Ellipse drawee) { drawee.copyToStack(this); }\r
85                         public virtual void polygon(Polygon drawee) { drawee.copyToStack(this); }\r
86                         public virtual void letters(Letters drawee) { drawee.copyToStack(this); }\r
87                         public virtual void image(Image drawee) { drawee.copyToStack(this); }\r
88                         public virtual void group(Group drawee) { drawee.copyToStack(this); }\r
89 \r
90                         public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
91                         public virtual void msg(string dstr, double x, double y, Color col)\r
92                         {\r
93                                 var let = new Letters(dstr);\r
94                                 let.locate(x, y);\r
95                                 let.fill = col;\r
96                                 this.letters(let);\r
97                         }\r
98                         public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }\r
99                         public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }\r
100 \r
101                         public virtual Point getCenter() { return new Point(0, 0, 0); }\r
102                 }\r
103 \r
104         }\r
105 \r
106         public class Canvas : Templates.StackableDrawable\r
107         {\r
108                 internal System.Windows.Controls.Canvas masterPool, prevPool;\r
109                 internal System.Windows.Point[] pointPool;\r
110                 internal int pointPoolN;\r
111                 internal SolidColorBrush[] brushPool;\r
112                 internal int brushPoolN;\r
113 \r
114                 internal System.Windows.Controls.Canvas[] UIElementPool;\r
115                 internal int UIElementPoolN;\r
116                 internal int lastVisibleN;\r
117 \r
118                 internal System.Windows.Shapes.Line[] linePool;\r
119                 internal int linePoolN;\r
120                 internal System.Windows.Shapes.Rectangle[] dummyRectPool;\r
121                 internal System.Windows.Shapes.Rectangle[] rectPool;\r
122                 internal int rectPoolN;\r
123                 internal System.Windows.Shapes.Ellipse[] ellipsePool;\r
124                 internal int ellipsePoolN;\r
125                 internal System.Windows.Shapes.Polygon[] polygonPool;\r
126                 internal int polygonPoolN;\r
127                 internal System.Windows.Controls.TextBlock[] lettersPool;\r
128                 internal int lettersPoolN;\r
129                 internal System.Windows.Controls.Image[] imagePool;\r
130                 internal int imagePoolN;\r
131                 internal Dictionary<int, bool> imagePoolT;\r
132                 internal System.Windows.Controls.Canvas[] groupPool;\r
133                 internal int groupPoolN;\r
134 \r
135                 #region initializer\r
136 \r
137                 internal delegate void TwoIntProcedure(int x, int y);\r
138                 internal delegate void SimpleProcedure();\r
139                 SimpleProcedure flipexec;\r
140 \r
141                 public static System.Windows.Controls.UserControl default_panel;\r
142                 public static System.Windows.Controls.Canvas default_api_canvas;\r
143                 public static WriteableBitmap default_buffer;\r
144                 internal System.Windows.Controls.Canvas api_canvas;\r
145                 internal System.Windows.Controls.UserControl panel;\r
146                 Rectangle back_panel;\r
147                 double width_, height_;\r
148                 Clock before;\r
149 \r
150                 public Canvas(int wid, int hei)\r
151                 {\r
152                         panel = default_panel;\r
153                         api_canvas = default_api_canvas;\r
154                         initialize(wid, hei);\r
155                 }\r
156                 public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs, System.Windows.Controls.UserControl system)\r
157                 {\r
158                         panel = system;\r
159                         api_canvas = apicnvs;\r
160                         initialize(wid, hei);\r
161                 }\r
162 \r
163                 protected bool AsyncInitBool;\r
164                 protected void initialize(int wid, int hei)\r
165                 {\r
166                         before = new Clock();\r
167                         before.update();\r
168                         AsyncInitBool = false;\r
169                         width_ = wid;\r
170                         height_ = hei;\r
171                         api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);\r
172                         while(!AsyncInitBool)\r
173                         {\r
174                         }\r
175                         Mouse._prime = api_canvas;\r
176                         Main.drawable = this;\r
177                         Main.canvas = this;\r
178 \r
179                         back_panel = new Rectangle(wid, hei);\r
180 \r
181                         flipexec = new SimpleProcedure(executeFlip);\r
182                         AppState.statusBar = "";\r
183                 }\r
184                 protected void initialize__(int wid, int hei)\r
185                 {\r
186                         api_canvas.Width = wid;\r
187                         api_canvas.Height = hei+20;\r
188                         api_canvas.MouseMove += Mouse.Canvas_MousePos;\r
189                         api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
190                         api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;\r
191                         api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;\r
192                         panel.KeyDown += Keyboard.Canvas_KeyDown;\r
193                         panel.KeyUp += Keyboard.Canvas_KeyUp;\r
194 \r
195                         HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");\r
196                         //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");\r
197                         htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");\r
198                         htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px");\r
199                         htmlHost.SetStyleAttribute("margin", "2em auto auto auto");\r
200 \r
201                         pointPool = new System.Windows.Point[CONST.MOBJ_N];\r
202                         brushPool = new SolidColorBrush[CONST.MOBJ_N];\r
203                         linePool = new System.Windows.Shapes.Line[CONST.MOBJ_N];\r
204                         rectPool = new System.Windows.Shapes.Rectangle[CONST.MOBJ_N];\r
205                         ellipsePool = new System.Windows.Shapes.Ellipse[CONST.MOBJ_N];\r
206                         for (int i = 0; i < CONST.MOBJ_N; i++)\r
207                         {\r
208                                 pointPool[i] = new System.Windows.Point();\r
209                                 brushPool[i] = new SolidColorBrush();\r
210                                 linePool[i] = new System.Windows.Shapes.Line();\r
211                                 rectPool[i] = new System.Windows.Shapes.Rectangle();\r
212                                 ellipsePool[i] = new System.Windows.Shapes.Ellipse();\r
213                         }\r
214                         polygonPool = new System.Windows.Shapes.Polygon[CONST.COBJ_N];\r
215                         lettersPool = new System.Windows.Controls.TextBlock[CONST.COBJ_N];\r
216                         for (int i = 0; i < CONST.COBJ_N; i++)\r
217                         {\r
218                                 polygonPool[i] = new System.Windows.Shapes.Polygon();\r
219                                 lettersPool[i] = new System.Windows.Controls.TextBlock();\r
220                         }\r
221                         imagePool = new System.Windows.Controls.Image[CONST.HOBJ_N];\r
222                         imagePoolT = new Dictionary<int, bool>(CONST.HOBJ_N);\r
223                         groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N];\r
224                         for (int i = 0; i < CONST.HOBJ_N; i++)\r
225                         {\r
226                                 imagePool[i] = new System.Windows.Controls.Image();\r
227                                 imagePoolT.Add(imagePool[i].GetHashCode(), false);\r
228                                 groupPool[i] = new System.Windows.Controls.Canvas();\r
229                         }\r
230 \r
231                         masterPool = new System.Windows.Controls.Canvas();\r
232                         prevPool = new System.Windows.Controls.Canvas();\r
233                         api_canvas.Children.Add(masterPool);\r
234 \r
235                         //api_canvas.Children.Remove(Internal.Main.widgetStack);\r
236                         Psychlops.Internal.Main.widgetStack = new StackPanel();\r
237                         Psychlops.Internal.Main.widgetStack.Orientation = Orientation.Vertical;\r
238                         Psychlops.Internal.Main.widgetStack.Height = hei;\r
239                         api_canvas.Children.Add(Psychlops.Internal.Main.widgetStack);\r
240                         \r
241 \r
242 \r
243                         UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N];\r
244                         dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N];\r
245                         for (int i = 0; i < CONST.MAX_OBJ_N; i++)\r
246                         {\r
247                                 UIElementPool[i] = new System.Windows.Controls.Canvas();\r
248                                 masterPool.Children.Add(UIElementPool[i]);\r
249                                 dummyRectPool[i] = new System.Windows.Shapes.Rectangle();\r
250                                 UIElementPool[i].Children.Add(dummyRectPool[i]);\r
251                                 dummyRectPool[i].Visibility = Visibility.Collapsed;\r
252                         }\r
253 \r
254 \r
255                         AsyncInitBool = true;\r
256                 }\r
257 \r
258                 internal int findEmptyInPool(Dictionary<int, bool> pool)\r
259                 {\r
260                         /*\r
261                         foreach( KeyValuePair<int, bool> elem in pool)\r
262                         {\r
263                                 if(elem) \r
264                         }*/\r
265                         return 0;\r
266                 }\r
267 \r
268                 #endregion\r
269 \r
270                 #region static initializer\r
271                 /*\r
272                 static Canvas()\r
273                 {\r
274                 }\r
275                 */\r
276                 #endregion\r
277 \r
278 \r
279                 public override void clear(Color col)\r
280                 {\r
281                         back_panel.fill = col;\r
282                         stackN = 0;\r
283                         rect(back_panel);\r
284                 }\r
285 \r
286                 int nextIntervalFrame = 1, chacked = 0;\r
287                 public void flip(int n)\r
288                 {\r
289                         lock (this)\r
290                         {\r
291                                 nextIntervalFrame = n;\r
292                                 chacked = 1;\r
293                         }\r
294                         //pointStackN = 0;\r
295                         lineStackN = 0;\r
296                         rectStackN = 0;\r
297                         polygonStackN = 0;\r
298                         ellipseStackN = 0;\r
299                         lettersStackN = 0;\r
300                         imageStackN = 0;\r
301                         groupStackN = 0;\r
302 \r
303                         UIElementPoolN = 0;\r
304                         brushPoolN = 0;\r
305                         /*\r
306                         pointPoolN = 0;\r
307                         brushPoolN = 0;\r
308                         linePoolN = 0;\r
309                         rectPoolN = 0;\r
310                         ellipsePoolN = 0;\r
311                         polygonPoolN = 0;\r
312                         lettersPoolN = 0;\r
313                         imagePoolN = 0;\r
314                         groupPoolN = 0;\r
315                          * */\r
316 \r
317                         //executeFlip();\r
318                         Internal.Main.canvas_flag.WaitOne();\r
319                 }\r
320                 public void flip()\r
321                 {\r
322                         flip(1);\r
323                 }\r
324 \r
325 \r
326                 #region version modifyNative2\r
327                 public void executeFlip()\r
328                 {\r
329                         Clock after = new Clock();\r
330                         after.update();\r
331                         AppState.statusBar = ((after - before).at_msec().ToString()) + " msec";\r
332 \r
333                         Line lineS;\r
334                         Rectangle rectS;\r
335                         Ellipse ellipseS;\r
336                         Polygon polygonS;\r
337                         Letters lettersS;\r
338                         Image imageS;\r
339                         Group groupS;\r
340                         System.Windows.Shapes.Line lineP;\r
341                         System.Windows.Shapes.Rectangle rectP;\r
342                         System.Windows.Shapes.Ellipse ellipseP;\r
343                         System.Windows.Shapes.Polygon polygonP;\r
344                         System.Windows.Controls.TextBlock lettersP;\r
345                         System.Windows.Controls.Image imageP;\r
346                         System.Windows.Controls.Canvas groupP;\r
347 \r
348                         lock (this)\r
349                         {\r
350                                 nextIntervalFrame--;\r
351                         }\r
352 \r
353                         var cnv = UIElementPool[0];\r
354                         if (nextIntervalFrame <= 0)\r
355                         {\r
356                                 if (chacked > 0)\r
357                                 {\r
358                                         if (stackN > 0)\r
359                                         {\r
360                                                 for (int i = 0; i < stackN; i++)\r
361                                                 {\r
362                                                         if( null != (rectS = stack[i] as Rectangle) )\r
363                                                         {\r
364                                                                 if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle))\r
365                                                                 {\r
366                                                                         rectS.modifyNative(rectP, this);\r
367                                                                 }\r
368                                                                 else\r
369                                                                 {\r
370                                                                         cnv.Children.Clear();\r
371                                                                         cnv.Children.Add(stack[i].poolNative(this));\r
372                                                                 }\r
373                                                         }\r
374                                                         else if (null != (lineS = stack[i] as Line))\r
375                                                         {\r
376                                                                 if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line))\r
377                                                                 {\r
378                                                                         lineS.modifyNative(lineP, this);\r
379                                                                 }\r
380                                                                 else\r
381                                                                 {\r
382                                                                         cnv.Children.Clear();\r
383                                                                         cnv.Children.Add(stack[i].poolNative(this));\r
384                                                                 }\r
385                                                         }\r
386                                                         else if (null != (ellipseS = stack[i] as Ellipse))\r
387                                                         {\r
388                                                                 if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse))\r
389                                                                 {\r
390                                                                         ellipseS.modifyNative(ellipseP, this);\r
391                                                                 }\r
392                                                                 else\r
393                                                                 {\r
394                                                                         cnv.Children.Clear();\r
395                                                                         cnv.Children.Add(stack[i].poolNative(this));\r
396                                                                 }\r
397                                                         }\r
398                                                         else if (null != (polygonS = stack[i] as Polygon))\r
399                                                         {\r
400                                                                 if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon))\r
401                                                                 {\r
402                                                                         polygonS.modifyNative(polygonP, this);\r
403                                                                 }\r
404                                                                 else\r
405                                                                 {\r
406                                                                         cnv.Children.Clear();\r
407                                                                         cnv.Children.Add(stack[i].poolNative(this));\r
408                                                                 }\r
409                                                         }\r
410                                                         else if (null != (lettersS = stack[i] as Letters))\r
411                                                         {\r
412                                                                 if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock))\r
413                                                                 {\r
414                                                                         lettersS.modifyNative(lettersP, this);\r
415                                                                 }\r
416                                                                 else\r
417                                                                 {\r
418                                                                         cnv.Children.Clear();\r
419                                                                         cnv.Children.Add(stack[i].poolNative(this));\r
420                                                                 }\r
421                                                         }\r
422                                                         else if (null != (imageS = stack[i] as Image))\r
423                                                         {\r
424                                                                 if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image))\r
425                                                                 {\r
426                                                                         imageS.modifyNative(imageP, this);\r
427                                                                 }\r
428                                                                 else\r
429                                                                 {\r
430                                                                         cnv.Children.Clear();\r
431                                                                         cnv.Children.Add(stack[i].poolNative(this));\r
432                                                                 }\r
433                                                         }\r
434                                                         else if (null != (groupS = stack[i] as Group))\r
435                                                         {\r
436                                                                 if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas))\r
437                                                                 {\r
438                                                                         groupS.modifyNative(groupP, this);\r
439                                                                 }\r
440                                                                 else\r
441                                                                 {\r
442                                                                         cnv.Children.Clear();\r
443                                                                         cnv.Children.Add(stack[i].poolNative(this));\r
444                                                                 }\r
445                                                         }\r
446                                                         cnv.Visibility = Visibility.Visible;\r
447                                                         UIElementPoolN++;\r
448                                                         cnv = UIElementPool[UIElementPoolN];\r
449                                                 }\r
450                                                 for (int i = UIElementPoolN; i < lastVisibleN; i++)\r
451                                                 {\r
452                                                         cnv = UIElementPool[i];\r
453                                                         cnv.Visibility = Visibility.Collapsed;\r
454                                                 }\r
455                                                 lastVisibleN = UIElementPoolN;\r
456                                                 stackN = 0;\r
457                                         }\r
458                                         lock (this)\r
459                                         {\r
460                                                 chacked = 0;\r
461                                         }\r
462                                         Psychlops.Internal.Main.canvas_flag.Set();\r
463                                 }\r
464                         }\r
465                         System.Threading.Thread.Sleep(0);\r
466                 }\r
467                 #endregion\r
468 \r
469                 #region version modifyNative\r
470                 /*\r
471                 public void executeFlip()\r
472                 {\r
473                         Line lineS;\r
474                         Rectangle rectS;\r
475                         Ellipse ellipseS;\r
476                         Polygon polygonS;\r
477                         Letters lettersS;\r
478                         Image imageS;\r
479                         Group groupS;\r
480                         System.Windows.Shapes.Line lineP;\r
481                         System.Windows.Shapes.Rectangle rectP;\r
482                         System.Windows.Shapes.Ellipse ellipseP;\r
483                         System.Windows.Shapes.Polygon polygonP;\r
484                         System.Windows.Controls.TextBlock lettersP;\r
485                         System.Windows.Controls.Image imageP;\r
486                         System.Windows.Controls.Canvas groupP;\r
487 \r
488                         lock (this)\r
489                         {\r
490                                 nextIntervalFrame--;\r
491                         }\r
492 \r
493                         var en = masterPool.Children.GetEnumerator();\r
494                         bool full = en.MoveNext();\r
495                         if (nextIntervalFrame <= 0)\r
496                         {\r
497                                 if (chacked > 0)\r
498                                 {\r
499                                         //masterPool.Children.Clear();\r
500                                         if (stackN > 0)\r
501                                         {\r
502                                                 for (int i = 0; i < stackN - 2; i++)\r
503                                                 {\r
504                                                         if (full == false)\r
505                                                         {\r
506                                                                 masterPool.Children.Add(stack[i].poolNative(this));\r
507                                                         }\r
508                                                         else\r
509                                                         {\r
510                                                                 if( null != (rectS = stack[i] as Rectangle) )\r
511                                                                 {\r
512                                                                         if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle))\r
513                                                                         {\r
514                                                                                 rectS.modifyNative(rectP, this);\r
515                                                                         }\r
516                                                                 }\r
517                                                                 else if (null != (lineS = stack[i] as Line))\r
518                                                                 {\r
519                                                                         if (null != (lineP = en.Current as System.Windows.Shapes.Line))\r
520                                                                         {\r
521                                                                                 lineS.modifyNative(lineP, this);\r
522                                                                         }\r
523                                                                 }\r
524                                                                 else if (null != (ellipseS = stack[i] as Ellipse))\r
525                                                                 {\r
526                                                                         if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse))\r
527                                                                         {\r
528                                                                                 ellipseS.modifyNative(ellipseP, this);\r
529                                                                         }\r
530                                                                         else\r
531                                                                         {\r
532                                                                                 masterPool.Children.Add(stack[i].poolNative(this));\r
533                                                                         }\r
534                                                                 }\r
535                                                                 else if (null != (polygonS = stack[i] as Polygon))\r
536                                                                 {\r
537                                                                         if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon))\r
538                                                                         {\r
539                                                                                 polygonS.modifyNative(polygonP, this);\r
540                                                                         }\r
541                                                                 }\r
542                                                                 else if (null != (lettersS = stack[i] as Letters))\r
543                                                                 {\r
544                                                                         if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock))\r
545                                                                         {\r
546                                                                                 lettersS.modifyNative(lettersP, this);\r
547                                                                         }\r
548                                                                 }\r
549                                                                 else if (null != (imageS = stack[i] as Image))\r
550                                                                 {\r
551                                                                         if (null != (imageP = en.Current as System.Windows.Controls.Image))\r
552                                                                         {\r
553                                                                                 imageS.modifyNative(imageP, this);\r
554                                                                         }\r
555                                                                 }\r
556                                                                 else if (null != (groupS = stack[i] as Group))\r
557                                                                 {\r
558                                                                         if (null != (groupP = en.Current as System.Windows.Controls.Canvas))\r
559                                                                         {\r
560                                                                                 groupS.modifyNative(groupP, this);\r
561                                                                         }\r
562                                                                 }\r
563                                                                 full = en.MoveNext();\r
564                                                         }\r
565                                                 }\r
566                                                 stackN = 0;\r
567                                         }\r
568                                         lock (this)\r
569                                         {\r
570                                                 chacked = 0;\r
571                                         }\r
572                                         Psychlops.Internal.Main.canvas_flag.Set();\r
573                                 }\r
574                         }\r
575                         System.Threading.Thread.Sleep(0);\r
576                 }\r
577                  * */\r
578                 #endregion\r
579 \r
580                 #region version poolNative 2\r
581                 /*\r
582                 public void executeFlip()\r
583                 {\r
584 \r
585                         lock (this)\r
586                         {\r
587                                 nextIntervalFrame--;\r
588                         }\r
589                         UIElementPoolN = 0;\r
590                         if (nextIntervalFrame <= 0)\r
591                         {\r
592                                 if (chacked > 0)\r
593                                 {\r
594                                         //masterPool.Children.Clear();\r
595                                         if (stackN > 0)\r
596                                         {\r
597                                                 for (int i = 0; i < stackN - 2; i++)\r
598                                                 {\r
599                                                         UIElementPool[UIElementPoolN] = stack[i].poolNative(this);\r
600                                                         UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;\r
601                                                         UIElementPoolN++;\r
602 \r
603                                                 }\r
604                                                 for (int i = stackN - 2; i < 10000; i++)\r
605                                                 {\r
606                                                         UIElementPool[UIElementPoolN] = rectPool[i];\r
607                                                         UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed;\r
608                                                         UIElementPoolN++;\r
609                                                 }\r
610                                                 stackN = 0;\r
611                                         }\r
612                                         lock (this)\r
613                                         {\r
614                                                 chacked = 0;\r
615                                         }\r
616                                         Psychlops.Internal.Main.canvas_flag.Set();\r
617                                 }\r
618                         }\r
619                         System.Threading.Thread.Sleep(0);\r
620                 }\r
621                 */\r
622                 #endregion\r
623 \r
624 \r
625                 #region Properties\r
626 \r
627                 public double width { get { return width_; } }\r
628                 public double height { get { return height_; } }\r
629                 public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }\r
630                 public double getWidth() { return width; }\r
631                 public double getHeight() { return height; }\r
632                 public override Point getCenter() { return center; }\r
633                 public double getHCenter() { return width / 2; }\r
634                 public double getVCenter() { return height / 2; }\r
635                 public double getRefreshRate() { return 60; }\r
636 \r
637                 #endregion\r
638 \r
639 \r
640         }\r
641 \r
642 \r
643 \r
644         #region primitive tokenizer\r
645 \r
646 \r
647         #region primitive\r
648 \r
649         partial struct Point\r
650         {\r
651                 public static implicit operator System.Windows.Point(Point d)\r
652                 {\r
653                         return new System.Windows.Point(d.x, d.y);\r
654                 }\r
655         }\r
656 \r
657         partial struct Color\r
658         {\r
659                 public static implicit operator System.Windows.Media.Color(Color d)\r
660                 {\r
661                         return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));\r
662                 }\r
663                 public static implicit operator System.Windows.Media.SolidColorBrush(Color d)\r
664                 {\r
665                         return new SolidColorBrush { Color = d };\r
666                 }\r
667                 public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)\r
668                 {\r
669                         var tmp = d.brushPool[d.brushPoolN];\r
670                         tmp.Color = this;\r
671                         d.brushPoolN++;\r
672                         return tmp;\r
673                 }\r
674 \r
675         }\r
676 \r
677         partial struct Stroke\r
678         {\r
679                 public void apply(System.Windows.Shapes.Shape target)\r
680                 {\r
681                         target.Stroke = this;\r
682                         //target.StrokeDashArray\r
683                         target.StrokeThickness = thick;\r
684                 }\r
685                 public static implicit operator SolidColorBrush(Stroke d)\r
686                 {\r
687                         return new SolidColorBrush { Color = d.color };\r
688                 }\r
689                 public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)\r
690                 {\r
691                         var tmp = d.brushPool[d.brushPoolN];\r
692                         tmp.Color = this.color;\r
693                         d.brushPoolN++;\r
694                         return tmp;\r
695                 }\r
696         }\r
697         \r
698         #endregion\r
699         \r
700         #region Line\r
701 \r
702         partial class Line\r
703         {\r
704                 public Line dup()\r
705                 {\r
706                         return (Line)MemberwiseClone();\r
707                 }\r
708                 public Line clone()\r
709                 {\r
710                         return (Line)MemberwiseClone();\r
711                 }\r
712                 public static implicit operator System.Windows.Shapes.Line(Line d)\r
713                 {\r
714                         var tmp =  new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };\r
715                         if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;\r
716                         else d.stroke.apply(tmp);\r
717                         return tmp;\r
718                 }\r
719                 public UIElement toNative() { return this; }\r
720 \r
721                 public void copyToStack(Templates.StackableDrawable d)\r
722                 {\r
723                         var tmp = d.lineStack[d.lineStackN];\r
724                         tmp.begin.x = begin.x;\r
725                         tmp.begin.y = begin.y;\r
726                         tmp.end.x = end.x;\r
727                         tmp.end.y = end.y;\r
728                         tmp.fill = fill;\r
729                         tmp.stroke = stroke;\r
730                         d.stack[d.stackN] = tmp;\r
731                         d.lineStackN++;\r
732                         d.stackN++;\r
733                 }\r
734                 public UIElement poolNative(Canvas d)\r
735                 {\r
736                         var tmp = d.linePool[d.linePoolN];\r
737                         tmp.X1 = begin.x;\r
738                         tmp.Y1 = begin.y;\r
739                         tmp.X2 = end.x;\r
740                         tmp.Y2 = end.y;\r
741                         if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);\r
742                         else stroke.apply(tmp);\r
743                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
744                         System.Windows.Controls.Canvas.SetTop(tmp, top);\r
745                         tmp.Visibility = Visibility.Visible;\r
746                         d.linePoolN++;\r
747                         return tmp;\r
748                 }\r
749                 public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d)\r
750                 {\r
751                         tmp.X1 = begin.x;\r
752                         tmp.Y1 = begin.y;\r
753                         tmp.X2 = end.x;\r
754                         tmp.Y2 = end.y;\r
755                         if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);\r
756                         else stroke.apply(tmp);\r
757                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
758                         System.Windows.Controls.Canvas.SetTop(tmp, top);\r
759                         tmp.Visibility = Visibility.Visible;\r
760                 }\r
761         }\r
762         \r
763         #endregion\r
764                 \r
765         #region Rectangle\r
766 \r
767         partial class Rectangle\r
768         {\r
769                 public Rectangle dup()\r
770                 {\r
771                         return (Rectangle)MemberwiseClone();\r
772                 }\r
773                 public Rectangle clone()\r
774                 {\r
775                         return (Rectangle)MemberwiseClone();\r
776                 }\r
777                 public static implicit operator System.Windows.Rect(Rectangle d)\r
778                 {\r
779                         return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);\r
780                 }\r
781                 public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)\r
782                 {\r
783                         var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };\r
784                         d.stroke.apply(tmp);\r
785                         System.Windows.Controls.Canvas.SetLeft(tmp, d.left);\r
786                         System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
787                         return tmp;\r
788                 }\r
789 \r
790                 public UIElement toNative() { return this; }\r
791                 public void copyToStack(Templates.StackableDrawable d)\r
792                 {\r
793                         var tmp = d.rectStack[d.rectStackN];\r
794                         tmp.v1 = v1;\r
795                         tmp.v2 = v2;\r
796                         tmp.fill = fill;\r
797                         d.stack[d.stackN] = tmp;\r
798                         d.rectStackN++;\r
799                         d.stackN++;\r
800                 }\r
801                 public UIElement poolNative(Canvas d)\r
802                 {\r
803                         var tmp = d.rectPool[d.rectPoolN];\r
804                         tmp.Width = width;\r
805                         tmp.Height = height;\r
806                         tmp.Fill = fill.getNativeFromStack(d);\r
807                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
808                         System.Windows.Controls.Canvas.SetTop(tmp, top);\r
809                         tmp.Visibility = Visibility.Visible;\r
810                         d.rectPoolN++;\r
811                         return tmp;\r
812                 }\r
813                 public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)\r
814                 {\r
815                         tmp.Width = width;\r
816                         tmp.Height = height;\r
817                         tmp.Fill = fill.getNativeFromStack(d);\r
818                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
819                         System.Windows.Controls.Canvas.SetTop(tmp, top);\r
820                         tmp.Visibility = Visibility.Visible;\r
821                 }\r
822         }\r
823         \r
824         #endregion\r
825 \r
826         #region Ellipse\r
827 \r
828         partial class Ellipse\r
829         {\r
830                 public Ellipse dup()\r
831                 {\r
832                         return (Ellipse)MemberwiseClone();\r
833                 }\r
834                 public Ellipse clone()\r
835                 {\r
836                         return (Ellipse)MemberwiseClone();\r
837                 }\r
838                 public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)\r
839                 {\r
840                         var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };\r
841                         d.stroke.apply(tmp);\r
842                         System.Windows.Controls.Canvas.SetLeft(tmp, d.left);\r
843                         System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
844                         return tmp;\r
845                 }\r
846 \r
847                 public UIElement toNative() { return this; }\r
848 \r
849                 public void copyToStack(Templates.StackableDrawable d)\r
850                 {\r
851                         var tmp = d.ellipseStack[d.ellipseStackN];\r
852                         tmp.datum = datum;\r
853                         tmp.xdiameter = xdiameter;\r
854                         tmp.ydiameter = ydiameter;\r
855                         tmp.fill = fill;\r
856                         d.stack[d.stackN] = tmp;\r
857                         d.ellipseStackN++;\r
858                         d.stackN++;\r
859                 }\r
860                 public UIElement poolNative(Canvas d)\r
861                 {\r
862                         var tmp = d.ellipsePool[d.ellipsePoolN];\r
863                         tmp.Width = width;\r
864                         tmp.Height = height;\r
865                         tmp.Fill = fill.getNativeFromStack(d);\r
866                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
867                         System.Windows.Controls.Canvas.SetTop(tmp, top);\r
868                         tmp.Visibility = Visibility.Visible;\r
869                         d.ellipsePoolN++;\r
870                         return tmp;\r
871                 }\r
872                 public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d)\r
873                 {\r
874                         tmp.Width = width;\r
875                         tmp.Height = height;\r
876                         tmp.Fill = fill.getNativeFromStack(d);\r
877                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
878                         System.Windows.Controls.Canvas.SetTop(tmp, top);\r
879                         tmp.Visibility = Visibility.Visible;\r
880                 }\r
881         }\r
882 \r
883         #endregion\r
884 \r
885         #region Polygon\r
886 \r
887         partial class Polygon\r
888         {\r
889                 public Polygon dup()\r
890                 {\r
891                         return (Polygon)MemberwiseClone();\r
892                 }\r
893                 public Polygon clone()\r
894                 {\r
895                         return (Polygon)MemberwiseClone();\r
896                 }\r
897                 public static implicit operator System.Windows.Shapes.Polygon(Polygon d)\r
898                 {\r
899                         var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };\r
900                         d.stroke.apply(tmp);\r
901                         foreach (Point p in d.vertices)\r
902                         {\r
903                                 tmp.Points.Add(p);\r
904                         }\r
905                         System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);\r
906                         System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);\r
907                         return tmp;\r
908                 }\r
909                 public UIElement toNative() { return this; }\r
910 \r
911                 public void copyToStack(Templates.StackableDrawable d)\r
912                 {\r
913                         var tmp = d.polygonStack[d.polygonStackN];\r
914                         tmp.datum = datum;\r
915                         tmp.vertices.Clear();\r
916                         foreach (var v in vertices)\r
917                         {\r
918                                 tmp.vertices.Add(v);\r
919                         }\r
920                         tmp.fill = fill;\r
921                         d.stack[d.stackN] = tmp;\r
922                         d.polygonStackN++;\r
923                         d.stackN++;\r
924                 }\r
925                 public UIElement poolNative(Canvas d)\r
926                 {\r
927                         var tmp = d.polygonPool[d.polygonPoolN];\r
928                         tmp.Fill = fill.getNativeFromStack(d);\r
929                         tmp.Points.Clear();\r
930                         foreach (var v in vertices)\r
931                         {\r
932                                 tmp.Points.Add(v);\r
933                         }\r
934                         System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
935                         System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
936                         tmp.Visibility = Visibility.Visible;\r
937                         d.polygonPoolN++;\r
938                         return tmp;\r
939                 }\r
940                 public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)\r
941                 {\r
942                         tmp.Fill = fill.getNativeFromStack(d);\r
943                         tmp.Points.Clear();\r
944                         foreach (var v in vertices)\r
945                         {\r
946                                 tmp.Points.Add(v);\r
947                         }\r
948                         System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
949                         System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
950                         tmp.Visibility = Visibility.Visible;\r
951                 }\r
952 \r
953         }\r
954                 \r
955         #endregion\r
956 \r
957         #region Letters\r
958 \r
959         partial class Letters\r
960         {\r
961                 #region static initializer\r
962                 internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;\r
963                 internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;\r
964                 internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;\r
965                 static Letters()\r
966                 {\r
967                         FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();\r
968                         FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);\r
969                         FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);\r
970                         FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();\r
971                         FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);\r
972                         FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);\r
973                         FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);\r
974                         LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();\r
975                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);\r
976                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);\r
977                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);\r
978                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);\r
979                 }\r
980                 #endregion\r
981                 public Letters dup()\r
982                 {\r
983                         return (Letters)MemberwiseClone();\r
984                 }\r
985                 public Letters clone()\r
986                 {\r
987                         return (Letters)MemberwiseClone();\r
988                 }\r
989                 public static implicit operator System.Windows.Controls.TextBlock(Letters d)\r
990                 {\r
991                         //var zapi_shape = new System.Windows.Documents.Glyphs();\r
992                         var tmp = new System.Windows.Controls.TextBlock {\r
993                                 Text = d.str, Width = 500, Height = 500,\r
994                                 FontSize = d.font.size,\r
995                                 //tmp.FontFamily = ,\r
996                                 FontStyle = FONT_STYLE_BRIDGE[d.font.style],\r
997                                 FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],\r
998                                 TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],\r
999                                 Foreground = d.fill\r
1000                         };\r
1001                         double left = 0;\r
1002                         switch (d.align)\r
1003                         {\r
1004                                 case Letters.HorizontalAlign.left: break;\r
1005                                 case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;\r
1006                                 case Letters.HorizontalAlign.right: left = tmp.Width; break;\r
1007                         }\r
1008                         System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);\r
1009                         System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);\r
1010                         return tmp;\r
1011                 }\r
1012                 public UIElement toNative() { return this; }\r
1013 \r
1014                 public void copyToStack(Templates.StackableDrawable d)\r
1015                 {\r
1016                         var tmp = d.lettersStack[d.lettersStackN];\r
1017                         tmp.str = str;\r
1018                         tmp.datum = datum;\r
1019                         tmp.fill = fill;\r
1020                         d.stack[d.stackN] = tmp;\r
1021                         d.lettersStackN++;\r
1022                         d.stackN++;\r
1023                 }\r
1024                 public UIElement poolNative(Canvas d)\r
1025                 {\r
1026                         var tmp = d.lettersPool[d.lettersPoolN];\r
1027                         tmp.Text = str;\r
1028                         tmp.Width = 500;\r
1029                         tmp.Height = 500;\r
1030                         tmp.FontSize = font.size;\r
1031                         //tmp.FontFamily = ,\r
1032                         tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];\r
1033                         tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];\r
1034                         tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];\r
1035                         tmp.Foreground = fill.getNativeFromStack(d);\r
1036                         System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
1037                         System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
1038                         tmp.Visibility = Visibility.Visible;\r
1039                         d.lettersPoolN++;\r
1040                         return tmp;\r
1041                 }\r
1042                 public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d)\r
1043                 {\r
1044                         tmp.Text = str;\r
1045                         tmp.Width = 500;\r
1046                         tmp.Height = 500;\r
1047                         tmp.FontSize = font.size;\r
1048                         //tmp.FontFamily = ,\r
1049                         tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];\r
1050                         tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];\r
1051                         tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];\r
1052                         tmp.Foreground = fill.getNativeFromStack(d);\r
1053                         System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
1054                         System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
1055                         tmp.Visibility = Visibility.Visible;\r
1056                 }\r
1057         }\r
1058         \r
1059         #endregion\r
1060         \r
1061         #region Image\r
1062 \r
1063         partial class Image\r
1064         {\r
1065                 internal void initialize__(int wid, int hei)\r
1066                 {\r
1067                         AsyncBool = false;\r
1068                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei);\r
1069                         while (!AsyncBool) { System.Threading.Thread.Sleep(10); }\r
1070                 }\r
1071                 internal void create__(int wid, int hei)\r
1072                 {\r
1073                         buffer = new WriteableBitmap(wid, hei);\r
1074                         AsyncBool = true;\r
1075                 }\r
1076                 internal void load__(string uri)\r
1077                 {\r
1078                         AsyncBool = false;\r
1079                         var ur = new System.Uri(uri,  System.UriKind.RelativeOrAbsolute);\r
1080                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action<Uri>(load_), ur);\r
1081                         while (!AsyncBool) { System.Threading.Thread.Sleep(10); }\r
1082                 }\r
1083                 internal void load_(Uri uri)\r
1084                 {\r
1085                         var bitmap = new BitmapImage();\r
1086                         bitmap.CreateOptions = BitmapCreateOptions.None;\r
1087                         bitmap.UriSource = uri;\r
1088                         try\r
1089                         {\r
1090                                 var wbm = new System.Windows.Media.Imaging.WriteableBitmap(bitmap);\r
1091                                 buffer = wbm;\r
1092                         }\r
1093                         catch (Exception e)\r
1094                         {\r
1095                                 buffer = new WriteableBitmap(64, 64);\r
1096                                 buffer.ForEach(bitmap_drawChecker);\r
1097                         }\r
1098                         self_rect.set(buffer.PixelWidth, buffer.PixelHeight);\r
1099                         AsyncBool = true;\r
1100                 }\r
1101                 static System.Windows.Media.Color[] CHECKER_C;\r
1102                 static Image()\r
1103                 {\r
1104                         CHECKER_C = new System.Windows.Media.Color[2];\r
1105                         CHECKER_C[0] = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);\r
1106                         CHECKER_C[1] = System.Windows.Media.Color.FromArgb(128,128,128,128);\r
1107                 }\r
1108                 static System.Windows.Media.Color bitmap_drawChecker(int x, int y)\r
1109                 {\r
1110                         return ((x / 4) + (y / 4)) % 2 == 0 ? CHECKER_C[0] : CHECKER_C[1];\r
1111                 }\r
1112                 delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);\r
1113                 delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);\r
1114                 public void field__(System.Func<int, int, System.Windows.Media.Color> func)\r
1115                 {\r
1116                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);\r
1117                         //buffer.ForEach(func);\r
1118                 }\r
1119                 public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
1120                 {\r
1121                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);\r
1122                         //buffer.ForEach(func);\r
1123                 }\r
1124                 public void field___(System.Func<int, int, System.Windows.Media.Color> func)\r
1125                 {\r
1126                         buffer.ForEach(func);\r
1127                 }\r
1128                 public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
1129                 {\r
1130                         buffer.ForEach(func);\r
1131                 }\r
1132 \r
1133                 public Image clone()\r
1134                 {\r
1135                         return (Image)MemberwiseClone();\r
1136                 }\r
1137                 public static implicit operator System.Windows.Controls.Image(Image d)\r
1138                 {\r
1139                         var tmp = new System.Windows.Controls.Image();\r
1140                         tmp.Source = d.buffer;\r
1141                         System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);\r
1142                         System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);\r
1143                         return tmp;\r
1144                 }\r
1145                 public UIElement toNative() { return this; }\r
1146 \r
1147                 public void copyToStack(Templates.StackableDrawable d)\r
1148                 {\r
1149                         var tmp = d.imageStack[d.imageStackN];\r
1150                         tmp.datum = datum;\r
1151                         tmp.buffer = buffer;\r
1152                         tmp.self_rect = self_rect;\r
1153                         d.stack[d.stackN] = tmp;\r
1154                         d.imageStackN++;\r
1155                         d.stackN++;\r
1156                 }\r
1157                 public UIElement poolNative(Canvas d)\r
1158                 {\r
1159                         var tmp = d.imagePool[d.imagePoolN];\r
1160                         tmp.Source = buffer;\r
1161                         System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
1162                         System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
1163                         tmp.Visibility = Visibility.Visible;\r
1164                         d.imagePoolN++;\r
1165                         return tmp;\r
1166                 }\r
1167                 public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)\r
1168                 {\r
1169                         tmp.Source = buffer;\r
1170                         System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
1171                         System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
1172                         tmp.Visibility = Visibility.Visible;\r
1173                 }\r
1174 \r
1175         }\r
1176 \r
1177         #endregion\r
1178 \r
1179         #region Group\r
1180 \r
1181         partial class Group\r
1182         {\r
1183                 internal void initialize__()\r
1184                 {\r
1185                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.SimpleProcedure(create__));\r
1186                 }\r
1187                 internal void create__()\r
1188                 {\r
1189                         cnvs = new System.Windows.Controls.Canvas();\r
1190                         trans = new System.Windows.Media.TransformGroup();\r
1191                         transF = new System.Windows.Media.TransformCollection();\r
1192                         rotateF = new System.Windows.Media.RotateTransform();\r
1193                         scaleF = new System.Windows.Media.ScaleTransform();\r
1194                         translateF = new System.Windows.Media.TranslateTransform();\r
1195                         transF.Add(rotateF);\r
1196                         transF.Add(scaleF);\r
1197                         transF.Add(translateF);\r
1198                         trans.Children = transF;\r
1199                         cnvs.RenderTransform = trans;\r
1200                         AsyncBool = true;\r
1201                 }\r
1202                 public Group clone()\r
1203                 {\r
1204                         return (Group)MemberwiseClone();\r
1205                 }\r
1206 \r
1207                 delegate void AppendFunc1(Internal.PrimitiveFigure func);\r
1208                 void append__(Internal.PrimitiveFigure fig)\r
1209                 {\r
1210                         fig.centering(0, 0);\r
1211                         UIElement e = fig.toNative();\r
1212                         cnvs.Children.Add(e);\r
1213                         System.Windows.Controls.Canvas.SetLeft(e, fig.datum.x);\r
1214                         System.Windows.Controls.Canvas.SetTop(e, fig.datum.y);\r
1215                 }\r
1216                 delegate void SimpleProcedure();\r
1217                 void getRotation__() { rotation_ = rotateF.Angle; }\r
1218                 void setRotation__() { rotateF.Angle = rotation_; }\r
1219                 //void getTranslation__() { rotation_ = rotateF.Angle; }\r
1220                 void setTranslation__() { translateF.X = datum.x; translateF.Y = datum.y; }\r
1221                 void setScaling__() { scaleF.ScaleX = scaling_.x; scaleF.ScaleY = scaling_.y; }\r
1222 \r
1223                 public static implicit operator System.Windows.Controls.Canvas(Group d)\r
1224                 {\r
1225                         var tmp = d.cnvs;//new System.Windows.Controls.Canvas();\r
1226                         System.Windows.Controls.Canvas.SetLeft(d.cnvs, d.datum.x);\r
1227                         System.Windows.Controls.Canvas.SetTop(d.cnvs, d.datum.y);\r
1228                         return tmp;\r
1229                 }\r
1230                 public UIElement toNative() { return this; }\r
1231 \r
1232                 public void copyToStack(Templates.StackableDrawable d)\r
1233                 {\r
1234                         var tmp = d.groupStack[d.groupStackN];\r
1235                         tmp.datum = datum;\r
1236                         tmp.cnvs = cnvs;\r
1237                         d.stack[d.stackN] = tmp;\r
1238                         d.groupStackN++;\r
1239                         d.stackN++;\r
1240                 }\r
1241                 public UIElement poolNative(Canvas d)\r
1242                 {\r
1243                         //d.groupPool[d.groupPoolN] = cnvs;\r
1244                         //var tmp = d.groupPool[d.groupPoolN];\r
1245                         var tmp = cnvs;\r
1246                         System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
1247                         System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
1248                         tmp.Visibility = Visibility.Visible;\r
1249                         //d.groupPoolN++;\r
1250                         return tmp;\r
1251                 }\r
1252                 public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d)\r
1253                 {\r
1254                         d.groupPool[d.groupPoolN] = cnvs;\r
1255                         System.Windows.Controls.Canvas.SetLeft(cnvs, datum.x);\r
1256                         System.Windows.Controls.Canvas.SetTop(cnvs, datum.y);\r
1257                         tmp.Visibility = Visibility.Visible;\r
1258                 }\r
1259 \r
1260         }\r
1261         #endregion\r
1262         \r
1263         #endregion\r
1264 \r
1265 \r
1266 }