예제 #1
0
        //public static bool operator ==(ERectangle r1, ERectangle 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 !=(ERectangle r1, ERectangle 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(ERectangle r)
        {
            if (r == null)
            {
                return(false);
            }
            return(r.X == this.X && r.Y == this.Y && r.Width == this.Width && r.Height == this.Height);
        }
예제 #2
0
        private void _picRef_Changed()
        {
            ERectangle rct = _picRef.SourceRectangle;

            this._regPointInternal = rct.TopLeft + _picRef.Offset;
            //this.RegPoint = rct.TopLeft + _picRef.Offset + this._regPointInternal;
            this.SourceRect = rct;
        }
예제 #3
0
        public override void Update()
        {
            Graphics g;

            bool bRenderAsText = true;

            g = Graphics.FromImage(m_spRoot.Member.Bitmap);
            g.Clear(Color);
            m_spRoot.EnterFrame();
            m_spRoot.Draw();


            bool bRenderASCII = false;

            if (bRenderASCII)             //for fun: render graphics as ASCII art
            {
                string sAll = "";
                if (bRenderAsText)
                {
                    string s        = " .,:|IOMW";
                    int    nDivider = 255 / (s.Length);
                    for (int y = 0; y < m_spRoot.SourceRect.Height; y += 16)
                    {
                        for (int x = 0; x < m_spRoot.SourceRect.Width; x += 8)
                        {
                            Color clr   = m_spRoot.Member.Bitmap.GetPixel(x, y);
                            int   nGray = (clr.R + clr.G + clr.B) / 3;
                            int   n     = nGray / nDivider;
                            if (n >= s.Length)
                            {
                                n = s.Length - 1;
                            }
                            sAll += s[n];
                        }
                        sAll += "\n";
                    }
                    g.Clear(Color);
                    Font font = new Font("Courier New", 10);
                    g.DrawString(sAll, font, new SolidBrush(Color.White), 10, 10);
                }
            }

            g = this.m_renderControl.CreateGraphics();
            g.DrawImage(m_spRoot.Member.Bitmap, new PointF(0, 0));


            g.Dispose();

            ERectangle rct = m_spRoot.Rect.ToERectangle();
            Point      pntScreenTopLeft = this.m_renderControl.PointToScreen(new System.Drawing.Point(0, 0));

            rct.X += pntScreenTopLeft.X;
            rct.Y += pntScreenTopLeft.Y;

            this.m_renderControl.Invalidate();
        }
예제 #4
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(ERectangle rct)
        {
            int oX = this.OppositeX;
            int 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);
        }
예제 #5
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;
        }
예제 #6
0
 private void PostConstructor(string originalName)
 {
     PicRef._numCreated++;
     if (originalName == null)
     {
         originalName = "Unnamed" + PicRef._numCreated;
     }
     this._originalName = originalName;
     this._offset       = new EPoint();
     this._sourceRect   = new ERectangle();
     PicRef.AddPicture(this);
 }
예제 #7
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);
        }
예제 #8
0
        protected void CreateRootSprite(ERectangle a_rct)
        {
            _spRoot            = new Sprite();
            _spRoot.SourceRect = a_rct;
            _spRoot.Name       = "root";

            _cam        = new Camera();
            _cam.Name   = "Camera";
            _cam.Parent = _spRoot;

            ParallaxLayer layer = new ParallaxLayer();

            layer.Name   = "DefaultLayer";
            layer.Parent = (Sprite)_cam;

            this._defaultParent = layer;
        }
예제 #9
0
        public void Intersect(ERectangle rct)
        {
            int oY = this.OppositeY;
            int 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);
//			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;
        }
예제 #10
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);
        }
예제 #11
0
        public CaveWalls()
        {
            m_noise = new Endogine.Procedural.Noise();
            m_noise.Frequency = 0.1f;
            m_noise.Octaves = 4;
            m_noise.Decay = 0.5f;

            m_wallSprites = new ArrayList();
            m_locYPairs = new SortedList();

            m_rctPlayArea = new ERectangle(0,0,640,480);
            m_fCaveHeight = m_rctPlayArea.Height*0.8f;

            m_rnd = new Random();
            for (int i = 0; i < m_rctPlayArea.Width/m_nTileWidth+1; i++)
            {
                this.CreateNewTiles(i*m_nTileWidth);
            }
        }
예제 #12
0
        public GameMain()
        {
            m_starField = new StarField();
            m_player = new Player(this);
            m_aAsteroids = new ArrayList();

            //The aOKLocs is generated so no asteroids will appear close to the ship
            EPoint pntStageSize = EndogineHub.Instance.Stage.Size;
            ArrayList aOKLocs = new ArrayList();
            EPoint pntNumPositions = new EPoint(6,6);
            ERectangle rctFreePositions = new ERectangle(2,2,2,2);
            for (int y = 0; y < pntNumPositions.Y; y++)
            {
                if (y >= rctFreePositions.Y && y < rctFreePositions.Bottom)
                    y+=rctFreePositions.Height;
                for (int x = 0; x < pntNumPositions.X; x++)
                {
                    if (x >= rctFreePositions.X && x < rctFreePositions.Right)
                        x+=rctFreePositions.Width;
                    EPoint pnt = new EPoint(x,y) * pntStageSize/(pntNumPositions-new EPoint(1,1)) - pntStageSize/2;;
                    aOKLocs.Add(pnt);
                }
            }

            Random rnd = new Random();
            for (int i = 0; i < 4; i++)
            {
                Asteroid asteroid = new Asteroid(this, 3);
                asteroid.Velocity = new EPointF((float)rnd.NextDouble()-0.5f, (float)rnd.NextDouble()-0.5f);

                int nRndPos = rnd.Next(aOKLocs.Count);
                EPoint pntLoc = (EPoint)aOKLocs[nRndPos];
                aOKLocs.RemoveAt(nRndPos);
                asteroid.Loc = pntLoc.ToEPointF();
            }
        }
