X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=dev4%2Fpsychlops%2Fcore%2Fgraphic%2Fcanvas.cs;h=5a1a7c97337b01971abdc8dd34e5a37dad424e95;hb=e1bcd188a9eeb10582140f13e77b5857f9244816;hp=ccdf1a240e610be00c3f30389013b1046339c0cf;hpb=99c03ee4e4cbc54d1123910016705c7657c4a9cc;p=psychlops%2Fsilverlight.git diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index ccdf1a2..5a1a7c9 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -26,6 +26,14 @@ namespace Psychlops internal int lineStackN; internal Rectangle[] rectStack; internal int rectStackN; + internal Ellipse[] ellipseStack; + internal int ellipseStackN; + internal Polygon[] polygonStack; + internal int polygonStackN; + internal Letters[] lettersStack; + internal int lettersStackN; + internal Image[] imageStack; + internal int imageStackN; public StackableDrawable() @@ -34,10 +42,21 @@ namespace Psychlops stack = new Internal.PrimitiveFigure[40000]; lineStack = new Line[10000]; rectStack = new Rectangle[10000]; + ellipseStack = new Ellipse[10000]; + polygonStack = new Polygon[1000]; + lettersStack = new Letters[1000]; + imageStack = new Image[1000]; for (int i = 0; i < 10000; i++) { lineStack[i] = new Line(0,0,0,0); rectStack[i] = new Rectangle(); + ellipseStack[i] = new Ellipse(); + } + for (int i = 0; i < 1000; i++) + { + polygonStack[i] = new Polygon(); + lettersStack[i] = new Letters(); + imageStack[i] = new Image(1,1); } } @@ -56,7 +75,8 @@ namespace Psychlops public virtual void line(Line drawee) { -// stack.Enqueue(drawee.clone()); + // stack.Enqueue(drawee.clone()); + drawee.copyToStack(this); } public virtual void rect(Rectangle drawee) @@ -68,22 +88,30 @@ namespace Psychlops public virtual void ellipse(Ellipse drawee) { -// stack.Enqueue(drawee.clone()); + // stack.Enqueue(drawee.clone()); + drawee.copyToStack(this); } public virtual void polygon(Polygon drawee) { -// stack.Enqueue(drawee.clone()); + // stack.Enqueue(drawee.clone()); + drawee.copyToStack(this); } public virtual void letters(Letters drawee) { -// stack.Enqueue(drawee.clone()); + // stack.Enqueue(drawee.clone()); + drawee.copyToStack(this); } public virtual void image(Image drawee) { -// stack.Enqueue(drawee.clone()); + // stack.Enqueue(drawee.clone()); + drawee.copyToStack(this); + } + public virtual void group(Group drawee) + { + drawee.copyToStack(this); } public void msg(string str, double x, double y) { msg(str, x, y, Color.white); } @@ -110,10 +138,22 @@ namespace Psychlops internal int pointPoolN; internal SolidColorBrush[] brushPool; internal int brushPoolN; + + internal System.Windows.UIElement[] UIElementPool; + internal int UIElementPoolN; + internal System.Windows.Shapes.Line[] linePool; internal int linePoolN; internal System.Windows.Shapes.Rectangle[] rectPool; internal int rectPoolN; + internal System.Windows.Shapes.Ellipse[] ellipsePool; + internal int ellipsePoolN; + internal System.Windows.Shapes.Polygon[] polygonPool; + internal int polygonPoolN; + internal System.Windows.Controls.TextBlock[] lettersPool; + internal int lettersPoolN; + internal System.Windows.Controls.Image[] imagePool; + internal int imagePoolN; #region initializer @@ -144,11 +184,17 @@ namespace Psychlops api_canvas = apicnvs; initialize(wid, hei); } + + protected bool AsyncInitBool; protected void initialize(int wid, int hei) { + AsyncInitBool = false; width_ = wid; height_ = hei; api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei); + while(!AsyncInitBool) + { + } Mouse._prime = api_canvas; Main.drawable = this; Main.canvas = this; @@ -156,6 +202,7 @@ namespace Psychlops back_panel = new Rectangle(wid, hei); flipexec = new SimpleProcedure(executeFlip); + AppState.statusBar = ""; } protected void initialize__(int wid, int hei) { @@ -174,27 +221,47 @@ namespace Psychlops htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px"); htmlHost.SetStyleAttribute("margin", "2em auto auto auto"); - + UIElementPool = new System.Windows.UIElement[10000]; pointPool = new System.Windows.Point[10000]; brushPool = new SolidColorBrush[10000]; linePool = new System.Windows.Shapes.Line[10000]; rectPool = new System.Windows.Shapes.Rectangle[10000]; + ellipsePool = new System.Windows.Shapes.Ellipse[10000]; for (int i = 0; i < 10000; i++) { pointPool[i] = new System.Windows.Point(); brushPool[i] = new SolidColorBrush(); linePool[i] = new System.Windows.Shapes.Line(); rectPool[i] = new System.Windows.Shapes.Rectangle(); + ellipsePool[i] = new System.Windows.Shapes.Ellipse(); } - for (int i = 0; i < 300; i++) + polygonPool = new System.Windows.Shapes.Polygon[1000]; + lettersPool = new System.Windows.Controls.TextBlock[1000]; + for (int i = 0; i < 1000; i++) { - api_canvas.Children.Add(rectStack[i].poolNative(this)); - api_canvas.Children.Add(rectStack[i].poolNative(this)); + polygonPool[i] = new System.Windows.Shapes.Polygon(); + lettersPool[i] = new System.Windows.Controls.TextBlock(); + } + imagePool = new System.Windows.Controls.Image[100]; + for (int i = 0; i < 100; i++) + { + imagePool[i] = new System.Windows.Controls.Image(); } masterPool = new System.Windows.Controls.Canvas(); prevPool = new System.Windows.Controls.Canvas(); -// masterPool.Children.Add() + api_canvas.Children.Add(masterPool); + //api_canvas.Children.Remove(Internal.Main.widgetStack); + + /* + for (int i = 0; i < 10000; i++) + { + masterPool.Children.Add(UIElementPool[i]); + } + * */ + + + AsyncInitBool = true; } #endregion @@ -231,75 +298,182 @@ namespace Psychlops public override void clear(Color col) { back_panel.fill = col; -// stack.Clear(); stackN = 0; rect(back_panel); } int nextIntervalFrame = 1, chacked = 0; + public void flip(int n) + { + flip(); + } public void flip() { - //api_canvas.Dispatcher.BeginInvoke(flipexec); - //flipexec(); - //System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); lock (this) { nextIntervalFrame = 1; chacked = 1; } -// pointPoolN = 0; -// brushPoolN = 0; -// linePoolN = 0; - rectPoolN = 0; + //pointStackN = 0; + //brushStackN = 0; lineStackN = 0; rectStackN = 0; + polygonStackN = 0; + ellipseStackN = 0; + lettersStackN = 0; + imageStackN = 0; + + pointPoolN = 0; + brushPoolN = 0; + linePoolN = 0; + rectPoolN = 0; + ellipsePoolN = 0; + polygonPoolN = 0; + lettersPoolN = 0; + imagePoolN = 0; + Internal.Main.canvas_flag.WaitOne(); } + #region version modifyNative public void executeFlip() { + Line lineS; + Rectangle rectS; + Ellipse ellipseS; + Polygon polygonS; + Letters lettersS; + Image imageS; + System.Windows.Shapes.Line lineP; + System.Windows.Shapes.Rectangle rectP; + System.Windows.Shapes.Ellipse ellipseP; + System.Windows.Shapes.Polygon polygonP; + System.Windows.Controls.TextBlock lettersP; + System.Windows.Controls.Image imageP; + lock (this) { nextIntervalFrame--; } + + var en = masterPool.Children.GetEnumerator(); + bool full = en.MoveNext(); if (nextIntervalFrame <= 0) { - var rr = new Random(); - //Psychlops.AppState.statusBar = chacked.ToString(); if (chacked > 0) { - // prevPool.Children.Clear(); - // var tmp = new System.Windows.Controls.Canvas(); -// if (stack.Count > 0) + //masterPool.Children.Clear(); if (stackN > 0) { - //foreach (UIElement e in api_canvas.Children) - //{ - //} -// foreach (Internal.PrimitiveFigure f in stack) for (int i = 0; i < stackN - 2; i++) { - // tmp.Children.Add(f.toNative()); -// tmp.Children.Add(f.poolNative(this)); - // tmp.Children.Add(stack[i].poolNative(this)); - System.Windows.Controls.Canvas.SetLeft(api_canvas.Children[i + 1], rectStack[i].left); - api_canvas.Children[0] = api_canvas.Children[0]; + if (full == false) + { + masterPool.Children.Add(stack[i].poolNative(this)); + } + else + { + if( null != (rectS = stack[i] as Rectangle) ) + { + if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle)) + { + rectS.modifyNative(rectP, this); + } + } + else if (null != (lineS = stack[i] as Line)) + { + if (null != (lineP = en.Current as System.Windows.Shapes.Line)) + { + lineS.modifyNative(lineP, this); + } + } + else if (null != (ellipseS = stack[i] as Ellipse)) + { + if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse)) + { + ellipseS.modifyNative(ellipseP, this); + } + } + else if (null != (polygonS = stack[i] as Polygon)) + { + if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon)) + { + polygonS.modifyNative(polygonP, this); + } + } + else if (null != (lettersS = stack[i] as Letters)) + { + if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock)) + { + lettersS.modifyNative(lettersP, this); + } + } + else if (null != (imageS = stack[i] as Image)) + { + if (null != (imageP = en.Current as System.Windows.Controls.Image)) + { + imageS.modifyNative(imageP, this); + } + } + full = en.MoveNext(); + } } stackN = 0; + } + lock (this) + { + chacked = 0; + } + Psychlops.Internal.Main.canvas_flag.Set(); + } + } + System.Threading.Thread.Sleep(0); + } + #endregion + + /* + #region version poolNative 2 + public void executeFlip() + { + lock (this) + { + nextIntervalFrame--; + } + UIElementPoolN = 0; + if (nextIntervalFrame <= 0) + { + if (chacked > 0) + { + //masterPool.Children.Clear(); + if (stackN > 0) + { + for (int i = 0; i < stackN - 2; i++) + { + UIElementPool[UIElementPoolN] = stack[i].poolNative(this); + UIElementPool[UIElementPoolN].Visibility = Visibility.Visible; + UIElementPoolN++; + + } + for (int i = stackN - 2; i < 10000; i++) + { + UIElementPool[UIElementPoolN] = rectPool[i]; + UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed; + UIElementPoolN++; + } + stackN = 0; } - // api_canvas.Children.Clear(); - // api_canvas.Children.Add(tmp); -// stack.Clear(); lock (this) { chacked = 0; } Psychlops.Internal.Main.canvas_flag.Set(); - // prevPool = tmp; } } System.Threading.Thread.Sleep(0); } + #endregion + */ + #region Properties @@ -375,6 +549,19 @@ namespace Psychlops } public UIElement toNative() { return this; } + public void copyToStack(Templates.StackableDrawable d) + { + var tmp = d.lineStack[d.lineStackN]; + tmp.begin.x = begin.x; + tmp.begin.y = begin.y; + tmp.end.x = end.x; + tmp.end.y = end.y; + tmp.fill = fill; + tmp.stroke = stroke; + d.stack[d.stackN] = tmp; + d.lineStackN++; + d.stackN++; + } public UIElement poolNative(Canvas d) { var tmp = d.linePool[d.linePoolN]; @@ -390,6 +577,18 @@ namespace Psychlops d.linePoolN++; return tmp; } + public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d) + { + tmp.X1 = begin.x; + tmp.Y1 = begin.y; + tmp.X2 = end.x; + tmp.Y2 = end.y; + if (stroke.thick == 0.0) tmp.Stroke = fill; + else stroke.apply(tmp); + System.Windows.Controls.Canvas.SetLeft(tmp, left); + System.Windows.Controls.Canvas.SetTop(tmp, top); + tmp.Visibility = Visibility.Visible; + } } partial class Rectangle @@ -402,16 +601,6 @@ namespace Psychlops { return (Rectangle)MemberwiseClone(); } - public void copyToStack(Templates.StackableDrawable d) - { - var tmp = d.rectStack[d.rectStackN]; - tmp.v1 = v1; - tmp.v2 = v2; - tmp.fill = fill; - d.stack[d.stackN] = tmp; - d.rectStackN++; - d.stackN++; - } public static implicit operator System.Windows.Rect(Rectangle d) { return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y); @@ -424,8 +613,18 @@ namespace Psychlops System.Windows.Controls.Canvas.SetTop(tmp, d.top); return tmp; } - public UIElement toNative() { return this; } + public UIElement toNative() { return this; } + public void copyToStack(Templates.StackableDrawable d) + { + var tmp = d.rectStack[d.rectStackN]; + tmp.v1 = v1; + tmp.v2 = v2; + tmp.fill = fill; + d.stack[d.stackN] = tmp; + d.rectStackN++; + d.stackN++; + } public UIElement poolNative(Canvas d) { var tmp = d.rectPool[d.rectPoolN]; @@ -438,6 +637,15 @@ namespace Psychlops d.rectPoolN++; return tmp; } + public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d) + { + tmp.Width = width; + tmp.Height = height; + tmp.Fill = fill; + System.Windows.Controls.Canvas.SetLeft(tmp, left); + System.Windows.Controls.Canvas.SetTop(tmp, top); + tmp.Visibility = Visibility.Visible; + } } partial class Ellipse @@ -458,20 +666,40 @@ namespace Psychlops System.Windows.Controls.Canvas.SetTop(tmp, d.top); return tmp; } + public UIElement toNative() { return this; } + public void copyToStack(Templates.StackableDrawable d) + { + var tmp = d.ellipseStack[d.ellipseStackN]; + tmp.datum = datum; + tmp.xdiameter = xdiameter; + tmp.ydiameter = ydiameter; + tmp.fill = fill; + d.stack[d.stackN] = tmp; + d.ellipseStackN++; + d.stackN++; + } public UIElement poolNative(Canvas d) { -/* var tmp = d.rectPool[d.rectPoolN]; + var tmp = d.ellipsePool[d.ellipsePoolN]; tmp.Width = width; tmp.Height = height; tmp.Fill = fill; System.Windows.Controls.Canvas.SetLeft(tmp, left); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); + System.Windows.Controls.Canvas.SetTop(tmp, top); + tmp.Visibility = Visibility.Visible; + d.ellipsePoolN++; + return tmp; + } + public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d) + { + tmp.Width = width; + tmp.Height = height; + tmp.Fill = fill; + System.Windows.Controls.Canvas.SetLeft(tmp, left); + System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; - d.rectPoolN++; -*/ - return this; } } @@ -499,18 +727,46 @@ namespace Psychlops } public UIElement toNative() { return this; } + public void copyToStack(Templates.StackableDrawable d) + { + var tmp = d.polygonStack[d.polygonStackN]; + tmp.datum = datum; + tmp.vertices.Clear(); + foreach (var v in vertices) + { + tmp.vertices.Add(v); + } + tmp.fill = fill; + d.stack[d.stackN] = tmp; + d.polygonStackN++; + d.stackN++; + } public UIElement poolNative(Canvas d) { - /* var tmp = d.rectPool[d.rectPoolN]; - tmp.Width = width; - tmp.Height = height; - tmp.Fill = fill; - System.Windows.Controls.Canvas.SetLeft(tmp, left); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); - tmp.Visibility = Visibility.Visible; - d.rectPoolN++; -*/ - return this; + var tmp = d.polygonPool[d.polygonPoolN]; + tmp.Fill = fill; + tmp.Points.Clear(); + foreach (var v in vertices) + { + tmp.Points.Add(v); + } + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); + tmp.Visibility = Visibility.Visible; + d.polygonPoolN++; + return tmp; + } + public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d) + { + tmp.Fill = fill; + tmp.Points.Clear(); + foreach (var v in vertices) + { + tmp.Points.Add(v); + } + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); + tmp.Visibility = Visibility.Visible; } } @@ -570,18 +826,48 @@ namespace Psychlops } public UIElement toNative() { return this; } + public void copyToStack(Templates.StackableDrawable d) + { + var tmp = d.lettersStack[d.lettersStackN]; + tmp.str = str; + tmp.datum = datum; + tmp.fill = fill; + d.stack[d.stackN] = tmp; + d.lettersStackN++; + d.stackN++; + } public UIElement poolNative(Canvas d) { - /* var tmp = d.rectPool[d.rectPoolN]; - tmp.Width = width; - tmp.Height = height; - tmp.Fill = fill; - System.Windows.Controls.Canvas.SetLeft(tmp, left); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); - tmp.Visibility = Visibility.Visible; - d.rectPoolN++; -*/ - return this; + var tmp = d.lettersPool[d.lettersPoolN]; + tmp.Text = str; + tmp.Width = 500; + tmp.Height = 500; + tmp.FontSize = font.size; + //tmp.FontFamily = , + tmp.FontStyle = FONT_STYLE_BRIDGE[font.style]; + tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight]; + tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align]; + tmp.Foreground = fill; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); + tmp.Visibility = Visibility.Visible; + d.lettersPoolN++; + return tmp; + } + public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d) + { + tmp.Text = str; + tmp.Width = 500; + tmp.Height = 500; + tmp.FontSize = font.size; + //tmp.FontFamily = , + tmp.FontStyle = FONT_STYLE_BRIDGE[font.style]; + tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight]; + tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align]; + tmp.Foreground = fill; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); + tmp.Visibility = Visibility.Visible; } } @@ -595,6 +881,7 @@ namespace Psychlops internal void create__(int wid, int hei) { buffer = new WriteableBitmap(wid, hei); + AsyncBool = true; } delegate void FieldFunc1(System.Func func); delegate void FieldFunc2(System.Func func); @@ -631,22 +918,102 @@ namespace Psychlops } public UIElement toNative() { return this; } + public void copyToStack(Templates.StackableDrawable d) + { + var tmp = d.imageStack[d.imageStackN]; + tmp.datum = datum; + tmp.buffer = buffer; + tmp.self_rect = self_rect; + d.stack[d.stackN] = tmp; + d.imageStackN++; + d.stackN++; + } public UIElement poolNative(Canvas d) { - /* var tmp = d.rectPool[d.rectPoolN]; - tmp.Width = width; - tmp.Height = height; - tmp.Fill = fill; - System.Windows.Controls.Canvas.SetLeft(tmp, left); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); - tmp.Visibility = Visibility.Visible; - d.rectPoolN++; -*/ + var tmp = d.imagePool[d.imagePoolN]; + tmp.Source = buffer; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); + tmp.Visibility = Visibility.Visible; + d.imagePoolN++; return this; } + public void modifyNative(System.Windows.Controls.Image tmp, Canvas d) + { + tmp.Source = buffer; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); + tmp.Visibility = Visibility.Visible; + } } + + partial class Group + { + internal void initialize__() + { + Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.SimpleProcedure(create__)); + } + internal void create__() + { + cnvs = new System.Windows.Controls.Canvas(); + AsyncBool = true; + } + delegate void AppendFunc1(System.Func func); + public void append__(Internal.PrimitiveFigure fig) + { + cnvs.Children.Add(fig.toNative()); + } + + public Group clone() + { + return (Group)MemberwiseClone(); + } + + public static implicit operator System.Windows.Controls.Canvas(Group d) + { + var tmp = new System.Windows.Controls.Canvas(); +/* foreach (var item in list) + { + tmp.Children.Add(d.); + } + System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y); +*/ return tmp; + } + public UIElement toNative() { return this; } + + public void copyToStack(Templates.StackableDrawable d) + { +/* var tmp = d.imageStack[d.imageStackN]; + tmp.datum = datum; + tmp.buffer = buffer; + tmp.self_rect = self_rect; + d.stack[d.stackN] = tmp; + d.imageStackN++; + d.stackN++; +*/ } + public UIElement poolNative(Canvas d) + { +/* var tmp = d.imagePool[d.imagePoolN]; + tmp.Source = buffer; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); + tmp.Visibility = Visibility.Visible; + d.imagePoolN++; +*/ return this; + } + public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d) + { +/* tmp.Source = buffer; + System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); + tmp.Visibility = Visibility.Visible; +*/ } + + } + #endregion