Example #1
0
        static void CreateNewFormCanvas(
            Form form1,
            MyRootGraphic myRootGfx,
            InnerViewportKind internalViewportKind,
            out LayoutFarm.UI.UISurfaceViewportControl canvasViewport)
        {
            var       innerViewport        = canvasViewport = new LayoutFarm.UI.UISurfaceViewportControl();
            Rectangle screenClientAreaRect = Conv.ToRect(Screen.PrimaryScreen.WorkingArea);

            canvasViewport.InitRootGraphics(myRootGfx, myRootGfx.TopWinEventPortal, internalViewportKind);
            canvasViewport.Bounds =
                new System.Drawing.Rectangle(0, 0,
                                             screenClientAreaRect.Width,
                                             screenClientAreaRect.Height);

            ////----------------------
            //form1.Controls.Add(canvasViewport);
            ////----------------------
            MakeFormCanvas(form1, canvasViewport);
            form1.SizeChanged += (s, e) =>
            {
                if (form1.WindowState == FormWindowState.Maximized)
                {
                    Screen currentScreen = GetScreenFromX(form1.Left);
                    //make full screen ?
                    if (innerViewport != null)
                    {
                        innerViewport.Size = currentScreen.WorkingArea.Size;
                    }
                }
            };
        }
Example #2
0
        private void cmdShowEmbededViewport_Click(object sender, EventArgs e)
        {
            Form simpleForm = new Form();

            simpleForm.Text        = "SimpleForm2";
            simpleForm.WindowState = FormWindowState.Maximized;
            Rectangle screenClientAreaRect = Screen.PrimaryScreen.WorkingArea;
            var       viewport             = new LayoutFarm.UI.UISurfaceViewportControl();

            viewport.Bounds = new Rectangle(0, 0, screenClientAreaRect.Width, screenClientAreaRect.Height);
            simpleForm.Controls.Add(viewport);

            int w = 800;
            int h = 600;



            var rootgfx = new MyRootGraphic(this.uiPlatformWinForm,
                                            this.gfxPlatform, w, h);

            viewport.InitRootGraphics(rootgfx, rootgfx.TopWinEventPortal,
                                      InnerViewportKind.GdiPlus);

            viewport.PaintMe();

            simpleForm.Show();

            ShowFormLayoutInspector(viewport);
        }
Example #3
0
        static void CreateReadyForm(
            out LayoutFarm.UI.UISurfaceViewportControl viewport,
            out Form formCanvas)
        {
            int w = 800;
            int h = 600;

            var rootgfx = new MyRootGraphic(uiPlatformWinForm,
                                            useOpenGL ? openGLPlatform : gdiPlatform,
                                            w, h);

            var topRenderBox = rootgfx.TopWindowRenderBox;


            formCanvas = FormCanvasHelper.CreateNewFormCanvas(rootgfx,
                                                              useOpenGL ? InnerViewportKind.GL : InnerViewportKind.GdiPlus,
                                                              out viewport);

            formCanvas.Text = "FormCanvas 1";

            viewport.PaintMe();

            formCanvas.WindowState = FormWindowState.Maximized;
            formCanvas.Show();
        }
Example #4
0
        public AppHostIOS(GameViewController vw, int canvasW, int canvasH)
        {
            //---------------------------------------
            //this specific for WindowForm viewport
            //---------------------------------------
            _vw = vw;
            _formTitleBarHeight = 0;
            _canvasW            = canvasW;
            _canvasH            = canvasH;

            _primaryScreenWorkingAreaW = vw.ViewWidth;
            _primaryScreenWorkingAreaH = vw.ViewHeight;

            string basedir = "";

            PixelFarm.Platforms.StorageService.RegisterProvider(new LocalFileStorageProvider(basedir));
            PixelFarm.CpuBlit.MemBitmapExtensions.DefaultMemBitmapIO = new YourImplementation.ImgCodecMemBitmapIO();

            int max = Math.Max(canvasW, canvasH);

            _pcx            = GLPainterContext.Create(max, max, canvasW, canvasH, true);
            _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;

            _painter = new GLPainter();
            _painter.BindToPainterContext(_pcx);
            _painter.SetClipBox(0, 0, canvasW, canvasH);
            _painter.TextPrinter = new GLBitmapGlyphTextPrinter(_painter, PixelFarm.Drawing.GLES2.GLES2Platform.TextService);
            //

            //
            _rootGfx = new MyRootGraphic(canvasW, canvasH, PixelFarm.Drawing.GLES2.GLES2Platform.TextService);
            SetUpGLSurface();
            _drawBoard = new MyGLDrawBoard(_painter);
        }