예제 #13
0
 public bool IntersectsWith(ERectangle rct)
 {
     ERectangle rctNew = this.Copy();
     rctNew.Intersect(rct);
     return !(rctNew.IsNegative || rctNew.IsEmpty);
 }
예제 #14
0
 public void Intersect(ERectangle rct)
 {
     int oY = this.OppositeY;
     int 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);
     //			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;
 }
예제 #15
0
 public void Inflate(ERectangle rct)
 {
     this.height += rct.Width;
     this.width += rct.Height;
     this.x += rct.X;
     this.y += rct.Y;
 }
예제 #16
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(ERectangle 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;
 }
예제 #17
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(ERectangle rct)
        {
            int oX = this.OppositeX;
            int 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);
        }
예제 #18
0
 private void PostConstructor(string originalName)
 {
     PicRef._numCreated++;
     if (originalName == null)
         originalName = "Unnamed" + PicRef._numCreated;
     this._originalName = originalName;
     this._offset = new EPoint();
     this._sourceRect = new ERectangle();
     PicRef.AddPicture(this);
 }
예제 #19
0
        private void label1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (!m_bMouseMoveDown)
            {
//				string sText = this.label1.Text.Split(" ".ToCharArray())[0];
                EPoint  pntMid   = new EPoint(this.label1.Left, this.label1.Top) + new EPoint(this.label1.Width, this.label1.Height) / 2;
                EPoint  pntMouse = new EPoint(e.X, e.Y);                //this.label1.PointToClient(new Point(e.X, e.Y))
                EPointF pntDiff  = (pntMouse - pntMid).ToEPointF();
                if (pntDiff.Length < 0.8f * this.label1.Width / 2)
                {
                    m_pntActiveAxes = new EPoint(1, 1);
                }
                else
                {
                    if ((pntDiff.Angle > Math.PI / 4 && pntDiff.Angle < 3 * Math.PI / 4) ||
                        (pntDiff.Angle < -Math.PI / 4 && pntDiff.Angle > -3 * Math.PI / 4))
                    {
                        m_pntActiveAxes = new EPoint(1, 0);
                    }
                    else
                    {
                        m_pntActiveAxes = new EPoint(0, 1);
                    }
                }


                if (m_pntActiveAxes.X == 1 && m_pntActiveAxes.Y == 1)
                {
//					sText+=" XY";
                    this.Cursor = System.Windows.Forms.Cursors.SizeAll;
                }
                else if (m_pntActiveAxes.X == 1)
                {
//					sText+=" X";
                    this.Cursor = System.Windows.Forms.Cursors.SizeWE;
                }
                else if (m_pntActiveAxes.Y == 1)
                {
//					sText+=" Y";
                    this.Cursor = System.Windows.Forms.Cursors.SizeNS;
                }

//				this.label1.Text = sText;
            }
            else
            {
                EPoint pntNow  = new EPoint(e.X, e.Y);
                EPoint pntDiff = pntNow - m_pntMouseLastLoc;
                //CameraMove(pntDiff.ToEPointF());

                //If mouse moves outside screen, wrap it around the edges:

                EPoint pntScreen = new EPoint(label1.PointToScreen(m_pntMouseLastLoc.ToPoint()));
                EPoint pntOrg    = pntScreen.Copy();

                ERectangle rct = new ERectangle(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea);
                rct = rct + new ERectangle(5, 5, -10, -10);
                rct.WrapPointInside(pntScreen);

                if (!pntOrg.Equals(pntScreen))
                {
                    System.Windows.Forms.Cursor.Position = pntScreen.ToPoint();
                    pntNow           = new EPoint(label1.PointToClient(pntScreen.ToPoint()));
                    m_pntWrappedAdd += pntOrg - pntScreen;
                }

                //when using timer - don't send on mouse move
                if (timer1.Enabled == false)
                {
                    if (DraggingEvent != null)
                    {
                        DraggingEvent(this, pntDiff.ToEPointF() * m_pntFactor * m_pntActiveAxes);
                    }
                }

                m_pntMouseLastLoc = pntNow;
            }
        }
예제 #20
0
 public void SetPosColor(EPoint pos, Color clr)
 {
     Graphics g = Graphics.FromImage(this.m_bmp);
     ERectangle rct = new ERectangle(pos.X, pos.Y, 1,1)*this.SquareSide;
     g.FillRectangle(new SolidBrush(clr), rct.ToRectangle());
 }
예제 #21
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;
        }
