Esempio n. 1
0
        /**
         * Adds the given browser as an overlay of this browser.
         *
         * The overlaid browser will appear transparently over the top of us on our texture.
         * {overlayBrowser} must not have an overlay and must be sized exactly the same as {this}.
         * Additionally, overlayBrowser.EnableRendering must be false. You still need to
         * do something to handle getting input to the right places. Overlays take a notable performance
         * hit on rendering (CPU alpha compositing).
         *
         * Overlays are used internally to implement context menus and pop-up dialogs (alert, onbeforeunload).
         * If the page causes any type of dialog, the overlay will be replaced.
         *
         * Overlays will be resized onto our texture when we are resized. The sizes must always match exactly.
         *
         * Remove the overlay (SetOverlay(null)) before closing either browser.
         *
         * (Note: though you can't set B as an overlay to A when B has an overlay, you can set
         * an overlay on B /while/ it is the overlay for A. For an example of this, try
         * right-clicking on the text area inside a prompt() popup. The context menu that
         * appears is an overlay to the overlay to the actual browser.)
         */
        public void SetOverlay(Browser overlayBrowser)
        {
            if (DeferUnready(() => SetOverlay(overlayBrowser)))
            {
                return;
            }
            if (overlayBrowser && overlayBrowser.DeferUnready(() => SetOverlay(overlayBrowser)))
            {
                return;
            }

            BrowserNative.zfb_setOverlay(browserId, overlayBrowser ? overlayBrowser.browserId : 0);
            overlay = overlayBrowser;

            if (!overlay)
            {
                return;
            }

            if (
                !overlay.Texture ||
                (overlay.Texture.width != Texture.width || overlay.Texture.height != Texture.height)
                )
            {
                overlay.Resize(Texture);
            }
        }
Esempio n. 2
0
        public static DialogHandler Create(Browser parent, DialogCallback dialogCallback, MenuCallback contextCallback)
        {
            if (dialogPage == null)
            {
                dialogPage = Resources.Load <TextAsset>("Browser/Dialogs").text;
            }
            GameObject    gameObject = new GameObject("Browser Dialog for " + parent.name);
            DialogHandler handler    = gameObject.AddComponent <DialogHandler>();

            handler.parentBrowser  = parent;
            handler.dialogCallback = dialogCallback;
            Browser browser = (handler.dialogBrowser = handler.GetComponent <Browser>());

            browser.UIHandler          = parent.UIHandler;
            browser.EnableRendering    = false;
            browser.EnableInput        = false;
            browser.allowContextMenuOn = BrowserNative.ContextMenuOrigin.Editable;
            browser.Resize(parent.Texture);
            browser.LoadHTML(dialogPage, "about:dialog");
            browser.UIHandler = parent.UIHandler;
            browser.RegisterFunction("reportDialogResult", delegate(JSONNode args)
            {
                dialogCallback(args[0], args[1], args[3]);
                handler.Hide();
            });
            browser.RegisterFunction("reportContextMenuResult", delegate(JSONNode args)
            {
                contextCallback(args[0]);
                handler.Hide();
            });
            return(handler);
        }
Esempio n. 3
0
        private IEnumerator WatchResize()
        {
            Rect currentSize = default(Rect);

            while (base.enabled)
            {
                Rect rect = rTransform.rect;
                if (rect.size.x <= 0f || rect.size.y <= 0f)
                {
                    rect.size = new Vector2(512f, 512f);
                }
                if (rect.size != currentSize.size)
                {
                    browser.Resize((int)rect.size.x, (int)rect.size.y);
                    currentSize = rect;
                }
                yield return(null);
            }
        }
Esempio n. 4
0
        public void InputUpdate()
        {
            MouseScroll = Vector2.zero;
            KeyEvents.Clear();
            delayedResize = new Vector2(float.NaN, float.NaN);

            lock (messages) {
                for (int i = 0; i < messages.Count; i++)
                {
                    HandleMessage(messages[i]);
                }
                messages.Clear();
            }

            if (!float.IsNaN(delayedResize.x))
            {
                browser.Resize((int)delayedResize.x, (int)delayedResize.y);
            }
        }
Esempio n. 5
0
        protected void _Resize(Texture2D newTexture, bool newTextureIsOurs)
        {
            var width  = newTexture.width;
            var height = newTexture.height;

            if (textureIsOurs && texture && newTexture != texture)
            {
                Destroy(texture);
            }

            _width  = width;
            _height = height;

            if (IsReady)
            {
                BrowserNative.zfb_resize(browserId, width, height);
            }
            else
            {
                WhenReady(() => BrowserNative.zfb_resize(browserId, width, height));
            }

            texture       = newTexture;
            textureIsOurs = newTextureIsOurs;

            var renderer = GetComponent <Renderer>();

            if (renderer)
            {
                renderer.material.mainTexture = texture;
            }

            afterResize(texture);

            if (overlay)
            {
                overlay.Resize(Texture);
            }
        }
        /** Automatically resizes the browser to match the size of this object. */
        private IEnumerator WatchResize()
        {
            Rect currentSize = new Rect();

            while (enabled)
            {
                var rect = rTransform.rect;

                if (rect.size.x <= 0 || rect.size.y <= 0)
                {
                    rect.size = new Vector2(512, 512);
                }
                if (rect.size != currentSize.size)
                {
                    browser.Resize((int)rect.size.x, (int)rect.size.y);
                    currentSize = rect;
                }

                //yield return new WaitForSeconds(.5f); won't work if you pause the game, which, BTW, is a great time to resize the screen ;-)
                yield return(null);
            }
        }