Exemple #1
0
 public Widget colorPickerSlider(TrackType trackType)
 {
     return(new ColorPickerSlider(
                trackType,
                currentHsvColor,
                (HSVColor color) =>
     {
         //UnityEngine.Debug.Log(color.toColor());
         setState(() => { currentHsvColor = color; });
         widget.onColorChanged(currentHsvColor.toColor());
     },
                displayThumbColor: widget.displayThumbColor,
                fullThumbColor: true
                ));
 }
Exemple #2
0
 Widget colorPickerSlider(TrackType trackType)
 {
     return(new ColorPickerSlider(
                trackType,
                currentHsvColor,
                (HSVColor color) =>
     {
         setState(() =>
         {
             currentHsvColor = color;
         });
         widget.onColorChanged(currentHsvColor.toColor());
     },
                displayThumbColor: widget.displayThumbColor
                ));
 }
Exemple #3
0
        void slideEvent(RenderBox getBox, BoxConstraints box, Offset globalPosition)
        {
            float localDx  = getBox.globalToLocal(globalPosition).dx - 15f;
            float progress = localDx.clamp(0f, box.maxWidth - 30f) / (box.maxWidth - 30f);

            switch (trackType)
            {
            case TrackType.hue:
                // 360 is the same as zero
                // if set to 360, sliding to end goes to zero
                onColorChanged(hsvColor.withHue(progress * 359));

                break;

            case TrackType.saturation:
                onColorChanged(hsvColor.withSaturation(progress));
                break;

            case TrackType.saturationForHSL:
                onColorChanged(Utils.hslToHsv(Utils.hsvToHsl(hsvColor).withSaturation(progress)));
                break;

            case TrackType.value:
                onColorChanged(hsvColor.withValue(progress));
                break;

            case TrackType.lightness:
                onColorChanged(Utils.hslToHsv(Utils.hsvToHsl(hsvColor).withLightness(progress)));
                break;

            case TrackType.red:
                onColorChanged(HSVColorExtention.fromColor(hsvColor.toColor().withRed((progress * 0xff).round())));
                break;

            case TrackType.green:
                onColorChanged(HSVColorExtention.fromColor(hsvColor.toColor().withGreen((progress * 0xff).round())));
                break;

            case TrackType.blue:
                onColorChanged(HSVColorExtention.fromColor(hsvColor.toColor().withBlue((progress * 0xff).round())));
                break;

            case TrackType.alpha:
                onColorChanged(hsvColor.withAlpha(localDx.clamp(0f, box.maxWidth - 30f) / (box.maxWidth - 30f)));
                break;
            }
        }
Exemple #4
0
        List <string> colorValue(HSVColor hsvColor, ColorModel colorModel)
        {
            Color color = hsvColor.toColor();

            if (colorModel == ColorModel.hex)
            {
                return(new List <string>()
                {
                    color.red.ToString("X2"),
                    color.green.ToString("X2"),
                    color.blue.ToString("X2"),
                    $"{(color.opacity * 100).round()}%"
                });
            }
            else if (colorModel == ColorModel.rgb)
            {
                return(new List <string>()
                {
                    color.red.ToString(),
                    color.green.ToString(),
                    color.blue.ToString(),
                    $"{(color.opacity * 100).round()}%"
                });
            }
            else if (colorModel == ColorModel.hsv)
            {
                return(new List <string>()
                {
                    $"{hsvColor.hue.round()}°",
                    $"{(hsvColor.saturation * 100).round()}%",
                    $"{(hsvColor.value * 100).round()}%",
                    $"{(hsvColor.alpha * 100).round()}%",
                });
            }
            else if (colorModel == ColorModel.hsl)
            {
                HSLColor hslColor = Utils.hsvToHsl(hsvColor);
                return(new List <string>()
                {
                    $"{hslColor.hue.round()}°",
                    $"{(hslColor.saturation * 100).round()}%",
                    $"{(hslColor.lightness * 100).round()}%",
                    $"{(hslColor.alpha * 100).round()}%",
                });
            }
            else
            {
                return(new List <string>()
                {
                    "??", "??", "??", "??"
                });
            }
        }
Exemple #5
0
        public override void paint(Canvas canvas, Size size)
        {
            Rect rect      = Offset.zero & size;
            var  gradientV = new LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: new List <Color> {
                Colors.white, Colors.black
            }
                );
            var gradientH = new LinearGradient(
                colors: new List <Color> {
                Colors.white,
                HSVColor.fromAHSV(1f, hsvColor.hue, 1f, 1f).toColor()
            }
                );

            var paint = new Paint()
            {
                strokeWidth = 1.5f, style = PaintingStyle.stroke
            };

            if (pointerColor != null)
            {
                paint.color = pointerColor;
            }
            else if (Utils.useWhiteForeground(hsvColor.toColor()))
            {
                paint.color = Colors.white;
            }
            else
            {
                paint.color = Colors.black;
            }


            canvas.drawRect(rect, new Paint()
            {
                shader = gradientV.createShader(rect)
            });
            canvas.drawRect(rect, new Paint()
            {
                blendMode = BlendMode.multiply, shader = gradientH.createShader(rect)
            });
            canvas.drawCircle(
                new Offset(size.width * hsvColor.saturation, size.height * (1 - hsvColor.value)),
                size.height * 0.04f,
                paint
                );
        }
