Ejemplo n.º 1
0
        protected override void OnStart(AppHost host)
        {
            //simple textbox
            var textbox       = new LayoutFarm.CustomWidgets.TextBox(100, 30, false);
            var textSpanStyle = new TextEditing.TextSpanStyle()
            {
                ReqFont   = new PixelFarm.Drawing.RequestFont("tahoma", 18),
                FontColor = new PixelFarm.Drawing.Color(255, 0, 0)
            };

            //test with various font style
            //set default style
            textbox.DefaultSpanStyle = textSpanStyle;
            //
            host.AddChild(textbox);


            //--------------
            //mask text box
            var maskTextBox    = new LayoutFarm.CustomWidgets.MaskTextBox(100, 30);
            var textSpanStyle2 = new TextEditing.TextSpanStyle()
            {
                ReqFont   = new PixelFarm.Drawing.RequestFont("tahoma", 18),
                FontColor = PixelFarm.Drawing.Color.Black
            };

            maskTextBox.SetLocation(0, 40);
            host.AddChild(maskTextBox);
        }
Ejemplo n.º 2
0
        protected override void OnStart(AppHost host)
        {
            ImageBinder imgBinder = host.LoadImageAndBind("../Data/imgs/favorites32.png");

            for (int i = 0; i < 100; ++i)
            {
                //share 1 img binder with multiple img boxes
                var imgBox = new CustomWidgets.ImageBox(
                    imgBinder.Width,
                    imgBinder.Height);

                imgBox.ImageBinder = imgBinder;
                imgBox.SetLocation(i * 32, 20);
                imgBox.MouseDown += (s, e) =>
                {
                    //test start animation
                    int nsteps = 40;
                    UIPlatform.RegisterTimerTask(20, timer =>
                    {
                        imgBox.SetLocation(imgBox.Left, imgBox.Top + 10);
                        nsteps--;
                        if (nsteps <= 0)
                        {
                            timer.Remove();
                        }
                    });
                };
                host.AddChild(imgBox);
            }
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        void TestSimplePlot1(AppHost host)
        {
            //------------
            //create sample data
            //1. basic data=> a list of (x,y) point

            List <PointF> pointList = new List <PointF>(10);

            pointList.Add(new PointF(10 * 3, 20 * 3));
            pointList.Add(new PointF(10 * 3, 80 * 3));
            pointList.Add(new PointF(15 * 3, 30 * 3));
            pointList.Add(new PointF(18 * 3, 40 * 3));
            pointList.Add(new PointF(20 * 3, 20 * 3));
            pointList.Add(new PointF(25 * 3, 25 * 3));
            pointList.Add(new PointF(30 * 3, 10 * 3));

            //2. from data create a presentation of that data



            int            j         = pointList.Count;
            List <PlotBox> plotBoxes = new List <PlotBox>(j);

            for (int i = 0; i < j; ++i)
            {
                PlotBox pt   = new PlotBox(5, 5);
                PointF  data = pointList[i];
                pt.SetLocation((int)data.X, _chartHeight - (int)data.Y); //invertY
                pt.BackColor = Color.Red;

                plotBoxes.Add(pt);
                host.AddChild(pt);
            }


            //3. create connected line between each plotbox
            //...

            for (int i = 0; i < j - 1; ++i)
            {
                PlotBox  p0   = plotBoxes[i];
                PlotBox  p1   = plotBoxes[i + 1];
                PlotLine line = new PlotLine(p0, p1);
                host.AddChild(line);
            }
        }
Ejemplo n.º 5
0
 void CreateHsvVarBoxes(AppHost host, int x, int y)
 {
     _hsv_varBoxes = new Box[9];
     for (int i = 0; i < 9; ++i)
     {
         Box hsv_varBox = new Box(40, 40);
         hsv_varBox.SetLocation(x + (i * 40), y);
         _hsv_varBoxes[i] = hsv_varBox;
         host.AddChild(hsv_varBox);
     }
 }
Ejemplo n.º 6
0
 void CreateSwatchBoxes(AppHost host, int x, int y)
 {
     _swatch_Boxes = new Box[6];
     for (int i = 0; i < 6; ++i)
     {
         Box swatchBox = new Box(40, 40);
         swatchBox.SetLocation(x + (i * 40), y);
         _swatch_Boxes[i] = swatchBox;
         host.AddChild(swatchBox);
     }
 }
Ejemplo n.º 7
0
 void CreateRBGVarBoxes(AppHost host, int x, int y)
 {
     _rgb_varBoxes = new Box[7];
     for (int i = 0; i < 7; ++i)
     {
         Box rgb_varBox = new Box(40, 40);
         rgb_varBox.SetLocation(x + (i * 40), y);
         _rgb_varBoxes[i] = rgb_varBox;
         host.AddChild(rgb_varBox);
     }
 }
Ejemplo n.º 8
0
        protected override void OnStart(AppHost host)
        {
            var sampleButton = new LayoutFarm.CustomWidgets.Box(100, _chartHeight);

            host.AddChild(sampleButton);
            int count = 0;

            sampleButton.MouseDown += new EventHandler <UIMouseEventArgs>((s, e2) =>
            {
                Console.WriteLine("click :" + (count++));
            });

            TestSimplePlot1(host);
        }
Ejemplo n.º 9
0
        protected override void OnStart(AppHost host)
        {
            //html box
            _host    = host;
            _painter = (GLPainter)host.GetPainter();


            var loadingQueueMx = new LayoutFarm.ContentManagers.ImageLoadingQueueManager();

            loadingQueueMx.AskForImage += loadingQueue_AskForImg;

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

            //
            _htmlBox = new HtmlBox(htmlHost, 1024, 800);
            _htmlBox.SetLocation(0, 300); //test
            _rootgfx = host.GetRootGraphics();
            _rootE   = _htmlBox.GetPrimaryRenderElement(_rootgfx);

            _drawBoard = host.GetDrawBoard();

            host.AddChild(_htmlBox);


            //-------

            _htmltext = @"<html>
                    <head>
                    <style> 
                        .myfont1{font-size:30pt;background-color:yellow}
                        .myfont2{font-size:24pt;background-color:rgb(255,215,0)}
                    </style>
                    </head>
                    <body>
                           <div class='myfont1'>Hello</div>
                           <div class='myfont2'>... from HtmlRenderer</div>
                    </body>        
            </html>";

            //if (_htmltext == null)
            //{
            //    _htmltext = @"<html><head></head><body>NOT FOUND!</body></html>";
            //}
            _htmlBox.LoadHtmlString(_htmltext);
        }
Ejemplo n.º 10
0
        protected override void OnStart(AppHost host)
        {
            _host = host;
            base.OnStart(host);

            _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);
                }
            }
        }
