OSDN Git Service

pooling
[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 \r
30 \r
31                         public StackableDrawable()\r
32                         {\r
33 //                              stack = new System.Collections.Generic.Queue<Internal.PrimitiveFigure>();\r
34                                 stack = new Internal.PrimitiveFigure[40000];\r
35                                 lineStack = new Line[10000];\r
36                                 rectStack = new Rectangle[10000];\r
37                                 for (int i = 0; i < 10000; i++)\r
38                                 {\r
39                                         lineStack[i] = new Line(0,0,0,0);\r
40                                         rectStack[i] = new Rectangle();\r
41                                 }\r
42                         }\r
43 \r
44                         public void clear()\r
45                         {\r
46                                 clear(Color.black);\r
47                         }\r
48                         public virtual void clear(Color col)\r
49                         {\r
50                                 //rect(back_panel, col);\r
51                         }\r
52 \r
53                         public virtual void pix(int x, int y, Color col)\r
54                         {\r
55                         }\r
56 \r
57                         public virtual void line(Line drawee)\r
58                         {\r
59 //                              stack.Enqueue(drawee.clone());\r
60                         }\r
61 \r
62                         public virtual void rect(Rectangle drawee)\r
63                         {\r
64                                 //stack.Enqueue(drawee.clone());\r
65 //                              stack.Enqueue(drawee.copyToStack(this));\r
66                                 drawee.copyToStack(this);\r
67                         }\r
68 \r
69                         public virtual void ellipse(Ellipse drawee)\r
70                         {\r
71 //                              stack.Enqueue(drawee.clone());\r
72                         }\r
73 \r
74                         public virtual void polygon(Polygon drawee)\r
75                         {\r
76 //                              stack.Enqueue(drawee.clone());\r
77                         }\r
78 \r
79                         public virtual void letters(Letters drawee)\r
80                         {\r
81 //                              stack.Enqueue(drawee.clone());\r
82                         }\r
83 \r
84                         public virtual void image(Image drawee)\r
85                         {\r
86 //                              stack.Enqueue(drawee.clone());\r
87                         }\r
88 \r
89                         public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
90                         public virtual void msg(string dstr, double x, double y, Color col)\r
91                         {\r
92                                 var let = new Letters(dstr);\r
93                                 let.locate(x, y);\r
94                                 let.fill = col;\r
95                                 this.letters(let);\r
96                         }\r
97                         public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }\r
98                         public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }\r
99 \r
100                         public virtual Point getCenter() { return new Point(0, 0, 0); }\r
101                 }\r
102 \r
103         }\r
104 \r
105         public class Canvas : Templates.StackableDrawable\r
106         {\r
107 \r
108                 internal System.Windows.Controls.Canvas masterPool, prevPool;\r
109                 internal System.Windows.Point[] pointPool;\r
110                 internal int pointPoolN;\r
111                 internal SolidColorBrush[] brushPool;\r
112                 internal int brushPoolN;\r
113                 internal System.Windows.Shapes.Line[] linePool;\r
114                 internal int linePoolN;\r
115                 internal System.Windows.Shapes.Rectangle[] rectPool;\r
116                 internal int rectPoolN;\r
117 \r
118                 #region initializer\r
119 \r
120                 internal delegate void TwoIntProcedure(int x, int y);\r
121                 internal delegate void SimpleProcedure();\r
122                 SimpleProcedure flipexec;\r
123 \r
124                 //public static System.Windows.Controls.Image default_buffer_frame;\r
125                 public static System.Windows.Controls.UserControl default_panel;\r
126                 public static System.Windows.Controls.Canvas default_api_canvas;\r
127                 public static WriteableBitmap default_buffer;\r
128                 //WriteableBitmap buffer;\r
129                 //System.Windows.Controls.Image instance;\r
130                 System.Windows.Controls.Canvas api_canvas;\r
131                 System.Windows.Controls.UserControl panel;\r
132                 Rectangle back_panel;\r
133                 double width_, height_;\r
134 \r
135                 public Canvas(int wid, int hei)\r
136                 {\r
137                         panel = default_panel;\r
138                         api_canvas = default_api_canvas;\r
139                         initialize(wid, hei);\r
140                 }\r
141                 public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs, System.Windows.Controls.UserControl system)\r
142                 {\r
143                         panel = system;\r
144                         api_canvas = apicnvs;\r
145                         initialize(wid, hei);\r
146                 }\r
147                 protected void initialize(int wid, int hei)\r
148                 {\r
149                         width_ = wid;\r
150                         height_ = hei;\r
151                         api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);\r
152                         Mouse._prime = api_canvas;\r
153                         Main.drawable = this;\r
154                         Main.canvas = this;\r
155 \r
156                         back_panel = new Rectangle(wid, hei);\r
157 \r
158                         flipexec = new SimpleProcedure(executeFlip);\r
159                 }\r
160                 protected void initialize__(int wid, int hei)\r
161                 {\r
162                         api_canvas.Width = wid;\r
163                         api_canvas.Height = hei;\r
164                         api_canvas.MouseMove += Mouse.Canvas_MousePos;\r
165                         api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
166                         api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;\r
167                         api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;\r
168                         panel.KeyDown += Keyboard.Canvas_KeyDown;\r
169                         panel.KeyUp += Keyboard.Canvas_KeyUp;\r
170 \r
171                         HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");\r
172                         //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");\r
173                         htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");\r
174                         htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px");\r
175                         htmlHost.SetStyleAttribute("margin", "2em auto auto auto");\r
176 \r
177 \r
178                         pointPool = new System.Windows.Point[10000];\r
179                         brushPool = new SolidColorBrush[10000];\r
180                         linePool = new System.Windows.Shapes.Line[10000];\r
181                         rectPool = new System.Windows.Shapes.Rectangle[10000];\r
182                         for (int i = 0; i < 10000; i++)\r
183                         {\r
184                                 pointPool[i] = new System.Windows.Point();\r
185                                 brushPool[i] = new SolidColorBrush();\r
186                                 linePool[i] = new System.Windows.Shapes.Line();\r
187                                 rectPool[i] = new System.Windows.Shapes.Rectangle();\r
188                         }\r
189                         for (int i = 0; i < 300; i++)\r
190                         {\r
191                                 api_canvas.Children.Add(rectStack[i].poolNative(this));\r
192                                 api_canvas.Children.Add(rectStack[i].poolNative(this));\r
193                         }\r
194 \r
195                         masterPool = new System.Windows.Controls.Canvas();\r
196                         prevPool = new System.Windows.Controls.Canvas();\r
197 //                      masterPool.Children.Add()\r
198                 }\r
199 \r
200                 #endregion\r
201 \r
202                 #region static initializer\r
203                 /*\r
204                 static System.Windows.Shapes.Line api_line;\r
205                 static System.Windows.Shapes.Path api_curve;\r
206                 static System.Windows.Shapes.Rectangle api_rect;\r
207                 static System.Windows.Shapes.Ellipse api_ellipse;\r
208                 static System.Windows.Shapes.Polygon api_polygon;\r
209                 static System.Windows.Shapes.Polyline api_polyline;\r
210                 static System.Windows.Media.Color api_color;\r
211                 static System.Windows.Media.SolidColorBrush api_fill;\r
212                 static System.Windows.Media.SolidColorBrush api_stroke;\r
213                 static System.Windows.Media.TranslateTransform api_translation;\r
214                 static Canvas()\r
215                 {\r
216                         api_line = new System.Windows.Shapes.Line();\r
217                         api_curve    = new System.Windows.Shapes.Path();\r
218                         api_rect     = new System.Windows.Shapes.Rectangle();\r
219                         api_ellipse  = new System.Windows.Shapes.Ellipse();\r
220                         api_polygon  = new System.Windows.Shapes.Polygon();\r
221                         api_polyline = new System.Windows.Shapes.Polyline();\r
222                         api_color       = new System.Windows.Media.Color();\r
223                         api_fill        = new System.Windows.Media.SolidColorBrush();\r
224                         api_stroke      = new System.Windows.Media.SolidColorBrush();\r
225                         api_translation = new System.Windows.Media.TranslateTransform();\r
226                 }\r
227                 */\r
228                 #endregion\r
229 \r
230 \r
231                 public override void clear(Color col)\r
232                 {\r
233                         back_panel.fill = col;\r
234 //                      stack.Clear();\r
235                         stackN = 0;\r
236                         rect(back_panel);\r
237                 }\r
238 \r
239                 int nextIntervalFrame = 1, chacked = 0;\r
240                 public void flip()\r
241                 {\r
242                         //api_canvas.Dispatcher.BeginInvoke(flipexec);\r
243                         //flipexec();\r
244                         //System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\r
245                         lock (this)\r
246                         {\r
247                                 nextIntervalFrame = 1;\r
248                                 chacked = 1;\r
249                         }\r
250 //                      pointPoolN = 0;\r
251 //                      brushPoolN = 0;\r
252 //                      linePoolN = 0;\r
253                         rectPoolN = 0;\r
254                         lineStackN = 0;\r
255                         rectStackN = 0;\r
256                         Internal.Main.canvas_flag.WaitOne();\r
257                 }\r
258                 public void executeFlip()\r
259                 {\r
260                         lock (this)\r
261                         {\r
262                                 nextIntervalFrame--;\r
263                         }\r
264                         if (nextIntervalFrame <= 0)\r
265                         {\r
266                                 var rr = new Random();\r
267                                 //Psychlops.AppState.statusBar = chacked.ToString();\r
268                                 if (chacked > 0)\r
269                                 {\r
270                 //                      prevPool.Children.Clear();\r
271                 //                      var tmp = new System.Windows.Controls.Canvas();\r
272 //                                      if (stack.Count > 0)\r
273                                         if (stackN > 0)\r
274                                         {\r
275 //                                              foreach (Internal.PrimitiveFigure f in stack)\r
276                                                 for (int i = 0; i < stackN - 2; i++ )\r
277                                                 {\r
278                                                         //                                                      tmp.Children.Add(f.toNative());\r
279 //                                                      tmp.Children.Add(f.poolNative(this));\r
280                 //                                      tmp.Children.Add(stack[i].poolNative(this));\r
281                                                         System.Windows.Controls.Canvas.SetLeft(api_canvas.Children[i + 1], rectStack[i].left);\r
282                                                         api_canvas.Children[0] = api_canvas.Children[0];\r
283                                                 }\r
284                                                 stackN = 0;\r
285 \r
286                                         }\r
287                 //                      api_canvas.Children.Clear();\r
288                 //                      api_canvas.Children.Add(tmp);\r
289 //                                      stack.Clear();\r
290                                         lock (this)\r
291                                         {\r
292                                                 chacked = 0;\r
293                                         }\r
294                                         Psychlops.Internal.Main.canvas_flag.Set();\r
295                 //                      prevPool = tmp;\r
296                                 }\r
297                         }\r
298                         System.Threading.Thread.Sleep(0);\r
299                 }\r
300 \r
301                 #region Properties\r
302 \r
303                 public double width { get { return width_; } }\r
304                 public double height { get { return height_; } }\r
305                 public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }\r
306                 public double getWidth() { return width; }\r
307                 public double getHeight() { return height; }\r
308                 public override Point getCenter() { return center; }\r
309                 public double getHCenter() { return width / 2; }\r
310                 public double getVCenter() { return height / 2; }\r
311                 public double getRefreshRate() { return 60; }\r
312 \r
313                 #endregion\r
314 \r
315 \r
316         }\r
317 \r
318 \r
319 \r
320         #region primitive tokenizer\r
321 \r
322         partial struct Point\r
323         {\r
324                 public static implicit operator System.Windows.Point(Point d)\r
325                 {\r
326                         return new System.Windows.Point(d.x, d.y);\r
327                 }\r
328         }\r
329 \r
330         partial struct Color\r
331         {\r
332                 public static implicit operator System.Windows.Media.Color(Color d)\r
333                 {\r
334                         return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));\r
335                 }\r
336                 public static implicit operator System.Windows.Media.SolidColorBrush(Color d)\r
337                 {\r
338                         return new SolidColorBrush { Color = d };\r
339                 }\r
340         }\r
341 \r
342         partial struct Stroke\r
343         {\r
344                 public void apply(System.Windows.Shapes.Shape target)\r
345                 {\r
346                         target.Stroke = this;\r
347                         //target.StrokeDashArray\r
348                         target.StrokeThickness = thick;\r
349                 }\r
350                 public static implicit operator SolidColorBrush(Stroke d)\r
351                 {\r
352                         return new SolidColorBrush { Color = d.color };\r
353                 }\r
354         }\r
355 \r
356         partial class Line\r
357         {\r
358                 public Line dup()\r
359                 {\r
360                         return (Line)MemberwiseClone();\r
361                 }\r
362                 public Line clone()\r
363                 {\r
364                         return (Line)MemberwiseClone();\r
365                 }\r
366                 public static implicit operator System.Windows.Shapes.Line(Line d)\r
367                 {\r
368                         var tmp =  new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };\r
369                         if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;\r
370                         else d.stroke.apply(tmp);\r
371                         return tmp;\r
372                 }\r
373                 public UIElement toNative() { return this; }\r
374 \r
375                 public UIElement poolNative(Canvas d)\r
376                 {\r
377                         var tmp = d.linePool[d.linePoolN];\r
378                         tmp.X1 = begin.x;\r
379                         tmp.Y1 = begin.y;\r
380                         tmp.X2 = end.x;\r
381                         tmp.Y2 = end.y;\r
382                         if (stroke.thick == 0.0) tmp.Stroke = fill;\r
383                         else stroke.apply(tmp);\r
384                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
385                         System.Windows.Controls.Canvas.SetTop(tmp, top);\r
386                         tmp.Visibility = Visibility.Visible;\r
387                         d.linePoolN++;\r
388                         return tmp;\r
389                 }\r
390         }\r
391 \r
392         partial class Rectangle\r
393         {\r
394                 public Rectangle dup()\r
395                 {\r
396                         return (Rectangle)MemberwiseClone();\r
397                 }\r
398                 public Rectangle clone()\r
399                 {\r
400                         return (Rectangle)MemberwiseClone();\r
401                 }\r
402                 public void copyToStack(Templates.StackableDrawable d)\r
403                 {\r
404                         var tmp = d.rectStack[d.rectStackN];\r
405                         tmp.v1 = v1;\r
406                         tmp.v2 = v2;\r
407                         tmp.fill = fill;\r
408                         d.stack[d.stackN] = tmp; \r
409                         d.rectStackN++;\r
410                         d.stackN++;\r
411                 }\r
412                 public static implicit operator System.Windows.Rect(Rectangle d)\r
413                 {\r
414                         return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);\r
415                 }\r
416                 public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)\r
417                 {\r
418                         var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };\r
419                         d.stroke.apply(tmp);\r
420                         System.Windows.Controls.Canvas.SetLeft(tmp, d.left);\r
421                         System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
422                         return tmp;\r
423                 }\r
424                 public UIElement toNative() { return this; }\r
425 \r
426                 public UIElement poolNative(Canvas d)\r
427                 {\r
428                         var tmp = d.rectPool[d.rectPoolN];\r
429                         tmp.Width = width;\r
430                         tmp.Height = height;\r
431                         tmp.Fill = fill;\r
432                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
433                         System.Windows.Controls.Canvas.SetTop(tmp, top);\r
434                         tmp.Visibility = Visibility.Visible;\r
435                         d.rectPoolN++;\r
436                         return tmp;\r
437                 }\r
438         }\r
439 \r
440         partial class Ellipse\r
441         {\r
442                 public Ellipse dup()\r
443                 {\r
444                         return (Ellipse)MemberwiseClone();\r
445                 }\r
446                 public Ellipse clone()\r
447                 {\r
448                         return (Ellipse)MemberwiseClone();\r
449                 }\r
450                 public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)\r
451                 {\r
452                         var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };\r
453                         d.stroke.apply(tmp);\r
454                         System.Windows.Controls.Canvas.SetLeft(tmp, d.left);\r
455                         System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
456                         return tmp;\r
457                 }\r
458                 public UIElement toNative() { return this; }\r
459 \r
460                 public UIElement poolNative(Canvas d)\r
461                 {\r
462 /*                      var tmp = d.rectPool[d.rectPoolN];\r
463                         tmp.Width = width;\r
464                         tmp.Height = height;\r
465                         tmp.Fill = fill;\r
466                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
467                         System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
468                         tmp.Visibility = Visibility.Visible;\r
469                         d.rectPoolN++;\r
470 */\r
471                         return this;\r
472                 }\r
473         }\r
474 \r
475         partial class Polygon\r
476         {\r
477                 public Polygon dup()\r
478                 {\r
479                         return (Polygon)MemberwiseClone();\r
480                 }\r
481                 public Polygon clone()\r
482                 {\r
483                         return (Polygon)MemberwiseClone();\r
484                 }\r
485                 public static implicit operator System.Windows.Shapes.Polygon(Polygon d)\r
486                 {\r
487                         var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };\r
488                         d.stroke.apply(tmp);\r
489                         foreach (Point p in d.vertices)\r
490                         {\r
491                                 tmp.Points.Add(p);\r
492                         }\r
493                         System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);\r
494                         System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);\r
495                         return tmp;\r
496                 }\r
497                 public UIElement toNative() { return this; }\r
498 \r
499                 public UIElement poolNative(Canvas d)\r
500                 {\r
501                         /*                      var tmp = d.rectPool[d.rectPoolN];\r
502                                                 tmp.Width = width;\r
503                                                 tmp.Height = height;\r
504                                                 tmp.Fill = fill;\r
505                                                 System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
506                                                 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
507                                                 tmp.Visibility = Visibility.Visible;\r
508                                                 d.rectPoolN++;\r
509 */\r
510                         return this;\r
511                 }\r
512 \r
513         }\r
514         \r
515         partial class Letters\r
516         {\r
517                 #region static initializer\r
518                 internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;\r
519                 internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;\r
520                 internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;\r
521                 static Letters()\r
522                 {\r
523                         FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();\r
524                         FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);\r
525                         FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);\r
526                         FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();\r
527                         FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);\r
528                         FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);\r
529                         FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);\r
530                         LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();\r
531                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);\r
532                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);\r
533                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);\r
534                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);\r
535                 }\r
536                 #endregion\r
537                 public Letters dup()\r
538                 {\r
539                         return (Letters)MemberwiseClone();\r
540                 }\r
541                 public Letters clone()\r
542                 {\r
543                         return (Letters)MemberwiseClone();\r
544                 }\r
545                 public static implicit operator System.Windows.Controls.TextBlock(Letters d)\r
546                 {\r
547                         //var zapi_shape = new System.Windows.Documents.Glyphs();\r
548                         var tmp = new System.Windows.Controls.TextBlock {\r
549                                 Text = d.str, Width = 500, Height = 500,\r
550                                 FontSize = d.font.size,\r
551                                 //tmp.FontFamily = ,\r
552                                 FontStyle = FONT_STYLE_BRIDGE[d.font.style],\r
553                                 FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],\r
554                                 TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],\r
555                                 Foreground = d.fill\r
556                         };\r
557                         double left = 0;\r
558                         switch (d.align)\r
559                         {\r
560                                 case Letters.HorizontalAlign.left: break;\r
561                                 case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;\r
562                                 case Letters.HorizontalAlign.right: left = tmp.Width; break;\r
563                         }\r
564                         System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);\r
565                         System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);\r
566                         return tmp;\r
567                 }\r
568                 public UIElement toNative() { return this; }\r
569 \r
570                 public UIElement poolNative(Canvas d)\r
571                 {\r
572                         /*                      var tmp = d.rectPool[d.rectPoolN];\r
573                                                 tmp.Width = width;\r
574                                                 tmp.Height = height;\r
575                                                 tmp.Fill = fill;\r
576                                                 System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
577                                                 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
578                                                 tmp.Visibility = Visibility.Visible;\r
579                                                 d.rectPoolN++;\r
580 */\r
581                         return this;\r
582                 }\r
583         }\r
584 \r
585         partial class Image\r
586         {\r
587                 internal void initialize__(int wid, int hei)\r
588                 {\r
589                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei);\r
590                         //buffer = new WriteableBitmap(wid, hei);\r
591                 }\r
592                 internal void create__(int wid, int hei)\r
593                 {\r
594                         buffer = new WriteableBitmap(wid, hei);\r
595                 }\r
596                 delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);\r
597                 delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);\r
598                 public void field__(System.Func<int, int, System.Windows.Media.Color> func)\r
599                 {\r
600                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);\r
601                         //buffer.ForEach(func);\r
602                 }\r
603                 public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
604                 {\r
605                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);\r
606                         //buffer.ForEach(func);\r
607                 }\r
608                 public void field___(System.Func<int, int, System.Windows.Media.Color> func)\r
609                 {\r
610                         buffer.ForEach(func);\r
611                 }\r
612                 public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
613                 {\r
614                         buffer.ForEach(func);\r
615                 }\r
616 \r
617                 public Image clone()\r
618                 {\r
619                         return (Image)MemberwiseClone();\r
620                 }\r
621                 public static implicit operator System.Windows.Controls.Image(Image d)\r
622                 {\r
623                         var tmp = new System.Windows.Controls.Image();\r
624                         tmp.Source = d.buffer;\r
625                         System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);\r
626                         System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);\r
627                         return tmp;\r
628                 }\r
629                 public UIElement toNative() { return this; }\r
630 \r
631                 public UIElement poolNative(Canvas d)\r
632                 {\r
633                         /*                      var tmp = d.rectPool[d.rectPoolN];\r
634                                                 tmp.Width = width;\r
635                                                 tmp.Height = height;\r
636                                                 tmp.Fill = fill;\r
637                                                 System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
638                                                 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
639                                                 tmp.Visibility = Visibility.Visible;\r
640                                                 d.rectPoolN++;\r
641 */\r
642                         return this;\r
643                 }\r
644 \r
645         }\r
646 \r
647         #endregion\r
648 \r
649 \r
650 }