X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=dev4%2Fpsychlops%2Fcore%2Fgraphic%2Fcanvas.cs;h=5b58b031df218d887f167a1c38330e60a548d251;hb=c778254ba66748949fba1e807aec154cdf5dadf1;hp=5a1a7c97337b01971abdc8dd34e5a37dad424e95;hpb=e1bcd188a9eeb10582140f13e77b5857f9244816;p=psychlops%2Fsilverlight.git diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index 5a1a7c9..5b58b03 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -9,11 +9,21 @@ using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Browser; +using System.Collections.Generic; + namespace Psychlops { + internal static partial class CONST + { + internal static readonly Int32 MAX_OBJ_N = 1500; + internal static readonly Int32 MOBJ_N = 1000; + internal static readonly Int32 COBJ_N = 300; + internal static readonly Int32 HOBJ_N = 100; + } + namespace Templates { @@ -21,98 +31,61 @@ namespace Psychlops { // protected System.Collections.Generic.Queue stack; internal Internal.PrimitiveFigure[] stack; - internal int stackN; + internal int stackN = 0; internal Line[] lineStack; - internal int lineStackN; + internal int lineStackN = 0; internal Rectangle[] rectStack; - internal int rectStackN; + internal int rectStackN = 0; internal Ellipse[] ellipseStack; - internal int ellipseStackN; + internal int ellipseStackN = 0; internal Polygon[] polygonStack; - internal int polygonStackN; + internal int polygonStackN = 0; internal Letters[] lettersStack; - internal int lettersStackN; + internal int lettersStackN = 0; internal Image[] imageStack; - internal int imageStackN; - + internal int imageStackN = 0; + internal Group[] groupStack; + internal int groupStackN = 0; public StackableDrawable() { -// stack = new System.Collections.Generic.Queue(); - 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++) + stack = new Internal.PrimitiveFigure[CONST.MAX_OBJ_N]; + lineStack = new Line[CONST.MOBJ_N]; + rectStack = new Rectangle[CONST.MOBJ_N]; + ellipseStack = new Ellipse[CONST.MOBJ_N]; + polygonStack = new Polygon[CONST.COBJ_N]; + lettersStack = new Letters[CONST.COBJ_N]; + imageStack = new Image[CONST.HOBJ_N]; + groupStack = new Group[CONST.HOBJ_N]; + for (int i = 0; i < CONST.MOBJ_N; i++) { lineStack[i] = new Line(0,0,0,0); rectStack[i] = new Rectangle(); ellipseStack[i] = new Ellipse(); } - for (int i = 0; i < 1000; i++) + for (int i = 0; i < CONST.COBJ_N; i++) { polygonStack[i] = new Polygon(); lettersStack[i] = new Letters(); - imageStack[i] = new Image(1,1); + } + for (int i = 0; i < CONST.HOBJ_N; i++) + { + imageStack[i] = new Image(); +// groupStack[i] = new Group(); } } - public void clear() - { - clear(Color.black); - } - public virtual void clear(Color col) - { - //rect(back_panel, col); - } - - public virtual void pix(int x, int y, Color col) - { - } - - public virtual void line(Line drawee) - { - // stack.Enqueue(drawee.clone()); - drawee.copyToStack(this); - } - - public virtual void rect(Rectangle drawee) - { - //stack.Enqueue(drawee.clone()); -// stack.Enqueue(drawee.copyToStack(this)); - drawee.copyToStack(this); - } - - public virtual void ellipse(Ellipse drawee) - { - // stack.Enqueue(drawee.clone()); - drawee.copyToStack(this); - } - - public virtual void polygon(Polygon drawee) - { - // stack.Enqueue(drawee.clone()); - drawee.copyToStack(this); - } - - public virtual void letters(Letters drawee) - { - // stack.Enqueue(drawee.clone()); - drawee.copyToStack(this); - } - - public virtual void image(Image drawee) - { - // stack.Enqueue(drawee.clone()); - drawee.copyToStack(this); - } - public virtual void group(Group drawee) - { - drawee.copyToStack(this); - } + public void clear() { clear(Color.black); } + public virtual void clear(Color col) { } //rect(back_panel, col); } + public virtual void pix(int x, int y, Color col) { } + public virtual void line(Line drawee) { drawee.copyToStack(this); } + public virtual void rect(Rectangle drawee) { drawee.copyToStack(this); } + public virtual void ellipse(Ellipse drawee) { drawee.copyToStack(this); } + public virtual void oval(Ellipse drawee) { drawee.copyToStack(this); } + public virtual void polygon(Polygon drawee) { drawee.copyToStack(this); } + public virtual void letters(Letters drawee) { drawee.copyToStack(this); } + public virtual void image(Image drawee) { 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) @@ -132,18 +105,19 @@ namespace Psychlops public class Canvas : Templates.StackableDrawable { - internal System.Windows.Controls.Canvas masterPool, prevPool; internal System.Windows.Point[] pointPool; internal int pointPoolN; internal SolidColorBrush[] brushPool; internal int brushPoolN; - internal System.Windows.UIElement[] UIElementPool; + internal System.Windows.Controls.Canvas[] UIElementPool; internal int UIElementPoolN; + internal int lastVisibleN; internal System.Windows.Shapes.Line[] linePool; internal int linePoolN; + internal System.Windows.Shapes.Rectangle[] dummyRectPool; internal System.Windows.Shapes.Rectangle[] rectPool; internal int rectPoolN; internal System.Windows.Shapes.Ellipse[] ellipsePool; @@ -154,6 +128,9 @@ namespace Psychlops internal int lettersPoolN; internal System.Windows.Controls.Image[] imagePool; internal int imagePoolN; + internal Dictionary imagePoolT; + internal System.Windows.Controls.Canvas[] groupPool; + internal int groupPoolN; #region initializer @@ -161,16 +138,14 @@ namespace Psychlops internal delegate void SimpleProcedure(); SimpleProcedure flipexec; - //public static System.Windows.Controls.Image default_buffer_frame; public static System.Windows.Controls.UserControl default_panel; public static System.Windows.Controls.Canvas default_api_canvas; public static WriteableBitmap default_buffer; - //WriteableBitmap buffer; - //System.Windows.Controls.Image instance; - System.Windows.Controls.Canvas api_canvas; - System.Windows.Controls.UserControl panel; + internal System.Windows.Controls.Canvas api_canvas; + internal System.Windows.Controls.UserControl panel; Rectangle back_panel; double width_, height_; + Clock before; public Canvas(int wid, int hei) { @@ -188,12 +163,17 @@ namespace Psychlops protected bool AsyncInitBool; protected void initialize(int wid, int hei) { + before = new Clock(); + before.update(); + var after = new Clock(); AsyncInitBool = false; width_ = wid; height_ = hei; api_canvas.Dispatcher.BeginInvoke(new TwoIntProcedure(initialize__), wid, hei); - while(!AsyncInitBool) + while (!AsyncInitBool) { + after.update(); + if ((after - before).at_msec() > 1000) break; } Mouse._prime = api_canvas; Main.drawable = this; @@ -202,12 +182,11 @@ namespace Psychlops back_panel = new Rectangle(wid, hei); flipexec = new SimpleProcedure(executeFlip); - AppState.statusBar = ""; } protected void initialize__(int wid, int hei) { api_canvas.Width = wid; - api_canvas.Height = hei; + api_canvas.Height = hei+20; api_canvas.MouseMove += Mouse.Canvas_MousePos; api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown; api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp; @@ -218,16 +197,15 @@ namespace Psychlops HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost"); //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null"); htmlHost.SetStyleAttribute("width", (wid).ToString()+"px"); - htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px"); + htmlHost.SetStyleAttribute("height", (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 = new System.Windows.Point[CONST.MOBJ_N]; + brushPool = new SolidColorBrush[CONST.MOBJ_N]; + linePool = new System.Windows.Shapes.Line[CONST.MOBJ_N]; + rectPool = new System.Windows.Shapes.Rectangle[CONST.MOBJ_N]; + ellipsePool = new System.Windows.Shapes.Ellipse[CONST.MOBJ_N]; + for (int i = 0; i < CONST.MOBJ_N; i++) { pointPool[i] = new System.Windows.Point(); brushPool[i] = new SolidColorBrush(); @@ -235,61 +213,65 @@ namespace Psychlops 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 = new System.Windows.Shapes.Polygon[CONST.COBJ_N]; + lettersPool = new System.Windows.Controls.TextBlock[CONST.COBJ_N]; + for (int i = 0; i < CONST.COBJ_N; i++) { 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 = new System.Windows.Controls.Image[CONST.HOBJ_N]; + imagePoolT = new Dictionary(CONST.HOBJ_N); + groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N]; + for (int i = 0; i < CONST.HOBJ_N; i++) { imagePool[i] = new System.Windows.Controls.Image(); + imagePoolT.Add(imagePool[i].GetHashCode(), false); + groupPool[i] = new System.Windows.Controls.Canvas(); } masterPool = new System.Windows.Controls.Canvas(); prevPool = new System.Windows.Controls.Canvas(); api_canvas.Children.Add(masterPool); + //api_canvas.Children.Remove(Internal.Main.widgetStack); + Psychlops.Internal.Main.widgetStack = new StackPanel(); + Psychlops.Internal.Main.widgetStack.Orientation = Orientation.Vertical; + Psychlops.Internal.Main.widgetStack.Height = hei; + api_canvas.Children.Add(Psychlops.Internal.Main.widgetStack); + Internal.Main.statusBar.Visibility = Visibility.Collapsed; - /* - for (int i = 0; i < 10000; i++) + + UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N]; + dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N]; + for (int i = 0; i < CONST.MAX_OBJ_N; i++) { + UIElementPool[i] = new System.Windows.Controls.Canvas(); masterPool.Children.Add(UIElementPool[i]); + dummyRectPool[i] = new System.Windows.Shapes.Rectangle(); + UIElementPool[i].Children.Add(dummyRectPool[i]); + dummyRectPool[i].Visibility = Visibility.Collapsed; } - * */ - AsyncInitBool = true; } + internal int findEmptyInPool(Dictionary pool) + { + /* + foreach( KeyValuePair elem in pool) + { + if(elem) + }*/ + return 0; + } + #endregion #region static initializer /* - static System.Windows.Shapes.Line api_line; - static System.Windows.Shapes.Path api_curve; - static System.Windows.Shapes.Rectangle api_rect; - static System.Windows.Shapes.Ellipse api_ellipse; - static System.Windows.Shapes.Polygon api_polygon; - static System.Windows.Shapes.Polyline api_polyline; - static System.Windows.Media.Color api_color; - static System.Windows.Media.SolidColorBrush api_fill; - static System.Windows.Media.SolidColorBrush api_stroke; - static System.Windows.Media.TranslateTransform api_translation; static Canvas() { - api_line = new System.Windows.Shapes.Line(); - api_curve = new System.Windows.Shapes.Path(); - api_rect = new System.Windows.Shapes.Rectangle(); - api_ellipse = new System.Windows.Shapes.Ellipse(); - api_polygon = new System.Windows.Shapes.Polygon(); - api_polyline = new System.Windows.Shapes.Polyline(); - api_color = new System.Windows.Media.Color(); - api_fill = new System.Windows.Media.SolidColorBrush(); - api_stroke = new System.Windows.Media.SolidColorBrush(); - api_translation = new System.Windows.Media.TranslateTransform(); } */ #endregion @@ -305,24 +287,23 @@ namespace Psychlops int nextIntervalFrame = 1, chacked = 0; public void flip(int n) { - flip(); - } - public void flip() - { lock (this) { - nextIntervalFrame = 1; + nextIntervalFrame = n; chacked = 1; } //pointStackN = 0; - //brushStackN = 0; lineStackN = 0; rectStackN = 0; polygonStackN = 0; ellipseStackN = 0; lettersStackN = 0; imageStackN = 0; + groupStackN = 0; + UIElementPoolN = 0; + brushPoolN = 0; + /* pointPoolN = 0; brushPoolN = 0; linePoolN = 0; @@ -331,10 +312,165 @@ namespace Psychlops polygonPoolN = 0; lettersPoolN = 0; imagePoolN = 0; + groupPoolN = 0; + * */ + //executeFlip(); Internal.Main.canvas_flag.WaitOne(); } + public void flip() + { + flip(1); + } + + + #region version modifyNative2 + public void executeFlip() + { +// Clock after = new Clock(); +// after.update(); +// AppState.statusBar = ((after - before).at_msec().ToString()) + " msec"; + + Line lineS; + Rectangle rectS; + Ellipse ellipseS; + Polygon polygonS; + Letters lettersS; + Image imageS; + Group groupS; + 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; + System.Windows.Controls.Canvas groupP; + + lock (this) + { + nextIntervalFrame--; + } + + var cnv = UIElementPool[0]; + if (nextIntervalFrame <= 0) + { + if (chacked > 0) + { + if (stackN > 0) + { + for (int i = 0; i < stackN; i++) + { + if( null != (rectS = stack[i] as Rectangle) ) + { + if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle)) + { + rectS.modifyNative(rectP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); + } + } + else if (null != (lineS = stack[i] as Line)) + { + if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line)) + { + lineS.modifyNative(lineP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); + } + } + else if (null != (ellipseS = stack[i] as Ellipse)) + { + if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse)) + { + ellipseS.modifyNative(ellipseP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); + } + } + else if (null != (polygonS = stack[i] as Polygon)) + { + if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon)) + { + polygonS.modifyNative(polygonP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); + } + } + else if (null != (lettersS = stack[i] as Letters)) + { + if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock)) + { + lettersS.modifyNative(lettersP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); + } + } + else if (null != (imageS = stack[i] as Image)) + { + if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image)) + { + imageS.modifyNative(imageP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); + } + } + else if (null != (groupS = stack[i] as Group)) + { + if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas)) + { + groupS.modifyNative(groupP, this); + } + else + { + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); + } + } + cnv.Visibility = Visibility.Visible; + UIElementPoolN++; + cnv = UIElementPool[UIElementPoolN]; + } + for (int i = UIElementPoolN; i < lastVisibleN; i++) + { + cnv = UIElementPool[i]; + cnv.Visibility = Visibility.Collapsed; + } + lastVisibleN = UIElementPoolN; + stackN = 0; + } + lock (this) + { + chacked = 0; + } + Psychlops.Internal.Main.canvas_flag.Set(); + } + } + System.Threading.Thread.Sleep(0); + } + #endregion + + + #region version modifyNative + /* public void executeFlip() { Line lineS; @@ -343,12 +479,14 @@ namespace Psychlops Polygon polygonS; Letters lettersS; Image imageS; + Group groupS; 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; + System.Windows.Controls.Canvas groupP; lock (this) { @@ -392,6 +530,10 @@ namespace Psychlops { ellipseS.modifyNative(ellipseP, this); } + else + { + masterPool.Children.Add(stack[i].poolNative(this)); + } } else if (null != (polygonS = stack[i] as Polygon)) { @@ -414,6 +556,13 @@ namespace Psychlops imageS.modifyNative(imageP, this); } } + else if (null != (groupS = stack[i] as Group)) + { + if (null != (groupP = en.Current as System.Windows.Controls.Canvas)) + { + groupS.modifyNative(groupP, this); + } + } full = en.MoveNext(); } } @@ -428,10 +577,11 @@ namespace Psychlops } System.Threading.Thread.Sleep(0); } + * */ #endregion - /* #region version poolNative 2 + /* public void executeFlip() { @@ -471,8 +621,8 @@ namespace Psychlops } System.Threading.Thread.Sleep(0); } - #endregion */ + #endregion #region Properties @@ -490,12 +640,46 @@ namespace Psychlops #endregion + #region compatibitily trick + + public enum Mode { window, fullscreen } + public static readonly Mode window = Mode.window, fullscreen = Mode.fullscreen; + + public Canvas(int wid, int hei, Mode mod) + { + panel = default_panel; + api_canvas = default_api_canvas; + initialize(500, 500); + } + public Canvas(Mode mod) : base() + { + panel = default_panel; + api_canvas = default_api_canvas; + initialize(500, 500); + } + + + public void showFPS(bool sw = true) { } + public void watchFPS(bool sw = true) { } + + + public void clear(double lum) + { + clear(new Color(lum)); + } + + #endregion + + } #region primitive tokenizer + + #region primitive + partial struct Point { public static implicit operator System.Windows.Point(Point d) @@ -514,6 +698,14 @@ namespace Psychlops { return new SolidColorBrush { Color = d }; } + public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d) + { + var tmp = d.brushPool[d.brushPoolN]; + tmp.Color = this; + d.brushPoolN++; + return tmp; + } + } partial struct Stroke @@ -528,7 +720,18 @@ namespace Psychlops { return new SolidColorBrush { Color = d.color }; } + public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d) + { + var tmp = d.brushPool[d.brushPoolN]; + tmp.Color = this.color; + d.brushPoolN++; + return tmp; + } } + + #endregion + + #region Line partial class Line { @@ -569,7 +772,7 @@ namespace Psychlops tmp.Y1 = begin.y; tmp.X2 = end.x; tmp.Y2 = end.y; - if (stroke.thick == 0.0) tmp.Stroke = fill; + if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d); else stroke.apply(tmp); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); @@ -583,13 +786,17 @@ namespace Psychlops tmp.Y1 = begin.y; tmp.X2 = end.x; tmp.Y2 = end.y; - if (stroke.thick == 0.0) tmp.Stroke = fill; + if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d); else stroke.apply(tmp); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; } } + + #endregion + + #region Rectangle partial class Rectangle { @@ -630,7 +837,7 @@ namespace Psychlops var tmp = d.rectPool[d.rectPoolN]; tmp.Width = width; tmp.Height = height; - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; @@ -641,12 +848,16 @@ namespace Psychlops { tmp.Width = width; tmp.Height = height; - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; } } + + #endregion + + #region Ellipse partial class Ellipse { @@ -685,7 +896,7 @@ namespace Psychlops var tmp = d.ellipsePool[d.ellipsePoolN]; tmp.Width = width; tmp.Height = height; - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; @@ -696,13 +907,17 @@ namespace Psychlops { tmp.Width = width; tmp.Height = height; - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, left); System.Windows.Controls.Canvas.SetTop(tmp, top); tmp.Visibility = Visibility.Visible; } } + #endregion + + #region Polygon + partial class Polygon { public Polygon dup() @@ -744,7 +959,7 @@ namespace Psychlops public UIElement poolNative(Canvas d) { var tmp = d.polygonPool[d.polygonPoolN]; - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); tmp.Points.Clear(); foreach (var v in vertices) { @@ -758,7 +973,7 @@ namespace Psychlops } public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d) { - tmp.Fill = fill; + tmp.Fill = fill.getNativeFromStack(d); tmp.Points.Clear(); foreach (var v in vertices) { @@ -770,7 +985,11 @@ namespace Psychlops } } - + + #endregion + + #region Letters + partial class Letters { #region static initializer @@ -847,7 +1066,7 @@ namespace Psychlops tmp.FontStyle = FONT_STYLE_BRIDGE[font.style]; tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight]; tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align]; - tmp.Foreground = fill; + tmp.Foreground = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; @@ -864,25 +1083,66 @@ namespace Psychlops tmp.FontStyle = FONT_STYLE_BRIDGE[font.style]; tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight]; tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align]; - tmp.Foreground = fill; + tmp.Foreground = fill.getNativeFromStack(d); System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; } } + + #endregion + + #region Image partial class Image { internal void initialize__(int wid, int hei) { + AsyncBool = false; Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Canvas.TwoIntProcedure(create__), wid, hei); - //buffer = new WriteableBitmap(wid, hei); + while (!AsyncBool) { System.Threading.Thread.Sleep(10); } } internal void create__(int wid, int hei) { buffer = new WriteableBitmap(wid, hei); AsyncBool = true; } + internal void load__(string uri) + { + AsyncBool = false; + var ur = new System.Uri(uri, System.UriKind.RelativeOrAbsolute); + Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action(load_), ur); + while (!AsyncBool) { System.Threading.Thread.Sleep(10); } + } + internal void load_(Uri uri) + { + var bitmap = new BitmapImage(); + bitmap.CreateOptions = BitmapCreateOptions.None; + bitmap.UriSource = uri; + //try + //{ + var wbm = new System.Windows.Media.Imaging.WriteableBitmap(bitmap); + buffer = wbm; + //} + //catch (Exception e) + //{ + // buffer = new WriteableBitmap(64, 64); + // buffer.ForEach(bitmap_drawChecker); + //} + self_rect.set(buffer.PixelWidth, buffer.PixelHeight); + AsyncBool = true; + } + static System.Windows.Media.Color[] CHECKER_C; + static Image() + { + CHECKER_C = new System.Windows.Media.Color[2]; + CHECKER_C[0] = System.Windows.Media.Color.FromArgb(0, 0, 0, 0); + CHECKER_C[1] = System.Windows.Media.Color.FromArgb(128,128,128,128); + } + static System.Windows.Media.Color bitmap_drawChecker(int x, int y) + { + return ((x / 4) + (y / 4)) % 2 == 0 ? CHECKER_C[0] : CHECKER_C[1]; + } delegate void FieldFunc1(System.Func func); delegate void FieldFunc2(System.Func func); public void field__(System.Func func) @@ -936,7 +1196,7 @@ namespace Psychlops System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; d.imagePoolN++; - return this; + return tmp; } public void modifyNative(System.Windows.Controls.Image tmp, Canvas d) { @@ -948,6 +1208,9 @@ namespace Psychlops } + #endregion + + #region Group partial class Group { @@ -958,61 +1221,78 @@ namespace Psychlops internal void create__() { cnvs = new System.Windows.Controls.Canvas(); + trans = new System.Windows.Media.TransformGroup(); + transF = new System.Windows.Media.TransformCollection(); + rotateF = new System.Windows.Media.RotateTransform(); + scaleF = new System.Windows.Media.ScaleTransform(); + translateF = new System.Windows.Media.TranslateTransform(); + transF.Add(rotateF); + transF.Add(scaleF); + transF.Add(translateF); + trans.Children = transF; + cnvs.RenderTransform = trans; AsyncBool = true; } - delegate void AppendFunc1(System.Func func); - public void append__(Internal.PrimitiveFigure fig) + public Group clone() { - cnvs.Children.Add(fig.toNative()); + return (Group)MemberwiseClone(); } - public Group clone() + delegate void AppendFunc1(Internal.PrimitiveFigure func); + void append__(Internal.PrimitiveFigure fig) { - return (Group)MemberwiseClone(); + fig.centering(0, 0); + UIElement e = fig.toNative(); + cnvs.Children.Add(e); + System.Windows.Controls.Canvas.SetLeft(e, fig.datum.x); + System.Windows.Controls.Canvas.SetTop(e, fig.datum.y); } + delegate void SimpleProcedure(); + void getRotation__() { rotation_ = rotateF.Angle; } + void setRotation__() { rotateF.Angle = rotation_; } + //void getTranslation__() { rotation_ = rotateF.Angle; } + void setTranslation__() { translateF.X = datum.x; translateF.Y = datum.y; } + void setScaling__() { scaleF.ScaleX = scaling_.x; scaleF.ScaleY = scaling_.y; } 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; + var tmp = d.cnvs;//new System.Windows.Controls.Canvas(); + System.Windows.Controls.Canvas.SetLeft(d.cnvs, d.datum.x); + System.Windows.Controls.Canvas.SetTop(d.cnvs, d.datum.y); + return tmp; } public UIElement toNative() { return this; } public void copyToStack(Templates.StackableDrawable d) { -/* var tmp = d.imageStack[d.imageStackN]; + var tmp = d.groupStack[d.groupStackN]; tmp.datum = datum; - tmp.buffer = buffer; - tmp.self_rect = self_rect; + tmp.cnvs = cnvs; d.stack[d.stackN] = tmp; - d.imageStackN++; + d.groupStackN++; d.stackN++; -*/ } + } public UIElement poolNative(Canvas d) { -/* var tmp = d.imagePool[d.imagePoolN]; - tmp.Source = buffer; + //d.groupPool[d.groupPoolN] = cnvs; + //var tmp = d.groupPool[d.groupPoolN]; + var tmp = cnvs; System.Windows.Controls.Canvas.SetLeft(tmp, datum.x); System.Windows.Controls.Canvas.SetTop(tmp, datum.y); tmp.Visibility = Visibility.Visible; - d.imagePoolN++; -*/ return this; + //d.groupPoolN++; + return tmp; } 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); + d.groupPool[d.groupPoolN] = cnvs; + System.Windows.Controls.Canvas.SetLeft(cnvs, datum.x); + System.Windows.Controls.Canvas.SetTop(cnvs, datum.y); tmp.Visibility = Visibility.Visible; -*/ } + } } + #endregion #endregion