OSDN Git Service

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