コード例 #1
0
        public IUIEventListener CreateEventListener()
        {
            //create new event listener
            var eventListener = new GeneralEventListener();

            return(eventListener);
        }
コード例 #2
0
        public bool AttachEventListener(IUIEventListener uiEventListener)
        {
            GeneralEventListener genEventListener = uiEventListener as GeneralEventListener;

            if (genEventListener != null)
            {
                genEventListener.uiElement = uiElem;
                uiElem.AttachExternalEventListener(genEventListener);
            }
            return(false);
        }
コード例 #3
0
ファイル: Boxes_with_Beh.cs プロジェクト: brezza92/PixelFarm
        protected override void OnStart(AppHost host)
        {
            int x_pos = 0;

            GeneralEventListener evListener = new GeneralEventListener();

            evListener.MouseEnter += (s, e) =>
            {
                IUIEventListener             ctx = e.CurrentContextElement;
                LayoutFarm.CustomWidgets.Box box = (LayoutFarm.CustomWidgets.Box)ctx;
                box.BackColor = Color.Red;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_enter:" + box.dbugId);
#endif
            };
            evListener.MouseLeave += (s, e) =>
            {
                IUIEventListener             ctx = e.CurrentContextElement;
                LayoutFarm.CustomWidgets.Box box = (LayoutFarm.CustomWidgets.Box)ctx;
                box.BackColor = Color.Blue;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_leave:" + box.dbugId);
#endif
            };

            for (int i = 0; i < 10; ++i)
            {
                var sampleButton = new LayoutFarm.CustomWidgets.Box(30, 30);
                sampleButton.BackColor = Color.Blue;
                sampleButton.SetLocation(x_pos, 10);
                sampleButton.AttachExternalEventListener(evListener);

                host.AddChild(sampleButton);

                x_pos += 30 + 5;
            }
        }
コード例 #4
0
ファイル: 9.4_SvgParts.cs プロジェクト: ywscr/HtmlRenderer
        UISprite CreateUISpriteFromVgVisualElem(VgVisualElement vgVisualElem, bool wrapWithVgVisualUse = false)
        {
            if (wrapWithVgVisualUse)
            {
                //then we create a 'svg use' element
                //and wrap the original vgVisualElement
                vgVisualElem = _vgVisualDoc.CreateVgUseVisualElement(vgVisualElem);
            }

            PixelFarm.CpuBlit.VertexProcessing.Q1RectD org_rectD = vgVisualElem.GetRectBounds();
            org_rectD.Offset(-org_rectD.Left, -org_rectD.Bottom);
            vgVisualElem.DisableBackingImage = true;
            //-----------------------------------------
            UISprite uiSprite = new UISprite(10, 10); //init size = (10,10), location=(0,0)

            uiSprite.DisableBmpCache = true;



            uiSprite.LoadVg(vgVisualElem);//



            _appHost.AddChild(uiSprite);

            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);
                }
            };
            spriteEvListener.MouseDown += (s1, e1) =>
            {
                if (_hitTestOnSubPath)
                {
                    //find which part ...
                    VgHitInfo hitInfo = uiSprite.FindRenderElementAtPos(e1.X, e1.Y, true);

                    if (hitInfo.hitElem != null &&
                        hitInfo.hitElem.VxsPath != null)
                    {
                        //PixelFarm.CpuBlit.RectD bounds = hitInfo.copyOfVxs.GetBoundingRect();
                    }
                    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);
                                //TODO: review here
                                //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();
                    }
                }
            };

            return(uiSprite);
        }
コード例 #5
0
        protected override void OnStart(AppHost host)
        {
            _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");

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

            PixelFarm.CpuBlit.RectD 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.InvalidateOuterGraphics();
                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.InvalidateOuterGraphics();


                    //_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.RectD 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);
            _rotationUI.SetCenter(svg_bounds.XCenter, svg_bounds.YCenter);
            _rotationUI.SetRadius(svg_bounds.XCenter + 200, svg_bounds.YCenter);
            host.AddChild(_rotationUI);



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

            var spriteEvListener = new GeneralEventListener();

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


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

                    _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 += 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 ...
                    VgHitInfo hitInfo = _uiSprite.FindRenderElementAtPos(e1.X, e1.Y, true);

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

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

                        ////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 (VectorToolBox.Borrow(out SimpleRect s))
                            using (VxsTemp.Borrow(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();
                    }
                }
            };
        }
