Esempio n. 1
0
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            ////==================================================
            //html box
            HtmlBoxes.HtmlHost htmlHost = HtmlHostCreatorHelper.CreateHtmlHost(host, null, null);
            var           htmlBox       = new HtmlBox(htmlHost, 800, 400);
            StringBuilder stbuilder     = new StringBuilder();

            stbuilder.Append("<html><head></head><body>");
            stbuilder.Append("<div>custom box1</div>");
            stbuilder.Append("<x id=\"my_custombox1\"></x>");
            stbuilder.Append("<div>custom box2</div>");
            stbuilder.Append("<x type=\"textbox\" id=\"my_custombox1\"></x>");
            stbuilder.Append("</body></html>");
            htmlBox.LoadHtmlString(stbuilder.ToString());
            host.AddChild(htmlBox);
            //==================================================

            //textbox
            var textbox = new LayoutFarm.CustomWidgets.TextBox(400, 100, true);

            textbox.SetLocation(0, 200);
            host.AddChild(textbox);
            textbox.Focus();
        }
Esempio n. 2
0
        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();
        }
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            base.OnStart(host, pcx); //setup

            WebDom.DomElement rootNode = _groundHtmlDoc.RootNode;

            //style 2, lambda and adhoc attach event
            rootNode.AddChild("body", body =>
            {
                body.AddChild("div", div =>
                {
                    div.AddChild("span", span =>
                    {
                        span.AddTextContent("ABCD");
                        //3. attach event to specific span
                        span.AttachMouseDownEvent(e =>
                        {
#if DEBUG
                            var s_span = new EaseScriptElement(span);
                            s_span.ChangeFontColor(PixelFarm.Drawing.Color.Blue);
#endif

                            e.StopPropagation();
                        });
                    });
                    div.AddChild("span", span =>
                    {
                        span.AddTextContent("EFGHIJK");
                        span.AttachMouseDownEvent(e =>
                        {
                            span.ClearAllElements();
                            span.AddTextContent("LMNOP0003");
                            var s_span = new EaseScriptElement(span);
                            s_span.ChangeFontColor(PixelFarm.Drawing.Color.Red);
                            s_span.ChangeBackgroundColor(PixelFarm.Drawing.Color.Yellow);
                        });
                        span.AttachMouseUpEvent(e =>
                        {
                            var s_span = new EaseScriptElement(span);
                            s_span.ChangeFontColor(PixelFarm.Drawing.Color.Black);
                            s_span.ChangeBackgroundColor(PixelFarm.Drawing.Color.White);
                        });
                    });
                    //----------------------
                    div.AttachEvent(UIEventName.MouseDown, e =>
                    {
#if DEBUG
                        //this will not print
                        //if e has been stop by its child
                        // System.Diagnostics.Debugger.Break();
                        //Console.WriteLine("div");
#endif
                    });
                });
            });
        }
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            base.OnStart(host, pcx); //setup

            var htmldoc  = _groundHtmlDoc;
            var rootNode = htmldoc.RootNode;

            //1. create body node
            // and content

            //style 2, lambda and adhoc attach event
            rootNode.AddChild("body", body =>
            {
                body.AddChild("div", div =>
                {
                    div.AddChild("span", span =>
                    {
                        span.AddTextContent("ABCD");
                        //3. attach event to specific span
                        span.AttachMouseDownEvent(e =>
                        {
#if DEBUG
                            // System.Diagnostics.Debugger.Break();
                            //test change span property
                            //clear prev content and add new  text content
                            span.ClearAllElements();
                            span.AddTextContent("XYZ0001");
#endif

                            e.StopPropagation();
                        });
                    });
                    div.AddChild("span", span =>
                    {
                        span.AddTextContent("EFGHIJK");
                        span.AttachMouseDownEvent(e =>
                        {
                            span.ClearAllElements();
                            span.AddTextContent("LMNOP0003");
                        });
                    });
                    //----------------------
                    div.AttachEvent(UIEventName.MouseDown, e =>
                    {
#if DEBUG
                        //this will not print
                        //if e has been stop by its child
                        // System.Diagnostics.Debugger.Break();
                        //Console.WriteLine("div");
#endif
                    });
                });
            });
        }
