コード例 #1
0
        public void OnPopulateMesh(VertexBuffer vb)
        {
            Rectangle rect = texture.GetDrawRect(vb.contentRect);

            vb.AddQuad(rect, vb.vertexColor, vb.uvRect);
            vb.AddTriangles();
        }
コード例 #2
0
ファイル: Image.cs プロジェクト: akwang1000/FairyGUI-unity
		public void OnPopulateMesh(VertexBuffer vb)
		{
			if (_fillMesh != null && _fillMesh.method != FillMethod.None)
			{
				_fillMesh.OnPopulateMesh(vb);
			}
			else if (_scaleByTile)
			{
				float sourceW = texture.width;
				float sourceH = texture.height;

				if (texture.root == texture
							&& texture.nativeTexture != null
							&& texture.nativeTexture.wrapMode == TextureWrapMode.Repeat)
				{
					Rect uvRect = vb.uvRect;
					uvRect.width *= vb.contentRect.width / sourceW;
					uvRect.height *= vb.contentRect.height / sourceH;

					vb.AddQuad(vb.contentRect, vb.vertexColor, uvRect);
					vb.AddTriangles();
				}
				else
				{
					TileFill(vb, vb.contentRect, vb.uvRect, sourceW, sourceH);
					vb.AddTriangles();
				}
			}
			else if (_scale9Grid != null)
			{
				SliceFill(vb);
			}
			else
				graphics.OnPopulateMesh(vb);
		}
コード例 #3
0
ファイル: Image.cs プロジェクト: pinzeweifen/DCET
        void TileFill(VertexBuffer vb, Rect contentRect, Rect uvRect, float sourceW, float sourceH)
        {
            int   hc         = Mathf.CeilToInt(contentRect.width / sourceW);
            int   vc         = Mathf.CeilToInt(contentRect.height / sourceH);
            float tailWidth  = contentRect.width - (hc - 1) * sourceW;
            float tailHeight = contentRect.height - (vc - 1) * sourceH;
            float xMax       = uvRect.xMax;
            float yMax       = uvRect.yMax;

            for (int i = 0; i < hc; i++)
            {
                for (int j = 0; j < vc; j++)
                {
                    Rect uvTmp = uvRect;
                    if (i == hc - 1)
                    {
                        uvTmp.xMax = Mathf.Lerp(uvRect.x, xMax, tailWidth / sourceW);
                    }
                    if (j == vc - 1)
                    {
                        uvTmp.yMin = Mathf.Lerp(uvRect.y, yMax, 1 - tailHeight / sourceH);
                    }

                    vb.AddQuad(new Rect(contentRect.x + i * sourceW, contentRect.y + j * sourceH,
                                        i == (hc - 1) ? tailWidth : sourceW, j == (vc - 1) ? tailHeight : sourceH), vb.vertexColor, uvTmp);
                }
            }
        }
コード例 #4
0
        void TileFill(VertexBuffer vb, Rectangle contentRect, Rectangle uvRect, float sourceW, float sourceH)
        {
            int   hc         = (int)Math.Ceiling(contentRect.Width / sourceW);
            int   vc         = (int)Math.Ceiling(contentRect.Height / sourceH);
            float tailWidth  = contentRect.Width - (hc - 1) * sourceW;
            float tailHeight = contentRect.Height - (vc - 1) * sourceH;
            float xMax       = uvRect.Right;
            float yMax       = uvRect.Bottom;

            for (int i = 0; i < hc; i++)
            {
                for (int j = 0; j < vc; j++)
                {
                    Rectangle uvTmp = uvRect;
                    if (i == hc - 1)
                    {
                        uvTmp.Width = MathHelper.Lerp(uvRect.X, xMax, tailWidth / sourceW) - uvTmp.X;
                    }
                    if (j == vc - 1)
                    {
                        float tmp = MathHelper.Lerp(uvRect.Y, yMax, 1 - tailHeight / sourceH);
                        uvTmp.Height -= (tmp - uvTmp.Y);
                        uvTmp.Y       = tmp;
                    }

                    vb.AddQuad(new Rectangle(contentRect.X + i * sourceW, contentRect.Y + j * sourceH,
                                             i == (hc - 1) ? tailWidth : sourceW, j == (vc - 1) ? tailHeight : sourceH), vb.vertexColor, uvTmp);
                }
            }
        }