コード例 #6
0
        protected override void OnStartDemo(SampleViewport viewport)
        {
            PaintLab.Svg.SvgParser parser = new SvgParser();
            _backBoard           = new BackDrawBoardUI(400, 400);
            _backBoard.BackColor = Color.White;
            viewport.AddContent(_backBoard);



            box1           = new LayoutFarm.CustomWidgets.SimpleBox(50, 50);
            box1.BackColor = Color.Red;
            box1.SetLocation(10, 10);
            //box1.dbugTag = 1;
            SetupActiveBoxProperties(box1);
            _backBoard.AddChild(box1);

            //----------------------

            //load lion svg
            string file       = @"d:\\WImageTest\\lion.svg";
            string svgContent = System.IO.File.ReadAllText(file);

            WebLexer.TextSnapshot textSnapshot = new WebLexer.TextSnapshot(svgContent);
            parser.ParseDocument(textSnapshot);
            //
            SvgRenderVx svgRenderVx = parser.GetResultAsRenderVx();
            var         uiSprite    = new UISprite(10, 10);

            uiSprite.LoadSvg(svgRenderVx);
            _backBoard.AddChild(uiSprite);
            //--------
            rectBoxController.Init();
            //------------
            viewport.AddContent(rectBoxController);

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

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

            uiSprite.AttachExternalEventListener(evListener);


            evListener.MouseDown += (e) =>
            {
                //e.MouseCursorStyle = MouseCursorStyle.Pointer;
                ////--------------------------------------------
                //e.SetMouseCapture(rectBoxController.ControllerBoxMain);
                rectBoxController.UpdateControllerBoxes(box1);
                rectBoxController.Focus();
                //System.Console.WriteLine("click :" + (count++));
            };
            rectBoxController.ControllerBoxMain.KeyDown += (s1, e1) =>
            {
                if (e1.Ctrl && e1.KeyCode == UIKeys.X)
                {
                    //test copy back image buffer from current rect area

#if DEBUG
                    //test save some area
                    int w = rectBoxController.ControllerBoxMain.Width;
                    int h = rectBoxController.ControllerBoxMain.Height;

                    using (DrawBoard gdiDrawBoard = DrawBoardCreator.CreateNewDrawBoard(1, w, h))
                    {
                        gdiDrawBoard.OffsetCanvasOrigin(rectBoxController.ControllerBoxMain.Left, rectBoxController.ControllerBoxMain.Top);
                        _backBoard.CurrentPrimaryRenderElement.CustomDrawToThisCanvas(gdiDrawBoard, new Rectangle(0, 0, w, h));
                        var img2 = new ActualImage(w, h);
                        //copy content from drawboard to target image and save
                        gdiDrawBoard.RenderTo(img2, 0, 0, w, h);

                        img2.dbugSaveToPngFile("d:\\WImageTest\\ddd001.png");
                    }
#endif
                }
            };
        }
コード例 #7
0
ファイル: 9.1_SvgTiger.cs プロジェクト: profK/HtmlRenderer
        protected override void OnStart(AppHost host)
        {
            _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.AddChild(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.AddChild(_redBox);
            //----------------------


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

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

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

            //uiSprite.AttachExternalEventListener(svgEvListener);
            svgEvListener.MouseDown += (e) =>
            {
                //e.MouseCursorStyle = MouseCursorStyle.Pointer;
                ////--------------------------------------------
                //e.SetMouseCapture(rectBoxController.ControllerBoxMain);
                _rectBoxController.UpdateControllerBoxes(_redBox);
                _rectBoxController.Focus();
                //System.Console.WriteLine("click :" + (count++));
            };
            _rectBoxController.ControllerBoxMain.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
                }
            };
        }
