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 ShaderField[] shaderStack;
\r
40 internal int shaderStackN = 0;
\r
41 internal Ellipse[] ellipseStack;
\r
42 internal int ellipseStackN = 0;
\r
43 internal Polygon[] polygonStack;
\r
44 internal int polygonStackN = 0;
\r
45 internal Letters[] lettersStack;
\r
46 internal int lettersStackN = 0;
\r
47 internal Image[] imageStack;
\r
48 internal int imageStackN = 0;
\r
49 internal Group[] groupStack;
\r
50 internal int groupStackN = 0;
\r
52 public StackableDrawable()
\r
54 stack = new Internal.PrimitiveFigure[CONST.MAX_OBJ_N];
\r
55 lineStack = new Line[CONST.MOBJ_N];
\r
56 rectStack = new Rectangle[CONST.MOBJ_N];
\r
57 ellipseStack = new Ellipse[CONST.MOBJ_N];
\r
58 shaderStack = new ShaderField[CONST.COBJ_N];
\r
59 polygonStack = new Polygon[CONST.COBJ_N];
\r
60 lettersStack = new Letters[CONST.COBJ_N];
\r
61 imageStack = new Image[CONST.HOBJ_N];
\r
62 groupStack = new Group[CONST.HOBJ_N];
\r
63 for (int i = 0; i < CONST.MOBJ_N; i++)
\r
65 lineStack[i] = new Line(0,0,0,0);
\r
66 rectStack[i] = new Rectangle();
\r
67 ellipseStack[i] = new Ellipse();
\r
69 for (int i = 0; i < CONST.COBJ_N; i++)
\r
71 shaderStack[i] = new ShaderField();
\r
72 polygonStack[i] = new Polygon();
\r
73 lettersStack[i] = new Letters();
\r
75 for (int i = 0; i < CONST.HOBJ_N; i++)
\r
77 imageStack[i] = new Image();
\r
78 // groupStack[i] = new Group();
\r
84 public void clear() { clear(Color.black); }
\r
85 public virtual void clear(Color col) { } //rect(back_panel, col); }
\r
86 public virtual void pix(int x, int y, Color col) { }
\r
87 public virtual void line(Line drawee) { drawee.copyToStack(this); }
\r
88 public virtual void rect(Rectangle drawee) { drawee.copyToStack(this); }
\r
89 public virtual void ellipse(Ellipse drawee) { drawee.copyToStack(this); }
\r
90 public virtual void oval(Ellipse drawee) { drawee.copyToStack(this); }
\r
91 public virtual void polygon(Polygon drawee) { drawee.copyToStack(this); }
\r
92 public virtual void letters(Letters drawee) { drawee.copyToStack(this); }
\r
93 public virtual void image(Image drawee) { drawee.copyToStack(this); }
\r
94 public virtual void group(Group drawee) { drawee.copyToStack(this); }
\r
95 public virtual void shader(ShaderField drawee) { drawee.copyToStack(this); }
\r
97 public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }
\r
98 public virtual void msg(string dstr, double x, double y, Color col)
\r
100 var let = new Letters(dstr);
\r
105 public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }
\r
106 public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }
\r
108 public virtual Point getCenter() { return new Point(0, 0, 0); }
\r
113 public class Canvas : Templates.StackableDrawable
\r
115 internal System.Windows.Controls.Canvas masterPool, prevPool;
\r
116 internal System.Windows.Point[] pointPool;
\r
117 internal int pointPoolN;
\r
118 internal SolidColorBrush[] brushPool;
\r
119 internal int brushPoolN;
\r
121 internal System.Windows.Controls.Canvas[] UIElementPool;
\r
122 internal int UIElementPoolN;
\r
123 internal int lastVisibleN;
\r
125 internal System.Windows.Shapes.Line[] linePool;
\r
126 internal int linePoolN;
\r
127 internal System.Windows.Shapes.Rectangle[] dummyRectPool;
\r
128 internal System.Windows.Shapes.Rectangle[] rectPool;
\r
129 internal int rectPoolN;
\r
130 internal System.Windows.Shapes.Rectangle[] shaderPool;
\r
131 internal int shaderPoolN;
\r
132 internal System.Windows.Shapes.Ellipse[] ellipsePool;
\r
133 internal int ellipsePoolN;
\r
134 internal System.Windows.Shapes.Polygon[] polygonPool;
\r
135 internal int polygonPoolN;
\r
136 internal System.Windows.Controls.TextBlock[] lettersPool;
\r
137 internal int lettersPoolN;
\r
138 internal System.Windows.Controls.Image[] imagePool;
\r
139 internal int imagePoolN;
\r
140 internal Dictionary<int, bool> imagePoolT;
\r
141 internal System.Windows.Controls.Canvas[] groupPool;
\r
142 internal int groupPoolN;
\r
144 #region initializer
\r
147 public static IList<Action> initialize_at_canvas_initialize__ = new List<Action>();
\r
149 public static System.Windows.Controls.UserControl default_panel;
\r
150 public static System.Windows.Controls.Canvas default_api_canvas;
\r
151 public static WriteableBitmap default_buffer;
\r
152 internal System.Windows.Controls.Canvas api_canvas;
\r
153 internal System.Windows.Controls.UserControl panel;
\r
154 Rectangle back_panel;
\r
155 double width_, height_;
\r
158 public Canvas(int wid, int hei)
\r
160 panel = default_panel;
\r
161 api_canvas = default_api_canvas;
\r
162 initialize(wid, hei);
\r
164 public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs, System.Windows.Controls.UserControl system)
\r
167 api_canvas = apicnvs;
\r
168 initialize(wid, hei);
\r
171 protected bool AsyncInitBool;
\r
172 internal void beginInvoke(Action a) { api_canvas.Dispatcher.BeginInvoke(a); }
\r
173 protected void initialize(int wid, int hei)
\r
175 before = new Clock();
\r
177 var after = new Clock();
\r
178 AsyncInitBool = false;
\r
181 api_canvas.Dispatcher.BeginInvoke(new Action<int,int>(initialize__), wid, hei);
\r
182 while (!AsyncInitBool)
\r
185 if ((after - before).at_msec() > 1000) break;
\r
187 Mouse._prime = api_canvas;
\r
188 Main.drawable = this;
\r
189 Main.canvas = this;
\r
191 back_panel = new Rectangle(wid, hei);
\r
193 flipexec = new Action(executeFlip);
\r
195 protected void initialize__(int wid, int hei)
\r
197 api_canvas.Width = wid;
\r
198 api_canvas.Height = hei+20;
\r
199 api_canvas.MouseMove += Mouse.Canvas_MousePos;
\r
200 api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;
\r
201 api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;
\r
202 api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;
\r
203 panel.KeyDown += Keyboard.Canvas_KeyDown;
\r
204 panel.KeyUp += Keyboard.Canvas_KeyUp;
\r
206 HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");
\r
207 //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");
\r
208 htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");
\r
209 htmlHost.SetStyleAttribute("height", (hei).ToString() + "px");
\r
210 htmlHost.SetStyleAttribute("margin", "2em auto auto auto");
\r
212 pointPool = new System.Windows.Point[CONST.MOBJ_N];
\r
213 brushPool = new SolidColorBrush[CONST.MOBJ_N];
\r
214 linePool = new System.Windows.Shapes.Line[CONST.MOBJ_N];
\r
215 rectPool = new System.Windows.Shapes.Rectangle[CONST.MOBJ_N];
\r
216 ellipsePool = new System.Windows.Shapes.Ellipse[CONST.MOBJ_N];
\r
217 for (int i = 0; i < CONST.MOBJ_N; i++)
\r
219 pointPool[i] = new System.Windows.Point();
\r
220 brushPool[i] = new SolidColorBrush();
\r
221 linePool[i] = new System.Windows.Shapes.Line();
\r
222 rectPool[i] = new System.Windows.Shapes.Rectangle();
\r
223 ellipsePool[i] = new System.Windows.Shapes.Ellipse();
\r
225 shaderPool = new System.Windows.Shapes.Rectangle[CONST.COBJ_N];
\r
226 polygonPool = new System.Windows.Shapes.Polygon[CONST.COBJ_N];
\r
227 lettersPool = new System.Windows.Controls.TextBlock[CONST.COBJ_N];
\r
228 for (int i = 0; i < CONST.COBJ_N; i++)
\r
230 shaderPool[i] = new System.Windows.Shapes.Rectangle();
\r
231 polygonPool[i] = new System.Windows.Shapes.Polygon();
\r
232 lettersPool[i] = new System.Windows.Controls.TextBlock();
\r
234 imagePool = new System.Windows.Controls.Image[CONST.HOBJ_N];
\r
235 imagePoolT = new Dictionary<int, bool>(CONST.HOBJ_N);
\r
236 groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N];
\r
237 for (int i = 0; i < CONST.HOBJ_N; i++)
\r
239 imagePool[i] = new System.Windows.Controls.Image();
\r
240 imagePoolT.Add(imagePool[i].GetHashCode(), false);
\r
241 groupPool[i] = new System.Windows.Controls.Canvas();
\r
244 masterPool = new System.Windows.Controls.Canvas();
\r
245 prevPool = new System.Windows.Controls.Canvas();
\r
246 api_canvas.Children.Add(masterPool);
\r
248 //api_canvas.Children.Remove(Internal.Main.widgetStack);
\r
249 Psychlops.Internal.Main.widgetStack = new StackPanel();
\r
250 Psychlops.Internal.Main.widgetStack.Orientation = Orientation.Vertical;
\r
251 Psychlops.Internal.Main.widgetStack.Height = hei;
\r
252 api_canvas.Children.Add(Psychlops.Internal.Main.widgetStack);
\r
253 Internal.Main.statusBar.Visibility = Visibility.Collapsed;
\r
256 UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N];
\r
257 dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N];
\r
258 for (int i = 0; i < CONST.MAX_OBJ_N; i++)
\r
260 UIElementPool[i] = new System.Windows.Controls.Canvas();
\r
261 masterPool.Children.Add(UIElementPool[i]);
\r
262 dummyRectPool[i] = new System.Windows.Shapes.Rectangle();
\r
263 UIElementPool[i].Children.Add(dummyRectPool[i]);
\r
264 dummyRectPool[i].Visibility = Visibility.Collapsed;
\r
267 AsyncInitBool = true;
\r
269 // initialize at Canvas initializing
\r
270 //Figures.ShaderGabor.initialize__();
\r
273 internal int findEmptyInPool(Dictionary<int, bool> pool)
\r
276 foreach( KeyValuePair<int, bool> elem in pool)
\r
285 #region static initializer
\r
294 public override void clear(Color col)
\r
296 back_panel.fill = col;
\r
301 int nextIntervalFrame = 1, chacked = 0;
\r
302 public void flip(int n)
\r
306 nextIntervalFrame = n;
\r
319 UIElementPoolN = 0;
\r
334 Internal.Main.canvas_flag.WaitOne();
\r
342 #region version modifyNative2
\r
343 public void executeFlip()
\r
345 // Clock after = new Clock();
\r
347 // AppState.statusBar = ((after - before).at_msec().ToString()) + " msec";
\r
350 ShaderField shaderS;
\r
357 System.Windows.Shapes.Line lineP;
\r
358 System.Windows.Shapes.Rectangle rectP;
\r
359 System.Windows.Shapes.Rectangle shaderP;
\r
360 System.Windows.Shapes.Ellipse ellipseP;
\r
361 System.Windows.Shapes.Polygon polygonP;
\r
362 System.Windows.Controls.TextBlock lettersP;
\r
363 System.Windows.Controls.Image imageP;
\r
364 System.Windows.Controls.Canvas groupP;
\r
368 nextIntervalFrame--;
\r
371 var cnv = UIElementPool[0];
\r
372 if (nextIntervalFrame <= 0)
\r
378 for (int i = 0; i < stackN; i++)
\r
380 if (null != (shaderS = stack[i] as ShaderField))
\r
382 if (null != (shaderP = cnv.Children[0] as System.Windows.Shapes.Rectangle))
\r
384 shaderS.modifyNative(shaderP, this);
\r
388 cnv.Children.Clear();
\r
389 cnv.Children.Add(stack[i].poolNative(this));
\r
392 else if( null != (rectS = stack[i] as Rectangle) )
\r
394 if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle))
\r
396 rectS.modifyNative(rectP, this);
\r
400 cnv.Children.Clear();
\r
401 cnv.Children.Add(stack[i].poolNative(this));
\r
404 else if (null != (lineS = stack[i] as Line))
\r
406 if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line))
\r
408 lineS.modifyNative(lineP, this);
\r
412 cnv.Children.Clear();
\r
413 cnv.Children.Add(stack[i].poolNative(this));
\r
416 else if (null != (ellipseS = stack[i] as Ellipse))
\r
418 if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse))
\r
420 ellipseS.modifyNative(ellipseP, this);
\r
424 cnv.Children.Clear();
\r
425 cnv.Children.Add(stack[i].poolNative(this));
\r
428 else if (null != (polygonS = stack[i] as Polygon))
\r
430 if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon))
\r
432 polygonS.modifyNative(polygonP, this);
\r
436 cnv.Children.Clear();
\r
437 cnv.Children.Add(stack[i].poolNative(this));
\r
440 else if (null != (lettersS = stack[i] as Letters))
\r
442 if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock))
\r
444 lettersS.modifyNative(lettersP, this);
\r
448 cnv.Children.Clear();
\r
449 cnv.Children.Add(stack[i].poolNative(this));
\r
452 else if (null != (imageS = stack[i] as Image))
\r
454 if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image))
\r
456 imageS.modifyNative(imageP, this);
\r
460 cnv.Children.Clear();
\r
461 cnv.Children.Add(stack[i].poolNative(this));
\r
464 else if (null != (groupS = stack[i] as Group))
\r
466 if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas))
\r
468 groupS.modifyNative(groupP, this);
\r
472 cnv.Children.Clear();
\r
473 cnv.Children.Add(stack[i].poolNative(this));
\r
476 cnv.Visibility = Visibility.Visible;
\r
478 cnv = UIElementPool[UIElementPoolN];
\r
480 for (int i = UIElementPoolN; i < lastVisibleN; i++)
\r
482 cnv = UIElementPool[i];
\r
483 cnv.Visibility = Visibility.Collapsed;
\r
485 lastVisibleN = UIElementPoolN;
\r
492 Psychlops.Internal.Main.canvas_flag.Set();
\r
495 System.Threading.Thread.Sleep(0);
\r
501 #region version modifyNative
\r
503 public void executeFlip()
\r
512 System.Windows.Shapes.Line lineP;
\r
513 System.Windows.Shapes.Rectangle rectP;
\r
514 System.Windows.Shapes.Ellipse ellipseP;
\r
515 System.Windows.Shapes.Polygon polygonP;
\r
516 System.Windows.Controls.TextBlock lettersP;
\r
517 System.Windows.Controls.Image imageP;
\r
518 System.Windows.Controls.Canvas groupP;
\r
522 nextIntervalFrame--;
\r
525 var en = masterPool.Children.GetEnumerator();
\r
526 bool full = en.MoveNext();
\r
527 if (nextIntervalFrame <= 0)
\r
531 //masterPool.Children.Clear();
\r
534 for (int i = 0; i < stackN - 2; i++)
\r
538 masterPool.Children.Add(stack[i].poolNative(this));
\r
542 if( null != (rectS = stack[i] as Rectangle) )
\r
544 if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle))
\r
546 rectS.modifyNative(rectP, this);
\r
549 else if (null != (lineS = stack[i] as Line))
\r
551 if (null != (lineP = en.Current as System.Windows.Shapes.Line))
\r
553 lineS.modifyNative(lineP, this);
\r
556 else if (null != (ellipseS = stack[i] as Ellipse))
\r
558 if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse))
\r
560 ellipseS.modifyNative(ellipseP, this);
\r
564 masterPool.Children.Add(stack[i].poolNative(this));
\r
567 else if (null != (polygonS = stack[i] as Polygon))
\r
569 if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon))
\r
571 polygonS.modifyNative(polygonP, this);
\r
574 else if (null != (lettersS = stack[i] as Letters))
\r
576 if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock))
\r
578 lettersS.modifyNative(lettersP, this);
\r
581 else if (null != (imageS = stack[i] as Image))
\r
583 if (null != (imageP = en.Current as System.Windows.Controls.Image))
\r
585 imageS.modifyNative(imageP, this);
\r
588 else if (null != (groupS = stack[i] as Group))
\r
590 if (null != (groupP = en.Current as System.Windows.Controls.Canvas))
\r
592 groupS.modifyNative(groupP, this);
\r
595 full = en.MoveNext();
\r
604 Psychlops.Internal.Main.canvas_flag.Set();
\r
607 System.Threading.Thread.Sleep(0);
\r
612 #region version poolNative 2
\r
614 public void executeFlip()
\r
619 nextIntervalFrame--;
\r
621 UIElementPoolN = 0;
\r
622 if (nextIntervalFrame <= 0)
\r
626 //masterPool.Children.Clear();
\r
629 for (int i = 0; i < stackN - 2; i++)
\r
631 UIElementPool[UIElementPoolN] = stack[i].poolNative(this);
\r
632 UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;
\r
636 for (int i = stackN - 2; i < 10000; i++)
\r
638 UIElementPool[UIElementPoolN] = rectPool[i];
\r
639 UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed;
\r
648 Psychlops.Internal.Main.canvas_flag.Set();
\r
651 System.Threading.Thread.Sleep(0);
\r
659 public double width { get { return width_; } }
\r
660 public double height { get { return height_; } }
\r
661 public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }
\r
662 public double getWidth() { return width; }
\r
663 public double getHeight() { return height; }
\r
664 public override Point getCenter() { return center; }
\r
665 public double getHCenter() { return width / 2; }
\r
666 public double getVCenter() { return height / 2; }
\r
667 public double getRefreshRate() { return 60; }
\r
672 #region compatibitily trick
\r
674 public enum Mode { window, fullscreen }
\r
675 public static readonly Mode window = Mode.window, fullscreen = Mode.fullscreen;
\r
677 public Canvas(int wid, int hei, Mode mod)
\r
679 panel = default_panel;
\r
680 api_canvas = default_api_canvas;
\r
681 initialize(500, 500);
\r
683 public Canvas(Mode mod)
\r
686 panel = default_panel;
\r
687 api_canvas = default_api_canvas;
\r
688 initialize(500, 500);
\r
691 public Canvas(int wid, int hei, Mode mod, Display.DisplayName name)
\r
693 panel = default_panel;
\r
694 api_canvas = default_api_canvas;
\r
695 initialize(500, 500);
\r
697 public Canvas(Mode mod, Display.DisplayName name)
\r
700 panel = default_panel;
\r
701 api_canvas = default_api_canvas;
\r
702 initialize(500, 500);
\r
706 public void showFPS(bool sw = true) { }
\r
707 public void watchFPS(bool sw = true) { }
\r
710 public void clear(double lum)
\r
712 clear(new Color(lum));
\r
722 #region primitive tokenizer
\r
727 partial struct Point
\r
729 public static implicit operator System.Windows.Point(Point d)
\r
731 return new System.Windows.Point(d.x, d.y);
\r
735 public Point datum { get { return this; } set { this = value; } }
\r
736 public Point shift(Point p) { this = this + p; return this; }
\r
737 public Point centering(Point p) { this = p; return this; }
\r
738 public Point getDatum() { return this; }
\r
739 public Point setDatum(Point p) { this = p; return p; }
\r
740 public Point shift(double x, double y, double z = 0.0) { return shift(new Point(x, y, z)); }
\r
741 public Point centering() { return centering(Main.drawable.getCenter()); }
\r
742 public Point centering(double x, double y, double z = 0.0) { return centering(new Point(x, y, z)); }
\r
745 partial struct Color
\r
747 public static implicit operator System.Windows.Media.Color(Color d)
\r
749 return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));
\r
751 public static implicit operator System.Windows.Media.SolidColorBrush(Color d)
\r
753 return new SolidColorBrush { Color = d };
\r
755 public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)
\r
757 var tmp = d.brushPool[d.brushPoolN];
\r
765 partial struct Stroke
\r
767 public void apply(System.Windows.Shapes.Shape target)
\r
769 target.Stroke = this;
\r
770 //target.StrokeDashArray
\r
771 target.StrokeThickness = thick;
\r
773 public static implicit operator SolidColorBrush(Stroke d)
\r
775 return new SolidColorBrush { Color = d.color };
\r
777 public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)
\r
779 var tmp = d.brushPool[d.brushPoolN];
\r
780 tmp.Color = this.color;
\r
794 return (Line)MemberwiseClone();
\r
796 public Line clone()
\r
798 return (Line)MemberwiseClone();
\r
800 public static implicit operator System.Windows.Shapes.Line(Line d)
\r
802 var tmp = new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };
\r
803 if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;
\r
804 else d.stroke.apply(tmp);
\r
807 public UIElement toNative() { return this; }
\r
809 public void copyToStack(Templates.StackableDrawable d)
\r
811 var tmp = d.lineStack[d.lineStackN];
\r
812 tmp.begin.x = begin.x;
\r
813 tmp.begin.y = begin.y;
\r
817 tmp.stroke = stroke;
\r
818 d.stack[d.stackN] = tmp;
\r
822 public UIElement poolNative(Canvas d)
\r
824 var tmp = d.linePool[d.linePoolN];
\r
829 if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);
\r
830 else stroke.apply(tmp);
\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 public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d)
\r
843 if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);
\r
844 else stroke.apply(tmp);
\r
845 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
846 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
847 tmp.Visibility = Visibility.Visible;
\r
855 partial class Rectangle
\r
857 public Rectangle dup()
\r
859 return (Rectangle)MemberwiseClone();
\r
861 public Rectangle clone()
\r
863 return (Rectangle)MemberwiseClone();
\r
865 public static implicit operator System.Windows.Rect(Rectangle d)
\r
867 return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);
\r
869 public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)
\r
871 var tmp = new System.Windows.Shapes.Rectangle { 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
879 public void copyToStack(Templates.StackableDrawable d)
\r
881 var tmp = d.rectStack[d.rectStackN];
\r
885 d.stack[d.stackN] = tmp;
\r
889 public UIElement poolNative(Canvas d)
\r
891 var tmp = d.rectPool[d.rectPoolN];
\r
893 tmp.Height = height;
\r
894 tmp.Fill = fill.getNativeFromStack(d);
\r
895 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
896 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
897 tmp.Visibility = Visibility.Visible;
\r
901 public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)
\r
904 tmp.Height = height;
\r
905 tmp.Fill = fill.getNativeFromStack(d);
\r
906 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
907 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
908 tmp.Visibility = Visibility.Visible;
\r
914 #region ShaderField
\r
916 partial class ShaderField
\r
918 public System.Windows.Media.Effects.Effect shader;
\r
919 protected static System.Windows.Media.SolidColorBrush dummyfill = null;
\r
921 protected static void initializeShader()
\r
923 dummyfill = new SolidColorBrush(System.Windows.Media.Colors.Blue);
\r
926 public UIElement toNative() { return null; }
\r
927 public void copyToStack(Templates.StackableDrawable d)
\r
929 var tmp = d.shaderStack[d.shaderStackN];
\r
930 tmp.initialize__ = initialize__;
\r
931 tmp.setParameters = setParameters;
\r
934 tmp.shader = shader;
\r
935 d.stack[d.stackN] = tmp;
\r
939 public UIElement poolNative(Canvas d)
\r
941 var tmp = d.shaderPool[d.shaderPoolN];
\r
943 tmp.Height = height;
\r
944 if (!initialized) { initialize__(); }
\r
946 tmp.Effect = shader;
\r
947 tmp.Fill = dummyfill;
\r
948 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
949 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
950 tmp.Visibility = Visibility.Visible;
\r
954 public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)
\r
957 tmp.Height = height;
\r
958 if (!initialized) { initialize__(); }
\r
960 tmp.Effect = shader;
\r
961 tmp.Fill = dummyfill;
\r
962 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
963 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
964 tmp.Visibility = Visibility.Visible;
\r
972 partial class Ellipse
\r
974 public Ellipse dup()
\r
976 return (Ellipse)MemberwiseClone();
\r
978 public Ellipse clone()
\r
980 return (Ellipse)MemberwiseClone();
\r
982 public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)
\r
984 var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };
\r
985 d.stroke.apply(tmp);
\r
986 System.Windows.Controls.Canvas.SetLeft(tmp, d.left);
\r
987 System.Windows.Controls.Canvas.SetTop(tmp, d.top);
\r
991 public UIElement toNative() { return this; }
\r
993 public void copyToStack(Templates.StackableDrawable d)
\r
995 var tmp = d.ellipseStack[d.ellipseStackN];
\r
997 tmp.xdiameter = xdiameter;
\r
998 tmp.ydiameter = ydiameter;
\r
1000 d.stack[d.stackN] = tmp;
\r
1001 d.ellipseStackN++;
\r
1004 public UIElement poolNative(Canvas d)
\r
1006 var tmp = d.ellipsePool[d.ellipsePoolN];
\r
1007 tmp.Width = width;
\r
1008 tmp.Height = height;
\r
1009 tmp.Fill = fill.getNativeFromStack(d);
\r
1010 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
1011 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
1012 tmp.Visibility = Visibility.Visible;
\r
1016 public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d)
\r
1018 tmp.Width = width;
\r
1019 tmp.Height = height;
\r
1020 tmp.Fill = fill.getNativeFromStack(d);
\r
1021 System.Windows.Controls.Canvas.SetLeft(tmp, left);
\r
1022 System.Windows.Controls.Canvas.SetTop(tmp, top);
\r
1023 tmp.Visibility = Visibility.Visible;
\r
1031 partial class Polygon
\r
1033 public Polygon dup()
\r
1035 return (Polygon)MemberwiseClone();
\r
1037 public Polygon clone()
\r
1039 return (Polygon)MemberwiseClone();
\r
1041 public static implicit operator System.Windows.Shapes.Polygon(Polygon d)
\r
1043 var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };
\r
1044 d.stroke.apply(tmp);
\r
1045 foreach (Point p in d.vertices)
\r
1047 tmp.Points.Add(p);
\r
1049 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
1050 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
1053 public UIElement toNative() { return this; }
\r
1055 public void copyToStack(Templates.StackableDrawable d)
\r
1057 var tmp = d.polygonStack[d.polygonStackN];
\r
1058 tmp.datum = datum;
\r
1059 tmp.vertices.Clear();
\r
1060 foreach (var v in vertices)
\r
1062 tmp.vertices.Add(v);
\r
1065 d.stack[d.stackN] = tmp;
\r
1066 d.polygonStackN++;
\r
1069 public UIElement poolNative(Canvas d)
\r
1071 var tmp = d.polygonPool[d.polygonPoolN];
\r
1072 tmp.Fill = fill.getNativeFromStack(d);
\r
1073 tmp.Points.Clear();
\r
1074 foreach (var v in vertices)
\r
1076 tmp.Points.Add(v);
\r
1078 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1079 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1080 tmp.Visibility = Visibility.Visible;
\r
1084 public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)
\r
1086 tmp.Fill = fill.getNativeFromStack(d);
\r
1087 tmp.Points.Clear();
\r
1088 foreach (var v in vertices)
\r
1090 tmp.Points.Add(v);
\r
1092 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1093 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1094 tmp.Visibility = Visibility.Visible;
\r
1103 partial class Letters
\r
1105 #region static initializer
\r
1106 internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;
\r
1107 internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;
\r
1108 internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;
\r
1111 FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();
\r
1112 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);
\r
1113 FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);
\r
1114 FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();
\r
1115 FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);
\r
1116 FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);
\r
1117 FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);
\r
1118 LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();
\r
1119 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);
\r
1120 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);
\r
1121 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);
\r
1122 LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);
\r
1125 public Letters dup()
\r
1127 return (Letters)MemberwiseClone();
\r
1129 public Letters clone()
\r
1131 return (Letters)MemberwiseClone();
\r
1133 public static implicit operator System.Windows.Controls.TextBlock(Letters d)
\r
1135 //var zapi_shape = new System.Windows.Documents.Glyphs();
\r
1136 var tmp = new System.Windows.Controls.TextBlock {
\r
1137 Text = d.str, Width = 500, Height = 500,
\r
1138 FontSize = d.font.size,
\r
1139 //tmp.FontFamily = ,
\r
1140 FontStyle = FONT_STYLE_BRIDGE[d.font.style],
\r
1141 FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],
\r
1142 TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],
\r
1143 Foreground = d.fill
\r
1148 case Letters.HorizontalAlign.left: break;
\r
1149 case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;
\r
1150 case Letters.HorizontalAlign.right: left = tmp.Width; break;
\r
1152 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);
\r
1153 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);
\r
1156 public UIElement toNative() { return this; }
\r
1158 public void copyToStack(Templates.StackableDrawable d)
\r
1160 var tmp = d.lettersStack[d.lettersStackN];
\r
1162 tmp.datum = datum;
\r
1164 d.stack[d.stackN] = tmp;
\r
1165 d.lettersStackN++;
\r
1168 public UIElement poolNative(Canvas d)
\r
1170 var tmp = d.lettersPool[d.lettersPoolN];
\r
1174 tmp.FontSize = font.size;
\r
1175 //tmp.FontFamily = ,
\r
1176 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
1177 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
1178 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
1179 tmp.Foreground = fill.getNativeFromStack(d);
\r
1180 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1181 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1182 tmp.Visibility = Visibility.Visible;
\r
1186 public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d)
\r
1191 tmp.FontSize = font.size;
\r
1192 //tmp.FontFamily = ,
\r
1193 tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];
\r
1194 tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];
\r
1195 tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];
\r
1196 tmp.Foreground = fill.getNativeFromStack(d);
\r
1197 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1198 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1199 tmp.Visibility = Visibility.Visible;
\r
1207 partial class Image
\r
1209 internal void initialize__(int wid, int hei)
\r
1211 AsyncBool = false;
\r
1212 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action<int,int>(create__), wid, hei);
\r
1213 while (!AsyncBool) { System.Threading.Thread.Sleep(10); }
\r
1215 internal void create__(int wid, int hei)
\r
1217 buffer = new WriteableBitmap(wid, hei);
\r
1220 internal void load__(string uri)
\r
1222 AsyncBool = false;
\r
1223 var ur = new System.Uri(uri, System.UriKind.RelativeOrAbsolute);
\r
1224 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action<Uri>(load_), ur);
\r
1225 while (!AsyncBool) { System.Threading.Thread.Sleep(10); }
\r
1227 internal void load_(Uri uri)
\r
1229 var bitmap = new BitmapImage();
\r
1230 bitmap.CreateOptions = BitmapCreateOptions.None;
\r
1231 bitmap.UriSource = uri;
\r
1234 var wbm = new System.Windows.Media.Imaging.WriteableBitmap(bitmap);
\r
1237 //catch (Exception e)
\r
1239 // buffer = new WriteableBitmap(64, 64);
\r
1240 // buffer.ForEach(bitmap_drawChecker);
\r
1242 self_rect.set(buffer.PixelWidth, buffer.PixelHeight);
\r
1245 static System.Windows.Media.Color[] CHECKER_C;
\r
1248 CHECKER_C = new System.Windows.Media.Color[2];
\r
1249 CHECKER_C[0] = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);
\r
1250 CHECKER_C[1] = System.Windows.Media.Color.FromArgb(128,128,128,128);
\r
1252 static System.Windows.Media.Color bitmap_drawChecker(int x, int y)
\r
1254 return ((x / 4) + (y / 4)) % 2 == 0 ? CHECKER_C[0] : CHECKER_C[1];
\r
1256 delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);
\r
1257 delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);
\r
1258 public void field__(System.Func<int, int, System.Windows.Media.Color> func)
\r
1260 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);
\r
1261 //buffer.ForEach(func);
\r
1263 public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
1265 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);
\r
1266 //buffer.ForEach(func);
\r
1268 public void field___(System.Func<int, int, System.Windows.Media.Color> func)
\r
1270 buffer.ForEach(func);
\r
1272 public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
1274 buffer.ForEach(func);
\r
1277 public Image clone()
\r
1279 return (Image)MemberwiseClone();
\r
1281 public static implicit operator System.Windows.Controls.Image(Image d)
\r
1283 var tmp = new System.Windows.Controls.Image();
\r
1284 tmp.Source = d.buffer;
\r
1285 System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);
\r
1286 System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);
\r
1289 public UIElement toNative() { return this; }
\r
1291 public void copyToStack(Templates.StackableDrawable d)
\r
1293 var tmp = d.imageStack[d.imageStackN];
\r
1294 tmp.datum = datum;
\r
1295 tmp.buffer = buffer;
\r
1296 tmp.self_rect = self_rect;
\r
1297 d.stack[d.stackN] = tmp;
\r
1301 public UIElement poolNative(Canvas d)
\r
1303 var tmp = d.imagePool[d.imagePoolN];
\r
1304 tmp.Source = buffer;
\r
1305 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1306 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1307 tmp.Visibility = Visibility.Visible;
\r
1311 public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)
\r
1313 tmp.Source = buffer;
\r
1314 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1315 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1316 tmp.Visibility = Visibility.Visible;
\r
1325 partial class Group
\r
1327 internal void initialize__()
\r
1329 Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action(create__));
\r
1331 internal void create__()
\r
1333 cnvs = new System.Windows.Controls.Canvas();
\r
1334 trans = new System.Windows.Media.TransformGroup();
\r
1335 transF = new System.Windows.Media.TransformCollection();
\r
1336 rotateF = new System.Windows.Media.RotateTransform();
\r
1337 scaleF = new System.Windows.Media.ScaleTransform();
\r
1338 translateF = new System.Windows.Media.TranslateTransform();
\r
1339 transF.Add(rotateF);
\r
1340 transF.Add(scaleF);
\r
1341 transF.Add(translateF);
\r
1342 trans.Children = transF;
\r
1343 cnvs.RenderTransform = trans;
\r
1346 public Group clone()
\r
1348 return (Group)MemberwiseClone();
\r
1351 delegate void AppendFunc1(Internal.PrimitiveFigure func);
\r
1352 void append__(Internal.PrimitiveFigure fig)
\r
1354 fig.centering(0, 0);
\r
1355 UIElement e = fig.toNative();
\r
1356 cnvs.Children.Add(e);
\r
1357 System.Windows.Controls.Canvas.SetLeft(e, fig.datum.x);
\r
1358 System.Windows.Controls.Canvas.SetTop(e, fig.datum.y);
\r
1360 delegate void SimpleProcedure();
\r
1361 void getRotation__() { rotation_ = rotateF.Angle; }
\r
1362 void setRotation__() { rotateF.Angle = rotation_; }
\r
1363 //void getTranslation__() { rotation_ = rotateF.Angle; }
\r
1364 void setTranslation__() { translateF.X = datum.x; translateF.Y = datum.y; }
\r
1365 void setScaling__() { scaleF.ScaleX = scaling_.x; scaleF.ScaleY = scaling_.y; }
\r
1367 public static implicit operator System.Windows.Controls.Canvas(Group d)
\r
1369 var tmp = d.cnvs;//new System.Windows.Controls.Canvas();
\r
1370 System.Windows.Controls.Canvas.SetLeft(d.cnvs, d.datum.x);
\r
1371 System.Windows.Controls.Canvas.SetTop(d.cnvs, d.datum.y);
\r
1374 public UIElement toNative() { return this; }
\r
1376 public void copyToStack(Templates.StackableDrawable d)
\r
1378 var tmp = d.groupStack[d.groupStackN];
\r
1379 tmp.datum = datum;
\r
1381 d.stack[d.stackN] = tmp;
\r
1385 public UIElement poolNative(Canvas d)
\r
1387 //d.groupPool[d.groupPoolN] = cnvs;
\r
1388 //var tmp = d.groupPool[d.groupPoolN];
\r
1390 System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);
\r
1391 System.Windows.Controls.Canvas.SetTop(tmp, datum.y);
\r
1392 tmp.Visibility = Visibility.Visible;
\r
1396 public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d)
\r
1398 d.groupPool[d.groupPoolN] = cnvs;
\r
1399 System.Windows.Controls.Canvas.SetLeft(cnvs, datum.x);
\r
1400 System.Windows.Controls.Canvas.SetTop(cnvs, datum.y);
\r
1401 tmp.Visibility = Visibility.Visible;
\r