Esempio n. 5
0
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            {
                string html = @"<html><head></head><body><div>OK1</div><div>OK2</div></body></html>";


                string testFilename = @"D:\projects\HtmlRenderer\Source\Test8_HtmlRenderer.Demo\Samples\0_acid1_dev\00.htm";
                //string testFilename = "..\\Test8_HtmlRenderer.Demo\\Samples\\0_acid1_dev\\00.htm";
                if (System.IO.File.Exists(testFilename))
                {
                    html = System.IO.File.ReadAllText(testFilename);
                }


                //html box1
                HtmlBoxes.HtmlHost htmlhost = HtmlHostCreatorHelper.CreateHtmlHost(host, null, null);
                //html box
                var htmlBox = new HtmlBox(htmlhost, 800, 600);
                htmlBox.SetLocation(0, 0);
                //htmlBox.PreferSoftwareRenderer = true;
                host.AddChild(htmlBox);

                htmlBox.LoadHtmlString(html);
                //==================================================
            }
            {
                //html box2

                HtmlBoxes.HtmlHost htmlhost = HtmlHostCreatorHelper.CreateHtmlHost(host, null, null);
                //html box
                var htmlBox = new HtmlBox(htmlhost, 800, 400);
#if DEBUG
                htmlBox.dbugPreferSoftwareRenderer = true;
#endif
                htmlBox.SetLocation(0, 610);//**
                host.AddChild(htmlBox);
                string html = @"<html><head></head><body><div>OK3</div><div>OK4</div></body></html>";
                htmlBox.LoadHtmlString(html);
                //==================================================
            }

            //{
            //    //textbox
            //    var textbox = new LayoutFarm.CustomWidgets.TextBox(400, 25, true);
            //    textbox.SetLocation(0, 0);
            //    host.AddChild(textbox);
            //    textbox.Focus();
            //}
        }
Esempio n. 6
0
        public HtmlMonoGamePanelControl GetPanel(IGameHTMLUI pcx)
        {
            _pcx = pcx;

            //1. create blank form
            YourImplementation.DemoFormCreatorHelper.CreateReadyForm(
                InnerViewportKind.MonoGame,
                out _viewroot,
                out _latest_formCanvas,
                _pcx.UI,
                _pcx);

            //_userInterface.UseRenderTarget = false;
            //_userInterface.AddEntity(_latest_formCanvas);

            AppHost       appHost = new AppHost(_pcx);
            AppHostConfig config  = new AppHostConfig();

            //YourImplementation.UISurfaceViewportSetupHelper.SetUISurfaceViewportControl(config, _viewroot);
            appHost.Setup(config);


            /*_latest_formCanvas.FormClosed += (s, e) =>
             * {
             *  //when owner form is disposed
             *  //we should clear our resource?
             *  app.OnClosing();
             *  app.OnClosed();
             *  _latest_formCanvas = null;
             *  _viewroot = null;
             * };*/


            //2. create app host
            appHost.StartApp(this);
            //_viewroot.TopDownRecalculateContent();



            //==================================================
            if (false) //true) //this.chkShowLayoutInspector.Checked)
            {
                ///YourImplementation.LayoutInspectorUtils.ShowFormLayoutInspector(_viewroot);
            }


            return(_latest_formCanvas);
        }
Esempio n. 7
0
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            _host         = host;
            this.htmlhost = HtmlHostCreatorHelper.CreateHtmlHost(host, null, null);
            SetupHtmlMenuBox();
            //==================================================
            //box1 test area
            //html box
            this.testHtmlBox = new HtmlBox(htmlhost, 800, 400);
            testHtmlBox.SetLocation(30, 50);
            host.AddChild(testHtmlBox);
            string html = @"<html><head></head><body><div id='div1'>OK1</div><div>OK2</div></body></html>";

            testHtmlBox.LoadHtmlString(html);
            //==================================================
        }