コード例 #5
0
        public void OnPopulateMesh(VertexBuffer vb)
        {
            Rect rect = texture.GetDrawRect(vb.contentRect);

            vb.AddQuad(rect, vb.vertexColor, vb.uvRect);
            vb.AddTriangles();
            vb._isArbitraryQuad = _vertexMatrix != null;
        }
コード例 #6
0
ファイル: NGraphics.cs プロジェクト: pinzeweifen/DCET
        public void OnPopulateMesh(VertexBuffer vb)
        {
            Rect rect = texture.GetDrawRect(vb.contentRect);

            if (_vertexMatrix != null)            //画多边形时,要对UV处理才能有正确的显示,暂时未掌握,这里用更多的面来临时解决。
            {
                int   hc = (int)Mathf.Min(Mathf.CeilToInt(rect.width / 30), 9);
                int   vc = (int)Mathf.Min(Mathf.CeilToInt(rect.height / 30), 9);
                int   eachPartX = Mathf.FloorToInt(rect.width / hc);
                int   eachPartY = Mathf.FloorToInt(rect.height / vc);
                float x, y;
                for (int i = 0; i <= vc; i++)
                {
                    if (i == vc)
                    {
                        y = rect.yMax;
                    }
                    else
                    {
                        y = rect.y + i * eachPartY;
                    }
                    for (int j = 0; j <= hc; j++)
                    {
                        if (j == hc)
                        {
                            x = rect.xMax;
                        }
                        else
                        {
                            x = rect.x + j * eachPartX;
                        }
                        vb.AddVert(new Vector3(x, y, 0));
                    }
                }

                for (int i = 0; i < vc; i++)
                {
                    int k = i * (hc + 1);
                    for (int j = 1; j <= hc; j++)
                    {
                        int m = k + j;
                        vb.AddTriangle(m - 1, m, m + hc);
                        vb.AddTriangle(m, m + hc + 1, m + hc);
                    }
                }
            }
            else
            {
                vb.AddQuad(rect, vb.vertexColor, vb.uvRect);
                vb.AddTriangles();
            }
        }
コード例 #7
0
        static void FillHorizontal(VertexBuffer vb, Rect vertRect, OriginHorizontal origin, float amount)
        {
            float a = vertRect.width * amount;

            if (origin == OriginHorizontal.Right)
            {
                vertRect.x += (vertRect.width - a);
            }
            vertRect.width = a;

            vb.AddQuad(vertRect);
            vb.AddTriangles();
        }
コード例 #8
0
        static void FillVertical(VertexBuffer vb, Rectangle vertRect, OriginVertical origin, float amount)
        {
            float a = vertRect.Height * amount;

            if (origin == OriginVertical.Bottom)
            {
                vertRect.Y += (vertRect.Height - a);
            }
            vertRect.Height = a;

            vb.AddQuad(vertRect);
            vb.AddTriangles();
        }
コード例 #9
0
        static void FillVertical(VertexBuffer vb, Rect vertRect, int origin, float amount)
        {
            float a = vertRect.height * amount;

            if ((OriginHorizontal)origin == OriginHorizontal.Right || (OriginVertical)origin == OriginVertical.Bottom)
            {
                vertRect.y += (vertRect.height - a);
            }
            vertRect.height = a;

            vb.AddQuad(vertRect);
            vb.AddTriangles();
        }
コード例 #10
0
        public void OnPopulateMesh(VertexBuffer vb)
        {
            int count = rects.Count;

            if (count == 0)
            {
                return;
            }

            for (int i = 0; i < count; i++)
            {
                vb.AddQuad(rects[i]);
            }
            vb.AddTriangles();
        }
コード例 #11
0
        public void OnPopulateMesh(VertexBuffer vb, Color[] gradientColors)
        {
            Rect rect = texture.GetDrawRect(vb.contentRect);

            if (gradientColors != null)
            {
                vb.AddGradientColorsQuad(rect, vb.vertexColor, gradientColors, vb.uvRect);
            }
            else
            {
                vb.AddQuad(rect, vb.vertexColor, vb.uvRect);
            }
            vb.AddTriangles();
            vb._isArbitraryQuad = vertexMatrix != null;
        }
