X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=dev4%2Fpsychlops%2Fcore%2Fgraphic%2Fcanvas.cs;h=c46f9fbc18e078514aa01f33cee41d504bfff6bf;hb=97a97a46267462940a24f18ad5bbd0f77006dfd9;hp=fdc39871272f78c3ea871f94d404ead221fa9274;hpb=a18f323a3bf447b6f2ce12d0d1a4f39a07814e93;p=psychlops%2Fsilverlight.git diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index fdc3987..c46f9fb 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,105 +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; + internal int groupStackN = 0; public StackableDrawable() { -// stack = new System.Collections.Generic.Queue(); - stack = new Internal.PrimitiveFigure[10000]; - lineStack = new Line[2000]; - rectStack = new Rectangle[2000]; - ellipseStack = new Ellipse[2000]; - polygonStack = new Polygon[1000]; - lettersStack = new Letters[1000]; - imageStack = new Image[100]; - groupStack = new Group[100]; - for (int i = 0; i < 2000; 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(); } - for (int i = 0; i < 100; i++) + for (int i = 0; i < CONST.HOBJ_N; i++) { imageStack[i] = new Image(1, 1); 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 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) @@ -139,7 +105,6 @@ namespace Psychlops public class Canvas : Templates.StackableDrawable { - internal System.Windows.Controls.Canvas masterPool, prevPool; internal System.Windows.Point[] pointPool; internal int pointPoolN; @@ -148,6 +113,7 @@ namespace Psychlops internal System.Windows.Controls.Canvas[] UIElementPool; internal int UIElementPoolN; + internal int lastVisibleN; internal System.Windows.Shapes.Line[] linePool; internal int linePoolN; @@ -162,6 +128,7 @@ 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; @@ -171,14 +138,11 @@ 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; @@ -234,79 +198,79 @@ namespace Psychlops htmlHost.SetStyleAttribute("height", (20+hei).ToString() + "px"); htmlHost.SetStyleAttribute("margin", "2em auto auto auto"); - UIElementPool = new System.Windows.Controls.Canvas[2000]; - pointPool = new System.Windows.Point[2000]; - brushPool = new SolidColorBrush[2000]; - linePool = new System.Windows.Shapes.Line[2000]; - rectPool = new System.Windows.Shapes.Rectangle[2000]; - dummyRectPool = new System.Windows.Shapes.Rectangle[2000]; - ellipsePool = new System.Windows.Shapes.Ellipse[2000]; - for (int i = 0; i < 2000; 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++) { - UIElementPool[i] = new System.Windows.Controls.Canvas(); pointPool[i] = new System.Windows.Point(); brushPool[i] = new SolidColorBrush(); linePool[i] = new System.Windows.Shapes.Line(); rectPool[i] = new System.Windows.Shapes.Rectangle(); - dummyRectPool[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]; - groupPool = new System.Windows.Controls.Canvas[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 < 2000; 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 @@ -328,7 +292,6 @@ namespace Psychlops chacked = 1; } //pointStackN = 0; - //brushStackN = 0; lineStackN = 0; rectStackN = 0; polygonStackN = 0; @@ -337,6 +300,8 @@ namespace Psychlops imageStackN = 0; groupStackN = 0; + UIElementPoolN = 0; + brushPoolN = 0; /* pointPoolN = 0; brushPoolN = 0; @@ -385,113 +350,109 @@ namespace Psychlops nextIntervalFrame--; } - - - var en = masterPool.Children.GetEnumerator(); - bool full = en.MoveNext(); - var cnv = en.Current as System.Windows.Controls.Canvas; + var cnv = UIElementPool[0]; if (nextIntervalFrame <= 0) { if (chacked > 0) { if (stackN > 0) { - for (int i = 0; i < stackN - 2; i++) + for (int i = 0; i < stackN; i++) { - if (full == false) + if( null != (rectS = stack[i] as Rectangle) ) { - break; + 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 + else if (null != (lineS = stack[i] as Line)) { - if( null != (rectS = stack[i] as Rectangle) ) + if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line)) { - 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)); - } + lineS.modifyNative(lineP, this); } - else if (null != (lineS = stack[i] as Line)) + else { - 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)); - } + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); } - else if (null != (ellipseS = stack[i] as Ellipse)) + } + else if (null != (ellipseS = stack[i] as Ellipse)) + { + if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.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)); - } + ellipseS.modifyNative(ellipseP, this); } - else if (null != (polygonS = stack[i] as Polygon)) + else { - 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)); - } + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); } - else if (null != (lettersS = stack[i] as Letters)) + } + else if (null != (polygonS = stack[i] as Polygon)) + { + if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon)) { - 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)); - } + polygonS.modifyNative(polygonP, this); } - else if (null != (imageS = stack[i] as Image)) + else { - 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)); - } + cnv.Children.Clear(); + cnv.Children.Add(stack[i].poolNative(this)); } - else if (null != (groupS = stack[i] as Group)) + } + else if (null != (lettersS = stack[i] as Letters)) + { + if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock)) { - 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)); - } + 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)); } - full = en.MoveNext(); - cnv = en.Current as System.Windows.Controls.Canvas; } + 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) @@ -676,12 +637,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) @@ -700,6 +695,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 @@ -714,7 +717,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 { @@ -755,7 +769,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); @@ -769,13 +783,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 { @@ -816,7 +834,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; @@ -827,12 +845,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 { @@ -871,7 +893,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; @@ -882,13 +904,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() @@ -930,7 +956,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) { @@ -944,7 +970,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) { @@ -956,7 +982,11 @@ namespace Psychlops } } - + + #endregion + + #region Letters + partial class Letters { #region static initializer @@ -1033,7 +1063,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; @@ -1050,25 +1080,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) @@ -1134,6 +1205,9 @@ namespace Psychlops } + #endregion + + #region Group partial class Group { @@ -1215,6 +1289,7 @@ namespace Psychlops } } + #endregion #endregion