Example #5
0
        public static EaseViewport CreateViewportControl(Form hostForm, int w, int h)
        {
            var rootgfx = new MyRootGraphic(uiPlatformWinForm,
                                            w, h);

            LayoutFarm.UI.UISurfaceViewportControl viewport;
            CreateNewFormCanvas(hostForm, rootgfx,
                                useOpenGL ? InnerViewportKind.GL : InnerViewportKind.GdiPlus,
                                out viewport);
            viewport.PaintMe();
            EaseViewport easeViewport = new EaseViewport(viewport);

            return(easeViewport);
        }
Example #6
0
        public void CreateMainForm()
        {
            int           w = 800, h = 600;
            GlFwForm      form1          = new GlFwForm(w, h, "PixelFarm on GLfw and GLES2");
            MyRootGraphic myRootGfx      = new MyRootGraphic(w, h, s_textServices);
            var           canvasViewport = new UISurfaceViewportControl();

            canvasViewport.InitRootGraphics(myRootGfx, myRootGfx.TopWinEventPortal, InnerViewportKind.GLES);
            canvasViewport.SetBounds(0, 0, w, h);
            form1.Controls.Add(canvasViewport);


            //demoContext2.LoadDemo(new T45_TextureWrap());
            //demoContext2.LoadDemo(new T48_MultiTexture());
            //demoContext2.LoadDemo(new T107_1_DrawImages());
            _demoBase = new OpenTkEssTest.T108_LionFill();//new T45_TextureWrap(),T48_MultiTexture()
            //_demoBase = new T110_DrawText();
            //_demoBase = new T107_1_DrawImages();

            _demoContext = new GLDemoContext(w, h);
            _demoContext.SetTextPrinter(painter =>
            {
                var printer         = new PixelFarm.DrawingGL.GLBitmapGlyphTextPrinter(painter, s_textServices);
                painter.TextPrinter = printer;
                //create text printer for opengl
                //----------------------
                //1. win gdi based
                //var printer = new WinGdiFontPrinter(canvas2d, w, h);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //2. raw vxs
                //var printer = new PixelFarm.Drawing.Fonts.VxsTextPrinter(canvasPainter);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //3. agg texture based font texture
                //var printer = new AggFontPrinter(canvasPainter, w, h);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //4. texture atlas based font texture
                //------------
                //resolve request font
                //var printer = new GLBmpGlyphTextPrinter(canvasPainter, YourImplementation.BootStrapWinGdi.myFontLoader);
                //canvasPainter.TextPrinter = printer;
            });


            form1.SetDrawFrameDelegate(e => _demoContext.Render());
            _demoContext.LoadDemo(_demoBase);
        }
Example #7
0
        private void cmdShowEmbededViewport_Click(object sender, EventArgs e)
        {
            Form simpleForm = new Form();

            simpleForm.Text        = "SimpleForm2";
            simpleForm.WindowState = FormWindowState.Maximized;
            Rectangle screenClientAreaRect = Screen.PrimaryScreen.WorkingArea;

            MyWinFormsControl actualWinUI = new MyWinFormsControl();

            simpleForm.Controls.Add(actualWinUI);


            InnerViewportKind internalViewportKind = InnerViewportKind.GdiPlus;


            int w = 800;
            int h = 600;


            var textService = new Typography.Text.OpenFontTextService();

            Typography.Text.TextServiceClient client = textService.CreateNewServiceClient();
            MyRootGraphic myRootGfx = new MyRootGraphic(w, h);

            var viewport = new GraphicsViewRoot(screenClientAreaRect.Width, screenClientAreaRect.Height);

            AbstractTopWindowBridge bridge = GetTopWindowBridge(
                internalViewportKind,
                myRootGfx,
                myRootGfx.TopWinEventPortal);

            IGpuOpenGLSurfaceView viewAbstraction = actualWinUI.CreateWindowWrapper(bridge);

            var rootgfx = new MyRootGraphic(w, h);

            viewport.InitRootGraphics(rootgfx,
                                      rootgfx.TopWinEventPortal,
                                      InnerViewportKind.GdiPlus,
                                      viewAbstraction,
                                      bridge);


            viewport.PaintToOutputWindow();
            simpleForm.Show();
            ShowFormLayoutInspector(viewport);
        }