예제 #22
0
        unsafe static private void BlitWithOps(byte *a_ptrSrc, byte *a_ptrDst,
                                               ERectangle a_rctSrc, ERectangle a_rctDst,
                                               int a_nStrideSrc, int a_nStrideDst,
                                               int a_nBppSrc, int a_nBppDst,
                                               int a_nInk, int a_nBlend)
        {
            int a_nBppSrc2 = a_nBppDst;
            //http://www.codeproject.com/cs/media/KVImageProcess.asp

            double dDstSizeDiffX = (double)a_rctDst.Width / a_rctSrc.Width;
            int    nStepDiff;

            if (dDstSizeDiffX < 1)
            {
                nStepDiff = (int)(-1.0 / dDstSizeDiffX) + 1;
            }
            else
            {
                nStepDiff = (int)dDstSizeDiffX - 1;
            }
            nStepDiff *= a_nBppDst;

            byte[,] aVals = null;
            if (m_slPreCalced != null && m_slPreCalced.Contains(a_nInk))
            {
                aVals = (byte[, ])m_slPreCalced[a_nInk];
            }

            unsafe
            {
                for (int nLineNum = 0; nLineNum < a_rctSrc.Height; nLineNum++)
                {
                    //int nLineOffsetDst = ((int)(dDstSizeDiffX*nLineNum)+(int)a_rctDst.Top)*a_nStrideDst;
                    int nLineOffsetDst = (nLineNum + (int)a_rctDst.Top) * a_nStrideDst;
                    int nLineOffsetSrc = (nLineNum + (int)a_rctSrc.Top) * a_nStrideSrc;

                    byte *pDstPix  = a_ptrDst + nLineOffsetDst + (int)a_rctDst.Left * a_nBppDst;
                    byte *pSrc1Pix = a_ptrSrc + nLineOffsetSrc + (int)a_rctSrc.Left * a_nBppSrc;
                    byte *pSrc2Pix = a_ptrDst + nLineOffsetDst + (int)a_rctDst.Left * a_nBppSrc2;
                    //EndogineHub.Put(a_rctSrc.ToString());
                    //per-pixel operations

                    if (aVals != null)                   //used precalced data if it exists
                    {
                        for (int x = a_rctSrc.Left; x < a_rctSrc.Right; x++)
                        {
                            for (int n = 0; n < a_nBppSrc; n++)
                            {
                                *pDstPix = aVals[*pSrc2Pix, *pSrc1Pix];
                                pDstPix++;
                                pSrc1Pix++;
                                pSrc2Pix++;
                            }
                            pDstPix  += a_nBppDst - a_nBppSrc;                        //+ nStepDiff;
                            pSrc2Pix += a_nBppSrc2 - a_nBppSrc;                       //+ nStepDiff;
                        }
                        continue;
                    }
                    //per-bit operations
                    for (int x = a_rctSrc.Left; x < a_rctSrc.Right; x++)
                    {
                        for (int n = 0; n < a_nBppSrc; n++)
                        {
                            //byte btDstBefore = *pDstPix;
                            switch (a_nInk)
                            {
                            /*0   COPY            d = s
                             *              1   TRANS           d = d AND s
                             *              2   REVERSE         d = d XOR s
                             *              3   GHOST           d = d OR (NOT s)
                             *              4   NOT_COPY        d = NOT s
                             *              5   NOT_TRANS       d = d AND (NOT s)
                             *              6   NOT_REVERSE     d = d XOR (NOT s)
                             *              7   NOT_GHOST       d = d OR s
                             *              32  BLEND           d = d * blend + s * (100% - blend)
                             *              36  BKGND_TRANS     d = s if s != bg
                             *              40  LIGHTEN         d = s * scaleFactor (bg) + addFactor (fg)
                             *              41  DARKEN          d = s * scaleFactor (bg) + addFactor ((256 - bg) + fg)*/
                            case 0:                                     //Copy
                                                                        //*pDstPix = 255;
                                if (a_nBlend != 255)
                                {
                                    *pDstPix = (byte)((255 - a_nBlend) * (*pSrc2Pix) / 255 + a_nBlend * (*pSrc1Pix) / 255);
                                }
                                else
                                {
                                    *pDstPix = *pSrc1Pix;
                                }
                                break;

                            case 1:                                     //Transparent
                                *pDstPix = (byte)(*pSrc2Pix & *pSrc1Pix);
                                break;

                            case 2:                                     //Reverse
                                *pDstPix = (byte)(*pSrc2Pix ^ *pSrc1Pix);
                                break;

                            case 3:                                          //Ghost
                                *pDstPix = (byte)(*pSrc2Pix | (~*pSrc1Pix)); //or (not src)
                                break;


                            case 33:                                     //Add pin
                                if (a_nBlend != 255)
                                {
                                    *pDstPix = (byte)Math.Min((int)*pSrc2Pix + (int)a_nBlend * (*pSrc1Pix) / 255, 255);
                                }
                                else
                                {
                                    *pDstPix = (byte)Math.Min((int)*pSrc2Pix + (int)*pSrc1Pix, 255);
                                }
                                break;

                            case 34:                                     //Add
                                if (a_nBlend != 255)
                                {
                                    *pDstPix += (byte)(a_nBlend * (*pSrc1Pix) / 255);
                                }
                                else
                                {
                                    *pDstPix += *pSrc1Pix;
                                }
                                break;

                            case 35:                                     //Subtract pin
                                if (a_nBlend != 255)
                                {
                                    *pDstPix = (byte)Math.Max((int)*pSrc2Pix - (int)a_nBlend * (*pSrc1Pix) / 255, 0);
                                }
                                else
                                {
                                    *pDstPix = (byte)Math.Max((int)*pSrc2Pix - (int)*pSrc1Pix, 0);
                                }
                                break;

                            case 37:                                     //Lightest
                                *pDstPix = (*pSrc1Pix > *pSrc2Pix)?*pSrc1Pix:*pSrc2Pix;
                                break;

                            case 38:                                     //Subtract
                                if (a_nBlend != 255)
                                {
                                    *pDstPix -= (byte)(a_nBlend * (*pSrc1Pix) / 255);
                                }
                                else
                                {
                                    *pDstPix -= *pSrc1Pix;
                                }
                                break;

                            case 39:                                     //Darkest
                                *pDstPix = (*pSrc1Pix < *pSrc2Pix)?*pSrc1Pix:*pSrc2Pix;
                                break;

                            default:
                                *pDstPix = *pSrc1Pix;
                                break;


                            //http://www.pegtop.net/delphi/blendmodes/
                            //Photoshop-like ops:

                            case 101:                                     //multiply
                                *pDstPix = (byte)((int)(*pSrc1Pix) * (*pSrc2Pix) / 255);
                                break;

                            case 103:                                    //screen
                                *pDstPix = (byte)(255 - ((int)(255 - *pSrc1Pix) * (255 - *pSrc2Pix) >> 8));
                                //pPDst[ulDP] = 255 - (int(255-pPSrc1[ulS1P]) * (255-pPSrc2[ulS2P]) >> 8);
                                break;

                            case 106:                                     //Overlay

                                if (*pSrc1Pix < 128)
                                {
                                    *pDstPix = (byte)((int)(*pSrc1Pix) * *pSrc1Pix >> 7);
                                }
                                else
                                {
                                    *pDstPix = (byte)(255 - ((255 - *pSrc1Pix) * (255 - *pSrc2Pix) >> 7));
                                }
                                break;

                            case 107:                                     //Color dodge
                                if (*pSrc2Pix == 255)
                                {
                                    *pDstPix = 255;
                                }
                                else
                                {
                                    int nTempVal = ((int)*pSrc1Pix << 8) / (256 - *pSrc2Pix);
                                    if (nTempVal > 255)
                                    {
                                        *pDstPix = 255;
                                    }
                                    else
                                    {
                                        *pDstPix = (byte)nTempVal;
                                    }
                                }
                                break;

                            case 108:                                     //Color burn
                                if (*pSrc2Pix == 0)
                                {
                                    *pDstPix = 0;
                                }
                                else
                                {
                                    int nTempVal = (int)255 - (((255 - *pSrc1Pix) << 8) / *pSrc2Pix);
                                    if (nTempVal < 0)
                                    {
                                        *pDstPix = 0;
                                    }
                                    else
                                    {
                                        *pDstPix = (byte)nTempVal;
                                    }
                                }
                                break;

                            case 109:                                     //Difference
                                *pDstPix = (byte)Math.Abs((int)*pSrc1Pix - *pSrc2Pix);
                                break;
                            }
                            pDstPix++;
                            pSrc1Pix++;
                            pSrc2Pix++;
                        }
                        pDstPix  += a_nBppDst - a_nBppSrc;                    //+ nStepDiff;
                        pSrc2Pix += a_nBppSrc2 - a_nBppSrc;                   //+ nStepDiff;


                        /*
                         * ulDP+=4;
                         * if (ulDP > cjbiiDst.ulNextLineByteNum-1) {
                         * cjbiiDst.ulCurrYInROI++;
                         * if (cjbiiDst.ulCurrYInROI > cjbiiDst.ulROIHeight-1) break;
                         * ulDP = cjbiiDst.lROIStartXOffsetBytes + (cjbiiDst.ulCurrYInROI+cjbiiDst.lROIStartYOffsetLines)*cjbiiDst.pmmImageInfo->iRowBytes;
                         * cjbiiDst.ulNextLineByteNum = ulDP + cjbiiDst.ulROIWidthNumBytes;
                         * }
                         *
                         * cjbiiSrc1.ulX++;
                         * ulS1P+=4;
                         * if (ulS1P > cjbiiSrc1.ulNextLineByteNum-1) {
                         * cjbiiSrc1.ulCurrYInROI++;
                         * if (cjbiiSrc1.ulCurrYInROI > cjbiiSrc1.ulROIHeight-1) break;
                         * ulS1P = cjbiiSrc1.lROIStartXOffsetBytes + (cjbiiSrc1.ulCurrYInROI+cjbiiSrc1.lROIStartYOffsetLines)*cjbiiSrc1.pmmImageInfo->iRowBytes;
                         * cjbiiSrc1.ulNextLineByteNum = ulS1P + cjbiiSrc1.ulROIWidthNumBytes;
                         * cjbiiSrc1.ulY++;
                         * cjbiiSrc1.ulX = cjbiiSrc1.mrctROI.left;
                         *
                         * }
                         *
                         * ulS2P+=4;
                         * if (ulS2P > cjbiiSrc2.ulNextLineByteNum-1) {
                         * cjbiiSrc2.ulCurrYInROI++;
                         * if (cjbiiSrc2.ulCurrYInROI > cjbiiSrc2.ulROIHeight-1) break;
                         * ulS2P = cjbiiSrc2.lROIStartXOffsetBytes + (cjbiiSrc2.ulCurrYInROI+cjbiiSrc2.lROIStartYOffsetLines)*cjbiiSrc2.pmmImageInfo->iRowBytes;
                         * cjbiiSrc2.ulNextLineByteNum = ulS2P + cjbiiSrc2.ulROIWidthNumBytes;
                         * }
                         */



                        //TODO: per-pixel ops

                        /*
                         *
                         * case 114: //Displacement
                         * //lTemp = 4*(char)(pPSrc2[ulS2P+2]) + (long)(cjbiiSrc1.pmmImageInfo->iRowBytes)*(char)(pPSrc2[ulS2P+1]) + ulS1P;
                         * //TODO: use modulo to wrap more than once around image!
                         * //TODO: optimize when dDisplacementFact == 1.0
                         * lX = (long)cjbiiSrc1.ulX + (long)(dDisplacementFact*(char)(pPSrc2[ulS2P+2]));
                         * lY = (long)cjbiiSrc1.ulY + (long)(dDisplacementFact*(char)(pPSrc2[ulS2P+1]));
                         * if (lY < cjbiiSrc1.mrctROI.top) {
                         * lY = cjbiiSrc1.mrctROI.bottom - (cjbiiSrc1.mrctROI.top - lY);
                         * }
                         * else if (lY > cjbiiSrc1.mrctROI.bottom) {
                         * lY = cjbiiSrc1.mrctROI.top + (lY - cjbiiSrc1.mrctROI.bottom);
                         * }
                         * if (lX < cjbiiSrc1.mrctROI.left) {
                         * lX = cjbiiSrc1.mrctROI.right - (cjbiiSrc1.mrctROI.left - lX);
                         * }
                         * else if (lX > cjbiiSrc1.mrctROI.right) {
                         * lX = cjbiiSrc1.mrctROI.left + (lX - cjbiiSrc1.mrctROI.right);
                         * }
                         * lTemp = 4*lX + lY*(cjbiiSrc1.pmmImageInfo->iRowBytes);
                         * //if (lTemp < 0 || lTemp > (cjbiiDst.ulROIHeight-1)*cjbiiDst.pmmImageInfo->iRowBytes) {
                         * //	break;
                         * //}
                         * ulTemp = (unsigned long)lTemp;
                         * pPDst[ulDP+2] = pPSrc1[ulTemp+2];
                         * pPDst[ulDP+1] = pPSrc1[ulTemp+1];
                         * pPDst[ulDP+0] = pPSrc1[ulTemp+0];
                         * break;
                         *
                         *                                                                      case 112: //Actual composite
                         * if (pPSrc1[ulS1P+3] + pPSrc2[ulS2P+3] == 0) {
                         * pPDst[ulDP+2] = 0;
                         * pPDst[ulDP+1] = 0;
                         * pPDst[ulDP+0] = 0;
                         * }
                         * else {
                         * ucTemp = (unsigned char)((unsigned int)pPSrc1[ulS1P+3]*(255-pPSrc2[ulS2P+3]) >> 8);
                         * pPDst[ulDP+3] = ucTemp + pPSrc2[ulS2P+3];
                         *
                         * pPDst[ulDP+2] = (unsigned char)((((unsigned int)ucTemp*pPSrc1[ulS1P+2] + (unsigned int)pPSrc2[ulS2P+2]*pPSrc2[ulS2P+3])/pPSrc1[ulS1P+3])); // >> 8);
                         * pPDst[ulDP+1] = (unsigned char)((((unsigned int)ucTemp*pPSrc1[ulS1P+1] + (unsigned int)pPSrc2[ulS2P+1]*pPSrc2[ulS2P+3])/pPSrc1[ulS1P+3])); // >> 8);
                         * pPDst[ulDP+0] = (unsigned char)((((unsigned int)ucTemp*pPSrc1[ulS1P+0] + (unsigned int)pPSrc2[ulS2P+0]*pPSrc2[ulS2P+3])/pPSrc1[ulS1P+3])); // >> 8);
                         * }
                         *
                         *              case 111: //Hue
                         * convRGB2HSB(pPSrc2[ulS2P+2], pPSrc2[ulS2P+1], pPSrc2[ulS2P+0], hsbH,ucTemp,ucTemp);
                         * convRGB2HSB(pPSrc1[ulS1P+2], pPSrc1[ulS1P+1], pPSrc1[ulS1P+0], unTemp,hsbS,hsbB);
                         * convHSB2RGB(hsbH,hsbS,hsbB, pPDst[ulDP+2], pPDst[ulDP+1], pPDst[ulDP+0]);
                         * break;
                         *
                         *                                                                      case 110: //Color
                         * convRGB2HSB(pPSrc2[ulS2P+2], pPSrc2[ulS2P+1], pPSrc2[ulS2P+0], hsbH,hsbS,ucTemp);
                         * convRGB2HSB(pPSrc1[ulS1P+2], pPSrc1[ulS1P+1], pPSrc1[ulS1P+0], unTemp,ucTemp,hsbB);
                         * convHSB2RGB(hsbH,hsbS,hsbB, pPDst[ulDP+2], pPDst[ulDP+1], pPDst[ulDP+0]);
                         * break;
                         *
                         * case 102: //HSB shift
                         * convRGB2HSB(pPSrc1[ulS1P+2], pPSrc1[ulS1P+1], pPSrc1[ulS1P+0], hsbH,hsbS,hsbB);
                         *
                         * nHsbH = (int)hsbH + (int)(pPSrc2[ulS2P+2]) * 360 / 255;
                         * if (nHsbH >= 360) nHsbH-=360;
                         * else if (nHsbH < 0) nHsbH+=360;
                         * nHsbS = (int)hsbS + (int)(char)(pPSrc2[ulS2P+1]);
                         * if (nHsbS > 100) nHsbS=100;
                         * else if (nHsbS < 0) nHsbS=0;
                         * nHsbB = (int)hsbB + (int)(char)(pPSrc2[ulS2P+0]);
                         * if (nHsbB > 100) nHsbB=100;
                         * else if (nHsbB < 0) nHsbB=0;
                         *
                         * convHSB2RGB((unsigned int)nHsbH,(unsigned char)nHsbS,(unsigned char)nHsbB, pPDst[ulDP+2], pPDst[ulDP+1], pPDst[ulDP+0]);
                         * break;*/
                    }
                }
            }
        }
