X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=dev4%2Fpsychlops%2Fcore%2Fgraphic%2Fcanvas.cs;h=4d65ec4c6725bcba89a6bec154fbe86f46a278f2;hb=7bd951bfbca3432f306f4f114cc0b06f47e13ed9;hp=c64f7f5c17f83c06209f611cacbd0376d938f29e;hpb=14b5f406aebde0b4bdc36a94f0c315a2864a1fee;p=psychlops%2Fsilverlight.git diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs index c64f7f5..4d65ec4 100644 --- a/dev4/psychlops/core/graphic/canvas.cs +++ b/dev4/psychlops/core/graphic/canvas.cs @@ -9,6 +9,8 @@ using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Browser; +using System.Collections.Generic; + namespace Psychlops @@ -16,10 +18,10 @@ namespace Psychlops internal static partial class CONST { - internal static readonly uint MAX_OBJ_N = 1500; - internal static readonly uint MOBJ_N = 1000; - internal static readonly uint COBJ_N = 300; - internal static readonly uint HOBJ_N = 100; + 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 @@ -29,22 +31,21 @@ 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() { @@ -69,8 +70,8 @@ namespace Psychlops } for (int i = 0; i < CONST.HOBJ_N; i++) { - imageStack[i] = new Image(1, 1); - groupStack[i] = new Group(); + imageStack[i] = new Image(); +// groupStack[i] = new Group(); } } @@ -80,6 +81,7 @@ namespace Psychlops 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); } @@ -126,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; @@ -138,8 +141,8 @@ namespace Psychlops public static System.Windows.Controls.UserControl default_panel; public static System.Windows.Controls.Canvas default_api_canvas; public static WriteableBitmap default_buffer; - 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; @@ -162,12 +165,15 @@ namespace Psychlops { 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; @@ -176,7 +182,6 @@ namespace Psychlops back_panel = new Rectangle(wid, hei); flipexec = new SimpleProcedure(executeFlip); - AppState.statusBar = ""; } protected void initialize__(int wid, int hei) { @@ -192,7 +197,7 @@ 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"); pointPool = new System.Windows.Point[CONST.MOBJ_N]; @@ -216,21 +221,26 @@ namespace Psychlops lettersPool[i] = new System.Windows.Controls.TextBlock(); } 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; + UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N]; dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N]; @@ -243,10 +253,19 @@ namespace Psychlops 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 @@ -308,9 +327,9 @@ namespace Psychlops #region version modifyNative2 public void executeFlip() { - Clock after = new Clock(); - after.update(); - AppState.statusBar = ((after - before).at_msec().ToString()) + " msec"; +// Clock after = new Clock(); +// after.update(); +// AppState.statusBar = ((after - before).at_msec().ToString()) + " msec"; Line lineS; Rectangle rectS; @@ -448,6 +467,8 @@ namespace Psychlops } #endregion + + #region version modifyNative /* public void executeFlip() @@ -619,12 +640,61 @@ 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 Canvas(int wid, int hei, Mode mod, Display.DisplayName name) + { + panel = default_panel; + api_canvas = default_api_canvas; + initialize(500, 500); + } + public Canvas(Mode mod, Display.DisplayName name) + : 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) @@ -673,6 +743,10 @@ namespace Psychlops return tmp; } } + + #endregion + + #region Line partial class Line { @@ -734,6 +808,10 @@ namespace Psychlops tmp.Visibility = Visibility.Visible; } } + + #endregion + + #region Rectangle partial class Rectangle { @@ -791,6 +869,10 @@ namespace Psychlops tmp.Visibility = Visibility.Visible; } } + + #endregion + + #region Ellipse partial class Ellipse { @@ -847,6 +929,10 @@ namespace Psychlops } } + #endregion + + #region Polygon + partial class Polygon { public Polygon dup() @@ -914,7 +1000,11 @@ namespace Psychlops } } - + + #endregion + + #region Letters + partial class Letters { #region static initializer @@ -1014,19 +1104,60 @@ namespace Psychlops 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) @@ -1092,6 +1223,9 @@ namespace Psychlops } + #endregion + + #region Group partial class Group { @@ -1173,6 +1307,7 @@ namespace Psychlops } } + #endregion #endregion