private void GenerateStencilClipEntryForSVGBackground() { bool flag = this.m_SVGBackgroundEntryIndex == -1; if (!flag) { UIRStylePainter.Entry entry = this.m_Entries[this.m_SVGBackgroundEntryIndex]; Debug.Assert(entry.vertices.Length > 0); Debug.Assert(entry.indices.Length > 0); this.m_StencilClip = true; this.m_CurrentEntry.vertices = entry.vertices; this.m_CurrentEntry.indices = entry.indices; this.m_CurrentEntry.uvIsDisplacement = entry.uvIsDisplacement; this.m_CurrentEntry.clipRectID = this.m_ClipRectID; this.m_CurrentEntry.isStencilClipped = this.m_StencilClip; this.m_CurrentEntry.isClipRegisterEntry = true; this.m_ClosingInfo.needsClosing = true; int length = this.m_CurrentEntry.vertices.Length; NativeSlice <Vertex> vertices = this.m_VertsPool.Alloc((uint)length); for (int i = 0; i < length; i++) { Vertex value = this.m_CurrentEntry.vertices[i]; value.position.z = 1f; vertices[i] = value; } this.m_CurrentEntry.vertices = vertices; this.totalVertices += this.m_CurrentEntry.vertices.Length; this.totalIndices += this.m_CurrentEntry.indices.Length; this.m_Entries.Add(this.m_CurrentEntry); this.m_CurrentEntry = default(UIRStylePainter.Entry); } }
private void DrawTextCore(MeshGenerationContextUtils.TextParams textParams, TextHandle handle, float pixelsPerPoint) { TextInfo textInfo = handle.Update(textParams, pixelsPerPoint); for (int i = 0; i < textInfo.materialCount; i++) { bool flag = textInfo.meshInfo[i].vertexCount == 0; if (flag) { break; } this.m_CurrentEntry.isTextEntry = true; this.m_CurrentEntry.clipRectID = this.m_ClipRectID; this.m_CurrentEntry.isStencilClipped = this.m_StencilClip; MeshBuilder.MakeText(textInfo.meshInfo[i], textParams.rect.min, new MeshBuilder.AllocMeshData { alloc = this.m_AllocRawVertsIndicesDelegate }); this.m_CurrentEntry.font = textInfo.meshInfo[i].material.mainTexture; this.m_Entries.Add(this.m_CurrentEntry); this.totalVertices += this.m_CurrentEntry.vertices.Length; this.totalIndices += this.m_CurrentEntry.indices.Length; this.m_CurrentEntry = default(UIRStylePainter.Entry); } }
private void DrawTextNative(MeshGenerationContextUtils.TextParams textParams, TextHandle handle, float pixelsPerPoint) { float scaling = TextHandle.ComputeTextScaling(this.currentElement.worldTransform, pixelsPerPoint); TextNativeSettings textNativeSettings = MeshGenerationContextUtils.TextParams.GetTextNativeSettings(textParams, scaling); using (NativeArray <UnityEngine.UIElements.TextVertex> vertices = TextNative.GetVertices(textNativeSettings)) { bool flag = vertices.Length == 0; if (!flag) { Vector2 offset = TextNative.GetOffset(textNativeSettings, textParams.rect); this.m_CurrentEntry.isTextEntry = true; this.m_CurrentEntry.clipRectID = this.m_ClipRectID; this.m_CurrentEntry.isStencilClipped = this.m_StencilClip; MeshBuilder.MakeText(vertices, offset, new MeshBuilder.AllocMeshData { alloc = this.m_AllocRawVertsIndicesDelegate }); this.m_CurrentEntry.font = textParams.font.material.mainTexture; this.m_Entries.Add(this.m_CurrentEntry); this.totalVertices += this.m_CurrentEntry.vertices.Length; this.totalIndices += this.m_CurrentEntry.indices.Length; this.m_CurrentEntry = default(UIRStylePainter.Entry); this.currentElement.renderChainData.usesLegacyText = true; this.currentElement.renderChainData.disableNudging = true; } } }
public void DrawVectorImage(MeshGenerationContextUtils.RectangleParams rectParams) { VectorImage vectorImage = rectParams.vectorImage; Debug.Assert(vectorImage != null); VertexFlags vertexFlags = (vectorImage.atlas != null) ? VertexFlags.IsSVGGradients : VertexFlags.IsSolid; int settingIndexOffset = 0; bool flag = vectorImage.atlas != null && this.m_VectorImageManager != null; if (flag) { GradientRemap gradientRemap = this.m_VectorImageManager.AddUser(vectorImage); vertexFlags = (gradientRemap.isAtlassed ? VertexFlags.IsSVGGradients : VertexFlags.IsCustomSVGGradients); settingIndexOffset = gradientRemap.destIndex; } int count = this.m_Entries.Count; MeshGenerationContext.MeshFlags flags = MeshGenerationContext.MeshFlags.None; bool flag2 = vertexFlags == VertexFlags.IsSVGGradients; if (flag2) { flags = MeshGenerationContext.MeshFlags.IsSVGGradients; } else { bool flag3 = vertexFlags == VertexFlags.IsCustomSVGGradients; if (flag3) { flags = MeshGenerationContext.MeshFlags.IsCustomSVGGradients; } } MeshBuilder.AllocMeshData meshAlloc = new MeshBuilder.AllocMeshData { alloc = this.m_AllocThroughDrawMeshDelegate, texture = ((vertexFlags == VertexFlags.IsCustomSVGGradients) ? vectorImage.atlas : null), flags = flags }; int num; int num2; MeshBuilder.MakeVectorGraphics(rectParams, settingIndexOffset, meshAlloc, out num, out num2); Debug.Assert(count <= this.m_Entries.Count + 1); bool flag4 = count != this.m_Entries.Count; if (flag4) { this.m_SVGBackgroundEntryIndex = this.m_Entries.Count - 1; bool flag5 = num != 0 && num2 != 0; if (flag5) { UIRStylePainter.Entry entry = this.m_Entries[this.m_SVGBackgroundEntryIndex]; entry.vertices = entry.vertices.Slice(0, num); entry.indices = entry.indices.Slice(0, num2); this.m_Entries[this.m_SVGBackgroundEntryIndex] = entry; } } }
private void GenerateStencilClipEntryForRoundedRectBackground() { bool flag = this.currentElement.layout.width <= Mathf.Epsilon || this.currentElement.layout.height <= Mathf.Epsilon; if (!flag) { ComputedStyle computedStyle = this.currentElement.computedStyle; Vector2 a; Vector2 a2; Vector2 a3; Vector2 a4; MeshGenerationContextUtils.GetVisualElementRadii(this.currentElement, out a, out a2, out a3, out a4); float value = computedStyle.borderTopWidth.value; float value2 = computedStyle.borderLeftWidth.value; float value3 = computedStyle.borderBottomWidth.value; float value4 = computedStyle.borderRightWidth.value; MeshGenerationContextUtils.RectangleParams rectParams = new MeshGenerationContextUtils.RectangleParams { rect = GUIUtility.AlignRectToDevice(this.currentElement.rect), color = Color.white, topLeftRadius = Vector2.Max(Vector2.zero, a - new Vector2(value2, value)), topRightRadius = Vector2.Max(Vector2.zero, a3 - new Vector2(value4, value)), bottomLeftRadius = Vector2.Max(Vector2.zero, a2 - new Vector2(value2, value3)), bottomRightRadius = Vector2.Max(Vector2.zero, a4 - new Vector2(value4, value3)), playmodeTintColor = ((this.currentElement.panel.contextType == ContextType.Editor) ? UIElementsUtility.editorPlayModeTintColor : Color.white) }; rectParams.rect.x = rectParams.rect.x + value2; rectParams.rect.y = rectParams.rect.y + value; rectParams.rect.width = rectParams.rect.width - (value2 + value4); rectParams.rect.height = rectParams.rect.height - (value + value3); bool flag2 = computedStyle.unityOverflowClipBox == OverflowClipBox.ContentBox; if (flag2) { rectParams.rect.x = rectParams.rect.x + computedStyle.paddingLeft.value.value; rectParams.rect.y = rectParams.rect.y + computedStyle.paddingTop.value.value; rectParams.rect.width = rectParams.rect.width - (computedStyle.paddingLeft.value.value + computedStyle.paddingRight.value.value); rectParams.rect.height = rectParams.rect.height - (computedStyle.paddingTop.value.value + computedStyle.paddingBottom.value.value); } this.m_CurrentEntry.clipRectID = this.m_ClipRectID; this.m_CurrentEntry.isStencilClipped = this.m_StencilClip; this.m_CurrentEntry.isClipRegisterEntry = true; MeshBuilder.MakeSolidRect(rectParams, 1f, new MeshBuilder.AllocMeshData { alloc = this.m_AllocRawVertsIndicesDelegate }); bool flag3 = this.m_CurrentEntry.vertices.Length > 0 && this.m_CurrentEntry.indices.Length > 0; if (flag3) { this.m_Entries.Add(this.m_CurrentEntry); this.totalVertices += this.m_CurrentEntry.vertices.Length; this.totalIndices += this.m_CurrentEntry.indices.Length; this.m_StencilClip = true; this.m_ClosingInfo.needsClosing = true; } this.m_CurrentEntry = default(UIRStylePainter.Entry); } }
public MeshWriteData DrawMesh(int vertexCount, int indexCount, Texture texture, Material material, MeshGenerationContext.MeshFlags flags) { MeshWriteData pooledMeshWriteData = this.GetPooledMeshWriteData(); bool flag = vertexCount == 0 || indexCount == 0; MeshWriteData result; if (flag) { pooledMeshWriteData.Reset(default(NativeSlice <Vertex>), default(NativeSlice <ushort>)); result = pooledMeshWriteData; } else { this.m_CurrentEntry = new UIRStylePainter.Entry { vertices = this.m_VertsPool.Alloc((uint)vertexCount), indices = this.m_IndicesPool.Alloc((uint)indexCount), material = material, uvIsDisplacement = (flags == MeshGenerationContext.MeshFlags.UVisDisplacement), clipRectID = this.m_ClipRectID, isStencilClipped = this.m_StencilClip, addFlags = VertexFlags.IsSolid }; Debug.Assert(this.m_CurrentEntry.vertices.Length == vertexCount); Debug.Assert(this.m_CurrentEntry.indices.Length == indexCount); Rect uvRegion = new Rect(0f, 0f, 1f, 1f); bool flag2 = flags == MeshGenerationContext.MeshFlags.IsSVGGradients; bool flag3 = flags == MeshGenerationContext.MeshFlags.IsCustomSVGGradients; bool flag4 = flag2 | flag3; if (flag4) { this.m_CurrentEntry.addFlags = (flag2 ? VertexFlags.IsSVGGradients : VertexFlags.IsCustomSVGGradients); bool flag5 = flag3; if (flag5) { this.m_CurrentEntry.custom = texture; } this.currentElement.renderChainData.usesAtlas = true; } else { bool flag6 = texture != null; if (flag6) { RectInt rectInt; bool flag7 = this.m_AtlasManager != null && this.m_AtlasManager.TryGetLocation(texture as Texture2D, out rectInt); if (flag7) { this.m_CurrentEntry.addFlags = ((texture.filterMode == FilterMode.Point) ? VertexFlags.IsAtlasTexturedPoint : VertexFlags.IsAtlasTexturedBilinear); this.currentElement.renderChainData.usesAtlas = true; uvRegion = new Rect((float)rectInt.x, (float)rectInt.y, (float)rectInt.width, (float)rectInt.height); } else { this.m_CurrentEntry.addFlags = VertexFlags.IsCustomTextured; this.m_CurrentEntry.custom = texture; } } } pooledMeshWriteData.Reset(this.m_CurrentEntry.vertices, this.m_CurrentEntry.indices, uvRegion); this.m_Entries.Add(this.m_CurrentEntry); this.totalVertices += this.m_CurrentEntry.vertices.Length; this.totalIndices += this.m_CurrentEntry.indices.Length; this.m_CurrentEntry = default(UIRStylePainter.Entry); result = pooledMeshWriteData; } return(result); }