FairyGUI.UpdateContext.EnterClipping C# (CSharp) Method

EnterClipping() public method

public EnterClipping ( uint clipId, Rect clipRect, Vector4 softness ) : void
clipId uint
clipRect UnityEngine.Rect
softness UnityEngine.Vector4
return void
        public void EnterClipping(uint clipId, Rect? clipRect, Vector4? softness)
        {
            _clipStack.Push(clipInfo);

            if (clipRect == null)
            {
                if (stencilReferenceValue == 0)
                    stencilReferenceValue = 1;
                else
                    stencilReferenceValue = stencilReferenceValue << 1;
                clipInfo.clipId = clipId;
                clipInfo.stencil = true;
                clipped = true;
            }
            else
            {
                Rect rect = (Rect)clipRect;
                if (rectMaskDepth > 0)
                    rect = ToolSet.Intersection(ref clipInfo.rect, ref rect);

                rectMaskDepth++;
                clipInfo.stencil = false;
                clipped = true;

                /* clipPos = xy * clipBox.zw + clipBox.xy
                    * 利用这个公式,使clipPos变为当前顶点距离剪切区域中心的距离值,剪切区域的大小为2x2
                    * 那么abs(clipPos)>1的都是在剪切区域外
                    */

                clipInfo.rect = rect;
                rect.x = rect.x + rect.width / 2f;
                rect.y = rect.y + rect.height / 2f;
                rect.width /= 2f;
                rect.height /= 2f;
                if (rect.width == 0 || rect.height == 0)
                    clipInfo.clipBox = new Vector4(-2, -2, 0, 0);
                else
                    clipInfo.clipBox = new Vector4(-rect.x / rect.width, -rect.y / rect.height,
                        1.0f / rect.width, 1.0f / rect.height);
                clipInfo.clipId = clipId;
                clipInfo.soft = softness != null;
                if (clipInfo.soft)
                {
                    clipInfo.softness = (Vector4)softness;
                    float vx = clipInfo.rect.width * Screen.height * 0.25f;
                    float vy = clipInfo.rect.height * Screen.height * 0.25f;

                    if (clipInfo.softness.x > 0)
                        clipInfo.softness.x = vx / clipInfo.softness.x;
                    else
                        clipInfo.softness.x = 10000f;

                    if (clipInfo.softness.y > 0)
                        clipInfo.softness.y = vy / clipInfo.softness.y;
                    else
                        clipInfo.softness.y = 10000f;

                    if (clipInfo.softness.z > 0)
                        clipInfo.softness.z = vx / clipInfo.softness.z;
                    else
                        clipInfo.softness.z = 10000f;

                    if (clipInfo.softness.w > 0)
                        clipInfo.softness.w = vy / clipInfo.softness.w;
                    else
                        clipInfo.softness.w = 10000f;
                }
            }
        }

Usage Example

示例#1
0
        override public void Update(UpdateContext context)
        {
            base.Update(context);

            if (_paintingMode != 0 && paintingGraphics.texture != null)
            {
                context.PushRenderTarget(paintingGraphics.texture, new Vector2(_renderRect.x, _renderRect.y));
            }

            if (_clipRect != null)
            {
                //在这里可以直接使用 _localToWorldMatrix, 因为已经更新
                Rect      clipRect = (Rect)_clipRect;
                Matrix4x4 mat      = Matrix4x4.Identity;
                ToolSet.TransformRect(ref clipRect, ref _localToWorldMatrix, ref mat);
                context.EnterClipping(this.id, clipRect);
            }

            float savedAlpha = context.alpha;

            context.alpha *= this.alpha;
            bool savedGrayed = context.grayed;

            context.grayed = context.grayed || this.grayed;

            int cnt = _children.Count;

            for (int i = 0; i < cnt; i++)
            {
                DisplayObject child = _children[i];
                if (child.visible)
                {
                    child.Update(context);
                }
            }

            if (_clipRect != null)
            {
                context.LeaveClipping();
            }

            if (_paintingMode != 0 && paintingGraphics.texture != null)
            {
                context.PopRenderTarget();
                paintingGraphics.Render(_renderRect, _renderScale, _renderRotation, 1, context);
            }

            context.alpha  = savedAlpha;
            context.grayed = savedGrayed;
        }
All Usage Examples Of FairyGUI.UpdateContext::EnterClipping