Пример #1
0
 public void SetZoom(double zoom)
 {
     if (_browserHost != null && _browserHost.GetZoomLevel() != zoom)
     {
         _browserHost.SetZoomLevel(dpi);
     }
 }
Пример #2
0
        internal void HandleAfterCreated(CefBrowser browser)
        {
            this.browser     = browser;
            this.browserHost = browser.GetHost();

            needInvalidate = true;
            browserHost.SetZoomLevel(zoom);

            var handler = Created;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
Пример #3
0
        internal void HandleAfterCreated(CefBrowser browser)
        {
            this.browser     = browser;
            this.browserHost = browser.GetHost();

            needInvalidate = true;
            browserHost.SetZoomLevel(Zoom);

            BrowserCreated?.Invoke(this);

            if (string.IsNullOrEmpty(StartURL) && string.IsNullOrEmpty(StartFile) && !string.IsNullOrEmpty(StartString))
            {
                LoadString(StartString);
            }
        }
Пример #4
0
 internal void OnLoadingStateChange(bool isLoading, bool canGoBack, bool canGoForward)
 {
     FIsLoading = isLoading;
     if (!isLoading)
     {
         using (var frame = FBrowser.GetMainFrame())
         {
             FCurrentUrl = frame.Url;
             UpdateDom(frame);
             UpdateDocumentSize();
         }
         FLoaded = true;
         // HACK: Re-apply zooming level :/ - https://vvvv.org/forum/htmltexture-bug-with-zoomlevel
         FBrowserHost.SetZoomLevel(ZoomLevel);
     }
     else
     {
         // Reset computed values like document size or DOM
         Reset();
     }
 }
Пример #5
0
        protected override void OnRenderUI(GuiRenderer renderer)
        {
            base.OnRenderUI(renderer);

            Vec2I size = GetNeededSize();

            if (browser == null)
            {
                CreateBrowser();
            }

            //update brower engine and texture
            if (browser != null)
            {
                if (viewSize != size /*&& !browser.IsResizing */)
                {
                    var oldSize = viewSize;
                    viewSize = size;
                    OnResized(oldSize, viewSize);
                }

                //create texture
                if (texture == null || textureSize != size || needRecreateTexture)
                {
                    if (texture != null)
                    {
                        texture.Dispose();
                        texture = null;
                    }

                    textureSize = size;

                    string textureName = TextureManager.Instance.GetUniqueName("WebBrowserControl");

                    bool mipmaps = false;
                    if (GetControlManager() != null && GetControlManager() is In3dControlManager)
                    {
                        mipmaps = inGame3DGuiMipmaps;
                    }

                    if (mipmaps)
                    {
                        texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D, textureSize,
                                                                 1, -1, PixelFormat.A8R8G8B8, Texture.Usage.DynamicWriteOnlyDiscardable | Texture.Usage.AutoMipmap);
                    }
                    else
                    {
                        texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D, textureSize,
                                                                 1, 0, PixelFormat.A8R8G8B8, Texture.Usage.DynamicWriteOnlyDiscardable);
                    }

                    needUpdateTexture   = true;
                    needRecreateTexture = false;
                }

                if (needInvalidate)
                {
                    browserHost.SetZoomLevel(zoom);
                    browserHost.Invalidate(CefPaintElementType.View);
                    //browserHost.Invalidate( new CefRectangle( 0, 0, 100000, 100000 ), CefPaintElementType.View );
                    needInvalidate = false;
                }

                //update texture
                if (/*browser.IsDirty ||*/ needUpdateTexture)
                {
                    if (texture != null)
                    {
                        UpdateTexture();
                    }
                    needUpdateTexture = false;
                }
            }

            //draw texture
            if (browser != null)
            {
                bool backColorZero = BackColor == new ColorValue(0, 0, 0, 0);

                ColorValue color = backColorZero ? new ColorValue(1, 1, 1) : BackColor;
                if (texture == null)
                {
                    color = new ColorValue(0, 0, 0, color.Alpha);
                }
                color *= GetTotalColorMultiplier();

                color.Clamp(new ColorValue(0, 0, 0, 0), new ColorValue(1, 1, 1, 1));

                Rect rect;
                GetScreenRectangle(out rect);

                if (renderer.IsScreen && !renderer._OutGeometryTransformEnabled)
                {
                    //screen per pixel accuracy

                    Vec2 viewportSize = renderer.ViewportForScreenGuiRenderer.DimensionsInPixels.Size.ToVec2();

                    Vec2 leftTop = rect.LeftTop;
                    leftTop *= viewportSize;
                    leftTop  = new Vec2((int)(leftTop.X + .9999f), (int)(leftTop.Y + .9999f));
                    if (RenderSystem.Instance.IsDirect3D())
                    {
                        leftTop -= new Vec2(.5f, .5f);
                    }
                    leftTop /= viewportSize;

                    Vec2 rightBottom = rect.RightBottom;
                    rightBottom *= viewportSize;
                    rightBottom  = new Vec2((int)(rightBottom.X + .9999f), (int)(rightBottom.Y + .9999f));
                    if (RenderSystem.Instance.IsDirect3D())
                    {
                        rightBottom -= new Vec2(.5f, .5f);
                    }
                    rightBottom /= viewportSize;

                    Rect fixedRect = new Rect(leftTop, rightBottom);

                    renderer.AddQuad(fixedRect, new Rect(0, 0, 1, 1), texture, color, true);
                }
                else
                {
                    renderer.AddQuad(rect, new Rect(0, 0, 1, 1), texture, color, true);
                }
            }

            if (cefRuntimeUnableToLoad)
            {
                renderer.AddTextWordWrap(
                    string.Format("WebBrowserControl: Unable to initialize web browser control. Error: {0}", cefRuntimeUnableToLoadError),
                    GetScreenRectangle(), Renderer.HorizontalAlign.Center, false, Renderer.VerticalAlign.Center, 0, new ColorValue(1, 0, 0));
            }
            else if (!IsSupportedByThisPlatform())
            {
                renderer.AddText(string.Format("WebBrowserControl: {0} is not supported.", PlatformInfo.Platform),
                                 new Vec2(.5f, .5f), Renderer.HorizontalAlign.Center, Renderer.VerticalAlign.Center, new ColorValue(1, 0, 0));
            }
        }
