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
112 public virtual void group(Group drawee)
\r
114 drawee.copyToStack(this);
\r
117 public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }
\r
118 public virtual void msg(string dstr, double x, double y, Color col)
\r
120 var let = new Letters(dstr);
\r
125 public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }
\r
126 public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }
\r
128 public virtual Point getCenter() { return new Point(0, 0, 0); }
\r
133 public class Canvas : Templates.StackableDrawable
\r
136 internal System.Windows.Controls.Canvas masterPool, prevPool;
\r
137 internal System.Windows.Point[] pointPool;
\r
138 internal int pointPoolN;
\r
139 internal SolidColorBrush[] brushPool;
\r
140 internal int brushPoolN;
\r
142 internal System.Windows.UIElement[] UIElementPool;
\r
143 internal int UIElementPoolN;
\r
145 internal System.Windows.Shapes.Line[] linePool;
\r
146 internal int linePoolN;
\r
147 internal System.Windows.Shapes.Rectangle[] rectPool;
\r
148 internal int rectPoolN;
\r
149 internal System.Windows.Shapes.Ellipse[] ellipsePool;
\r
150 internal int ellipsePoolN;
\r
151 internal System.Windows.Shapes.Polygon[] polygonPool;
\r
152 internal int polygonPoolN;
\r
153 internal System.Windows.Controls.TextBlock[] lettersPool;
\r
154 internal int lettersPoolN;
\r
155 internal System.Windows.Controls.Image[] imagePool;
\r
156 internal int imagePoolN;
\r
158 #region initializer
\r
160 internal delegate void TwoIntProcedure(int x, int y);
\r
161 internal delegate void SimpleProcedure();
\r
162 SimpleProcedure flipexec;
\r
164 //public static System.Windows.Controls.Image default_buffer_frame;
\r
165 public static System.Windows.Controls.UserControl default_panel;
\r
166 public static System.Windows.Controls.Canvas default_api_canvas;
\r
167 public static WriteableBitmap default_buffer;
\r
168 //WriteableBitmap buffer;
\r
169 //System.Windows.Controls.Image instance;
\r
170 System.Windows.Controls.Canvas api_canvas;
\r
171 System.Windows.Controls.UserControl panel;
\r
172 Rectangle back_panel;
\r
173 double width_, height_;
\r
175 public Canvas(int wid, int hei)
\r
177 panel = default_panel;
\r
178 api_canvas = default_api_canvas;
\r
179 initialize(wid, hei);
\r
181 public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs, System.Windows.Controls.UserControl system)
\r
184 api_canvas = apicnvs;
\r
185 initialize(wid, hei);
\r
188 protected bool AsyncInitBool;
\r
189 protected void initialize(int wid, int hei)
\r
191 AsyncInitBool = false;
\r
194 api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);
\r
195 while(!AsyncInitBool)
\r
198 Mouse._prime = api_canvas;
\r
199 Main.drawable = this;
\r
200 Main.canvas = this;
\r
202 back_panel = new Rectangle(wid, hei);
\r
204 flipexec = new SimpleProcedure(executeFlip);
\r
205 AppState.statusBar = "";
\r
207 protected void initialize__(int wid, int hei)
\r
209 api_canvas.Width = wid;
\r
210 api_canvas.Height = hei;
\r
211 api_canvas.MouseMove += Mouse.Canvas_MousePos;
\r
212 api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;
\r
213 api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;
\r
214 api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;
\r
215 panel.KeyDown += Keyboard.Canvas_KeyDown;
\r
216 panel.KeyUp += Keyboard.Canvas_KeyUp;
\r
218 HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");
\r
219 //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");
\r
220 htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");
\r
221 htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px");
\r
222 htmlHost.SetStyleAttribute("margin", "2em auto auto auto");
\r
224 UIElementPool = new System.Windows.UIElement[10000];
\r
225 pointPool = new System.Windows.Point[10000];
\r
226 brushPool = new SolidColorBrush[10000];
\r
227 linePool = new System.Windows.Shapes.Line[10000];
\r
228 rectPool = new System.Windows.Shapes.Rectangle[10000];
\r
229 ellipsePool = new System.Windows.Shapes.Ellipse[10000];
\r
230 for (int i = 0; i < 10000; i++)
\r
232 pointPool[i] = new System.Windows.Point();
\r
233 brushPool[i] = new SolidColorBrush();
\r
234 linePool[i] = new System.Windows.Shapes.Line();
\r
235 rectPool[i] = new System.Windows.Shapes.Rectangle();
\r
236 ellipsePool[i] = new System.Windows.Shapes.Ellipse();
\r
238 polygonPool = new System.Windows.Shapes.Polygon[1000];
\r
239 lettersPool = new System.Windows.Controls.TextBlock[1000];
\r
240 for (int i = 0; i < 1000; i++)
\r
242 polygonPool[i] = new System.Windows.Shapes.Polygon();
\r
243 lettersPool[i] = new System.Windows.Controls.TextBlock();
\r
245 imagePool = new System.Windows.Controls.Image[100];
\r
246 for (int i = 0; i < 100; i++)
\r
248 imagePool[i] = new System.Windows.Controls.Image();
\r
251 masterPool = new System.Windows.Controls.Canvas();
\r
252 prevPool = new System.Windows.Controls.Canvas();
\r
253 api_canvas.Children.Add(masterPool);
\r
254 //api_canvas.Children.Remove(Internal.Main.widgetStack);
\r
257 for (int i = 0; i < 10000; i++)
\r
259 masterPool.Children.Add(UIElementPool[i]);
\r
264 AsyncInitBool = true;
\r
269 #region static initializer
\r
271 static System.Windows.Shapes.Line api_line;
\r
272 static System.Windows.Shapes.Path api_curve;
\r
273 static System.Windows.Shapes.Rectangle api_rect;
\r
274 static System.Windows.Shapes.Ellipse api_ellipse;
\r
275 static System.Windows.Shapes.Polygon api_polygon;
\r
276 static System.Windows.Shapes.Polyline api_polyline;
\r
277 static System.Windows.Media.Color api_color;
\r
278 static System.Windows.Media.SolidColorBrush api_fill;
\r
279 static System.Windows.Media.SolidColorBrush api_stroke;
\r
280 static System.Windows.Media.TranslateTransform api_translation;
\r
283 api_line = new System.Windows.Shapes.Line();
\r
284 api_curve = new System.Windows.Shapes.Path();
\r
285 api_rect = new System.Windows.Shapes.Rectangle();
\r
286 api_ellipse = new System.Windows.Shapes.Ellipse();
\r
287 api_polygon = new System.Windows.Shapes.Polygon();
\r
288 api_polyline = new System.Windows.Shapes.Polyline();
\r
289 api_color = new System.Windows.Media.Color();
\r
290 api_fill = new System.Windows.Media.SolidColorBrush();
\r
291 api_stroke = new System.Windows.Media.SolidColorBrush();
\r
292 api_translation = new System.Windows.Media.TranslateTransform();
\r
298 public override void clear(Color col)
\r
300 back_panel.fill = col;
\r
305 int nextIntervalFrame = 1, chacked = 0;
\r
306 public void flip(int n)
\r
314 nextIntervalFrame = 1;
\r
335 Internal.Main.canvas_flag.WaitOne();
\r
337 #region version modifyNative
\r
338 public void executeFlip()
\r
346 System.Windows.Shapes.Line lineP;
\r
347 System.Windows.Shapes.Rectangle rectP;
\r
348 System.Windows.Shapes.Ellipse ellipseP;
\r
349 System.Windows.Shapes.Polygon polygonP;
\r
350 System.Windows.Controls.TextBlock lettersP;
\r
351 System.Windows.Controls.Image imageP;
\r
355 nextIntervalFrame--;
\r
358 var en = masterPool.Children.GetEnumerator();
\r
359 bool full = en.MoveNext();
\r
360 if (nextIntervalFrame <= 0)
\r
364 //masterPool.Children.Clear();
\r
367 for (int i = 0; i < stackN - 2; i++)
\r
371 masterPool.Children.Add(stack[i].poolNative(this));
\r
375 if( null != (rectS = stack[i] as Rectangle) )
\r
377 if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle))
\r
379 rectS.modifyNative(rectP, this);
\r
382 else if (null != (lineS = stack[i] as Line))
\r
384 if (null != (lineP = en.Current as System.Windows.Shapes.Line))
\r
386 lineS.modifyNative(lineP, this);
\r
389 else if (null != (ellipseS = stack[i] as Ellipse))
\r
391 if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse))
\r
393 ellipseS.modifyNative(ellipseP, this);
\r
396 else if (null != (polygonS = stack[i] as Polygon))
\r
398 if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon))
\r
400 polygonS.modifyNative(polygonP, this);
\r
403 else if (null != (lettersS = stack[i] as Letters))
\r
405 if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock))
\r
407 lettersS.modifyNative(lettersP, this);
\r
410 else if (null != (imageS = stack[i] as Image))
\r
412 if (null != (imageP = en.Current as System.Windows.Controls.Image))
\r
414 imageS.modifyNative(imageP, this);
\r
417 full = en.MoveNext();
\r
426 Psychlops.Internal.Main.canvas_flag.Set();
\r
429 System.Threading.Thread.Sleep(0);
\r
434 #region version poolNative 2
\r
435 public void executeFlip()
\r
440 nextIntervalFrame--;
\r
442 UIElementPoolN = 0;
\r
443 if (nextIntervalFrame <= 0)
\r
447 //masterPool.Children.Clear();
\r
450 for (int i = 0; i < stackN - 2; i++)
\r
452 UIElementPool[UIElementPoolN] = stack[i].poolNative(this);
\r
453 UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;
\r
457 for (int i = stackN - 2; i < 10000; i++)
\r
459 UIElementPool[UIElementPoolN] = rectPool[i];
\r
460 UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed;
\r
469 Psychlops.Internal.Main.canvas_flag.Set();
\r
472 System.Threading.Thread.Sleep(0);
\r
480 public double width { get { return width_; } }
\r
481 public double height { get { return height_; } }
\r
482 public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }
\r
483 public double getWidth() { return width; }
\r
484 public double getHeight() { return height; }
\r
485 public override Point getCenter() { return center; }
\r
486 public double getHCenter() { return width / 2; }
\r
487 public double getVCenter() { return height / 2; }
\r
488 public double getRefreshRate() { return 60; }
\r
497 #region primitive tokenizer
\r
499 partial struct Point
\r
501 public static implicit operator System.Windows.Point(Point d)
\r
503 return new System.Windows.Point(d.x, d.y);
\r
507 partial struct Color
\r
509 public static implicit operator System.Windows.Media.Color(Color d)
\r
511 return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));
\r
513 public static implicit operator System.Windows.Media.SolidColorBrush(Color d)
\r
515 return new SolidColorBrush { Color = d };
\r
519 partial struct Stroke
\r
521 public void apply(System.Windows.Shapes.Shape target)
\r
523 target.Stroke = this;
\r
524 //target.StrokeDashArray
\r
525 target.StrokeThickness = thick;
\r
527 public static implicit operator SolidColorBrush(Stroke d)
\r
529 return new SolidColorBrush { Color = d.color };
\r
537 return (Line)MemberwiseClone();
\r
539 public Line clone()
\r
541 return (Line)MemberwiseClone();
\r
543 public static implicit operator System.Windows.Shapes.Line(Line d)
\r
545 var tmp = new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };
\r
546 if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;
\r
547 else d.stroke.apply(tmp);
\r
550 public UIElement toNative() { return this; }
\r
552 public void copyToStack(Templates.StackableDrawable d)
\r
554 var tmp = d.lineStack[d.lineStackN];
\r
555 tmp.begin.x = begin.x;
\r
556 tmp.begin.y = begin.y;
\r
560 tmp.stroke = stroke;
\r
561 d.stack[d.stackN] = tmp;
\r
565 public UIElement poolNative(Canvas d)
\r
567 var tmp = d.linePool[d.linePoolN];
\r
572 if (stroke.thick == 0.0) tmp.Stroke = fill;
\r
573 else stroke.apply(tmp);
\r
574 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
575 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
576 tmp.Visibility = Visibility.Visible;
\r
580 public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d)
\r
586 if (stroke.thick == 0.0) tmp.Stroke = fill;
\r
587 else stroke.apply(tmp);
\r
588 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
589 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
590 tmp.Visibility = Visibility.Visible;
\r
594 partial class Rectangle
\r
596 public Rectangle dup()
\r
598 return (Rectangle)MemberwiseClone();
\r
600 public Rectangle clone()
\r
602 return (Rectangle)MemberwiseClone();
\r
604 public static implicit operator System.Windows.Rect(Rectangle d)
\r
606 return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);
\r
608 public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)
\r
610 var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };
\r
611 d.stroke.apply(tmp);
\r
612 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
613 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
617 public UIElement toNative() { return this; }
\r
618 public void copyToStack(Templates.StackableDrawable d)
\r
620 var tmp = d.rectStack[d.rectStackN];
\r
624 d.stack[d.stackN] = tmp;
\r
628 public UIElement poolNative(Canvas d)
\r
630 var tmp = d.rectPool[d.rectPoolN];
\r
632 tmp.Height = height;
\r
634 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
635 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
636 tmp.Visibility = Visibility.Visible;
\r
640 public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)
\r
643 tmp.Height = height;
\r
645 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
646 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
647 tmp.Visibility = Visibility.Visible;
\r
651 partial class Ellipse
\r
653 public Ellipse dup()
\r
655 return (Ellipse)MemberwiseClone();
\r
657 public Ellipse clone()
\r
659 return (Ellipse)MemberwiseClone();
\r
661 public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)
\r
663 var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };
\r
664 d.stroke.apply(tmp);
\r
665 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
666 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
670 public UIElement toNative() { return this; }
\r
672 public void copyToStack(Templates.StackableDrawable d)
\r
674 var tmp = d.ellipseStack[d.ellipseStackN];
\r
676 tmp.xdiameter = xdiameter;
\r
677 tmp.ydiameter = ydiameter;
\r
679 d.stack[d.stackN] = tmp;
\r
683 public UIElement poolNative(Canvas d)
\r
685 var tmp = d.ellipsePool[d.ellipsePoolN];
\r
687 tmp.Height = height;
\r
689 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
690 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
691 tmp.Visibility = Visibility.Visible;
\r
695 public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d)
\r
698 tmp.Height = height;
\r
700 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
701 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
702 tmp.Visibility = Visibility.Visible;
\r
706 partial class Polygon
\r
708 public Polygon dup()
\r
710 return (Polygon)MemberwiseClone();
\r
712 public Polygon clone()
\r
714 return (Polygon)MemberwiseClone();
\r
716 public static implicit operator System.Windows.Shapes.Polygon(Polygon d)
\r
718 var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };
\r
719 d.stroke.apply(tmp);
\r
720 foreach (Point p in d.vertices)
\r
724 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
725 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
728 public UIElement toNative() { return this; }
\r
730 public void copyToStack(Templates.StackableDrawable d)
\r
732 var tmp = d.polygonStack[d.polygonStackN];
\r
734 tmp.vertices.Clear();
\r
735 foreach (var v in vertices)
\r
737 tmp.vertices.Add(v);
\r
740 d.stack[d.stackN] = tmp;
\r
744 public UIElement poolNative(Canvas d)
\r
746 var tmp = d.polygonPool[d.polygonPoolN];
\r
748 tmp.Points.Clear();
\r
749 foreach (var v in vertices)
\r
753 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
754 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
755 tmp.Visibility = Visibility.Visible;
\r
759 public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)
\r
762 tmp.Points.Clear();
\r
763 foreach (var v in vertices)
\r
767 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
768 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
769 tmp.Visibility = Visibility.Visible;
\r
774 partial class Letters
\r
776 #region static initializer
\r
777 internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;
\r
778 internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;
\r
779 internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;
\r
782 FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();
\r
783 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);
\r
784 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);
\r
785 FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();
\r
786 FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);
\r
787 FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);
\r
788 FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);
\r
789 LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();
\r
790 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);
\r
791 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);
\r
792 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);
\r
793 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);
\r
796 public Letters dup()
\r
798 return (Letters)MemberwiseClone();
\r
800 public Letters clone()
\r
802 return (Letters)MemberwiseClone();
\r
804 public static implicit operator System.Windows.Controls.TextBlock(Letters d)
\r
806 //var zapi_shape = new System.Windows.Documents.Glyphs();
\r
807 var tmp = new System.Windows.Controls.TextBlock {
\r
808 Text = d.str, Width = 500, Height = 500,
\r
809 FontSize = d.font.size,
\r
810 //tmp.FontFamily = ,
\r
811 FontStyle = FONT_STYLE_BRIDGE[d.font.style],
\r
812 FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],
\r
813 TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],
\r
814 Foreground = d.fill
\r
819 case Letters.HorizontalAlign.left: break;
\r
820 case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;
\r
821 case Letters.HorizontalAlign.right: left = tmp.Width; break;
\r
823 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);
\r
824 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);
\r
827 public UIElement toNative() { return this; }
\r
829 public void copyToStack(Templates.StackableDrawable d)
\r
831 var tmp = d.lettersStack[d.lettersStackN];
\r
835 d.stack[d.stackN] = tmp;
\r
839 public UIElement poolNative(Canvas d)
\r
841 var tmp = d.lettersPool[d.lettersPoolN];
\r
845 tmp.FontSize = font.size;
\r
846 //tmp.FontFamily = ,
\r
847 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
848 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
849 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
850 tmp.Foreground = fill;
\r
851 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
852 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
853 tmp.Visibility = Visibility.Visible;
\r
857 public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d)
\r
862 tmp.FontSize = font.size;
\r
863 //tmp.FontFamily = ,
\r
864 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
865 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
866 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
867 tmp.Foreground = fill;
\r
868 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
869 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
870 tmp.Visibility = Visibility.Visible;
\r
874 partial class Image
\r
876 internal void initialize__(int wid, int hei)
\r
878 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei);
\r
879 //buffer = new WriteableBitmap(wid, hei);
\r
881 internal void create__(int wid, int hei)
\r
883 buffer = new WriteableBitmap(wid, hei);
\r
886 delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);
\r
887 delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);
\r
888 public void field__(System.Func<int, int, System.Windows.Media.Color> func)
\r
890 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);
\r
891 //buffer.ForEach(func);
\r
893 public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
895 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);
\r
896 //buffer.ForEach(func);
\r
898 public void field___(System.Func<int, int, System.Windows.Media.Color> func)
\r
900 buffer.ForEach(func);
\r
902 public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
904 buffer.ForEach(func);
\r
907 public Image clone()
\r
909 return (Image)MemberwiseClone();
\r
911 public static implicit operator System.Windows.Controls.Image(Image d)
\r
913 var tmp = new System.Windows.Controls.Image();
\r
914 tmp.Source = d.buffer;
\r
915 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
916 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
919 public UIElement toNative() { return this; }
\r
921 public void copyToStack(Templates.StackableDrawable d)
\r
923 var tmp = d.imageStack[d.imageStackN];
\r
925 tmp.buffer = buffer;
\r
926 tmp.self_rect = self_rect;
\r
927 d.stack[d.stackN] = tmp;
\r
931 public UIElement poolNative(Canvas d)
\r
933 var tmp = d.imagePool[d.imagePoolN];
\r
934 tmp.Source = buffer;
\r
935 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
936 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
937 tmp.Visibility = Visibility.Visible;
\r
941 public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)
\r
943 tmp.Source = buffer;
\r
944 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
945 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
946 tmp.Visibility = Visibility.Visible;
\r
952 partial class Group
\r
954 internal void initialize__()
\r
956 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.SimpleProcedure(create__));
\r
958 internal void create__()
\r
960 cnvs = new System.Windows.Controls.Canvas();
\r
963 delegate void AppendFunc1(System.Func<Figure> func);
\r
964 public void append__(Shape fig)
\r
968 public Group clone()
\r
970 return (Group)MemberwiseClone();
\r
973 public static implicit operator System.Windows.Controls.Canvas(Group d)
\r
975 var tmp = new System.Windows.Controls.Canvas();
\r
976 /* foreach (var item in list)
\r
978 tmp.Children.Add(d.);
\r
980 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
981 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
984 public UIElement toNative() { return this; }
\r
986 public void copyToStack(Templates.StackableDrawable d)
\r
988 /* var tmp = d.imageStack[d.imageStackN];
\r
990 tmp.buffer = buffer;
\r
991 tmp.self_rect = self_rect;
\r
992 d.stack[d.stackN] = tmp;
\r
996 public UIElement poolNative(Canvas d)
\r
998 /* var tmp = d.imagePool[d.imagePoolN];
\r
999 tmp.Source = buffer;
\r
1000 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1001 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1002 tmp.Visibility = Visibility.Visible;
\r
1006 public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d)
\r
1008 /* tmp.Source = buffer;
\r
1009 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1010 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1011 tmp.Visibility = Visibility.Visible;
\r