示例#1
0
文件: paint.cs 项目: JC-ut0/CubeGame
 public uiPaint(
     uiColor?color             = null,
     BlendMode blendMode       = BlendMode.srcOver,
     PaintingStyle style       = PaintingStyle.fill,
     float strokeWidth         = 0f,
     StrokeCap strokeCap       = StrokeCap.butt,
     StrokeJoin strokeJoin     = StrokeJoin.miter,
     float strokeMiterLimit    = 4.0f,
     FilterMode filterMode     = FilterMode.Bilinear,
     uiColorFilter?colorFilter = null,
     uiMaskFilter?maskFilter   = null,
     uiImageFilter backdrop    = null,
     PaintShader shader        = null,
     bool invertColors         = false
     )
 {
     this.color            = color ?? _kColorDefault;
     this.blendMode        = blendMode;
     this.style            = style;
     this.strokeWidth      = strokeWidth;
     this.strokeCap        = strokeCap;
     this.strokeJoin       = strokeJoin;
     this.strokeMiterLimit = strokeMiterLimit;
     this.filterMode       = filterMode;
     this.colorFilter      = colorFilter;
     this.maskFilter       = maskFilter;
     this.backdrop         = backdrop;
     this.shader           = shader;
     this.invertColors     = invertColors;
 }
示例#2
0
 static Vector4 _colorToVector4(uiColor c)
 {
     return(new Vector4(
                c.red / 255f,
                c.green / 255f,
                c.blue / 255f,
                c.alpha / 255f
                ));
 }
示例#3
0
        static void drawShadowFast(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
                                   float lightRadius, uiColor ambientColor, uiColor spotColor, int flags)
        {
            Matrix3 viewMatrix = canvas.getTotalMatrix();

            //debug shadow
            #pragma warning disable CS0162
            if (debugShadow)
            {
                var isRRect = path.isNaiveRRect;
                if (isRRect)
                {
                    ambientColor = uiColor.fromColor(Colors.red);
                    spotColor    = uiColor.fromColor(Colors.red);
                }
                else
                {
                    ambientColor = uiColor.fromColor(Colors.green);
                    spotColor    = uiColor.fromColor(Colors.green);
                }
            }
            #pragma warning restore CS0162

            //ambient light
            float devSpaceOutset = ambientBlurRadius(zPlaneParams.z);
            float oneOverA       = ambientRecipAlpha(zPlaneParams.z);
            float blurRadius     = 0.5f * devSpaceOutset * oneOverA;
            float strokeWidth    = 0.5f * (devSpaceOutset - blurRadius);

            _shadowPaint.color       = new Color(ambientColor.value);
            _shadowPaint.strokeWidth = strokeWidth;
            _shadowPaint.style       = PaintingStyle.fill;
            canvas.drawPath(path, _shadowPaint);

            //spot light
            float radius = 0.0f;
            if (!getSpotShadowTransform(devLightPos, lightRadius, viewMatrix, zPlaneParams, path.getBounds(),
                                        _shadowMatrix, ref radius))
            {
                return;
            }

            canvas.save();
            canvas.setMatrix(_shadowMatrix);

            _shadowPaint.color       = new Color(spotColor.value);
            _shadowPaint.strokeWidth = 0;
            _shadowPaint.style       = PaintingStyle.fill;
            float sigma2 = convertRadiusToSigma(radius);
            _shadowPaint.maskFilter = path.isNaiveRRect ? MaskFilter.fastShadow(sigma2) : MaskFilter.blur(BlurStyle.normal, sigma2);
            canvas.drawPath(path, _shadowPaint);

            canvas.restore();

            _shadowPaint.maskFilter = null;
        }
示例#4
0
 public static void drawShadow(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
                               float lightRadius, uiColor ambientColor, uiColor spotColor, int flags)
 {
     if (kUseFastShadow)
     {
         drawShadowFast(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);
     }
     else
     {
         drawShadowFull(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);
     }
 }
示例#5
0
        static void drawShadowFull(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
                                   float lightRadius, uiColor ambientColor, uiColor spotColor, int flags)
        {
            Matrix3 viewMatrix = canvas.getTotalMatrix();

            //ambient light
            _devSpacePath.resetAll();
            _devSpacePath.addPath(path, viewMatrix);
            float devSpaceOutset = ambientBlurRadius(zPlaneParams.z);
            float oneOverA       = ambientRecipAlpha(zPlaneParams.z);
            float blurRadius     = 0.5f * devSpaceOutset * oneOverA;
            float strokeWidth    = 0.5f * (devSpaceOutset - blurRadius);

            //Paint paint = new Paint {color = ambientColor, strokeWidth = strokeWidth, style = PaintingStyle.fill};
            _shadowPaint.color       = new Color(ambientColor.value);
            _shadowPaint.strokeWidth = strokeWidth;
            _shadowPaint.style       = PaintingStyle.fill;

            canvas.save();
            _shadowMatrix.reset();
            canvas.setMatrix(_shadowMatrix);
            float sigma = convertRadiusToSigma(blurRadius);

            _shadowPaint.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma);
            canvas.drawPath(_devSpacePath, _shadowPaint);
            canvas.restore();

            //spot light
            //Matrix3 shadowMatrix = Matrix3.I();
            float radius = 0.0f;

            if (!getSpotShadowTransform(devLightPos, lightRadius, viewMatrix, zPlaneParams, path.getBounds(),
                                        _shadowMatrix, ref radius))
            {
                return;
            }

            canvas.save();
            canvas.setMatrix(_shadowMatrix);

            _shadowPaint.color       = new Color(spotColor.value);
            _shadowPaint.strokeWidth = 0;
            _shadowPaint.style       = PaintingStyle.fill;
            float sigma2 = convertRadiusToSigma(radius);

            _shadowPaint.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma2);
            canvas.drawPath(path, _shadowPaint);

            canvas.restore();

            _shadowPaint.maskFilter = null;
        }
