Ejemplo n.º 1
0
Archivo: Rect.cs Proyecto: sinshu/dtf
 /// <summary>
 /// rect�����deep copy��s�Ȃ��B
 /// </summary>
 /// <param name="r"></param>
 public Rect(Rect rect)
 {
     Left = rect.Left;
     Right = rect.Right;
     Top = rect.Top;
     Bottom = rect.Bottom;
 }
Ejemplo n.º 2
0
 public void DrawBullet(Image image, int x, int y, int width, int height, int row, int col, int deg)
 {
     int left = width * col;
     int top = height * row;
     int right = left + width;
     int bottom = top + height;
     Rect srcRect = new Rect((float)left, (float)top, (float)right, (float)bottom);
     int yaneRad = -(int)Math.Round((double)(deg * 512) / 360);
     screen.BltRotate(textures[(int)image], x - width, y - height / 2, srcRect, yaneRad, 1.0f, width, height / 2);
 }
Ejemplo n.º 3
0
 public void DrawBackground(Image image, int x, int y, int width, int height, int row, int col, double stretch)
 {
     int left = width * col;
     int top = height * row;
     int right = left + width;
     int bottom = top + height;
     Rect srcRect = new Rect((float)left, (float)top, (float)right, (float)bottom);
     Point[] points = new Point[4];
     points[0] = new Point((float)x, (float)(y * stretch));
     points[1] = new Point((float)(x + width), (float)(y * stretch));
     points[2] = new Point((float)(x + width), (float)((y + height) * stretch));
     points[3] = new Point((float)x, (float)((y + height) * stretch));
     screen.Blt(textures[(int)image], srcRect, points);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// �e�N�X�`���ƁA���̂ǂ̕�������̃e�N�X�`���Ƃ��Ĉ����̂���ݒ肷��B
 /// 
 /// �����Ŏw�肷��offsetX,offsetY�͂��̃N���X�̃v���p�e�B�ł���
 /// OffsetX,OffsetY�B
 /// </summary>
 public void SetTexture(ITexture texture, Rect rect, float offsetX, float offsetY)
 {
     this.texture = texture;
     this.rect = rect;
     this.offsetX = offsetX;
     this.offsetY = offsetY;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// SetTexture(texture,null)�Ɠ��`�B
 /// </summary>
 /// <param name="texture"></param>
 public void SetTexture(ITexture texture)
 {
     this.texture = texture;
     this.rect = null;
     this.offsetX = this.offsetY = 0;
 }
Ejemplo n.º 6
0
 ///	<summary>画像の描画(2D)</summary>
 /// <remarks>
 ///	bltの転送元矩形と転送先4点の指定できるバージョン。
 ///	srcRectがnullのときはソース全域。
 ///	転送元矩形が、転送先として指定された4点に移動。
 ///
 ///	転送先は、
 ///	point[0]が左上、point[1]が右上、point[2]が右下、point[3]が左下
 ///	の点を指定しているものとする。
 /// </remarks>
 /// <example>
 /// <code>
 ///	Screen screen = new Screen;
 ///	screen.setVideoMode(640,480,0);
 ///	GlTexture tex = new GlTexture;
 ///	tex.load("title.png");
 ///
 ///	while (GameFrame.pollEvent()==0){
 ///
 ///		screen.clear();
 ///
 ///		Point[4] points;
 ///		points[0].setPoint(100,100);
 ///		points[1].setPoint(400,100);
 ///		points[2].setPoint(640,480);
 ///		points[3].setPoint(0,480);
 ///		screen.blt(tex2,0,0,null,points);	//	台形描画
 ///
 ///		screen.Update();
 ///	}
 ///	</code>
 ///	</example>
 public void Blt(ITexture src, Rect srcRect, Point[] point)
 {
     if (src != null)
         src.Blt(DrawContext, srcRect, point);
 }
Ejemplo n.º 7
0
 public Region2D(Rect rect)
 {
     this.Rect = rect;
 }
Ejemplo n.º 8
0
        public YanesdkResult Update()
        {
            // �܂������ŁALayout�̎w���s�Ȃ��K�v������̂�
            // Top,Left,Bottom,Right��m�肳���Ă����B

            float top, left, bottom, right;
            if (Rect1.Left < Rect1.Right)
            {
                left = Rect1.Left;
                right = Rect1.Right;
            }
            else
            {
                left = Rect1.Right;
                right = Rect1.Left;
            }
            if (Rect1.Top < Rect1.Bottom)
            {
                top = Rect1.Top;
                bottom = Rect1.Bottom;
            }
            else
            {
                top = Rect1.Bottom;
                bottom = Rect1.Top;
            }

            float srcRectWidth = right - left;
            float srcRectHeight = bottom - top;
            if (srcRectWidth <= 0 || srcRectHeight <= 0)
                return YanesdkResult.InvalidParameter;

            switch (Layout)
            {
                case BltLayout.TopLeft:
                    LayoutPoint = new Point(left, top); break;
                case BltLayout.TopMiddle:
                    LayoutPoint = new Point(left + srcRectWidth / 2, top); break;
                //	���]������`�̍��W���[���ɂȂ�ƃA���`�G�C���A�X��
                // �������ċC���������C��������邪�A����͎d�l�Ƃ������ƂŁB
                case BltLayout.TopRight:
                    LayoutPoint = new Point(right, top); break;

                case BltLayout.MiddleLeft:
                    LayoutPoint = new Point(left, top + srcRectHeight / 2); break;
                case BltLayout.Center:
                    LayoutPoint = new Point(left + srcRectWidth / 2, top + srcRectHeight / 2); break;
                case BltLayout.MiddleRight:
                    LayoutPoint = new Point(right, top + srcRectHeight / 2); break;

                case BltLayout.BottomLeft:
                    LayoutPoint = new Point(left, bottom); break;
                case BltLayout.BottomMiddle:
                    LayoutPoint = new Point(left + srcRectWidth / 2, bottom); break;
                case BltLayout.BottomRight:
                    LayoutPoint = new Point(right, bottom); break;

                default:
                    return YanesdkResult.InvalidParameter; // �����Ă͂Ȃ�Ȃ��̂����B
            }

            Rect2 = new Rect(left, top, right, bottom);

            return YanesdkResult.NoError;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// ITextureのBltのoverride
        /// </summary>
        /// <remarks>
        /// rateを考慮してのblt
        /// </remarks>
        /// <param name="drawContext"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="srcRect"></param>
        /// <param name="dstSize"></param>
        public void Blt(DrawContext drawContext,float x,float y, Rect srcRect,Size dstSize)
        {
            Point[] points = new Point[4];

            if (srcRect == null)
            {
                srcRect = new Rect(0, 0, Width, Height);
            }
            if (dstSize == null)
            {
                dstSize = new Size(drawContext.ScreenSizeX, drawContext.ScreenSizeY);
            }

            points[0].SetPoint(x,y);
            points[1].SetPoint(x+dstSize.Cx-1,y);
            points[2].SetPoint(x+dstSize.Cx-1,y+dstSize.Cy-1);
            points[3].SetPoint(x,y+dstSize.Cy-1);

            Blt(drawContext,srcRect,points);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// SetTexture����˂�R���X�g���N�^�B
 /// </summary>
 public TextureRect(ITexture texture, Rect srcRect,float offsetX, float offsetY)
 {
     SetTexture(texture, rect,offsetX, offsetY);
 }
Ejemplo n.º 11
0
 public void DrawImage(Image image, int x, int y, int width, int height, int row, int col, int deg, double stretch)
 {
     int left = width * col;
     int top = height * row;
     int right = left + width;
     int bottom = top + height;
     Rect srcRect = new Rect((float)left, (float)top, (float)right, (float)bottom);
     int yaneRad = -(int)Math.Round((double)(deg * 512) / 360);
     screen.BltRotate(textures[(int)image], x, y, srcRect, yaneRad, (float)stretch, 0, 0);
 }
Ejemplo n.º 12
0
 public void DrawImage(Image image, int x, int y, int width, int height, int row, int col)
 {
     int left = width * col;
     int top = height * row;
     int right = left + width;
     int bottom = top + height;
     Rect srcRect = new Rect((float)left, (float)top, (float)right, (float)bottom);
     screen.Blt(textures[(int)image], x, y, srcRect);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// �ʑ��p�`�Ƌ�`�Ƃ̌���̈����߂�B��`�͐����ł��邱�ƁB
        /// ����̈悪���݂��Ȃ����null�B
        /// 
        /// ��������ӎ����ăR�[�f�B���O���Ă���B
        /// �ʑ��p�`���܂邲��Rect a�Ɏ��܂�Ȃ�΁A�ʑ��p�`�ł���b�̎Q�Ƃ����̂܂ܕԂ邱�Ƃ����B(�������̂���)
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Point[] Intersect(Rect a, Point[] b)
        {
            int N = b.Length;

            // ���݂̃J�����g�̓_�̓����W�O�ł��邩
            bool isLastPointOut = false, isCurrentPointOut = false;
            // �������Ő錾����͍̂s�V���������A����͖{�����������Ȃ��Ă����ϐ��Ȃ̂�
            // unroll���Ă���Ƃ���ʼn��x����������ꂽ���Ȃ��B

            // y = top�Őؒf
            {
                bool inRect = true;  // ���ׂĂ���`��
                bool outRect = true; // ���ׂĂ���`�O
                float top = a.Top;

                for (int i = 0; i < N; ++i)
                {
                    outRect = outRect && (b[i].Y <= top);
                    inRect = inRect && (b[i].Y >= top);
                }
                if (outRect)
                    return null;
                if (!inRect)
                {
                    // �ʑ��p�`c �� y = top�Őؒf������̂�b�Ƃ���K�v������B
                    Polygon c = new Polygon();

                    // ���[�v�� 0��[1,N]�ɂ���΁A[1,N]�̋�Ԃ�(i-1)���񕉂ł��邱�Ƃ�ۏ؂ł���
                    for (int i = 0; i < N + 1; ++i)
                    {
                        isCurrentPointOut = b[i % N].Y < top;
                        if (i != 0)
                        {
                            if (isLastPointOut ^ isCurrentPointOut)
                            {
                                // �ӂ̗��[���̈��܂����̂Œ�����y=top�Ƃ̌�_��o��
                                Point p1 = b[(i - 1) % N];
                                Point p2 = b[i % N];

                                // t�EP1 + (1-t)�EP2 = { x , top }
                                // t(P1 - P2) + P2 = { x, top }
                                // �� t = (top - P2.Y)/(P1.Y - P2.Y)

                                float t = (top - p2.Y) / (p1.Y - p2.Y);
                                float x = t * p1.X + (1 - t) * p2.X;

                                c.Add(new Point(x, top));
                            }
                            if (!isCurrentPointOut)
                            {
                                // �ӂ̍���̒��_������̈�Ȃ̂�b[i]��o��
                                c.Add(b[i % N]);
                            }
                        }
                        isLastPointOut = isCurrentPointOut;
                    }
                    b = c.ToArray();
                    N = b.Length;
                }
            }

            // y = bottom�Őؒf
            {
                bool inRect = true;  // ���ׂĂ���`��
                bool outRect = true; // ���ׂĂ���`�O
                float bottom = a.Bottom;

                for (int i = 0; i < N; ++i)
                {
                    outRect = outRect && (b[i].Y >= bottom);
                    inRect = inRect && (b[i].Y <= bottom);
                }
                if (outRect)
                    return null;
                if (!inRect)
                {
                    // �ʑ��p�`c �� y = bottom�Őؒf������̂�b�Ƃ���K�v������B
                    Polygon c = new Polygon();

                    // ���[�v�� 0��[1,N]�ɂ���΁A[1,N]�̋�Ԃ�(i-1)���񕉂ł��邱�Ƃ�ۏ؂ł���
                    for (int i = 0; i < N + 1; ++i)
                    {
                        isCurrentPointOut = b[i % N].Y > bottom;
                        if (i != 0)
                        {
                            if (isLastPointOut ^ isCurrentPointOut)
                            {
                                // �ӂ̗��[���̈��܂����̂Œ�����y=bottom�Ƃ̌�_��o��
                                Point p1 = b[(i - 1) % N];
                                Point p2 = b[i % N];

                                // t�EP1 + (1-t)�EP2 = { x , bottom }
                                // t(P1 - P2) + P2 = { x, bottom }
                                // �� t = (bottom - P2.Y)/(P1.Y - P2.Y)

                                float t = (bottom - p2.Y) / (p1.Y - p2.Y);
                                float x = t * p1.X + (1 - t) * p2.X;

                                c.Add(new Point(x, bottom));
                            }
                            if (!isCurrentPointOut)
                            {
                                // �ӂ̍���̒��_������̈�Ȃ̂�b[i]��o��
                                c.Add(b[i % N]);
                            }
                        }
                        isLastPointOut = isCurrentPointOut;
                    }
                    b = c.ToArray();
                    N = b.Length;
                }
            }

            // x = left�Őؒf
            {
                bool inRect = true;  // ���ׂĂ���`��
                bool outRect = true; // ���ׂĂ���`�O
                float left = a.Left;

                for (int i = 0; i < N; ++i)
                {
                    outRect = outRect && (b[i].X <= left);
                    inRect = inRect && (b[i].X >= left);
                }
                if (outRect)
                    return null;
                if (!inRect)
                {
                    // �ʑ��p�`c �� y = left�Őؒf������̂�b�Ƃ���K�v������B
                    Polygon c = new Polygon();

                    // ���[�v�� 0��[1,N]�ɂ���΁A[1,N]�̋�Ԃ�(i-1)���񕉂ł��邱�Ƃ�ۏ؂ł���
                    for (int i = 0; i < N + 1; ++i)
                    {
                        isCurrentPointOut = b[i % N].X < left;
                        if (i != 0)
                        {
                            if (isLastPointOut ^ isCurrentPointOut)
                            {
                                // �ӂ̗��[���̈��܂����̂Œ�����x=left�Ƃ̌�_��o��
                                Point p1 = b[(i - 1) % N];
                                Point p2 = b[i % N];

                                // t�EP1 + (1-t)�EP2 = { left , y }
                                // t(P1 - P2) + P2 = { left , y }
                                // �� t = (left - P2.X)/(P1.X - P2.X)

                                float t = (left - p2.X) / (p1.X - p2.X);
                                float y = t * p1.Y + (1 - t) * p2.Y;

                                c.Add(new Point(left, y));
                            }
                            if (!isCurrentPointOut)
                            {
                                // �ӂ̍���̒��_������̈�Ȃ̂�b[i]��o��
                                c.Add(b[i % N]);
                            }
                        }
                        isLastPointOut = isCurrentPointOut;
                    }
                    b = c.ToArray();
                    N = b.Length;
                }
            }

            // x = right�Őؒf
            {
                bool inRect = true;  // ���ׂĂ���`��
                bool outRect = true; // ���ׂĂ���`�O
                float right = a.Right;

                for (int i = 0; i < N; ++i)
                {
                    outRect = outRect && (b[i].X >= right);
                    inRect = inRect && (b[i].X <= right);
                }
                if (outRect)
                    return null;
                if (!inRect)
                {
                    // �ʑ��p�`c �� y = right�Őؒf������̂�b�Ƃ���K�v������B
                    Polygon c = new Polygon();

                    // ���[�v�� 0��[1,N]�ɂ���΁A[1,N]�̋�Ԃ�(i-1)���񕉂ł��邱�Ƃ�ۏ؂ł���
                    for (int i = 0; i < N + 1; ++i)
                    {
                        isCurrentPointOut = b[i % N].X > right;
                        if (i != 0)
                        {
                            if (isLastPointOut ^ isCurrentPointOut)
                            {
                                // �ӂ̗��[���̈��܂����̂Œ�����x=right�Ƃ̌�_��o��
                                Point p1 = b[(i - 1) % N];
                                Point p2 = b[i % N];

                                // t�EP1 + (1-t)�EP2 = { left , y }
                                // t(P1 - P2) + P2 = { left , y }
                                // �� t = (left - P2.X)/(P1.X - P2.X)

                                float t = (right - p2.X) / (p1.X - p2.X);
                                float y = t * p1.Y + (1 - t) * p2.Y;

                                c.Add(new Point(right, y));
                            }
                            if (!isCurrentPointOut)
                            {
                                // �ӂ̍���̒��_������̈�Ȃ̂�b[i]��o��
                                c.Add(b[i % N]);
                            }
                        }
                    }
                    b = c.ToArray();
                    N = b.Length;
                }
            }

            return b;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Rect��Rect�̌���͈͂���߂�B
        /// ����̈悪�Ȃ����null�B
        /// 
        /// rect1,rect2�Ƃ�ɐ����łȂ���΂Ȃ�Ȃ��B
        /// </summary>
        /// <param name="rect1"></param>
        /// <param name="rect2"></param>
        /// <returns></returns>
        public static Rect Intersect(Rect rect1, Rect rect2)
        {
            if (rect1.Right <= rect2.Left ||
                rect2.Right <= rect1.Left ||
                rect1.Bottom <= rect2.Top ||
                rect2.Bottom <= rect1.Top )
                return null;

            // ����̈�͋�W���ł͂Ȃ��B

            return new Rect
            (
                rect1.Left < rect2.Left ? rect2.Left : rect1.Left ,			// max(left)
                rect1.Top < rect2.Top ? rect2.Top : rect1.Top ,				// max(top)
                rect1.Right < rect2.Right ? rect1.Right : rect2.Right,		// min(right)
                rect1.Bottom < rect2.Bottom ? rect1.Bottom : rect2.Bottom 	// min(bottom)
            );
        }
Ejemplo n.º 15
0
        /// <summary>
        /// bltの回転機能つき。
        /// </summary>
        /// <param name="src"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="srcRect"></param>
        /// <param name="rad"></param>
        /// <param name="rate"></param>
        /// <param name="bx"></param>
        /// <param name="by"></param>
        /// <remarks>
        /// <para>
        /// 指定のテクスチャを転送先の(x,y)に半径rで描画します。
        /// </para>
        /// <para>
        /// radの単位は、0~512で一周(2π)となる角度。
        /// 	回転の方向は、右まわり(時計まわり)。
        /// rateは、拡大率。1.0ならば等倍。
        /// (bx,by)は転送元の画像の、回転中心。
        /// srcRectは転送元矩形。nullならば転送元テクスチャ全体。
        /// </para>
        /// </remarks>
        public void BltRotate(ITexture src, int x, int y, Rect srcRect, int rad, float rate, int bx, int by)
        {
            if (src == null) return;

            int sx, sy;	//	転送元サイズ

            if (srcRect == null)
            {
                srcRect = new Rect(0, 0, src.Width, src.Height);
            }

            {
                sx = (int)(srcRect.Right - srcRect.Left);
                sy = (int)(srcRect.Bottom - srcRect.Top);
            }

            if (sx == 0 || sy == 0) return;

            int dx, dy;	//	転送先サイズ
            dx = (int)(sx * rate);
            dy = (int)(sy * rate);
            if (dx == 0 || dy == 0) return;

            // 転送元の回転中心
            bx = (int)(bx * rate);
            by = (int)(by * rate);

            //	転送後の座標を計算する
            int nSin = SinTable.Instance.Sin(rad);
            int nCos = SinTable.Instance.Cos(rad);

            Point[] dstPoints = new Point[4];

            //	0.5での丸めのための修正項 → 0x8000
            int px = x + bx;
            int py = y + by;

            int ax0 = -bx;
            int ay0 = -by;
            dstPoints[0].X = Round.RShift((int)(ax0 * nCos - ay0 * nSin), 16) + px;
            dstPoints[0].Y = Round.RShift((int)(ax0 * nSin + ay0 * nCos), 16) + py;
            int ax1 = dx - bx;
            int ay1 = -by;
            dstPoints[1].X = Round.RShift((int)(ax1 * nCos - ay1 * nSin), 16) + px;
            dstPoints[1].Y = Round.RShift((int)(ax1 * nSin + ay1 * nCos), 16) + py;
            int ax2 = dx - bx;
            int ay2 = dy - by;
            dstPoints[2].X = Round.RShift((int)(ax2 * nCos - ay2 * nSin), 16) + px;
            dstPoints[2].Y = Round.RShift((int)(ax2 * nSin + ay2 * nCos), 16) + py;
            int ax3 = -bx;
            int ay3 = dy - by;
            dstPoints[3].X = Round.RShift((int)(ax3 * nCos - ay3 * nSin), 16) + px;
            dstPoints[3].Y = Round.RShift((int)(ax3 * nSin + ay3 * nCos), 16) + py;
            //	変数無駄な代入が多いが、最適化されるかなぁ(´Д`)

            src.Blt(DrawContext, srcRect, dstPoints);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// �e�N�X�`���ƁA���̂ǂ̕�������̃e�N�X�`���Ƃ��Ĉ����̂���ݒ肷��B
 /// 
 /// �����Ŏw�肷��offsetX,offsetY�͂��̃N���X�̃v���p�e�B�ł���
 /// OffsetX,OffsetY�B
 /// </summary>
 public void SetTexture(ITexture texture, float offsetX, float offsetY)
 {
     this.texture = texture;
     this.rect = null;
     this.offsetX = offsetX;
     this.offsetY = offsetY;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// SetTexture����˂�R���X�g���N�^�B
 /// </summary>
 public TextureRect(ITexture texture, Rect rect)
 {
     SetTexture(texture, rect);
 }
Ejemplo n.º 18
0
 public void DrawCharacter(char c, int x, int y)
 {
     ITexture texture = textures[(int)Image.Hud];
     int u, v;
     if ('0' <= c && c <= '9')
     {
         u = (c - '0') * 16;
         v = 0;
     }
     else if ('A' <= c && c <= 'P')
     {
         u = (c - 'A') * 16;
         v = 16;
     }
     else if ('Q' <= c && c <= 'Z')
     {
         u = (c - 'Q') * 16;
         v = 32;
     }
     else
     {
         switch (c)
         {
             case '#':
                 u = 160;
                 v = 0;
                 break;
             case '$':
                 u = 160;
                 v = 32;
                 break;
             case '_':
                 u = 176;
                 v = 32;
                 break;
             case '<':
                 u = 0;
                 v = 48;
                 break;
             case '>':
                 u = 16;
                 v = 48;
                 break;
             default:
                 return;
         }
     }
     Rect srcRect = new Rect((float)u, (float)v, (float)(u + 16), (float)(v + 16));
     screen.Blt(texture, x, y, srcRect);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// ITextureのBltのoverride
        /// </summary>
        /// <remarks>
        /// rateを考慮してのblt
        /// </remarks>
        /// <param name="drawContext"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="srcRect"></param>
        public void Blt(DrawContext drawContext,float x,float y,Rect srcRect)
        {
            Point[] points = new Point[4];
            float w,h;

            if (srcRect == null)
            {
                srcRect = new Rect(0, 0, Width, Height);
            }

            w = srcRect.Right - srcRect.Left;
            if (w<0) w = -w;

            h = srcRect.Bottom - srcRect.Top;
            if (h<0) h = -h;

            points[0].SetPoint(x,y);
            points[1].SetPoint(x+w*rate,y);
            points[2].SetPoint(x+w*rate,y+h*rate);
            points[3].SetPoint(x,y+h*rate);

            Blt(drawContext,srcRect,points);
        }
Ejemplo n.º 20
0
        /*
        /// <summary>
        /// ���̃e�N�X�`����w���screen��blt����B
        /// </summary>
        /// <param name="drawContext"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <remarks>
        /// visitor�p�^�[���̂��߂Ɏ������Ă���B
        /// SDLWindow.blt����Visitor�Ƃ��ČĂяo�����B
        /// </remarks>
        public void Blt(DrawContext context, float x, float y)
        {
            texture.Blt(context, x +DstOffsetX, y + DstOffsetY, rect);
        }

        /// <summary>
        /// ���̃e�N�X�`����w���screen��blt����B
        /// </summary>
        /// <param name="drawContext"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="srcRect"></param>
        /// <remarks>
        /// visitor�p�^�[���̂��߂Ɏ������Ă���B
        /// SDLWindow.blt����Visitor�Ƃ��ČĂяo�����B
        /// </remarks>
        public void Blt(DrawContext src, float x, float y, Rect srcRect)
        {
            // ����srcRect��rect�̂Ȃ��ł̍��W��Ӗ�����̂ō��W�ϊ���{���K�v������B
            Rect r = Rect.CalcRectInRect(rect, srcRect);

            texture.Blt(src, x + DstOffsetX, y + DstOffsetY, r);
        }
        */
        /// <summary>
        /// ���̃e�N�X�`����w���screen��blt����B
        /// </summary>
        /// <param name="drawContext"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="srcRect"></param>
        /// <param name="dstSize"></param>
        /// <remarks>
        /// visitor�p�^�[���̂��߂Ɏ������Ă���B
        /// SDLWindow.blt����Visitor�Ƃ��ČĂяo�����B
        /// </remarks>
        public void Blt(DrawContext src, float x, float y, Rect srcRect, Size dstSize)
        {
            // ����srcRect��rect�̂Ȃ��ł̍��W��Ӗ�����̂ō��W�ϊ���{���K�v������B
            //	Rect r = Rect.CalcRectInRect(rect, srcRect);
            Rect r = srcRect;

            texture.Blt(src, x + DstOffsetX, y + DstOffsetY, r, dstSize);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// ITextureのBltのoverride
        /// </summary>
        /// <param name="drawContext"></param>
        /// <param name="srcRect"></param>
        /// <param name="dstPoint"></param>
        public void Blt(DrawContext drawContext,Rect srcRect,Point[] dstPoint)
        {
            float w = Width;
            float h = Height;

            if (srcRect == null)
            {
                srcRect = new Rect(0, 0, Width, Height);
            }

            Rect sr = new Rect(srcRect.Left / w, srcRect.Top / h, srcRect.Right / w, srcRect.Bottom / h);
            {
                //	転送元は0.0~1.0にclipping
                if (sr.Left<0.0) sr.Left = 0.0f;
                if (sr.Right<0.0) sr.Right = 0.0f;
                if (sr.Top<0.0) sr.Top = 0.0f;
                if (sr.Bottom<0.0) sr.Bottom = 0.0f;
                if (sr.Left>1.0) sr.Left = 1.0f;
                if (sr.Right>1.0) sr.Right = 1.0f;
                if (sr.Top>1.0) sr.Top = 1.0f;
                if (sr.Bottom>1.0) sr.Bottom = 1.0f;
            }

            bool bW=false,bH=false; // 水平方向の反転フラグ

            float www = sr.Right - sr.Left;
            float hhh = sr.Bottom - sr.Top;

            if (www == 0 || hhh == 0) return ;
            if (www<0) { www = -www; bW = true; }
            if (hhh<0) { hhh = -hhh; bH = true; }

            foreach(TextureInfo info in infos){

                Point[] dp = new Point[4];	//	転送先
                Rect r = new Rect();			//	転送元矩形

                //	転送元矩形をテクスチャ座標で表したもの
                Rect rr = new Rect(info.Left, info.Top, info.Right, info.Bottom);

                // sr のなかに含まれる矩形か?
                if (sr.Left <= info.Left && info.Right	<= sr.Right
                    &&	sr.Top	<= info.Top  && info.Bottom <= sr.Bottom){
                    //	含まれるのでそのまま描画
                    r.SetRect(0,0,info.Width,info.Height);
                } else {
                    //	完全には含まれていないので、削り取る作業が必要
                    r.SetRect(0,0,info.Width,info.Height);

                    float ww = info.Width  / (info.Right-info.Left);
                    float hh = info.Height / (info.Bottom-info.Top);

                    float t;

                    if (!bW){
                        t = sr.Left - info.Left;
                        if (t>0) {
                            r.Left += t * ww;
                            rr.Left = sr.Left;
                        }
                        t = info.Right - sr.Right;
                        if (t>0) {
                            r.Right -= t * ww;
                            rr.Right = sr.Right;
                        }

                        if (r.Left > r.Right) continue; // 表示エリアなし
                    } else {
                        t = sr.Right - info.Left;
                        if (t>0) {
                            r.Left += t * ww;
                            rr.Left = sr.Right;
                        }

                        t = info.Right - sr.Left;
                        if (t>0) {
                            r.Right -= t * ww;
                            rr.Right = sr.Left;
                        }
                        if (r.Left > r.Right) continue; // 表示エリアなし
                    }
                    if (!bH){
                        t = sr.Top - info.Top;
                        if (t>0) {
                            r.Top += t * hh;
                            rr.Top = sr.Top;
                        }
                        t = info.Bottom - sr.Bottom;
                        if (t>0) {
                            r.Bottom -= t * hh;
                            rr.Bottom = sr.Bottom;
                        } else t = 0;
                        if (r.Top > r.Bottom) continue; // 表示エリアなし
                    } else {
                        t = sr.Bottom - info.Top;
                        if (t>0) {
                            r.Top += t * hh;
                            rr.Top = sr.Bottom;
                        } else t = 0;
                        t = info.Bottom - sr.Top;
                        if (t>0) {
                            r.Bottom -= t * hh;
                            rr.Bottom = sr.Top;
                        }
                        if (r.Top > r.Bottom) continue; // 表示エリアなし
                    }
                }

                float leftRM;
                float rightRM;
                if (!bW){
                    leftRM	= (rr.Left - sr.Left) / www;
                    rightRM = (rr.Right - sr.Left) / www;
                } else {
                    leftRM	= (1 - (rr.Left - sr.Right)) / www;
                    rightRM = (1 - (rr.Right - sr.Right)) / www;
                }
                float topRM;
                float bottomRM;
                if (!bH){
                    topRM = (rr.Top - sr.Top) / hhh;
                    bottomRM = (rr.Bottom - sr.Top) / hhh;
                } else {
                    topRM = (1-(rr.Top - sr.Bottom)) / hhh;
                    bottomRM = (1-(rr.Bottom - sr.Bottom)) / hhh;
                }

                calcUV(dstPoint,leftRM,topRM,ref dp[0]);
                calcUV(dstPoint,rightRM,topRM,ref dp[1]);
                calcUV(dstPoint,rightRM,bottomRM,ref dp[2]);
                calcUV(dstPoint,leftRM,bottomRM,ref dp[3]);

                info.Texture.Blt(drawContext,r,dp);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// ���̃e�N�X�`����w���screen��blt����B
        /// </summary>
        /// <param name="src"></param>
        /// <param name="srcRect"></param>
        /// <param name="dstPoint"></param>
        /// <remarks>
        /// visitor�p�^�[���̂��߂Ɏ������Ă���B
        /// SDLWindow.blt����Visitor�Ƃ��ČĂяo�����B
        /// </remarks>
        public void Blt(DrawContext src, Rect srcRect, Point[] dstPoint)
        {
            // ����srcRect��rect�̂Ȃ��ł̍��W��Ӗ�����̂ō��W�ϊ���{���K�v������B
            //	Rect r = Rect.CalcRectInRect(rect, srcRect);
            Rect r = srcRect;

            Point[] dstPoint_ = new Point[dstPoint.Length];
            for (int i = 0; i < dstPoint_.Length; ++i)
            {
                dstPoint_[i].X = dstPoint[i].X + DstOffsetX;
                dstPoint_[i].Y = dstPoint[i].Y + DstOffsetY;
            }

            texture.Blt(src, r, dstPoint_);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// src Rect��dst Rect�֕ϊ�����Affine�s�����߂�B
        /// src,dst Rect�͐����ł��邱�ƁB
        /// �����̐���ɂ‚��Ă�Rect�̐�������B
        /// 
        /// �܂����߂�ׂ�Affine�s�񂪑��݂��Ȃ��Ƃ���null���Ԃ�B
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        public static Affine2D RectToRect(Rect src,Rect dst)
        {
            float srcWidth = src.Width;
            if (srcWidth == 0)
                return null;
            float widthRate = dst.Width / srcWidth;

            float srcHeight = src.Height;
            if (srcHeight == 0)
                return null;
            float heightRate = dst.Height / srcHeight;

            // ���s�ړ���
            Point point = dst.TopLeft - src.TopLeft;

            return new Affine2D(widthRate, 0, 0, heightRate, point.X,point.Y);
        }
Ejemplo n.º 24
0
 /// <summary>
 /// �e�N�X�`���ƁA���̂ǂ̕�������̃e�N�X�`���Ƃ��Ĉ����̂���ݒ肷��B
 /// 
 /// rect == null�ł����texture�S�́B
 /// OffsetX = OffsetY = 0�ɂ���B
 /// 
 /// �����Ŏw�肷��offsetX,offsetY�͂��̃N���X�̃v���p�e�B�ł���
 /// OffsetX,OffsetY�B
 /// </summary>
 /// <param name="texture"></param>
 /// <param name="rect"></param>
 public void SetTexture(ITexture texture, Rect rect)
 {
     this.texture = texture;
     this.rect = rect;
     this.offsetX = this.offsetY = 0;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// クリップする矩形を指定する。
 /// </summary>
 /// <param name="rc"></param>
 /// <remarks>
 /// <para>
 /// ここで指定するRectの座標系は、
 /// (screenSizeX,screenSizeY)を基準とする。
 /// </para>
 /// <para>
 /// Rectの(Left,bottm)の点は含まない。
 /// </para>>
 /// <para>
 /// すなわち、 <c>screenSizeX = 640, screenSize Y = 480 </c>のときに
 /// (0,0,640,480)のRectをClip矩形として渡した場合、
 /// <c>Top = 0, Left = 0, Right = 1.0 , Bottom = 1.0</c>
 /// がclip位置として記録されることになる。
 /// </para>
 /// </remarks>
 public void SetClipRect(ref Rect rc)
 {
     Left   = rc.Left   / screenSizeX;
     Top    = rc.Top    / screenSizeY;
     Right  = rc.Right  / screenSizeX;
     Bottom = rc.Bottom / screenSizeY;
     Update();
 }
Ejemplo n.º 26
0
 ///	<summary>画像の描画(2D)。</summary>
 /// <remarks>
 ///	bltの転送元矩形と転送先サイズの指定できるバージョン。
 ///	srcRectがnullのときはソース全域。
 ///	dstSizeがnullのときは転送先全域(のサイズ)。
 ///
 ///	転送元矩形として、(Right,Top,Left,Bottom)を指定すれば
 ///	左右反転して表示される。(Left,Bottom,Right,Top)を指定すれば
 ///	上下反転して表示される。
 /// </remarks>
 public void Blt(ITexture src, int x, int y, Rect srcRect, Size dstSize)
 {
     if (src != null)
         src.Blt(DrawContext, x, y, srcRect, dstSize);
 }