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
12 using System.Collections.Generic;
\r
19 internal static partial class CONST
\r
21 internal static readonly Int32 MAX_OBJ_N = 1500;
\r
22 internal static readonly Int32 MOBJ_N = 1000;
\r
23 internal static readonly Int32 COBJ_N = 300;
\r
24 internal static readonly Int32 HOBJ_N = 100;
\r
30 public class StackableDrawable : Drawable
\r
32 // protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;
\r
33 internal Internal.PrimitiveFigure[] stack;
\r
34 internal int stackN = 0;
\r
35 internal Line[] lineStack;
\r
36 internal int lineStackN = 0;
\r
37 internal Rectangle[] rectStack;
\r
38 internal int rectStackN = 0;
\r
39 internal Ellipse[] ellipseStack;
\r
40 internal int ellipseStackN = 0;
\r
41 internal Polygon[] polygonStack;
\r
42 internal int polygonStackN = 0;
\r
43 internal Letters[] lettersStack;
\r
44 internal int lettersStackN = 0;
\r
45 internal Image[] imageStack;
\r
46 internal int imageStackN = 0;
\r
47 internal Group[] groupStack;
\r
48 internal int groupStackN = 0;
\r
50 public StackableDrawable()
\r
52 stack = new Internal.PrimitiveFigure[CONST.MAX_OBJ_N];
\r
53 lineStack = new Line[CONST.MOBJ_N];
\r
54 rectStack = new Rectangle[CONST.MOBJ_N];
\r
55 ellipseStack = new Ellipse[CONST.MOBJ_N];
\r
56 polygonStack = new Polygon[CONST.COBJ_N];
\r
57 lettersStack = new Letters[CONST.COBJ_N];
\r
58 imageStack = new Image[CONST.HOBJ_N];
\r
59 groupStack = new Group[CONST.HOBJ_N];
\r
60 for (int i = 0; i < CONST.MOBJ_N; i++)
\r
62 lineStack[i] = new Line(0,0,0,0);
\r
63 rectStack[i] = new Rectangle();
\r
64 ellipseStack[i] = new Ellipse();
\r
66 for (int i = 0; i < CONST.COBJ_N; i++)
\r
68 polygonStack[i] = new Polygon();
\r
69 lettersStack[i] = new Letters();
\r
71 for (int i = 0; i < CONST.HOBJ_N; i++)
\r
73 imageStack[i] = new Image();
\r
74 // groupStack[i] = new Group();
\r
78 public void clear() { clear(Color.black); }
\r
79 public virtual void clear(Color col) { } //rect(back_panel, col); }
\r
80 public virtual void pix(int x, int y, Color col) { }
\r
81 public virtual void line(Line drawee) { drawee.copyToStack(this); }
\r
82 public virtual void rect(Rectangle drawee) { drawee.copyToStack(this); }
\r
83 public virtual void ellipse(Ellipse drawee) { drawee.copyToStack(this); }
\r
84 public virtual void oval(Ellipse drawee) { drawee.copyToStack(this); }
\r
85 public virtual void polygon(Polygon drawee) { drawee.copyToStack(this); }
\r
86 public virtual void letters(Letters drawee) { drawee.copyToStack(this); }
\r
87 public virtual void image(Image drawee) { drawee.copyToStack(this); }
\r
88 public virtual void group(Group drawee) { drawee.copyToStack(this); }
\r
90 public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }
\r
91 public virtual void msg(string dstr, double x, double y, Color col)
\r
93 var let = new Letters(dstr);
\r
98 public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }
\r
99 public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }
\r
101 public virtual Point getCenter() { return new Point(0, 0, 0); }
\r
106 public class Canvas : Templates.StackableDrawable
\r
108 internal System.Windows.Controls.Canvas masterPool, prevPool;
\r
109 internal System.Windows.Point[] pointPool;
\r
110 internal int pointPoolN;
\r
111 internal SolidColorBrush[] brushPool;
\r
112 internal int brushPoolN;
\r
114 internal System.Windows.Controls.Canvas[] UIElementPool;
\r
115 internal int UIElementPoolN;
\r
116 internal int lastVisibleN;
\r
118 internal System.Windows.Shapes.Line[] linePool;
\r
119 internal int linePoolN;
\r
120 internal System.Windows.Shapes.Rectangle[] dummyRectPool;
\r
121 internal System.Windows.Shapes.Rectangle[] rectPool;
\r
122 internal int rectPoolN;
\r
123 internal System.Windows.Shapes.Ellipse[] ellipsePool;
\r
124 internal int ellipsePoolN;
\r
125 internal System.Windows.Shapes.Polygon[] polygonPool;
\r
126 internal int polygonPoolN;
\r
127 internal System.Windows.Controls.TextBlock[] lettersPool;
\r
128 internal int lettersPoolN;
\r
129 internal System.Windows.Controls.Image[] imagePool;
\r
130 internal int imagePoolN;
\r
131 internal Dictionary<int, bool> imagePoolT;
\r
132 internal System.Windows.Controls.Canvas[] groupPool;
\r
133 internal int groupPoolN;
\r
135 #region initializer
\r
137 internal delegate void TwoIntProcedure(int x, int y);
\r
138 internal delegate void SimpleProcedure();
\r
139 SimpleProcedure flipexec;
\r
141 public static System.Windows.Controls.UserControl default_panel;
\r
142 public static System.Windows.Controls.Canvas default_api_canvas;
\r
143 public static WriteableBitmap default_buffer;
\r
144 internal System.Windows.Controls.Canvas api_canvas;
\r
145 internal System.Windows.Controls.UserControl panel;
\r
146 Rectangle back_panel;
\r
147 double width_, height_;
\r
150 public Canvas(int wid, int hei)
\r
152 panel = default_panel;
\r
153 api_canvas = default_api_canvas;
\r
154 initialize(wid, hei);
\r
156 public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs, System.Windows.Controls.UserControl system)
\r
159 api_canvas = apicnvs;
\r
160 initialize(wid, hei);
\r
163 protected bool AsyncInitBool;
\r
164 protected void initialize(int wid, int hei)
\r
166 before = new Clock();
\r
168 var after = new Clock();
\r
169 AsyncInitBool = false;
\r
172 api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);
\r
173 while (!AsyncInitBool)
\r
176 if ((after - before).at_msec() > 1000) break;
\r
178 Mouse._prime = api_canvas;
\r
179 Main.drawable = this;
\r
180 Main.canvas = this;
\r
182 back_panel = new Rectangle(wid, hei);
\r
184 flipexec = new SimpleProcedure(executeFlip);
\r
186 protected void initialize__(int wid, int hei)
\r
188 api_canvas.Width = wid;
\r
189 api_canvas.Height = hei+20;
\r
190 api_canvas.MouseMove += Mouse.Canvas_MousePos;
\r
191 api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;
\r
192 api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;
\r
193 api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;
\r
194 panel.KeyDown += Keyboard.Canvas_KeyDown;
\r
195 panel.KeyUp += Keyboard.Canvas_KeyUp;
\r
197 HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");
\r
198 //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");
\r
199 htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");
\r
200 htmlHost.SetStyleAttribute("height", (hei).ToString() + "px");
\r
201 htmlHost.SetStyleAttribute("margin", "2em auto auto auto");
\r
203 pointPool = new System.Windows.Point[CONST.MOBJ_N];
\r
204 brushPool = new SolidColorBrush[CONST.MOBJ_N];
\r
205 linePool = new System.Windows.Shapes.Line[CONST.MOBJ_N];
\r
206 rectPool = new System.Windows.Shapes.Rectangle[CONST.MOBJ_N];
\r
207 ellipsePool = new System.Windows.Shapes.Ellipse[CONST.MOBJ_N];
\r
208 for (int i = 0; i < CONST.MOBJ_N; i++)
\r
210 pointPool[i] = new System.Windows.Point();
\r
211 brushPool[i] = new SolidColorBrush();
\r
212 linePool[i] = new System.Windows.Shapes.Line();
\r
213 rectPool[i] = new System.Windows.Shapes.Rectangle();
\r
214 ellipsePool[i] = new System.Windows.Shapes.Ellipse();
\r
216 polygonPool = new System.Windows.Shapes.Polygon[CONST.COBJ_N];
\r
217 lettersPool = new System.Windows.Controls.TextBlock[CONST.COBJ_N];
\r
218 for (int i = 0; i < CONST.COBJ_N; i++)
\r
220 polygonPool[i] = new System.Windows.Shapes.Polygon();
\r
221 lettersPool[i] = new System.Windows.Controls.TextBlock();
\r
223 imagePool = new System.Windows.Controls.Image[CONST.HOBJ_N];
\r
224 imagePoolT = new Dictionary<int, bool>(CONST.HOBJ_N);
\r
225 groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N];
\r
226 for (int i = 0; i < CONST.HOBJ_N; i++)
\r
228 imagePool[i] = new System.Windows.Controls.Image();
\r
229 imagePoolT.Add(imagePool[i].GetHashCode(), false);
\r
230 groupPool[i] = new System.Windows.Controls.Canvas();
\r
233 masterPool = new System.Windows.Controls.Canvas();
\r
234 prevPool = new System.Windows.Controls.Canvas();
\r
235 api_canvas.Children.Add(masterPool);
\r
237 //api_canvas.Children.Remove(Internal.Main.widgetStack);
\r
238 Psychlops.Internal.Main.widgetStack = new StackPanel();
\r
239 Psychlops.Internal.Main.widgetStack.Orientation = Orientation.Vertical;
\r
240 Psychlops.Internal.Main.widgetStack.Height = hei;
\r
241 api_canvas.Children.Add(Psychlops.Internal.Main.widgetStack);
\r
242 Internal.Main.statusBar.Visibility = Visibility.Collapsed;
\r
245 UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N];
\r
246 dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N];
\r
247 for (int i = 0; i < CONST.MAX_OBJ_N; i++)
\r
249 UIElementPool[i] = new System.Windows.Controls.Canvas();
\r
250 masterPool.Children.Add(UIElementPool[i]);
\r
251 dummyRectPool[i] = new System.Windows.Shapes.Rectangle();
\r
252 UIElementPool[i].Children.Add(dummyRectPool[i]);
\r
253 dummyRectPool[i].Visibility = Visibility.Collapsed;
\r
256 AsyncInitBool = true;
\r
259 internal int findEmptyInPool(Dictionary<int, bool> pool)
\r
262 foreach( KeyValuePair<int, bool> elem in pool)
\r
271 #region static initializer
\r
280 public override void clear(Color col)
\r
282 back_panel.fill = col;
\r
287 int nextIntervalFrame = 1, chacked = 0;
\r
288 public void flip(int n)
\r
292 nextIntervalFrame = n;
\r
304 UIElementPoolN = 0;
\r
319 Internal.Main.canvas_flag.WaitOne();
\r
327 #region version modifyNative2
\r
328 public void executeFlip()
\r
330 // Clock after = new Clock();
\r
332 // AppState.statusBar = ((after - before).at_msec().ToString()) + " msec";
\r
341 System.Windows.Shapes.Line lineP;
\r
342 System.Windows.Shapes.Rectangle rectP;
\r
343 System.Windows.Shapes.Ellipse ellipseP;
\r
344 System.Windows.Shapes.Polygon polygonP;
\r
345 System.Windows.Controls.TextBlock lettersP;
\r
346 System.Windows.Controls.Image imageP;
\r
347 System.Windows.Controls.Canvas groupP;
\r
351 nextIntervalFrame--;
\r
354 var cnv = UIElementPool[0];
\r
355 if (nextIntervalFrame <= 0)
\r
361 for (int i = 0; i < stackN; i++)
\r
363 if( null != (rectS = stack[i] as Rectangle) )
\r
365 if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle))
\r
367 rectS.modifyNative(rectP, this);
\r
371 cnv.Children.Clear();
\r
372 cnv.Children.Add(stack[i].poolNative(this));
\r
375 else if (null != (lineS = stack[i] as Line))
\r
377 if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line))
\r
379 lineS.modifyNative(lineP, this);
\r
383 cnv.Children.Clear();
\r
384 cnv.Children.Add(stack[i].poolNative(this));
\r
387 else if (null != (ellipseS = stack[i] as Ellipse))
\r
389 if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse))
\r
391 ellipseS.modifyNative(ellipseP, this);
\r
395 cnv.Children.Clear();
\r
396 cnv.Children.Add(stack[i].poolNative(this));
\r
399 else if (null != (polygonS = stack[i] as Polygon))
\r
401 if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon))
\r
403 polygonS.modifyNative(polygonP, this);
\r
407 cnv.Children.Clear();
\r
408 cnv.Children.Add(stack[i].poolNative(this));
\r
411 else if (null != (lettersS = stack[i] as Letters))
\r
413 if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock))
\r
415 lettersS.modifyNative(lettersP, this);
\r
419 cnv.Children.Clear();
\r
420 cnv.Children.Add(stack[i].poolNative(this));
\r
423 else if (null != (imageS = stack[i] as Image))
\r
425 if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image))
\r
427 imageS.modifyNative(imageP, this);
\r
431 cnv.Children.Clear();
\r
432 cnv.Children.Add(stack[i].poolNative(this));
\r
435 else if (null != (groupS = stack[i] as Group))
\r
437 if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas))
\r
439 groupS.modifyNative(groupP, this);
\r
443 cnv.Children.Clear();
\r
444 cnv.Children.Add(stack[i].poolNative(this));
\r
447 cnv.Visibility = Visibility.Visible;
\r
449 cnv = UIElementPool[UIElementPoolN];
\r
451 for (int i = UIElementPoolN; i < lastVisibleN; i++)
\r
453 cnv = UIElementPool[i];
\r
454 cnv.Visibility = Visibility.Collapsed;
\r
456 lastVisibleN = UIElementPoolN;
\r
463 Psychlops.Internal.Main.canvas_flag.Set();
\r
466 System.Threading.Thread.Sleep(0);
\r
472 #region version modifyNative
\r
474 public void executeFlip()
\r
483 System.Windows.Shapes.Line lineP;
\r
484 System.Windows.Shapes.Rectangle rectP;
\r
485 System.Windows.Shapes.Ellipse ellipseP;
\r
486 System.Windows.Shapes.Polygon polygonP;
\r
487 System.Windows.Controls.TextBlock lettersP;
\r
488 System.Windows.Controls.Image imageP;
\r
489 System.Windows.Controls.Canvas groupP;
\r
493 nextIntervalFrame--;
\r
496 var en = masterPool.Children.GetEnumerator();
\r
497 bool full = en.MoveNext();
\r
498 if (nextIntervalFrame <= 0)
\r
502 //masterPool.Children.Clear();
\r
505 for (int i = 0; i < stackN - 2; i++)
\r
509 masterPool.Children.Add(stack[i].poolNative(this));
\r
513 if( null != (rectS = stack[i] as Rectangle) )
\r
515 if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle))
\r
517 rectS.modifyNative(rectP, this);
\r
520 else if (null != (lineS = stack[i] as Line))
\r
522 if (null != (lineP = en.Current as System.Windows.Shapes.Line))
\r
524 lineS.modifyNative(lineP, this);
\r
527 else if (null != (ellipseS = stack[i] as Ellipse))
\r
529 if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse))
\r
531 ellipseS.modifyNative(ellipseP, this);
\r
535 masterPool.Children.Add(stack[i].poolNative(this));
\r
538 else if (null != (polygonS = stack[i] as Polygon))
\r
540 if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon))
\r
542 polygonS.modifyNative(polygonP, this);
\r
545 else if (null != (lettersS = stack[i] as Letters))
\r
547 if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock))
\r
549 lettersS.modifyNative(lettersP, this);
\r
552 else if (null != (imageS = stack[i] as Image))
\r
554 if (null != (imageP = en.Current as System.Windows.Controls.Image))
\r
556 imageS.modifyNative(imageP, this);
\r
559 else if (null != (groupS = stack[i] as Group))
\r
561 if (null != (groupP = en.Current as System.Windows.Controls.Canvas))
\r
563 groupS.modifyNative(groupP, this);
\r
566 full = en.MoveNext();
\r
575 Psychlops.Internal.Main.canvas_flag.Set();
\r
578 System.Threading.Thread.Sleep(0);
\r
583 #region version poolNative 2
\r
585 public void executeFlip()
\r
590 nextIntervalFrame--;
\r
592 UIElementPoolN = 0;
\r
593 if (nextIntervalFrame <= 0)
\r
597 //masterPool.Children.Clear();
\r
600 for (int i = 0; i < stackN - 2; i++)
\r
602 UIElementPool[UIElementPoolN] = stack[i].poolNative(this);
\r
603 UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;
\r
607 for (int i = stackN - 2; i < 10000; i++)
\r
609 UIElementPool[UIElementPoolN] = rectPool[i];
\r
610 UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed;
\r
619 Psychlops.Internal.Main.canvas_flag.Set();
\r
622 System.Threading.Thread.Sleep(0);
\r
630 public double width { get { return width_; } }
\r
631 public double height { get { return height_; } }
\r
632 public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }
\r
633 public double getWidth() { return width; }
\r
634 public double getHeight() { return height; }
\r
635 public override Point getCenter() { return center; }
\r
636 public double getHCenter() { return width / 2; }
\r
637 public double getVCenter() { return height / 2; }
\r
638 public double getRefreshRate() { return 60; }
\r
643 #region compatibitily trick
\r
645 public enum Mode { window, fullscreen }
\r
646 public static readonly Mode window = Mode.window, fullscreen = Mode.fullscreen;
\r
648 public Canvas(int wid, int hei, Mode mod)
\r
650 panel = default_panel;
\r
651 api_canvas = default_api_canvas;
\r
652 initialize(500, 500);
\r
654 public Canvas(Mode mod) : base()
\r
656 panel = default_panel;
\r
657 api_canvas = default_api_canvas;
\r
658 initialize(500, 500);
\r
662 public void showFPS(bool sw = true) { }
\r
663 public void watchFPS(bool sw = true) { }
\r
666 public void clear(double lum)
\r
668 clear(new Color(lum));
\r
678 #region primitive tokenizer
\r
683 partial struct Point
\r
685 public static implicit operator System.Windows.Point(Point d)
\r
687 return new System.Windows.Point(d.x, d.y);
\r
691 partial struct Color
\r
693 public static implicit operator System.Windows.Media.Color(Color d)
\r
695 return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));
\r
697 public static implicit operator System.Windows.Media.SolidColorBrush(Color d)
\r
699 return new SolidColorBrush { Color = d };
\r
701 public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)
\r
703 var tmp = d.brushPool[d.brushPoolN];
\r
711 partial struct Stroke
\r
713 public void apply(System.Windows.Shapes.Shape target)
\r
715 target.Stroke = this;
\r
716 //target.StrokeDashArray
\r
717 target.StrokeThickness = thick;
\r
719 public static implicit operator SolidColorBrush(Stroke d)
\r
721 return new SolidColorBrush { Color = d.color };
\r
723 public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)
\r
725 var tmp = d.brushPool[d.brushPoolN];
\r
726 tmp.Color = this.color;
\r
740 return (Line)MemberwiseClone();
\r
742 public Line clone()
\r
744 return (Line)MemberwiseClone();
\r
746 public static implicit operator System.Windows.Shapes.Line(Line d)
\r
748 var tmp = new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };
\r
749 if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;
\r
750 else d.stroke.apply(tmp);
\r
753 public UIElement toNative() { return this; }
\r
755 public void copyToStack(Templates.StackableDrawable d)
\r
757 var tmp = d.lineStack[d.lineStackN];
\r
758 tmp.begin.x = begin.x;
\r
759 tmp.begin.y = begin.y;
\r
763 tmp.stroke = stroke;
\r
764 d.stack[d.stackN] = tmp;
\r
768 public UIElement poolNative(Canvas d)
\r
770 var tmp = d.linePool[d.linePoolN];
\r
775 if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);
\r
776 else stroke.apply(tmp);
\r
777 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
778 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
779 tmp.Visibility = Visibility.Visible;
\r
783 public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d)
\r
789 if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);
\r
790 else stroke.apply(tmp);
\r
791 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
792 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
793 tmp.Visibility = Visibility.Visible;
\r
801 partial class Rectangle
\r
803 public Rectangle dup()
\r
805 return (Rectangle)MemberwiseClone();
\r
807 public Rectangle clone()
\r
809 return (Rectangle)MemberwiseClone();
\r
811 public static implicit operator System.Windows.Rect(Rectangle d)
\r
813 return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);
\r
815 public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)
\r
817 var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };
\r
818 d.stroke.apply(tmp);
\r
819 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
820 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
824 public UIElement toNative() { return this; }
\r
825 public void copyToStack(Templates.StackableDrawable d)
\r
827 var tmp = d.rectStack[d.rectStackN];
\r
831 d.stack[d.stackN] = tmp;
\r
835 public UIElement poolNative(Canvas d)
\r
837 var tmp = d.rectPool[d.rectPoolN];
\r
839 tmp.Height = height;
\r
840 tmp.Fill = fill.getNativeFromStack(d);
\r
841 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
842 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
843 tmp.Visibility = Visibility.Visible;
\r
847 public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)
\r
850 tmp.Height = height;
\r
851 tmp.Fill = fill.getNativeFromStack(d);
\r
852 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
853 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
854 tmp.Visibility = Visibility.Visible;
\r
862 partial class Ellipse
\r
864 public Ellipse dup()
\r
866 return (Ellipse)MemberwiseClone();
\r
868 public Ellipse clone()
\r
870 return (Ellipse)MemberwiseClone();
\r
872 public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)
\r
874 var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };
\r
875 d.stroke.apply(tmp);
\r
876 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
877 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
881 public UIElement toNative() { return this; }
\r
883 public void copyToStack(Templates.StackableDrawable d)
\r
885 var tmp = d.ellipseStack[d.ellipseStackN];
\r
887 tmp.xdiameter = xdiameter;
\r
888 tmp.ydiameter = ydiameter;
\r
890 d.stack[d.stackN] = tmp;
\r
894 public UIElement poolNative(Canvas d)
\r
896 var tmp = d.ellipsePool[d.ellipsePoolN];
\r
898 tmp.Height = height;
\r
899 tmp.Fill = fill.getNativeFromStack(d);
\r
900 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
901 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
902 tmp.Visibility = Visibility.Visible;
\r
906 public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d)
\r
909 tmp.Height = height;
\r
910 tmp.Fill = fill.getNativeFromStack(d);
\r
911 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
912 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
913 tmp.Visibility = Visibility.Visible;
\r
921 partial class Polygon
\r
923 public Polygon dup()
\r
925 return (Polygon)MemberwiseClone();
\r
927 public Polygon clone()
\r
929 return (Polygon)MemberwiseClone();
\r
931 public static implicit operator System.Windows.Shapes.Polygon(Polygon d)
\r
933 var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };
\r
934 d.stroke.apply(tmp);
\r
935 foreach (Point p in d.vertices)
\r
939 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
940 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
943 public UIElement toNative() { return this; }
\r
945 public void copyToStack(Templates.StackableDrawable d)
\r
947 var tmp = d.polygonStack[d.polygonStackN];
\r
949 tmp.vertices.Clear();
\r
950 foreach (var v in vertices)
\r
952 tmp.vertices.Add(v);
\r
955 d.stack[d.stackN] = tmp;
\r
959 public UIElement poolNative(Canvas d)
\r
961 var tmp = d.polygonPool[d.polygonPoolN];
\r
962 tmp.Fill = fill.getNativeFromStack(d);
\r
963 tmp.Points.Clear();
\r
964 foreach (var v in vertices)
\r
968 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
969 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
970 tmp.Visibility = Visibility.Visible;
\r
974 public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)
\r
976 tmp.Fill = fill.getNativeFromStack(d);
\r
977 tmp.Points.Clear();
\r
978 foreach (var v in vertices)
\r
982 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
983 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
984 tmp.Visibility = Visibility.Visible;
\r
993 partial class Letters
\r
995 #region static initializer
\r
996 internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;
\r
997 internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;
\r
998 internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;
\r
1001 FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();
\r
1002 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);
\r
1003 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);
\r
1004 FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();
\r
1005 FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);
\r
1006 FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);
\r
1007 FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);
\r
1008 LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();
\r
1009 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);
\r
1010 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);
\r
1011 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);
\r
1012 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);
\r
1015 public Letters dup()
\r
1017 return (Letters)MemberwiseClone();
\r
1019 public Letters clone()
\r
1021 return (Letters)MemberwiseClone();
\r
1023 public static implicit operator System.Windows.Controls.TextBlock(Letters d)
\r
1025 //var zapi_shape = new System.Windows.Documents.Glyphs();
\r
1026 var tmp = new System.Windows.Controls.TextBlock {
\r
1027 Text = d.str, Width = 500, Height = 500,
\r
1028 FontSize = d.font.size,
\r
1029 //tmp.FontFamily = ,
\r
1030 FontStyle = FONT_STYLE_BRIDGE[d.font.style],
\r
1031 FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],
\r
1032 TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],
\r
1033 Foreground = d.fill
\r
1038 case Letters.HorizontalAlign.left: break;
\r
1039 case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;
\r
1040 case Letters.HorizontalAlign.right: left = tmp.Width; break;
\r
1042 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);
\r
1043 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);
\r
1046 public UIElement toNative() { return this; }
\r
1048 public void copyToStack(Templates.StackableDrawable d)
\r
1050 var tmp = d.lettersStack[d.lettersStackN];
\r
1052 tmp.datum = datum;
\r
1054 d.stack[d.stackN] = tmp;
\r
1055 d.lettersStackN++;
\r
1058 public UIElement poolNative(Canvas d)
\r
1060 var tmp = d.lettersPool[d.lettersPoolN];
\r
1064 tmp.FontSize = font.size;
\r
1065 //tmp.FontFamily = ,
\r
1066 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
1067 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
1068 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
1069 tmp.Foreground = fill.getNativeFromStack(d);
\r
1070 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1071 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1072 tmp.Visibility = Visibility.Visible;
\r
1076 public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d)
\r
1081 tmp.FontSize = font.size;
\r
1082 //tmp.FontFamily = ,
\r
1083 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
1084 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
1085 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
1086 tmp.Foreground = fill.getNativeFromStack(d);
\r
1087 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1088 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1089 tmp.Visibility = Visibility.Visible;
\r
1097 partial class Image
\r
1099 internal void initialize__(int wid, int hei)
\r
1101 AsyncBool = false;
\r
1102 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei);
\r
1103 while (!AsyncBool) { System.Threading.Thread.Sleep(10); }
\r
1105 internal void create__(int wid, int hei)
\r
1107 buffer = new WriteableBitmap(wid, hei);
\r
1110 internal void load__(string uri)
\r
1112 AsyncBool = false;
\r
1113 var ur = new System.Uri(uri, System.UriKind.RelativeOrAbsolute);
\r
1114 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action<Uri>(load_), ur);
\r
1115 while (!AsyncBool) { System.Threading.Thread.Sleep(10); }
\r
1117 internal void load_(Uri uri)
\r
1119 var bitmap = new BitmapImage();
\r
1120 bitmap.CreateOptions = BitmapCreateOptions.None;
\r
1121 bitmap.UriSource = uri;
\r
1124 var wbm = new System.Windows.Media.Imaging.WriteableBitmap(bitmap);
\r
1127 //catch (Exception e)
\r
1129 // buffer = new WriteableBitmap(64, 64);
\r
1130 // buffer.ForEach(bitmap_drawChecker);
\r
1132 self_rect.set(buffer.PixelWidth, buffer.PixelHeight);
\r
1135 static System.Windows.Media.Color[] CHECKER_C;
\r
1138 CHECKER_C = new System.Windows.Media.Color[2];
\r
1139 CHECKER_C[0] = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);
\r
1140 CHECKER_C[1] = System.Windows.Media.Color.FromArgb(128,128,128,128);
\r
1142 static System.Windows.Media.Color bitmap_drawChecker(int x, int y)
\r
1144 return ((x / 4) + (y / 4)) % 2 == 0 ? CHECKER_C[0] : CHECKER_C[1];
\r
1146 delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);
\r
1147 delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);
\r
1148 public void field__(System.Func<int, int, System.Windows.Media.Color> func)
\r
1150 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);
\r
1151 //buffer.ForEach(func);
\r
1153 public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
1155 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);
\r
1156 //buffer.ForEach(func);
\r
1158 public void field___(System.Func<int, int, System.Windows.Media.Color> func)
\r
1160 buffer.ForEach(func);
\r
1162 public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
1164 buffer.ForEach(func);
\r
1167 public Image clone()
\r
1169 return (Image)MemberwiseClone();
\r
1171 public static implicit operator System.Windows.Controls.Image(Image d)
\r
1173 var tmp = new System.Windows.Controls.Image();
\r
1174 tmp.Source = d.buffer;
\r
1175 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
1176 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
1179 public UIElement toNative() { return this; }
\r
1181 public void copyToStack(Templates.StackableDrawable d)
\r
1183 var tmp = d.imageStack[d.imageStackN];
\r
1184 tmp.datum = datum;
\r
1185 tmp.buffer = buffer;
\r
1186 tmp.self_rect = self_rect;
\r
1187 d.stack[d.stackN] = tmp;
\r
1191 public UIElement poolNative(Canvas d)
\r
1193 var tmp = d.imagePool[d.imagePoolN];
\r
1194 tmp.Source = buffer;
\r
1195 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1196 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1197 tmp.Visibility = Visibility.Visible;
\r
1201 public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)
\r
1203 tmp.Source = buffer;
\r
1204 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1205 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1206 tmp.Visibility = Visibility.Visible;
\r
1215 partial class Group
\r
1217 internal void initialize__()
\r
1219 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.SimpleProcedure(create__));
\r
1221 internal void create__()
\r
1223 cnvs = new System.Windows.Controls.Canvas();
\r
1224 trans = new System.Windows.Media.TransformGroup();
\r
1225 transF = new System.Windows.Media.TransformCollection();
\r
1226 rotateF = new System.Windows.Media.RotateTransform();
\r
1227 scaleF = new System.Windows.Media.ScaleTransform();
\r
1228 translateF = new System.Windows.Media.TranslateTransform();
\r
1229 transF.Add(rotateF);
\r
1230 transF.Add(scaleF);
\r
1231 transF.Add(translateF);
\r
1232 trans.Children = transF;
\r
1233 cnvs.RenderTransform = trans;
\r
1236 public Group clone()
\r
1238 return (Group)MemberwiseClone();
\r
1241 delegate void AppendFunc1(Internal.PrimitiveFigure func);
\r
1242 void append__(Internal.PrimitiveFigure fig)
\r
1244 fig.centering(0, 0);
\r
1245 UIElement e = fig.toNative();
\r
1246 cnvs.Children.Add(e);
\r
1247 System.Windows.Controls.Canvas.SetLeft(e, fig.datum.x);
\r
1248 System.Windows.Controls.Canvas.SetTop(e, fig.datum.y);
\r
1250 delegate void SimpleProcedure();
\r
1251 void getRotation__() { rotation_ = rotateF.Angle; }
\r
1252 void setRotation__() { rotateF.Angle = rotation_; }
\r
1253 //void getTranslation__() { rotation_ = rotateF.Angle; }
\r
1254 void setTranslation__() { translateF.X = datum.x; translateF.Y = datum.y; }
\r
1255 void setScaling__() { scaleF.ScaleX = scaling_.x; scaleF.ScaleY = scaling_.y; }
\r
1257 public static implicit operator System.Windows.Controls.Canvas(Group d)
\r
1259 var tmp = d.cnvs;//new System.Windows.Controls.Canvas();
\r
1260 System.Windows.Controls.Canvas.SetLeft(d.cnvs, d.datum.x);
\r
1261 System.Windows.Controls.Canvas.SetTop(d.cnvs, d.datum.y);
\r
1264 public UIElement toNative() { return this; }
\r
1266 public void copyToStack(Templates.StackableDrawable d)
\r
1268 var tmp = d.groupStack[d.groupStackN];
\r
1269 tmp.datum = datum;
\r
1271 d.stack[d.stackN] = tmp;
\r
1275 public UIElement poolNative(Canvas d)
\r
1277 //d.groupPool[d.groupPoolN] = cnvs;
\r
1278 //var tmp = d.groupPool[d.groupPoolN];
\r
1280 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1281 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1282 tmp.Visibility = Visibility.Visible;
\r
1286 public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d)
\r
1288 d.groupPool[d.groupPoolN] = cnvs;
\r
1289 System.Windows.Controls.Canvas.SetLeft(cnvs, datum.x);
\r
1290 System.Windows.Controls.Canvas.SetTop(cnvs, datum.y);
\r
1291 tmp.Visibility = Visibility.Visible;
\r