public static ChipThemeData lerp(ChipThemeData a, ChipThemeData b, float t) { if (a == null && b == null) { return(null); } return(new ChipThemeData( backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), deleteIconColor: Color.lerp(a?.deleteIconColor, b?.deleteIconColor, t), disabledColor: Color.lerp(a?.disabledColor, b?.disabledColor, t), selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t), secondarySelectedColor: Color.lerp(a?.secondarySelectedColor, b?.secondarySelectedColor, t), shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), selectedShadowColor: Color.lerp(a?.selectedShadowColor, b?.selectedShadowColor, t), checkmarkColor: Color.lerp(a?.checkmarkColor, b?.checkmarkColor, t), labelPadding: EdgeInsetsGeometry.lerp(a?.labelPadding, b?.labelPadding, t), padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t), shape: ShapeBorder.lerp(a?.shape, b?.shape, t), labelStyle: TextStyle.lerp(a?.labelStyle, b?.labelStyle, t), secondaryLabelStyle: TextStyle.lerp(a?.secondaryLabelStyle, b?.secondaryLabelStyle, t), brightness: t < 0.5f ? a?.brightness ?? Brightness.light : b?.brightness ?? Brightness.light, elevation: MathUtils.lerpNullableFloat(a?.elevation, b?.elevation, t), pressElevation: MathUtils.lerpNullableFloat(a?.pressElevation, b?.pressElevation, t) )); }
void _updateBubblesPaints() { float progress1 = LikeButtonUtil.clamp(this.m_CurrentProgress, 0.6f, 1); int alpha = (int)LikeButtonUtil.mapValueFromRangeToRange(progress1, 0.6f, 1, 255, 0); if (this.m_CurrentProgress < 0.5) { float progress2 = LikeButtonUtil.mapValueFromRangeToRange(this.m_CurrentProgress, 0, 0.5f, 0, 1); this.m_CirclePaints[0].color = Color.lerp(this.m_Color1, this.m_Color2, progress2).withAlpha(alpha); this.m_CirclePaints[1].color = Color.lerp(this.m_Color2, this.m_Color3, progress2).withAlpha(alpha); this.m_CirclePaints[2].color = Color.lerp(this.m_Color3, this.m_Color4, progress2).withAlpha(alpha); this.m_CirclePaints[3].color = Color.lerp(this.m_Color4, this.m_Color1, progress2).withAlpha(alpha); } else { float progress3 = LikeButtonUtil.mapValueFromRangeToRange(this.m_CurrentProgress, 0.5f, 1, 0, 1); this.m_CirclePaints[0].color = Color.lerp(this.m_Color2, this.m_Color3, progress3).withAlpha(alpha); this.m_CirclePaints[1].color = Color.lerp(this.m_Color3, this.m_Color4, progress3).withAlpha(alpha); this.m_CirclePaints[2].color = Color.lerp(this.m_Color4, this.m_Color1, progress3).withAlpha(alpha); this.m_CirclePaints[3].color = Color.lerp(this.m_Color1, this.m_Color2, progress3).withAlpha(alpha); } }
public static SliderThemeData lerp(SliderThemeData a, SliderThemeData b, float t) { D.assert(a != null); D.assert(b != null); return(new SliderThemeData( trackHeight: MathUtils.lerpFloat(a.trackHeight, b.trackHeight, t), activeTrackColor: Color.lerp(a.activeTrackColor, b.activeTrackColor, t), inactiveTrackColor: Color.lerp(a.inactiveTrackColor, b.inactiveTrackColor, t), disabledActiveTrackColor: Color.lerp(a.disabledActiveTrackColor, b.disabledActiveTrackColor, t), disabledInactiveTrackColor: Color.lerp(a.disabledInactiveTrackColor, b.disabledInactiveTrackColor, t), activeTickMarkColor: Color.lerp(a.activeTickMarkColor, b.activeTickMarkColor, t), inactiveTickMarkColor: Color.lerp(a.inactiveTickMarkColor, b.inactiveTickMarkColor, t), disabledActiveTickMarkColor: Color.lerp(a.disabledActiveTickMarkColor, b.disabledActiveTickMarkColor, t), disabledInactiveTickMarkColor: Color.lerp(a.disabledInactiveTickMarkColor, b.disabledInactiveTickMarkColor, t), thumbColor: Color.lerp(a.thumbColor, b.thumbColor, t), disabledThumbColor: Color.lerp(a.disabledThumbColor, b.disabledThumbColor, t), overlayColor: Color.lerp(a.overlayColor, b.overlayColor, t), valueIndicatorColor: Color.lerp(a.valueIndicatorColor, b.valueIndicatorColor, t), trackShape: t < 0.5 ? a.trackShape : b.trackShape, tickMarkShape: t < 0.5 ? a.tickMarkShape : b.tickMarkShape, thumbShape: t < 0.5 ? a.thumbShape : b.thumbShape, overlayShape: t < 0.5 ? a.overlayShape : b.overlayShape, valueIndicatorShape: t < 0.5 ? a.valueIndicatorShape : b.valueIndicatorShape, showValueIndicator: t < 0.5 ? a.showValueIndicator : b.showValueIndicator, valueIndicatorTextStyle: TextStyle.lerp(a.valueIndicatorTextStyle, b.valueIndicatorTextStyle, t) )); }
public static BorderSide lerp(BorderSide a, BorderSide b, float t) { D.assert(a != null); D.assert(b != null); if (t == 0.0f) { return(a); } if (t == 1.0f) { return(b); } float width = MathUtils.lerpFloat(a.width, b.width, t); if (width < 0.0) { return(none); } if (a.style == b.style) { return(new BorderSide( color: Color.lerp(a.color, b.color, t), width: width, style: a.style // == b.style )); } Color colorA = null, colorB = null; switch (a.style) { case BorderStyle.solid: colorA = a.color; break; case BorderStyle.none: colorA = a.color.withAlpha(0x00); break; } switch (b.style) { case BorderStyle.solid: colorB = b.color; break; case BorderStyle.none: colorB = b.color.withAlpha(0x00); break; } return(new BorderSide( color: Color.lerp(colorA, colorB, t), width: width, style: BorderStyle.solid )); }
public static _ColorsAndStops _interpolateColorsAndStops( List <Color> aColors, List <float> aStops, List <Color> bColors, List <float> bStops, float t) { D.assert(aColors.Count == bColors.Count, "Cannot interpolate between two gradients with a different number of colors."); D.assert((aStops == null && aColors.Count == 2) || (aStops != null && aStops.Count == aColors.Count)); D.assert((bStops == null && bColors.Count == 2) || (bStops != null && bStops.Count == bColors.Count)); List <Color> interpolatedColors = new List <Color>(); for (int i = 0; i < aColors.Count; i += 1) { interpolatedColors.Add(Color.lerp(aColors[i], bColors[i], t)); } List <float> interpolatedStops = null; if (aStops != null || bStops != null) { aStops = aStops ?? new List <float> { 0.0f, 1.0f }; bStops = bStops ?? new List <float> { 0.0f, 1.0f }; D.assert(aStops.Count == bStops.Count); interpolatedStops = new List <float>(); for (int i = 0; i < aStops.Count; i += 1) { interpolatedStops.Add(MathUtils.lerpFloat(aStops[i], bStops[i], t).clamp(0.0f, 1.0f)); } } return(new _ColorsAndStops(interpolatedColors, interpolatedStops)); }
public override void paint(PaintingContext context, Offset offset) { Canvas canvas = context.canvas; float currentValue = _state.position.value; float currentReactionValue = _state._reaction.value; float visualPosition = 0.0f; switch (textDirection) { case TextDirection.rtl: visualPosition = 1.0f - currentValue; break; case TextDirection.ltr: visualPosition = currentValue; break; } Paint paint = new Paint() { color = Color.lerp(trackColor, activeColor, currentValue) }; Rect trackRect = Rect.fromLTWH( offset.dx + (size.width - CupertinoSwitchUtils._kTrackWidth) / 2.0f, offset.dy + (size.height - CupertinoSwitchUtils._kTrackHeight) / 2.0f, CupertinoSwitchUtils._kTrackWidth, CupertinoSwitchUtils._kTrackHeight ); RRect trackRRect = RRect.fromRectAndRadius(trackRect, Radius.circular(CupertinoSwitchUtils._kTrackRadius)); canvas.drawRRect(trackRRect, paint); float currentThumbExtension = CupertinoThumbPainter.extension * currentReactionValue; float thumbLeft = MathUtils.lerpNullableFloat( trackRect.left + CupertinoSwitchUtils._kTrackInnerStart - CupertinoThumbPainter.radius, trackRect.left + CupertinoSwitchUtils._kTrackInnerEnd - CupertinoThumbPainter.radius - currentThumbExtension, visualPosition ); float thumbRight = MathUtils.lerpNullableFloat( trackRect.left + CupertinoSwitchUtils._kTrackInnerStart + CupertinoThumbPainter.radius + currentThumbExtension, trackRect.left + CupertinoSwitchUtils._kTrackInnerEnd + CupertinoThumbPainter.radius, visualPosition ); float thumbCenterY = offset.dy + size.height / 2.0f; Rect thumbBounds = Rect.fromLTRB( thumbLeft, thumbCenterY - CupertinoThumbPainter.radius, thumbRight, thumbCenterY + CupertinoThumbPainter.radius ); context.pushClipRRect(needsCompositing, Offset.zero, thumbBounds, trackRRect, (PaintingContext innerContext, Offset offset1) => { CupertinoThumbPainter.switchThumb().paint(innerContext.canvas, thumbBounds); }); }
public static BottomAppBarTheme lerp(BottomAppBarTheme a, BottomAppBarTheme b, float t) { return(new BottomAppBarTheme( color: Color.lerp(a?.color, b?.color, t), elevation: MathUtils.lerpNullableFloat(a?.elevation, b?.elevation, t), shape: t < 0.5f ? a?.shape : b?.shape )); }
public override Gradient scale(float factor) { return(new LinearGradient( begin: begin, end: end, colors: LinqUtils <Color> .SelectList(colors, (color => Color.lerp(null, color, factor))), stops: stops, tileMode: tileMode )); }
public override Gradient scale(float factor) { return(new RadialGradient( center: this.center, radius: this.radius, colors: this.colors.Select(color => Color.lerp(null, color, factor)).ToList(), stops: this.stops, tileMode: this.tileMode )); }
public override Gradient scale(float factor) { return(new LinearGradient( begin: this.begin, end: this.end, colors: this.colors.Select(color => Color.lerp(null, color, factor)).ToList(), stops: this.stops, tileMode: this.tileMode )); }
public override Gradient scale(float factor) { return(new RadialGradient( center: center, radius: radius, colors: LinqUtils <Color> .SelectList(colors, (color => Color.lerp(null, color, factor))), stops: stops, tileMode: tileMode )); }
public static DialogTheme lerp(DialogTheme a, DialogTheme b, float t) { return(new DialogTheme( backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), elevation: MathUtils.lerpNullableFloat(a?.elevation, b?.elevation, t), shape: ShapeBorder.lerp(a?.shape, b?.shape, t), titleTextStyle: TextStyle.lerp(a?.titleTextStyle, b?.titleTextStyle, t), contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t) )); }
public static DividerThemeData lerp(DividerThemeData a, DividerThemeData b, float t) { return(new DividerThemeData( color: Color.lerp(a?.color, b?.color, t), space: MathUtils.lerpNullableFloat(a?.space, b?.space, t), thickness: MathUtils.lerpNullableFloat(a?.thickness, b?.thickness, t), indent: MathUtils.lerpNullableFloat(a?.indent, b?.indent, t), endIndent: MathUtils.lerpNullableFloat(a?.endIndent, b?.endIndent, t) )); }
public static Bar lerp(Bar begin, Bar end, float t) { D.assert(begin.rank == end.rank); return(new Bar( begin.rank, MathUtils.lerpFloat(begin.x, end.x, t), MathUtils.lerpFloat(begin.width, end.width, t), MathUtils.lerpFloat(begin.height, end.height, t), Color.lerp(begin.color, end.color, t) )); }
public static AppBarTheme lerp(AppBarTheme a, AppBarTheme b, float t) { return(new AppBarTheme( brightness: t < 0.5f ? a?.brightness : b?.brightness, color: Color.lerp(a?.color, b?.color, t), elevation: MathUtils.lerpNullableFloat(a?.elevation, b?.elevation, t), iconTheme: IconThemeData.lerp(a?.iconTheme, b?.iconTheme, t), actionsIconTheme: IconThemeData.lerp(a?.actionsIconTheme, b?.actionsIconTheme, t), textTheme: TextTheme.lerp(a?.textTheme, b?.textTheme, t) )); }
public override Gradient scale(float factor) { return(new SweepGradient( center: center, startAngle: startAngle, endAngle: endAngle, colors: LinqUtils <Color> .SelectList(colors, (color => Color.lerp(null, color, factor))), stops: stops, tileMode: tileMode )); }
public override Gradient scale(float factor) { return(new SweepGradient( center: this.center, startAngle: this.startAngle, endAngle: this.endAngle, colors: this.colors.Select(color => Color.lerp(null, color, factor)).ToList(), stops: this.stops, tileMode: this.tileMode )); }
public static CardTheme lerp(CardTheme a, CardTheme b, float t) { return(new CardTheme( clipBehavior: t < 0.5f ? a?.clipBehavior : b?.clipBehavior, color: Color.lerp(a?.color, b?.color, t), shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), elevation: MathUtils.lerpNullableFloat(a?.elevation, b?.elevation, t), margin: EdgeInsetsGeometry.lerp(a?.margin, b?.margin, t), shape: ShapeBorder.lerp(a?.shape, b?.shape, t) )); }
public static SnackBarThemeData lerp(SnackBarThemeData a, SnackBarThemeData b, float t) { return(new SnackBarThemeData( backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), actionTextColor: Color.lerp(a?.actionTextColor, b?.actionTextColor, t), disabledActionTextColor: Color.lerp(a?.disabledActionTextColor, b?.disabledActionTextColor, t), contentTextStyle: TextStyle.lerp(a?.contentTextStyle, b?.contentTextStyle, t), elevation: MathUtils.lerpNullableFloat(a?.elevation, b?.elevation, t), shape: ShapeBorder.lerp(a?.shape, b?.shape, t), behavior: t < 0.5 ? a.behavior : b.behavior )); }
public BoxDecoration scale(float factor) { return(new BoxDecoration( color: Color.lerp(null, this.color, factor), image: this.image, border: Border.lerp(null, this.border, factor), borderRadius: BorderRadius.lerp(null, this.borderRadius, factor), boxShadow: BoxShadow.lerpList(null, this.boxShadow, factor), gradient: this.gradient?.scale(factor), backgroundBlendMode: this.backgroundBlendMode, shape: this.shape )); }
public static PopupMenuThemeData lerp(PopupMenuThemeData a, PopupMenuThemeData b, float t) { if (a == null && b == null) { return(null); } return(new PopupMenuThemeData( color: Color.lerp(a?.color, b?.color, t), shape: ShapeBorder.lerp(a?.shape, b?.shape, t), elevation: MathUtils.lerpNullableFloat(a?.elevation, b?.elevation, t), textStyle: TextStyle.lerp(a?.textStyle, b?.textStyle, t) )); }
Image fillGradient(List <Color> colors, List <float> positions) { Texture2D tex = new Texture2D(this.resolution, 1, TextureFormat.RGBA32, false); tex.hideFlags = HideFlags.HideAndDontSave; tex.wrapMode = TextureWrapMode.Clamp; var bytes = new byte[this.resolution * 4]; int count = colors.Count; int prevIndex = 0; for (int i = 1; i < count; i++) { // Historically, stops have been mapped to [0, 256], with 256 then nudged to the next // smaller value, then truncate for the texture index. This seems to produce the best // results for some common distributions, so we preserve the behavior. int nextIndex = (int)Mathf.Min(positions[i] * this.resolution, this.resolution - 1); if (nextIndex > prevIndex) { var c0 = colors[i - 1]; var c1 = colors[i]; var step = 1.0f / (nextIndex - prevIndex); var t = 0.0f; for (int curIndex = prevIndex; curIndex <= nextIndex; ++curIndex) { var c = Color.lerp(c0, c1, t); var baseIndex = curIndex << 2; bytes[baseIndex] = (byte)c.red; bytes[baseIndex + 1] = (byte)c.green; bytes[baseIndex + 2] = (byte)c.blue; bytes[baseIndex + 3] = (byte)c.alpha; t += step; } } prevIndex = nextIndex; } D.assert(prevIndex == this.resolution - 1); tex.LoadRawTextureData(bytes); tex.Apply(); return(new Image(tex)); }
public static BottomSheetThemeData lerp(BottomSheetThemeData a, BottomSheetThemeData b, float t) { if (a == null && b == null) { return(null); } return(new BottomSheetThemeData( backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), elevation: MathUtils.lerpNullableFloat(a?.elevation, b?.elevation, t), modalBackgroundColor: Color.lerp(a?.modalBackgroundColor, b?.modalBackgroundColor, t), modalElevation: MathUtils.lerpNullableFloat(a?.modalElevation, b?.modalElevation, t), shape: ShapeBorder.lerp(a?.shape, b?.shape, t), clipBehavior: t < 0.5 ? a?.clipBehavior : b?.clipBehavior )); }
public static NavigationRailThemeData lerp(NavigationRailThemeData a, NavigationRailThemeData b, float t) { if (a == null && b == null) { return(null); } return(new NavigationRailThemeData( backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), elevation: MathUtils.lerpNullableFloat(a?.elevation, b?.elevation, t), unselectedLabelTextStyle: TextStyle.lerp(a?.unselectedLabelTextStyle, b?.unselectedLabelTextStyle, t), selectedLabelTextStyle: TextStyle.lerp(a?.selectedLabelTextStyle, b?.selectedLabelTextStyle, t), unselectedIconTheme: IconThemeData.lerp(a?.unselectedIconTheme, b?.unselectedIconTheme, t), selectedIconTheme: IconThemeData.lerp(a?.selectedIconTheme, b?.selectedIconTheme, t), groupAlignment: MathUtils.lerpNullableFloat(a?.groupAlignment, b?.groupAlignment, t), labelType: t < 0.5 ? a?.labelType : b?.labelType )); }
public override void paint(Canvas canvas, Size size) { Paint paint = new Paint(); canvas.save(); canvas.translate(size.width / 2.0f, size.height / 2.0f); int activeTick = (CupertinoActivityIndicatorUtils._kTickCount * this.position.value).floor(); for (int i = 0; i < CupertinoActivityIndicatorUtils._kTickCount; ++i) { float t = (((i + activeTick) % CupertinoActivityIndicatorUtils._kTickCount) / CupertinoActivityIndicatorUtils._kHalfTickCount).clamp(0, 1); paint.color = Color.lerp(a: CupertinoActivityIndicatorUtils._kActiveTickColor, b: CupertinoActivityIndicatorUtils._kTickColor, t: t); canvas.drawRRect(rect: this.tickFundamentalRRect, paint: paint); canvas.rotate(-CupertinoActivityIndicatorUtils._kTwoPI / CupertinoActivityIndicatorUtils._kTickCount); } canvas.restore(); }
public static BoxDecoration lerp(BoxDecoration a, BoxDecoration b, float t) { if (a == null && b == null) { return(null); } if (a == null) { return(b.scale(t)); } if (b == null) { return(a.scale(1.0f - t)); } if (t == 0.0) { return(a); } if (t == 1.0) { return(b); } return(new BoxDecoration( color: Color.lerp(a.color, b.color, t), image: t < 0.5 ? a.image : b.image, border: Border.lerp(a.border, b.border, t), borderRadius: BorderRadius.lerp(a.borderRadius, b.borderRadius, t), boxShadow: BoxShadow.lerpList(a.boxShadow, b.boxShadow, t), gradient: Gradient.lerp(a.gradient, b.gradient, t), backgroundBlendMode: t < 0.5 ? a.backgroundBlendMode : b.backgroundBlendMode, shape: t < 0.5 ? a.shape : b.shape )); }
public static FloatingActionButtonThemeData lerp(FloatingActionButtonThemeData a, FloatingActionButtonThemeData b, float t) { if (a == null && b == null) { return(null); } return(new FloatingActionButtonThemeData( foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t), backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), focusColor: Color.lerp(a?.focusColor, b?.focusColor, t), hoverColor: Color.lerp(a?.hoverColor, b?.hoverColor, t), splashColor: Color.lerp(a?.splashColor, b?.splashColor, t), elevation: MathUtils.lerpNullableFloat(a?.elevation, b?.elevation, t), focusElevation: MathUtils.lerpNullableFloat(a?.focusElevation, b?.focusElevation, t), hoverElevation: MathUtils.lerpNullableFloat(a?.hoverElevation, b?.hoverElevation, t), disabledElevation: MathUtils.lerpNullableFloat(a?.disabledElevation, b?.disabledElevation, t), highlightElevation: MathUtils.lerpNullableFloat(a?.highlightElevation, b?.highlightElevation, t), shape: ShapeBorder.lerp(a?.shape, b?.shape, t) )); }
static Color _sample(List <Color> colors, List <float> stops, float t) { D.assert(colors != null); D.assert(colors.isNotEmpty); D.assert(stops != null); D.assert(stops.isNotEmpty); if (t < stops.first()) { return(colors.first()); } if (t > stops.last()) { return(colors.last()); } int index = stops.FindLastIndex((float s) => { return(s <= t); }); D.assert(index != -1); return(Color.lerp(colors[index], colors[index + 1], (t - stops[index]) / (stops[index + 1] - stops[index]))); }
public static BoxShadow lerp(BoxShadow a, BoxShadow b, float t) { if (a == null && b == null) { return(null); } if (a == null) { return(b.scale(t)); } if (b == null) { return(a.scale(1.0f - t)); } return(new BoxShadow( color: Color.lerp(a.color, b.color, t), offset: Offset.lerp(a.offset, b.offset, t), blurRadius: MathUtils.lerpFloat(a.blurRadius, b.blurRadius, t), spreadRadius: MathUtils.lerpFloat(a.spreadRadius, b.spreadRadius, t) )); }
internal static _ColorsAndStops _interpolateColorsAndStops( List <Color> aColors, List <float> aStops, List <Color> bColors, List <float> bStops, float t) { D.assert(aColors.Count >= 2); D.assert(bColors.Count >= 2); D.assert(aStops.Count == aColors.Count); D.assert(bStops.Count == bColors.Count); SplayTree <float, bool> stops = new SplayTree <float, bool>(); stops.AddAll(aStops); stops.AddAll(bStops); List <float> interpolatedStops = stops.Keys.ToList(); List <Color> interpolatedColors = interpolatedStops.Select <float, Color>((float stop) => { return(Color.lerp(_sample(aColors, aStops, stop), _sample(bColors, bStops, stop), t)); }).ToList(); return(new _ColorsAndStops(interpolatedColors, interpolatedStops)); }