private static void MakeVectorGraphics9SliceBackground(Vertex[] svgVertices, ushort[] svgIndices, float svgWidth, float svgHeight, Rect targetRect, Vector4 sliceLTRB, bool stretch, Color tint, int settingIndexOffset, MeshBuilder.AllocMeshData meshAlloc) { MeshWriteData meshWriteData = meshAlloc.alloc((uint)svgVertices.Length, (uint)svgIndices.Length, ref meshAlloc); meshWriteData.SetAllIndices(svgIndices); bool flag = !stretch; if (flag) { throw new NotImplementedException("Support for repeating 9-slices is not done yet"); } MeshBuilder.s_VectorGraphics9Slice.Begin(); Rect uvRegion = meshWriteData.uvRegion; int num = svgVertices.Length; Vector2 vector = new Vector2(1f / (svgWidth - sliceLTRB.z - sliceLTRB.x), 1f / (svgHeight - sliceLTRB.w - sliceLTRB.y)); Vector2 vector2 = new Vector2(targetRect.width - svgWidth, targetRect.height - svgHeight); for (int i = 0; i < num; i++) { Vertex vertex = svgVertices[i]; Vector2 vector3; vector3.x = Mathf.Clamp01((vertex.position.x - sliceLTRB.x) * vector.x); vector3.y = Mathf.Clamp01((vertex.position.y - sliceLTRB.y) * vector.y); vertex.position.x = vertex.position.x + vector3.x * vector2.x; vertex.position.y = vertex.position.y + vector3.y * vector2.y; vertex.uv.x = vertex.uv.x * uvRegion.width + uvRegion.xMin; vertex.uv.y = vertex.uv.y * uvRegion.height + uvRegion.yMin; vertex.tint *= tint; uint num2 = (uint)(((int)vertex.opacityPageSVGSettingIndex.b << 8 | (int)vertex.opacityPageSVGSettingIndex.a) + settingIndexOffset); vertex.opacityPageSVGSettingIndex.b = (byte)(num2 >> 8); vertex.opacityPageSVGSettingIndex.a = (byte)num2; meshWriteData.SetNextVertex(vertex); } MeshBuilder.s_VectorGraphics9Slice.End(); }
internal static void MakeVectorGraphicsStretchBackground(Vertex[] svgVertices, ushort[] svgIndices, float svgWidth, float svgHeight, Rect targetRect, Rect sourceUV, ScaleMode scaleMode, Color tint, int settingIndexOffset, MeshBuilder.AllocMeshData meshAlloc, out int finalVertexCount, out int finalIndexCount) { Vector2 vector = new Vector2(svgWidth * sourceUV.width, svgHeight * sourceUV.height); Vector2 vector2 = new Vector2(sourceUV.xMin * svgWidth, sourceUV.yMin * svgHeight); Rect rect = new Rect(vector2, vector); bool flag = sourceUV.xMin != 0f || sourceUV.yMin != 0f || sourceUV.width != 1f || sourceUV.height != 1f; float num = vector.x / vector.y; float num2 = targetRect.width / targetRect.height; Vector2 vector3; Vector2 vector4; switch (scaleMode) { case ScaleMode.StretchToFill: vector3 = new Vector2(0f, 0f); vector4.x = targetRect.width / vector.x; vector4.y = targetRect.height / vector.y; break; case ScaleMode.ScaleAndCrop: { vector3 = new Vector2(0f, 0f); bool flag2 = num2 > num; if (flag2) { vector4.x = (vector4.y = targetRect.width / vector.x); float num3 = targetRect.height / vector4.y; float num4 = rect.height / 2f - num3 / 2f; vector3.y -= num4 * vector4.y; rect.y += num4; rect.height = num3; flag = true; } else { bool flag3 = num2 < num; if (flag3) { vector4.x = (vector4.y = targetRect.height / vector.y); float num5 = targetRect.width / vector4.x; float num6 = rect.width / 2f - num5 / 2f; vector3.x -= num6 * vector4.x; rect.x += num6; rect.width = num5; flag = true; } else { vector4.x = (vector4.y = targetRect.width / vector.x); } } break; } case ScaleMode.ScaleToFit: { bool flag4 = num2 > num; if (flag4) { vector4.x = (vector4.y = targetRect.height / vector.y); vector3.x = (targetRect.width - vector.x * vector4.x) * 0.5f; vector3.y = 0f; } else { vector4.x = (vector4.y = targetRect.width / vector.x); vector3.x = 0f; vector3.y = (targetRect.height - vector.y * vector4.y) * 0.5f; } break; } default: throw new NotImplementedException(); } MeshBuilder.s_VectorGraphicsStretch.Begin(); vector3 -= vector2 * vector4; int num7 = svgVertices.Length; int num8 = svgIndices.Length; MeshBuilder.ClipCounts clipCounts = default(MeshBuilder.ClipCounts); Vector4 zero = Vector4.zero; bool flag5 = flag; if (flag5) { bool flag6 = rect.width <= 0f || rect.height <= 0f; if (flag6) { finalVertexCount = (finalIndexCount = 0); MeshBuilder.s_VectorGraphicsStretch.End(); return; } zero = new Vector4(rect.xMin, rect.yMin, rect.xMax, rect.yMax); clipCounts = MeshBuilder.UpperBoundApproximateRectClippingResults(svgVertices, svgIndices, zero); num7 += clipCounts.clippedTriangles * 6; num8 += clipCounts.addedTriangles * 3; num8 -= clipCounts.degenerateTriangles * 3; } MeshWriteData meshWriteData = meshAlloc.alloc((uint)num7, (uint)num8, ref meshAlloc); bool flag7 = flag; if (flag7) { MeshBuilder.RectClip(svgVertices, svgIndices, zero, meshWriteData, clipCounts, ref num7); } else { meshWriteData.SetAllIndices(svgIndices); } Debug.Assert(meshWriteData.currentVertex == 0); Rect uvRegion = meshWriteData.uvRegion; int num9 = svgVertices.Length; for (int i = 0; i < num9; i++) { Vertex vertex = svgVertices[i]; vertex.position.x = vertex.position.x * vector4.x + vector3.x; vertex.position.y = vertex.position.y * vector4.y + vector3.y; vertex.uv.x = vertex.uv.x * uvRegion.width + uvRegion.xMin; vertex.uv.y = vertex.uv.y * uvRegion.height + uvRegion.yMin; vertex.tint *= tint; uint num10 = (uint)(((int)vertex.opacityPageSVGSettingIndex.b << 8 | (int)vertex.opacityPageSVGSettingIndex.a) + settingIndexOffset); vertex.opacityPageSVGSettingIndex.b = (byte)(num10 >> 8); vertex.opacityPageSVGSettingIndex.a = (byte)num10; meshWriteData.SetNextVertex(vertex); } for (int j = num9; j < num7; j++) { Vertex vertex2 = meshWriteData.m_Vertices[j]; vertex2.position.x = vertex2.position.x * vector4.x + vector3.x; vertex2.position.y = vertex2.position.y * vector4.y + vector3.y; vertex2.uv.x = vertex2.uv.x * uvRegion.width + uvRegion.xMin; vertex2.uv.y = vertex2.uv.y * uvRegion.height + uvRegion.yMin; vertex2.tint *= tint; uint num11 = (uint)(((int)vertex2.opacityPageSVGSettingIndex.b << 8 | (int)vertex2.opacityPageSVGSettingIndex.a) + settingIndexOffset); vertex2.opacityPageSVGSettingIndex.b = (byte)(num11 >> 8); vertex2.opacityPageSVGSettingIndex.a = (byte)num11; meshWriteData.SetNextVertex(vertex2); } finalVertexCount = meshWriteData.vertexCount; finalIndexCount = meshWriteData.indexCount; MeshBuilder.s_VectorGraphicsStretch.End(); }