Example #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(IDefault page = null)
 {
     #region scripts -> InitializeContent
     new[]
     {
         new global::WebGLPlanetGenerator.Design.sylvester().Content,
         new global::WebGLPlanetGenerator.Design.glUtils().Content,
         new global::WebGLPlanetGenerator.Design.particle_terrain().Content,
         new global::WebGLPlanetGenerator.Design.planet().Content,
     }.ForEach(
         (SourceScriptElement, i, MoveNext) =>
     {
         SourceScriptElement.AttachToDocument().onload +=
             delegate
         {
             MoveNext();
         };
     }
         )(
         delegate
     {
         InitializeContent(page);
     }
         );
     #endregion
 }
Example #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(IDefault page = null)
        {
            #region await then do InitializeContent
            new[]
            {
                new Data.macbook().Content,
            }.ForEach(
                (SourceScriptElement, i, MoveNext) =>
            {
                SourceScriptElement.AttachToDocument().onload +=
                    delegate
                {
                    MoveNext();
                };
            }
                )(
                delegate
            {
                InitializeContent(page);
            }
                );
            #endregion



            style.Content.AttachToHead();
        }
Example #3
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(IDefault page = null)
        {
            var location = "" + Native.document.location;

#if false
            #region workaround for ThreeJS/chrome webgl upscale bug
            // workaround for not knowing how to tell three js to upscale correctly..
            // X:\jsc.svn\examples\javascript\Test\TestNestedIFrameForMoreWidth\TestNestedIFrameForMoreWidth\Application.cs
            // instead of reloading full app
            // could we run part of it instead?
            // like let jsc know that this sub application should be reloadable?
            // this will be like threading
            // the outer code wil just stop doing anything
            // and the inner app will take over.


            if (Native.window.Width < Native.screen.width)
            {
                #region make sure the url looks different to make iframe actually load
                Native.window.parent.With(
                    parent =>
                {
                    // http://stackoverflow.com/questions/5934538/is-there-a-limitation-on-an-iframe-containing-another-iframe-with-the-same-url

                    var parentlocation = "";

                    try
                    {
                        parentlocation = parent.document.location.href;
                        Console.WriteLine(new { parentlocation });
                    }
                    catch
                    {
                        // we are sandboxed!
                    }

                    if (parentlocation.TakeUntilIfAny("#") == location.TakeUntilIfAny("#"))
                    {
                        var withouthash = location.TakeUntilIfAny("#");
                        var onlyhash    = location.SkipUntilOrEmpty("#");

                        withouthash += "?";

                        if (onlyhash != "")
                        {
                            withouthash += "#" + onlyhash;
                        }

                        location = withouthash;
                    }
                }
                    );
                #endregion



                // this check only looks for default screen width
                // what about height and secondary screens?
                Console.WriteLine("will prepare... " + location);

                var iframe = new IHTMLIFrame
                {
                    frameBorder     = "0",
                    allowFullScreen = true
                };

                iframe.style.minWidth  = Native.screen.width + "px";
                iframe.style.minHeight = Native.screen.height + "px";

                iframe.style.position = IStyle.PositionEnum.absolute;
                iframe.style.left     = "0px";
                iframe.style.top      = "0px";
                iframe.style.width    = "100%";
                iframe.style.height   = "100%";

                Native.document.body.Clear();
                Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;

                Native.window.onmessage +=
                    e =>
                {
                    Console.WriteLine("Native.Window.onmessage " + new { e.data });

                    // pure trickery :P
                    if ((string)e.data == "WebGLDynamicTerrainTemplate.loaded")
                    {
                        iframe.style.minWidth  = "";
                        iframe.style.minHeight = "";
                    }
                };

                iframe.onload +=
                    delegate
                {
                    if (iframe.src != location)
                    {
                        return;
                    }

                    Native.window.requestAnimationFrame +=
                        delegate
                    {
                        Console.WriteLine("reload done! " + new { location, iframe.src });
                        iframe.contentWindow.postMessage("ready yet?");
                    };
                };

                Native.window.requestAnimationFrame +=
                    delegate
                {
                    Console.WriteLine("will reload... " + location);
                    iframe.AttachToDocument();
                    iframe.src = location;
                };

                return;
            }



            #endregion
#endif


            #region await Three.js then do InitializeContent
            new[]
            {
                new global::WebGLDynamicTerrainTemplate.Design.ThreeTerrain().Content,

                new global::WebGLDynamicTerrainTemplate.Design.ShaderTerrain().Content,
                new global::WebGLDynamicTerrainTemplate.Design.ShaderExtrasTerrain().Content,
                new global::WebGLDynamicTerrainTemplate.Design.PostprocessingTerrain().Content,
            }.ForEach(
                (SourceScriptElement, i, MoveNext) =>
            {
                SourceScriptElement.AttachToDocument().onload +=
                    delegate
                {
                    MoveNext();
                };
            }
                )(
                delegate
            {
                InitializeContent(page);
            }
                );
            #endregion


            style.Content.AttachToHead();
        }