public override void paint(Canvas canvas, Size size) { Rect rect = Offset.zero & size; var gradientH = new LinearGradient( colors: new List <Color> { new Color(0xff808080), HSLColor.fromAHSL(1f, hslColor.hue, 1f, 0.5f).toColor() } ); var gradientV = new LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, stops: new List <float> { 0.0f, 0.5f, 0.5f, 1f }, colors: new List <Color> { Colors.white, new Color(0x00ffffff), Colors.transparent, Colors.black } ); var paint = new Paint() { strokeWidth = 1.5f, style = PaintingStyle.stroke }; if (pointerColor != null) { paint.color = pointerColor; } else if (Utils.useWhiteForeground(hslColor.toColor())) { paint.color = Colors.white; } else { paint.color = Colors.black; } canvas.drawRect(rect, new Paint() { shader = gradientV.createShader(rect) }); canvas.drawRect(rect, new Paint() { shader = gradientH.createShader(rect) }); canvas.drawCircle( new Offset(size.width * hslColor.saturation, size.height * (1 - hslColor.lightness)), size.height * 0.04f, paint ); }
public HSLColor withLightness(float lightness) { return(HSLColor.fromAHSL(this.alpha, this.hue, this.saturation, lightness)); }
public HSLColor withSaturation(float saturation) { return(HSLColor.fromAHSL(this.alpha, this.hue, saturation, this.lightness)); }
public override Widget build(BuildContext context) { float thumbOffset = 15f; Color _thumbColor = Colors.black; return(new LayoutBuilder(builder: (BuildContext _, BoxConstraints box) => { switch (trackType) { case TrackType.hue: thumbOffset += (box.maxWidth - 30f) * hsvColor.hue / 360f; _thumbColor = HSVColor.fromAHSV(1f, hsvColor.hue, 1f, 1f).toColor(); break; case TrackType.saturation: thumbOffset += (box.maxWidth - 30f) * hsvColor.saturation; _thumbColor = HSVColor.fromAHSV(1f, hsvColor.hue, hsvColor.saturation, 1f) .toColor(); break; case TrackType.saturationForHSL: thumbOffset += (box.maxWidth - 30f) * Utils.hsvToHsl(hsvColor).saturation; _thumbColor = HSLColor.fromAHSL( 1f, hsvColor.hue, Utils.hsvToHsl(hsvColor).saturation, 0.5f) .toColor(); break; case TrackType.value: thumbOffset += (box.maxWidth - 30f) * hsvColor.value; _thumbColor = HSVColor.fromAHSV(1f, hsvColor.hue, 1f, hsvColor.value) .toColor(); break; case TrackType.lightness: thumbOffset += (box.maxWidth - 30f) * Utils.hsvToHsl(hsvColor).lightness; _thumbColor = HSLColor.fromAHSL( 1f, hsvColor.hue, 1f, Utils.hsvToHsl(hsvColor).lightness) .toColor(); break; case TrackType.red: thumbOffset += (box.maxWidth - 30f) * hsvColor.toColor().red / 0xff; _thumbColor = hsvColor.toColor().withOpacity(1f); break; case TrackType.green: thumbOffset += (box.maxWidth - 30f) * hsvColor.toColor().green / 0xff; _thumbColor = hsvColor.toColor().withOpacity(1f); break; case TrackType.blue: thumbOffset += (box.maxWidth - 30f) * hsvColor.toColor().blue / 0xff; _thumbColor = hsvColor.toColor().withOpacity(1f); break; case TrackType.alpha: thumbOffset += (box.maxWidth - 30f) * hsvColor.toColor().opacity; _thumbColor = Colors.black.withOpacity(hsvColor.alpha); break; }//switch return new CustomMultiChildLayout( layoutDelegate: new _SliderLayout(), children: new List <Widget> { new LayoutId( id: _SliderLayout.track, child: new ClipRRect( borderRadius: BorderRadius.all(Radius.circular(3f)), child: new CustomPaint( painter: new TrackPainter(this.trackType, this.hsvColor) ) //CustomPaint ) ), //LayoutId new LayoutId( id: _SliderLayout.thumb, child: Transform.translate( offset: new Offset(thumbOffset, 0f), child: new CustomPaint( painter: new ThumbPainter( thumbColor: !displayThumbColor ? null : _thumbColor, fullThumbColor: fullThumbColor ) //ThumbPainter ) //CustomPaint ) //Transform ), //LayoutId new LayoutId( id: _SliderLayout.gestureContainer, child: new LayoutBuilder( builder: (BuildContext __, BoxConstraints _box) => { RenderBox getBox = context.findRenderObject() as RenderBox; return new GestureDetector( child: new Container(color: Colors.transparent), onPanDown: (DragDownDetails details) => { slideEvent(getBox, box, details.globalPosition); }, onPanUpdate: (DragUpdateDetails details ) => { slideEvent(getBox, box, details.globalPosition); } ); } ) //LayoutBuilder ) //LayoutId } //list Widget ); //CustomMultiChildLayout })); //LayoutBuilder }