Beispiel #1
0
        public static HtmlBoxes.HtmlHost CreateHtmlHost(AppHost appHost,
                                                        EventHandler <ContentManagers.ImageRequestEventArgs> imageReqHandler,
                                                        EventHandler <ContentManagers.TextRequestEventArgs> textReq)
        {
            List <HtmlBoxes.HtmlVisualRoot> htmlVisualRootUpdateList = new List <HtmlBoxes.HtmlVisualRoot>();

            var config = new HtmlBoxes.HtmlHostCreationConfig()
            {
                RootGraphic = appHost.RootGfx,
                TextService = appHost.RootGfx.TextServices
            };

            //1.
            HtmlBoxes.HtmlHost htmlhost = new HtmlBoxes.HtmlHost(config);  //create html host with config
            appHost.RootGfx.ClearingBeforeRender += (s, e) =>
            {
                //
                htmlhost.ClearUpdateWaitingCssBoxes();
                //
                int j = htmlVisualRootUpdateList.Count;
                for (int i = 0; i < j; ++i)
                {
                    HtmlBoxes.HtmlVisualRoot htmlVisualRoot = htmlVisualRootUpdateList[i];
                    htmlVisualRoot.RefreshDomIfNeed();
                    htmlVisualRoot.IsInUpdateQueue = false;
                }
                htmlVisualRootUpdateList.Clear();
            };
            //2.
            htmlhost.RegisterCssBoxGenerator(new LayoutFarm.CustomWidgets.MyCustomCssBoxGenerator(htmlhost));
            //3.
            htmlhost.AttachEssentailHandlers(imageReqHandler, textReq);
            //4.
            htmlhost.SetHtmlVisualRootUpdateHandler(htmlVisualRoot =>
            {
                if (!htmlVisualRoot.IsInUpdateQueue)
                {
                    htmlVisualRoot.IsInUpdateQueue = true;
                    htmlVisualRootUpdateList.Add(htmlVisualRoot);
                }
            });

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

            if (PaintLab.Svg.VgResourceIO.VgImgIOHandler == null)
            {
                var imgLoadingQ = new ContentManagers.ImageLoadingQueueManager();
                imgLoadingQ.AskForImage += (s, e) =>
                {
                    //check loading policy here
                    //
                    e.SetResultImage(LoadImage(e.ImagSource));
                };
                PaintLab.Svg.VgResourceIO.VgImgIOHandler = (LayoutFarm.ImageBinder binder, PaintLab.Svg.VgVisualElement imgRun, object requestFrom) =>
                {
                    imgLoadingQ.AddRequestImage(binder);
                };
            }

            return(htmlhost);
        }