コード例 #8
0
        protected override void OnStart(AppHost host)
        {
            _host      = host;
            _vgVisElem = VgVisualDocHelper.CreateVgVisualDocFromFile(@"Samples\lion.svg").VgRootElem;
            _mySprite  = new MyTestSprite(_vgVisElem);
            var evListener = new GeneralEventListener();

            evListener.MouseDown += e =>
            {
                if (e.Button == UIMouseButtons.Right)
                {
                    VgVisualElement foundE = _mySprite.HitTest(e.X, e.Y, true);
                    if (foundE != null)
                    {
                        foundE.VisualSpec.FillColor = Color.Red;
                        _mySprite.InvalidateLayout();
                    }
                }
            };
            evListener.MouseMove += e =>
            {
                if (e.Button == UIMouseButtons.Left && e.IsDragging)
                {
                    if (e.Ctrl)
                    {
                        //TODO:
                        //classic Agg's move and rotate
                    }
                    else
                    {   //just move
                        _mySprite.SetLocation(_mySprite.X + e.XDiff, _mySprite.Y + e.YDiff);
                    }
                }
            };

            _mySprite.AttachExternalEventListener(evListener);

            host.AddChild(_mySprite);



            ////
            //var textbox = new LayoutFarm.CustomWidgets.TextBox(100, 30, false);
            //var textSpanStyle = new Text.TextSpanStyle();

            ////test with various font style
            //textSpanStyle.FontInfo = new PixelFarm.Drawing.RequestFont("tahoma", 18);
            //textSpanStyle.FontColor = new PixelFarm.Drawing.Color(255, 0, 0);
            ////set default style
            //textbox.DefaultSpanStyle = textSpanStyle;

            //host.AddChild(textbox);


            //var box1 = new LayoutFarm.CustomWidgets.Box(50, 50);
            //box1.BackColor = Color.Red;
            //box1.SetLocation(10, 10);
            //host.AddChild(box1);
            ////--------------------------------
            //var box2 = new LayoutFarm.CustomWidgets.Box(30, 30);
            //box2.SetLocation(50, 50);
            //host.AddChild(box2);
            ////1. mouse down
            //box1.MouseDown += (s, e) =>
            //{
            //    box1.BackColor = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
            //    box2.Visible = false;
            //};
            //box1.MouseUp += (s, e) =>
            //{
            //    box1.BackColor = Color.Red;
            //    box2.Visible = true;
            //};
        }
コード例 #9
0
        protected override void OnStartDemo(SampleViewport viewport)
        {
            SvgPart     svgPart = new SvgPart(SvgRenderVxKind.Path);
            VertexStore vxs     = new VertexStore();

            vxs.AddMoveTo(100, 20);
            vxs.AddLineTo(150, 50);
            vxs.AddLineTo(110, 80);
            vxs.AddCloseFigure();
            //-------------------------------------------
            svgPart.SetVxsAsOriginal(vxs);
            svgPart.FillColor = Color.Red;
            SvgRenderVx svgRenderVx = new SvgRenderVx(new SvgPart[] { svgPart });

            svgRenderVx.DisableBackingImage = true;


            var uiSprite = new UISprite(10, 10); //init size = (10,10), location=(0,0)

            uiSprite.LoadSvg(svgRenderVx);
            viewport.AddContent(uiSprite);

            var spriteEvListener = new GeneralEventListener();

            uiSprite.AttachExternalEventListener(spriteEvListener);



            //box1 = new LayoutFarm.CustomWidgets.SimpleBox(50, 50);
            //box1.BackColor = Color.Red;
            //box1.SetLocation(10, 10);
            ////box1.dbugTag = 1;
            //SetupActiveBoxProperties(box1);
            //viewport.AddContent(box1);
            //--------
            rectBoxController.Init();
            //polygonController.Visible = false;
            viewport.AddContent(polygonController);
            //-------------------------------------------
            viewport.AddContent(rectBoxController);

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

            spriteEvListener.MouseDown += e1 =>
            {
                //mousedown on ui sprite
                polygonController.SetPosition((int)uiSprite.Left, (int)uiSprite.Top);
                polygonController.SetTargetUISprite(uiSprite);
                polygonController.UpdateControlPoints(svgPart);
            };
            spriteEvListener.MouseMove += e1 =>
            {
                if (e1.IsDragging)
                {
                    //drag event on uisprite

                    int left = (int)uiSprite.Left;
                    int top  = (int)uiSprite.Top;

                    int new_left = left + e1.DiffCapturedX;
                    int new_top  = top + e1.DiffCapturedY;
                    uiSprite.SetLocation(new_left, new_top);
                    //-----
                    //also update controller position
                    polygonController.SetPosition(new_left, new_top);
                }
            };
        }