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
51 public StackableDrawable()
\r
53 stack = new Internal.PrimitiveFigure[CONST.MAX_OBJ_N];
\r
54 lineStack = new Line[CONST.MOBJ_N];
\r
55 rectStack = new Rectangle[CONST.MOBJ_N];
\r
56 ellipseStack = new Ellipse[CONST.MOBJ_N];
\r
57 polygonStack = new Polygon[CONST.COBJ_N];
\r
58 lettersStack = new Letters[CONST.COBJ_N];
\r
59 imageStack = new Image[CONST.HOBJ_N];
\r
60 groupStack = new Group[CONST.HOBJ_N];
\r
61 for (int i = 0; i < CONST.MOBJ_N; i++)
\r
63 lineStack[i] = new Line(0,0,0,0);
\r
64 rectStack[i] = new Rectangle();
\r
65 ellipseStack[i] = new Ellipse();
\r
67 for (int i = 0; i < CONST.COBJ_N; i++)
\r
69 polygonStack[i] = new Polygon();
\r
70 lettersStack[i] = new Letters();
\r
72 for (int i = 0; i < CONST.HOBJ_N; i++)
\r
74 imageStack[i] = new Image(1, 1);
\r
75 groupStack[i] = new Group();
\r
79 public void clear() { clear(Color.black); }
\r
80 public virtual void clear(Color col) { } //rect(back_panel, col); }
\r
81 public virtual void pix(int x, int y, Color col) { }
\r
82 public virtual void line(Line drawee) { drawee.copyToStack(this); }
\r
83 public virtual void rect(Rectangle drawee) { drawee.copyToStack(this); }
\r
84 public virtual void ellipse(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 AsyncInitBool = false;
\r
171 api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);
\r
172 while(!AsyncInitBool)
\r
175 Mouse._prime = api_canvas;
\r
176 Main.drawable = this;
\r
177 Main.canvas = this;
\r
179 back_panel = new Rectangle(wid, hei);
\r
181 flipexec = new SimpleProcedure(executeFlip);
\r
182 AppState.statusBar = "";
\r
184 protected void initialize__(int wid, int hei)
\r
186 api_canvas.Width = wid;
\r
187 api_canvas.Height = hei+20;
\r
188 api_canvas.MouseMove += Mouse.Canvas_MousePos;
\r
189 api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;
\r
190 api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;
\r
191 api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;
\r
192 panel.KeyDown += Keyboard.Canvas_KeyDown;
\r
193 panel.KeyUp += Keyboard.Canvas_KeyUp;
\r
195 HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");
\r
196 //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");
\r
197 htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");
\r
198 htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px");
\r
199 htmlHost.SetStyleAttribute("margin", "2em auto auto auto");
\r
201 pointPool = new System.Windows.Point[CONST.MOBJ_N];
\r
202 brushPool = new SolidColorBrush[CONST.MOBJ_N];
\r
203 linePool = new System.Windows.Shapes.Line[CONST.MOBJ_N];
\r
204 rectPool = new System.Windows.Shapes.Rectangle[CONST.MOBJ_N];
\r
205 ellipsePool = new System.Windows.Shapes.Ellipse[CONST.MOBJ_N];
\r
206 for (int i = 0; i < CONST.MOBJ_N; i++)
\r
208 pointPool[i] = new System.Windows.Point();
\r
209 brushPool[i] = new SolidColorBrush();
\r
210 linePool[i] = new System.Windows.Shapes.Line();
\r
211 rectPool[i] = new System.Windows.Shapes.Rectangle();
\r
212 ellipsePool[i] = new System.Windows.Shapes.Ellipse();
\r
214 polygonPool = new System.Windows.Shapes.Polygon[CONST.COBJ_N];
\r
215 lettersPool = new System.Windows.Controls.TextBlock[CONST.COBJ_N];
\r
216 for (int i = 0; i < CONST.COBJ_N; i++)
\r
218 polygonPool[i] = new System.Windows.Shapes.Polygon();
\r
219 lettersPool[i] = new System.Windows.Controls.TextBlock();
\r
221 imagePool = new System.Windows.Controls.Image[CONST.HOBJ_N];
\r
222 imagePoolT = new Dictionary<int, bool>(CONST.HOBJ_N);
\r
223 groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N];
\r
224 for (int i = 0; i < CONST.HOBJ_N; i++)
\r
226 imagePool[i] = new System.Windows.Controls.Image();
\r
227 imagePoolT.Add(imagePool[i].GetHashCode(), false);
\r
228 groupPool[i] = new System.Windows.Controls.Canvas();
\r
231 masterPool = new System.Windows.Controls.Canvas();
\r
232 prevPool = new System.Windows.Controls.Canvas();
\r
233 api_canvas.Children.Add(masterPool);
\r
235 //api_canvas.Children.Remove(Internal.Main.widgetStack);
\r
236 Psychlops.Internal.Main.widgetStack = new StackPanel();
\r
237 Psychlops.Internal.Main.widgetStack.Orientation = Orientation.Vertical;
\r
238 Psychlops.Internal.Main.widgetStack.Height = hei;
\r
239 api_canvas.Children.Add(Psychlops.Internal.Main.widgetStack);
\r
240 Internal.Main.statusBar.Visibility = Visibility.Collapsed;
\r
243 UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N];
\r
244 dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N];
\r
245 for (int i = 0; i < CONST.MAX_OBJ_N; i++)
\r
247 UIElementPool[i] = new System.Windows.Controls.Canvas();
\r
248 masterPool.Children.Add(UIElementPool[i]);
\r
249 dummyRectPool[i] = new System.Windows.Shapes.Rectangle();
\r
250 UIElementPool[i].Children.Add(dummyRectPool[i]);
\r
251 dummyRectPool[i].Visibility = Visibility.Collapsed;
\r
255 AsyncInitBool = true;
\r
258 internal int findEmptyInPool(Dictionary<int, bool> pool)
\r
261 foreach( KeyValuePair<int, bool> elem in pool)
\r
270 #region static initializer
\r
279 public override void clear(Color col)
\r
281 back_panel.fill = col;
\r
286 int nextIntervalFrame = 1, chacked = 0;
\r
287 public void flip(int n)
\r
291 nextIntervalFrame = n;
\r
303 UIElementPoolN = 0;
\r
318 Internal.Main.canvas_flag.WaitOne();
\r
326 #region version modifyNative2
\r
327 public void executeFlip()
\r
329 Clock after = new Clock();
\r
331 AppState.statusBar = ((after - before).at_msec().ToString()) + " msec";
\r
340 System.Windows.Shapes.Line lineP;
\r
341 System.Windows.Shapes.Rectangle rectP;
\r
342 System.Windows.Shapes.Ellipse ellipseP;
\r
343 System.Windows.Shapes.Polygon polygonP;
\r
344 System.Windows.Controls.TextBlock lettersP;
\r
345 System.Windows.Controls.Image imageP;
\r
346 System.Windows.Controls.Canvas groupP;
\r
350 nextIntervalFrame--;
\r
353 var cnv = UIElementPool[0];
\r
354 if (nextIntervalFrame <= 0)
\r
360 for (int i = 0; i < stackN; i++)
\r
362 if( null != (rectS = stack[i] as Rectangle) )
\r
364 if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle))
\r
366 rectS.modifyNative(rectP, this);
\r
370 cnv.Children.Clear();
\r
371 cnv.Children.Add(stack[i].poolNative(this));
\r
374 else if (null != (lineS = stack[i] as Line))
\r
376 if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line))
\r
378 lineS.modifyNative(lineP, this);
\r
382 cnv.Children.Clear();
\r
383 cnv.Children.Add(stack[i].poolNative(this));
\r
386 else if (null != (ellipseS = stack[i] as Ellipse))
\r
388 if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse))
\r
390 ellipseS.modifyNative(ellipseP, this);
\r
394 cnv.Children.Clear();
\r
395 cnv.Children.Add(stack[i].poolNative(this));
\r
398 else if (null != (polygonS = stack[i] as Polygon))
\r
400 if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon))
\r
402 polygonS.modifyNative(polygonP, this);
\r
406 cnv.Children.Clear();
\r
407 cnv.Children.Add(stack[i].poolNative(this));
\r
410 else if (null != (lettersS = stack[i] as Letters))
\r
412 if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock))
\r
414 lettersS.modifyNative(lettersP, this);
\r
418 cnv.Children.Clear();
\r
419 cnv.Children.Add(stack[i].poolNative(this));
\r
422 else if (null != (imageS = stack[i] as Image))
\r
424 if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image))
\r
426 imageS.modifyNative(imageP, this);
\r
430 cnv.Children.Clear();
\r
431 cnv.Children.Add(stack[i].poolNative(this));
\r
434 else if (null != (groupS = stack[i] as Group))
\r
436 if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas))
\r
438 groupS.modifyNative(groupP, this);
\r
442 cnv.Children.Clear();
\r
443 cnv.Children.Add(stack[i].poolNative(this));
\r
446 cnv.Visibility = Visibility.Visible;
\r
448 cnv = UIElementPool[UIElementPoolN];
\r
450 for (int i = UIElementPoolN; i < lastVisibleN; i++)
\r
452 cnv = UIElementPool[i];
\r
453 cnv.Visibility = Visibility.Collapsed;
\r
455 lastVisibleN = UIElementPoolN;
\r
462 Psychlops.Internal.Main.canvas_flag.Set();
\r
465 System.Threading.Thread.Sleep(0);
\r
469 #region version modifyNative
\r
471 public void executeFlip()
\r
480 System.Windows.Shapes.Line lineP;
\r
481 System.Windows.Shapes.Rectangle rectP;
\r
482 System.Windows.Shapes.Ellipse ellipseP;
\r
483 System.Windows.Shapes.Polygon polygonP;
\r
484 System.Windows.Controls.TextBlock lettersP;
\r
485 System.Windows.Controls.Image imageP;
\r
486 System.Windows.Controls.Canvas groupP;
\r
490 nextIntervalFrame--;
\r
493 var en = masterPool.Children.GetEnumerator();
\r
494 bool full = en.MoveNext();
\r
495 if (nextIntervalFrame <= 0)
\r
499 //masterPool.Children.Clear();
\r
502 for (int i = 0; i < stackN - 2; i++)
\r
506 masterPool.Children.Add(stack[i].poolNative(this));
\r
510 if( null != (rectS = stack[i] as Rectangle) )
\r
512 if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle))
\r
514 rectS.modifyNative(rectP, this);
\r
517 else if (null != (lineS = stack[i] as Line))
\r
519 if (null != (lineP = en.Current as System.Windows.Shapes.Line))
\r
521 lineS.modifyNative(lineP, this);
\r
524 else if (null != (ellipseS = stack[i] as Ellipse))
\r
526 if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse))
\r
528 ellipseS.modifyNative(ellipseP, this);
\r
532 masterPool.Children.Add(stack[i].poolNative(this));
\r
535 else if (null != (polygonS = stack[i] as Polygon))
\r
537 if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon))
\r
539 polygonS.modifyNative(polygonP, this);
\r
542 else if (null != (lettersS = stack[i] as Letters))
\r
544 if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock))
\r
546 lettersS.modifyNative(lettersP, this);
\r
549 else if (null != (imageS = stack[i] as Image))
\r
551 if (null != (imageP = en.Current as System.Windows.Controls.Image))
\r
553 imageS.modifyNative(imageP, this);
\r
556 else if (null != (groupS = stack[i] as Group))
\r
558 if (null != (groupP = en.Current as System.Windows.Controls.Canvas))
\r
560 groupS.modifyNative(groupP, this);
\r
563 full = en.MoveNext();
\r
572 Psychlops.Internal.Main.canvas_flag.Set();
\r
575 System.Threading.Thread.Sleep(0);
\r
580 #region version poolNative 2
\r
582 public void executeFlip()
\r
587 nextIntervalFrame--;
\r
589 UIElementPoolN = 0;
\r
590 if (nextIntervalFrame <= 0)
\r
594 //masterPool.Children.Clear();
\r
597 for (int i = 0; i < stackN - 2; i++)
\r
599 UIElementPool[UIElementPoolN] = stack[i].poolNative(this);
\r
600 UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;
\r
604 for (int i = stackN - 2; i < 10000; i++)
\r
606 UIElementPool[UIElementPoolN] = rectPool[i];
\r
607 UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed;
\r
616 Psychlops.Internal.Main.canvas_flag.Set();
\r
619 System.Threading.Thread.Sleep(0);
\r
627 public double width { get { return width_; } }
\r
628 public double height { get { return height_; } }
\r
629 public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }
\r
630 public double getWidth() { return width; }
\r
631 public double getHeight() { return height; }
\r
632 public override Point getCenter() { return center; }
\r
633 public double getHCenter() { return width / 2; }
\r
634 public double getVCenter() { return height / 2; }
\r
635 public double getRefreshRate() { return 60; }
\r
640 #region compatibitily trick
\r
642 public enum Mode { window, fullscreen }
\r
643 public static readonly Mode window = Mode.window, fullscreen = Mode.fullscreen;
\r
645 public Canvas(int wid, int hei, Mode mod)
\r
647 panel = default_panel;
\r
648 api_canvas = default_api_canvas;
\r
649 initialize(500, 500);
\r
651 public Canvas(Mode mod) : base()
\r
653 panel = default_panel;
\r
654 api_canvas = default_api_canvas;
\r
655 initialize(500, 500);
\r
659 public void showFPS(bool sw = true) { }
\r
660 public void watchFPS(bool sw = true) { }
\r
663 public void clear(double lum)
\r
665 clear(new Color(lum));
\r
675 #region primitive tokenizer
\r
680 partial struct Point
\r
682 public static implicit operator System.Windows.Point(Point d)
\r
684 return new System.Windows.Point(d.x, d.y);
\r
688 partial struct Color
\r
690 public static implicit operator System.Windows.Media.Color(Color d)
\r
692 return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));
\r
694 public static implicit operator System.Windows.Media.SolidColorBrush(Color d)
\r
696 return new SolidColorBrush { Color = d };
\r
698 public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)
\r
700 var tmp = d.brushPool[d.brushPoolN];
\r
708 partial struct Stroke
\r
710 public void apply(System.Windows.Shapes.Shape target)
\r
712 target.Stroke = this;
\r
713 //target.StrokeDashArray
\r
714 target.StrokeThickness = thick;
\r
716 public static implicit operator SolidColorBrush(Stroke d)
\r
718 return new SolidColorBrush { Color = d.color };
\r
720 public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)
\r
722 var tmp = d.brushPool[d.brushPoolN];
\r
723 tmp.Color = this.color;
\r
737 return (Line)MemberwiseClone();
\r
739 public Line clone()
\r
741 return (Line)MemberwiseClone();
\r
743 public static implicit operator System.Windows.Shapes.Line(Line d)
\r
745 var tmp = new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };
\r
746 if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;
\r
747 else d.stroke.apply(tmp);
\r
750 public UIElement toNative() { return this; }
\r
752 public void copyToStack(Templates.StackableDrawable d)
\r
754 var tmp = d.lineStack[d.lineStackN];
\r
755 tmp.begin.x = begin.x;
\r
756 tmp.begin.y = begin.y;
\r
760 tmp.stroke = stroke;
\r
761 d.stack[d.stackN] = tmp;
\r
765 public UIElement poolNative(Canvas d)
\r
767 var tmp = d.linePool[d.linePoolN];
\r
772 if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);
\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 public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d)
\r
786 if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);
\r
787 else stroke.apply(tmp);
\r
788 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
789 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
790 tmp.Visibility = Visibility.Visible;
\r
798 partial class Rectangle
\r
800 public Rectangle dup()
\r
802 return (Rectangle)MemberwiseClone();
\r
804 public Rectangle clone()
\r
806 return (Rectangle)MemberwiseClone();
\r
808 public static implicit operator System.Windows.Rect(Rectangle d)
\r
810 return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);
\r
812 public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)
\r
814 var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };
\r
815 d.stroke.apply(tmp);
\r
816 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
817 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
821 public UIElement toNative() { return this; }
\r
822 public void copyToStack(Templates.StackableDrawable d)
\r
824 var tmp = d.rectStack[d.rectStackN];
\r
828 d.stack[d.stackN] = tmp;
\r
832 public UIElement poolNative(Canvas d)
\r
834 var tmp = d.rectPool[d.rectPoolN];
\r
836 tmp.Height = height;
\r
837 tmp.Fill = fill.getNativeFromStack(d);
\r
838 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
839 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
840 tmp.Visibility = Visibility.Visible;
\r
844 public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)
\r
847 tmp.Height = height;
\r
848 tmp.Fill = fill.getNativeFromStack(d);
\r
849 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
850 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
851 tmp.Visibility = Visibility.Visible;
\r
859 partial class Ellipse
\r
861 public Ellipse dup()
\r
863 return (Ellipse)MemberwiseClone();
\r
865 public Ellipse clone()
\r
867 return (Ellipse)MemberwiseClone();
\r
869 public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)
\r
871 var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };
\r
872 d.stroke.apply(tmp);
\r
873 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
874 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
878 public UIElement toNative() { return this; }
\r
880 public void copyToStack(Templates.StackableDrawable d)
\r
882 var tmp = d.ellipseStack[d.ellipseStackN];
\r
884 tmp.xdiameter = xdiameter;
\r
885 tmp.ydiameter = ydiameter;
\r
887 d.stack[d.stackN] = tmp;
\r
891 public UIElement poolNative(Canvas d)
\r
893 var tmp = d.ellipsePool[d.ellipsePoolN];
\r
895 tmp.Height = height;
\r
896 tmp.Fill = fill.getNativeFromStack(d);
\r
897 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
898 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
899 tmp.Visibility = Visibility.Visible;
\r
903 public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d)
\r
906 tmp.Height = height;
\r
907 tmp.Fill = fill.getNativeFromStack(d);
\r
908 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
909 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
910 tmp.Visibility = Visibility.Visible;
\r
918 partial class Polygon
\r
920 public Polygon dup()
\r
922 return (Polygon)MemberwiseClone();
\r
924 public Polygon clone()
\r
926 return (Polygon)MemberwiseClone();
\r
928 public static implicit operator System.Windows.Shapes.Polygon(Polygon d)
\r
930 var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };
\r
931 d.stroke.apply(tmp);
\r
932 foreach (Point p in d.vertices)
\r
936 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
937 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
940 public UIElement toNative() { return this; }
\r
942 public void copyToStack(Templates.StackableDrawable d)
\r
944 var tmp = d.polygonStack[d.polygonStackN];
\r
946 tmp.vertices.Clear();
\r
947 foreach (var v in vertices)
\r
949 tmp.vertices.Add(v);
\r
952 d.stack[d.stackN] = tmp;
\r
956 public UIElement poolNative(Canvas d)
\r
958 var tmp = d.polygonPool[d.polygonPoolN];
\r
959 tmp.Fill = fill.getNativeFromStack(d);
\r
960 tmp.Points.Clear();
\r
961 foreach (var v in vertices)
\r
965 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
966 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
967 tmp.Visibility = Visibility.Visible;
\r
971 public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)
\r
973 tmp.Fill = fill.getNativeFromStack(d);
\r
974 tmp.Points.Clear();
\r
975 foreach (var v in vertices)
\r
979 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
980 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
981 tmp.Visibility = Visibility.Visible;
\r
990 partial class Letters
\r
992 #region static initializer
\r
993 internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;
\r
994 internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;
\r
995 internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;
\r
998 FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();
\r
999 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);
\r
1000 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);
\r
1001 FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();
\r
1002 FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);
\r
1003 FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);
\r
1004 FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);
\r
1005 LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();
\r
1006 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);
\r
1007 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);
\r
1008 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);
\r
1009 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);
\r
1012 public Letters dup()
\r
1014 return (Letters)MemberwiseClone();
\r
1016 public Letters clone()
\r
1018 return (Letters)MemberwiseClone();
\r
1020 public static implicit operator System.Windows.Controls.TextBlock(Letters d)
\r
1022 //var zapi_shape = new System.Windows.Documents.Glyphs();
\r
1023 var tmp = new System.Windows.Controls.TextBlock {
\r
1024 Text = d.str, Width = 500, Height = 500,
\r
1025 FontSize = d.font.size,
\r
1026 //tmp.FontFamily = ,
\r
1027 FontStyle = FONT_STYLE_BRIDGE[d.font.style],
\r
1028 FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],
\r
1029 TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],
\r
1030 Foreground = d.fill
\r
1035 case Letters.HorizontalAlign.left: break;
\r
1036 case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;
\r
1037 case Letters.HorizontalAlign.right: left = tmp.Width; break;
\r
1039 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);
\r
1040 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);
\r
1043 public UIElement toNative() { return this; }
\r
1045 public void copyToStack(Templates.StackableDrawable d)
\r
1047 var tmp = d.lettersStack[d.lettersStackN];
\r
1049 tmp.datum = datum;
\r
1051 d.stack[d.stackN] = tmp;
\r
1052 d.lettersStackN++;
\r
1055 public UIElement poolNative(Canvas d)
\r
1057 var tmp = d.lettersPool[d.lettersPoolN];
\r
1061 tmp.FontSize = font.size;
\r
1062 //tmp.FontFamily = ,
\r
1063 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
1064 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
1065 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
1066 tmp.Foreground = fill.getNativeFromStack(d);
\r
1067 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1068 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1069 tmp.Visibility = Visibility.Visible;
\r
1073 public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d)
\r
1078 tmp.FontSize = font.size;
\r
1079 //tmp.FontFamily = ,
\r
1080 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
1081 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
1082 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
1083 tmp.Foreground = fill.getNativeFromStack(d);
\r
1084 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1085 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1086 tmp.Visibility = Visibility.Visible;
\r
1094 partial class Image
\r
1096 internal void initialize__(int wid, int hei)
\r
1098 AsyncBool = false;
\r
1099 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei);
\r
1100 while (!AsyncBool) { System.Threading.Thread.Sleep(10); }
\r
1102 internal void create__(int wid, int hei)
\r
1104 buffer = new WriteableBitmap(wid, hei);
\r
1107 internal void load__(string uri)
\r
1109 AsyncBool = false;
\r
1110 var ur = new System.Uri(uri, System.UriKind.RelativeOrAbsolute);
\r
1111 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action<Uri>(load_), ur);
\r
1112 while (!AsyncBool) { System.Threading.Thread.Sleep(10); }
\r
1114 internal void load_(Uri uri)
\r
1116 var bitmap = new BitmapImage();
\r
1117 bitmap.CreateOptions = BitmapCreateOptions.None;
\r
1118 bitmap.UriSource = uri;
\r
1121 var wbm = new System.Windows.Media.Imaging.WriteableBitmap(bitmap);
\r
1124 //catch (Exception e)
\r
1126 // buffer = new WriteableBitmap(64, 64);
\r
1127 // buffer.ForEach(bitmap_drawChecker);
\r
1129 self_rect.set(buffer.PixelWidth, buffer.PixelHeight);
\r
1132 static System.Windows.Media.Color[] CHECKER_C;
\r
1135 CHECKER_C = new System.Windows.Media.Color[2];
\r
1136 CHECKER_C[0] = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);
\r
1137 CHECKER_C[1] = System.Windows.Media.Color.FromArgb(128,128,128,128);
\r
1139 static System.Windows.Media.Color bitmap_drawChecker(int x, int y)
\r
1141 return ((x / 4) + (y / 4)) % 2 == 0 ? CHECKER_C[0] : CHECKER_C[1];
\r
1143 delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);
\r
1144 delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);
\r
1145 public void field__(System.Func<int, int, System.Windows.Media.Color> func)
\r
1147 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);
\r
1148 //buffer.ForEach(func);
\r
1150 public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
1152 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);
\r
1153 //buffer.ForEach(func);
\r
1155 public void field___(System.Func<int, int, System.Windows.Media.Color> func)
\r
1157 buffer.ForEach(func);
\r
1159 public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
1161 buffer.ForEach(func);
\r
1164 public Image clone()
\r
1166 return (Image)MemberwiseClone();
\r
1168 public static implicit operator System.Windows.Controls.Image(Image d)
\r
1170 var tmp = new System.Windows.Controls.Image();
\r
1171 tmp.Source = d.buffer;
\r
1172 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
1173 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
1176 public UIElement toNative() { return this; }
\r
1178 public void copyToStack(Templates.StackableDrawable d)
\r
1180 var tmp = d.imageStack[d.imageStackN];
\r
1181 tmp.datum = datum;
\r
1182 tmp.buffer = buffer;
\r
1183 tmp.self_rect = self_rect;
\r
1184 d.stack[d.stackN] = tmp;
\r
1188 public UIElement poolNative(Canvas d)
\r
1190 var tmp = d.imagePool[d.imagePoolN];
\r
1191 tmp.Source = buffer;
\r
1192 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1193 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1194 tmp.Visibility = Visibility.Visible;
\r
1198 public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)
\r
1200 tmp.Source = buffer;
\r
1201 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1202 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1203 tmp.Visibility = Visibility.Visible;
\r
1212 partial class Group
\r
1214 internal void initialize__()
\r
1216 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.SimpleProcedure(create__));
\r
1218 internal void create__()
\r
1220 cnvs = new System.Windows.Controls.Canvas();
\r
1221 trans = new System.Windows.Media.TransformGroup();
\r
1222 transF = new System.Windows.Media.TransformCollection();
\r
1223 rotateF = new System.Windows.Media.RotateTransform();
\r
1224 scaleF = new System.Windows.Media.ScaleTransform();
\r
1225 translateF = new System.Windows.Media.TranslateTransform();
\r
1226 transF.Add(rotateF);
\r
1227 transF.Add(scaleF);
\r
1228 transF.Add(translateF);
\r
1229 trans.Children = transF;
\r
1230 cnvs.RenderTransform = trans;
\r
1233 public Group clone()
\r
1235 return (Group)MemberwiseClone();
\r
1238 delegate void AppendFunc1(Internal.PrimitiveFigure func);
\r
1239 void append__(Internal.PrimitiveFigure fig)
\r
1241 fig.centering(0, 0);
\r
1242 UIElement e = fig.toNative();
\r
1243 cnvs.Children.Add(e);
\r
1244 System.Windows.Controls.Canvas.SetLeft(e, fig.datum.x);
\r
1245 System.Windows.Controls.Canvas.SetTop(e, fig.datum.y);
\r
1247 delegate void SimpleProcedure();
\r
1248 void getRotation__() { rotation_ = rotateF.Angle; }
\r
1249 void setRotation__() { rotateF.Angle = rotation_; }
\r
1250 //void getTranslation__() { rotation_ = rotateF.Angle; }
\r
1251 void setTranslation__() { translateF.X = datum.x; translateF.Y = datum.y; }
\r
1252 void setScaling__() { scaleF.ScaleX = scaling_.x; scaleF.ScaleY = scaling_.y; }
\r
1254 public static implicit operator System.Windows.Controls.Canvas(Group d)
\r
1256 var tmp = d.cnvs;//new System.Windows.Controls.Canvas();
\r
1257 System.Windows.Controls.Canvas.SetLeft(d.cnvs, d.datum.x);
\r
1258 System.Windows.Controls.Canvas.SetTop(d.cnvs, d.datum.y);
\r
1261 public UIElement toNative() { return this; }
\r
1263 public void copyToStack(Templates.StackableDrawable d)
\r
1265 var tmp = d.groupStack[d.groupStackN];
\r
1266 tmp.datum = datum;
\r
1268 d.stack[d.stackN] = tmp;
\r
1272 public UIElement poolNative(Canvas d)
\r
1274 //d.groupPool[d.groupPoolN] = cnvs;
\r
1275 //var tmp = d.groupPool[d.groupPoolN];
\r
1277 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1278 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1279 tmp.Visibility = Visibility.Visible;
\r
1283 public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d)
\r
1285 d.groupPool[d.groupPoolN] = cnvs;
\r
1286 System.Windows.Controls.Canvas.SetLeft(cnvs, datum.x);
\r
1287 System.Windows.Controls.Canvas.SetTop(cnvs, datum.y);
\r
1288 tmp.Visibility = Visibility.Visible;
\r