\r
public class StackableDrawable : Drawable\r
{\r
- protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
+// protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
+ internal Internal.PrimitiveFigure[] stack;\r
+ internal int stackN;\r
+ internal Line[] lineStack;\r
+ internal int lineStackN;\r
+ internal Rectangle[] rectStack;\r
+ internal int rectStackN;\r
+ internal Ellipse[] ellipseStack;\r
+ internal int ellipseStackN;\r
+ internal Polygon[] polygonStack;\r
+ internal int polygonStackN;\r
+ internal Letters[] lettersStack;\r
+ internal int lettersStackN;\r
+ internal Image[] imageStack;\r
+ internal int imageStackN;\r
+\r
\r
public StackableDrawable()\r
{\r
- stack = new System.Collections.Generic.Queue<Internal.PrimitiveFigure>();\r
+// stack = new System.Collections.Generic.Queue<Internal.PrimitiveFigure>();\r
+ stack = new Internal.PrimitiveFigure[40000];\r
+ lineStack = new Line[10000];\r
+ rectStack = new Rectangle[10000];\r
+ ellipseStack = new Ellipse[10000];\r
+ polygonStack = new Polygon[1000];\r
+ lettersStack = new Letters[1000];\r
+ imageStack = new Image[1000];\r
+ for (int i = 0; i < 10000; i++)\r
+ {\r
+ lineStack[i] = new Line(0,0,0,0);\r
+ rectStack[i] = new Rectangle();\r
+ ellipseStack[i] = new Ellipse();\r
+ }\r
+ for (int i = 0; i < 1000; i++)\r
+ {\r
+ polygonStack[i] = new Polygon();\r
+ lettersStack[i] = new Letters();\r
+ //imageStack[i] = new Image();\r
+ }\r
}\r
\r
public void clear()\r
\r
public virtual void line(Line drawee)\r
{\r
- stack.Enqueue(drawee.clone());\r
+// stack.Enqueue(drawee.clone());\r
}\r
\r
public virtual void rect(Rectangle drawee)\r
{\r
- stack.Enqueue(drawee.clone());\r
+ //stack.Enqueue(drawee.clone());\r
+// stack.Enqueue(drawee.copyToStack(this));\r
+ drawee.copyToStack(this);\r
}\r
\r
public virtual void ellipse(Ellipse drawee)\r
{\r
- stack.Enqueue(drawee.clone());\r
+ // stack.Enqueue(drawee.clone());\r
+ drawee.copyToStack(this);\r
}\r
\r
public virtual void polygon(Polygon drawee)\r
{\r
- stack.Enqueue(drawee.clone());\r
+ // stack.Enqueue(drawee.clone());\r
+ drawee.copyToStack(this);\r
}\r
\r
public virtual void letters(Letters drawee)\r
{\r
- stack.Enqueue(drawee.clone());\r
+ // stack.Enqueue(drawee.clone());\r
+ drawee.copyToStack(this);\r
}\r
\r
public virtual void image(Image drawee)\r
{\r
- stack.Enqueue(drawee.clone());\r
+ // stack.Enqueue(drawee.clone());\r
+ drawee.copyToStack(this);\r
}\r
\r
public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
public class Canvas : Templates.StackableDrawable\r
{\r
\r
+ internal System.Windows.Controls.Canvas masterPool, prevPool;\r
+ internal System.Windows.Point[] pointPool;\r
+ internal int pointPoolN;\r
+ internal SolidColorBrush[] brushPool;\r
+ internal int brushPoolN;\r
+ internal System.Windows.Shapes.Line[] linePool;\r
+ internal int linePoolN;\r
+ internal System.Windows.Shapes.Rectangle[] rectPool;\r
+ internal int rectPoolN;\r
+ internal System.Windows.Shapes.Ellipse[] ellipsePool;\r
+ internal int ellipsePoolN;\r
+ internal System.Windows.Shapes.Polygon[] polygonPool;\r
+ internal int polygonPoolN;\r
+\r
#region initializer\r
\r
internal delegate void TwoIntProcedure(int x, int y);\r
}\r
protected void initialize(int wid, int hei)\r
{\r
-\r
width_ = wid;\r
height_ = hei;\r
api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei);\r
\r
HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");\r
//if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");\r
- htmlHost.SetStyleAttribute("width", (200+wid).ToString()+"px");\r
+ htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");\r
htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px");\r
htmlHost.SetStyleAttribute("margin", "2em auto auto auto");\r
+\r
+\r
+ pointPool = new System.Windows.Point[10000];\r
+ brushPool = new SolidColorBrush[10000];\r
+ linePool = new System.Windows.Shapes.Line[10000];\r
+ rectPool = new System.Windows.Shapes.Rectangle[10000];\r
+ for (int i = 0; i < 10000; i++)\r
+ {\r
+ pointPool[i] = new System.Windows.Point();\r
+ brushPool[i] = new SolidColorBrush();\r
+ linePool[i] = new System.Windows.Shapes.Line();\r
+ rectPool[i] = new System.Windows.Shapes.Rectangle();\r
+ }\r
+ for (int i = 0; i < 300; i++)\r
+ {\r
+ api_canvas.Children.Add(rectStack[i].poolNative(this));\r
+ api_canvas.Children.Add(rectStack[i].poolNative(this));\r
+ }\r
+\r
+ masterPool = new System.Windows.Controls.Canvas();\r
+ prevPool = new System.Windows.Controls.Canvas();\r
+// masterPool.Children.Add()\r
}\r
\r
#endregion\r
public override void clear(Color col)\r
{\r
back_panel.fill = col;\r
+// stack.Clear();\r
+ stackN = 0;\r
rect(back_panel);\r
}\r
\r
int nextIntervalFrame = 1, chacked = 0;\r
+ /*\r
public void flip()\r
{\r
//api_canvas.Dispatcher.BeginInvoke(flipexec);\r
nextIntervalFrame = 1;\r
chacked = 1;\r
}\r
+// pointPoolN = 0;\r
+// brushPoolN = 0;\r
+// linePoolN = 0;\r
+ rectPoolN = 0;\r
+ lineStackN = 0;\r
+ rectStackN = 0;\r
Internal.Main.canvas_flag.WaitOne();\r
}\r
public void executeFlip()\r
}\r
if (nextIntervalFrame <= 0)\r
{\r
+ var rr = new Random();\r
//Psychlops.AppState.statusBar = chacked.ToString();\r
if (chacked > 0)\r
{\r
+ // prevPool.Children.Clear();\r
var tmp = new System.Windows.Controls.Canvas();\r
if (stack.Count > 0)\r
+ // if (stackN > 0)\r
{\r
- foreach (Internal.PrimitiveFigure f in stack)\r
+ //foreach (UIElement e in api_canvas.Children)\r
+ //{\r
+ //}\r
+// foreach (Internal.PrimitiveFigure f in stack)\r
+ for (int i = 0; i < stackN - 2; i++)\r
{\r
- tmp.Children.Add(f.toNative());\r
+ // tmp.Children.Add(f.toNative());\r
+// tmp.Children.Add(f.poolNative(this));\r
+ tmp.Children.Add(stack[i].poolNative(this));\r
+ // System.Windows.Controls.Canvas.SetLeft(api_canvas.Children[i + 1], rectStack[i].left);\r
+ // api_canvas.Children[0] = api_canvas.Children[0];\r
}\r
+ stackN = 0;\r
+\r
}\r
api_canvas.Children.Clear();\r
api_canvas.Children.Add(tmp);\r
- stack.Clear();\r
+ // stack.Clear();\r
+ lock (this)\r
+ {\r
+ chacked = 0;\r
+ }\r
+ Psychlops.Internal.Main.canvas_flag.Set();\r
+ // prevPool = tmp;\r
+ }\r
+ }\r
+ System.Threading.Thread.Sleep(0);\r
+ }\r
+ */\r
+\r
+ public void flip()\r
+ {\r
+ lock (this)\r
+ {\r
+ nextIntervalFrame = 1;\r
+ chacked = 1;\r
+ }\r
+ // pointPoolN = 0;\r
+ // brushPoolN = 0;\r
+ // linePoolN = 0;\r
+ rectPoolN = 0;\r
+ lineStackN = 0;\r
+ rectStackN = 0;\r
+ Internal.Main.canvas_flag.WaitOne();\r
+ }\r
+ public void executeFlip()\r
+ {\r
+ lock (this)\r
+ {\r
+ nextIntervalFrame--;\r
+ }\r
+ if (nextIntervalFrame <= 0)\r
+ {\r
+ if (chacked > 0)\r
+ {\r
+ //api_canvas.Children.Clear();\r
+ //var tmp = new System.Windows.Controls.Canvas();\r
+ if (stackN > 0)\r
+ {\r
+ for (int i = 0; i < stackN - 2; i++)\r
+ {\r
+ //api_canvas.Children.Add(stack[i].poolNative(this));\r
+ api_canvas.Children.Add(stack[i].poolNative(this));\r
+ }\r
+ stackN = 0;\r
+ }\r
+ //api_canvas.Children.Clear();\r
+ //api_canvas.Children.Add(tmp);\r
lock (this)\r
{\r
chacked = 0;\r
System.Threading.Thread.Sleep(0);\r
}\r
\r
+\r
+\r
#region Properties\r
\r
public double width { get { return width_; } }\r
return tmp;\r
}\r
public UIElement toNative() { return this; }\r
+\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.linePool[d.linePoolN];\r
+ tmp.X1 = begin.x;\r
+ tmp.Y1 = begin.y;\r
+ tmp.X2 = end.x;\r
+ tmp.Y2 = end.y;\r
+ if (stroke.thick == 0.0) tmp.Stroke = fill;\r
+ else stroke.apply(tmp);\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.linePoolN++;\r
+ return tmp;\r
+ }\r
}\r
\r
partial class Rectangle\r
System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
return tmp;\r
}\r
+\r
public UIElement toNative() { return this; }\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.rectStack[d.rectStackN];\r
+ tmp.v1 = v1;\r
+ tmp.v2 = v2;\r
+ tmp.fill = fill;\r
+ d.stack[d.stackN] = tmp;\r
+ d.rectStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.rectPool[d.rectPoolN];\r
+ tmp.Width = width;\r
+ tmp.Height = height;\r
+ tmp.Fill = fill;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.rectPoolN++;\r
+ return tmp;\r
+ }\r
}\r
\r
partial class Ellipse\r
System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
return tmp;\r
}\r
+\r
public UIElement toNative() { return this; }\r
+\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.ellipseStack[d.ellipseStackN];\r
+ tmp.datum = datum;\r
+ tmp.xdiameter = xdiameter;\r
+ tmp.ydiameter = ydiameter;\r
+ tmp.fill = fill;\r
+ d.stack[d.stackN] = tmp;\r
+ d.rectStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.ellipsePool[d.ellipsePoolN];\r
+ tmp.Width = width;\r
+ tmp.Height = height;\r
+ tmp.Fill = fill;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.ellipsePoolN++;\r
+ return this;\r
+ }\r
}\r
\r
partial class Polygon\r
return tmp;\r
}\r
public UIElement toNative() { return this; }\r
+\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.polygonStack[d.polygonStackN];\r
+ tmp.datum = datum;\r
+ tmp.vertices.Clear();\r
+ foreach (var v in vertices)\r
+ {\r
+ tmp.vertices.Add(v);\r
+ }\r
+ tmp.fill = fill;\r
+ d.stack[d.stackN] = tmp;\r
+ d.rectStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ var tmp = d.polygonPool[d.polygonPoolN];\r
+ tmp.Fill = fill;\r
+ /*\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
+ */ \r
+ tmp.Visibility = Visibility.Visible;\r
+ d.polygonPoolN++;\r
+ return this;\r
+ }\r
+\r
}\r
\r
partial class Letters\r
return tmp;\r
}\r
public UIElement toNative() { return this; }\r
+\r
+ public void copyToStack(Templates.StackableDrawable d)\r
+ {\r
+ var tmp = d.polygonStack[d.polygonStackN];\r
+ tmp.datum = datum;\r
+ tmp.fill = fill;\r
+ d.stack[d.stackN] = tmp;\r
+ d.rectStackN++;\r
+ d.stackN++;\r
+ }\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ /* var tmp = d.rectPool[d.rectPoolN];\r
+ tmp.Width = width;\r
+ tmp.Height = height;\r
+ tmp.Fill = fill;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.rectPoolN++;\r
+*/\r
+ return this;\r
+ }\r
}\r
\r
partial class Image\r
return tmp;\r
}\r
public UIElement toNative() { return this; }\r
+\r
+ public UIElement poolNative(Canvas d)\r
+ {\r
+ /* var tmp = d.rectPool[d.rectPoolN];\r
+ tmp.Width = width;\r
+ tmp.Height = height;\r
+ tmp.Fill = fill;\r
+ System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+ System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top);\r
+ tmp.Visibility = Visibility.Visible;\r
+ d.rectPoolN++;\r
+*/\r
+ return this;\r
+ }\r
+\r
}\r
\r
#endregion\r