예제 #1
0
        void CreateRBGScrollBarAndSampleColorBox(
            int x, int y,
            out ScrollBar scBar,
            out SimpleBox sampleBox,
            SimpleAction <ScrollBar, SimpleBox> pairAction
            )
        {
            //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 SimpleBox(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);
        }
예제 #2
0
        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();
            }
        }
예제 #3
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();
            }
        }
    }