コード例 #12
0
ファイル: Image.cs プロジェクト: tuita520/TinyDialogueEditor
        public void OnPopulateMesh(VertexBuffer vb)
        {
            if (_fillMesh != null && _fillMesh.method != FillMethod.None)
            {
                _fillMesh.OnPopulateMesh(vb);
            }
            else if (_scaleByTile)
            {
                NTexture texture = graphics.texture;
                if (texture.root == texture &&
                    texture.nativeTexture != null &&
                    texture.nativeTexture.wrapMode == TextureWrapMode.Repeat)
                {
                    Rect uvRect = vb.uvRect;
                    uvRect.width  *= vb.contentRect.width / texture.width * _textureScale.x;
                    uvRect.height *= vb.contentRect.height / texture.height * _textureScale.y;

                    vb.AddQuad(vb.contentRect, vb.vertexColor, uvRect);
                    vb.AddTriangles();
                }
                else
                {
                    Rect contentRect = vb.contentRect;
                    contentRect.width  *= _textureScale.x;
                    contentRect.height *= _textureScale.y;

                    TileFill(vb, contentRect, vb.uvRect, texture.width, texture.height);
                    vb.AddTriangles();
                }
            }
            else if (_scale9Grid != null)
            {
                SliceFill(vb);
            }
            else
            {
                graphics.OnPopulateMesh(vb);
            }
        }
コード例 #13
0
ファイル: RectMesh.cs プロジェクト: kyrie6510/FairyExample
        public void OnPopulateMesh(VertexBuffer vb)
        {
            Rect    rect  = drawRect != null ? (Rect)drawRect : vb.contentRect;
            Color32 color = fillColor != null ? (Color32)fillColor : vb.vertexColor;

            if (lineWidth == 0)
            {
                if (color.a != 0)//optimized
                {
                    vb.AddQuad(rect, color);
                }
            }
            else
            {
                Rect part;

                //left,right
                part = new Rect(rect.x, rect.y, lineWidth, rect.height);
                vb.AddQuad(part, lineColor);
                part = new Rect(rect.xMax - lineWidth, rect.y, lineWidth, rect.height);
                vb.AddQuad(part, lineColor);

                //top, bottom
                part = new Rect(rect.x + lineWidth, rect.y, rect.width - lineWidth * 2, lineWidth);
                vb.AddQuad(part, lineColor);
                part = new Rect(rect.x + lineWidth, rect.yMax - lineWidth, rect.width - lineWidth * 2, lineWidth);
                vb.AddQuad(part, lineColor);

                //middle
                if (color.a != 0)//optimized
                {
                    part = Rect.MinMaxRect(rect.x + lineWidth, rect.y + lineWidth, rect.xMax - lineWidth, rect.yMax - lineWidth);
                    if (part.width > 0 && part.height > 0)
                    {
                        vb.AddQuad(part, color);
                    }
                }
            }

            if (colors != null)
            {
                vb.RepeatColors(colors, 0, vb.currentVertCount);
            }

            vb.AddTriangles();
        }
コード例 #14
0
ファイル: RectMesh.cs プロジェクト: zhzhwcn/FairyGUI-monogame
        public void OnPopulateMesh(VertexBuffer vb)
        {
            Rectangle rect  = drawRect != null ? (Rectangle)drawRect : vb.contentRect;
            Color     color = fillColor != null ? (Color)fillColor : vb.vertexColor;

            if (lineWidth == 0)
            {
                if (color.A != 0)                //optimized
                {
                    vb.AddQuad(rect, color);
                }
            }
            else
            {
                Rectangle part;

                //left,right
                part = Rectangle.FromLTRB(rect.X, rect.Y, lineWidth, rect.Height);
                vb.AddQuad(part, lineColor);
                part = Rectangle.FromLTRB(rect.Right - lineWidth, 0, rect.Right, rect.Bottom);
                vb.AddQuad(part, lineColor);

                //top, bottom
                part = Rectangle.FromLTRB(lineWidth, rect.X, rect.Right - lineWidth, lineWidth);
                vb.AddQuad(part, lineColor);
                part = Rectangle.FromLTRB(lineWidth, rect.Bottom - lineWidth, rect.Right - lineWidth, rect.Bottom);
                vb.AddQuad(part, lineColor);

                //middle
                if (color.A != 0)                //optimized
                {
                    part = Rectangle.FromLTRB(lineWidth, lineWidth, rect.Right - lineWidth, rect.Bottom - lineWidth);
                    vb.AddQuad(part, color);
                }
            }

            if (colors != null)
            {
                vb.RepeatColors(colors, 0, vb.currentVertCount);
            }

            vb.AddTriangles();
        }