示例#6
0
文件: paint.cs 项目: JC-ut0/CubeGame
 public uiPaint(uiPaint paint)
 {
     this.color            = paint.color;
     this.blendMode        = paint.blendMode;
     this.style            = paint.style;
     this.strokeWidth      = paint.strokeWidth;
     this.strokeCap        = paint.strokeCap;
     this.strokeJoin       = paint.strokeJoin;
     this.strokeMiterLimit = paint.strokeMiterLimit;
     this.filterMode       = paint.filterMode;
     this.colorFilter      = paint.colorFilter;
     this.maskFilter       = paint.maskFilter;
     this.backdrop         = paint.backdrop;
     this.shader           = paint.shader;
     this.invertColors     = paint.invertColors;
 }
示例#7
0
        static void drawShadowFast(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
                                   float lightRadius, uiColor ambientColor, uiColor spotColor, int flags)
        {
            Matrix3 viewMatrix = canvas.getTotalMatrix();

            //ambient light
            float devSpaceOutset = ambientBlurRadius(zPlaneParams.z);
            float oneOverA       = ambientRecipAlpha(zPlaneParams.z);
            float blurRadius     = 0.5f * devSpaceOutset * oneOverA;
            float strokeWidth    = 0.5f * (devSpaceOutset - blurRadius);

            //Paint paint = new Paint {color = ambientColor, strokeWidth = strokeWidth, style = PaintingStyle.fill};
            _shadowPaint.color       = new Color(ambientColor.value);
            _shadowPaint.strokeWidth = strokeWidth;
            _shadowPaint.style       = PaintingStyle.fill;
            canvas.drawPath(path, _shadowPaint);

            //spot light
            float radius = 0.0f;

            if (!getSpotShadowTransform(devLightPos, lightRadius, viewMatrix, zPlaneParams, path.getBounds(),
                                        _shadowMatrix, ref radius))
            {
                return;
            }

            canvas.save();
            canvas.setMatrix(_shadowMatrix);
            //Paint paint2 = new Paint {color = spotColor};
            _shadowPaint.color       = new Color(spotColor.value);
            _shadowPaint.strokeWidth = 0;
            _shadowPaint.style       = PaintingStyle.fill;
            canvas.drawPath(path, _shadowPaint);

            canvas.restore();
        }
示例#8
0
        public static PictureFlusher.CmdDraw fastShadow(PictureFlusher.RenderLayer layer, uiMeshMesh mesh, float sigma,
                                                        bool isRect, bool isCircle, float corner, Vector4 bound, uiColor color)
        {
            Vector4 viewport = layer.viewport;
            var     mat      = _shadowBox;

            if (!isRect)
            {
                mat = _shadowRBox;
            }

            var props = ObjectPool <MaterialPropertyBlockWrapper> .alloc();

            props.SetVector(_viewportId, viewport);
            props.SetFloat(_shadowSigmaId, sigma);
            props.SetVector(_shadowBoxId, bound);
            props.SetVector(_shadowColorId, _colorToVector4(color));
            if (!isRect)
            {
                props.SetFloat(_shadowCornerId, corner);
            }

            return(PictureFlusher.CmdDraw.create(
                       mesh: mesh,
                       pass: 0,
                       material: mat,
                       properties: props
                       ));
        }
示例#9
0
文件: paint.cs 项目: JC-ut0/CubeGame
 public static uiColorFilter mode(uiColor color, BlendMode blendMode)
 {
     return(new uiColorFilter(color, blendMode));
 }
示例#10
0
文件: paint.cs 项目: JC-ut0/CubeGame
 uiColorFilter(uiColor color, BlendMode blendMode)
 {
     this.color     = color;
     this.blendMode = blendMode;
 }
示例#11
0
 public static void computeTonalColors(uiColor inAmbientColor, uiColor inSpotColor,
                                       ref uiColor?outAmbientColor, ref uiColor?outSpotColor)
 {
     outAmbientColor = uiColor.fromARGB(inAmbientColor.alpha, 0, 0, 0);
     outSpotColor    = inSpotColor;
 }