Пример #6
0
        protected override void OnRenderUI(CanvasRenderer renderer)
        {
            base.OnRenderUI(renderer);

            Vector2I size = GetNeededSize();

            if (browser == null)
            {
                CreateBrowser();
            }

            //update brower engine and texture
            if (browser != null)
            {
                if (viewSize != size /*&& !browser.IsResizing */)
                {
                    var oldSize = viewSize;
                    viewSize = size;
                    OnResized(oldSize, viewSize);
                }

                //create texture
                if (texture == null || textureSize != size || needRecreateTexture)
                {
                    if (texture != null)
                    {
                        texture.Dispose();
                        texture = null;
                    }

                    textureSize = size;

                    bool mipmaps = false;
                    //!!!!
                    //if( ControlManager != null && ControlManager is UI3DControlContainer )
                    //	mipmaps = renderingIn3DMipmaps;

                    var usage = Component_Image.Usages.WriteOnly;
                    if (mipmaps)
                    {
                        usage |= Component_Image.Usages.AutoMipmaps;
                    }

                    texture               = ComponentUtility.CreateComponent <Component_Image>(null, true, false);
                    texture.CreateType    = Component_Image.TypeEnum._2D;
                    texture.CreateSize    = textureSize;
                    texture.CreateMipmaps = mipmaps;                    // ? -1 : 0;
                    texture.CreateFormat  = PixelFormat.A8R8G8B8;
                    texture.CreateUsage   = usage;
                    texture.Enabled       = true;

                    //Log.Info( textureSize.ToString() );

                    //if( mipmaps )
                    //{
                    //	texture = TextureManager.Instance.Create( textureName, Texture.Type.Type2D, textureSize,
                    //		1, -1, PixelFormat.A8R8G8B8, Texture.Usage.DynamicWriteOnlyDiscardable | Texture.Usage.AutoMipmap );
                    //}
                    //else
                    //{
                    //	texture = TextureManager.Instance.Create( textureName, Texture.Type.Type2D, textureSize,
                    //		1, 0, PixelFormat.A8R8G8B8, Texture.Usage.DynamicWriteOnlyDiscardable );
                    //}

                    needUpdateTexture   = true;
                    needRecreateTexture = false;
                }

                if (needInvalidate)
                {
                    browserHost.SetZoomLevel(Zoom);
                    browserHost.Invalidate(new CefRectangle(0, 0, 100000, 100000), CefPaintElementType.View);
                    needInvalidate = false;
                }

                //update texture
                if (/*browser.IsDirty ||*/ needUpdateTexture)
                {
                    if (texture != null)
                    {
                        UpdateTexture();
                    }
                    needUpdateTexture = false;
                }
            }

            //draw texture
            {
                //bool backColorZero = BackColor == new ColorValue( 0, 0, 0, 0 );

                //ColorValue color = new ColorValue( 1, 1, 1 );
                ////ColorValue color = backColorZero ? new ColorValue( 1, 1, 1 ) : BackColor;
                //if( texture == null )
                //	color = new ColorValue( 0, 0, 0, color.Alpha );
                //color *= GetTotalColorMultiplier();

                //var color = GetTotalColorMultiplier();
                //if( color.Alpha > 0 )
                //{
                var color = new ColorValue(1, 1, 1);
                //color.Saturate();

                GetScreenRectangle(out var rect);

                Component_Image tex = null;
                if (renderBuffer != null && renderBufferForSize == ViewSize && renderBuffer.Length == ViewSize.X * ViewSize.Y * 4)
                {
                    tex = texture;
                }
                if (tex == null)
                {
                    tex = ResourceUtility.WhiteTexture2D;
                }

                if (renderer.IsScreen)                 //&& !renderer._OutGeometryTransformEnabled )
                {
                    ////screen per pixel accuracy

                    Vector2   viewportSize = renderer.ViewportForScreenCanvasRenderer.SizeInPixels.ToVector2F();
                    var       v            = size.ToVector2() / viewportSize;
                    Rectangle fixedRect    = new Rectangle(rect.LeftTop, rect.LeftTop + v);

                    //Vec2 leftTop = rect.LeftTop;
                    //leftTop *= viewportSize;
                    //leftTop = new Vec2( (int)( leftTop.X + .9999f ), (int)( leftTop.Y + .9999f ) );
                    ////!!!!!
                    ////if( RenderSystem.Instance.IsDirect3D() )
                    ////	leftTop -= new Vec2( .5f, .5f );
                    //leftTop /= viewportSize;

                    //Vec2 rightBottom = rect.RightBottom;
                    //rightBottom *= viewportSize;
                    //rightBottom = new Vec2( (int)( rightBottom.X + .9999f ), (int)( rightBottom.Y + .9999f ) );
                    ////!!!!!
                    ////if( RenderSystem.Instance.IsDirect3D() )
                    ////	rightBottom -= new Vec2( .5f, .5f );
                    //rightBottom /= viewportSize;

                    //Rect fixedRect = new Rect( leftTop, rightBottom );

                    renderer.PushTextureFilteringMode(CanvasRenderer.TextureFilteringMode.Point);
                    renderer.AddQuad(fixedRect, new Rectangle(0, 0, 1, 1), tex, color, true);
                    renderer.PopTextureFilteringMode();
                }
                else
                {
                    renderer.AddQuad(rect, new Rectangle(0, 0, 1, 1), tex, color, true);
                }
                //}
            }

            if (!IsSupportedByThisPlatform())
            {
                var text   = string.Format("UIWebBrowser: {0} is not supported.", SystemSettings.CurrentPlatform);
                var center = GetScreenRectangle().GetCenter();
                renderer.AddText(text, center, EHorizontalAlignment.Center, EVerticalAlignment.Center, new ColorValue(1, 0, 0));
            }
        }