コード例 #15
0
        //12 vertex
        static void FillRadial360(VertexBuffer vb, Rect vertRect, Origin360 origin, float amount, bool clockwise)
        {
            switch (origin)
            {
            case Origin360.Top:
                if (amount < 0.5f)
                {
                    vertRect.width /= 2;
                    if (clockwise)
                    {
                        vertRect.x += vertRect.width;
                    }

                    FillRadial180(vb, vertRect, clockwise ? Origin180.Left : Origin180.Right, amount / 0.5f, clockwise);
                    Vector3 vec = vb.GetPosition(-8);
                    vb.AddQuad(new Rect(vec.x, vec.y, 0, 0));
                    vb.AddTriangles(-4);
                }
                else
                {
                    vertRect.width /= 2;
                    if (!clockwise)
                    {
                        vertRect.x += vertRect.width;
                    }

                    FillRadial180(vb, vertRect, clockwise ? Origin180.Right : Origin180.Left, (amount - 0.5f) / 0.5f, clockwise);

                    if (clockwise)
                    {
                        vertRect.x += vertRect.width;
                    }
                    else
                    {
                        vertRect.x -= vertRect.width;
                    }
                    vb.AddQuad(vertRect);
                    vb.AddTriangles(-4);
                }

                break;

            case Origin360.Bottom:
                if (amount < 0.5f)
                {
                    vertRect.width /= 2;
                    if (!clockwise)
                    {
                        vertRect.x += vertRect.width;
                    }

                    FillRadial180(vb, vertRect, clockwise ? Origin180.Right : Origin180.Left, amount / 0.5f, clockwise);
                    Vector3 vec = vb.GetPosition(-8);
                    vb.AddQuad(new Rect(vec.x, vec.y, 0, 0));
                    vb.AddTriangles(-4);
                }
                else
                {
                    vertRect.width /= 2;
                    if (clockwise)
                    {
                        vertRect.x += vertRect.width;
                    }

                    FillRadial180(vb, vertRect, clockwise ? Origin180.Left : Origin180.Right, (amount - 0.5f) / 0.5f, clockwise);

                    if (clockwise)
                    {
                        vertRect.x -= vertRect.width;
                    }
                    else
                    {
                        vertRect.x += vertRect.width;
                    }
                    vb.AddQuad(vertRect);
                    vb.AddTriangles(-4);
                }
                break;

            case Origin360.Left:
                if (amount < 0.5f)
                {
                    vertRect.height /= 2;
                    if (!clockwise)
                    {
                        vertRect.y += vertRect.height;
                    }

                    FillRadial180(vb, vertRect, clockwise ? Origin180.Bottom : Origin180.Top, amount / 0.5f, clockwise);
                    Vector3 vec = vb.GetPosition(-8);
                    vb.AddQuad(new Rect(vec.x, vec.y, 0, 0));
                    vb.AddTriangles(-4);
                }
                else
                {
                    vertRect.height /= 2;
                    if (clockwise)
                    {
                        vertRect.y += vertRect.height;
                    }

                    FillRadial180(vb, vertRect, clockwise ? Origin180.Top : Origin180.Bottom, (amount - 0.5f) / 0.5f, clockwise);

                    if (clockwise)
                    {
                        vertRect.y -= vertRect.height;
                    }
                    else
                    {
                        vertRect.y += vertRect.height;
                    }
                    vb.AddQuad(vertRect);
                    vb.AddTriangles(-4);
                }
                break;

            case Origin360.Right:
                if (amount < 0.5f)
                {
                    vertRect.height /= 2;
                    if (clockwise)
                    {
                        vertRect.y += vertRect.height;
                    }

                    FillRadial180(vb, vertRect, clockwise ? Origin180.Top : Origin180.Bottom, amount / 0.5f, clockwise);
                    Vector3 vec = vb.GetPosition(-8);
                    vb.AddQuad(new Rect(vec.x, vec.y, 0, 0));
                    vb.AddTriangles(-4);
                }
                else
                {
                    vertRect.height /= 2;
                    if (!clockwise)
                    {
                        vertRect.y += vertRect.height;
                    }

                    FillRadial180(vb, vertRect, clockwise ? Origin180.Bottom : Origin180.Top, (amount - 0.5f) / 0.5f, clockwise);

                    if (clockwise)
                    {
                        vertRect.y += vertRect.height;
                    }
                    else
                    {
                        vertRect.y -= vertRect.height;
                    }
                    vb.AddQuad(vertRect);
                    vb.AddTriangles(-4);
                }
                break;
            }
        }
