Esempio n. 1
0
            public override void ApplyState()
            {
                base.ApplyState();

                if (!Source.Masking && (Source.BorderThickness != 0.0f || edgeEffect.Type != EdgeEffectType.None))
                {
                    throw new InvalidOperationException("Can not have border effects/edge effects if masking is disabled.");
                }

                Vector3 scale = DrawInfo.MatrixInverse.ExtractScale();

                maskingInfo = !Source.Masking
                    ? (MaskingInfo?)null
                    : new MaskingInfo
                {
                    ScreenSpaceAABB = Source.ScreenSpaceDrawQuad.AABB,
                    MaskingRect     = Source.DrawRectangle,
                    ToMaskingSpace  = DrawInfo.MatrixInverse,
                    CornerRadius    = Source.CornerRadius,
                    BorderThickness = Source.BorderThickness,
                    BorderColour    = Source.BorderColour,
                    // We are setting the linear blend range to the approximate size of a _pixel_ here.
                    // This results in the optimal trade-off between crispness and smoothness of the
                    // edges of the masked region according to sampling theory.
                    BlendRange    = Source.MaskingSmoothness * (scale.X + scale.Y) / 2,
                    AlphaExponent = 1,
                };

                edgeEffect             = Source.EdgeEffect;
                screenSpaceMaskingQuad = null;
                Shader = Source.Shader;
                forceLocalVertexBatch = Source.ForceLocalVertexBatch;
            }
            public override void ApplyState()
            {
                base.ApplyState();

                if (!Source.Masking && (Source.BorderThickness != 0.0f || Source.EdgeEffect.Type != EdgeEffectType.None))
                {
                    throw new InvalidOperationException("Can not have border effects/edge effects if masking is disabled.");
                }

                Vector3 scale      = DrawInfo.MatrixInverse.ExtractScale();
                float   blendRange = Source.MaskingSmoothness * (scale.X + scale.Y) / 2;

                // Calculate a shrunk rectangle which is free from corner radius/smoothing/border effects
                float shrinkage = Source.CornerRadius - Source.CornerRadius * cos_45 + blendRange + Source.borderThickness;

                // Normalise to handle negative sizes, and clamp the shrinkage to prevent size from going negative.
                RectangleF shrunkDrawRectangle = Source.DrawRectangle.Normalize();

                shrunkDrawRectangle = shrunkDrawRectangle.Shrink(new Vector2(Math.Min(shrunkDrawRectangle.Width / 2, shrinkage), Math.Min(shrunkDrawRectangle.Height / 2, shrinkage)));

                maskingInfo = !Source.Masking
                    ? (MaskingInfo?)null
                    : new MaskingInfo
                {
                    ScreenSpaceAABB             = Source.ScreenSpaceDrawQuad.AABB,
                    MaskingRect                 = Source.DrawRectangle.Normalize(),
                    ConservativeScreenSpaceQuad = Quad.FromRectangle(shrunkDrawRectangle) * DrawInfo.Matrix,
                    ToMaskingSpace              = DrawInfo.MatrixInverse,
                    CornerRadius                = Source.effectiveCornerRadius,
                    CornerExponent              = Source.CornerExponent,
                    BorderThickness             = Source.BorderThickness,
                    BorderColour                = Source.BorderColour,
                    // We are setting the linear blend range to the approximate size of a _pixel_ here.
                    // This results in the optimal trade-off between crispness and smoothness of the
                    // edges of the masked region according to sampling theory.
                    BlendRange    = blendRange,
                    AlphaExponent = 1,
                };

                edgeEffect             = Source.EdgeEffect;
                screenSpaceMaskingQuad = null;
                Shader = Source.Shader;
                forceLocalVertexBatch = Source.ForceLocalVertexBatch;
                sourceChildrenCount   = Source.internalChildren.Count;
            }