Esempio n. 8
0
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            base.OnStart(host, pcx);//setup

            //
            var htmldoc  = _groundHtmlDoc;
            var rootNode = htmldoc.RootNode;

            //1. create body node
            // and content

            //style 2, lambda and adhoc attach event
            rootNode.AddChild("body", body =>
            {
                body.AddChild("div", div =>
                {
                    div.AddChild("span", span =>
                    {
                        span.AddTextContent("ABCD");
                        //3. attach event to specific span
                        span.AttachEvent(UIEventName.MouseDown, e =>
                        {
                            //-------------------------------
                            //mousedown on specific span !
                            //-------------------------------
#if DEBUG
                            // System.Diagnostics.Debugger.Break();
                            //Console.WriteLine("span");
#endif

                            //test stop propagation
                            e.StopPropagation();
                        });
                    });
                    //----------------------
                    div.AttachEvent(UIEventName.MouseDown, e =>
                    {
#if DEBUG
                        //this will not print
                        //if e has been stop by its child
                        // System.Diagnostics.Debugger.Break();
                        //Console.WriteLine("div");
#endif
                    });
                });
            });
        }
Esempio n. 9
0
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            htmlHost = HtmlHostCreatorHelper.CreateHtmlHost(host, null, null);
            ////==================================================
            //html box
            {
                HtmlBox lightHtmlBox = new HtmlBox(htmlHost, 800, 50);
                lightHtmlBox.SetLocation(50, 450);
                host.AddChild(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.LoadHtmlFragmentString(html);
            }
            //==================================================
            {
                HtmlBox lightHtmlBox2 = new HtmlBox(htmlHost, 800, 50);
                lightHtmlBox2.SetLocation(0, 60);
                host.AddChild(lightHtmlBox2);
                //light box can't load full html
                //all light boxs of the same lightbox host share resource with the host
                string html2 = @"<div>OK3</div><div>OK4</div>";
                //if you want to use ful l html-> use HtmlBox instead
                lightHtmlBox2.LoadHtmlFragmentString(html2);
            }
            //==================================================
            {
                HtmlBox lightHtmlBox3 = new HtmlBox(htmlHost, 800, 50);
                lightHtmlBox3.SetLocation(0, 100);
                host.AddChild(lightHtmlBox3);
                //fragment dom
                //create dom then to thie light box
                lightHtmlBox3.LoadHtmlDom(CreateSampleHtmlDoc());
            }
            //==================================================
            //textbox
            var textbox = new LayoutFarm.CustomWidgets.TextBox(400, 150, true);

            textbox.SetLocation(0, 200);
            host.AddChild(textbox);
            textbox.Focus();
        }
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            string appPath = host.ExecutablePath; //System.Windows.Forms.Application.ExecutablePath;
            int    pos     = appPath.IndexOf("\\bin\\");

            if (pos > -1)
            {
                string sub01 = appPath.Substring(0, pos);
                imgFolderPath = sub01 + "\\images";
            }
            //==================================================
            //html box
            var htmlBox = new HtmlBox(GetHtmlHost(host), 800, 600);

            host.AddChild(htmlBox);
            string html = "<html><head></head><body><div>OK1</div><div>3 Images</div><img src=\"sample01.png\"></img><img src=\"sample01.png\"></img><img src=\"sample01.png\"></img></body></html>";

            htmlBox.LoadHtmlString(html);
        }
Esempio n. 11
0
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            _appHost = host;//**
            string svgfile = "../Test8_HtmlRenderer.Demo/Samples/Svg/others/volcano3.svg";

            _vgVisualDoc = VgVisualDocHelper.CreateVgVisualDocFromFile(svgfile);
            //
            VgVisualElement vgVisualElem = _vgVisualDoc.VgRootElem;

            {
                UISprite wholeImgSprite = CreateUISpriteFromVgVisualElem(vgVisualElem);
            }
            //
            if (_vgVisualDoc.TryGetVgVisualElementById("path62_larva3", out VgVisualElement vgPart))
            {
                UISprite larvaSprite = CreateUISpriteFromVgVisualElem(vgPart, true);
                larvaSprite.SetTransformation(Affine.NewScaling(4));//scale
                larvaSprite.SetLocation(100, 100);
            }
        }