コード例 #16
0
        //8 vertex
        static void FillRadial180(VertexBuffer vb, Rectangle vertRect, Origin180 origin, float amount, bool clockwise)
        {
            switch (origin)
            {
            case Origin180.Top:
                if (amount <= 0.5f)
                {
                    vertRect.Width /= 2;
                    if (clockwise)
                    {
                        vertRect.X += vertRect.Width;
                    }

                    FillRadial90(vb, vertRect, clockwise ? Origin90.TopLeft : Origin90.TopRight, amount / 0.5f, clockwise);
                    Vector3 vec = vb.GetPosition(-4);
                    vb.AddQuad(new Rectangle(vec.X, vec.Y, 0, 0));
                    vb.AddTriangles(-4);
                }
                else
                {
                    vertRect.Width /= 2;
                    if (!clockwise)
                    {
                        vertRect.X += vertRect.Width;
                    }

                    FillRadial90(vb, vertRect, clockwise ? Origin90.TopRight : Origin90.TopLeft, (amount - 0.5f) / 0.5f, clockwise);

                    if (clockwise)
                    {
                        vertRect.X += vertRect.Width;
                    }
                    else
                    {
                        vertRect.X -= vertRect.Width;
                    }
                    vb.AddQuad(vertRect);
                    vb.AddTriangles(-4);
                }
                break;

            case Origin180.Bottom:
                if (amount <= 0.5f)
                {
                    vertRect.Width /= 2;
                    if (!clockwise)
                    {
                        vertRect.X += vertRect.Width;
                    }

                    FillRadial90(vb, vertRect, clockwise ? Origin90.BottomRight : Origin90.BottomLeft, amount / 0.5f, clockwise);
                    Vector3 vec = vb.GetPosition(-4);
                    vb.AddQuad(new Rectangle(vec.X, vec.Y, 0, 0));
                    vb.AddTriangles(-4);
                }
                else
                {
                    vertRect.Width /= 2;
                    if (clockwise)
                    {
                        vertRect.X += vertRect.Width;
                    }

                    FillRadial90(vb, vertRect, clockwise ? Origin90.BottomLeft : Origin90.BottomRight, (amount - 0.5f) / 0.5f, clockwise);

                    if (clockwise)
                    {
                        vertRect.X -= vertRect.Width;
                    }
                    else
                    {
                        vertRect.X += vertRect.Width;
                    }
                    vb.AddQuad(vertRect);
                    vb.AddTriangles(-4);
                }
                break;

            case Origin180.Left:
                if (amount <= 0.5f)
                {
                    vertRect.Height /= 2;
                    if (!clockwise)
                    {
                        vertRect.Y += vertRect.Height;
                    }

                    FillRadial90(vb, vertRect, clockwise ? Origin90.BottomLeft : Origin90.TopLeft, amount / 0.5f, clockwise);
                    Vector3 vec = vb.GetPosition(-4);
                    vb.AddQuad(new Rectangle(vec.X, vec.Y, 0, 0));
                    vb.AddTriangles(-4);
                }
                else
                {
                    vertRect.Height /= 2;
                    if (clockwise)
                    {
                        vertRect.Y += vertRect.Height;
                    }

                    FillRadial90(vb, vertRect, clockwise ? Origin90.TopLeft : Origin90.BottomLeft, (amount - 0.5f) / 0.5f, clockwise);

                    if (clockwise)
                    {
                        vertRect.Y -= vertRect.Height;
                    }
                    else
                    {
                        vertRect.Y += vertRect.Height;
                    }
                    vb.AddQuad(vertRect);
                    vb.AddTriangles(-4);
                }
                break;

            case Origin180.Right:
                if (amount <= 0.5f)
                {
                    vertRect.Height /= 2;
                    if (clockwise)
                    {
                        vertRect.Y += vertRect.Height;
                    }

                    FillRadial90(vb, vertRect, clockwise ? Origin90.TopRight : Origin90.BottomRight, amount / 0.5f, clockwise);
                    Vector3 vec = vb.GetPosition(-4);
                    vb.AddQuad(new Rectangle(vec.X, vec.Y, 0, 0));
                    vb.AddTriangles(-4);
                }
                else
                {
                    vertRect.Height /= 2;
                    if (!clockwise)
                    {
                        vertRect.Y += vertRect.Height;
                    }

                    FillRadial90(vb, vertRect, clockwise ? Origin90.BottomRight : Origin90.TopRight, (amount - 0.5f) / 0.5f, clockwise);

                    if (clockwise)
                    {
                        vertRect.Y += vertRect.Height;
                    }
                    else
                    {
                        vertRect.Y -= vertRect.Height;
                    }
                    vb.AddQuad(vertRect);
                    vb.AddTriangles(-4);
                }
                break;
            }
        }
