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
17 internal static partial class CONST
\r
19 internal static readonly uint MAX_OBJ_N = 1500;
\r
20 internal static readonly uint MOBJ_N = 1000;
\r
21 internal static readonly uint COBJ_N = 300;
\r
22 internal static readonly uint HOBJ_N = 100;
\r
28 public class StackableDrawable : Drawable
\r
30 // protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;
\r
31 internal Internal.PrimitiveFigure[] stack;
\r
32 internal int stackN;
\r
33 internal Line[] lineStack;
\r
34 internal int lineStackN;
\r
35 internal Rectangle[] rectStack;
\r
36 internal int rectStackN;
\r
37 internal Ellipse[] ellipseStack;
\r
38 internal int ellipseStackN;
\r
39 internal Polygon[] polygonStack;
\r
40 internal int polygonStackN;
\r
41 internal Letters[] lettersStack;
\r
42 internal int lettersStackN;
\r
43 internal Image[] imageStack;
\r
44 internal int imageStackN;
\r
45 internal Group[] groupStack;
\r
46 internal int groupStackN;
\r
49 public StackableDrawable()
\r
51 stack = new Internal.PrimitiveFigure[CONST.MAX_OBJ_N];
\r
52 lineStack = new Line[CONST.MOBJ_N];
\r
53 rectStack = new Rectangle[CONST.MOBJ_N];
\r
54 ellipseStack = new Ellipse[CONST.MOBJ_N];
\r
55 polygonStack = new Polygon[CONST.COBJ_N];
\r
56 lettersStack = new Letters[CONST.COBJ_N];
\r
57 imageStack = new Image[CONST.HOBJ_N];
\r
58 groupStack = new Group[CONST.HOBJ_N];
\r
59 for (int i = 0; i < CONST.MOBJ_N; i++)
\r
61 lineStack[i] = new Line(0,0,0,0);
\r
62 rectStack[i] = new Rectangle();
\r
63 ellipseStack[i] = new Ellipse();
\r
65 for (int i = 0; i < CONST.COBJ_N; i++)
\r
67 polygonStack[i] = new Polygon();
\r
68 lettersStack[i] = new Letters();
\r
70 for (int i = 0; i < CONST.HOBJ_N; i++)
\r
72 imageStack[i] = new Image(1, 1);
\r
73 groupStack[i] = new Group();
\r
77 public void clear() { clear(Color.black); }
\r
78 public virtual void clear(Color col) { } //rect(back_panel, col); }
\r
79 public virtual void pix(int x, int y, Color col) { }
\r
80 public virtual void line(Line drawee) { drawee.copyToStack(this); }
\r
81 public virtual void rect(Rectangle drawee) { drawee.copyToStack(this); }
\r
82 public virtual void ellipse(Ellipse drawee) { drawee.copyToStack(this); }
\r
83 public virtual void polygon(Polygon drawee) { drawee.copyToStack(this); }
\r
84 public virtual void letters(Letters drawee) { drawee.copyToStack(this); }
\r
85 public virtual void image(Image drawee) { drawee.copyToStack(this); }
\r
86 public virtual void group(Group drawee) { drawee.copyToStack(this); }
\r
88 public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }
\r
89 public virtual void msg(string dstr, double x, double y, Color col)
\r
91 var let = new Letters(dstr);
\r
96 public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }
\r
97 public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }
\r
99 public virtual Point getCenter() { return new Point(0, 0, 0); }
\r
104 public class Canvas : Templates.StackableDrawable
\r
106 internal System.Windows.Controls.Canvas masterPool, prevPool;
\r
107 internal System.Windows.Point[] pointPool;
\r
108 internal int pointPoolN;
\r
109 internal SolidColorBrush[] brushPool;
\r
110 internal int brushPoolN;
\r
112 internal System.Windows.Controls.Canvas[] UIElementPool;
\r
113 internal int UIElementPoolN;
\r
114 internal int lastVisibleN;
\r
116 internal System.Windows.Shapes.Line[] linePool;
\r
117 internal int linePoolN;
\r
118 internal System.Windows.Shapes.Rectangle[] dummyRectPool;
\r
119 internal System.Windows.Shapes.Rectangle[] rectPool;
\r
120 internal int rectPoolN;
\r
121 internal System.Windows.Shapes.Ellipse[] ellipsePool;
\r
122 internal int ellipsePoolN;
\r
123 internal System.Windows.Shapes.Polygon[] polygonPool;
\r
124 internal int polygonPoolN;
\r
125 internal System.Windows.Controls.TextBlock[] lettersPool;
\r
126 internal int lettersPoolN;
\r
127 internal System.Windows.Controls.Image[] imagePool;
\r
128 internal int imagePoolN;
\r
129 internal System.Windows.Controls.Canvas[] groupPool;
\r
130 internal int groupPoolN;
\r
132 #region initializer
\r
134 internal delegate void TwoIntProcedure(int x, int y);
\r
135 internal delegate void SimpleProcedure();
\r
136 SimpleProcedure flipexec;
\r
138 public static System.Windows.Controls.UserControl default_panel;
\r
139 public static System.Windows.Controls.Canvas default_api_canvas;
\r
140 public static WriteableBitmap default_buffer;
\r
141 System.Windows.Controls.Canvas api_canvas;
\r
142 System.Windows.Controls.UserControl panel;
\r
143 Rectangle back_panel;
\r
144 double width_, height_;
\r
147 public Canvas(int wid, int hei)
\r
149 panel = default_panel;
\r
150 api_canvas = default_api_canvas;
\r
151 initialize(wid, hei);
\r
153 public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs, System.Windows.Controls.UserControl system)
\r
156 api_canvas = apicnvs;
\r
157 initialize(wid, hei);
\r
160 protected bool AsyncInitBool;
\r
161 protected void initialize(int wid, int hei)
\r
163 before = new Clock();
\r
165 AsyncInitBool = false;
\r
168 api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);
\r
169 while(!AsyncInitBool)
\r
172 Mouse._prime = api_canvas;
\r
173 Main.drawable = this;
\r
174 Main.canvas = this;
\r
176 back_panel = new Rectangle(wid, hei);
\r
178 flipexec = new SimpleProcedure(executeFlip);
\r
179 AppState.statusBar = "";
\r
181 protected void initialize__(int wid, int hei)
\r
183 api_canvas.Width = wid;
\r
184 api_canvas.Height = hei+20;
\r
185 api_canvas.MouseMove += Mouse.Canvas_MousePos;
\r
186 api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;
\r
187 api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;
\r
188 api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;
\r
189 panel.KeyDown += Keyboard.Canvas_KeyDown;
\r
190 panel.KeyUp += Keyboard.Canvas_KeyUp;
\r
192 HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");
\r
193 //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");
\r
194 htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");
\r
195 htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px");
\r
196 htmlHost.SetStyleAttribute("margin", "2em auto auto auto");
\r
198 pointPool = new System.Windows.Point[CONST.MOBJ_N];
\r
199 brushPool = new SolidColorBrush[CONST.MOBJ_N];
\r
200 linePool = new System.Windows.Shapes.Line[CONST.MOBJ_N];
\r
201 rectPool = new System.Windows.Shapes.Rectangle[CONST.MOBJ_N];
\r
202 ellipsePool = new System.Windows.Shapes.Ellipse[CONST.MOBJ_N];
\r
203 for (int i = 0; i < CONST.MOBJ_N; i++)
\r
205 pointPool[i] = new System.Windows.Point();
\r
206 brushPool[i] = new SolidColorBrush();
\r
207 linePool[i] = new System.Windows.Shapes.Line();
\r
208 rectPool[i] = new System.Windows.Shapes.Rectangle();
\r
209 ellipsePool[i] = new System.Windows.Shapes.Ellipse();
\r
211 polygonPool = new System.Windows.Shapes.Polygon[CONST.COBJ_N];
\r
212 lettersPool = new System.Windows.Controls.TextBlock[CONST.COBJ_N];
\r
213 for (int i = 0; i < CONST.COBJ_N; i++)
\r
215 polygonPool[i] = new System.Windows.Shapes.Polygon();
\r
216 lettersPool[i] = new System.Windows.Controls.TextBlock();
\r
218 imagePool = new System.Windows.Controls.Image[CONST.HOBJ_N];
\r
219 groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N];
\r
220 for (int i = 0; i < CONST.HOBJ_N; i++)
\r
222 imagePool[i] = new System.Windows.Controls.Image();
\r
223 groupPool[i] = new System.Windows.Controls.Canvas();
\r
226 masterPool = new System.Windows.Controls.Canvas();
\r
227 prevPool = new System.Windows.Controls.Canvas();
\r
228 api_canvas.Children.Add(masterPool);
\r
229 //api_canvas.Children.Remove(Internal.Main.widgetStack);
\r
230 Psychlops.Internal.Main.widgetStack = new StackPanel();
\r
231 Psychlops.Internal.Main.widgetStack.Orientation = Orientation.Vertical;
\r
232 Psychlops.Internal.Main.widgetStack.Height = hei;
\r
233 api_canvas.Children.Add(Psychlops.Internal.Main.widgetStack);
\r
235 UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N];
\r
236 dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N];
\r
237 for (int i = 0; i < CONST.MAX_OBJ_N; i++)
\r
239 UIElementPool[i] = new System.Windows.Controls.Canvas();
\r
240 masterPool.Children.Add(UIElementPool[i]);
\r
241 dummyRectPool[i] = new System.Windows.Shapes.Rectangle();
\r
242 UIElementPool[i].Children.Add(dummyRectPool[i]);
\r
243 dummyRectPool[i].Visibility = Visibility.Collapsed;
\r
247 AsyncInitBool = true;
\r
252 #region static initializer
\r
261 public override void clear(Color col)
\r
263 back_panel.fill = col;
\r
268 int nextIntervalFrame = 1, chacked = 0;
\r
269 public void flip(int n)
\r
273 nextIntervalFrame = n;
\r
285 UIElementPoolN = 0;
\r
300 Internal.Main.canvas_flag.WaitOne();
\r
308 #region version modifyNative2
\r
309 public void executeFlip()
\r
311 Clock after = new Clock();
\r
313 AppState.statusBar = ((after - before).at_msec().ToString()) + " msec";
\r
322 System.Windows.Shapes.Line lineP;
\r
323 System.Windows.Shapes.Rectangle rectP;
\r
324 System.Windows.Shapes.Ellipse ellipseP;
\r
325 System.Windows.Shapes.Polygon polygonP;
\r
326 System.Windows.Controls.TextBlock lettersP;
\r
327 System.Windows.Controls.Image imageP;
\r
328 System.Windows.Controls.Canvas groupP;
\r
332 nextIntervalFrame--;
\r
335 var cnv = UIElementPool[0];
\r
336 if (nextIntervalFrame <= 0)
\r
342 for (int i = 0; i < stackN; i++)
\r
344 if( null != (rectS = stack[i] as Rectangle) )
\r
346 if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle))
\r
348 rectS.modifyNative(rectP, this);
\r
352 cnv.Children.Clear();
\r
353 cnv.Children.Add(stack[i].poolNative(this));
\r
356 else if (null != (lineS = stack[i] as Line))
\r
358 if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line))
\r
360 lineS.modifyNative(lineP, this);
\r
364 cnv.Children.Clear();
\r
365 cnv.Children.Add(stack[i].poolNative(this));
\r
368 else if (null != (ellipseS = stack[i] as Ellipse))
\r
370 if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse))
\r
372 ellipseS.modifyNative(ellipseP, this);
\r
376 cnv.Children.Clear();
\r
377 cnv.Children.Add(stack[i].poolNative(this));
\r
380 else if (null != (polygonS = stack[i] as Polygon))
\r
382 if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon))
\r
384 polygonS.modifyNative(polygonP, this);
\r
388 cnv.Children.Clear();
\r
389 cnv.Children.Add(stack[i].poolNative(this));
\r
392 else if (null != (lettersS = stack[i] as Letters))
\r
394 if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock))
\r
396 lettersS.modifyNative(lettersP, this);
\r
400 cnv.Children.Clear();
\r
401 cnv.Children.Add(stack[i].poolNative(this));
\r
404 else if (null != (imageS = stack[i] as Image))
\r
406 if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image))
\r
408 imageS.modifyNative(imageP, this);
\r
412 cnv.Children.Clear();
\r
413 cnv.Children.Add(stack[i].poolNative(this));
\r
416 else if (null != (groupS = stack[i] as Group))
\r
418 if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas))
\r
420 groupS.modifyNative(groupP, this);
\r
424 cnv.Children.Clear();
\r
425 cnv.Children.Add(stack[i].poolNative(this));
\r
428 cnv.Visibility = Visibility.Visible;
\r
430 cnv = UIElementPool[UIElementPoolN];
\r
432 for (int i = UIElementPoolN; i < lastVisibleN; i++)
\r
434 cnv = UIElementPool[i];
\r
435 cnv.Visibility = Visibility.Collapsed;
\r
437 lastVisibleN = UIElementPoolN;
\r
444 Psychlops.Internal.Main.canvas_flag.Set();
\r
447 System.Threading.Thread.Sleep(0);
\r
451 #region version modifyNative
\r
453 public void executeFlip()
\r
462 System.Windows.Shapes.Line lineP;
\r
463 System.Windows.Shapes.Rectangle rectP;
\r
464 System.Windows.Shapes.Ellipse ellipseP;
\r
465 System.Windows.Shapes.Polygon polygonP;
\r
466 System.Windows.Controls.TextBlock lettersP;
\r
467 System.Windows.Controls.Image imageP;
\r
468 System.Windows.Controls.Canvas groupP;
\r
472 nextIntervalFrame--;
\r
475 var en = masterPool.Children.GetEnumerator();
\r
476 bool full = en.MoveNext();
\r
477 if (nextIntervalFrame <= 0)
\r
481 //masterPool.Children.Clear();
\r
484 for (int i = 0; i < stackN - 2; i++)
\r
488 masterPool.Children.Add(stack[i].poolNative(this));
\r
492 if( null != (rectS = stack[i] as Rectangle) )
\r
494 if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle))
\r
496 rectS.modifyNative(rectP, this);
\r
499 else if (null != (lineS = stack[i] as Line))
\r
501 if (null != (lineP = en.Current as System.Windows.Shapes.Line))
\r
503 lineS.modifyNative(lineP, this);
\r
506 else if (null != (ellipseS = stack[i] as Ellipse))
\r
508 if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse))
\r
510 ellipseS.modifyNative(ellipseP, this);
\r
514 masterPool.Children.Add(stack[i].poolNative(this));
\r
517 else if (null != (polygonS = stack[i] as Polygon))
\r
519 if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon))
\r
521 polygonS.modifyNative(polygonP, this);
\r
524 else if (null != (lettersS = stack[i] as Letters))
\r
526 if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock))
\r
528 lettersS.modifyNative(lettersP, this);
\r
531 else if (null != (imageS = stack[i] as Image))
\r
533 if (null != (imageP = en.Current as System.Windows.Controls.Image))
\r
535 imageS.modifyNative(imageP, this);
\r
538 else if (null != (groupS = stack[i] as Group))
\r
540 if (null != (groupP = en.Current as System.Windows.Controls.Canvas))
\r
542 groupS.modifyNative(groupP, this);
\r
545 full = en.MoveNext();
\r
554 Psychlops.Internal.Main.canvas_flag.Set();
\r
557 System.Threading.Thread.Sleep(0);
\r
562 #region version poolNative 2
\r
564 public void executeFlip()
\r
569 nextIntervalFrame--;
\r
571 UIElementPoolN = 0;
\r
572 if (nextIntervalFrame <= 0)
\r
576 //masterPool.Children.Clear();
\r
579 for (int i = 0; i < stackN - 2; i++)
\r
581 UIElementPool[UIElementPoolN] = stack[i].poolNative(this);
\r
582 UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;
\r
586 for (int i = stackN - 2; i < 10000; i++)
\r
588 UIElementPool[UIElementPoolN] = rectPool[i];
\r
589 UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed;
\r
598 Psychlops.Internal.Main.canvas_flag.Set();
\r
601 System.Threading.Thread.Sleep(0);
\r
609 public double width { get { return width_; } }
\r
610 public double height { get { return height_; } }
\r
611 public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }
\r
612 public double getWidth() { return width; }
\r
613 public double getHeight() { return height; }
\r
614 public override Point getCenter() { return center; }
\r
615 public double getHCenter() { return width / 2; }
\r
616 public double getVCenter() { return height / 2; }
\r
617 public double getRefreshRate() { return 60; }
\r
626 #region primitive tokenizer
\r
628 partial struct Point
\r
630 public static implicit operator System.Windows.Point(Point d)
\r
632 return new System.Windows.Point(d.x, d.y);
\r
636 partial struct Color
\r
638 public static implicit operator System.Windows.Media.Color(Color d)
\r
640 return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));
\r
642 public static implicit operator System.Windows.Media.SolidColorBrush(Color d)
\r
644 return new SolidColorBrush { Color = d };
\r
646 public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)
\r
648 var tmp = d.brushPool[d.brushPoolN];
\r
656 partial struct Stroke
\r
658 public void apply(System.Windows.Shapes.Shape target)
\r
660 target.Stroke = this;
\r
661 //target.StrokeDashArray
\r
662 target.StrokeThickness = thick;
\r
664 public static implicit operator SolidColorBrush(Stroke d)
\r
666 return new SolidColorBrush { Color = d.color };
\r
668 public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)
\r
670 var tmp = d.brushPool[d.brushPoolN];
\r
671 tmp.Color = this.color;
\r
681 return (Line)MemberwiseClone();
\r
683 public Line clone()
\r
685 return (Line)MemberwiseClone();
\r
687 public static implicit operator System.Windows.Shapes.Line(Line d)
\r
689 var tmp = new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };
\r
690 if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;
\r
691 else d.stroke.apply(tmp);
\r
694 public UIElement toNative() { return this; }
\r
696 public void copyToStack(Templates.StackableDrawable d)
\r
698 var tmp = d.lineStack[d.lineStackN];
\r
699 tmp.begin.x = begin.x;
\r
700 tmp.begin.y = begin.y;
\r
704 tmp.stroke = stroke;
\r
705 d.stack[d.stackN] = tmp;
\r
709 public UIElement poolNative(Canvas d)
\r
711 var tmp = d.linePool[d.linePoolN];
\r
716 if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);
\r
717 else stroke.apply(tmp);
\r
718 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
719 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
720 tmp.Visibility = Visibility.Visible;
\r
724 public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d)
\r
730 if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);
\r
731 else stroke.apply(tmp);
\r
732 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
733 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
734 tmp.Visibility = Visibility.Visible;
\r
738 partial class Rectangle
\r
740 public Rectangle dup()
\r
742 return (Rectangle)MemberwiseClone();
\r
744 public Rectangle clone()
\r
746 return (Rectangle)MemberwiseClone();
\r
748 public static implicit operator System.Windows.Rect(Rectangle d)
\r
750 return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);
\r
752 public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)
\r
754 var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };
\r
755 d.stroke.apply(tmp);
\r
756 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
757 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
761 public UIElement toNative() { return this; }
\r
762 public void copyToStack(Templates.StackableDrawable d)
\r
764 var tmp = d.rectStack[d.rectStackN];
\r
768 d.stack[d.stackN] = tmp;
\r
772 public UIElement poolNative(Canvas d)
\r
774 var tmp = d.rectPool[d.rectPoolN];
\r
776 tmp.Height = height;
\r
777 tmp.Fill = fill.getNativeFromStack(d);
\r
778 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
779 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
780 tmp.Visibility = Visibility.Visible;
\r
784 public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)
\r
787 tmp.Height = height;
\r
788 tmp.Fill = fill.getNativeFromStack(d);
\r
789 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
790 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
791 tmp.Visibility = Visibility.Visible;
\r
795 partial class Ellipse
\r
797 public Ellipse dup()
\r
799 return (Ellipse)MemberwiseClone();
\r
801 public Ellipse clone()
\r
803 return (Ellipse)MemberwiseClone();
\r
805 public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)
\r
807 var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };
\r
808 d.stroke.apply(tmp);
\r
809 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
810 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
814 public UIElement toNative() { return this; }
\r
816 public void copyToStack(Templates.StackableDrawable d)
\r
818 var tmp = d.ellipseStack[d.ellipseStackN];
\r
820 tmp.xdiameter = xdiameter;
\r
821 tmp.ydiameter = ydiameter;
\r
823 d.stack[d.stackN] = tmp;
\r
827 public UIElement poolNative(Canvas d)
\r
829 var tmp = d.ellipsePool[d.ellipsePoolN];
\r
831 tmp.Height = height;
\r
832 tmp.Fill = fill.getNativeFromStack(d);
\r
833 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
834 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
835 tmp.Visibility = Visibility.Visible;
\r
839 public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d)
\r
842 tmp.Height = height;
\r
843 tmp.Fill = fill.getNativeFromStack(d);
\r
844 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
845 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
846 tmp.Visibility = Visibility.Visible;
\r
850 partial class Polygon
\r
852 public Polygon dup()
\r
854 return (Polygon)MemberwiseClone();
\r
856 public Polygon clone()
\r
858 return (Polygon)MemberwiseClone();
\r
860 public static implicit operator System.Windows.Shapes.Polygon(Polygon d)
\r
862 var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };
\r
863 d.stroke.apply(tmp);
\r
864 foreach (Point p in d.vertices)
\r
868 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
869 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
872 public UIElement toNative() { return this; }
\r
874 public void copyToStack(Templates.StackableDrawable d)
\r
876 var tmp = d.polygonStack[d.polygonStackN];
\r
878 tmp.vertices.Clear();
\r
879 foreach (var v in vertices)
\r
881 tmp.vertices.Add(v);
\r
884 d.stack[d.stackN] = tmp;
\r
888 public UIElement poolNative(Canvas d)
\r
890 var tmp = d.polygonPool[d.polygonPoolN];
\r
891 tmp.Fill = fill.getNativeFromStack(d);
\r
892 tmp.Points.Clear();
\r
893 foreach (var v in vertices)
\r
897 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
898 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
899 tmp.Visibility = Visibility.Visible;
\r
903 public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)
\r
905 tmp.Fill = fill.getNativeFromStack(d);
\r
906 tmp.Points.Clear();
\r
907 foreach (var v in vertices)
\r
911 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
912 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
913 tmp.Visibility = Visibility.Visible;
\r
918 partial class Letters
\r
920 #region static initializer
\r
921 internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;
\r
922 internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;
\r
923 internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;
\r
926 FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();
\r
927 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);
\r
928 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);
\r
929 FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();
\r
930 FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);
\r
931 FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);
\r
932 FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);
\r
933 LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();
\r
934 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);
\r
935 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);
\r
936 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);
\r
937 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);
\r
940 public Letters dup()
\r
942 return (Letters)MemberwiseClone();
\r
944 public Letters clone()
\r
946 return (Letters)MemberwiseClone();
\r
948 public static implicit operator System.Windows.Controls.TextBlock(Letters d)
\r
950 //var zapi_shape = new System.Windows.Documents.Glyphs();
\r
951 var tmp = new System.Windows.Controls.TextBlock {
\r
952 Text = d.str, Width = 500, Height = 500,
\r
953 FontSize = d.font.size,
\r
954 //tmp.FontFamily = ,
\r
955 FontStyle = FONT_STYLE_BRIDGE[d.font.style],
\r
956 FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],
\r
957 TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],
\r
958 Foreground = d.fill
\r
963 case Letters.HorizontalAlign.left: break;
\r
964 case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;
\r
965 case Letters.HorizontalAlign.right: left = tmp.Width; break;
\r
967 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);
\r
968 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);
\r
971 public UIElement toNative() { return this; }
\r
973 public void copyToStack(Templates.StackableDrawable d)
\r
975 var tmp = d.lettersStack[d.lettersStackN];
\r
979 d.stack[d.stackN] = tmp;
\r
983 public UIElement poolNative(Canvas d)
\r
985 var tmp = d.lettersPool[d.lettersPoolN];
\r
989 tmp.FontSize = font.size;
\r
990 //tmp.FontFamily = ,
\r
991 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
992 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
993 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
994 tmp.Foreground = fill.getNativeFromStack(d);
\r
995 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
996 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
997 tmp.Visibility = Visibility.Visible;
\r
1001 public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d)
\r
1006 tmp.FontSize = font.size;
\r
1007 //tmp.FontFamily = ,
\r
1008 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
1009 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
1010 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
1011 tmp.Foreground = fill.getNativeFromStack(d);
\r
1012 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1013 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1014 tmp.Visibility = Visibility.Visible;
\r
1018 partial class Image
\r
1020 internal void initialize__(int wid, int hei)
\r
1022 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei);
\r
1023 //buffer = new WriteableBitmap(wid, hei);
\r
1025 internal void create__(int wid, int hei)
\r
1027 buffer = new WriteableBitmap(wid, hei);
\r
1030 delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);
\r
1031 delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);
\r
1032 public void field__(System.Func<int, int, System.Windows.Media.Color> func)
\r
1034 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);
\r
1035 //buffer.ForEach(func);
\r
1037 public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
1039 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);
\r
1040 //buffer.ForEach(func);
\r
1042 public void field___(System.Func<int, int, System.Windows.Media.Color> func)
\r
1044 buffer.ForEach(func);
\r
1046 public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
1048 buffer.ForEach(func);
\r
1051 public Image clone()
\r
1053 return (Image)MemberwiseClone();
\r
1055 public static implicit operator System.Windows.Controls.Image(Image d)
\r
1057 var tmp = new System.Windows.Controls.Image();
\r
1058 tmp.Source = d.buffer;
\r
1059 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
1060 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
1063 public UIElement toNative() { return this; }
\r
1065 public void copyToStack(Templates.StackableDrawable d)
\r
1067 var tmp = d.imageStack[d.imageStackN];
\r
1068 tmp.datum = datum;
\r
1069 tmp.buffer = buffer;
\r
1070 tmp.self_rect = self_rect;
\r
1071 d.stack[d.stackN] = tmp;
\r
1075 public UIElement poolNative(Canvas d)
\r
1077 var tmp = d.imagePool[d.imagePoolN];
\r
1078 tmp.Source = buffer;
\r
1079 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1080 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1081 tmp.Visibility = Visibility.Visible;
\r
1085 public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)
\r
1087 tmp.Source = buffer;
\r
1088 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1089 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1090 tmp.Visibility = Visibility.Visible;
\r
1096 partial class Group
\r
1098 internal void initialize__()
\r
1100 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.SimpleProcedure(create__));
\r
1102 internal void create__()
\r
1104 cnvs = new System.Windows.Controls.Canvas();
\r
1105 trans = new System.Windows.Media.TransformGroup();
\r
1106 transF = new System.Windows.Media.TransformCollection();
\r
1107 rotateF = new System.Windows.Media.RotateTransform();
\r
1108 scaleF = new System.Windows.Media.ScaleTransform();
\r
1109 translateF = new System.Windows.Media.TranslateTransform();
\r
1110 transF.Add(rotateF);
\r
1111 transF.Add(scaleF);
\r
1112 transF.Add(translateF);
\r
1113 trans.Children = transF;
\r
1114 cnvs.RenderTransform = trans;
\r
1117 public Group clone()
\r
1119 return (Group)MemberwiseClone();
\r
1122 delegate void AppendFunc1(Internal.PrimitiveFigure func);
\r
1123 void append__(Internal.PrimitiveFigure fig)
\r
1125 fig.centering(0, 0);
\r
1126 UIElement e = fig.toNative();
\r
1127 cnvs.Children.Add(e);
\r
1128 System.Windows.Controls.Canvas.SetLeft(e, fig.datum.x);
\r
1129 System.Windows.Controls.Canvas.SetTop(e, fig.datum.y);
\r
1131 delegate void SimpleProcedure();
\r
1132 void getRotation__() { rotation_ = rotateF.Angle; }
\r
1133 void setRotation__() { rotateF.Angle = rotation_; }
\r
1134 //void getTranslation__() { rotation_ = rotateF.Angle; }
\r
1135 void setTranslation__() { translateF.X = datum.x; translateF.Y = datum.y; }
\r
1136 void setScaling__() { scaleF.ScaleX = scaling_.x; scaleF.ScaleY = scaling_.y; }
\r
1138 public static implicit operator System.Windows.Controls.Canvas(Group d)
\r
1140 var tmp = d.cnvs;//new System.Windows.Controls.Canvas();
\r
1141 System.Windows.Controls.Canvas.SetLeft(d.cnvs, d.datum.x);
\r
1142 System.Windows.Controls.Canvas.SetTop(d.cnvs, d.datum.y);
\r
1145 public UIElement toNative() { return this; }
\r
1147 public void copyToStack(Templates.StackableDrawable d)
\r
1149 var tmp = d.groupStack[d.groupStackN];
\r
1150 tmp.datum = datum;
\r
1152 d.stack[d.stackN] = tmp;
\r
1156 public UIElement poolNative(Canvas d)
\r
1158 //d.groupPool[d.groupPoolN] = cnvs;
\r
1159 //var tmp = d.groupPool[d.groupPoolN];
\r
1161 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1162 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1163 tmp.Visibility = Visibility.Visible;
\r
1167 public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d)
\r
1169 d.groupPool[d.groupPoolN] = cnvs;
\r
1170 System.Windows.Controls.Canvas.SetLeft(cnvs, datum.x);
\r
1171 System.Windows.Controls.Canvas.SetTop(cnvs, datum.y);
\r
1172 tmp.Visibility = Visibility.Visible;
\r