示例#1
0
        /// <summary>
        /// Clips the rects so that the destination's bitmap's clipping boundaries aren't exceeded.
        /// If the destination rect needs to be clipped, the source rect must be clipped accordingly.
        /// </summary>
        /// <param name="a_rctSrc">The rect to blit</param>
        /// <param name="a_rctDst">The requested destination rect</param>
        /// <param name="a_rctDstClip">The destination clipping rect</param>
        /// <param name="a_rctNewSrc">The resulting source rect</param>
        /// <param name="a_rctNewDst">The resulting destination rect</param>
        static private void CalcClippedRects(
            ERectangle a_rctSrc, ERectangleF a_rctDst, ERectangle a_rctDstClip,
            out ERectangle a_rctNewSrc, out ERectangle a_rctNewDst)
        {
            ERectangleF rctNewDstTmp = a_rctDst.Copy();
            //a_rctDstClip - the srcClip of the dest sprite

            ERectangleF rctDstClipTmp = new ERectangleF((float)a_rctDstClip.X, (float)a_rctDstClip.Y, (float)a_rctDstClip.Width, (float)a_rctDstClip.Height);

            rctNewDstTmp.Intersect(rctDstClipTmp);
            a_rctNewDst = new ERectangle((int)rctNewDstTmp.X, (int)rctNewDstTmp.Y, (int)rctNewDstTmp.Width, (int)rctNewDstTmp.Height);
            //and if so, the src clip must be adjusted accordingly:
            ERectangleF rctDiff = new ERectangleF(
                rctNewDstTmp.Left - a_rctDst.Left,
                rctNewDstTmp.Top - a_rctDst.Top,
                rctNewDstTmp.Width - a_rctDst.Width,
                rctNewDstTmp.Height - a_rctDst.Height);

            PointF     pntScale      = new PointF(a_rctSrc.Width / a_rctDst.Width, a_rctSrc.Height / a_rctDst.Height);
            ERectangle rctTmpSrcClip = a_rctSrc.Copy();

            rctTmpSrcClip.X      = a_rctSrc.X + (int)(pntScale.X * rctDiff.X);
            rctTmpSrcClip.Width  = a_rctSrc.Width + (int)(pntScale.X * rctDiff.Width);
            rctTmpSrcClip.Y      = a_rctSrc.Y + (int)(pntScale.Y * rctDiff.Y);
            rctTmpSrcClip.Height = a_rctSrc.Height + (int)(pntScale.Y * rctDiff.Height);

            if (rctTmpSrcClip.X < 0)
            {
                rctTmpSrcClip.X = 0;
            }

            a_rctNewSrc = rctTmpSrcClip;
        }
示例#2
0
        public bool IntersectsWith(ERectangleF rct)
        {
            ERectangleF rctNew = this.Copy();

            rctNew.Intersect(rct);
            return(!(rctNew.IsNegative || rctNew.IsEmpty));
        }