コード例 #17
0
ファイル: Image.cs プロジェクト: pinzeweifen/DCET
        public void SliceFill(VertexBuffer vb)
        {
            Rect gridRect    = (Rect)_scale9Grid;
            Rect contentRect = vb.contentRect;
            Rect uvRect      = vb.uvRect;

            float sourceW = texture.width;
            float sourceH = texture.height;
            float sx      = uvRect.width / sourceW;
            float sy      = uvRect.height / sourceH;
            float xMax    = uvRect.xMax;
            float yMax    = uvRect.yMax;
            float xMax2   = gridRect.xMax;
            float yMax2   = gridRect.yMax;

            gridTexX[0] = uvRect.x;
            gridTexX[1] = uvRect.x + gridRect.x * sx;
            gridTexX[2] = uvRect.x + xMax2 * sx;
            gridTexX[3] = xMax;
            gridTexY[0] = yMax;
            gridTexY[1] = yMax - gridRect.y * sy;
            gridTexY[2] = yMax - yMax2 * sy;
            gridTexY[3] = uvRect.y;

            if (contentRect.width >= (sourceW - gridRect.width))
            {
                gridX[1] = gridRect.x;
                gridX[2] = contentRect.width - (sourceW - xMax2);
                gridX[3] = contentRect.width;
            }
            else
            {
                float tmp = gridRect.x / (sourceW - xMax2);
                tmp      = contentRect.width * tmp / (1 + tmp);
                gridX[1] = tmp;
                gridX[2] = tmp;
                gridX[3] = contentRect.width;
            }

            if (contentRect.height >= (sourceH - gridRect.height))
            {
                gridY[1] = gridRect.y;
                gridY[2] = contentRect.height - (sourceH - yMax2);
                gridY[3] = contentRect.height;
            }
            else
            {
                float tmp = gridRect.y / (sourceH - yMax2);
                tmp      = contentRect.height * tmp / (1 + tmp);
                gridY[1] = tmp;
                gridY[2] = tmp;
                gridY[3] = contentRect.height;
            }

            if (_tileGridIndice == 0)
            {
                for (int cy = 0; cy < 4; cy++)
                {
                    for (int cx = 0; cx < 4; cx++)
                    {
                        vb.AddVert(new Vector2(gridX[cx], gridY[cy]), vb.vertexColor, new Vector2(gridTexX[cx], gridTexY[cy]));
                    }
                }
                vb.AddTriangles(TRIANGLES_9_GRID);
            }
            else
            {
                int  hc, vc;
                Rect drawRect;
                Rect texRect;
                int  row, col;
                int  part;

                //先计算需要的顶点数量
                int vertCount = 0;
                for (int pi = 0; pi < 9; pi++)
                {
                    col  = pi % 3;
                    row  = pi / 3;
                    part = gridTileIndice[pi];

                    if (part != -1 && (_tileGridIndice & (1 << part)) != 0)
                    {
                        if (part == 0 || part == 1 || part == 4)
                        {
                            hc = Mathf.CeilToInt((gridX[col + 1] - gridX[col]) / gridRect.width);
                        }
                        else
                        {
                            hc = 1;
                        }
                        if (part == 2 || part == 3 || part == 4)
                        {
                            vc = Mathf.CeilToInt((gridY[row + 1] - gridY[row]) / gridRect.height);
                        }
                        else
                        {
                            vc = 1;
                        }
                        vertCount += hc * vc * 4;
                    }
                    else
                    {
                        vertCount += 4;
                    }
                }

                for (int pi = 0; pi < 9; pi++)
                {
                    col      = pi % 3;
                    row      = pi / 3;
                    part     = gridTileIndice[pi];
                    drawRect = Rect.MinMaxRect(gridX[col], gridY[row], gridX[col + 1], gridY[row + 1]);
                    texRect  = Rect.MinMaxRect(gridTexX[col], gridTexY[row + 1], gridTexX[col + 1], gridTexY[row]);

                    if (part != -1 && (_tileGridIndice & (1 << part)) != 0)
                    {
                        TileFill(vb, drawRect, texRect,
                                 (part == 0 || part == 1 || part == 4) ? gridRect.width : drawRect.width,
                                 (part == 2 || part == 3 || part == 4) ? gridRect.height : drawRect.height);
                    }
                    else
                    {
                        vb.AddQuad(drawRect, vb.vertexColor, texRect);
                    }
                }

                vb.AddTriangles();
            }
        }
