Ejemplo n.º 1
0
        public bool IntersectsWith(ERectangleF rct)
        {
            ERectangleF rctNew = this.Copy();

            rctNew.Intersect(rct);
            return(!(rctNew.IsNegative || rctNew.IsEmpty));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Expands the rectangle if needed so that it completely encloses rct
 /// If it had negative height or width, it stays that way.
 /// </summary>
 /// <param name="rct"></param>
 public void ExpandSpecial(ERectangleF rct)
 {
     this.Left   = rct.Left < this.Left?rct.Left:this.Left;
     this.Top    = rct.Top < this.Top?rct.Top:this.Top;
     this.Right  = rct.Right > this.Right?rct.Right:this.Right;
     this.Bottom = rct.Bottom > this.Bottom?rct.Bottom:this.Bottom;
 }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        protected void AdjustVertices()
        {
            if (m_sp.Member == null)
            {
                return;
            }
            if (vertexBuffer == null)
            {
                return;
            }

            float[,] aUVs = GenerateUVs();

            ERectangleF rct = new ERectangleF(0, 0, 1, 1);

            CustomVertex[] vertices = null;
            try
            {
                vertices = vertexBuffer.Lock(0, 0) as CustomVertex[];
            }
            catch (Exception e)
            {
                //TODO: why does this happen??
                return;
                //throw new Exception("Failed to lock buffer...");
            }
            int nColor = System.Drawing.Color.FromArgb(255, 255, 0, 120).ToArgb();                //255,255,255,255

            vertices[0] = new CustomVertex(rct.Left, rct.Top, 0.0f, aUVs[0, 0], aUVs[0, 1]);      //,      nColor);
            vertices[1] = new CustomVertex(rct.Right, rct.Top, 0.0f, aUVs[1, 0], aUVs[1, 1]);     //,      nColor);
            vertices[2] = new CustomVertex(rct.Left, -rct.Bottom, 0.0f, aUVs[3, 0], aUVs[3, 1]);  //,nColor);
            vertices[3] = new CustomVertex(rct.Right, -rct.Bottom, 0.0f, aUVs[2, 0], aUVs[2, 1]); //,nColor);
            vertexBuffer.Unlock();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get the rectangle that completely encompasses all child sprites (and optionally their children)
        /// </summary>
        /// <returns></returns>
        public ERectangleF GetBoundingRectangle(bool includeChildrensBounds, bool onlyThoseWithMembers, bool includeThis)
        {
            ERectangleF rct = ERectangleF.FromLTRB(9999999, 9999999, -9999999, -9999999);

            if (includeThis)
            {
                if ((onlyThoseWithMembers && this.Member != null) || !onlyThoseWithMembers)
                {
                    rct.Expand(this.Rect);
                }
            }

            for (int i = this.ChildCount - 1; i >= 0; i--)
            {
                Sprite sp = this.GetChildByIndex(i);

                if ((onlyThoseWithMembers && this.Member != null) || !onlyThoseWithMembers)
                {
                    rct.Expand(sp.Rect);
                }

                if (includeChildrensBounds)
                {
                    rct.Expand(sp.GetBoundingRectangle(true, onlyThoseWithMembers, false));
                }
            }
            return(rct);
        }
Ejemplo n.º 6
0
        public ERectangleF GetPortionOfMemberToDisplay()
        {
            //TODO: doesn't care about SrcCrop!
            ERectangleF rctfCropped;

            EPoint size      = Member.Size; // Member.TotalSize;
            EPoint sizeFrame = Member.Size;
            EPoint sizeReal  = size;        //GetUpperPowerTextureSize(size);

            //if (Member.GotAnimation)
            //{
            //    ERectangle rctAnim = SourceRect;

            //    rctfCropped = new ERectangleF((float)rctAnim.X/sizeReal.X, (float)rctAnim.Y/sizeReal.Y,
            //        (float)rctAnim.Width/sizeReal.X, (float)rctAnim.Height/sizeReal.Y);
            //}
            //else
            //{
            ERectangle rctAnim = SourceRect;

            rctfCropped = new ERectangleF((float)rctAnim.X / sizeReal.X, (float)rctAnim.Y / sizeReal.Y,
                                          (float)rctAnim.Width / sizeReal.X, (float)rctAnim.Height / sizeReal.Y);
            //}

            return(rctfCropped);
        }
Ejemplo n.º 7
0
        //public static bool operator ==(ERectangleF r1, ERectangleF r2)
        //{
        //    if (r1.Equals(null))
        //        return (r2.Equals(null));
        //    else if (r2.Equals(null))
        //        return false;
        //    return (r1.X == r2.X && r1.Y == r2.Y && r1.Width == r2.Width && r1.Height == r2.Height);
        //}
        //public static bool operator !=(ERectangleF r1, ERectangleF r2)
        //{
        //    if (r1.Equals(null))
        //        return !(r2.Equals(null));
        //    else if (r2.Equals(null))
        //        return true;
        //    return !(r1.X == r2.X && r1.Y == r2.Y && r1.Width == r2.Width && r1.Height == r2.Height);
        //}

        //TODO: how to override ==? I must be able to check r == null... and that leads to infinite loop!
        public bool IsEqualTo(ERectangleF r)
        {
            if (r == null)
            {
                return(false);
            }
            return(r.X == this.X && r.Y == this.Y && r.Width == this.Width && r.Height == this.Height);
        }
Ejemplo n.º 8
0
 public Quad(ERectangleF rct)
 {
     this._points    = new EPointF[4];
     this._points[0] = rct.TopLeft;
     this._points[1] = new EPointF(rct.Right, rct.Top);
     this._points[2] = rct.BottomRight;
     this._points[3] = new EPointF(rct.Left, rct.Bottom);
 }
Ejemplo n.º 9
0
 public Quad(ERectangleF rct)
 {
     this._points = new EPointF[4];
     this._points[0] = rct.TopLeft;
     this._points[1] = new EPointF(rct.Right, rct.Top);
     this._points[2] = rct.BottomRight;
     this._points[3] = new EPointF(rct.Left, rct.Bottom);
 }
Ejemplo n.º 10
0
 public void AddArea(ERectangleF rctConstraint, ERectangleF rctSnap, bool bConstrainRectInsteadOfPoint, object tag)
 {
     ConstrainArea area = new ConstrainArea();
     area.Constraint = rctConstraint;
     area.Snap = rctSnap;
     area.ConstrainRectInsteadOfPoint = bConstrainRectInsteadOfPoint;
     area.Tag = tag;
     this.AddArea(area);
 }
Ejemplo n.º 11
0
        public override void EnterFrame()
        {
            base.EnterFrame();

            ERectangleF rct = new ERectangleF(0,0,640,480);
            EPointF loc = this.ConvParentLocToRootLoc(Loc);
            rct.WrapPointInside(loc);
            Loc = this.ConvRootLocToParentLoc(loc);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Will expand this rectangle to enclose the provided rct.  Actually, a more natural name would be Union I think.
        /// </summary>
        /// <param name="rct"></param>
        public void Expand(ERectangleF rct)
        {
            float oX = this.OppositeX;
            float oY = this.OppositeY;

            x = Math.Min(x, rct.X);
            y = Math.Min(y, rct.Y);

            this.OppositeX = Math.Max(oX, rct.OppositeX);
            this.OppositeY = Math.Max(oY, rct.OppositeY);
        }
 private MeterXY Create2DMeter(ERectangleF rct, string prop, float limit)
 {
     MeterXY xy = new MeterXY();
     xy.Rect = rct;
     xy.SetAutoFetch(this._car, prop);
     xy.RangeX.MinIn = -limit;
     xy.RangeX.MaxIn = limit;
     xy.RangeY.MinIn = -limit;
     xy.RangeY.MaxIn = limit;
     return xy;
 }
Ejemplo n.º 14
0
        public EPointF MapPointFromRectAToRectB(EPointF a_pnt, ERectangleF a_rctA, ERectangleF a_rctB)
        {
            EPointF pntNew = new EPointF(a_pnt.X - a_rctA.Left, a_pnt.Y - a_rctA.Top);

            pntNew.X /= a_rctA.Width;
            pntNew.Y /= a_rctA.Height;

            pntNew.X = pntNew.X * a_rctB.Width + a_rctB.Left;
            pntNew.Y = pntNew.Y * a_rctB.Height + a_rctB.Top;
            return(pntNew);
        }
Ejemplo n.º 15
0
        private void Init(bool bAutoSetParent)
        {
            m_aChildrenToRemove        = new ArrayList();
            m_plChildrenByHash         = new Hashtable();
            this._slChildrenLocZSorted = new SortedFloatList();

            m_sID    = "";
            m_nInk   = (int)RasterOps.ROPs.Copy;
            m_nBlend = 255;


            m_matrix = new Matrix4();
            m_vPivot = new Vector3();

            m_fLocZ       = 0.0f;
            m_pntLoc      = new EPointF(0.0f, 0.0f);
            m_pntScale    = new EPointF(1.0f, 1.0f);
            m_pntRegPoint = new EPoint(0, 0);


            m_rctSrcClip   = new ERectangle(0, 0, 1, 1);
            m_clr          = Color.White;
            m_rctDstParent = new ERectangleF(0, 0, 0, 0);

            m_aBehaviors = new ArrayList();

            m_nMemberAnimFrame = 0;

            m_dtChildren = new DataTable();
            m_dtChildren.Columns.Add("Name", typeof(System.String));
            m_dtChildren.Columns.Add("LocZ", typeof(System.Double));
            m_dtChildren.Columns.Add("Hash", typeof(System.Int32));

            m_pntMouseDown = new EPoint();
            m_pntMouseLast = new EPoint();
            _pntMouse      = new EPoint();

            if (bAutoSetParent && m_endogine != null && m_endogine.Stage != null)
            {
                Parent = m_endogine.Stage.DefaultParent;
            }

            m_renderStrategy = m_endogine.Stage.CreateRenderStrategy();

            m_renderStrategy.SetEndogine(m_endogine);
            m_renderStrategy.SetSprite(this);
            m_renderStrategy.Init();

            //TODO: make this optional (takes some resources)
            Sprite[] lcs = new Sprite[1];
            lcs[0] = this;
            EH.Instance.LatestCreatedSprites = lcs;
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Transforms a point in a rectangle to where it would be in the quad
 /// </summary>
 /// <param name="pnt"></param>
 /// <param name="rect"></param>
 /// <returns></returns>
 public EPointF MapFromRect(EPointF pnt, ERectangleF rect)
 {
     EPointF fract = pnt / rect.Size;
     EPointF pntTopOfQuadAtX = (this._points[1] - this._points[0])*fract.X + this._points[0];
     EPointF pntBottomOfQuadAtX = (this._points[2] - this._points[3]) * fract.X + this._points[3];
     EPointF inQuad = (pntBottomOfQuadAtX - pntTopOfQuadAtX) * fract.Y + pntTopOfQuadAtX;
     return inQuad;
     //pntFract = point(float(a_pnt[1])/a_rct.width, float(a_pnt[2])/a_rct.height)
     //pntTopOfQuadAtX = (a_aQuad[2]-a_aQuad[1])*pntFract[1]+a_aQuad[1]
     //pntBottomOfQuadAtX = (a_aQuad[3]-a_aQuad[4])*pntFract[1]+a_aQuad[4]
     //return (pntBottomOfQuadAtX-pntTopOfQuadAtX)*pntFract[2] + pntTopOfQuadAtX
 }
Ejemplo n.º 17
0
        static public void CopyPixels(Bitmap a_bmpDst, Bitmap a_bmpSrc,
                                      ERectangleF a_rctDst, ERectangle a_rctSrc, ERectangle a_rctDstClip, int a_nInk, int a_nBlend)
        {
            ERectangle rctNewSrc, rctNewDst;

            CalcClippedRects(a_rctSrc, a_rctDst, a_rctDstClip, out rctNewSrc, out rctNewDst);
            if (rctNewDst.Width <= 0 || rctNewDst.Height <= 0 || rctNewSrc.Width <= 0 || rctNewSrc.Height <= 0)
            {
                return;
            }

            BitmapData bmpdtDst = null, bmpdtSrc = null;

            try
            {
                bmpdtDst = a_bmpDst.LockBits(new Rectangle(0, 0, a_bmpDst.Width, a_bmpDst.Height),              //rctNewDst,
                                             System.Drawing.Imaging.ImageLockMode.ReadWrite,
                                             a_bmpDst.PixelFormat);
                bmpdtSrc = a_bmpSrc.LockBits(new Rectangle(0, 0, a_bmpSrc.Width, a_bmpSrc.Height),              //rctNewSrc,
                                             System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                             a_bmpSrc.PixelFormat);
            }
            catch
            {
                if (bmpdtDst != null)
                {
                    a_bmpDst.UnlockBits(bmpdtDst);
                }
                if (bmpdtSrc != null)
                {
                    a_bmpSrc.UnlockBits(bmpdtSrc);
                }

                return;
            }

            int nBytesPerPixelDst = (a_bmpDst.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)?3:
                                    ((a_bmpDst.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)?1:4);
            int nBytesPerPixelSrc = (a_bmpSrc.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)?3:
                                    ((a_bmpSrc.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)?1:4);

//				((a_bmpSrc.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)?8:32);
            unsafe
            {
                BlitWithOps((byte *)bmpdtSrc.Scan0, (byte *)bmpdtDst.Scan0,
                            rctNewSrc, rctNewDst, bmpdtSrc.Stride, bmpdtDst.Stride,
                            nBytesPerPixelSrc, nBytesPerPixelDst, a_nInk, a_nBlend);
            }

            a_bmpDst.UnlockBits(bmpdtDst);
            a_bmpSrc.UnlockBits(bmpdtDst);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Transforms a point in a rectangle to where it would be in the quad
        /// </summary>
        /// <param name="pnt"></param>
        /// <param name="rect"></param>
        /// <returns></returns>
        public EPointF MapFromRect(EPointF pnt, ERectangleF rect)
        {
            EPointF fract              = pnt / rect.Size;
            EPointF pntTopOfQuadAtX    = (this._points[1] - this._points[0]) * fract.X + this._points[0];
            EPointF pntBottomOfQuadAtX = (this._points[2] - this._points[3]) * fract.X + this._points[3];
            EPointF inQuad             = (pntBottomOfQuadAtX - pntTopOfQuadAtX) * fract.Y + pntTopOfQuadAtX;

            return(inQuad);
            //pntFract = point(float(a_pnt[1])/a_rct.width, float(a_pnt[2])/a_rct.height)
            //pntTopOfQuadAtX = (a_aQuad[2]-a_aQuad[1])*pntFract[1]+a_aQuad[1]
            //pntBottomOfQuadAtX = (a_aQuad[3]-a_aQuad[4])*pntFract[1]+a_aQuad[4]
            //return (pntBottomOfQuadAtX-pntTopOfQuadAtX)*pntFract[2] + pntTopOfQuadAtX
        }
Ejemplo n.º 19
0
        protected float[,] GenerateUVs()
        {
            ERectangleF rctfCropped = m_sp.GetPortionOfMemberToDisplay();

            float tXOffset = 0f;             //.5f/sizeReal.Width;
            float tYOffset = 0f;             //.5f/sizeReal.Height;

            float[,] tUVs = new float[, ] {
                { rctfCropped.X + tXOffset, rctfCropped.Y + tYOffset },
                { rctfCropped.OppositeX - tXOffset, rctfCropped.Y + tYOffset },
                { rctfCropped.OppositeX - tXOffset, rctfCropped.OppositeY - tYOffset },
                { rctfCropped.X + tXOffset, rctfCropped.OppositeY - tYOffset }
            };

            return(tUVs);
        }
Ejemplo n.º 20
0
        public void Intersect(ERectangleF rct)
        {
//			if (rct.Left>this.Left)
//				this.Left = rct.Left;
//			if (rct.Top>this.Top)
//				this.Top = rct.Top;
//			if (rct.Right<this.Right)
//				this.Right = rct.Right;
//			if (rct.Bottom<this.Bottom)
//				this.Bottom = rct.Bottom;
            float oY = this.OppositeY;
            float oX = this.OppositeX;

            x = Math.Max(rct.X, x);
            y = Math.Max(rct.Y, y);
            this.OppositeY = Math.Min(rct.OppositeY, oY);
            this.OppositeX = Math.Min(rct.OppositeX, oX);
        }
Ejemplo n.º 21
0
        public void SetLine(EPointF a_pnt1, EPointF a_pnt2)
        {
            m_rct = ERectangleF.FromLTRB(a_pnt1.X, a_pnt1.Y, a_pnt2.X, a_pnt2.Y);
            if (Member!=null)
                Member.Dispose();

            Loc = m_rct.Location;

            Bitmap bmp = new Bitmap((int)Math.Abs(m_rct.Width),(int)Math.Abs(m_rct.Height), PixelFormat.Format24bppRgb);
            Graphics g = Graphics.FromImage(bmp);
            //Point pnt1 = a_pnt1;
            //if (a_pnt1.Y <= a_pnt2.Y && a_pnt1.X <= a_pnt2.X)
            g.DrawLine(new Pen(Color.White, 1), new Point(0,0), new Point((int)m_rct.Width, (int)m_rct.Height));
            g.Dispose();

            MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp);
            Member = mb;
        }
Ejemplo n.º 22
0
        public static void CopyPixels(Bitmap a_bmpDst, Bitmap a_bmpSrc,
            ERectangleF a_rctDst, ERectangle a_rctSrc, ERectangle a_rctDstClip, int a_nInk, int a_nBlend)
        {
            ERectangle rctNewSrc, rctNewDst;

            CalcClippedRects(a_rctSrc, a_rctDst, a_rctDstClip, out rctNewSrc, out rctNewDst);
            if (rctNewDst.Width <= 0 || rctNewDst.Height <= 0 || rctNewSrc.Width <= 0 || rctNewSrc.Height <= 0)
                return;

            BitmapData bmpdtDst = null, bmpdtSrc = null;
            try
            {
                bmpdtDst = a_bmpDst.LockBits(new Rectangle(0,0,a_bmpDst.Width,a_bmpDst.Height), //rctNewDst,
                    System.Drawing.Imaging.ImageLockMode.ReadWrite,
                    a_bmpDst.PixelFormat);
                bmpdtSrc = a_bmpSrc.LockBits(new Rectangle(0,0,a_bmpSrc.Width,a_bmpSrc.Height), //rctNewSrc,
                    System.Drawing.Imaging.ImageLockMode.ReadOnly,
                    a_bmpSrc.PixelFormat);
            }
            catch
            {
                if (bmpdtDst != null)
                    a_bmpDst.UnlockBits(bmpdtDst);
                if (bmpdtSrc != null)
                    a_bmpSrc.UnlockBits(bmpdtSrc);

                return;
            }

            int nBytesPerPixelDst = (a_bmpDst.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)?3:
                ((a_bmpDst.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)?1:4);
            int nBytesPerPixelSrc = (a_bmpSrc.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)?3:
                ((a_bmpSrc.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)?1:4);
            //				((a_bmpSrc.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)?8:32);
            unsafe
            {
                BlitWithOps((byte*)bmpdtSrc.Scan0, (byte*)bmpdtDst.Scan0,
                    rctNewSrc, rctNewDst, bmpdtSrc.Stride, bmpdtDst.Stride,
                    nBytesPerPixelSrc, nBytesPerPixelDst, a_nInk, a_nBlend);
            }

            a_bmpDst.UnlockBits(bmpdtDst);
            a_bmpSrc.UnlockBits(bmpdtDst);
        }
Ejemplo n.º 23
0
        public virtual void CalcInParent()
        {
            m_rctDstParent = m_rctSrcClip.ToERectangleF();

            m_rctDstParent.X      *= m_pntScale.X;
            m_rctDstParent.Y      *= m_pntScale.Y;
            m_rctDstParent.Width  *= m_pntScale.X;
            m_rctDstParent.Height *= m_pntScale.Y;

            //TODO: use sprite pntLoc instead of member's! (hm, did I mean regPoint instead of pntLoc??)
            //if (Member != null)

            m_rctDstParent.Offset(m_pntLoc.X - (m_pntRegPoint.X + this._regPointInternal.X) * m_pntScale.X, m_pntLoc.Y - (m_pntRegPoint.Y + this._regPointInternal.Y) * m_pntScale.Y);
            //else
            //	m_rctDstParent.Offset(m_pntLoc);

            //if (Member != null && Member.GotAnimation)
            //    m_rctDstParent.Offset(Member.GetOffsetForFrame(this.MemberAnimationFrame).ToEPointF()*-1);

            m_renderStrategy.RecalcedParentOutput();
        }
Ejemplo n.º 24
0
 public void Intersect(ERectangleF rct)
 {
     //			if (rct.Left>this.Left)
     //				this.Left = rct.Left;
     //			if (rct.Top>this.Top)
     //				this.Top = rct.Top;
     //			if (rct.Right<this.Right)
     //				this.Right = rct.Right;
     //			if (rct.Bottom<this.Bottom)
     //				this.Bottom = rct.Bottom;
     float oY = this.OppositeY;
     float oX = this.OppositeX;
     x = Math.Max(rct.X, x);
     y = Math.Max(rct.Y, y);
     this.OppositeY = Math.Min(rct.OppositeY, oY);
     this.OppositeX = Math.Min(rct.OppositeX, oX);
 }
Ejemplo n.º 25
0
 protected abstract void SetSourceClipRect(ERectangleF rct);
Ejemplo n.º 26
0
 abstract protected void SetSourceClipRect(ERectangleF rct);
Ejemplo n.º 27
0
        public virtual void CalcInParent()
        {
            m_rctDstParent = m_rctSrcClip.ToERectangleF();

            m_rctDstParent.X *= m_pntScale.X;
            m_rctDstParent.Y *= m_pntScale.Y;
            m_rctDstParent.Width *= m_pntScale.X;
            m_rctDstParent.Height *= m_pntScale.Y;

            //TODO: use sprite pntLoc instead of member's! (hm, did I mean regPoint instead of pntLoc??)
            //if (Member != null)

            m_rctDstParent.Offset(m_pntLoc.X - (m_pntRegPoint.X+this._regPointInternal.X)*m_pntScale.X, m_pntLoc.Y - (m_pntRegPoint.Y+this._regPointInternal.Y)*m_pntScale.Y);
            //else
            //	m_rctDstParent.Offset(m_pntLoc);

            //if (Member != null && Member.GotAnimation)
            //    m_rctDstParent.Offset(Member.GetOffsetForFrame(this.MemberAnimationFrame).ToEPointF()*-1);

            m_renderStrategy.RecalcedParentOutput();
        }
Ejemplo n.º 28
0
 //public static bool operator ==(ERectangleF r1, ERectangleF r2)
 //{
 //    if (r1.Equals(null))
 //        return (r2.Equals(null));
 //    else if (r2.Equals(null))
 //        return false;
 //    return (r1.X == r2.X && r1.Y == r2.Y && r1.Width == r2.Width && r1.Height == r2.Height);
 //}
 //public static bool operator !=(ERectangleF r1, ERectangleF r2)
 //{
 //    if (r1.Equals(null))
 //        return !(r2.Equals(null));
 //    else if (r2.Equals(null))
 //        return true;
 //    return !(r1.X == r2.X && r1.Y == r2.Y && r1.Width == r2.Width && r1.Height == r2.Height);
 //}
 //TODO: how to override ==? I must be able to check r == null... and that leads to infinite loop!
 public bool IsEqualTo(ERectangleF r)
 {
     if (r == null)
         return false;
     return (r.X == this.X && r.Y == this.Y && r.Width == this.Width && r.Height == this.Height);
 }
Ejemplo n.º 29
0
 abstract public void CalcRenderRegion(ERectangleF rctDrawTarget, float rotation, EPoint regPoint, EPoint sourceRectSize);
Ejemplo n.º 30
0
 /// <summary>
 /// Expands the rectangle if needed so that it completely encloses rct
 /// If it had negative height or width, it stays that way.
 /// </summary>
 /// <param name="rct"></param>
 public void ExpandSpecial(ERectangleF rct)
 {
     this.Left = rct.Left<this.Left?rct.Left:this.Left;
     this.Top = rct.Top<this.Top?rct.Top:this.Top;
     this.Right = rct.Right>this.Right?rct.Right:this.Right;
     this.Bottom = rct.Bottom>this.Bottom?rct.Bottom:this.Bottom;
 }
Ejemplo n.º 31
0
        public override void SubDraw()
        {
            ERectangleF rctDraw = m_sp.CalcRectInDrawTarget();
            //TODO: if same rect as last time, use a cached matrix instead of re-calculating all this.

//			if (m_sp.Picture != null)
//			{
//				ERectangleF x = rctDraw.Copy();
//				x.Intersect(new ERectangleF(0,0,600,600));
//				if (!x.IsEmpty && !x.IsNegative)
//				{
//					x.Width+=1;
//				}
//			}


            Matrix QuadMatrix = Matrix.Scaling(rctDraw.Width, rctDraw.Height, 1);

            EPointF pntRegOff = m_sp.RegPoint.ToEPointF() / new EPointF(m_sp.SourceRect.Width, m_sp.SourceRect.Height) * new EPointF(rctDraw.Width, rctDraw.Height);

            QuadMatrix.Multiply(Matrix.Translation(-pntRegOff.X, pntRegOff.Y, 0));
            QuadMatrix.Multiply(Matrix.RotationZ(-m_sp.Rotation));
            QuadMatrix.Multiply(Matrix.Translation(pntRegOff.X, -pntRegOff.Y, 0));

            EPointF pntLoc = new EPointF(rctDraw.X - device.Viewport.Width / 2, rctDraw.Y - device.Viewport.Height / 2);

            QuadMatrix.Multiply(Matrix.Translation(pntLoc.X, -pntLoc.Y, 0f));

            Stage3D stage = ((Stage3D)EH.Instance.Stage);

            stage.ZCurrent += stage.ZStep;
            QuadMatrix.M43  = 10000f - stage.ZCurrent - 1;
            //QuadMatrix.M43 = 10000f-m_sp.LocZ-1;
//			if (this.m_sp.Parent.Name == "Bar" && (this.m_sp.Name == "2;1" || this.m_sp.Name == "2;2"))
//			{
//				this.m_sp.CalcInParent();
//				m_sp.CalcRectInDrawTarget();
//				float x = rctDraw.Bottom;
//				x++;
//			}

            device.Material = m_mtrl;

            //TODO: (in controlling mechanism:) render order by RenderStates somehow? I hear that state changes are expensive
            switch (m_sp.Ink)
            {
            case RasterOps.ROPs.Copy:
                if (this.m_sp.Member.GotAlpha || true)                         //this.m_mtrl.Diffuse.A != 255)
                {
                    device.RenderState.AlphaBlendEnable = true;
                    device.RenderState.SourceBlend      = Blend.SourceAlpha;
                    device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

                    if (this.m_mtrl.Diffuse.A != 255)
                    {
                        device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
                        device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;
                        device.TextureState[0].AlphaOperation = TextureOperation.Modulate;

                        device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                        device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
                        device.TextureState[0].ColorOperation = TextureOperation.Modulate;

                        device.TextureState[1].AlphaOperation = TextureOperation.Disable;
                        device.TextureState[1].ColorOperation = TextureOperation.Disable;
                    }
                }
                else
                {
                    device.RenderState.AlphaBlendEnable = false;
                }
                break;

            case RasterOps.ROPs.AddPin:
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.DestinationBlend = Blend.InvSourceColor;
                device.RenderState.SourceBlend      = Blend.One;
                break;

            case RasterOps.ROPs.Multiply:
                //multiply?
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.BlendOperation   = BlendOperation.Min;                       //device.RenderState.SourceBlend = Blend.DestinationColor same?
                break;

            case RasterOps.ROPs.BgTransparent:
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.SourceBlend      = Blend.SourceAlpha;
                device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

//					if (m_sp.Blend!=255)
//					{
//						device.RenderState.BlendFactor = Color.FromArgb(0, m_sp.Blend, m_sp.Blend,m_sp.Blend);//m_sp.Blend, m_sp.Blend, m_sp.Blend);
//						device.RenderState.AlphaSourceBlend = Blend.BlendFactor;
//					}
                break;

            case RasterOps.ROPs.Lightest:
                //lightest?
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.BlendOperation   = BlendOperation.Max;
                break;

            case RasterOps.ROPs.SubtractPin:                     //OK
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.SourceBlend      = Blend.Zero;
                device.RenderState.DestinationBlend = Blend.InvSourceColor;
                break;

            case RasterOps.ROPs.Difference:                     //Hmm..
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.SourceBlend      = Blend.InvDestinationColor;
                device.RenderState.DestinationBlend = Blend.InvSourceColor;
                break;

            case RasterOps.ROPs.D3DTest1:
                //Director blend ink (by sprite's Blend value)
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.BlendFactor      = Color.FromArgb(0, m_sp.Blend, m_sp.Blend, m_sp.Blend);                  //m_sp.Blend, m_sp.Blend, m_sp.Blend);
                device.RenderState.SourceBlend      = Blend.BlendFactor;
                device.RenderState.DestinationBlend = Blend.InvBlendFactor;
                break;

            case RasterOps.ROPs.D3DTest2:
                //Alpha channel blending
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.BlendFactor      = Color.FromArgb(0, m_sp.Blend, m_sp.Blend, m_sp.Blend);
                device.RenderState.SourceBlend      = Blend.SourceAlpha;
                device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
                break;

            case RasterOps.ROPs.D3DTest3:
                //don't understand this one...
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.SourceBlend      = Blend.InvSourceColor;
                break;

            case RasterOps.ROPs.D3DTest4:
                //device.RenderState.AlphaTestEnable = false;
                //device.RenderState.ReferenceAlpha = 0x01;
                //device.RenderState.AlphaFunction = Compare.GreaterEqual;
                device.RenderState.AlphaBlendEnable = true;
                //device.RenderState.BlendFactor = Color.FromArgb(m_sp.Blend, 255,255,255);//m_sp.Blend, m_sp.Blend, m_sp.Blend);
                device.RenderState.BlendFactor = Color.FromArgb(0, m_sp.Blend, m_sp.Blend, m_sp.Blend);                       //m_sp.Blend, m_sp.Blend, m_sp.Blend);
                //device.RenderState.AlphaSourceBlend = Blend.BlendFactor;
                //device.RenderState.AlphaDestinationBlend = Blend.BlendFactor;
                device.RenderState.SourceBlend      = Blend.BlendFactor;
                device.RenderState.DestinationBlend = Blend.InvBlendFactor;
                //device.RenderState.Ambient = System.Drawing.Color.FromArgb(0, 255, 255, 255);
                //m_mtrl.Ambient = m_mtrl.Diffuse = Color.FromArgb(10, m_mtrl.Diffuse.R, m_mtrl.Diffuse.G, m_mtrl.Diffuse.B);
                //device.RenderState.BlendFactor = Color.FromArgb(10, 127, 127, 127);
                //device.RenderState.DiffuseMaterialSource = ColorSource.Material;
                //device.RenderState.BlendOperation = BlendOperation.Add;
                //device.SetTextureStageState(0, TextureStageStates.AlphaArgument0, 100f);
                //device.Material = m_mtrl;

                //device.SetRenderState(RenderStates.DestinationBlend, 4);
                //device.RenderState.SourceBlend = Blend.BothSourceAlpha; //let's though key only?
                //device.RenderState.DestinationBlend = Blend.SourceColor; //some transparency in grayish areas?
                //device.RenderState.BlendOperation = BlendOperation.Subtract; ??
                //device.RenderState.BlendOperation = BlendOperation.Add;
                //device.SetRenderState(RenderStates.BlendFactor, 0.5f);
                //device.RenderState.SourceBlend = Blend.SourceAlpha;
                //device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
                //device.RenderState.BlendFactor = Color.FromArgb(127, 127, 127, 127);
                //device.RenderState.BlendFactor = Color.FromArgb(127, 255, 255, 255);
                //m_mtrl.Diffuse = Color.FromArgb(127, m_mtrl.Diffuse.R, m_mtrl.Diffuse.G, m_mtrl.Diffuse.B);
                //device.SetTextureStageState(0, TextureStageStates.AlphaArgument1, 100f);
                break;

                //http://www.two-kings.de/tutorials/d3d.html //disappeared??
                // http://www.toymaker.info/Games/html/render_states.html
            }

            device.SetTexture(0, m_sp.Member.Texture);

            device.SamplerState[0].MagFilter = this.m_sp.TextureMagFilter;
            device.SamplerState[0].MinFilter = this.m_sp.TextureMinFilter;

            device.SetStreamSource(0, vertexBuffer, 0);
            device.VertexFormat = customVertexFlags;
            device.SetTransform(TransformType.View, QuadMatrix);
            device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, numVerts - 2);
        }
Ejemplo n.º 32
0
        public override Endogine.BitmapHelpers.PixelDataProvider TransformIntoRenderTarget(Endogine.BitmapHelpers.PixelDataProvider pdp)
        {
            Surface surf = ((PixelDataProvider)pdp).Texture.GetSurfaceLevel(0);
            bool isTarget = ((int)surf.Description.Usage & (int)Usage.RenderTarget) != 0;
            if (isTarget)
                return pdp;

            Surface oldSurfRT = this._device.GetRenderTarget(0);

            PixelDataProvider pdpRT = new PixelDataProvider(pdp.Width, pdp.Height, pdp.BitsPerPixel / 8, this._device, Usage.RenderTarget);
            this.RenderTarget = pdpRT;

            Endogine.SpriteRenderStrategy rs = this.CreateRenderStrategy();
            rs.Init();
            rs.SetPixelDataProvider(pdp);
            ERectangleF rctDrawTarget = new ERectangleF(0,0, pdp.Width, pdp.Height);//-pdp.Width, -pdp.Height, pdp.Width * 2, pdp.Height * 2) * 2;
            //rs.SourceClipRect = sourceClipRect;
            rs.CalcRenderRegion(rctDrawTarget, 0, new EPoint(), new EPoint(pdp.Width, pdp.Height));

            //render:
            this.PreUpdate();
            rs.SubDraw();
            this.EndUpdate();

            //reset renderer and finish up:
            this._device.SetRenderTarget(0, oldSurfRT);
            this.PostUpdate();

            return pdpRT;
        }
Ejemplo n.º 33
0
        public EPointF MapPointFromRectAToRectB(EPointF a_pnt, ERectangleF a_rctA, ERectangleF a_rctB)
        {
            EPointF pntNew = new EPointF(a_pnt.X-a_rctA.Left, a_pnt.Y-a_rctA.Top);
            pntNew.X/=a_rctA.Width;
            pntNew.Y/=a_rctA.Height;

            pntNew.X = pntNew.X*a_rctB.Width + a_rctB.Left;
            pntNew.Y = pntNew.Y*a_rctB.Height + a_rctB.Top;
            return pntNew;
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Transforms a point in the quad to where it would be if the quad was stretched out to a rectangle
        /// </summary>
        /// <param name="pnt"></param>
        /// <param name="rect"></param>
        /// <returns></returns>
        public EPointF MapToRect(EPointF pnt, ERectangleF rect)
        {
            //--Courtesy of NoiseCrime

            float x = pnt.X;
            float y = pnt.Y;

            float af = this._points[0].X - this._points[1].X - this._points[3].X + this._points[2].X;
            float bf = this._points[1].X - this._points[0].X;
            float cf = this._points[3].X - this._points[0].X;
            float df = this._points[0].X;

            float ef = this._points[0].Y - this._points[1].Y - this._points[3].Y + this._points[2].Y;
            float ff = this._points[1].Y - this._points[0].Y;
            float gf = this._points[3].Y - this._points[0].Y;
            float hf = this._points[0].Y;

            float A = af * ff - bf * ef;
            float B = ef * x - af * y + af * hf - df * ef + cf * ff - bf * gf;
            float C = gf * x - cf * y + cf * hf - df * gf;
            float D = af * gf - cf * ef;

            float u, v;
            float tmpBResult = 0;
            if (Math.Abs(A) > 0.00001f)
            {
                tmpBResult = (B * B) - (4f * A * C);

                if (tmpBResult < 0)
                    return null;

                tmpBResult = (float)Math.Sqrt(tmpBResult);

                u = (-B - tmpBResult) / (2f * A);

                float u2 = 0;
                //  If our u is outside our range.
                if ((u < 0) || (u > 1))
                    u2 = (-B + tmpBResult) / (2f * A);

                // If u2 is in the correct range, use u2
                if ((u2 >= 0) && (u2 <= 1))
                    u = u2;
                else //pick whichever is closest to range (0...1)
                    if (Math.Abs(u2 - 0.5f) < Math.Abs(u - 0.5f))
                        u = u2;
            }
            else
            {
                if ((int)Math.Round(B) != 0)
                    u = -C / B;
                else
                    u = 0; //return null; //!!@ "Error Quad mapping U = 0")
            }

            if (Math.Abs(D) > 0.00001f)
            {
                float temp = af * u + cf;
                v = -1f;

                if ((temp > 0.00001f) || (temp < -0.00001f))
                    v = (x - bf * u - df) / temp;
                else
                    v = 0; //return null; //    v = 0 -- !!@ "Error Quad mapping V = 0

                if ((v < 0) || (v > 1))
                {
                    float E = ef * x - af * y + af * hf - df * ef - cf * ff + bf * gf;
                    float F = ff * x - bf * y + bf * hf - df * ff;

                    float tmpEResult = E * E - 4f * D * F;
                    if (tmpBResult < 0) //TODO: he meant tmpEResult, no?
                        return null;

                    tmpBResult = (float)Math.Sqrt(tmpBResult); //TODO: he meant tmpEResult, no?

                    // If our result is going to be outside our rect, use the alternative value for the quadratic equation.
                    v = (-E + tmpEResult) / (2f * D);

                    if ((v < 0) || (v > 1))
                    {
                        float v2 = (-E - tmpEResult) / (2f * D);
                        // If v2 is in the correct range, use u2
                        if ((v2 >= 0) && (v2 <= 1))
                            v = v2;
                        else // pick whichever is closest to range (0...1)
                            if (Math.Abs(v2 - 0.5f) < Math.Abs(v - 0.5f))
                                v = v2;
                    }
                }
            }
            else
            {
                float E = ef * x - af * y + af * hf - df * ef - cf * ff + bf * gf;
                float F = ff * x - bf * y + bf * hf - df * ff;

                if ((int)Math.Round(E) != 0)
                    v = -F / E;
                else
                    return null; //Error Quad mapping VE= 0")
            }

            //--JB 041001:
            float pToh = u * rect.Width + rect.X; //-rect.X + prect[1] + 0.0) --+ 0.5
            float pTov = v * rect.Height + rect.Y; //-prect[2] + prect[2] + 0.0) --+ 0.5

            return new EPointF(pToh, pTov);
        }
Ejemplo n.º 35
0
        private void Init(bool bAutoSetParent)
        {
            m_aChildrenToRemove = new ArrayList();
            m_plChildrenByHash = new Hashtable();
            this._slChildrenLocZSorted = new SortedFloatList();

            m_sID = "";
            m_nInk = (int)RasterOps.ROPs.Copy;
            m_nBlend = 255;

            m_matrix = new Matrix4();
            m_vPivot = new Vector3();

            m_fLocZ = 0.0f;
            m_pntLoc = new EPointF(0.0f, 0.0f);
            m_pntScale = new EPointF(1.0f, 1.0f);
            m_pntRegPoint = new EPoint(0,0);

            m_rctSrcClip = new ERectangle(0,0,1,1);
            m_clr = Color.White;
            m_rctDstParent = new ERectangleF(0,0,0,0);

            m_aBehaviors = new ArrayList();

            m_nMemberAnimFrame = 0;

            m_dtChildren = new DataTable();
            m_dtChildren.Columns.Add("Name", typeof(System.String));
            m_dtChildren.Columns.Add("LocZ", typeof(System.Double));
            m_dtChildren.Columns.Add("Hash", typeof(System.Int32));

            m_pntMouseDown = new EPoint();
            m_pntMouseLast = new EPoint();
            _pntMouse = new EPoint();

            if (bAutoSetParent && m_endogine!=null && m_endogine.Stage != null)
                Parent = m_endogine.Stage.DefaultParent;

            m_renderStrategy = m_endogine.Stage.CreateRenderStrategy();

            m_renderStrategy.SetEndogine(m_endogine);
            m_renderStrategy.SetSprite(this);
            m_renderStrategy.Init();

            //TODO: make this optional (takes some resources)
            Sprite[] lcs = new Sprite[1];
            lcs[0] = this;
            EH.Instance.LatestCreatedSprites = lcs;
        }
Ejemplo n.º 36
0
 public abstract void CalcRenderRegion(ERectangleF rctDrawTarget, float rotation, EPoint regPoint, EPoint sourceRectSize);
Ejemplo n.º 37
0
        public override void EnterFrame()
        {
            float minStep = (float)Math.PI / 32;
            if (this._keys.GetKeyActive("right"))
                this._inputSteerAngle = Math.Max(this._inputSteerAngle - minStep, -(float)Math.PI / 4);
            if (this._keys.GetKeyActive("left"))
                this._inputSteerAngle = Math.Min(this._inputSteerAngle + minStep, (float)Math.PI / 4);

            if (this._inputSteerAngle > 0)
            {
                this._inputSteerAngle -= minStep / 4;
                if (this._inputSteerAngle < 0)
                    this._inputSteerAngle = 0;
            }
            else if (this._inputSteerAngle < 0)
            {
                this._inputSteerAngle += minStep / 4;
                if (this._inputSteerAngle > 0)
                    this._inputSteerAngle = 0;
            }

            if (this._keys.GetKeyActive("up"))
            {
                this._targetSpeed += 1;
                this._inputThrottle = Math.Min(this._inputThrottle + 10, 100f);
            }
            else if (this._keys.GetKeyActive("down"))
            {
                this._targetSpeed -= 1;
                this._inputThrottle = Math.Max(this._inputThrottle - 10, -60f);
            }
            else
            {
                if (localVel.X > 0)
                {
                    if (localVel.X > 0.5f)
                    {
                        this._inputThrottle = -25;
                    }
                    else if (this._inputThrottle == 0)
                        this._velocity = new EPointF();
                }
            }

            //if (this.Velocity.Length < this._targetSpeed)
            //    this._inputThrottle = 30;
            //else if (this.Velocity.Length > this._targetSpeed)
            //    this._inputThrottle = -30;

            if (this._inputThrottle > 0)
                this._inputThrottle -= 5;
            else if (this._inputThrottle < 0)
                this._inputThrottle += 5;

            if (this._keys.GetKeyActive("action"))
            {
                this._inputBrake = 100;
                this._inputThrottle = 0;
            }
            else
                this._inputBrake = 0;

            if (this._lastFrameTicks > 0)
            {
                int timeDelta = (int)(DateTime.Now.Ticks - this._lastFrameTicks);
                if (timeDelta > 0)
                    //this.DoPhysics(10);
                    this.DoPhysics(timeDelta / 10000);
            }
            this._lastFrameTicks = DateTime.Now.Ticks;
            this.Rotation = -this._angle;
            ERectangleF rct = new ERectangleF(new EPointF(), EH.Instance.Stage.ControlSize.ToEPointF());
            EPointF loc = this.Loc.Copy();
            rct.WrapPointInside(loc);
            this.Loc = loc;

            base.EnterFrame();
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Will expand this rectangle to enclose the provided rct.  Actually, a more natural name would be Union I think.
        /// </summary>
        /// <param name="rct"></param>
        public void Expand(ERectangleF rct)
        {
            float oX = this.OppositeX;
            float oY = this.OppositeY;

            x = Math.Min(x, rct.X);
            y = Math.Min(y, rct.Y);

            this.OppositeX = Math.Max(oX, rct.OppositeX);
            this.OppositeY = Math.Max(oY, rct.OppositeY);
        }
Ejemplo n.º 39
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>
        private static 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;
        }
Ejemplo n.º 40
0
 public bool IntersectsWith(ERectangleF rct)
 {
     ERectangleF rctNew = this.Copy();
     rctNew.Intersect(rct);
     return !(rctNew.IsNegative || rctNew.IsEmpty);
 }
Ejemplo n.º 41
0
        public ERectangleF GetPortionOfMemberToDisplay()
        {
            //TODO: doesn't care about SrcCrop!
            ERectangleF rctfCropped;

            EPoint size = Member.Size; // Member.TotalSize;
            EPoint sizeFrame = Member.Size;
            EPoint sizeReal = size;//GetUpperPowerTextureSize(size);

            //if (Member.GotAnimation)
            //{
            //    ERectangle rctAnim = SourceRect;

            //    rctfCropped = new ERectangleF((float)rctAnim.X/sizeReal.X, (float)rctAnim.Y/sizeReal.Y,
            //        (float)rctAnim.Width/sizeReal.X, (float)rctAnim.Height/sizeReal.Y);
            //}
            //else
            //{
                ERectangle rctAnim = SourceRect;
                rctfCropped = new ERectangleF((float)rctAnim.X/sizeReal.X, (float)rctAnim.Y/sizeReal.Y,
                    (float)rctAnim.Width/sizeReal.X, (float)rctAnim.Height/sizeReal.Y);
            //}

            return rctfCropped;
        }
Ejemplo n.º 42
0
        /// <summary>
        /// Transforms a point in the quad to where it would be if the quad was stretched out to a rectangle
        /// </summary>
        /// <param name="pnt"></param>
        /// <param name="rect"></param>
        /// <returns></returns>
        public EPointF MapToRect(EPointF pnt, ERectangleF rect)
        {
            //--Courtesy of NoiseCrime

            float x = pnt.X;
            float y = pnt.Y;

            float af = this._points[0].X - this._points[1].X - this._points[3].X + this._points[2].X;
            float bf = this._points[1].X - this._points[0].X;
            float cf = this._points[3].X - this._points[0].X;
            float df = this._points[0].X;

            float ef = this._points[0].Y - this._points[1].Y - this._points[3].Y + this._points[2].Y;
            float ff = this._points[1].Y - this._points[0].Y;
            float gf = this._points[3].Y - this._points[0].Y;
            float hf = this._points[0].Y;

            float A = af * ff - bf * ef;
            float B = ef * x - af * y + af * hf - df * ef + cf * ff - bf * gf;
            float C = gf * x - cf * y + cf * hf - df * gf;
            float D = af * gf - cf * ef;

            float u, v;
            float tmpBResult = 0;

            if (Math.Abs(A) > 0.00001f)
            {
                tmpBResult = (B * B) - (4f * A * C);

                if (tmpBResult < 0)
                {
                    return(null);
                }

                tmpBResult = (float)Math.Sqrt(tmpBResult);

                u = (-B - tmpBResult) / (2f * A);

                float u2 = 0;
                //  If our u is outside our range.
                if ((u < 0) || (u > 1))
                {
                    u2 = (-B + tmpBResult) / (2f * A);
                }

                // If u2 is in the correct range, use u2
                if ((u2 >= 0) && (u2 <= 1))
                {
                    u = u2;
                }
                else //pick whichever is closest to range (0...1)
                if (Math.Abs(u2 - 0.5f) < Math.Abs(u - 0.5f))
                {
                    u = u2;
                }
            }
            else
            {
                if ((int)Math.Round(B) != 0)
                {
                    u = -C / B;
                }
                else
                {
                    u = 0; //return null; //!!@ "Error Quad mapping U = 0")
                }
            }

            if (Math.Abs(D) > 0.00001f)
            {
                float temp = af * u + cf;
                v = -1f;

                if ((temp > 0.00001f) || (temp < -0.00001f))
                {
                    v = (x - bf * u - df) / temp;
                }
                else
                {
                    v = 0; //return null; //    v = 0 -- !!@ "Error Quad mapping V = 0
                }
                if ((v < 0) || (v > 1))
                {
                    float E = ef * x - af * y + af * hf - df * ef - cf * ff + bf * gf;
                    float F = ff * x - bf * y + bf * hf - df * ff;

                    float tmpEResult = E * E - 4f * D * F;
                    if (tmpBResult < 0) //TODO: he meant tmpEResult, no?
                    {
                        return(null);
                    }

                    tmpBResult = (float)Math.Sqrt(tmpBResult); //TODO: he meant tmpEResult, no?

                    // If our result is going to be outside our rect, use the alternative value for the quadratic equation.
                    v = (-E + tmpEResult) / (2f * D);

                    if ((v < 0) || (v > 1))
                    {
                        float v2 = (-E - tmpEResult) / (2f * D);
                        // If v2 is in the correct range, use u2
                        if ((v2 >= 0) && (v2 <= 1))
                        {
                            v = v2;
                        }
                        else // pick whichever is closest to range (0...1)
                        if (Math.Abs(v2 - 0.5f) < Math.Abs(v - 0.5f))
                        {
                            v = v2;
                        }
                    }
                }
            }
            else
            {
                float E = ef * x - af * y + af * hf - df * ef - cf * ff + bf * gf;
                float F = ff * x - bf * y + bf * hf - df * ff;

                if ((int)Math.Round(E) != 0)
                {
                    v = -F / E;
                }
                else
                {
                    return(null); //Error Quad mapping VE= 0")
                }
            }

            //--JB 041001:
            float pToh = u * rect.Width + rect.X;  //-rect.X + prect[1] + 0.0) --+ 0.5
            float pTov = v * rect.Height + rect.Y; //-prect[2] + prect[2] + 0.0) --+ 0.5

            return(new EPointF(pToh, pTov));
        }
Ejemplo n.º 43
0
        protected void AdjustVertices()
        {
            if (m_sp.Member == null)
                return;
            if (vertexBuffer == null)
                return;

            float[,] aUVs = GenerateUVs();

            ERectangleF rct = new ERectangleF(0,0,1,1);

            CustomVertex[] vertices = null;
            try
            {
                vertices = vertexBuffer.Lock(0, 0) as CustomVertex[];
            }
            catch (Exception e)
            {
                //TODO: why does this happen??
                return;
                //throw new Exception("Failed to lock buffer...");
            }
            int nColor = System.Drawing.Color.FromArgb(255,255,0,120).ToArgb(); //255,255,255,255
            vertices[0] = new CustomVertex(rct.Left,		rct.Top, 0.0f, aUVs[0,0], aUVs[0,1]);//,      nColor);
            vertices[1] = new CustomVertex(rct.Right,	rct.Top, 0.0f, aUVs[1,0], aUVs[1,1]);//,      nColor);
            vertices[2] = new CustomVertex(rct.Left,		-rct.Bottom, 0.0f, aUVs[3,0], aUVs[3,1]);//,nColor);
            vertices[3] = new CustomVertex(rct.Right,	-rct.Bottom, 0.0f, aUVs[2,0], aUVs[2,1]);//,nColor);
            vertexBuffer.Unlock();
        }
Ejemplo n.º 44
0
        public override void SubDraw()
        {
            ERectangleF rctDraw = m_sp.CalcRectInDrawTarget();

            //attribs.SetColorMatrix(new ColorMatrix(), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);


            if (m_sp.Ink == RasterOps.ROPs.Copy || m_sp.Ink == RasterOps.ROPs.BgTransparent || m_sp.DrawToSprite == null)             //TODO: allow RasterOps on root sprite.
            {
                if (m_sp.Rect.Width <= 0 || m_sp.Rect.Height <= 0)
                {
                    return;
                }

                PointF   ulCorner1 = new PointF(rctDraw.X, rctDraw.Y);
                PointF   urCorner1 = new PointF(rctDraw.OppositeX, rctDraw.Y);
                PointF   llCorner1 = new PointF(rctDraw.X, rctDraw.OppositeY);
                PointF[] destPara1 = { ulCorner1, urCorner1, llCorner1 };

                ERectangle rctSrc = m_sp.SourceRect;                 //m_sp.Member.GetRectForFrame(m_sp.MemberAnimationFrame);
                //RectangleF rctfCropped = m_sp.GetPortionOfMemberToDisplay();

                //g.FillRectangle(new SolidBrush(Color.Red), rctDraw);

                Graphics        g       = Graphics.FromImage(m_sp.DrawToSprite.Member.Bitmap);
                ImageAttributes attribs = new ImageAttributes();
                attribs.SetWrapMode(WrapMode.Tile);
                if (m_sp.Ink == RasterOps.ROPs.BgTransparent)
                {
                    attribs.SetColorKey(m_sp.Member.ColorKey, m_sp.Member.ColorKey);
                }

                g.SmoothingMode      = SmoothingMode.None;
                g.CompositingMode    = CompositingMode.SourceOver;
                g.CompositingQuality = CompositingQuality.Invalid;
                g.DrawImage(m_sp.Member.Bitmap, destPara1, rctSrc.ToRectangleF(), GraphicsUnit.Pixel, attribs);
                g.Dispose();
            }
            else
            {
                //since it's difficult to write a RasterOp algorithm that both does effects and scales/interpolates properly,
                //I cheat by creating a temporary scaled bitmap
                if (m_sp.Rect.ToERectangle().Width <= 0 || m_sp.Rect.ToERectangle().Height <= 0)
                {
                    return;
                }

                Bitmap     bmp    = m_sp.Member.Bitmap;
                ERectangle rctSrc = m_sp.SourceRect;
                if (m_sp.Scaling.X != 1 || m_sp.Scaling.Y != 1 || m_sp.Color != Color.White)
                {
                    //TODO: other/faster resizing algorithms at
                    //http://www.codeproject.com/csharp/ImgResizOutperfGDIPlus.asp
                    rctSrc = m_sp.Rect.ToERectangle();
                    rctSrc.Offset(-rctSrc.X, -rctSrc.Y);
                    bmp = new Bitmap(m_sp.Rect.ToERectangle().Width, m_sp.Rect.ToERectangle().Height, m_sp.Member.Bitmap.PixelFormat);                     //m_sp.Member.Bitmap, new Size(m_sp.RectInt.Width, m_sp.RectInt.Height));
                    Graphics        g       = Graphics.FromImage(bmp);
                    ImageAttributes attribs = new ImageAttributes();

                    ColorMatrix colorMatrix = new ColorMatrix();
                    colorMatrix.Matrix00 = (float)m_sp.Color.R / 255;
                    colorMatrix.Matrix11 = (float)m_sp.Color.G / 255;
                    colorMatrix.Matrix22 = (float)m_sp.Color.B / 255;
                    colorMatrix.Matrix33 = 1.00f;                     // alpha
                    colorMatrix.Matrix44 = 1.00f;                     // w
                    attribs.SetColorMatrix(colorMatrix);

                    g.DrawImage(m_sp.Member.Bitmap, rctSrc.ToRectangle(),
                                m_sp.SourceRect.X, m_sp.SourceRect.Y, m_sp.SourceRect.Width, m_sp.SourceRect.Height,
                                GraphicsUnit.Pixel, attribs);
                    g.Dispose();
                }

                RasterOps.CopyPixels(m_sp.DrawToSprite.Member.Bitmap, bmp,
                                     rctDraw, rctSrc, m_sp.DrawToSprite.SourceRect, (int)m_sp.Ink, m_sp.Blend);
            }
        }
Ejemplo n.º 45
0
 public Matrix4(ERectangleF rect)
 {
     this.MakeIdentity();
     this.Translation = new Vector3(rect.X, rect.Y, 0);
     this.Scale = new Vector3(rect.Width, rect.Height, 1);
 }
Ejemplo n.º 46
0
 private void m_resizeCorner_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, MouseEventType t)
 {
     if (t==Sprite.MouseEventType.StillDown)
     {
         EPoint pntDiff = new EPoint(e.X-m_resizeCorner.MouseLastLoc.X, e.Y-m_resizeCorner.MouseLastLoc.Y);
         Rect = new ERectangleF(Rect.Location, Rect.Size+pntDiff.ToEPointF());//SizeF(Rect.Size.Width+pntDiff.X,Rect.Size.Height+pntDiff.Y));
     }
 }