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
20 public class StackableDrawable : Drawable
\r
22 // protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;
\r
23 internal Internal.PrimitiveFigure[] stack;
\r
24 internal int stackN;
\r
25 internal Line[] lineStack;
\r
26 internal int lineStackN;
\r
27 internal Rectangle[] rectStack;
\r
28 internal int rectStackN;
\r
29 internal Ellipse[] ellipseStack;
\r
30 internal int ellipseStackN;
\r
31 internal Polygon[] polygonStack;
\r
32 internal int polygonStackN;
\r
33 internal Letters[] lettersStack;
\r
34 internal int lettersStackN;
\r
35 internal Image[] imageStack;
\r
36 internal int imageStackN;
\r
39 public StackableDrawable()
\r
41 // stack = new System.Collections.Generic.Queue<Internal.PrimitiveFigure>();
\r
42 stack = new Internal.PrimitiveFigure[40000];
\r
43 lineStack = new Line[10000];
\r
44 rectStack = new Rectangle[10000];
\r
45 ellipseStack = new Ellipse[10000];
\r
46 polygonStack = new Polygon[1000];
\r
47 lettersStack = new Letters[1000];
\r
48 imageStack = new Image[1000];
\r
49 for (int i = 0; i < 10000; i++)
\r
51 lineStack[i] = new Line(0,0,0,0);
\r
52 rectStack[i] = new Rectangle();
\r
53 ellipseStack[i] = new Ellipse();
\r
55 for (int i = 0; i < 1000; i++)
\r
57 polygonStack[i] = new Polygon();
\r
58 lettersStack[i] = new Letters();
\r
59 imageStack[i] = new Image(1,1);
\r
67 public virtual void clear(Color col)
\r
69 //rect(back_panel, col);
\r
72 public virtual void pix(int x, int y, Color col)
\r
76 public virtual void line(Line drawee)
\r
78 // stack.Enqueue(drawee.clone());
\r
79 drawee.copyToStack(this);
\r
82 public virtual void rect(Rectangle drawee)
\r
84 //stack.Enqueue(drawee.clone());
\r
85 // stack.Enqueue(drawee.copyToStack(this));
\r
86 drawee.copyToStack(this);
\r
89 public virtual void ellipse(Ellipse drawee)
\r
91 // stack.Enqueue(drawee.clone());
\r
92 drawee.copyToStack(this);
\r
95 public virtual void polygon(Polygon drawee)
\r
97 // stack.Enqueue(drawee.clone());
\r
98 drawee.copyToStack(this);
\r
101 public virtual void letters(Letters drawee)
\r
103 // stack.Enqueue(drawee.clone());
\r
104 drawee.copyToStack(this);
\r
107 public virtual void image(Image drawee)
\r
109 // stack.Enqueue(drawee.clone());
\r
110 drawee.copyToStack(this);
\r
113 public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }
\r
114 public virtual void msg(string dstr, double x, double y, Color col)
\r
116 var let = new Letters(dstr);
\r
121 public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }
\r
122 public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }
\r
124 public virtual Point getCenter() { return new Point(0, 0, 0); }
\r
129 public class Canvas : Templates.StackableDrawable
\r
132 internal System.Windows.Controls.Canvas masterPool, prevPool;
\r
133 internal System.Windows.Point[] pointPool;
\r
134 internal int pointPoolN;
\r
135 internal SolidColorBrush[] brushPool;
\r
136 internal int brushPoolN;
\r
138 internal System.Windows.UIElement[] UIElementPool;
\r
139 internal int UIElementPoolN;
\r
141 internal System.Windows.Shapes.Line[] linePool;
\r
142 internal int linePoolN;
\r
143 internal System.Windows.Shapes.Rectangle[] rectPool;
\r
144 internal int rectPoolN;
\r
145 internal System.Windows.Shapes.Ellipse[] ellipsePool;
\r
146 internal int ellipsePoolN;
\r
147 internal System.Windows.Shapes.Polygon[] polygonPool;
\r
148 internal int polygonPoolN;
\r
149 internal System.Windows.Controls.TextBlock[] lettersPool;
\r
150 internal int lettersPoolN;
\r
151 internal System.Windows.Controls.Image[] imagePool;
\r
152 internal int imagePoolN;
\r
154 #region initializer
\r
156 internal delegate void TwoIntProcedure(int x, int y);
\r
157 internal delegate void SimpleProcedure();
\r
158 SimpleProcedure flipexec;
\r
160 //public static System.Windows.Controls.Image default_buffer_frame;
\r
161 public static System.Windows.Controls.UserControl default_panel;
\r
162 public static System.Windows.Controls.Canvas default_api_canvas;
\r
163 public static WriteableBitmap default_buffer;
\r
164 //WriteableBitmap buffer;
\r
165 //System.Windows.Controls.Image instance;
\r
166 System.Windows.Controls.Canvas api_canvas;
\r
167 System.Windows.Controls.UserControl panel;
\r
168 Rectangle back_panel;
\r
169 double width_, height_;
\r
171 public Canvas(int wid, int hei)
\r
173 panel = default_panel;
\r
174 api_canvas = default_api_canvas;
\r
175 initialize(wid, hei);
\r
177 public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs, System.Windows.Controls.UserControl system)
\r
180 api_canvas = apicnvs;
\r
181 initialize(wid, hei);
\r
184 protected bool AsyncInitBool;
\r
185 protected void initialize(int wid, int hei)
\r
187 AsyncInitBool = false;
\r
190 api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);
\r
191 while(!AsyncInitBool)
\r
194 Mouse._prime = api_canvas;
\r
195 Main.drawable = this;
\r
196 Main.canvas = this;
\r
198 back_panel = new Rectangle(wid, hei);
\r
200 flipexec = new SimpleProcedure(executeFlip);
\r
202 protected void initialize__(int wid, int hei)
\r
204 api_canvas.Width = wid;
\r
205 api_canvas.Height = hei;
\r
206 api_canvas.MouseMove += Mouse.Canvas_MousePos;
\r
207 api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;
\r
208 api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;
\r
209 api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;
\r
210 panel.KeyDown += Keyboard.Canvas_KeyDown;
\r
211 panel.KeyUp += Keyboard.Canvas_KeyUp;
\r
213 HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");
\r
214 //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");
\r
215 htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");
\r
216 htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px");
\r
217 htmlHost.SetStyleAttribute("margin", "2em auto auto auto");
\r
219 UIElementPool = new System.Windows.UIElement[10000];
\r
220 pointPool = new System.Windows.Point[10000];
\r
221 brushPool = new SolidColorBrush[10000];
\r
222 linePool = new System.Windows.Shapes.Line[10000];
\r
223 rectPool = new System.Windows.Shapes.Rectangle[10000];
\r
224 ellipsePool = new System.Windows.Shapes.Ellipse[10000];
\r
225 for (int i = 0; i < 10000; i++)
\r
227 pointPool[i] = new System.Windows.Point();
\r
228 brushPool[i] = new SolidColorBrush();
\r
229 linePool[i] = new System.Windows.Shapes.Line();
\r
230 rectPool[i] = new System.Windows.Shapes.Rectangle();
\r
231 ellipsePool[i] = new System.Windows.Shapes.Ellipse();
\r
233 polygonPool = new System.Windows.Shapes.Polygon[1000];
\r
234 lettersPool = new System.Windows.Controls.TextBlock[1000];
\r
235 for (int i = 0; i < 1000; i++)
\r
237 polygonPool[i] = new System.Windows.Shapes.Polygon();
\r
238 lettersPool[i] = new System.Windows.Controls.TextBlock();
\r
240 imagePool = new System.Windows.Controls.Image[100];
\r
241 for (int i = 0; i < 100; i++)
\r
243 imagePool[i] = new System.Windows.Controls.Image();
\r
246 masterPool = new System.Windows.Controls.Canvas();
\r
247 prevPool = new System.Windows.Controls.Canvas();
\r
248 api_canvas.Children.Add(masterPool);
\r
249 //api_canvas.Children.Remove(Internal.Main.widgetStack);
\r
251 for (int i = 0; i < 10000; i++)
\r
253 masterPool.Children.Add(UIElementPool[i]);
\r
257 AsyncInitBool = true;
\r
262 #region static initializer
\r
264 static System.Windows.Shapes.Line api_line;
\r
265 static System.Windows.Shapes.Path api_curve;
\r
266 static System.Windows.Shapes.Rectangle api_rect;
\r
267 static System.Windows.Shapes.Ellipse api_ellipse;
\r
268 static System.Windows.Shapes.Polygon api_polygon;
\r
269 static System.Windows.Shapes.Polyline api_polyline;
\r
270 static System.Windows.Media.Color api_color;
\r
271 static System.Windows.Media.SolidColorBrush api_fill;
\r
272 static System.Windows.Media.SolidColorBrush api_stroke;
\r
273 static System.Windows.Media.TranslateTransform api_translation;
\r
276 api_line = new System.Windows.Shapes.Line();
\r
277 api_curve = new System.Windows.Shapes.Path();
\r
278 api_rect = new System.Windows.Shapes.Rectangle();
\r
279 api_ellipse = new System.Windows.Shapes.Ellipse();
\r
280 api_polygon = new System.Windows.Shapes.Polygon();
\r
281 api_polyline = new System.Windows.Shapes.Polyline();
\r
282 api_color = new System.Windows.Media.Color();
\r
283 api_fill = new System.Windows.Media.SolidColorBrush();
\r
284 api_stroke = new System.Windows.Media.SolidColorBrush();
\r
285 api_translation = new System.Windows.Media.TranslateTransform();
\r
291 public override void clear(Color col)
\r
293 back_panel.fill = col;
\r
298 int nextIntervalFrame = 1, chacked = 0;
\r
299 public void flip(int n)
\r
307 nextIntervalFrame = 1;
\r
328 Internal.Main.canvas_flag.WaitOne();
\r
330 public void executeFlip()
\r
332 #region version modifyNative
\r
339 System.Windows.Shapes.Line lineP;
\r
340 System.Windows.Shapes.Rectangle rectP;
\r
341 System.Windows.Shapes.Ellipse ellipseP;
\r
342 System.Windows.Shapes.Polygon polygonP;
\r
343 System.Windows.Controls.TextBlock lettersP;
\r
344 System.Windows.Controls.Image imageP;
\r
349 nextIntervalFrame--;
\r
352 var en = masterPool.Children.GetEnumerator();
\r
353 bool full = en.MoveNext();
\r
354 UIElementPoolN = 0;
\r
355 if (nextIntervalFrame <= 0)
\r
359 //masterPool.Children.Clear();
\r
362 for (int i = 0; i < stackN - 2; i++)
\r
364 UIElementPool[UIElementPoolN] = stack[i].poolNative(this);
\r
365 UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;
\r
368 #region version modifyNative
\r
372 masterPool.Children.Add(stack[i].poolNative(this));
\r
376 if( null != (rectS = stack[i] as Rectangle) )
\r
378 if ( null != (rectP = en.Current as System.Windows.Shapes.Rectangle) )
\r
380 rectS.modifyNative(rectP, this);
\r
383 else if (null != (lineS = stack[i] as Line))
\r
385 if (null != (lineP = en.Current as System.Windows.Shapes.Line))
\r
387 lineS.modifyNative(lineP, this);
\r
390 else if (null != (ellipseS = stack[i] as Ellipse))
\r
392 if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse))
\r
394 ellipseS.modifyNative(ellipseP, this);
\r
397 else if (null != (polygonS = stack[i] as Polygon))
\r
399 if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon))
\r
401 polygonS.modifyNative(polygonP, this);
\r
404 else if (null != (lettersS = stack[i] as Letters))
\r
406 if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock))
\r
408 lettersS.modifyNative(lettersP, this);
\r
411 else if (null != (imageS = stack[i] as Image))
\r
413 if (null != (imageP = en.Current as System.Windows.Controls.Image))
\r
415 imageS.modifyNative(imageP, this);
\r
418 full = en.MoveNext();
\r
423 for (int i = stackN - 2; i < 10000; i++)
\r
425 UIElementPool[UIElementPoolN] = rectPool[i];
\r
426 UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed;
\r
435 Psychlops.Internal.Main.canvas_flag.Set();
\r
438 System.Threading.Thread.Sleep(0);
\r
445 public double width { get { return width_; } }
\r
446 public double height { get { return height_; } }
\r
447 public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }
\r
448 public double getWidth() { return width; }
\r
449 public double getHeight() { return height; }
\r
450 public override Point getCenter() { return center; }
\r
451 public double getHCenter() { return width / 2; }
\r
452 public double getVCenter() { return height / 2; }
\r
453 public double getRefreshRate() { return 60; }
\r
462 #region primitive tokenizer
\r
464 partial struct Point
\r
466 public static implicit operator System.Windows.Point(Point d)
\r
468 return new System.Windows.Point(d.x, d.y);
\r
472 partial struct Color
\r
474 public static implicit operator System.Windows.Media.Color(Color d)
\r
476 return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));
\r
478 public static implicit operator System.Windows.Media.SolidColorBrush(Color d)
\r
480 return new SolidColorBrush { Color = d };
\r
484 partial struct Stroke
\r
486 public void apply(System.Windows.Shapes.Shape target)
\r
488 target.Stroke = this;
\r
489 //target.StrokeDashArray
\r
490 target.StrokeThickness = thick;
\r
492 public static implicit operator SolidColorBrush(Stroke d)
\r
494 return new SolidColorBrush { Color = d.color };
\r
502 return (Line)MemberwiseClone();
\r
504 public Line clone()
\r
506 return (Line)MemberwiseClone();
\r
508 public static implicit operator System.Windows.Shapes.Line(Line d)
\r
510 var tmp = new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };
\r
511 if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;
\r
512 else d.stroke.apply(tmp);
\r
515 public UIElement toNative() { return this; }
\r
517 public void copyToStack(Templates.StackableDrawable d)
\r
519 var tmp = d.lineStack[d.lineStackN];
\r
520 tmp.begin.x = begin.x;
\r
521 tmp.begin.y = begin.y;
\r
525 tmp.stroke = stroke;
\r
526 d.stack[d.stackN] = tmp;
\r
530 public UIElement poolNative(Canvas d)
\r
532 var tmp = d.linePool[d.linePoolN];
\r
537 if (stroke.thick == 0.0) tmp.Stroke = fill;
\r
538 else stroke.apply(tmp);
\r
539 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
540 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
541 tmp.Visibility = Visibility.Visible;
\r
545 public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d)
\r
551 if (stroke.thick == 0.0) tmp.Stroke = fill;
\r
552 else stroke.apply(tmp);
\r
553 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
554 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
555 tmp.Visibility = Visibility.Visible;
\r
559 partial class Rectangle
\r
561 public Rectangle dup()
\r
563 return (Rectangle)MemberwiseClone();
\r
565 public Rectangle clone()
\r
567 return (Rectangle)MemberwiseClone();
\r
569 public static implicit operator System.Windows.Rect(Rectangle d)
\r
571 return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);
\r
573 public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)
\r
575 var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };
\r
576 d.stroke.apply(tmp);
\r
577 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
578 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
582 public UIElement toNative() { return this; }
\r
583 public void copyToStack(Templates.StackableDrawable d)
\r
585 var tmp = d.rectStack[d.rectStackN];
\r
589 d.stack[d.stackN] = tmp;
\r
593 public UIElement poolNative(Canvas d)
\r
595 var tmp = d.rectPool[d.rectPoolN];
\r
597 tmp.Height = height;
\r
599 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
600 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
601 tmp.Visibility = Visibility.Visible;
\r
605 public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)
\r
608 tmp.Height = height;
\r
610 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
611 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
612 tmp.Visibility = Visibility.Visible;
\r
616 partial class Ellipse
\r
618 public Ellipse dup()
\r
620 return (Ellipse)MemberwiseClone();
\r
622 public Ellipse clone()
\r
624 return (Ellipse)MemberwiseClone();
\r
626 public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)
\r
628 var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };
\r
629 d.stroke.apply(tmp);
\r
630 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
631 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
635 public UIElement toNative() { return this; }
\r
637 public void copyToStack(Templates.StackableDrawable d)
\r
639 var tmp = d.ellipseStack[d.ellipseStackN];
\r
641 tmp.xdiameter = xdiameter;
\r
642 tmp.ydiameter = ydiameter;
\r
644 d.stack[d.stackN] = tmp;
\r
648 public UIElement poolNative(Canvas d)
\r
650 var tmp = d.ellipsePool[d.ellipsePoolN];
\r
652 tmp.Height = height;
\r
654 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
655 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);
\r
656 tmp.Visibility = Visibility.Visible;
\r
660 public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d)
\r
663 tmp.Height = height;
\r
665 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
666 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);
\r
667 tmp.Visibility = Visibility.Visible;
\r
671 partial class Polygon
\r
673 public Polygon dup()
\r
675 return (Polygon)MemberwiseClone();
\r
677 public Polygon clone()
\r
679 return (Polygon)MemberwiseClone();
\r
681 public static implicit operator System.Windows.Shapes.Polygon(Polygon d)
\r
683 var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };
\r
684 d.stroke.apply(tmp);
\r
685 foreach (Point p in d.vertices)
\r
689 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
690 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
693 public UIElement toNative() { return this; }
\r
695 public void copyToStack(Templates.StackableDrawable d)
\r
697 var tmp = d.polygonStack[d.polygonStackN];
\r
699 tmp.vertices.Clear();
\r
700 foreach (var v in vertices)
\r
702 tmp.vertices.Add(v);
\r
705 d.stack[d.stackN] = tmp;
\r
709 public UIElement poolNative(Canvas d)
\r
711 var tmp = d.polygonPool[d.polygonPoolN];
\r
713 tmp.Points.Clear();
\r
714 foreach (var v in vertices)
\r
718 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
719 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);
\r
720 tmp.Visibility = Visibility.Visible;
\r
724 public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)
\r
727 tmp.Points.Clear();
\r
728 foreach (var v in vertices)
\r
732 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
733 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);
\r
734 tmp.Visibility = Visibility.Visible;
\r
739 partial class Letters
\r
741 #region static initializer
\r
742 internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;
\r
743 internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;
\r
744 internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;
\r
747 FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();
\r
748 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);
\r
749 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);
\r
750 FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();
\r
751 FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);
\r
752 FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);
\r
753 FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);
\r
754 LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();
\r
755 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);
\r
756 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);
\r
757 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);
\r
758 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);
\r
761 public Letters dup()
\r
763 return (Letters)MemberwiseClone();
\r
765 public Letters clone()
\r
767 return (Letters)MemberwiseClone();
\r
769 public static implicit operator System.Windows.Controls.TextBlock(Letters d)
\r
771 //var zapi_shape = new System.Windows.Documents.Glyphs();
\r
772 var tmp = new System.Windows.Controls.TextBlock {
\r
773 Text = d.str, Width = 500, Height = 500,
\r
774 FontSize = d.font.size,
\r
775 //tmp.FontFamily = ,
\r
776 FontStyle = FONT_STYLE_BRIDGE[d.font.style],
\r
777 FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],
\r
778 TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],
\r
779 Foreground = d.fill
\r
784 case Letters.HorizontalAlign.left: break;
\r
785 case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;
\r
786 case Letters.HorizontalAlign.right: left = tmp.Width; break;
\r
788 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);
\r
789 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);
\r
792 public UIElement toNative() { return this; }
\r
794 public void copyToStack(Templates.StackableDrawable d)
\r
796 var tmp = d.lettersStack[d.lettersStackN];
\r
800 d.stack[d.stackN] = tmp;
\r
804 public UIElement poolNative(Canvas d)
\r
806 var tmp = d.lettersPool[d.lettersPoolN];
\r
810 tmp.FontSize = font.size;
\r
811 //tmp.FontFamily = ,
\r
812 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
813 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
814 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
815 tmp.Foreground = fill;
\r
816 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
817 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);
\r
818 tmp.Visibility = Visibility.Visible;
\r
822 public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d)
\r
827 tmp.FontSize = font.size;
\r
828 //tmp.FontFamily = ,
\r
829 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
830 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
831 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
832 tmp.Foreground = fill;
\r
833 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
834 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);
\r
835 tmp.Visibility = Visibility.Visible;
\r
839 partial class Image
\r
841 internal void initialize__(int wid, int hei)
\r
843 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei);
\r
844 //buffer = new WriteableBitmap(wid, hei);
\r
846 internal void create__(int wid, int hei)
\r
848 buffer = new WriteableBitmap(wid, hei);
\r
851 delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);
\r
852 delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);
\r
853 public void field__(System.Func<int, int, System.Windows.Media.Color> func)
\r
855 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);
\r
856 //buffer.ForEach(func);
\r
858 public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
860 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);
\r
861 //buffer.ForEach(func);
\r
863 public void field___(System.Func<int, int, System.Windows.Media.Color> func)
\r
865 buffer.ForEach(func);
\r
867 public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
869 buffer.ForEach(func);
\r
872 public Image clone()
\r
874 return (Image)MemberwiseClone();
\r
876 public static implicit operator System.Windows.Controls.Image(Image d)
\r
878 var tmp = new System.Windows.Controls.Image();
\r
879 tmp.Source = d.buffer;
\r
880 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
881 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
884 public UIElement toNative() { return this; }
\r
886 public void copyToStack(Templates.StackableDrawable d)
\r
888 var tmp = d.imageStack[d.imageStackN];
\r
890 tmp.buffer = buffer;
\r
891 tmp.self_rect = self_rect;
\r
892 d.stack[d.stackN] = tmp;
\r
896 public UIElement poolNative(Canvas d)
\r
898 var tmp = d.imagePool[d.imagePoolN];
\r
899 tmp.Source = buffer;
\r
900 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
901 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);
\r
902 tmp.Visibility = Visibility.Visible;
\r
906 public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)
\r
908 throw new Exception("Image.modifyNative");
\r
909 tmp.Source = buffer;
\r
910 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
911 System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y);
\r
912 tmp.Visibility = Visibility.Visible;
\r