Пример #1
0
        public static void drawShadow(Canvas canvas, Path path, Color color, float elevation, bool transparentOccluder,
                                      float dpr)
        {
            float kAmbientAlpha = 0.039f;
            float kSpotAlpha    = ShadowUtils.kUseFastShadow ? 0.1f : 0.25f;
            float kLightHeight  = 600f;
            float kLightRadius  = 800f;

            Rect  bounds   = path.getBounds();
            float shadow_x = (bounds.left + bounds.right) / 2f;
            float shadow_y = bounds.top - 600.0f;

            _inAmbient    = color.withAlpha((int)(kAmbientAlpha * color.alpha));
            _inSpot       = color.withAlpha((int)(kSpotAlpha * color.alpha));
            _ambientColor = null;
            _spotColor    = null;
            ShadowUtils.computeTonalColors(_inAmbient, _inSpot, ref _ambientColor, ref _spotColor);

            _zPlane.Set(0, 0, dpr * elevation);
            _devLight.Set(shadow_x, shadow_y, dpr * kLightHeight);

            ShadowUtils.drawShadow(
                canvas,
                path,
                _zPlane,
                _devLight,
                dpr * kLightRadius,
                _ambientColor,
                _spotColor,
                0
                );
        }
        public static void drawShadow(Canvas canvas, Path path, Color color, float elevation, bool transparentOccluder,
                                      float dpr)
        {
            float kAmbientAlpha = 0.039f;
            float kSpotAlpha    = 0.25f;
            float kLightHeight  = 600f;
            float kLightRadius  = 800f;

            Rect  bounds       = path.getBounds();
            float shadow_x     = (bounds.left + bounds.right) / 2f;
            float shadow_y     = bounds.top - 600.0f;
            Color inAmbient    = color.withAlpha((int)(kAmbientAlpha * color.alpha));
            Color inSpot       = color.withAlpha((int)(kSpotAlpha * color.alpha));
            Color ambientColor = null;
            Color spotColor    = null;

            ShadowUtils.computeTonalColors(inAmbient, inSpot, ref ambientColor, ref spotColor);
            ShadowUtils.drawShadow(
                canvas,
                path,
                new Vector3(0, 0, dpr * elevation),
                new Vector3(shadow_x, shadow_y, dpr * kLightHeight),
                dpr * kLightRadius,
                ambientColor,
                spotColor,
                0
                );
        }