Esempio n. 12
0
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            _pcx = pcx;
            //html box
            _host = host;
            var loadingQueueMx = new LayoutFarm.ContentManagers.ImageLoadingQueueManager();

            loadingQueueMx.AskForImage += loadingQueue_AskForImg;

            HtmlBoxes.HtmlHost htmlHost = HtmlHostCreatorHelper.CreateHtmlHost(host,
                                                                               (s, e) => loadingQueueMx.AddRequestImage(e.ImageBinder),
                                                                               contentMx_LoadStyleSheet);

            //
            _htmlBox = new HtmlBox(htmlHost, 1000, 1000);
            //DEO _htmlBox.SetLocation(0, 10); //test
            host.AddChild(_htmlBox);
            if (_htmltext == null)
            {
                _htmltext = @"<html><head></head><body>NOT FOUND!</body></html>";
            }
            _htmlBox.LoadHtmlString(_htmltext);
        }
Esempio n. 13
0
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            _vgVisualDocHost = new VgVisualDocHost();
            _vgVisualDocHost.SetInvalidateDelegate(vgElem =>
            {
                //invalidate graphic here
            });

            _backBoard           = new BackDrawBoardUI(800, 600);
            _backBoard.BackColor = Color.White;
            host.AddChild(_backBoard);

            //load lion svg

            string svgfile = "../Test8_HtmlRenderer.Demo/Samples/Svg/others/tiger.svg";
            //string svgfile = "1f30b.svg";
            //string svgfile = "../Data/Svg/twemoji/1f30b.svg";
            //string svgfile = "../Data/1f30b.svg";
            //string svgfile = "../Data/Svg/twemoji/1f370.svg";

            VgVisualDoc     vgDocRoot = ReadSvgFile(svgfile);
            VgVisualElement vgVisElem = vgDocRoot.VgRootElem;
            var             uiSprite  = new UISprite(10, 10);

            uiSprite.LoadVg(vgVisElem);
            _backBoard.Add(uiSprite);


            //
            _redBox           = new LayoutFarm.CustomWidgets.Box(50, 50); //visual rect box
            _redBox.BackColor = Color.Red;
            _redBox.SetLocation(10, 10);
            //box1.dbugTag = 1;
            SetupActiveBoxProperties(_redBox);
            _backBoard.Add(_redBox);
            //----------------------


            //--------
            _rectBoxController = new CustomWidgets.RectBoxController();
            _rectBoxController.Init();
            _backBoard.Add(_rectBoxController);

            //foreach (var ui in rectBoxController.GetControllerIter())
            //{
            //    viewport.AddContent(ui);
            //}

            //--------
            var svgEvListener = new GeneralEventListener();

            //uiSprite.AttachExternalEventListener(svgEvListener);
            svgEvListener.MouseDown += (s, e) =>
            {
                //e.MouseCursorStyle = MouseCursorStyle.Pointer;
                ////--------------------------------------------
                //e.SetMouseCapture(rectBoxController.ControllerBoxMain);
                _rectBoxController.UpdateControllerBoxes(_redBox);
                _rectBoxController.Focus();
                //System.Console.WriteLine("click :" + (count++));
            };


            GeneralEventListener controllBoxMainListener = new GeneralEventListener();

            controllBoxMainListener.KeyDown += (s1, e1) =>
            {
                if (e1.KeyCode == UIKeys.C && e1.Ctrl)
                {
                    //test copy back image buffer from current rect area

#if DEBUG
                    //int left = rectBoxController.ControllerBoxMain.Left;
                    //int top = rectBoxController.ControllerBoxMain.Top;
                    //int width = rectBoxController.ControllerBoxMain.Width;
                    //int height = rectBoxController.ControllerBoxMain.Height;

                    //using (DrawBoard drawBoard = DrawBoardCreator.CreateNewDrawBoard(1, width, height))
                    //{

                    //    //create new draw board
                    //    drawBoard.OffsetCanvasOrigin(left, top);
                    //    _backBoard.CurrentPrimaryRenderElement.CustomDrawToThisCanvas(drawBoard, new Rectangle(0, 0, width, height));
                    //    using (var img2 = new PixelFarm.CpuBlit.ActualBitmap(width, height))
                    //    {
                    //        //copy content from drawboard to target image and save
                    //        drawBoard.RenderTo(img2, 0, 0, width, height);

                    //        PixelFarm.CpuBlit.Imaging.PngImageWriter.SaveImgBufferToPngFile(
                    //            PixelFarm.CpuBlit.ActualBitmap.GetBufferPtr(img2),
                    //            img2.Stride,
                    //            img2.Width,
                    //            img2.Height,
                    //            "d:\\WImageTest\\tiger.png");
                    //    }
                    //    //copy content from drawboard to target image and save
                    //}
#endif
                }
            };

            _rectBoxController.ControllerBoxMain.AttachExternalEventListener(controllBoxMainListener);
        }
