Ejemplo n.º 1
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            sprite.wmode();

            sprite.AttachSpriteToDocument().With(
                embed =>
            {
                embed.style.SetLocation(0, 0);
                embed.style.SetSize(Native.Window.Width, Native.Window.Height);

                Native.Window.onresize +=
                    delegate
                {
                    embed.style.SetSize(Native.Window.Width, Native.Window.Height);
                };
            }
                );


            #region con
            var con = new ConsoleForm();

            con.InitializeConsoleFormWriter();

            con.Show();

            con.Left = Native.Window.Width - con.Width;
            con.Top  = 0;

            Native.Window.onresize +=
                delegate
            {
                con.Left = Native.Window.Width - con.Width;
                con.Top  = 0;
            };


            con.Opacity = 0.6;


            sprite.InitializeConsoleFormWriter(
                Console.Write,
                Console.WriteLine
                );
            #endregion



            sprite.fps +=
                fps =>
            {
                con.Text = new { fps }.ToString();
            };


            sprite.context_new_remotegame +=
                remotegame =>
            {
                var remotegame_con = new ConsoleForm();

                remotegame_con.Show();
                remotegame_con.Left = 0;
                remotegame_con.Top  = Native.Window.Height - remotegame_con.Height;

                remotegame_con.Opacity = 0.5;

                remotegame.AtTitleChange    +=
                    e => remotegame_con.Text = e;

                remotegame.AtWriteLine +=
                    e =>
                {
                    remotegame_con.textBox1.AppendText(e + Environment.NewLine);
                    remotegame_con.textBox1.ScrollToCaret();
                };
            };

            {
                int c = 2000;

                Action <MessageEvent> window_onmessage =
                    e =>
                {
                    var xml = XElement.Parse((string)e.data);

                    c++;
                    //Console.WriteLine(c + " window -> sprite " + xml);

                    sprite.game_postMessage(xml);
                };


                Console.WriteLine("add window_onmessage");
                Native.Window.onmessage += window_onmessage;
            }

            Action <XElement> sprite_context_onmessage = delegate { };

            int ccc = 0;
            sprite.context_onmessage +=
                e =>
            {
                ccc++;
                //Console.WriteLine(ccc + " sprite ->  " + e);
                sprite_context_onmessage(e);
            };

            if (Native.Window.opener != null)
            {
                // opener closes, we close.
                Native.Window.opener.onbeforeunload +=
                    delegate
                {
                    Native.Window.close();
                };

                sprite_context_onmessage +=
                    e =>
                {
                    Native.Window.opener.postMessage(e.ToString());
                };
            }
            else
            {
                new Button {
                    Text = "Secondary View"
                }.With(
                    connect =>
                {
                    connect.AttachTo(con);

                    connect.Left = 8;
                    connect.Top  = 8;

                    connect.Click +=
                        delegate
                    {
                        var w = Native.Window.open(Native.Document.location.href, "_blank", 600, 600, false);


                        w.onload +=
                            delegate
                        {
                            Console.WriteLine("loaded: " + w.document.location.href);

                            if (w.document.location.href == "about:blank")
                            {
                                // fck you blank:P 4h of debugging for this.

                                return;
                            }

                            //Native.Window.onmessage +=
                            //     e =>
                            //     {
                            //         if (e.source == w)
                            //             return;

                            //         // relay, not echo
                            //         w.postMessage(e.data);
                            //     };

                            var w_closed = false;

                            w.onbeforeunload +=
                                delegate
                            {
                                w_closed = true;
                            };

                            var xcc = 0;
                            Action <XElement> __sprite_context_onmessage = e =>
                            {
                                if (w_closed)
                                {
                                    return;
                                }

                                xcc++;
                                //Console.WriteLine(xcc + " to child ->  " + e);
                                w.postMessage(e.ToString());
                            };


                            sprite_context_onmessage += __sprite_context_onmessage;
                        };
                    };
                }
                    );
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            sprite.AttachSpriteToDocument().With(
                embed =>
            {
                embed.style.SetLocation(0, 0);
                embed.style.SetSize(Native.window.Width, Native.window.Height);

                Native.window.onresize +=
                    delegate
                {
                    embed.style.SetSize(Native.window.Width, Native.window.Height);
                };
            }
                );



            var con = new ConsoleForm();

            con.InitializeConsoleFormWriter();

            con.Show();

            con.Left = Native.window.Width - con.Width;
            con.Top  = 0;

            Native.window.onresize +=
                delegate
            {
                con.Left = Native.window.Width - con.Width;
                con.Top  = 0;
            };


            con.Opacity = 0.6;

            sprite.fps +=
                fps =>
            {
                con.Text = new { fps }.ToString();
            };


            sprite.InitializeConsoleFormWriter(
                Console.Write,
                Console.WriteLine
                );

            Native.window.onmessage +=
                e =>
            {
                sprite.game_postMessage(XElement.Parse((string)e.data));
            };

            if (Native.window.opener != null)
            {
                sprite.context_onmessage +=
                    e =>
                {
                    Native.window.opener.postMessage(e.ToString());
                };
            }
            else
            {
                new Button {
                    Text = "Secondary View"
                }.With(
                    connect =>
                {
                    connect.AttachTo(con);

                    connect.Left = 8;
                    connect.Top  = 8;

                    connect.Click +=
                        delegate
                    {
                        var w = Native.window.open(Native.Document.location.href, "_blank", 600, 600, false);


                        w.onload +=
                            delegate
                        {
                            Console.WriteLine("loaded: " + w.document.location.href);

                            Native.window.onmessage +=
                                e =>
                            {
                                if (e.source == w)
                                {
                                    return;
                                }

                                // relay, not echo
                                w.postMessage(e.data);
                            };

                            sprite.context_onmessage +=
                                e =>
                            {
                                w.postMessage(e.ToString());
                            };
                        };
                    };
                }
                    );
            }
        }