コード例 #18
0
ファイル: Image.cs プロジェクト: qufangliu/OneManOneDog
        public void SliceFill(VertexBuffer vb)
        {
            Rect gridRect    = (Rect)_scale9Grid;
            Rect contentRect = vb.contentRect;
            Rect uvRect      = vb.uvRect;

            float sourceW = texture.width;
            float sourceH = texture.height;

            if (graphics.flip != FlipType.None)
            {
                if (graphics.flip == FlipType.Horizontal || graphics.flip == FlipType.Both)
                {
                    gridRect.x    = sourceW - gridRect.xMax;
                    gridRect.xMax = gridRect.x + gridRect.width;
                }

                if (graphics.flip == FlipType.Vertical || graphics.flip == FlipType.Both)
                {
                    gridRect.y    = sourceH - gridRect.yMax;
                    gridRect.yMax = gridRect.y + gridRect.height;
                }
            }

            float sx    = uvRect.width / sourceW;
            float sy    = uvRect.height / sourceH;
            float xMax  = uvRect.xMax;
            float yMax  = uvRect.yMax;
            float xMax2 = gridRect.xMax;
            float yMax2 = gridRect.yMax;

            gridTexX[0] = uvRect.x;
            gridTexX[1] = uvRect.x + gridRect.x * sx;
            gridTexX[2] = uvRect.x + xMax2 * sx;
            gridTexX[3] = xMax;
            gridTexY[0] = yMax;
            gridTexY[1] = yMax - gridRect.y * sy;
            gridTexY[2] = yMax - yMax2 * sy;
            gridTexY[3] = uvRect.y;

            if (contentRect.width >= (sourceW - gridRect.width))
            {
                gridX[1] = gridRect.x;
                gridX[2] = contentRect.width - (sourceW - xMax2);
                gridX[3] = contentRect.width;
            }
            else
            {
                float tmp = gridRect.x / (sourceW - xMax2);
                tmp      = contentRect.width * tmp / (1 + tmp);
                gridX[1] = tmp;
                gridX[2] = tmp;
                gridX[3] = contentRect.width;
            }

            if (contentRect.height >= (sourceH - gridRect.height))
            {
                gridY[1] = gridRect.y;
                gridY[2] = contentRect.height - (sourceH - yMax2);
                gridY[3] = contentRect.height;
            }
            else
            {
                float tmp = gridRect.y / (sourceH - yMax2);
                tmp      = contentRect.height * tmp / (1 + tmp);
                gridY[1] = tmp;
                gridY[2] = tmp;
                gridY[3] = contentRect.height;
            }

            if (_tileGridIndice == 0)
            {
                for (int cy = 0; cy < 4; cy++)
                {
                    for (int cx = 0; cx < 4; cx++)
                    {
                        vb.AddVert(new Vector2(gridX[cx], gridY[cy]), vb.vertexColor, new Vector2(gridTexX[cx], gridTexY[cy]));
                    }
                }
                vb.AddTriangles(TRIANGLES_9_GRID);
            }
            else
            {
                Rect drawRect;
                Rect texRect;
                int  row, col;
                int  part;

                for (int pi = 0; pi < 9; pi++)
                {
                    col      = pi % 3;
                    row      = pi / 3;
                    part     = gridTileIndice[pi];
                    drawRect = Rect.MinMaxRect(gridX[col], gridY[row], gridX[col + 1], gridY[row + 1]);
                    texRect  = Rect.MinMaxRect(gridTexX[col], gridTexY[row + 1], gridTexX[col + 1], gridTexY[row]);

                    if (part != -1 && (_tileGridIndice & (1 << part)) != 0)
                    {
                        TileFill(vb, drawRect, texRect,
                                 (part == 0 || part == 1 || part == 4) ? gridRect.width : drawRect.width,
                                 (part == 2 || part == 3 || part == 4) ? gridRect.height : drawRect.height);
                    }
                    else
                    {
                        vb.AddQuad(drawRect, vb.vertexColor, texRect);
                    }
                }

                vb.AddTriangles();
            }
        }
