protected override void OnStartDemo(SampleViewport viewport) { this.sampleViewport = viewport; imageContentMan = new ContentManagers.ImageContentManager(viewport.Platform); imageContentMan.ImageLoadingRequest += (s, e) => { e.SetResultImage(LoadBitmap(e.ImagSource)); }; //init host myHtmlHost = HtmlHostCreatorHelper.CreateHtmlHost(viewport, (s, e) => this.imageContentMan.AddRequestImage(e.ImageBinder), (s, e) => { }); //----------------------------------------------------- this.groundHtmlBox = new HtmlBox(myHtmlHost, 800, 600); string html = @"<div></div>"; //if you want to use full html-> use HtmlBox instead this.sampleViewport.AddContent(groundHtmlBox); //----------------------------------------------------- groundHtmlBox.LoadHtmlFragmentString(html); this.groundHtmlDoc = groundHtmlBox.HtmlContainer.WebDocument as HtmlDocument; OnHtmlHostCreated(); }
protected override void OnStart(AppHost host, IGameHTMLUI pcx) { _host = host; _imgLoadingQ = new ContentManagers.ImageLoadingQueueManager(); _imgLoadingQ.AskForImage += (s, e) => { e.SetResultImage(host.LoadImage(e.ImagSource)); }; //init host _myHtmlHost = HtmlHostCreatorHelper.CreateHtmlHost(host, (s, e) => _imgLoadingQ.AddRequestImage(e.ImageBinder), (s, e) => { }); //----------------------------------------------------- _groundHtmlBox = new HtmlBox(_myHtmlHost, 800, 600); string html = @"<div></div>"; //if you want to use full html-> use HtmlBox instead _host.AddChild(_groundHtmlBox); //----------------------------------------------------- _groundHtmlBox.LoadHtmlFragmentString(html); _groundHtmlDoc = _groundHtmlBox.HtmlDoc as HtmlDocument; OnHtmlHostCreated(); }
public void StartModule(LayoutFarm.SampleViewport sampleViewport) { this.viewport = sampleViewport; dzBoardModule = new DesignBoardModule(); menuModule = new MenuBoardModule(); menuModule.menuItemClick += new EventHandler <MenuItemClickEventArgs>(menuModule_menuItemClick); var contentMx = new LayoutFarm.ContentManagers.ImageContentManager(); contentMx.ImageLoadingRequest += contentMx_ImageLoadingRequest; //app specific here documentRootPath = System.Windows.Forms.Application.ExecutablePath; this.htmlHost = HtmlHostCreatorHelper.CreateHtmlHost(viewport, (s, e) => contentMx.AddRequestImage(e.ImageBinder), contentMx_LoadStyleSheet); //1. design board dzBoardModule.StartModule(htmlHost, this.viewport); ////2. canvas board //drawingBoard.StartModule(htmlHost, this.viewport); //3. menu menuModule.StartModule(htmlHost, this.viewport); //------------------------------------------------------ //context knowledge*** //------------------------------------------------------ }
protected override void OnStart(AppHost host) { //html box _host = host; _painter = (GLPainter)host.GetPainter(); var loadingQueueMx = new LayoutFarm.ContentManagers.ImageLoadingQueueManager(); loadingQueueMx.AskForImage += loadingQueue_AskForImg; HtmlHost htmlHost = HtmlHostCreatorHelper.CreateHtmlHost(host, (s, e) => loadingQueueMx.AddRequestImage(e.ImageBinder), contentMx_LoadStyleSheet); // _htmlBox = new HtmlBox(htmlHost, 1024, 800); _htmlBox.SetLocation(0, 300); //test _rootgfx = host.GetRootGraphics(); _rootE = _htmlBox.GetPrimaryRenderElement(_rootgfx); _drawBoard = host.GetDrawBoard(); host.AddChild(_htmlBox); //------- _htmltext = @"<html> <head> <style> .myfont1{font-size:30pt;background-color:yellow} .myfont2{font-size:24pt;background-color:rgb(255,215,0)} </style> </head> <body> <div class='myfont1'>Hello</div> <div class='myfont2'>... from HtmlRenderer</div> </body> </html>"; //if (_htmltext == null) //{ // _htmltext = @"<html><head></head><body>NOT FOUND!</body></html>"; //} _htmlBox.LoadHtmlString(_htmltext); }
public static void Start() { if (!Glfw.Init()) { Console.WriteLine("can't init glfw"); return; } //--------------------------------------------------- //specific OpenGLES *** Glfw.WindowHint(WindowHint.GLFW_CLIENT_API, (int)OpenGLAPI.OpenGLESAPI); Glfw.WindowHint(WindowHint.GLFW_CONTEXT_CREATION_API, (int)OpenGLContextCreationAPI.GLFW_EGL_CONTEXT_API); Glfw.WindowHint(WindowHint.GLFW_CONTEXT_VERSION_MAJOR, 2); Glfw.WindowHint(WindowHint.GLFW_CONTEXT_VERSION_MINOR, 0); //--------------------------------------------------- Glfw.SwapInterval(1); GlFwForm form1 = GlfwApp.CreateGlfwForm( 800, 600, "PixelFarm + Skia on GLfw and OpenGLES2"); form1.MakeCurrent(); //------------------------------------ //*** GLFWPlatforms.CreateGLESContext(); //------------------------------------ form1.Activate(); int ww_w = 800; int ww_h = 600; int max = Math.Max(ww_w, ww_h); canvasGL2d = PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvasGL2d(max, max); //------------------------------------ GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.ClearColor(1, 1, 1, 1); //-------------------------------------------------------------------------------- //setup viewport size //set up canvas needUpdateContent = true; //GL.Viewport(0, 0, 800, 600); GL.Viewport(0, 0, max, max); FormRenderUpdateEventArgs formRenderUpdateEventArgs = new FormRenderUpdateEventArgs(); formRenderUpdateEventArgs.form = form1; LayoutFarm.Ease.EaseHost.StartGraphicsHost(); var rootgfx = new MyRootGraphic( LayoutFarm.UI.UIPlatformWinNeutral.platform, LayoutFarm.UI.UIPlatformWinNeutral.platform.GetIFonts(), ww_w, ww_h); var surfaceViewportControl = new LayoutFarm.UI.WinNeutral.UISurfaceViewportControl(); surfaceViewportControl.InitRootGraphics(rootgfx, rootgfx.TopWinEventPortal, InnerViewportKind.GL); //lion fill sample OpenTkEssTest.T108_LionFill lionFill = new OpenTkEssTest.T108_LionFill(); lionFill.Init2(canvasGL2d); GLCanvasPainter painter1 = lionFill.Painter; var myCanvasGL = new PixelFarm.Drawing.GLES2.MyGLCanvas(painter1, 0, 0, 800, 600); //(PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvas(0, 0, 800, 600, canvasGL2d, painter1); surfaceViewportControl.SetupCanvas(myCanvasGL); SampleViewport viewport = new LayoutFarm.SampleViewport(surfaceViewportControl); HtmlHost htmlHost; htmlHost = HtmlHostCreatorHelper.CreateHtmlHost(viewport, null, null); ////================================================== //html box HtmlBox lightHtmlBox = new HtmlBox(htmlHost, 800, 50); { lightHtmlBox.SetLocation(50, 450); viewport.AddContent(lightHtmlBox); //light box can't load full html //all light boxs of the same lightbox host share resource with the host string html = @"<div>OK1</div><div>OK2</div>"; //if you want to use full html-> use HtmlBox instead lightHtmlBox.LoadHtmlString(html); } form1.SetDrawFrameDelegate(() => { //render each frame if (needUpdateContent) { UpdateViewContent(formRenderUpdateEventArgs); } canvasGL2d.Clear(Color.White); //canvasGL2d.DrawRect(0, 0, 200, 200); ////canvasGL2d.DrawImage(glBmp, 0, 600); //int tmp_x = lightHtmlBox.Left; //int tmp_y = lightHtmlBox.Top; //myCanvasGL.SetCanvasOrigin(tmp_x, tmp_y); canvasGL2d.SmoothMode = CanvasSmoothMode.No; //--------- //flip y axis for html box (and other UI) canvasGL2d.FlipY = true; lightHtmlBox.CurrentPrimaryRenderElement.DrawToThisCanvas( myCanvasGL, new Rectangle(0, 0, 800, 600)); canvasGL2d.FlipY = false; //myCanvasGL.SetCanvasOrigin(tmp_x, -tmp_y); //lion use canvas coordinate system lionFill.TestRender(); //surfaceViewportControl.PaintMe(canvasGL2d); }); while (!GlfwApp.ShouldClose()) { //--------------- //render phase and swap GlfwApp.UpdateWindowsFrame(); /* Poll for and process events */ Glfw.PollEvents(); } Glfw.Terminate(); }