Esempio n. 14
0
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            _appHost = host;//**

            //string svgfile = "../Test8_HtmlRenderer.Demo/Samples/Svg/others/cat_simple.svg";
            //string svgfile = "../Test8_HtmlRenderer.Demo/Samples/Svg/others/cat_complex.svg";
            //string svgfile = "../Test8_HtmlRenderer.Demo/Samples/Svg/others/lion.svg";
            string svgfile = "../Test8_HtmlRenderer.Demo/Samples/Svg/others/tiger.svg";

            //return VgVisualElemHelper.ReadSvgFile(svgfile);
            _rotationUI.AngleUpdated += _rotationUI_AngleUpdated;
            //string svgfile = "../Test8_HtmlRenderer.Demo/Samples/Svg/freepik/dog1.svg";
            //string svgfile = "1f30b.svg";
            //string svgfile = "../Data/Svg/twemoji/1f30b.svg";
            //string svgfile = "../Data/1f30b.svg";
            //string svgfile = "../Data/Svg/twemoji/1f370.svg";

            //_svgRenderVx = CreateTestRenderVx_FromSvg();
            //_svgRenderVx = CreateTestRenderVx_BasicShape();
            //_vgVisualElem = CreateTestRenderVx_FromImg("d:\\WImageTest\\alpha1.png");

            //string fontfile = "../Test8_HtmlRenderer.Demo/Samples/Fonts/SOV_Thanamas.ttf";
            //_vgVisualElem = VgVisualElemHelper.CreateVgVisualElementFromGlyph(fontfile, 256, 'a'); //create from glyph

            _vgVisualElem = CreateTestRenderVx_FromImg("d:\\WImageTest\\fenec.png");
            //_vgVisualElem = VgVisualElemHelper.ReadSvgFile(svgfile);


            //PixelFarm.CpuBlit.RectD org_rectD = _svgRenderVx.GetBounds();
            //_svgRenderVx = CreateEllipseVxs(org_rectD);

            PixelFarm.CpuBlit.VertexProcessing.Q1RectD org_rectD = _vgVisualElem.GetRectBounds();
            org_rectD.Offset(-org_rectD.Left, -org_rectD.Bottom);
            //
            _quadController.SetSrcRect(org_rectD.Left, org_rectD.Bottom, org_rectD.Right, org_rectD.Top);
            _quadController.SetDestQuad(
                org_rectD.Left, org_rectD.Top,
                org_rectD.Right, org_rectD.Top,
                org_rectD.Right, org_rectD.Bottom,
                org_rectD.Left, org_rectD.Bottom);
            //create control point
            _quadController.SetPolygonController(_quadPolygonController);
            _quadController.BuildControlBoxes();
            _quadController.UpdateTransformTarget += (s1, e1) =>
            {
                //after quadController is updated then
                //we use the coordTransformer to transform target uiSprite
                _uiSprite.SetTransformation(_quadController.GetCoordTransformer());
                _uiSprite.InvalidateGraphics();
                if (_quadController.Left != 0 || _quadController.Top != 0)
                {
                    float xxdiff = _quadController.Left - _uiSprite.Left;
                    float yydiff = _quadController.Top - _uiSprite.Top;

                    _uiSprite.SetLocation(_quadController.Left, _quadController.Top);
                    _uiSprite.InvalidateGraphics();


                    //_rotationUI.InvalidateGraphics();
                    //_rotationUI.SetLocation(
                    //    _rotationUI.Left + xxdiff,
                    //    _rotationUI.Top + yydiff);
                    //_rotationUI.InvalidateGraphics();

                    //_rotationControllerPointUI.InvalidateGraphics();
                    //_rotationControllerPointUI.SetPosition(
                    //   (int)(_rotationControllerPointUI.Left + xxdiff),
                    //   (int)(_rotationControllerPointUI.Top + yydiff));
                    //_rotationControllerPointUI.InvalidateGraphics();
                }
            };



            //_rectBoundsWidgetBox = new Box2(50, 50); //visual rect box
            //Color c = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
            //_rectBoundsWidgetBox.BackColor = Color.FromArgb(100, c);
            //_rectBoundsWidgetBox.SetLocation(10, 10);
            /////box1.dbugTag = 1;
            //SetupActiveBoxProperties(_rectBoundsWidgetBox);
            //host.AddChild(_rectBoundsWidgetBox);
            //_quadController.Visible = _quadPolygonController.Visible = false;
            //_rectBoxController.Init();

            PixelFarm.CpuBlit.VertexProcessing.Q1RectD svg_bounds = _vgVisualElem.GetRectBounds(); //bounds of graphic shape
            //ICoordTransformer tx = ((ICoordTransformer)_bilinearTx).MultiplyWith(scaleMat);
            ICoordTransformer tx = _quadController.GetCoordTransformer();

            //svgRenderVx._coordTx = tx;
            //svgRenderVx._coordTx = ((ICoordTransformer)_bilinearTx).MultiplyWith(scaleMat);
            //host.AddChild(_quadController);
            //host.AddChild(_quadPolygonController);
            //VgRenderVx svgRenderVx = CreateTestRenderVx();

            //test transform svgRenderVx

            _vgVisualElem.DisableBackingImage = true;


            //-----------------------------------------
            _uiSprite = new UISprite(10, 10); //init size = (10,10), location=(0,0)
            _uiSprite.DisableBmpCache = true;
            _uiSprite.LoadVg(_vgVisualElem);  //
            _uiSprite.SetTransformation(tx);  //set transformation
            host.AddChild(_uiSprite);
            //-----------------------------------------
            //host.AddChild(_quadController);
            host.AddChild(_quadPolygonController);
            {
                PointControllerBox center = new PointControllerBox(10, 10);
                PointControllerBox radius = new PointControllerBox(10, 10);
                host.AddChild(center);
                host.AddChild(radius);
                _rotationUI.AddControlPoints(center, radius);
            }

            _rotationUI.SetReferenceOwner(_quadController);

            double x_center = (svg_bounds.Left + svg_bounds.Right) / 2;
            double y_center = (svg_bounds.Top + svg_bounds.Bottom) / 2;

            _rotationUI.SetCenter(x_center, y_center);
            _rotationUI.SetRadius(x_center + 200, y_center);

            host.AddChild(_rotationUI);



            _quadController.Drag += (s1, ev) =>
            {
                _rotationUI.SetLocation(
                    _rotationUI.Left + ev.XDiff,
                    _rotationUI.Top + ev.YDiff);
            };


            var spriteEvListener = new GeneralEventListener();

            _uiSprite.AttachExternalEventListener(spriteEvListener);
            spriteEvListener.MouseMove += (s1, e1) =>
            {
                if (e1.IsDragging)
                {
                    //when drag on sprie


                    _uiSprite.InvalidateGraphics();
                    _uiSprite.SetLocation(
                        _uiSprite.Left + e1.XDiff,
                        _uiSprite.Top + e1.YDiff
                        );
                    //we also move quadController and _quadPolygonController
                    //
                    _quadController.InvalidateGraphics();
                    _quadController.SetLocation(
                        _quadController.Left + e1.XDiff,
                        _quadController.Top + e1.YDiff);
                    _quadController.InvalidateGraphics();
                    //
                    _quadPolygonController.InvalidateGraphics();
                    _quadPolygonController.SetLocation(
                        _quadPolygonController.Left + e1.XDiff,
                        _quadPolygonController.Top + e1.YDiff
                        );
                    _quadPolygonController.InvalidateGraphics();
                    //
                    _rotationUI.InvalidateGraphics();
                    _rotationUI.SetLocation(
                        _rotationUI.Left + e1.XDiff,
                        _rotationUI.Top + e1.YDiff);
                    _rotationUI.InvalidateGraphics();

                    //_rotationControllerPointUI.InvalidateGraphics();
                    //_rotationControllerPointUI.SetPosition(
                    //   _rotationControllerPointUI.Left + e1.XDiff,
                    //   _rotationControllerPointUI.Top + e1.YDiff);
                    //_rotationControllerPointUI.InvalidateGraphics();
                }
            };
            spriteEvListener.MouseDown += (s1, e1) =>
            {
                //mousedown on ui sprite
                //find exact part ...

                _quadController.BringToTopMost();
                _quadController.Visible        = true;
                _quadPolygonController.Visible = true;
                _quadController.Focus();

                // _polygonController.BringToTopMost();

                if (_hitTestOnSubPath)
                {
                    //find which part ...

                    double            e1_x = e1.X;
                    double            e1_y = e1.Y;
                    ICoordTransformer tx1  = _quadController.GetCoordTransformer();
                    if (tx1 != null)
                    {
                        //if the sprite is transformed before render
                        //we must invert x,y back to
                        ICoordTransformer tx1_inv = tx1.CreateInvert();
                        tx1_inv.Transform(ref e1_x, ref e1_y);
                    }

                    VgHitInfo hitInfo = _uiSprite.FindRenderElementAtPos((float)e1_x, (float)e1_y, true);

                    if (hitInfo.hitElem != null &&
                        hitInfo.hitElem.VxsPath != null)
                    {
                        PixelFarm.CpuBlit.VertexProcessing.Q1RectD bounds = hitInfo.copyOfVxs.GetBoundingRect();

                        _quadPolygonController.ClearControlPoints(); //clear old control points
                        _quadPolygonController.UpdateControlPoints(  //create new control points
                            hitInfo.copyOfVxs,
                            _uiSprite.ActualXOffset, _uiSprite.ActualYOffset, tx1);

                        ////move redbox and its controller
                        //_rectBoundsWidgetBox.SetLocationAndSize(
                        //    (int)(bounds.Left + _uiSprite.ActualXOffset), (int)(bounds.Top - bounds.Height + _uiSprite.ActualYOffset),
                        //    (int)bounds.Width, (int)bounds.Height);
                        ////_rectBoxController.UpdateControllerBoxes(_rectBoundsWidgetBox);

                        //_rectBoundsWidgetBox.Visible = true;
                        ////_rectBoxController.Visible = true;
                        //show bounds
                    }
                    else
                    {
                        //_rectBoundsWidgetBox.Visible = false;
                        // _rectBoxController.Visible = false;
                    }
                }
                else
                {
                    //hit on sprite
                    if (e1.Ctrl)
                    {
                        //test***
                        //
                        _uiSprite.GetElementBounds(out float left, out float top, out float right, out float bottom);
                        //
                        using (Tools.BorrowRect(out SimpleRect s))
                            using (Tools.BorrowVxs(out var v1))
                            {
                                s.SetRect(left - _uiSprite.ActualXOffset,
                                          bottom - _uiSprite.ActualYOffset,
                                          right - _uiSprite.ActualXOffset,
                                          top - _uiSprite.ActualYOffset);
                                s.MakeVxs(v1);
                                //_polygonController.UpdateControlPoints(v1.CreateTrim());
                            }
                    }
                    else
                    {
                        //_rectBoundsWidgetBox.SetTarget(_uiSprite);
                        //_rectBoundsWidgetBox.SetLocationAndSize(    //blue
                        //      (int)_uiSprite.Left, (int)_uiSprite.Top,
                        //      (int)_uiSprite.Width, (int)_uiSprite.Height);
                        ////_rectBoxController.SetTarget(_uiSprite);

                        ////_rectBoxController.UpdateControllerBoxes(_rectBoundsWidgetBox);  //control 4 corners
                        //_rectBoundsWidgetBox.Visible = true;
                        ////_rectBoxController.Visible = true;

                        //UpdateTransformedShape2();
                    }
                }
            };
        }
