コード例 #1
0
        public ColorPickerPanel()
        {
            var colorProperty = new Property <ColorHSVA>(() => colorHSVA, c => colorHSVA = c);

            spectrum              = new Spectrum(colorProperty);
            spectrum.DragStarted += () => DragStarted?.Invoke();
            spectrum.Changed     += () => Changed?.Invoke();
            spectrum.DragEnded   += () => DragEnded?.Invoke();
            valueSlider           = new ValueSlider(colorProperty);
            alphaSlider           = new AlphaSlider(colorProperty);
            SetupSliderDragHandlers(valueSlider.Widget);
            SetupSliderDragHandlers(alphaSlider.Widget);
            Widget = new Widget
            {
                Padding = new Thickness(8),
                Layout  = new VBoxLayout {
                    Spacing = 8
                },
                Nodes =
                {
                    new Widget {
                        LayoutCell = new LayoutCell(Alignment.Center),
                        Layout     = new StackLayout(),
                        Nodes      =
                        {
                            spectrum.Widget
                        }
                    },
                    valueSlider.Widget,
                    alphaSlider.Widget,
                }
            };
            Widget.FocusScope = new KeyboardFocusScope(Widget);
        }
コード例 #2
0
ファイル: ColorPickerPanel.cs プロジェクト: aologos/Citrus
            void DrawControl()
            {
                int size = (int)Math.Floor(OuterRadius * 2);

                if (wasHueChanged)
                {
                    if (image == null)
                    {
                        image = new Color4[size * size];
                    }
                    for (int y = 0; y < size; ++y)
                    {
                        for (int x = 0; x < size; ++x)
                        {
                            var pick = Pick(size - x - 1, y);
                            if (pick.Area == Area.Outside)
                            {
                                image[y * size + x] = Color4.Transparent;
                            }
                            else if (pick.Area == Area.Wheel)
                            {
                                image[y * size + x] = new ColorHSVA(pick.H.Value, 1, 1).ToRGBA();
                            }
                            else
                            {
                                image[y * size + x] = new ColorHSVA(color.Value.H, pick.S.Value, pick.V.Value).ToRGBA();
                            }
                        }
                    }
                    texture.LoadImage(image, size, size);
                    wasHueChanged = false;
                }
                Renderer.DrawSprite(texture, Color4.White, Vector2.Zero, Vector2.One * size, new Vector2(1, 0), new Vector2(0, 1));
            }
コード例 #3
0
            public static ColorHSVA FromRGBA(Color4 rgb)
            {
                var c   = new ColorHSVA();
                int max = Math.Max(rgb.R, Math.Max(rgb.G, rgb.B));
                int min = Math.Min(rgb.R, Math.Min(rgb.G, rgb.B));

                c.H = GetHue(rgb);
                c.S = (max == 0) ? 0 : 1f - (1f * min / max);
                c.V = max / 255f;
                c.A = rgb.A / 255f;
                return(c);
            }