Beispiel #2
0
        protected override void OnStart(AppHost host)
        {
            _vgVisElem = VgVisualDocHelper.CreateVgVisualDocFromFile(@"Data\lion.svg").VgRootElem;
            _mySprite  = new MyTestSprite(_vgVisElem);
            var evListener = new GeneralEventListener();

            evListener.MouseDown += (s, e) =>
            {
                if (e.Buttons == UIMouseButtons.Right)
                {
                    //right click=> hit test and change fill color
                    VgVisualElement foundE = _mySprite.HitTest(e.X, e.Y, true);
                    if (foundE != null)
                    {
                        foundE.VisualSpec.FillColor = Color.Red;
                        _mySprite.InvalidateLayout();
                    }
                }
            };
            evListener.MouseDrag += (s, e) =>
            {
                if (e.Ctrl)
                {
                    //TODO:
                    //classic Agg's move and rotate
                }
                else
                {   //just move
                    _mySprite.SetLocation(_mySprite.Left + e.XDiff, _mySprite.Top + 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;
            //};
        }
        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
                }
            };
        }
        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");
            //_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();
                    }
                }
            };
        }
        protected override void OnStart(AppHost host)
        {
            //grid0
            {
                var gridView = new LayoutFarm.CustomWidgets.GridBox(100, 100);
                gridView.SetLocation(50, 50);
                gridView.BuildGrid(2, 4, CellSizeStyle.UniformCell);
                host.AddChild(gridView);
                gridView.MouseDown += (s1, e1) =>
                {
                };
            }
            //grid1
            {
                var gridView = new LayoutFarm.CustomWidgets.GridBox(100, 100);
                gridView.SetLocation(200, 50);
                gridView.BuildGrid(2, 4, CellSizeStyle.UniformCell);
                host.AddChild(gridView);
                var simpleButton = new LayoutFarm.CustomWidgets.Box(20, 20);
                simpleButton.BackColor = KnownColors.FromKnownColor(KnownColor.OliveDrab);
                gridView.SetCellContent(simpleButton, 1, 1);
                gridView.MouseDown += (s1, e1) =>
                {
                };

                simpleButton.MouseDown += (s1, e1) =>
                {
                    var box = (LayoutFarm.CustomWidgets.Box)s1;
                    box.BackColor = KnownColors.FromKnownColor(KnownColor.OrangeRed);
                };
            }
            ////-----
            //grid2
            {
                var gridView = new LayoutFarm.CustomWidgets.GridBox(200, 100);
                gridView.SetLocation(350, 50);
                gridView.BuildGrid(10, 8, CellSizeStyle.UniformCell);
                host.AddChild(gridView);
            }

            ////-----
            //grid3
            {
                var gridView = new LayoutFarm.CustomWidgets.GridBox(200, 100);
                gridView.SetLocation(50, 250);
                gridView.BuildGrid(10, 8, CellSizeStyle.UniformCell);
                host.AddChild(gridView);
            }


            ////-----
            //grid4
            //{
            //    var gridView = new LayoutFarm.CustomWidgets.GridView(800, 400);
            //    gridView.SetLocation(10, 10);
            //    gridView.HasSpecificHeight = true;
            //    gridView.HasSpecificWidth = true;
            //    gridView.NeedClipArea = true;
            //    gridView.BuildGrid(4, 4, CellSizeStyle.UniformCell);



            //    var gridBox = new LayoutFarm.CustomWidgets.GridBox(400, 200);
            //    gridBox.SetLocation(300, 250);
            //    gridBox.SetGridView(gridView);
            //    viewport.AddContent(gridBox);
            //    gridBox.PerformContentLayout();
            //}
            ////-----
            //grid5
            {
                var gridView = new LayoutFarm.CustomWidgets.GridBox(200, 100);
                gridView.SetLocation(50, 500);
                gridView.BuildGrid(10, 8, CellSizeStyle.UniformCell);
                host.AddChild(gridView);
            }

            {
                //grid 6
                var gridView = new LayoutFarm.CustomWidgets.GridBox(200, 100);
                //gridView.HasSpecificHeight = true; //if not set ,scroll bar will not show scroll button
                //gridView.HasSpecificWidth = true;//if not set ,scroll bar will not show scroll button

                gridView.SetLocation(300, 500);
                gridView.NeedClipArea = true;
                gridView.BuildGrid(100, 4, 5, 20);
                host.AddChild(gridView);

                //manual sc-bar
                var vscbar = new LayoutFarm.CustomWidgets.ScrollBar(15, 100);
                {
                    //add vrcbar for grid view
                    vscbar.SetLocation(gridView.Right + 10, gridView.Top);
                    vscbar.MinValue    = 0;
                    vscbar.MaxValue    = gridView.Height;
                    vscbar.SmallChange = 20;
                    host.AddChild(vscbar);

                    //add relation between viewpanel and scroll bar
                    var scRelation = new LayoutFarm.CustomWidgets.ScrollingRelation(vscbar.SliderBox, gridView);
                }
                //
                var hscbar = new LayoutFarm.CustomWidgets.ScrollBar(200, 15);
                {
                    //horizontal scrollbar
                    hscbar.ScrollBarType = CustomWidgets.ScrollBarType.Horizontal;
                    hscbar.SetLocation(gridView.Left, gridView.Bottom + 10);
                    hscbar.MinValue    = 0;
                    hscbar.MaxValue    = gridView.Width;
                    hscbar.SmallChange = 2;
                    host.AddChild(hscbar);
                    //add relation between viewpanel and scroll bar
                    var scRelation = new LayoutFarm.CustomWidgets.ScrollingRelation(hscbar.SliderBox, gridView);
                }

                //perform content layout again***
                //gridView.PerformContentLayout();
            }
        }
 protected override void OnStart(AppHost host)
 {
     //Test1(host);
     //Test2(host);
     Test3(host);
 }
        protected override void OnStart(AppHost host)
        {
            //SetupImageList(host);
            for (int i = 1; i < 5; ++i)
            {
                var textbox = new LayoutFarm.CustomWidgets.Box(30, 30);
                textbox.SetLocation(i * 40, i * 40);
                host.AddChild(textbox);
            }
            //--------------------
            //image box
            //load bitmap with gdi+
            ImageBinder imgBinder = host.LoadImageAndBind("../Data/imgs/favorites32.png");

            var imgBox = new CustomWidgets.ImageBox(imgBinder.Width, imgBinder.Height);

            imgBox.ImageBinder = imgBinder;
            host.AddChild(imgBox);
            //--------------------
            //checked box
            int boxHeight = 20;
            int boxY      = 50;

            //multiple select
            for (int i = 0; i < 4; ++i)
            {
                var statedBox = new LayoutFarm.CustomWidgets.CheckBox(20, boxHeight);
                statedBox.SetLocation(10, boxY);
                boxY += boxHeight + 5;
                host.AddChild(statedBox);
            }
            //-------------------------------------------------------------------------
            //single select
            boxY += 50;
            for (int i = 0; i < 4; ++i)
            {
                var statedBox = new LayoutFarm.CustomWidgets.CheckBox(20, boxHeight);
                statedBox.SetLocation(10, boxY);
                boxY += boxHeight + 5;
                host.AddChild(statedBox);
                statedBox.CheckChanged += (s, e) =>
                {
                    var selectedBox = (LayoutFarm.CustomWidgets.CheckBox)s;
                    if (selectedBox != _currentSingleCheckedBox)
                    {
                        if (_currentSingleCheckedBox != null)
                        {
                            _currentSingleCheckedBox.Checked = false;
                        }
                        _currentSingleCheckedBox = selectedBox;
                    }
                };
            }
            //-------------------------------------------------------------------
            //test canvas
            var canvasBox = new MyDrawingCanvas(300, 300);

            canvasBox.SetLocation(400, 150);
            host.AddChild(canvasBox);
            //-------------------------------------------------------------------
        }
        protected override void OnStart(AppHost host)
        {
            _background           = new Box(800, 600);
            _background.BackColor = Color.White;
            host.AddChild(_background);



            //---------------------------
            _vgVisElem = VgVisualDocHelper.CreateVgVisualDocFromFile(@"Samples\lion.svg").VgRootElem;
            _mySprite  = new MyTestSprite(_vgVisElem);
            //var evListener = new GeneralEventListener();
            //evListener.MouseDrag += (s, e) =>
            //{
            //    if (e.Ctrl)
            //    {
            //        //TODO:
            //        //classic Agg's move and rotate

            //    }
            //    else
            //    {   //just move
            //        _mySprite.SetLocation(_mySprite.Left + e.XDiff, _mySprite.Top + e.YDiff);
            //    }
            //};
            //_mySprite.AttachExternalEventListener(evListener);


            var rectBounds = _vgVisElem.GetRectBounds();

            _quadControl = new QuadWidgetControl();
            _quadControl.ShapeUpdated += _quadControl_ShapeUpdated;
            //
            _quadControl.SetupCorners(
                new Quad2f(
                    (float)rectBounds.Left,
                    (float)rectBounds.Bottom,
                    (float)rectBounds.Width,
                    (float)rectBounds.Height));

            _lionBounds = new RectangleF((float)rectBounds.Left,
                                         (float)rectBounds.Bottom,
                                         (float)rectBounds.Width,
                                         (float)rectBounds.Height);

            host.AddChild(_mySprite);
            host.AddChild(_quadControl);


            //--------------------
            _cmdBiliear = new Box(30, 30);
            _cmdBiliear.SetLocation(400, 20);
            _cmdBiliear.BackColor  = Color.Yellow;
            _cmdBiliear.MouseDown += (s, e) =>
            {
                if (_useBilinear)
                {
                    _cmdBiliear.BackColor = Color.Yellow;
                    _useBilinear          = false;
                }
                else
                {
                    _cmdBiliear.BackColor = Color.Red;
                    _useBilinear          = true;
                }
            };
            host.AddChild(_cmdBiliear);
        }