コード例 #19
0
        public void SliceFill(VertexBuffer vb)
        {
            Rectangle gridRect    = (Rectangle)_scale9Grid;
            Rectangle contentRect = vb.contentRect;
            Rectangle uvRect      = vb.uvRect;

            float sourceW = texture.width;
            float sourceH = texture.height;
            float sx      = uvRect.Width / sourceW;
            float sy      = uvRect.Height / sourceH;
            float xMax    = uvRect.Right;
            float yMax    = uvRect.Bottom;
            float xMax2   = gridRect.Right;
            float yMax2   = gridRect.Bottom;

            gridTexX[0] = uvRect.X;
            gridTexX[1] = uvRect.X + gridRect.X * sx;
            gridTexX[2] = uvRect.X + xMax2 * sx;
            gridTexX[3] = xMax;
            gridTexY[0] = yMax;
            gridTexY[1] = yMax - gridRect.Y * sy;
            gridTexY[2] = yMax - yMax2 * sy;
            gridTexY[3] = uvRect.Y;

            if (contentRect.Width >= (sourceW - gridRect.Width))
            {
                gridX[1] = gridRect.X;
                gridX[2] = contentRect.Width - (sourceW - xMax2);
                gridX[3] = contentRect.Width;
            }
            else
            {
                float tmp = gridRect.X / (sourceW - xMax2);
                tmp      = contentRect.Width * tmp / (1 + tmp);
                gridX[1] = tmp;
                gridX[2] = tmp;
                gridX[3] = contentRect.Width;
            }

            if (contentRect.Height >= (sourceH - gridRect.Height))
            {
                gridY[1] = gridRect.Y;
                gridY[2] = contentRect.Height - (sourceH - yMax2);
                gridY[3] = contentRect.Height;
            }
            else
            {
                float tmp = gridRect.Y / (sourceH - yMax2);
                tmp      = contentRect.Height * tmp / (1 + tmp);
                gridY[1] = tmp;
                gridY[2] = tmp;
                gridY[3] = contentRect.Height;
            }

            if (_tileGridIndice == 0)
            {
                for (int cy = 0; cy < 4; cy++)
                {
                    for (int cx = 0; cx < 4; cx++)
                    {
                        vb.AddVert(new Vector3(gridX[cx], gridY[cy], 0), vb.vertexColor, new Vector2(gridTexX[cx], gridTexY[cy]));
                    }
                }
                vb.AddTriangles(TRIANGLES_9_GRID);
            }
            else
            {
                Rectangle drawRect;
                Rectangle texRect;
                int       row, col;
                int       part;

                for (int pi = 0; pi < 9; pi++)
                {
                    col      = pi % 3;
                    row      = pi / 3;
                    part     = gridTileIndice[pi];
                    drawRect = Rectangle.FromLTRB(gridX[col], gridY[row], gridX[col + 1], gridY[row + 1]);
                    texRect  = Rectangle.FromLTRB(gridTexX[col], gridTexY[row + 1], gridTexX[col + 1], gridTexY[row]);

                    if (part != -1 && (_tileGridIndice & (1 << part)) != 0)
                    {
                        TileFill(vb, drawRect, texRect,
                                 (part == 0 || part == 1 || part == 4) ? gridRect.Width : drawRect.Width,
                                 (part == 2 || part == 3 || part == 4) ? gridRect.Height : drawRect.Height);
                    }
                    else
                    {
                        vb.AddQuad(drawRect, vb.vertexColor, texRect);
                    }
                }

                vb.AddTriangles();
            }
        }