protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

            //this.ToFullscreen();

            var v = new RenderingContextView(this);
            var s = new RaySurface(v);

            this.setContentView(v);

            //this.TryHideActionbar(v);

            //this.ShowToast("http://my.jsc-solutions.net");
        }
Example #2
0
        public void InitializeContent()
        {
            // Initialise WebGL

            // if canvas object makes use of toDataUrl then this arg is required!
            var gl = new WebGLRenderingContext(preserveDrawingBuffer: true, alpha: false);

            var canvas = gl.canvas;

            Native.document.body.style.overflow = IStyle.OverflowEnum.hidden;

            canvas.AttachToDocument();
            canvas.style.SetLocation(0, 0);
            canvas.style.backgroundColor = "black";

            var s = new RaySurface(this);

            this.onsurface(gl);



            #region Dispose
            var IsDisposed = false;

            Dispose = delegate
            {
                if (IsDisposed)
                {
                    return;
                }

                IsDisposed = true;

                canvas.Orphanize();
            };
            #endregion

            #region AtResize
            Action AtResize = delegate
            {
                if (IsDisposed)
                {
                    return;
                }

                canvas.width  = Native.window.Width;
                canvas.height = Native.window.Height;

                this.onresize(Native.window.Width, Native.window.Height);
            };

            AtResize();

            Native.window.onresize += delegate
            {
                AtResize();
            };
            #endregion

            Func <string> newicon = delegate
            {
                var icon = canvas.toDataURL("image/png");

                Native.document.getElementsByTagName("link").AsEnumerable().ToList().WithEach(
                    e =>
                {
                    var link = (IHTMLLink)e;

                    if (link.rel == "icon")
                    {
                        if (link.type == "image/png")
                        {
                            link.href = icon;
                        }
                        else
                        {
                            link.Orphanize();
                        }
                    }
                }
                    );

                return(icon);
            };


            Native.window.onframe += delegate
            {
                if (IsDisposed)
                {
                    return;
                }

                this.onframe();
            };

            Native.document.body.onclick +=
                delegate
            {
                if (IsDisposed)
                {
                    return;
                }

                newicon();
            };


            Native.document.body.ondblclick +=
                delegate
            {
                if (IsDisposed)
                {
                    return;
                }


                Native.document.body.requestFullscreen();
            };

            #region draggable

            // http://www.thecssninja.com/javascript/gmail-dragout
            // can we drag ourself into crx?
            @"Sphere Ray Trace".ToDocumentTitle();

            Native.window.requestAnimationFrame +=
                delegate
            {
                var icon = newicon();
                var img  = new IHTMLImage {
                    src = icon
                };

                //img.width = Native.Window.Width / 2;
                //img.height = Native.Window.Height / 2;

#if PackageAsApplication
                Native.Document.getElementsByTagName("script")
                .Select(k => (IHTMLScript)k)
                .FirstOrDefault(k => k.src.EndsWith("/view-source"))
                .With(
                    source =>
                {
                    #region PackageAsApplication
                    Action <IHTMLScript, XElement, Action <string> > PackageAsApplication =
                        (source0, xml, yield) =>
                    {
                        new IXMLHttpRequest(
                            ScriptCoreLib.Shared.HTTPMethodEnum.GET, source0.src,
                            (IXMLHttpRequest r) =>
                        {
                            // store hash
                            xml.Add(new XElement("link", new XAttribute("rel", "location"), new XAttribute("href", Native.Document.location.hash)));

                            #region script
                            xml.Add(
                                new XElement("script",
                                             "/* source */"
                                             )
                                );

                            var data = "";


                            Action later = delegate
                            {
                                data = data.Replace("/* source */", r.responseText);
                            };
                            #endregion


                            //Native.Document.getElementsByTagName("link").AsEnumerable().ToList().ForEach(

                            xml.Elements("link").ToList().ForEach(
                                (XElement link, Action next) =>
                            {
                                #region style
                                var rel = link.Attribute("rel");
                                if (rel.Value != "stylesheet")
                                {
                                    next();
                                    return;
                                }

                                var href = link.Attribute("href");

                                var placeholder = "/* " + href.Value + " */";

                                //page.DragHTM.innerText += " " + placeholder;


                                xml.Add(new XElement("style", placeholder));

                                new IXMLHttpRequest(ScriptCoreLib.Shared.HTTPMethodEnum.GET, href.Value,
                                                    rr =>
                                {
                                    later += delegate
                                    {
                                        data = data.Replace(placeholder, rr.responseText);
                                    };

                                    Console.WriteLine("link Remove");
                                    link.Remove();

                                    next();
                                }
                                                    );

                                #endregion
                            }
                                )(
                                delegate
                            {
                                data = xml.ToString();
                                Console.WriteLine("data: " + data);
                                later();

                                yield(data);
                            }
                                );
                        }
                            );
                    };
                    #endregion


                    PackageAsApplication(
                        source,
                        XElement.Parse(new DefaultPage.XMLSourceSource().Text),
                        data =>
                    {
                        var bytes  = Encoding.ASCII.GetBytes(data);
                        var data64 = System.Convert.ToBase64String(bytes);


                        Native.Document.body.title = "Drag me!";

                        Native.Document.body.ondragstart +=
                            e =>
                        {
                            //e.dataTransfer.setData("text/plain", "Sphere");

                            // http://codebits.glennjones.net/downloadurl/virtualdownloadurl.htm
                            //e.dataTransfer.setData("DownloadURL", "image/png:Sphere.png:" + icon);

                            e.dataTransfer.setData("DownloadURL", "application/octet-stream:Sphere.htm:data:application/octet-stream;base64," + data64);
                            e.dataTransfer.setData("text/html", data);
                            e.dataTransfer.setData("text/uri-list", Native.Document.location + "");
                            e.dataTransfer.setDragImage(img, img.width / 2, img.height / 2);
                        };
                    }
                        );
                }
                    );
#endif
            };


            #endregion
        }