예제 #23
0
 //public static bool operator ==(ERectangle r1, ERectangle 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 !=(ERectangle r1, ERectangle 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(ERectangle r)
 {
     if (r == null)
         return false;
     return (r.X == this.X && r.Y == this.Y && r.Width == this.Width && r.Height == this.Height);
 }
예제 #24
0
        protected void CreateRootSprite(ERectangle a_rct)
        {
            _spRoot = new Sprite();
            _spRoot.SourceRect = a_rct;
            _spRoot.Name = "root";

            _cam = new Camera();
            _cam.Name = "Camera";
            _cam.Parent = _spRoot;

            ParallaxLayer layer = new ParallaxLayer();
            layer.Name = "DefaultLayer";
            layer.Parent = (Sprite)_cam;

            this._defaultParent = layer;
        }
예제 #25
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;
        }
예제 #26
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);
            }
        }
예제 #27
0
        private void label1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (!m_bMouseMoveDown)
            {
            //				string sText = this.label1.Text.Split(" ".ToCharArray())[0];
                EPoint pntMid = new EPoint(this.label1.Left, this.label1.Top) + new EPoint(this.label1.Width, this.label1.Height)/2;
                EPoint pntMouse = new EPoint(e.X, e.Y); //this.label1.PointToClient(new Point(e.X, e.Y))
                EPointF pntDiff = (pntMouse-pntMid).ToEPointF();
                if (pntDiff.Length < 0.8f*this.label1.Width/2)
                    m_pntActiveAxes = new EPoint(1,1);
                else
                {
                    if ((pntDiff.Angle > Math.PI/4 && pntDiff.Angle < 3*Math.PI/4) ||
                        (pntDiff.Angle < -Math.PI/4 && pntDiff.Angle > -3*Math.PI/4))
                        m_pntActiveAxes = new EPoint(1,0);
                    else
                        m_pntActiveAxes = new EPoint(0,1);
                }

                if (m_pntActiveAxes.X == 1 && m_pntActiveAxes.Y == 1)
                {
            //					sText+=" XY";
                    this.Cursor = System.Windows.Forms.Cursors.SizeAll;
                }
                else if (m_pntActiveAxes.X == 1)
                {
            //					sText+=" X";
                    this.Cursor = System.Windows.Forms.Cursors.SizeWE;
                }
                else if (m_pntActiveAxes.Y == 1)
                {
            //					sText+=" Y";
                    this.Cursor = System.Windows.Forms.Cursors.SizeNS;
                }

            //				this.label1.Text = sText;
            }
            else
            {
                EPoint pntNow = new EPoint(e.X, e.Y);
                EPoint pntDiff = pntNow-m_pntMouseLastLoc;
                //CameraMove(pntDiff.ToEPointF());

                //If mouse moves outside screen, wrap it around the edges:

                EPoint pntScreen = new EPoint(label1.PointToScreen(m_pntMouseLastLoc.ToPoint()));
                EPoint pntOrg = pntScreen.Copy();

                ERectangle rct = new ERectangle(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea);
                rct = rct + new ERectangle(5,5,-10,-10);
                rct.WrapPointInside(pntScreen);

                if (!pntOrg.Equals(pntScreen))
                {
                    System.Windows.Forms.Cursor.Position = pntScreen.ToPoint();
                    pntNow = new EPoint(label1.PointToClient(pntScreen.ToPoint()));
                    m_pntWrappedAdd+=pntOrg-pntScreen;
                }

                //when using timer - don't send on mouse move
                if (timer1.Enabled == false)
                    if (DraggingEvent!=null) DraggingEvent(this, pntDiff.ToEPointF()*m_pntFactor*m_pntActiveAxes);

                m_pntMouseLastLoc = pntNow;
            }
        }
