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
37 internal Group[] groupStack;
\r
38 internal int groupStackN;
\r
41 public StackableDrawable()
\r
43 // stack = new System.Collections.Generic.Queue<Internal.PrimitiveFigure>();
\r
44 stack = new Internal.PrimitiveFigure[10000];
\r
45 lineStack = new Line[2000];
\r
46 rectStack = new Rectangle[2000];
\r
47 ellipseStack = new Ellipse[2000];
\r
48 polygonStack = new Polygon[1000];
\r
49 lettersStack = new Letters[1000];
\r
50 imageStack = new Image[100];
\r
51 groupStack = new Group[100];
\r
52 for (int i = 0; i < 2000; i++)
\r
54 lineStack[i] = new Line(0,0,0,0);
\r
55 rectStack[i] = new Rectangle();
\r
56 ellipseStack[i] = new Ellipse();
\r
58 for (int i = 0; i < 1000; i++)
\r
60 polygonStack[i] = new Polygon();
\r
61 lettersStack[i] = new Letters();
\r
63 for (int i = 0; i < 100; i++)
\r
65 imageStack[i] = new Image(1, 1);
\r
66 groupStack[i] = new Group();
\r
74 public virtual void clear(Color col)
\r
76 //rect(back_panel, col);
\r
79 public virtual void pix(int x, int y, Color col)
\r
83 public virtual void line(Line drawee)
\r
85 // stack.Enqueue(drawee.clone());
\r
86 drawee.copyToStack(this);
\r
89 public virtual void rect(Rectangle drawee)
\r
91 //stack.Enqueue(drawee.clone());
\r
92 // stack.Enqueue(drawee.copyToStack(this));
\r
93 drawee.copyToStack(this);
\r
96 public virtual void ellipse(Ellipse drawee)
\r
98 // stack.Enqueue(drawee.clone());
\r
99 drawee.copyToStack(this);
\r
102 public virtual void polygon(Polygon drawee)
\r
104 // stack.Enqueue(drawee.clone());
\r
105 drawee.copyToStack(this);
\r
108 public virtual void letters(Letters drawee)
\r
110 // stack.Enqueue(drawee.clone());
\r
111 drawee.copyToStack(this);
\r
114 public virtual void image(Image drawee)
\r
116 // stack.Enqueue(drawee.clone());
\r
117 drawee.copyToStack(this);
\r
119 public virtual void group(Group drawee)
\r
121 drawee.copyToStack(this);
\r
124 public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }
\r
125 public virtual void msg(string dstr, double x, double y, Color col)
\r
127 var let = new Letters(dstr);
\r
132 public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }
\r
133 public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }
\r
135 public virtual Point getCenter() { return new Point(0, 0, 0); }
\r
140 public class Canvas : Templates.StackableDrawable
\r
143 internal System.Windows.Controls.Canvas masterPool, prevPool;
\r
144 internal System.Windows.Point[] pointPool;
\r
145 internal int pointPoolN;
\r
146 internal SolidColorBrush[] brushPool;
\r
147 internal int brushPoolN;
\r
149 internal System.Windows.Controls.Canvas[] UIElementPool;
\r
150 internal int UIElementPoolN;
\r
152 internal System.Windows.Shapes.Line[] linePool;
\r
153 internal int linePoolN;
\r
154 internal System.Windows.Shapes.Rectangle[] dummyRectPool;
\r
155 internal System.Windows.Shapes.Rectangle[] rectPool;
\r
156 internal int rectPoolN;
\r
157 internal System.Windows.Shapes.Ellipse[] ellipsePool;
\r
158 internal int ellipsePoolN;
\r
159 internal System.Windows.Shapes.Polygon[] polygonPool;
\r
160 internal int polygonPoolN;
\r
161 internal System.Windows.Controls.TextBlock[] lettersPool;
\r
162 internal int lettersPoolN;
\r
163 internal System.Windows.Controls.Image[] imagePool;
\r
164 internal int imagePoolN;
\r
165 internal System.Windows.Controls.Canvas[] groupPool;
\r
166 internal int groupPoolN;
\r
168 #region initializer
\r
170 internal delegate void TwoIntProcedure(int x, int y);
\r
171 internal delegate void SimpleProcedure();
\r
172 SimpleProcedure flipexec;
\r
174 //public static System.Windows.Controls.Image default_buffer_frame;
\r
175 public static System.Windows.Controls.UserControl default_panel;
\r
176 public static System.Windows.Controls.Canvas default_api_canvas;
\r
177 public static WriteableBitmap default_buffer;
\r
178 //WriteableBitmap buffer;
\r
179 //System.Windows.Controls.Image instance;
\r
180 System.Windows.Controls.Canvas api_canvas;
\r
181 System.Windows.Controls.UserControl panel;
\r
182 Rectangle back_panel;
\r
183 double width_, height_;
\r
186 public Canvas(int wid, int hei)
\r
188 panel = default_panel;
\r
189 api_canvas = default_api_canvas;
\r
190 initialize(wid, hei);
\r
192 public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs, System.Windows.Controls.UserControl system)
\r
195 api_canvas = apicnvs;
\r
196 initialize(wid, hei);
\r
199 protected bool AsyncInitBool;
\r
200 protected void initialize(int wid, int hei)
\r
202 before = new Clock();
\r
204 AsyncInitBool = false;
\r
207 api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);
\r
208 while(!AsyncInitBool)
\r
211 Mouse._prime = api_canvas;
\r
212 Main.drawable = this;
\r
213 Main.canvas = this;
\r
215 back_panel = new Rectangle(wid, hei);
\r
217 flipexec = new SimpleProcedure(executeFlip);
\r
218 AppState.statusBar = "";
\r
220 protected void initialize__(int wid, int hei)
\r
222 api_canvas.Width = wid;
\r
223 api_canvas.Height = hei+20;
\r
224 api_canvas.MouseMove += Mouse.Canvas_MousePos;
\r
225 api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;
\r
226 api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;
\r
227 api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;
\r
228 panel.KeyDown += Keyboard.Canvas_KeyDown;
\r
229 panel.KeyUp += Keyboard.Canvas_KeyUp;
\r
231 HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");
\r
232 //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");
\r
233 htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");
\r
234 htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px");
\r
235 htmlHost.SetStyleAttribute("margin", "2em auto auto auto");
\r
237 UIElementPool = new System.Windows.Controls.Canvas[2000];
\r
238 pointPool = new System.Windows.Point[2000];
\r
239 brushPool = new SolidColorBrush[2000];
\r
240 linePool = new System.Windows.Shapes.Line[2000];
\r
241 rectPool = new System.Windows.Shapes.Rectangle[2000];
\r
242 dummyRectPool = new System.Windows.Shapes.Rectangle[2000];
\r
243 ellipsePool = new System.Windows.Shapes.Ellipse[2000];
\r
244 for (int i = 0; i < 2000; i++)
\r
246 UIElementPool[i] = new System.Windows.Controls.Canvas();
\r
247 pointPool[i] = new System.Windows.Point();
\r
248 brushPool[i] = new SolidColorBrush();
\r
249 linePool[i] = new System.Windows.Shapes.Line();
\r
250 rectPool[i] = new System.Windows.Shapes.Rectangle();
\r
251 dummyRectPool[i] = new System.Windows.Shapes.Rectangle();
\r
252 ellipsePool[i] = new System.Windows.Shapes.Ellipse();
\r
254 polygonPool = new System.Windows.Shapes.Polygon[1000];
\r
255 lettersPool = new System.Windows.Controls.TextBlock[1000];
\r
256 for (int i = 0; i < 1000; i++)
\r
258 polygonPool[i] = new System.Windows.Shapes.Polygon();
\r
259 lettersPool[i] = new System.Windows.Controls.TextBlock();
\r
261 imagePool = new System.Windows.Controls.Image[100];
\r
262 groupPool = new System.Windows.Controls.Canvas[100];
\r
263 for (int i = 0; i < 100; i++)
\r
265 imagePool[i] = new System.Windows.Controls.Image();
\r
266 groupPool[i] = new System.Windows.Controls.Canvas();
\r
269 masterPool = new System.Windows.Controls.Canvas();
\r
270 prevPool = new System.Windows.Controls.Canvas();
\r
271 api_canvas.Children.Add(masterPool);
\r
272 //api_canvas.Children.Remove(Internal.Main.widgetStack);
\r
274 for (int i = 0; i < 2000; i++)
\r
276 masterPool.Children.Add(UIElementPool[i]);
\r
277 UIElementPool[i].Children.Add(dummyRectPool[i]);
\r
281 AsyncInitBool = true;
\r
286 #region static initializer
\r
288 static System.Windows.Shapes.Line api_line;
\r
289 static System.Windows.Shapes.Path api_curve;
\r
290 static System.Windows.Shapes.Rectangle api_rect;
\r
291 static System.Windows.Shapes.Ellipse api_ellipse;
\r
292 static System.Windows.Shapes.Polygon api_polygon;
\r
293 static System.Windows.Shapes.Polyline api_polyline;
\r
294 static System.Windows.Media.Color api_color;
\r
295 static System.Windows.Media.SolidColorBrush api_fill;
\r
296 static System.Windows.Media.SolidColorBrush api_stroke;
\r
297 static System.Windows.Media.TranslateTransform api_translation;
\r
300 api_line = new System.Windows.Shapes.Line();
\r
301 api_curve = new System.Windows.Shapes.Path();
\r
302 api_rect = new System.Windows.Shapes.Rectangle();
\r
303 api_ellipse = new System.Windows.Shapes.Ellipse();
\r
304 api_polygon = new System.Windows.Shapes.Polygon();
\r
305 api_polyline = new System.Windows.Shapes.Polyline();
\r
306 api_color = new System.Windows.Media.Color();
\r
307 api_fill = new System.Windows.Media.SolidColorBrush();
\r
308 api_stroke = new System.Windows.Media.SolidColorBrush();
\r
309 api_translation = new System.Windows.Media.TranslateTransform();
\r
315 public override void clear(Color col)
\r
317 back_panel.fill = col;
\r
322 int nextIntervalFrame = 1, chacked = 0;
\r
323 public void flip(int n)
\r
327 nextIntervalFrame = n;
\r
353 Internal.Main.canvas_flag.WaitOne();
\r
361 #region version modifyNative2
\r
362 public void executeFlip()
\r
364 Clock after = new Clock();
\r
366 AppState.statusBar = ((after - before).at_msec().ToString()) + " msec";
\r
375 System.Windows.Shapes.Line lineP;
\r
376 System.Windows.Shapes.Rectangle rectP;
\r
377 System.Windows.Shapes.Ellipse ellipseP;
\r
378 System.Windows.Shapes.Polygon polygonP;
\r
379 System.Windows.Controls.TextBlock lettersP;
\r
380 System.Windows.Controls.Image imageP;
\r
381 System.Windows.Controls.Canvas groupP;
\r
385 nextIntervalFrame--;
\r
390 var en = masterPool.Children.GetEnumerator();
\r
391 bool full = en.MoveNext();
\r
392 var cnv = en.Current as System.Windows.Controls.Canvas;
\r
393 if (nextIntervalFrame <= 0)
\r
399 for (int i = 0; i < stackN - 2; i++)
\r
407 if( null != (rectS = stack[i] as Rectangle) )
\r
409 if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle))
\r
411 rectS.modifyNative(rectP, this);
\r
415 cnv.Children.Clear();
\r
416 cnv.Children.Add(stack[i].poolNative(this));
\r
419 else if (null != (lineS = stack[i] as Line))
\r
421 if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line))
\r
423 lineS.modifyNative(lineP, this);
\r
427 cnv.Children.Clear();
\r
428 cnv.Children.Add(stack[i].poolNative(this));
\r
431 else if (null != (ellipseS = stack[i] as Ellipse))
\r
433 if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse))
\r
435 ellipseS.modifyNative(ellipseP, this);
\r
439 cnv.Children.Clear();
\r
440 cnv.Children.Add(stack[i].poolNative(this));
\r
443 else if (null != (polygonS = stack[i] as Polygon))
\r
445 if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon))
\r
447 polygonS.modifyNative(polygonP, this);
\r
451 cnv.Children.Clear();
\r
452 cnv.Children.Add(stack[i].poolNative(this));
\r
455 else if (null != (lettersS = stack[i] as Letters))
\r
457 if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock))
\r
459 lettersS.modifyNative(lettersP, this);
\r
463 cnv.Children.Clear();
\r
464 cnv.Children.Add(stack[i].poolNative(this));
\r
467 else if (null != (imageS = stack[i] as Image))
\r
469 if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image))
\r
471 imageS.modifyNative(imageP, this);
\r
475 cnv.Children.Clear();
\r
476 cnv.Children.Add(stack[i].poolNative(this));
\r
479 else if (null != (groupS = stack[i] as Group))
\r
481 if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas))
\r
483 groupS.modifyNative(groupP, this);
\r
487 cnv.Children.Clear();
\r
488 cnv.Children.Add(stack[i].poolNative(this));
\r
491 full = en.MoveNext();
\r
492 cnv = en.Current as System.Windows.Controls.Canvas;
\r
501 Psychlops.Internal.Main.canvas_flag.Set();
\r
504 System.Threading.Thread.Sleep(0);
\r
508 #region version modifyNative
\r
510 public void executeFlip()
\r
519 System.Windows.Shapes.Line lineP;
\r
520 System.Windows.Shapes.Rectangle rectP;
\r
521 System.Windows.Shapes.Ellipse ellipseP;
\r
522 System.Windows.Shapes.Polygon polygonP;
\r
523 System.Windows.Controls.TextBlock lettersP;
\r
524 System.Windows.Controls.Image imageP;
\r
525 System.Windows.Controls.Canvas groupP;
\r
529 nextIntervalFrame--;
\r
532 var en = masterPool.Children.GetEnumerator();
\r
533 bool full = en.MoveNext();
\r
534 if (nextIntervalFrame <= 0)
\r
538 //masterPool.Children.Clear();
\r
541 for (int i = 0; i < stackN - 2; i++)
\r
545 masterPool.Children.Add(stack[i].poolNative(this));
\r
549 if( null != (rectS = stack[i] as Rectangle) )
\r
551 if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle))
\r
553 rectS.modifyNative(rectP, this);
\r
556 else if (null != (lineS = stack[i] as Line))
\r
558 if (null != (lineP = en.Current as System.Windows.Shapes.Line))
\r
560 lineS.modifyNative(lineP, this);
\r
563 else if (null != (ellipseS = stack[i] as Ellipse))
\r
565 if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse))
\r
567 ellipseS.modifyNative(ellipseP, this);
\r
571 masterPool.Children.Add(stack[i].poolNative(this));
\r
574 else if (null != (polygonS = stack[i] as Polygon))
\r
576 if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon))
\r
578 polygonS.modifyNative(polygonP, this);
\r
581 else if (null != (lettersS = stack[i] as Letters))
\r
583 if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock))
\r
585 lettersS.modifyNative(lettersP, this);
\r
588 else if (null != (imageS = stack[i] as Image))
\r
590 if (null != (imageP = en.Current as System.Windows.Controls.Image))
\r
592 imageS.modifyNative(imageP, this);
\r
595 else if (null != (groupS = stack[i] as Group))
\r
597 if (null != (groupP = en.Current as System.Windows.Controls.Canvas))
\r
599 groupS.modifyNative(groupP, this);
\r
602 full = en.MoveNext();
\r
611 Psychlops.Internal.Main.canvas_flag.Set();
\r
614 System.Threading.Thread.Sleep(0);
\r
619 #region version poolNative 2
\r
621 public void executeFlip()
\r
626 nextIntervalFrame--;
\r
628 UIElementPoolN = 0;
\r
629 if (nextIntervalFrame <= 0)
\r
633 //masterPool.Children.Clear();
\r
636 for (int i = 0; i < stackN - 2; i++)
\r
638 UIElementPool[UIElementPoolN] = stack[i].poolNative(this);
\r
639 UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;
\r
643 for (int i = stackN - 2; i < 10000; i++)
\r
645 UIElementPool[UIElementPoolN] = rectPool[i];
\r
646 UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed;
\r
655 Psychlops.Internal.Main.canvas_flag.Set();
\r
658 System.Threading.Thread.Sleep(0);
\r
666 public double width { get { return width_; } }
\r
667 public double height { get { return height_; } }
\r
668 public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }
\r
669 public double getWidth() { return width; }
\r
670 public double getHeight() { return height; }
\r
671 public override Point getCenter() { return center; }
\r
672 public double getHCenter() { return width / 2; }
\r
673 public double getVCenter() { return height / 2; }
\r
674 public double getRefreshRate() { return 60; }
\r
683 #region primitive tokenizer
\r
685 partial struct Point
\r
687 public static implicit operator System.Windows.Point(Point d)
\r
689 return new System.Windows.Point(d.x, d.y);
\r
693 partial struct Color
\r
695 public static implicit operator System.Windows.Media.Color(Color d)
\r
697 return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));
\r
699 public static implicit operator System.Windows.Media.SolidColorBrush(Color d)
\r
701 return new SolidColorBrush { Color = d };
\r
705 partial struct Stroke
\r
707 public void apply(System.Windows.Shapes.Shape target)
\r
709 target.Stroke = this;
\r
710 //target.StrokeDashArray
\r
711 target.StrokeThickness = thick;
\r
713 public static implicit operator SolidColorBrush(Stroke d)
\r
715 return new SolidColorBrush { Color = d.color };
\r
723 return (Line)MemberwiseClone();
\r
725 public Line clone()
\r
727 return (Line)MemberwiseClone();
\r
729 public static implicit operator System.Windows.Shapes.Line(Line d)
\r
731 var tmp = new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };
\r
732 if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;
\r
733 else d.stroke.apply(tmp);
\r
736 public UIElement toNative() { return this; }
\r
738 public void copyToStack(Templates.StackableDrawable d)
\r
740 var tmp = d.lineStack[d.lineStackN];
\r
741 tmp.begin.x = begin.x;
\r
742 tmp.begin.y = begin.y;
\r
746 tmp.stroke = stroke;
\r
747 d.stack[d.stackN] = tmp;
\r
751 public UIElement poolNative(Canvas d)
\r
753 var tmp = d.linePool[d.linePoolN];
\r
758 if (stroke.thick == 0.0) tmp.Stroke = fill;
\r
759 else stroke.apply(tmp);
\r
760 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
761 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
762 tmp.Visibility = Visibility.Visible;
\r
766 public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d)
\r
772 if (stroke.thick == 0.0) tmp.Stroke = fill;
\r
773 else stroke.apply(tmp);
\r
774 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
775 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
776 tmp.Visibility = Visibility.Visible;
\r
780 partial class Rectangle
\r
782 public Rectangle dup()
\r
784 return (Rectangle)MemberwiseClone();
\r
786 public Rectangle clone()
\r
788 return (Rectangle)MemberwiseClone();
\r
790 public static implicit operator System.Windows.Rect(Rectangle d)
\r
792 return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);
\r
794 public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)
\r
796 var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };
\r
797 d.stroke.apply(tmp);
\r
798 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
799 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
803 public UIElement toNative() { return this; }
\r
804 public void copyToStack(Templates.StackableDrawable d)
\r
806 var tmp = d.rectStack[d.rectStackN];
\r
810 d.stack[d.stackN] = tmp;
\r
814 public UIElement poolNative(Canvas d)
\r
816 var tmp = d.rectPool[d.rectPoolN];
\r
818 tmp.Height = height;
\r
820 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
821 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
822 tmp.Visibility = Visibility.Visible;
\r
826 public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)
\r
829 tmp.Height = height;
\r
831 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
832 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
833 tmp.Visibility = Visibility.Visible;
\r
837 partial class Ellipse
\r
839 public Ellipse dup()
\r
841 return (Ellipse)MemberwiseClone();
\r
843 public Ellipse clone()
\r
845 return (Ellipse)MemberwiseClone();
\r
847 public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)
\r
849 var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };
\r
850 d.stroke.apply(tmp);
\r
851 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
852 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
856 public UIElement toNative() { return this; }
\r
858 public void copyToStack(Templates.StackableDrawable d)
\r
860 var tmp = d.ellipseStack[d.ellipseStackN];
\r
862 tmp.xdiameter = xdiameter;
\r
863 tmp.ydiameter = ydiameter;
\r
865 d.stack[d.stackN] = tmp;
\r
869 public UIElement poolNative(Canvas d)
\r
871 var tmp = d.ellipsePool[d.ellipsePoolN];
\r
873 tmp.Height = height;
\r
875 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
876 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
877 tmp.Visibility = Visibility.Visible;
\r
881 public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d)
\r
884 tmp.Height = height;
\r
886 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
887 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
888 tmp.Visibility = Visibility.Visible;
\r
892 partial class Polygon
\r
894 public Polygon dup()
\r
896 return (Polygon)MemberwiseClone();
\r
898 public Polygon clone()
\r
900 return (Polygon)MemberwiseClone();
\r
902 public static implicit operator System.Windows.Shapes.Polygon(Polygon d)
\r
904 var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };
\r
905 d.stroke.apply(tmp);
\r
906 foreach (Point p in d.vertices)
\r
910 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
911 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
914 public UIElement toNative() { return this; }
\r
916 public void copyToStack(Templates.StackableDrawable d)
\r
918 var tmp = d.polygonStack[d.polygonStackN];
\r
920 tmp.vertices.Clear();
\r
921 foreach (var v in vertices)
\r
923 tmp.vertices.Add(v);
\r
926 d.stack[d.stackN] = tmp;
\r
930 public UIElement poolNative(Canvas d)
\r
932 var tmp = d.polygonPool[d.polygonPoolN];
\r
934 tmp.Points.Clear();
\r
935 foreach (var v in vertices)
\r
939 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
940 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
941 tmp.Visibility = Visibility.Visible;
\r
945 public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)
\r
948 tmp.Points.Clear();
\r
949 foreach (var v in vertices)
\r
953 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
954 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
955 tmp.Visibility = Visibility.Visible;
\r
960 partial class Letters
\r
962 #region static initializer
\r
963 internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;
\r
964 internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;
\r
965 internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;
\r
968 FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();
\r
969 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);
\r
970 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);
\r
971 FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();
\r
972 FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);
\r
973 FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);
\r
974 FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);
\r
975 LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();
\r
976 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);
\r
977 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);
\r
978 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);
\r
979 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);
\r
982 public Letters dup()
\r
984 return (Letters)MemberwiseClone();
\r
986 public Letters clone()
\r
988 return (Letters)MemberwiseClone();
\r
990 public static implicit operator System.Windows.Controls.TextBlock(Letters d)
\r
992 //var zapi_shape = new System.Windows.Documents.Glyphs();
\r
993 var tmp = new System.Windows.Controls.TextBlock {
\r
994 Text = d.str, Width = 500, Height = 500,
\r
995 FontSize = d.font.size,
\r
996 //tmp.FontFamily = ,
\r
997 FontStyle = FONT_STYLE_BRIDGE[d.font.style],
\r
998 FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],
\r
999 TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],
\r
1000 Foreground = d.fill
\r
1005 case Letters.HorizontalAlign.left: break;
\r
1006 case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;
\r
1007 case Letters.HorizontalAlign.right: left = tmp.Width; break;
\r
1009 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);
\r
1010 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);
\r
1013 public UIElement toNative() { return this; }
\r
1015 public void copyToStack(Templates.StackableDrawable d)
\r
1017 var tmp = d.lettersStack[d.lettersStackN];
\r
1019 tmp.datum = datum;
\r
1021 d.stack[d.stackN] = tmp;
\r
1022 d.lettersStackN++;
\r
1025 public UIElement poolNative(Canvas d)
\r
1027 var tmp = d.lettersPool[d.lettersPoolN];
\r
1031 tmp.FontSize = font.size;
\r
1032 //tmp.FontFamily = ,
\r
1033 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
1034 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
1035 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
1036 tmp.Foreground = fill;
\r
1037 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1038 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1039 tmp.Visibility = Visibility.Visible;
\r
1043 public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d)
\r
1048 tmp.FontSize = font.size;
\r
1049 //tmp.FontFamily = ,
\r
1050 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
1051 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
1052 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
1053 tmp.Foreground = fill;
\r
1054 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1055 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1056 tmp.Visibility = Visibility.Visible;
\r
1060 partial class Image
\r
1062 internal void initialize__(int wid, int hei)
\r
1064 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei);
\r
1065 //buffer = new WriteableBitmap(wid, hei);
\r
1067 internal void create__(int wid, int hei)
\r
1069 buffer = new WriteableBitmap(wid, hei);
\r
1072 delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);
\r
1073 delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);
\r
1074 public void field__(System.Func<int, int, System.Windows.Media.Color> func)
\r
1076 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);
\r
1077 //buffer.ForEach(func);
\r
1079 public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
1081 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);
\r
1082 //buffer.ForEach(func);
\r
1084 public void field___(System.Func<int, int, System.Windows.Media.Color> func)
\r
1086 buffer.ForEach(func);
\r
1088 public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
1090 buffer.ForEach(func);
\r
1093 public Image clone()
\r
1095 return (Image)MemberwiseClone();
\r
1097 public static implicit operator System.Windows.Controls.Image(Image d)
\r
1099 var tmp = new System.Windows.Controls.Image();
\r
1100 tmp.Source = d.buffer;
\r
1101 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
1102 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
1105 public UIElement toNative() { return this; }
\r
1107 public void copyToStack(Templates.StackableDrawable d)
\r
1109 var tmp = d.imageStack[d.imageStackN];
\r
1110 tmp.datum = datum;
\r
1111 tmp.buffer = buffer;
\r
1112 tmp.self_rect = self_rect;
\r
1113 d.stack[d.stackN] = tmp;
\r
1117 public UIElement poolNative(Canvas d)
\r
1119 var tmp = d.imagePool[d.imagePoolN];
\r
1120 tmp.Source = buffer;
\r
1121 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1122 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1123 tmp.Visibility = Visibility.Visible;
\r
1127 public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)
\r
1129 tmp.Source = buffer;
\r
1130 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1131 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1132 tmp.Visibility = Visibility.Visible;
\r
1138 partial class Group
\r
1140 internal void initialize__()
\r
1142 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.SimpleProcedure(create__));
\r
1144 internal void create__()
\r
1146 cnvs = new System.Windows.Controls.Canvas();
\r
1147 trans = new System.Windows.Media.TransformGroup();
\r
1148 transF = new System.Windows.Media.TransformCollection();
\r
1149 rotateF = new System.Windows.Media.RotateTransform();
\r
1150 scaleF = new System.Windows.Media.ScaleTransform();
\r
1151 translateF = new System.Windows.Media.TranslateTransform();
\r
1152 transF.Add(rotateF);
\r
1153 transF.Add(scaleF);
\r
1154 transF.Add(translateF);
\r
1155 trans.Children = transF;
\r
1156 cnvs.RenderTransform = trans;
\r
1159 public Group clone()
\r
1161 return (Group)MemberwiseClone();
\r
1164 delegate void AppendFunc1(Internal.PrimitiveFigure func);
\r
1165 void append__(Internal.PrimitiveFigure fig)
\r
1167 fig.centering(0, 0);
\r
1168 UIElement e = fig.toNative();
\r
1169 cnvs.Children.Add(e);
\r
1170 System.Windows.Controls.Canvas.SetLeft(e, fig.datum.x);
\r
1171 System.Windows.Controls.Canvas.SetTop(e, fig.datum.y);
\r
1173 delegate void SimpleProcedure();
\r
1174 void getRotation__() { rotation_ = rotateF.Angle; }
\r
1175 void setRotation__() { rotateF.Angle = rotation_; }
\r
1176 //void getTranslation__() { rotation_ = rotateF.Angle; }
\r
1177 void setTranslation__() { translateF.X = datum.x; translateF.Y = datum.y; }
\r
1178 void setScaling__() { scaleF.ScaleX = scaling_.x; scaleF.ScaleY = scaling_.y; }
\r
1180 public static implicit operator System.Windows.Controls.Canvas(Group d)
\r
1182 var tmp = d.cnvs;//new System.Windows.Controls.Canvas();
\r
1183 System.Windows.Controls.Canvas.SetLeft(d.cnvs, d.datum.x);
\r
1184 System.Windows.Controls.Canvas.SetTop(d.cnvs, d.datum.y);
\r
1187 public UIElement toNative() { return this; }
\r
1189 public void copyToStack(Templates.StackableDrawable d)
\r
1191 var tmp = d.groupStack[d.groupStackN];
\r
1192 tmp.datum = datum;
\r
1194 d.stack[d.stackN] = tmp;
\r
1198 public UIElement poolNative(Canvas d)
\r
1200 //d.groupPool[d.groupPoolN] = cnvs;
\r
1201 //var tmp = d.groupPool[d.groupPoolN];
\r
1203 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1204 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1205 tmp.Visibility = Visibility.Visible;
\r
1209 public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d)
\r
1211 d.groupPool[d.groupPoolN] = cnvs;
\r
1212 System.Windows.Controls.Canvas.SetLeft(cnvs, datum.x);
\r
1213 System.Windows.Controls.Canvas.SetTop(cnvs, datum.y);
\r
1214 tmp.Visibility = Visibility.Visible;
\r