OSDN Git Service

123
[psychlops/silverlight.git] / dev4 / psychlops / core / graphic / canvas.cs
1 using System;\r
2 using System.Windows;\r
3 using System.Windows.Controls;\r
4 using System.Windows.Documents;\r
5 using System.Windows.Input;\r
6 using System.Windows.Media;\r
7 using System.Windows.Media.Animation;\r
8 using System.Windows.Media.Imaging;\r
9 using System.Windows.Shapes;\r
10 using System.Windows.Browser;\r
11 \r
12 \r
13 \r
14 namespace Psychlops\r
15 {\r
16 \r
17         namespace Templates\r
18         {\r
19 \r
20                 public class StackableDrawable : Drawable\r
21                 {\r
22 //                      protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
23                         internal Internal.PrimitiveFigure[] stack;\r
24                         internal int stackN;\r
25                         internal Line[] lineStack;\r
26                         internal int lineStackN;\r
27                         internal Rectangle[] rectStack;\r
28                         internal int rectStackN;\r
29 \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 (UIElement e in api_canvas.Children)\r
276                                                 //{\r
277                                                 //}\r
278 //                                              foreach (Internal.PrimitiveFigure f in stack)\r
279                                                 for (int i = 0; i < stackN - 2; i++)\r
280                                                 {\r
281                                                         //                                                      tmp.Children.Add(f.toNative());\r
282 //                                                      tmp.Children.Add(f.poolNative(this));\r
283                 //                                      tmp.Children.Add(stack[i].poolNative(this));\r
284                                                         System.Windows.Controls.Canvas.SetLeft(api_canvas.Children[i + 1], rectStack[i].left);\r
285                                                         api_canvas.Children[0] = api_canvas.Children[0];\r
286                                                 }\r
287                                                 stackN = 0;\r
288 \r
289                                         }\r
290                 //                      api_canvas.Children.Clear();\r
291                 //                      api_canvas.Children.Add(tmp);\r
292 //                                      stack.Clear();\r
293                                         lock (this)\r
294                                         {\r
295                                                 chacked = 0;\r
296                                         }\r
297                                         Psychlops.Internal.Main.canvas_flag.Set();\r
298                 //                      prevPool = tmp;\r
299                                 }\r
300                         }\r
301                         System.Threading.Thread.Sleep(0);\r
302                 }\r
303 \r
304                 #region Properties\r
305 \r
306                 public double width { get { return width_; } }\r
307                 public double height { get { return height_; } }\r
308                 public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }\r
309                 public double getWidth() { return width; }\r
310                 public double getHeight() { return height; }\r
311                 public override Point getCenter() { return center; }\r
312                 public double getHCenter() { return width / 2; }\r
313                 public double getVCenter() { return height / 2; }\r
314                 public double getRefreshRate() { return 60; }\r
315 \r
316                 #endregion\r
317 \r
318 \r
319         }\r
320 \r
321 \r
322 \r
323         #region primitive tokenizer\r
324 \r
325         partial struct Point\r
326         {\r
327                 public static implicit operator System.Windows.Point(Point d)\r
328                 {\r
329                         return new System.Windows.Point(d.x, d.y);\r
330                 }\r
331         }\r
332 \r
333         partial struct Color\r
334         {\r
335                 public static implicit operator System.Windows.Media.Color(Color d)\r
336                 {\r
337                         return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));\r
338                 }\r
339                 public static implicit operator System.Windows.Media.SolidColorBrush(Color d)\r
340                 {\r
341                         return new SolidColorBrush { Color = d };\r
342                 }\r
343         }\r
344 \r
345         partial struct Stroke\r
346         {\r
347                 public void apply(System.Windows.Shapes.Shape target)\r
348                 {\r
349                         target.Stroke = this;\r
350                         //target.StrokeDashArray\r
351                         target.StrokeThickness = thick;\r
352                 }\r
353                 public static implicit operator SolidColorBrush(Stroke d)\r
354                 {\r
355                         return new SolidColorBrush { Color = d.color };\r
356                 }\r
357         }\r
358 \r
359         partial class Line\r
360         {\r
361                 public Line dup()\r
362                 {\r
363                         return (Line)MemberwiseClone();\r
364                 }\r
365                 public Line clone()\r
366                 {\r
367                         return (Line)MemberwiseClone();\r
368                 }\r
369                 public static implicit operator System.Windows.Shapes.Line(Line d)\r
370                 {\r
371                         var tmp =  new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };\r
372                         if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;\r
373                         else d.stroke.apply(tmp);\r
374                         return tmp;\r
375                 }\r
376                 public UIElement toNative() { return this; }\r
377 \r
378                 public UIElement poolNative(Canvas d)\r
379                 {\r
380                         var tmp = d.linePool[d.linePoolN];\r
381                         tmp.X1 = begin.x;\r
382                         tmp.Y1 = begin.y;\r
383                         tmp.X2 = end.x;\r
384                         tmp.Y2 = end.y;\r
385                         if (stroke.thick == 0.0) tmp.Stroke = fill;\r
386                         else stroke.apply(tmp);\r
387                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
388                         System.Windows.Controls.Canvas.SetTop(tmp, top);\r
389                         tmp.Visibility = Visibility.Visible;\r
390                         d.linePoolN++;\r
391                         return tmp;\r
392                 }\r
393         }\r
394 \r
395         partial class Rectangle\r
396         {\r
397                 public Rectangle dup()\r
398                 {\r
399                         return (Rectangle)MemberwiseClone();\r
400                 }\r
401                 public Rectangle clone()\r
402                 {\r
403                         return (Rectangle)MemberwiseClone();\r
404                 }\r
405                 public void copyToStack(Templates.StackableDrawable d)\r
406                 {\r
407                         var tmp = d.rectStack[d.rectStackN];\r
408                         tmp.v1 = v1;\r
409                         tmp.v2 = v2;\r
410                         tmp.fill = fill;\r
411                         d.stack[d.stackN] = tmp; \r
412                         d.rectStackN++;\r
413                         d.stackN++;\r
414                 }\r
415                 public static implicit operator System.Windows.Rect(Rectangle d)\r
416                 {\r
417                         return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);\r
418                 }\r
419                 public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)\r
420                 {\r
421                         var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };\r
422                         d.stroke.apply(tmp);\r
423                         System.Windows.Controls.Canvas.SetLeft(tmp, d.left);\r
424                         System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
425                         return tmp;\r
426                 }\r
427                 public UIElement toNative() { return this; }\r
428 \r
429                 public UIElement poolNative(Canvas d)\r
430                 {\r
431                         var tmp = d.rectPool[d.rectPoolN];\r
432                         tmp.Width = width;\r
433                         tmp.Height = height;\r
434                         tmp.Fill = fill;\r
435                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
436                         System.Windows.Controls.Canvas.SetTop(tmp, top);\r
437                         tmp.Visibility = Visibility.Visible;\r
438                         d.rectPoolN++;\r
439                         return tmp;\r
440                 }\r
441         }\r
442 \r
443         partial class Ellipse\r
444         {\r
445                 public Ellipse dup()\r
446                 {\r
447                         return (Ellipse)MemberwiseClone();\r
448                 }\r
449                 public Ellipse clone()\r
450                 {\r
451                         return (Ellipse)MemberwiseClone();\r
452                 }\r
453                 public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)\r
454                 {\r
455                         var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };\r
456                         d.stroke.apply(tmp);\r
457                         System.Windows.Controls.Canvas.SetLeft(tmp, d.left);\r
458                         System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
459                         return tmp;\r
460                 }\r
461                 public UIElement toNative() { return this; }\r
462 \r
463                 public UIElement poolNative(Canvas d)\r
464                 {\r
465 /*                      var tmp = d.rectPool[d.rectPoolN];\r
466                         tmp.Width = width;\r
467                         tmp.Height = height;\r
468                         tmp.Fill = fill;\r
469                         System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
470                         System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
471                         tmp.Visibility = Visibility.Visible;\r
472                         d.rectPoolN++;\r
473 */\r
474                         return this;\r
475                 }\r
476         }\r
477 \r
478         partial class Polygon\r
479         {\r
480                 public Polygon dup()\r
481                 {\r
482                         return (Polygon)MemberwiseClone();\r
483                 }\r
484                 public Polygon clone()\r
485                 {\r
486                         return (Polygon)MemberwiseClone();\r
487                 }\r
488                 public static implicit operator System.Windows.Shapes.Polygon(Polygon d)\r
489                 {\r
490                         var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };\r
491                         d.stroke.apply(tmp);\r
492                         foreach (Point p in d.vertices)\r
493                         {\r
494                                 tmp.Points.Add(p);\r
495                         }\r
496                         System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);\r
497                         System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);\r
498                         return tmp;\r
499                 }\r
500                 public UIElement toNative() { return this; }\r
501 \r
502                 public UIElement poolNative(Canvas d)\r
503                 {\r
504                         /*                      var tmp = d.rectPool[d.rectPoolN];\r
505                                                 tmp.Width = width;\r
506                                                 tmp.Height = height;\r
507                                                 tmp.Fill = fill;\r
508                                                 System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
509                                                 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
510                                                 tmp.Visibility = Visibility.Visible;\r
511                                                 d.rectPoolN++;\r
512 */\r
513                         return this;\r
514                 }\r
515 \r
516         }\r
517         \r
518         partial class Letters\r
519         {\r
520                 #region static initializer\r
521                 internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;\r
522                 internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;\r
523                 internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;\r
524                 static Letters()\r
525                 {\r
526                         FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();\r
527                         FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);\r
528                         FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);\r
529                         FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();\r
530                         FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);\r
531                         FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);\r
532                         FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);\r
533                         LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();\r
534                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);\r
535                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);\r
536                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);\r
537                         LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);\r
538                 }\r
539                 #endregion\r
540                 public Letters dup()\r
541                 {\r
542                         return (Letters)MemberwiseClone();\r
543                 }\r
544                 public Letters clone()\r
545                 {\r
546                         return (Letters)MemberwiseClone();\r
547                 }\r
548                 public static implicit operator System.Windows.Controls.TextBlock(Letters d)\r
549                 {\r
550                         //var zapi_shape = new System.Windows.Documents.Glyphs();\r
551                         var tmp = new System.Windows.Controls.TextBlock {\r
552                                 Text = d.str, Width = 500, Height = 500,\r
553                                 FontSize = d.font.size,\r
554                                 //tmp.FontFamily = ,\r
555                                 FontStyle = FONT_STYLE_BRIDGE[d.font.style],\r
556                                 FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],\r
557                                 TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],\r
558                                 Foreground = d.fill\r
559                         };\r
560                         double left = 0;\r
561                         switch (d.align)\r
562                         {\r
563                                 case Letters.HorizontalAlign.left: break;\r
564                                 case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;\r
565                                 case Letters.HorizontalAlign.right: left = tmp.Width; break;\r
566                         }\r
567                         System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);\r
568                         System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);\r
569                         return tmp;\r
570                 }\r
571                 public UIElement toNative() { return this; }\r
572 \r
573                 public UIElement poolNative(Canvas d)\r
574                 {\r
575                         /*                      var tmp = d.rectPool[d.rectPoolN];\r
576                                                 tmp.Width = width;\r
577                                                 tmp.Height = height;\r
578                                                 tmp.Fill = fill;\r
579                                                 System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
580                                                 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
581                                                 tmp.Visibility = Visibility.Visible;\r
582                                                 d.rectPoolN++;\r
583 */\r
584                         return this;\r
585                 }\r
586         }\r
587 \r
588         partial class Image\r
589         {\r
590                 internal void initialize__(int wid, int hei)\r
591                 {\r
592                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei);\r
593                         //buffer = new WriteableBitmap(wid, hei);\r
594                 }\r
595                 internal void create__(int wid, int hei)\r
596                 {\r
597                         buffer = new WriteableBitmap(wid, hei);\r
598                 }\r
599                 delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);\r
600                 delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);\r
601                 public void field__(System.Func<int, int, System.Windows.Media.Color> func)\r
602                 {\r
603                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);\r
604                         //buffer.ForEach(func);\r
605                 }\r
606                 public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
607                 {\r
608                         Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);\r
609                         //buffer.ForEach(func);\r
610                 }\r
611                 public void field___(System.Func<int, int, System.Windows.Media.Color> func)\r
612                 {\r
613                         buffer.ForEach(func);\r
614                 }\r
615                 public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
616                 {\r
617                         buffer.ForEach(func);\r
618                 }\r
619 \r
620                 public Image clone()\r
621                 {\r
622                         return (Image)MemberwiseClone();\r
623                 }\r
624                 public static implicit operator System.Windows.Controls.Image(Image d)\r
625                 {\r
626                         var tmp = new System.Windows.Controls.Image();\r
627                         tmp.Source = d.buffer;\r
628                         System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);\r
629                         System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);\r
630                         return tmp;\r
631                 }\r
632                 public UIElement toNative() { return this; }\r
633 \r
634                 public UIElement poolNative(Canvas d)\r
635                 {\r
636                         /*                      var tmp = d.rectPool[d.rectPoolN];\r
637                                                 tmp.Width = width;\r
638                                                 tmp.Height = height;\r
639                                                 tmp.Fill = fill;\r
640                                                 System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
641                                                 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
642                                                 tmp.Visibility = Visibility.Visible;\r
643                                                 d.rectPoolN++;\r
644 */\r
645                         return this;\r
646                 }\r
647 \r
648         }\r
649 \r
650         #endregion\r
651 \r
652 \r
653 }