Beispiel #9
0
        protected override void OnStart(AppHost host)
        {
            int x_pos = 0;


            //mouse behavior for LayoutFarm.CustomWidgets.Box,
            //with special attachment state => MyButtonState


            var mouseBeh = new UIMouseBehaviour <LayoutFarm.CustomWidgets.Box, MyButtonState>();

            mouseBeh.MouseEnter += (s, e) =>
            {
                //s is a behaviour object that raise the event
                //not the the current context element
                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _mouseEnterState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_enter:" + box.dbugId);
#endif
            };
            mouseBeh.MouseLeave += (s, e) =>
            {
                //s is a behaviour object that raise the event
                //not the the current context element

                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _normalState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_leave:" + box.dbugId);
#endif
            };
            mouseBeh.MouseHover += (s, e) =>
            {
                //b is a behaviour object that raise the event
                //not the the current context element

                LayoutFarm.CustomWidgets.Box box = s.Source;
                box.BackColor = _hoverState;
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_hover:" + box.dbugId);
#endif
            };
            mouseBeh.MousePress += (s, e) =>
            {
                //s is a behaviour object that raise the event
                //not the the current context element
                LayoutFarm.CustomWidgets.Box box = s.Source;
                Color back_color = box.BackColor;
                box.BackColor = new Color((byte)System.Math.Min(back_color.A + 10, 255), back_color.R, back_color.G, back_color.B);
#if DEBUG
                System.Diagnostics.Debug.WriteLine("mouse_press:" + box.dbugId);
#endif
            };
            mouseBeh.MouseDown += (s, e) =>
            {
                MyButtonState buttonState = s.State;
                if (buttonState != null)
                {
                    if (buttonState.ClickCount > 3)
                    {
                        s.Source.BackColor = Color.Magenta;
                    }
                    buttonState.ClickCount++;
                }
            };


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

                MyButtonState state = new MyButtonState();
                mouseBeh.AttachUniqueBehaviorTo(sampleButton, state);

                host.AddChild(sampleButton);

                x_pos += 30 + 5;
            }
        }
Beispiel #10
0
 protected sealed override void OnStart(AppHost host)
 {
     _appHost = host;
     OnInitializing();
 }