X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=dev4%2Fpsychlops%2Fcore%2Fgraphic%2Fcanvas.cs;h=5a1a7c97337b01971abdc8dd34e5a37dad424e95;hb=e1bcd188a9eeb10582140f13e77b5857f9244816;hp=7f6360c3306be02775792d3696a22619f5720efe;hpb=feba6ebcec2fd2c6381c0ee16a784ca9c38a33af;p=psychlops%2Fsilverlight.git diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index 7f6360c..5a1a7c9 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -56,7 +56,7 @@ namespace Psychlops { polygonStack[i] = new Polygon(); lettersStack[i] = new Letters(); - //imageStack[i] = new Image(); + imageStack[i] = new Image(1,1); } } @@ -75,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) @@ -108,6 +109,10 @@ namespace Psychlops // 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); } public virtual void msg(string dstr, double x, double y, Color col) @@ -133,6 +138,10 @@ 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; @@ -141,6 +150,10 @@ namespace Psychlops 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 @@ -171,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; @@ -183,6 +202,7 @@ namespace Psychlops back_panel = new Rectangle(wid, hei); flipexec = new SimpleProcedure(executeFlip); + AppState.statusBar = ""; } protected void initialize__(int wid, int hei) { @@ -201,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(); + } + polygonPool = new System.Windows.Shapes.Polygon[1000]; + lettersPool = new System.Windows.Controls.TextBlock[1000]; + for (int i = 0; i < 1000; i++) + { + polygonPool[i] = new System.Windows.Shapes.Polygon(); + lettersPool[i] = new System.Windows.Controls.TextBlock(); } - for (int i = 0; i < 300; i++) + imagePool = new System.Windows.Controls.Image[100]; + for (int i = 0; i < 100; i++) { - api_canvas.Children.Add(rectStack[i].poolNative(this)); - api_canvas.Children.Add(rectStack[i].poolNative(this)); + 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 @@ -258,116 +298,170 @@ 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) - // if (stackN > 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; - } - 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 - public void flip() - { - lock (this) - { - nextIntervalFrame = 1; - chacked = 1; - } - // pointPoolN = 0; - // brushPoolN = 0; - // linePoolN = 0; - rectPoolN = 0; - lineStackN = 0; - rectStackN = 0; - Internal.Main.canvas_flag.WaitOne(); - } + /* + #region version poolNative 2 public void executeFlip() { + lock (this) { nextIntervalFrame--; } + UIElementPoolN = 0; if (nextIntervalFrame <= 0) { if (chacked > 0) { - //api_canvas.Children.Clear(); - //var tmp = new System.Windows.Controls.Canvas(); + //masterPool.Children.Clear(); if (stackN > 0) { for (int i = 0; i < stackN - 2; i++) { - //api_canvas.Children.Add(stack[i].poolNative(this)); - api_canvas.Children.Add(stack[i].poolNative(this)); + 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); lock (this) { chacked = 0; @@ -377,7 +471,8 @@ namespace Psychlops } System.Threading.Thread.Sleep(0); } - + #endregion + */ #region Properties @@ -454,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]; @@ -469,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 @@ -517,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 @@ -548,7 +677,7 @@ namespace Psychlops tmp.ydiameter = ydiameter; tmp.fill = fill; d.stack[d.stackN] = tmp; - d.rectStackN++; + d.ellipseStackN++; d.stackN++; } public UIElement poolNative(Canvas d) @@ -558,10 +687,19 @@ namespace Psychlops 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 this; + 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; } } @@ -600,20 +738,35 @@ namespace Psychlops } tmp.fill = fill; d.stack[d.stackN] = tmp; - d.rectStackN++; + d.polygonStackN++; d.stackN++; } public UIElement poolNative(Canvas d) { var tmp = d.polygonPool[d.polygonPoolN]; tmp.Fill = fill; - /* - System.Windows.Controls.Canvas.SetLeft(tmp, left); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], top); - */ + 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 this; + 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; } } @@ -675,25 +828,46 @@ namespace Psychlops public void copyToStack(Templates.StackableDrawable d) { - var tmp = d.polygonStack[d.polygonStackN]; + var tmp = d.lettersStack[d.lettersStackN]; + tmp.str = str; tmp.datum = datum; tmp.fill = fill; d.stack[d.stackN] = tmp; - d.rectStackN++; + 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; } } @@ -707,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); @@ -743,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