Ejemplo n.º 11
0
        protected override void OnStart(AppHost host)
        {
            //----------------------------------------------------------------
            {
                var slideBox = new LayoutFarm.CustomWidgets.SliderBox(15, 200);
                slideBox.SetLocation(10, 400);
                slideBox.MinValue    = 0;
                slideBox.MaxValue    = 100;
                slideBox.SmallChange = 50;
                host.AddChild(slideBox);
                slideBox.ScrollValue = 150;
            }
            //----------------------------------------------------------------


            //----------------------------------------------------------------
            {
                var scbar = new LayoutFarm.CustomWidgets.ScrollBar(15, 200);
                scbar.SetLocation(10, 10);
                scbar.MinValue    = 0;
                scbar.MaxValue    = 100;
                scbar.SmallChange = 50;
                scbar.ScrollValue = 150;
                host.AddChild(scbar);
            }
            //----------------------------------------------------------------
            {
                var scbar = new LayoutFarm.CustomWidgets.ScrollBar(15, 200);
                scbar.SetLocation(30, 10);
                scbar.MinValue    = 0;
                scbar.MaxValue    = 100;
                scbar.SmallChange = 25;
                host.AddChild(scbar);
            }
            //----------------------------------------------------------------
            {
                var scbar = new LayoutFarm.CustomWidgets.ScrollBar(15, 200);
                scbar.SetLocation(50, 10);
                scbar.MinValue    = 0;
                scbar.MaxValue    = 1000;
                scbar.SmallChange = 100;
                host.AddChild(scbar);
            }
            //-------------------------------------
            {
                //horizontal scrollbar
                var scbar = new LayoutFarm.CustomWidgets.ScrollBar(200, 15);
                scbar.ScrollBarType = CustomWidgets.ScrollBarType.Horizontal;
                scbar.SetLocation(80, 10);
                scbar.MinValue    = 0;
                scbar.MaxValue    = 100;
                scbar.SmallChange = 50;
                host.AddChild(scbar);
            }
            {
                //horizontal scrollbar
                var scbar = new LayoutFarm.CustomWidgets.ScrollBar(200, 15);
                scbar.ScrollBarType = CustomWidgets.ScrollBarType.Horizontal;
                scbar.SetLocation(80, 40);
                scbar.MinValue    = 0;
                scbar.MaxValue    = 100;
                scbar.SmallChange = 25;
                host.AddChild(scbar);
            }

            {
                //horizontal scrollbar
                var scbar = new LayoutFarm.CustomWidgets.ScrollBar(200, 15);
                scbar.ScrollBarType = CustomWidgets.ScrollBarType.Horizontal;
                scbar.SetLocation(80, 80);
                scbar.MinValue    = 0;
                scbar.MaxValue    = 1000;
                scbar.SmallChange = 100;
                host.AddChild(scbar);
            }
        }
