public static bool IsBorder(BorderParameters border) { return(border.leftWidth >= Mathf.Epsilon || border.topWidth >= Mathf.Epsilon || border.rightWidth >= Mathf.Epsilon || border.bottomWidth >= Mathf.Epsilon); }
private static bool HasBorder(BorderParameters border) { return (border.leftWidth > kEpsilon || border.topWidth > kEpsilon || border.rightWidth > kEpsilon || border.bottomWidth > kEpsilon); }
private static bool IsSimpleRect(BorderParameters border) { return(border.topLeftRadius < Mathf.Epsilon && border.topRightRadius < Mathf.Epsilon && border.bottomRightRadius < Mathf.Epsilon && border.bottomLeftRadius < Mathf.Epsilon && !IsBorder(border)); }
private static bool IsSimpleRectangle(BorderParameters border) { return (border.leftWidth < kEpsilon && border.topWidth < kEpsilon && border.rightWidth < kEpsilon && border.bottomWidth < kEpsilon && border.topLeftRadius < kEpsilon && border.topRightRadius < kEpsilon && border.bottomRightRadius < kEpsilon && border.bottomLeftRadius < kEpsilon); }
public static RectStylePainterParameters GetDefault(VisualElement ve) { ComputedStyle style = ve.computedStyle; var painterParams = new RectStylePainterParameters { rect = GUIUtility.AlignRectToDevice(ve.rect), color = style.backgroundColor.value, }; BorderParameters.SetFromStyle(ref painterParams.border, style); return(painterParams); }
private static BorderParameters AdjustBorderParameters(Rect rect, BorderParameters border) { var halfSize = new Vector2(rect.width / 2.0f, rect.height / 2.0f); var minHalfSize = Mathf.Min(halfSize.x, halfSize.y); return(new BorderParameters() { leftWidth = Mathf.Min(border.leftWidth, halfSize.x), topWidth = Mathf.Min(border.topWidth, halfSize.y), rightWidth = Mathf.Min(border.rightWidth, halfSize.x), bottomWidth = Mathf.Min(border.bottomWidth, halfSize.y), topLeftRadius = Mathf.Min(border.topLeftRadius, minHalfSize), topRightRadius = Mathf.Min(border.topRightRadius, minHalfSize), bottomRightRadius = Mathf.Min(border.bottomRightRadius, minHalfSize), bottomLeftRadius = Mathf.Min(border.bottomLeftRadius, minHalfSize), }); }
public static TextureStylePainterParameters GetDefault(VisualElement ve) { ComputedStyle style = ve.computedStyle; var painterParams = new TextureStylePainterParameters { rect = GUIUtility.AlignRectToDevice(ve.rect), uv = new Rect(0, 0, 1, 1), color = (Color)Color.white, texture = style.backgroundImage.value.texture, scaleMode = style.unityBackgroundScaleMode.value, sliceLeft = style.unitySliceLeft.value, sliceTop = style.unitySliceTop.value, sliceRight = style.unitySliceRight.value, sliceBottom = style.unitySliceBottom.value }; BorderParameters.SetFromStyle(ref painterParams.border, style); return(painterParams); }
private static void TessellateRoundBorders(Rect rect, Color color, float posZ, VertexFlags vertexFlags, BorderParameters border, NativeSlice <Vertex>?vertices, NativeSlice <UInt16>?indices, ref UInt16 vertexCount, ref UInt16 indexCount, bool countOnly) { // To tessellate the 4 corners, the rect is divided in 4 quadrants and every quadrant is computed as if they were the top-left corner. // The quadrants are then mirrored and the triangles winding flipped as necessary. UInt16 indexOffset = 0; UInt16 startVc = 0, startIc = 0; bool hasBorder = HasBorder(border); var halfSize = new Vector2(rect.width / 2.0f, rect.height / 2.0f); var quarterRect = new Rect(rect.x, rect.y, halfSize.x, halfSize.y); // Top-left TessellateRoundedCorner(quarterRect, color, posZ, vertexFlags, border.topLeftRadius, border.leftWidth, border.topWidth, hasBorder, vertices, indices, ref indexOffset, ref vertexCount, ref indexCount, countOnly); // Top-right startVc = vertexCount; startIc = indexCount; TessellateRoundedCorner(quarterRect, color, posZ, vertexFlags, border.topRightRadius, border.rightWidth, border.topWidth, hasBorder, vertices, indices, ref indexOffset, ref vertexCount, ref indexCount, countOnly); MirrorVertices(quarterRect, vertices, startVc, vertexCount - startVc, true); FlipWinding(indices, startIc, indexCount - startIc); // Bottom-right startVc = vertexCount; startIc = indexCount; TessellateRoundedCorner(quarterRect, color, posZ, vertexFlags, border.bottomRightRadius, border.rightWidth, border.bottomWidth, hasBorder, vertices, indices, ref indexOffset, ref vertexCount, ref indexCount, countOnly); MirrorVertices(quarterRect, vertices, startVc, vertexCount - startVc, true); MirrorVertices(quarterRect, vertices, startVc, vertexCount - startVc, false); // Bottom-left startVc = vertexCount; startIc = indexCount; TessellateRoundedCorner(quarterRect, color, posZ, vertexFlags, border.bottomLeftRadius, border.leftWidth, border.bottomWidth, hasBorder, vertices, indices, ref indexOffset, ref vertexCount, ref indexCount, countOnly); MirrorVertices(quarterRect, vertices, startVc, vertexCount - startVc, false); FlipWinding(indices, startIc, indexCount - startIc); }
private static void TessellateBorderedRectInternal(Rect rect, Color color, float posZ, VertexFlags vertexFlags, BorderParameters border, NativeSlice <Vertex>?vertices, NativeSlice <UInt16>?indices, ref UInt16 vertexCount, ref UInt16 indexCount, bool countOnly = false) { if (IsSimpleRectangle(border)) { UInt16 indexOffset = 0; TessellateQuad(rect, TessellationType.Content, color, posZ, vertexFlags, vertices, indices, ref indexOffset, ref vertexCount, ref indexCount, countOnly); } else { TessellateRoundBorders(rect, color, posZ, vertexFlags, border, vertices, indices, ref vertexCount, ref indexCount, countOnly); } }
private static void CountBorderedRectTriangles(Rect rect, BorderParameters border, ref UInt16 vertexCount, ref UInt16 indexCount) { // To count the required triangles, we call the tessellation method with a "countOnly=true" flag, which skips // tessellation and only update the vertex and index counts. TessellateBorderedRectInternal(rect, Color.white, 0, VertexFlags.IsSolid, border, null, null, ref vertexCount, ref indexCount, true); }
///<summary> /// Tessellates the border OR the content: /// If any of the left/right/top/bottom border parameters is greater than Epsilon, we tessellate ONLY a border. /// Otherwise we tessellate ONLY the content. /// </summary> /// <param name="vertexFlags">Flags are only used for content, not for a border.</param> public static void TessellateBorderedRect(Rect rect, Rect texCoords, Color color, BorderParameters border, float posZ, VertexFlags vertexFlags, UIRMeshBuilder.AllocMeshData meshAlloc) { if (rect.width < kEpsilon || rect.height < kEpsilon) { return; } Profiler.BeginSample("TessellateBorderedRect"); border = AdjustBorderParameters(rect, border); UInt16 vertexCount = 0, indexCount = 0; CountBorderedRectTriangles(rect, border, ref vertexCount, ref indexCount); var mesh = meshAlloc(vertexCount, indexCount); vertexCount = 0; indexCount = 0; TessellateBorderedRectInternal(rect, color, posZ, vertexFlags, border, mesh.vertices, mesh.indices, ref vertexCount, ref indexCount); if (!HasBorder(border) && ((vertexFlags == VertexFlags.IsTextured) || (vertexFlags == VertexFlags.IsCustom))) { ComputeUVs(rect, texCoords, mesh.vertices); } Profiler.EndSample(); }
public static void SetFromStyle(ref BorderParameters border, ComputedStyle style) { border.SetWidth(style.borderTopWidth.value, style.borderRightWidth.value, style.borderBottomWidth.value, style.borderLeftWidth.value); border.SetRadius(style.borderTopLeftRadius.value.value, style.borderTopRightRadius.value.value, style.borderBottomRightRadius.value.value, style.borderBottomLeftRadius.value.value); }