X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=dev4%2Fpsychlops%2Fcore%2Fgraphic%2Fcanvas.cs;h=5a1a7c97337b01971abdc8dd34e5a37dad424e95;hb=e1bcd188a9eeb10582140f13e77b5857f9244816;hp=6216e532d9dce505438149b1d88a86ada7a66d10;hpb=a20f03a97a7f2375b92496bad49f6ec520e162d2;p=psychlops%2Fsilverlight.git diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index 6216e53..5a1a7c9 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -109,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) @@ -134,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; @@ -194,6 +202,7 @@ namespace Psychlops back_panel = new Rectangle(wid, hei); flipexec = new SimpleProcedure(executeFlip); + AppState.statusBar = ""; } protected void initialize__(int wid, int hei) { @@ -212,7 +221,7 @@ 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]; @@ -233,12 +242,25 @@ namespace Psychlops 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(); 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; } @@ -292,10 +314,8 @@ namespace Psychlops nextIntervalFrame = 1; chacked = 1; } - // pointPoolN = 0; - // brushPoolN = 0; - linePoolN = 0; - rectPoolN = 0; + //pointStackN = 0; + //brushStackN = 0; lineStackN = 0; rectStackN = 0; polygonStackN = 0; @@ -314,22 +334,88 @@ namespace Psychlops 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) { if (chacked > 0) { - masterPool.Children.Clear(); + //masterPool.Children.Clear(); if (stackN > 0) { for (int i = 0; i < stackN - 2; i++) { - masterPool.Children.Add(stack[i].poolNative(this)); + 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; } @@ -342,7 +428,51 @@ namespace Psychlops } 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; + } + lock (this) + { + chacked = 0; + } + Psychlops.Internal.Main.canvas_flag.Set(); + } + } + System.Threading.Thread.Sleep(0); + } + #endregion + */ #region Properties @@ -447,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 @@ -495,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 @@ -536,11 +687,20 @@ 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 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; + } } partial class Polygon @@ -591,11 +751,23 @@ namespace Psychlops tmp.Points.Add(v); } System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + 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; + } } @@ -677,11 +849,26 @@ namespace Psychlops tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align]; tmp.Foreground = fill; System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + 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; + } } partial class Image @@ -746,14 +933,87 @@ namespace Psychlops var tmp = d.imagePool[d.imagePoolN]; tmp.Source = buffer; System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); - System.Windows.Controls.Canvas.SetTop(d.rectPool[d.rectPoolN], datum.y); + System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; - d.rectPoolN++; + 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