Ejemplo n.º 12
0
        protected override void OnStart(AppHost host)
        {
            _colorMatch = new ColorMatch();
            _colorMatch.VariationsRGB = new RGB[7];
            _colorMatch.VariationsHSV = new RGB[9];
            _blenderAlgo = _colorMatch.Algorithms[0];
            //

            {
                _lstbox_blendAlgo = new ListBox(200, 400);
                _lstbox_blendAlgo.SetLocation(500, 20);
                host.AddChild(_lstbox_blendAlgo);
                _lstbox_blendAlgo.ListItemMouseEvent += (s, e) =>
                {
                    if (_lstbox_blendAlgo.SelectedIndex > -1)
                    {
                        _blenderAlgo = _colorMatch.Algorithms[_lstbox_blendAlgo.SelectedIndex];
                        UpdateAllComponents();
                    }
                };

                //add item
                foreach (IAlgorithm algo in _colorMatch.Algorithms)
                {
                    ListItem listItem = new ListItem(200, 20);
                    listItem.Text = algo.GetType().Name;
                    listItem.Tag  = algo;
                    _lstbox_blendAlgo.AddItem(listItem);
                }
            }

            //start RGB value
            byte r_value = 200;
            byte g_value = 46;
            byte b_value = 49;


            CreateRBGVarBoxes(host, 20, 250);
            CreateHsvVarBoxes(host, 20, 300);
            CreateSwatchBoxes(host, 20, 350);

            {
                _pure_rgbBox           = new Box(50, 50);
                _pure_rgbBox.BackColor = new PixelFarm.Drawing.Color(
                    (byte)r_value,
                    (byte)b_value,
                    (byte)g_value);
                _pure_rgbBox.SetLocation(0, 0);
                host.AddChild(_pure_rgbBox);
            }

            //R
            {
                CreateRBGScrollBarAndSampleColorBox(80, 80, out _r_sc, out _r_sampleBox, (n_scrollBar, n_sampleBox) =>
                {
                    if (_component_ready)
                    {
                        n_sampleBox.BackColor = new PixelFarm.Drawing.Color((byte)(n_scrollBar.ScrollValue / 10), 0, 0);
                        UpdateAllComponents();
                    }
                });
                host.AddChild(_r_sc);
                host.AddChild(_r_sampleBox);
            }
            //G
            {
                CreateRBGScrollBarAndSampleColorBox(80, 120, out _g_sc, out _g_sampleBox, (n_scrollBar, n_sampleBox) =>
                {
                    if (_component_ready)
                    {
                        n_sampleBox.BackColor = new PixelFarm.Drawing.Color(0, (byte)(n_scrollBar.ScrollValue / 10), 0);
                        UpdateAllComponents();
                    }
                });
                host.AddChild(_g_sc);
                host.AddChild(_g_sampleBox);
            }
            //B
            {
                CreateRBGScrollBarAndSampleColorBox(80, 160, out _b_sc, out _b_sampleBox, (n_scrollBar, n_sampleBox) =>
                {
                    if (_component_ready)
                    {
                        n_sampleBox.BackColor = new PixelFarm.Drawing.Color(0, 0, (byte)(n_scrollBar.ScrollValue / 10));
                        UpdateAllComponents();
                    }
                });
                host.AddChild(_b_sc);
                host.AddChild(_b_sampleBox);
            }
            _component_ready = true;

            //---------
            CreateChromaTestButtons(host, 20, 450);
        }