Example #8
0
        static void CreateNewFormCanvas(
            int w, int h,
            PixelFarm.Forms.Form form1,
            InnerViewportKind internalViewportKind,
            out LayoutFarm.UI.WinNeutral.UISurfaceViewportControl canvasViewport)
        {
            var rootgfx = new MyRootGraphic(
                LayoutFarm.UI.UIPlatformWinNeutral.platform,
                LayoutFarm.UI.UIPlatformWinNeutral.platform.GetIFonts(),
                w, h);
            var innerViewport = canvasViewport = new LayoutFarm.UI.WinNeutral.UISurfaceViewportControl();
            //temp fix
            Rectangle screenClientAreaRect = new Rectangle(0, 0, 800, 600); // Conv.ToRect(Screen.PrimaryScreen.WorkingArea);

            canvasViewport.InitRootGraphics(rootgfx, rootgfx.TopWinEventPortal, internalViewportKind);
            canvasViewport.Bounds =
                new Rectangle(0, 0,
                              screenClientAreaRect.Width,
                              screenClientAreaRect.Height);
            ////----------------------
            //form1.Controls.Add(canvasViewport);
            ////----------------------
            MakeFormCanvas(form1, canvasViewport);
            //form1.SizeChanged += (s, e) =>
            //{
            //    if (form1.WindowState == FormWindowState.Maximized)
            //    {
            //        Screen currentScreen = GetScreenFromX(form1.Left);
            //        //make full screen ?
            //        if (innerViewport != null)
            //        {
            //            innerViewport.Size = currentScreen.WorkingArea.Size;
            //        }
            //    }
            //};
        }
Example #9
0
        private void cmdShowBasicFormCanvas_Click(object sender, EventArgs e)
        {
            LayoutFarm.UI.UISurfaceViewportControl viewport;

            int w = 800;
            int h = 600;



            MyRootGraphic rootgfx = new MyRootGraphic(
                this.uiPlatformWinForm,
                this.gfxPlatform,
                w,
                h);


            Form formCanvas = FormCanvasHelper.CreateNewFormCanvas(rootgfx,
                                                                   InnerViewportKind.GdiPlus,
                                                                   out viewport);

            viewport.PaintMe();
            formCanvas.Show();
            ShowFormLayoutInspector(viewport);
        }
Example #10
0
        public void CreateMainForm(int w, int h)
        {
            GlFwForm      form1          = new GlFwForm(w, h, "PixelFarm on GLfw and GLES2");
            MyRootGraphic myRootGfx      = new MyRootGraphic(w, h, s_textServices);
            var           canvasViewport = new UISurfaceViewportControl();

            canvasViewport.InitRootGraphics(myRootGfx, myRootGfx.TopWinEventPortal, InnerViewportKind.GLES);
            canvasViewport.SetBounds(0, 0, w, h);
            form1.Controls.Add(canvasViewport);


            _surfaceViewport = canvasViewport;
            LayoutFarm.AppHostNeutral appHost = new LayoutFarm.AppHostNeutral(canvasViewport);
            form1.SetDrawFrameDelegate(e =>
            {
                _surfaceViewport.PaintMeFullMode();
            });
            if (_app != null)
            {
                appHost.StartApp(_app);//start app
                canvasViewport.TopDownRecalculateContent();
                canvasViewport.PaintMe();
            }
        }
Example #11
0
        void CreateReadyForm(
            out LayoutFarm.UI.UISurfaceViewportControl viewport,
            out Form formCanvas)
        {
            var workingArea = Screen.PrimaryScreen.WorkingArea;
            int w           = workingArea.Width;
            int h           = workingArea.Height;


            MyRootGraphic rootgfx = new MyRootGraphic(this.uiPlatformWinForm,
                                                      this.chkUseGLCanvas.Checked ? openGLPlatform : gdiPlatform,
                                                      w, h);

            formCanvas = FormCanvasHelper.CreateNewFormCanvas(rootgfx,
                                                              this.chkUseGLCanvas.Checked ? InnerViewportKind.GL : InnerViewportKind.GdiPlus,
                                                              out viewport);

            formCanvas.Text = "FormCanvas 1";

            viewport.PaintMe();

            formCanvas.WindowState = FormWindowState.Maximized;
            formCanvas.Show();
        }