Пример #3
0
        public static ChipThemeData fromDefaults(
            Brightness?brightness = null,
            Color primaryColor    = null,
            Color secondaryColor  = null,
            TextStyle labelStyle  = null
            )
        {
            D.assert(primaryColor != null || brightness != null,
                     () => "One of primaryColor or brightness must be specified");
            D.assert(primaryColor == null || brightness == null,
                     () => "Only one of primaryColor or brightness may be specified");
            D.assert(secondaryColor != null);
            D.assert(labelStyle != null);

            if (primaryColor != null)
            {
                brightness = ThemeData.estimateBrightnessForColor(primaryColor);
            }

            const int          backgroundAlpha = 0x1f; // 12%
            const int          deleteIconAlpha = 0xde; // 87%
            const int          disabledAlpha   = 0x0c; // 38% * 12% = 5%
            const int          selectAlpha     = 0x3d; // 12% + 12% = 24%
            const int          textLabelAlpha  = 0xde; // 87%
            ShapeBorder        shape           = new StadiumBorder();
            EdgeInsetsGeometry labelPadding    = EdgeInsets.symmetric(horizontal: 8.0f);
            EdgeInsetsGeometry padding         = EdgeInsets.all(4.0f);

            primaryColor = primaryColor ?? (brightness == Brightness.light ? Colors.black : Colors.white);
            Color     backgroundColor        = primaryColor.withAlpha(backgroundAlpha);
            Color     deleteIconColor        = primaryColor.withAlpha(deleteIconAlpha);
            Color     disabledColor          = primaryColor.withAlpha(disabledAlpha);
            Color     selectedColor          = primaryColor.withAlpha(selectAlpha);
            Color     secondarySelectedColor = secondaryColor.withAlpha(selectAlpha);
            TextStyle secondaryLabelStyle    = labelStyle.copyWith(
                color: secondaryColor.withAlpha(textLabelAlpha)
                );

            labelStyle = labelStyle.copyWith(color: primaryColor.withAlpha(textLabelAlpha));

            return(new ChipThemeData(
                       backgroundColor: backgroundColor,
                       deleteIconColor: deleteIconColor,
                       disabledColor: disabledColor,
                       selectedColor: selectedColor,
                       secondarySelectedColor: secondarySelectedColor,
                       labelPadding: labelPadding,
                       padding: padding,
                       shape: shape,
                       labelStyle: labelStyle,
                       secondaryLabelStyle: secondaryLabelStyle,
                       brightness: brightness
                       ));
        }
        public static SliderThemeData fromPrimaryColors(
            Color primaryColor                = null,
            Color primaryColorDark            = null,
            Color primaryColorLight           = null,
            TextStyle valueIndicatorTextStyle = null)
        {
            D.assert(primaryColor != null);
            D.assert(primaryColorDark != null);
            D.assert(primaryColorLight != null);
            D.assert(valueIndicatorTextStyle != null);

            const int activeTrackAlpha              = 0xff;
            const int inactiveTrackAlpha            = 0x3d; // 24% opacity
            const int disabledActiveTrackAlpha      = 0x52; // 32% opacity
            const int disabledInactiveTrackAlpha    = 0x1f; // 12% opacity
            const int activeTickMarkAlpha           = 0x8a; // 54% opacity
            const int inactiveTickMarkAlpha         = 0x8a; // 54% opacity
            const int disabledActiveTickMarkAlpha   = 0x1f; // 12% opacity
            const int disabledInactiveTickMarkAlpha = 0x1f; // 12% opacity
            const int thumbAlpha          = 0xff;
            const int disabledThumbAlpha  = 0x52;           // 32% opacity
            const int valueIndicatorAlpha = 0xff;

            const int overlayLightAlpha = 0x29;

            return(new SliderThemeData(
                       trackHeight: 2.0f,
                       activeTrackColor: primaryColor.withAlpha(activeTrackAlpha),
                       inactiveTrackColor: primaryColor.withAlpha(inactiveTrackAlpha),
                       disabledActiveTrackColor: primaryColorDark.withAlpha(disabledActiveTrackAlpha),
                       disabledInactiveTrackColor: primaryColorDark.withAlpha(disabledInactiveTrackAlpha),
                       activeTickMarkColor: primaryColorLight.withAlpha(activeTickMarkAlpha),
                       inactiveTickMarkColor: primaryColor.withAlpha(inactiveTickMarkAlpha),
                       disabledActiveTickMarkColor: primaryColorLight.withAlpha(disabledActiveTickMarkAlpha),
                       disabledInactiveTickMarkColor: primaryColorDark.withAlpha(disabledInactiveTickMarkAlpha),
                       thumbColor: primaryColor.withAlpha(thumbAlpha),
                       disabledThumbColor: primaryColorDark.withAlpha(disabledThumbAlpha),
                       overlayColor: primaryColor.withAlpha(overlayLightAlpha),
                       valueIndicatorColor: primaryColor.withAlpha(valueIndicatorAlpha),
                       trackShape: new RectangularSliderTrackShape(),
                       tickMarkShape: new RoundSliderTickMarkShape(),
                       thumbShape: new RoundSliderThumbShape(),
                       overlayShape: new RoundSliderOverlayShape(),
                       valueIndicatorShape: new PaddleSliderValueIndicatorShape(),
                       valueIndicatorTextStyle: valueIndicatorTextStyle,
                       showValueIndicator: ShowValueIndicator.onlyForDiscrete
                       ));
        }
Пример #5
0
        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 * position.value).floor();

            for (int i = 0; i < CupertinoActivityIndicatorUtils._kTickCount; ++i)
            {
                int t = ((i + activeTick) % CupertinoActivityIndicatorUtils._kTickCount);
                paint.color = activeColor.withAlpha(CupertinoActivityIndicatorUtils._alphaValues[t]);
                canvas.drawRRect(tickFundamentalRRect, paint);
                canvas.rotate(-CupertinoActivityIndicatorUtils._kTwoPI / CupertinoActivityIndicatorUtils._kTickCount);
            }

            canvas.restore();
        }
Пример #6
0
 internal static Color _scaleAlpha(this Color a, float factor)
 {
     return(a.withAlpha((a.alpha * factor).round().clamp(0, 255)));
 }
Пример #7
0
 internal static Color _scaleAlpha(Color a, double factor)
 {
     return(a.withAlpha((a.alpha * factor).round().clamp(0, 255)));
 }