Esempio n. 15
0
        protected override void OnStart(AppHost host, IGameHTMLUI pcx)
        {
            _host = host;
            base.OnStart(host, pcx);

            _vgDocHost = new VgVisualDocHost();
            _vgDocHost.SetImgRequestDelgate(ImgBinderLoadImg);
            _vgDocHost.SetInvalidateDelegate(vgElem =>
            {
                //TODO
            });
            //
            {
                _backBoard = new BackDrawBoardUI(800, 600);
                _backBoard.SetLocation(0, 0);
                _backBoard.BackColor = PixelFarm.Drawing.Color.White;
                host.AddChild(_backBoard);
            }
            {
                _lstbox_svgFiles = new ListBox(200, 400);
                _lstbox_svgFiles.SetLocation(500, 20);
                host.AddChild(_lstbox_svgFiles);
                //
                _lstbox_svgFiles.ListItemMouseEvent += (s, e) =>
                {
                    if (_lstbox_svgFiles.SelectedIndex > -1)
                    {
                        if (_lstbox_svgFiles.GetItem(_lstbox_svgFiles.SelectedIndex).Tag is string filename)
                        {
                            ParseAndRenderSvgFile(filename);
                        }
                    }
                };

                //foreach (string file in System.IO.Directory.GetFiles("../Test8_HtmlRenderer.Demo/Samples/Svg/others", "*.svg"))
                //{
                //    ListItem listItem = new ListItem(200, 20);
                //    listItem.Text = System.IO.Path.GetFileName(file);
                //    listItem.Tag = file;
                //    _lstvw_svgFiles.AddItem(listItem);
                //}
                //foreach (string file in System.IO.Directory.GetFiles("../Test8_HtmlRenderer.Demo/Samples/Svg/freepik", "*.svg"))
                //{
                //    ListItem listItem = new ListItem(200, 20);
                //    listItem.Text = System.IO.Path.GetFileName(file);
                //    listItem.Tag = file;
                //    _lstvw_svgFiles.AddItem(listItem);
                //}
                //foreach (string file in System.IO.Directory.GetFiles("../../../HtmlRenderer.SomeTestResources/Svg/twemoji", "*.svg"))
                //{
                //    ListItem listItem = new ListItem(200, 20);
                //    listItem.Text = System.IO.Path.GetFileName(file);
                //    listItem.Tag = file;
                //    _lstvw_svgFiles.AddItem(listItem);
                //}


                //string[] allFiles = System.IO.Directory.GetFiles("../../../HtmlRenderer.SomeTestResources/Svg/noto_emoji", "*.svg");

                string rootSampleFolder = "..\\Test8_HtmlRenderer.Demo\\Samples\\Svg\\others";

                string[] allFiles = System.IO.Directory.GetFiles(rootSampleFolder, "*.svg");
                int      i        = 0;
                int      lim      = Math.Min(allFiles.Length, 150);

                for (; i < lim; ++i)
                {
                    string   file     = allFiles[i];
                    ListItem listItem = new ListItem(200, 20);
                    listItem.Text = System.IO.Path.GetFileName(file);
                    listItem.Tag  = file;
                    _lstbox_svgFiles.AddItem(listItem);
                }
            }
        }