Ejemplo n.º 13
0
        void CreateChromaTestButtons(AppHost host, int x, int y)
        {
            void ShowColorBoxs(Box colorBoxPanel, PixelFarm.Drawing.Color[] colors)
            {
                //nested method
                colorBoxPanel.ClearChildren();
                for (int i = 0; i < colors.Length; ++i)
                {
                    Box colorBox = new Box(30, 30);

                    PixelFarm.Drawing.Color c = colors[i];
                    colorBox.BackColor = new PixelFarm.Drawing.Color(c.R, c.G, c.B);
                    colorBoxPanel.Add(colorBox);
                }

                UI.LayoutUpdateArgs updateArgs = new UI.LayoutUpdateArgs();

                colorBoxPanel.PerformContentLayout(updateArgs);
            }

            Box colorPanel = new Box(200, 40);

            colorPanel.ContentLayoutKind = BoxContentLayoutKind.HorizontalStack;
            colorPanel.BackColor         = PixelFarm.Drawing.Color.White;
            colorPanel.SetLocation(x, y);
            host.AddChild(colorPanel);

            y += colorPanel.Height;

            //test1...
            var buttonBeh = new UI.UIMouseBehaviour <Label, object>();

            buttonBeh.MouseMove += (s, e) =>
            {
                if (e.CurrentContextElement is Label lbl)
                {
                    lbl.BackColor = PixelFarm.Drawing.Color.Yellow;
                }
            };
            buttonBeh.MouseLeave += (s, e) =>
            {
                if (e.CurrentContextElement is Label lbl)
                {
                    lbl.BackColor = PixelFarm.Drawing.KnownColors.Gray;
                }
            };


            //----------------------------------
            {
                Label lblChromaDarken = new Label();
                lblChromaDarken.BackColor = PixelFarm.Drawing.KnownColors.Gray;
                lblChromaDarken.Text      = "Darken";
                lblChromaDarken.SetLocation(x, y);

                buttonBeh.AttachSharedBehaviorTo(lblChromaDarken);

                UI.GeneralEventListener evListener = new UI.GeneralEventListener();
                evListener.MouseDown += (s, e) =>
                {
                    PixelFarm.Drawing.Color color = PixelFarm.Drawing.KnownColors.DeepPink;
                    using (Tools.More.BorrowChromaTool(out var chroma))
                    {
                        chroma.SetColor(color);
                        PixelFarm.Drawing.Color[] colors = new[] {
                            color,
                            chroma.Darken(),
                            chroma.Darken(2),
                            chroma.Darken(2.6)
                        };
                        //present in the box
                        ShowColorBoxs(colorPanel, colors);
                    }
                };
                lblChromaDarken.AttachExternalEventListener(evListener);
                x += 50;

                host.AddChild(lblChromaDarken);
            }

            //----------------------------------
            {
                Label lblLighten = new Label();
                lblLighten.Text = "Brighten";
                buttonBeh.AttachSharedBehaviorTo(lblLighten);

                lblLighten.SetLocation(x, y);
                {
                    UI.GeneralEventListener evListener = new UI.GeneralEventListener();
                    evListener.MouseDown += (s, e) =>
                    {
                        PixelFarm.Drawing.Color color = PixelFarm.Drawing.KnownColors.DeepPink;
                        using (Tools.More.BorrowChromaTool(out var chroma))
                        {
                            chroma.SetColor(color);
                            PixelFarm.Drawing.Color[] colors = new[] {
                                color,
                                chroma.Brighten(),
                                chroma.Brighten(2),
                                chroma.Brighten(3)
                            };
                            //present in the box
                            ShowColorBoxs(colorPanel, colors);
                        }
                    };
                    lblLighten.AttachExternalEventListener(evListener);
                }
                x += lblLighten.Width + 5;

                host.AddChild(lblLighten);
            }
        }

        void CreateRBGVarBoxes(AppHost host, int x, int y)
        {
            _rgb_varBoxes = new Box[7];
            for (int i = 0; i < 7; ++i)
            {
                Box rgb_varBox = new Box(40, 40);
                rgb_varBox.SetLocation(x + (i * 40), y);
                _rgb_varBoxes[i] = rgb_varBox;
                host.AddChild(rgb_varBox);
            }
        }

        void CreateSwatchBoxes(AppHost host, int x, int y)
        {
            _swatch_Boxes = new Box[6];
            for (int i = 0; i < 6; ++i)
            {
                Box swatchBox = new Box(40, 40);
                swatchBox.SetLocation(x + (i * 40), y);
                _swatch_Boxes[i] = swatchBox;
                host.AddChild(swatchBox);
            }
        }

        void CreateHsvVarBoxes(AppHost host, int x, int y)
        {
            _hsv_varBoxes = new Box[9];
            for (int i = 0; i < 9; ++i)
            {
                Box hsv_varBox = new Box(40, 40);
                hsv_varBox.SetLocation(x + (i * 40), y);
                _hsv_varBoxes[i] = hsv_varBox;
                host.AddChild(hsv_varBox);
            }
        }

        void CreateRBGScrollBarAndSampleColorBox(
            int x, int y,
            out ScrollBar scBar,
            out Box sampleBox,
            Action <ScrollBar, Box> pairAction
            )
        {
            //Action<>
            //horizontal scrollbar
            scBar = new LayoutFarm.CustomWidgets.ScrollBar(300, 15);

            //TODO: add mx with layout engine
            scBar.ScrollBarType = CustomWidgets.ScrollBarType.Horizontal;
            scBar.SetLocation(x, y);
            scBar.MinValue    = 0;
            scBar.MaxValue    = 255 * 10;
            scBar.SmallChange = 1;
            //
            scBar.ScrollValue = 0; //init
                                   //
            sampleBox = new Box(30, 30);
            sampleBox.SetLocation(x + 350, y);
            //
            var n_scBar     = scBar;
            var n_sampleBox = sampleBox;

            scBar.SliderBox.UserScroll += (s, e) => pairAction(n_scBar, n_sampleBox);

            pairAction(n_scBar, n_sampleBox);
        }

        bool _component_ready = false;

        void UpdateAllComponents()
        {
            byte r = (byte)(_r_sc.ScrollValue / 10);
            byte g = (byte)(_g_sc.ScrollValue / 10);
            byte b = (byte)(_b_sc.ScrollValue / 10);

            _pure_rgbBox.BackColor = new PixelFarm.Drawing.Color(r, g, b);

            //the update ColorMatch
            _colorMatch.CurrentAlgorithm = _blenderAlgo;
            _colorMatch.CurrentRGB       = new RGB(r, g, b);
            _colorMatch.CurrentHSV       = _colorMatch.CurrentRGB.ToHSV();
            _colorMatch.CurrentRGB       = _colorMatch.CurrentHSV.ToRGB();//?
            _colorMatch.Update();
            //then present color match results
            //1. rgb variants
            for (int i = 0; i < 7; ++i)
            {
                _rgb_varBoxes[i].BackColor = _colorMatch.VariationsRGB[i].ToPixelFarmColor();
            }
            //2. hsv variants
            for (int i = 0; i < 9; ++i)
            {
                _hsv_varBoxes[i].BackColor = _colorMatch.VariationsHSV[i].ToPixelFarmColor();
            }
            //3. swatch box
            Blend blend = _colorMatch.CurrentBlend;

            for (int i = 0; i < 6; ++i)
            {
                _swatch_Boxes[i].BackColor = blend.Colors[i].ToRGB().ToPixelFarmColor();
            }
        }
    }