OSDN Git Service

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