using System.Windows.Media.Animation;\r
using System.Windows.Media.Imaging;\r
using System.Windows.Shapes;\r
+using System.Windows.Browser;\r
\r
\r
\r
namespace Psychlops\r
{\r
\r
- public class Canvas : Drawable\r
+ namespace Templates\r
+ {\r
+\r
+ public class StackableDrawable : Drawable\r
+ {\r
+ protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
+\r
+ public StackableDrawable()\r
+ {\r
+ stack = new System.Collections.Generic.Queue<Internal.PrimitiveFigure>();\r
+ }\r
+\r
+ public void clear()\r
+ {\r
+ clear(Color.black);\r
+ }\r
+ public virtual void clear(Color col)\r
+ {\r
+ //rect(back_panel, col);\r
+ }\r
+\r
+ public virtual void pix(int x, int y, Color col)\r
+ {\r
+ }\r
+\r
+ public virtual void line(Line drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public virtual void rect(Rectangle drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public virtual void ellipse(Ellipse drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public virtual void polygon(Polygon drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public virtual void letters(Letters drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public virtual void image(Image drawee)\r
+ {\r
+ stack.Enqueue(drawee.clone());\r
+ }\r
+\r
+ public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
+ public virtual void msg(string str, double x, double y, Color col)\r
+ {\r
+ var let = new Letters(str);\r
+ let.locate(x, y);\r
+ let.fill = col;\r
+ this.letters(let);\r
+ }\r
+ public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }\r
+ public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }\r
+\r
+ public virtual Point getCenter() { return new Point(0, 0, 0); }\r
+ }\r
+\r
+ }\r
+\r
+ public class Canvas : Templates.StackableDrawable\r
{\r
\r
#region initializer\r
\r
- System.Collections.Generic.Queue<Figure> stock;\r
internal delegate void TwoIntProcedure(int x, int y);\r
internal delegate void SimpleProcedure();\r
SimpleProcedure flipexec;\r
\r
back_panel = new Rectangle(wid, hei);\r
\r
- stock = new System.Collections.Generic.Queue<Figure>();\r
flipexec = new SimpleProcedure(executeFlip);\r
}\r
protected void initialize__(int wid, int hei)\r
api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;\r
panel.KeyDown += Keyboard.Canvas_KeyDown;\r
panel.KeyUp += Keyboard.Canvas_KeyUp;\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("height", (20+hei).ToString() + "px");\r
+ htmlHost.SetStyleAttribute("margin", "2em auto auto auto");\r
}\r
\r
#endregion\r
#endregion\r
\r
\r
- public void clear()\r
- {\r
- clear(Color.black);\r
- }\r
- public void clear(Color col)\r
- {\r
- //api_canvas.Children.Clear();\r
- rect(back_panel, col);\r
- }\r
-\r
- public void pix(int x, int y, Color col)\r
- {\r
- //buffer.SetPixel(x, y, col);\r
- }\r
-\r
- public void line(Line drawee, Color col)\r
- {\r
- var tmp = drawee.clone();\r
- tmp.fill = col;\r
- stock.Enqueue(tmp);\r
- }\r
- public void line(Line drawee)\r
- {\r
- stock.Enqueue(drawee.clone());\r
- }\r
- public void rect(Rectangle drawee, Color col)\r
- {\r
- var tmp = drawee.clone();\r
- tmp.fill = col;\r
- stock.Enqueue(tmp);\r
- }\r
- public void rect(Rectangle drawee)\r
- {\r
- stock.Enqueue(drawee.clone());\r
- }\r
- public void ellipse(Ellipse drawee, Color col)\r
- {\r
- var tmp = drawee.clone();\r
- tmp.fill = col;\r
- stock.Enqueue(tmp);\r
- }\r
- public void ellipse(Ellipse drawee)\r
- {\r
- stock.Enqueue(drawee.clone());\r
- }\r
- public void polygon(Polygon drawee, Color col)\r
- {\r
- var tmp = drawee.clone();\r
- tmp.fill = col;\r
- stock.Enqueue(tmp);\r
- }\r
- public void polygon(Polygon drawee)\r
- {\r
- stock.Enqueue(drawee.clone());\r
- }\r
- public void letters(Letters drawee, Color col)\r
- {\r
- var tmp = drawee.clone();\r
- tmp.fill = col;\r
- stock.Enqueue(tmp);\r
- }\r
- public void letters(Letters drawee)\r
- {\r
- stock.Enqueue(drawee.clone());\r
- }\r
- public void image(Image drawee)\r
- {\r
- //buffer.Blit(drawee.datum, drawee.buffer, drawee.self_rect, Colors.White, WriteableBitmapExtensions.BlendMode.None);\r
- stock.Enqueue(drawee.clone());\r
- }\r
-\r
-\r
- public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
- public void msg(string str, double x, double y, Color col)\r
+ public override void clear(Color col)\r
{\r
- var let = new Letters(str);\r
- let.locate(x, y);\r
- this.letters(let, col);\r
+ back_panel.fill = col;\r
+ rect(back_panel);\r
}\r
- public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }\r
- public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }\r
-\r
\r
+ int nextIntervalFrame = 1;\r
public void flip()\r
{\r
//api_canvas.Dispatcher.BeginInvoke(flipexec);\r
//flipexec();\r
//System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\r
- Main.flag.WaitOne();\r
+ lock (this)\r
+ {\r
+ nextIntervalFrame = 1;\r
+ }\r
+ Internal.Main.canvas_flag.WaitOne();\r
}\r
- \r
public void executeFlip()\r
{\r
- api_canvas.Children.Clear();\r
- foreach (Figure f in stock)\r
+ lock (this)\r
+ {\r
+ nextIntervalFrame--;\r
+ }\r
+ if (nextIntervalFrame <= 0)\r
{\r
- api_canvas.Children.Add(f.toNative());\r
+ var tmp = new System.Windows.Controls.Canvas();\r
+ if (stack.Count > 0)\r
+ {\r
+ foreach (Internal.PrimitiveFigure f in stack)\r
+ {\r
+ tmp.Children.Add(f.toNative());\r
+ }\r
+ }\r
+ api_canvas.Children.Clear();\r
+ api_canvas.Children.Add(tmp);\r
+ stack.Clear();\r
+ Psychlops.Internal.Main.canvas_flag.Set();\r
}\r
- stock.Clear();\r
+ System.Threading.Thread.Sleep(0);\r
}\r
\r
#region Properties\r
public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }\r
public double getWidth() { return width; }\r
public double getHeight() { return height; }\r
- public Point getCenter() { return center; }\r
+ public override Point getCenter() { return center; }\r
public double getHCenter() { return width / 2; }\r
public double getVCenter() { return height / 2; }\r
public double getRefreshRate() { return 60; }\r
\r
\r
\r
+ #region primitive tokenizer\r
\r
partial struct Point\r
{\r
public UIElement toNative() { return this; }\r
}\r
\r
- internal class CanvasTokenizer\r
- {\r
+ #endregion\r
\r
- }\r
\r
}
\ No newline at end of file