Exemple #6
0
 public override Widget build(BuildContext context)
 {
     return(new Container(
                width: width,
                height: height,
                decoration: new BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(1000f)),
                    border: Border.all(color: new Color(0xffdddddd))
                    ),//BoxDecoration
                child: new ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(1000)),
                    child: new CustomPaint(painter: new IndicatorPainter(hsvColor.toColor()))
                    ) //ClipRRect
                ));   //Container
 }
Exemple #7
0
        public override void paint(Canvas canvas, Size size)
        {
            Rect rect = Offset.zero & size;

            if (trackType == TrackType.alpha)
            {
                Size  chessSize   = new Size(size.height / 2, size.height / 2);
                Paint chessPaintB = new Paint()
                {
                    color = new Color(0xffcccccc)
                };
                Paint chessPaintW = new Paint()
                {
                    color = Colors.white
                };

                int height = (size.height / chessSize.height).round();
                int width  = (size.width / chessSize.width).round();
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        canvas.drawRect(
                            new Offset(chessSize.width * x, chessSize.width * y) & chessSize,
                            (x + y) % 2 != 0 ? chessPaintW : chessPaintB
                            );
                    }
                }
            }

            List <Color>   colors;
            LinearGradient gradient;

            switch (trackType)
            {
            case TrackType.hue:
                colors = new List <Color>
                {
                    HSVColor.fromAHSV(1f, 0f, 1f, 1f).toColor(),
                    HSVColor.fromAHSV(1f, 60f, 1f, 1f).toColor(),
                    HSVColor.fromAHSV(1f, 120f, 1f, 1f).toColor(),
                    HSVColor.fromAHSV(1f, 180f, 1f, 1f).toColor(),
                    HSVColor.fromAHSV(1f, 240f, 1f, 1f).toColor(),
                    HSVColor.fromAHSV(1f, 240f, 1f, 1f).toColor(),
                    HSVColor.fromAHSV(1f, 300f, 1f, 1f).toColor(),
                    HSVColor.fromAHSV(1f, 360f, 1f, 1f).toColor()
                };
                gradient = new LinearGradient(colors: colors);
                canvas.drawRect(rect, new Paint()
                {
                    shader = gradient.createShader(rect)
                });
                break;

            case TrackType.saturation:
                colors = new List <Color> {
                    HSVColor.fromAHSV(1f, hsvColor.hue, 0f, 1f).toColor(),
                    HSVColor.fromAHSV(1f, hsvColor.hue, 1f, 1f).toColor()
                };
                gradient = new LinearGradient(colors: colors);
                canvas.drawRect(rect, new Paint()
                {
                    shader = gradient.createShader(rect)
                });
                break;

            case TrackType.saturationForHSL:
                colors = new List <Color> {
                    HSVColor.fromAHSV(1f, hsvColor.hue, 0f, .5f).toColor(),
                    HSVColor.fromAHSV(1f, hsvColor.hue, 1f, .5f).toColor()
                };
                gradient = new LinearGradient(colors: colors);
                canvas.drawRect(rect, new Paint()
                {
                    shader = gradient.createShader(rect)
                });
                break;

            case TrackType.value:
                colors = new List <Color> {
                    HSVColor.fromAHSV(1f, hsvColor.hue, 1f, 0f).toColor(),
                    HSVColor.fromAHSV(1f, hsvColor.hue, 1f, 1f).toColor()
                };
                gradient = new LinearGradient(colors: colors);
                canvas.drawRect(rect, new Paint()
                {
                    shader = gradient.createShader(rect)
                });
                break;

            case TrackType.lightness:
                colors = new List <Color> {
                    HSVColor.fromAHSV(1f, hsvColor.hue, 1f, 0f).toColor(),
                    HSVColor.fromAHSV(1f, hsvColor.hue, 1f, 0.5f).toColor(),
                    HSVColor.fromAHSV(1f, hsvColor.hue, 1f, 1f).toColor()
                };
                gradient = new LinearGradient(colors: colors);
                canvas.drawRect(rect, new Paint()
                {
                    shader = gradient.createShader(rect)
                });
                break;

            case TrackType.red:
                colors = new List <Color> {
                    hsvColor.toColor().withRed(0).withOpacity(1f),
                    hsvColor.toColor().withRed(255).withOpacity(1f)
                };
                gradient = new LinearGradient(colors: colors);
                canvas.drawRect(rect, new Paint()
                {
                    shader = gradient.createShader(rect)
                });
                break;

            case TrackType.green:
                colors = new List <Color> {
                    hsvColor.toColor().withGreen(0).withOpacity(1f),
                    hsvColor.toColor().withGreen(255).withOpacity(1f)
                };
                gradient = new LinearGradient(colors: colors);
                canvas.drawRect(rect, new Paint()
                {
                    shader = gradient.createShader(rect)
                });
                break;

            case TrackType.blue:
                colors = new List <Color> {
                    hsvColor.toColor().withBlue(0).withOpacity(1f),
                    hsvColor.toColor().withBlue(255).withOpacity(1f)
                };
                gradient = new LinearGradient(colors: colors);
                canvas.drawRect(rect, new Paint()
                {
                    shader = gradient.createShader(rect)
                });
                break;

            case TrackType.alpha:
                colors = new List <Color> {
                    Colors.black.withOpacity(0f),
                    Colors.black.withOpacity(1f)
                };
                gradient = new LinearGradient(colors: colors);
                canvas.drawRect(rect, new Paint()
                {
                    shader = gradient.createShader(rect)
                });
                break;
            }
        }