예제 #28
0
 public particle(ERectangle emitterIn, Smoke smokeIn)
 {
     emitter = emitterIn;
     smoke = smokeIn;
 }
예제 #29
0
        private static unsafe void BlitWithOps(byte* a_ptrSrc, byte* a_ptrDst,
            ERectangle a_rctSrc, ERectangle a_rctDst,
            int a_nStrideSrc, int a_nStrideDst,
            int a_nBppSrc, int a_nBppDst,
            int a_nInk, int a_nBlend)
        {
            int a_nBppSrc2 = a_nBppDst;
            //http://www.codeproject.com/cs/media/KVImageProcess.asp

            double dDstSizeDiffX = (double)a_rctDst.Width/a_rctSrc.Width;
            int nStepDiff;
            if (dDstSizeDiffX < 1)
                nStepDiff = (int)(-1.0/dDstSizeDiffX)+1;
            else
                nStepDiff = (int)dDstSizeDiffX-1;
            nStepDiff*=a_nBppDst;

            byte[,] aVals = null;
            if (m_slPreCalced!=null && m_slPreCalced.Contains(a_nInk))
                aVals = (byte[,])m_slPreCalced[a_nInk];

            unsafe
            {

                for (int nLineNum = 0; nLineNum < a_rctSrc.Height; nLineNum++)
                {
                    //int nLineOffsetDst = ((int)(dDstSizeDiffX*nLineNum)+(int)a_rctDst.Top)*a_nStrideDst;
                    int nLineOffsetDst = (nLineNum+(int)a_rctDst.Top)*a_nStrideDst;
                    int nLineOffsetSrc = (nLineNum+(int)a_rctSrc.Top)*a_nStrideSrc;

                    byte* pDstPix = a_ptrDst+nLineOffsetDst+(int)a_rctDst.Left*a_nBppDst;
                    byte* pSrc1Pix = a_ptrSrc+nLineOffsetSrc+(int)a_rctSrc.Left*a_nBppSrc;
                    byte* pSrc2Pix = a_ptrDst+nLineOffsetDst+(int)a_rctDst.Left*a_nBppSrc2;
                    //EndogineHub.Put(a_rctSrc.ToString());
                    //per-pixel operations

                    if (aVals!=null) //used precalced data if it exists
                    {
                        for (int x = a_rctSrc.Left; x < a_rctSrc.Right; x++)
                        {
                            for (int n = 0; n < a_nBppSrc; n++)
                            {
                                *pDstPix = aVals[*pSrc2Pix, *pSrc1Pix];
                                pDstPix++;
                                pSrc1Pix++;
                                pSrc2Pix++;
                            }
                            pDstPix+=a_nBppDst-a_nBppSrc; //+ nStepDiff;
                            pSrc2Pix+=a_nBppSrc2-a_nBppSrc; //+ nStepDiff;
                        }
                        continue;
                    }
                    //per-bit operations
                    for (int x = a_rctSrc.Left; x < a_rctSrc.Right; x++)
                    {
                        for (int n = 0; n < a_nBppSrc; n++)
                        {
                            //byte btDstBefore = *pDstPix;
                            switch (a_nInk)
                            {
                                    /*0   COPY            d = s
                                            1   TRANS           d = d AND s
                                            2   REVERSE         d = d XOR s
                                            3   GHOST           d = d OR (NOT s)
                                            4   NOT_COPY        d = NOT s
                                            5   NOT_TRANS       d = d AND (NOT s)
                                            6   NOT_REVERSE     d = d XOR (NOT s)
                                            7   NOT_GHOST       d = d OR s
                                            32  BLEND           d = d * blend + s * (100% - blend)
                                            36  BKGND_TRANS     d = s if s != bg
                                            40  LIGHTEN         d = s * scaleFactor (bg) + addFactor (fg)
                                            41  DARKEN          d = s * scaleFactor (bg) + addFactor ((256 - bg) + fg)*/
                                case 0: //Copy
                                    //*pDstPix = 255;
                                    if (a_nBlend != 255)
                                        *pDstPix = (byte)((255-a_nBlend)*(*pSrc2Pix)/255 + a_nBlend*(*pSrc1Pix)/255);
                                    else
                                        *pDstPix = *pSrc1Pix;
                                    break;
                                case 1: //Transparent
                                    *pDstPix = (byte)(*pSrc2Pix & *pSrc1Pix);
                                    break;
                                case 2: //Reverse
                                    *pDstPix = (byte)(*pSrc2Pix ^ *pSrc1Pix);
                                    break;
                                case 3: //Ghost
                                    *pDstPix = (byte)(*pSrc2Pix | (~*pSrc1Pix)); //or (not src)
                                    break;

                                case 33: //Add pin
                                    if (a_nBlend != 255)
                                        *pDstPix = (byte)Math.Min((int)*pSrc2Pix+(int)a_nBlend*(*pSrc1Pix)/255, 255);
                                    else
                                        *pDstPix = (byte)Math.Min((int)*pSrc2Pix+(int)*pSrc1Pix, 255);
                                    break;
                                case 34: //Add
                                    if (a_nBlend != 255)
                                        *pDstPix += (byte)(a_nBlend*(*pSrc1Pix)/255);
                                    else
                                        *pDstPix += *pSrc1Pix;
                                    break;
                                case 35: //Subtract pin
                                    if (a_nBlend != 255)
                                        *pDstPix = (byte)Math.Max((int)*pSrc2Pix-(int)a_nBlend*(*pSrc1Pix)/255, 0);
                                    else
                                        *pDstPix = (byte)Math.Max((int)*pSrc2Pix-(int)*pSrc1Pix, 0);
                                    break;
                                case 37: //Lightest
                                    *pDstPix = (*pSrc1Pix>*pSrc2Pix)?*pSrc1Pix:*pSrc2Pix;
                                    break;
                                case 38: //Subtract
                                    if (a_nBlend != 255)
                                        *pDstPix -= (byte)(a_nBlend*(*pSrc1Pix)/255);
                                    else
                                        *pDstPix -= *pSrc1Pix;
                                    break;
                                case 39: //Darkest
                                    *pDstPix = (*pSrc1Pix<*pSrc2Pix)?*pSrc1Pix:*pSrc2Pix;
                                    break;
                                default:
                                    *pDstPix = *pSrc1Pix;
                                    break;

                                    //http://www.pegtop.net/delphi/blendmodes/
                                    //Photoshop-like ops:

                                case 101: //multiply
                                    *pDstPix = (byte)((int)(*pSrc1Pix)*(*pSrc2Pix) / 255);
                                    break;

                                case 103://screen
                                    *pDstPix = (byte)(255- ((int)(255-*pSrc1Pix)*(255-*pSrc2Pix) >> 8));
                                    //pPDst[ulDP] = 255 - (int(255-pPSrc1[ulS1P]) * (255-pPSrc2[ulS2P]) >> 8);
                                    break;

                                case 106: //Overlay

                                    if (*pSrc1Pix<128) *pDstPix = (byte)((int)(*pSrc1Pix)* *pSrc1Pix >> 7);
                                    else *pDstPix = (byte)(255 - ((255-*pSrc1Pix) * (255-*pSrc2Pix) >> 7));
                                    break;

                                case 107: //Color dodge
                                    if (*pSrc2Pix==255) *pDstPix = 255;
                                    else
                                    {
                                        int nTempVal = ((int)*pSrc1Pix<<8) / (256 - *pSrc2Pix);
                                        if (nTempVal > 255) *pDstPix = 255;
                                        else *pDstPix = (byte)nTempVal; }
                                    break;

                                case 108: //Color burn
                                    if (*pSrc2Pix==0) *pDstPix = 0;
                                    else
                                    {
                                        int nTempVal = (int)255 - (((255-*pSrc1Pix) << 8) / *pSrc2Pix);
                                        if (nTempVal < 0) *pDstPix = 0;
                                        else *pDstPix = (byte)nTempVal; }
                                    break;

                                case 109: //Difference
                                    *pDstPix = (byte)Math.Abs((int)*pSrc1Pix - *pSrc2Pix);
                                    break;
                            }
                            pDstPix++;
                            pSrc1Pix++;
                            pSrc2Pix++;
                        }
                        pDstPix+=a_nBppDst-a_nBppSrc; //+ nStepDiff;
                        pSrc2Pix+=a_nBppSrc2-a_nBppSrc; //+ nStepDiff;

                            /*
                             * ulDP+=4;
            if (ulDP > cjbiiDst.ulNextLineByteNum-1) {
            cjbiiDst.ulCurrYInROI++;
            if (cjbiiDst.ulCurrYInROI > cjbiiDst.ulROIHeight-1) break;
            ulDP = cjbiiDst.lROIStartXOffsetBytes + (cjbiiDst.ulCurrYInROI+cjbiiDst.lROIStartYOffsetLines)*cjbiiDst.pmmImageInfo->iRowBytes;
            cjbiiDst.ulNextLineByteNum = ulDP + cjbiiDst.ulROIWidthNumBytes;
            }

            cjbiiSrc1.ulX++;
            ulS1P+=4;
            if (ulS1P > cjbiiSrc1.ulNextLineByteNum-1) {
            cjbiiSrc1.ulCurrYInROI++;
            if (cjbiiSrc1.ulCurrYInROI > cjbiiSrc1.ulROIHeight-1) break;
            ulS1P = cjbiiSrc1.lROIStartXOffsetBytes + (cjbiiSrc1.ulCurrYInROI+cjbiiSrc1.lROIStartYOffsetLines)*cjbiiSrc1.pmmImageInfo->iRowBytes;
            cjbiiSrc1.ulNextLineByteNum = ulS1P + cjbiiSrc1.ulROIWidthNumBytes;
            cjbiiSrc1.ulY++;
            cjbiiSrc1.ulX = cjbiiSrc1.mrctROI.left;

            }

            ulS2P+=4;
            if (ulS2P > cjbiiSrc2.ulNextLineByteNum-1) {
            cjbiiSrc2.ulCurrYInROI++;
            if (cjbiiSrc2.ulCurrYInROI > cjbiiSrc2.ulROIHeight-1) break;
            ulS2P = cjbiiSrc2.lROIStartXOffsetBytes + (cjbiiSrc2.ulCurrYInROI+cjbiiSrc2.lROIStartYOffsetLines)*cjbiiSrc2.pmmImageInfo->iRowBytes;
            cjbiiSrc2.ulNextLineByteNum = ulS2P + cjbiiSrc2.ulROIWidthNumBytes;
            }
            */

                            //TODO: per-pixel ops
                            /*
                             *
                             case 114: //Displacement
            //lTemp = 4*(char)(pPSrc2[ulS2P+2]) + (long)(cjbiiSrc1.pmmImageInfo->iRowBytes)*(char)(pPSrc2[ulS2P+1]) + ulS1P;
            //TODO: use modulo to wrap more than once around image!
            //TODO: optimize when dDisplacementFact == 1.0
            lX = (long)cjbiiSrc1.ulX + (long)(dDisplacementFact*(char)(pPSrc2[ulS2P+2]));
            lY = (long)cjbiiSrc1.ulY + (long)(dDisplacementFact*(char)(pPSrc2[ulS2P+1]));
            if (lY < cjbiiSrc1.mrctROI.top) {
                lY = cjbiiSrc1.mrctROI.bottom - (cjbiiSrc1.mrctROI.top - lY);
            }
            else if (lY > cjbiiSrc1.mrctROI.bottom) {
                lY = cjbiiSrc1.mrctROI.top + (lY - cjbiiSrc1.mrctROI.bottom);
            }
            if (lX < cjbiiSrc1.mrctROI.left) {
                lX = cjbiiSrc1.mrctROI.right - (cjbiiSrc1.mrctROI.left - lX);
            }
            else if (lX > cjbiiSrc1.mrctROI.right) {
                lX = cjbiiSrc1.mrctROI.left + (lX - cjbiiSrc1.mrctROI.right);
            }
            lTemp = 4*lX + lY*(cjbiiSrc1.pmmImageInfo->iRowBytes);
            //if (lTemp < 0 || lTemp > (cjbiiDst.ulROIHeight-1)*cjbiiDst.pmmImageInfo->iRowBytes) {
            //	break;
            //}
            ulTemp = (unsigned long)lTemp;
            pPDst[ulDP+2] = pPSrc1[ulTemp+2];
            pPDst[ulDP+1] = pPSrc1[ulTemp+1];
            pPDst[ulDP+0] = pPSrc1[ulTemp+0];
            break;

                                                                case 112: //Actual composite
            if (pPSrc1[ulS1P+3] + pPSrc2[ulS2P+3] == 0) {
                pPDst[ulDP+2] = 0;
                pPDst[ulDP+1] = 0;
                pPDst[ulDP+0] = 0;
            }
            else {
                ucTemp = (unsigned char)((unsigned int)pPSrc1[ulS1P+3]*(255-pPSrc2[ulS2P+3]) >> 8);
                pPDst[ulDP+3] = ucTemp + pPSrc2[ulS2P+3];

                pPDst[ulDP+2] = (unsigned char)((((unsigned int)ucTemp*pPSrc1[ulS1P+2] + (unsigned int)pPSrc2[ulS2P+2]*pPSrc2[ulS2P+3])/pPSrc1[ulS1P+3])); // >> 8);
                pPDst[ulDP+1] = (unsigned char)((((unsigned int)ucTemp*pPSrc1[ulS1P+1] + (unsigned int)pPSrc2[ulS2P+1]*pPSrc2[ulS2P+3])/pPSrc1[ulS1P+3])); // >> 8);
                pPDst[ulDP+0] = (unsigned char)((((unsigned int)ucTemp*pPSrc1[ulS1P+0] + (unsigned int)pPSrc2[ulS2P+0]*pPSrc2[ulS2P+3])/pPSrc1[ulS1P+3])); // >> 8);
            }

                                    case 111: //Hue
            convRGB2HSB(pPSrc2[ulS2P+2], pPSrc2[ulS2P+1], pPSrc2[ulS2P+0], hsbH,ucTemp,ucTemp);
            convRGB2HSB(pPSrc1[ulS1P+2], pPSrc1[ulS1P+1], pPSrc1[ulS1P+0], unTemp,hsbS,hsbB);
            convHSB2RGB(hsbH,hsbS,hsbB, pPDst[ulDP+2], pPDst[ulDP+1], pPDst[ulDP+0]);
            break;

                                                                case 110: //Color
            convRGB2HSB(pPSrc2[ulS2P+2], pPSrc2[ulS2P+1], pPSrc2[ulS2P+0], hsbH,hsbS,ucTemp);
            convRGB2HSB(pPSrc1[ulS1P+2], pPSrc1[ulS1P+1], pPSrc1[ulS1P+0], unTemp,ucTemp,hsbB);
            convHSB2RGB(hsbH,hsbS,hsbB, pPDst[ulDP+2], pPDst[ulDP+1], pPDst[ulDP+0]);
            break;

                             * case 102: //HSB shift
            convRGB2HSB(pPSrc1[ulS1P+2], pPSrc1[ulS1P+1], pPSrc1[ulS1P+0], hsbH,hsbS,hsbB);

            nHsbH = (int)hsbH + (int)(pPSrc2[ulS2P+2]) * 360 / 255;
            if (nHsbH >= 360) nHsbH-=360;
            else if (nHsbH < 0) nHsbH+=360;
            nHsbS = (int)hsbS + (int)(char)(pPSrc2[ulS2P+1]);
            if (nHsbS > 100) nHsbS=100;
            else if (nHsbS < 0) nHsbS=0;
            nHsbB = (int)hsbB + (int)(char)(pPSrc2[ulS2P+0]);
            if (nHsbB > 100) nHsbB=100;
            else if (nHsbB < 0) nHsbB=0;

            convHSB2RGB((unsigned int)nHsbH,(unsigned char)nHsbS,(unsigned char)nHsbB, pPDst[ulDP+2], pPDst[ulDP+1], pPDst[ulDP+0]);
            break;*/
                    }
                }
            }
        }