Example #12
0
        static void Init(GlFwForm form)
        {
            //PART1:
            //1. storage io
            PixelFarm.Platforms.StorageService.RegisterProvider(new YourImplementation.LocalFileStorageProvider(""));

            //2. img-io implementation
            PixelFarm.CpuBlit.MemBitmapExt.DefaultMemBitmapIO = new YourImplementation.ImgCodecMemBitmapIO(); // new PixelFarm.Drawing.WinGdi.GdiBitmapIO();
            //PixelFarm.CpuBlit.MemBitmapExtensions.DefaultMemBitmapIO = new PixelFarm.Drawing.WinGdi.GdiBitmapIO();

            //------------------------------------------------------------------------
            //
            //if we don't set this, it will error on read-write image
            //you can implement this with other lib that can read-write images

            var pars = new PixelFarm.Platforms.ImageIOSetupParameters();

            pars.SaveToPng = (IntPtr imgBuffer, int stride, int width, int height, string filename) =>
            {
                MemBitmap memBmp = new MemBitmap(width, height, imgBuffer);
                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    PixelFarm.CpuBlit.MemBitmapExt.DefaultMemBitmapIO.SaveImage(memBmp, fs,
                                                                                MemBitmapIO.OutputImageFormat.Png,
                                                                                null);
                }

                //---save with GDI+---
                //using (System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                //{
                //    PixelFarm.CpuBlit.BitmapHelper.CopyToGdiPlusBitmapSameSize(imgBuffer, newBmp);
                //    //save
                //    newBmp.Save(filename);
                //}
            };
            pars.ReadFromMemStream = (System.IO.MemoryStream ms, string kind) =>
            {
                return(PixelFarm.CpuBlit.MemBitmapExt.DefaultMemBitmapIO.LoadImage(ms));
                //read/guest img format

                //--- load img with GDI+---
                ////read
                //using (System.Drawing.Bitmap gdiBmp = new System.Drawing.Bitmap(ms))
                //{
                //    PixelFarm.CpuBlit.MemBitmap memBmp = new PixelFarm.CpuBlit.MemBitmap(gdiBmp.Width, gdiBmp.Height);
                //    //#if DEBUG
                //    //                        memBmp._dbugNote = "img;
                //    //#endif

                //    PixelFarm.CpuBlit.BitmapHelper.CopyFromGdiPlusBitmapSameSizeTo32BitsBuffer(gdiBmp, memBmp);
                //    return memBmp;
                //}
            };
            PixelFarm.Platforms.ImageIOPortal.Setup(pars);
            //------------------------------------------------------------------------


            //3. setup text-breaker
            string icu_datadir = "brkitr"; //see brkitr folder, we link data from Typography project and copy to output if newer

            if (!System.IO.Directory.Exists(icu_datadir))
            {
                throw new System.NotSupportedException("dic");
            }
            Typography.TextBreak.CustomBreakerBuilder.Setup(new Typography.TextBreak.IcuSimpleTextFileDictionaryProvider()
            {
                DataDir = icu_datadir
            });

            //---------------------------------------------------------------------------
            //4. Typography TextService
            Typography.Text.OpenFontTextService textService = new Typography.Text.OpenFontTextService();
            textService.LoadFontsFromFolder("Fonts");
            Typography.Text.TextServiceClient serviceClient = textService.CreateNewServiceClient();
            GlobalTextService.TextService = serviceClient;
            //---------------------------------------------------------------------------

            //PART2: root graphics
            Size primScreenSize = UIPlatform.CurrentPlatform.GetPrimaryMonitorSize();

            s_myRootGfx = new MyRootGraphic(primScreenSize.Width, primScreenSize.Height);
            s_viewroot  = new GraphicsViewRoot(primScreenSize.Width, primScreenSize.Height);
            MyGlfwTopWindowBridge bridge1 = new MyGlfwTopWindowBridge(s_myRootGfx, s_myRootGfx.TopWinEventPortal);

            ((MyGlfwTopWindowBridge.GlfwEventBridge)(form.WindowEventListener)).SetWindowBridge(bridge1);


            var glfwWindowWrapper = new GlfwWindowWrapper(form);

            bridge1.BindWindowControl(glfwWindowWrapper);

            s_viewroot.InitRootGraphics(s_myRootGfx,
                                        s_myRootGfx.TopWinEventPortal,
                                        InnerViewportKind.GLES,
                                        glfwWindowWrapper,
                                        bridge1);



            //------------------------------------------------------------------------
            //optional:
            if (s_viewroot.GetGLPainter() is GLPainter glPainter)
            {
                glPainter.SmoothingMode = SmoothingMode.AntiAlias;
            }
        }
Example #13
0
        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();
        }