public static void WriteRenderBox(UIPassState *state, BackgroundConfig *backgroundConfig, BorderConfig *borderConfig, UIVertexData *vertexPtr, UIContextData *context) { UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 0, new UIVertexData { background = new float3(backgroundConfig->image.value.x, backgroundConfig->image.value.y - backgroundConfig->image.value.w, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x, state->globalBox.y, 0), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.top.Normalize(*context), borderConfig->width.left.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.left.Normalize(*context), borderConfig->width.top.Normalize(*context))), borderConfig->radius.topLeft.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 1, new UIVertexData { background = new float3(backgroundConfig->image.value.x + backgroundConfig->image.value.z, backgroundConfig->image.value.y - backgroundConfig->image.value.w, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x + state->size.x, state->globalBox.y, 0), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.top.Normalize(*context), borderConfig->width.right.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.right.Normalize(*context), borderConfig->width.top.Normalize(*context))), borderConfig->radius.topRight.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 2, new UIVertexData { background = new float3(backgroundConfig->image.value.x, backgroundConfig->image.value.y, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x, state->globalBox.y + state->size.y, 0), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.bottom.Normalize(*context), borderConfig->width.left.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.left.Normalize(*context), borderConfig->width.bottom.Normalize(*context))), borderConfig->radius.bottomLeft.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 3, new UIVertexData { background = new float3(backgroundConfig->image.value.x + backgroundConfig->image.value.z, backgroundConfig->image.value.y, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x + state->size.x, state->globalBox.y + state->size.y, 0), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.bottom.Normalize(*context), borderConfig->width.right.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.right.Normalize(*context), borderConfig->width.bottom.Normalize(*context))), borderConfig->radius.bottomRight.Normalize(*context)), }); }
public static void Render(IntPtr configPtr, NodeInfo *nodeInfo, UIPassState *statePtr, UIVertexData *vertexDataPtr, UIContextData *context) { IntPtr configSource = configPtr + nodeInfo->configOffset; TextConfig * textConfig = (TextConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.TextConfig, configSource).ToPointer(); BackgroundConfig *backgroundConfig = (BackgroundConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BackgroundConfig, configSource).ToPointer(); FontConfig * fontConfig = (FontConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.FontConfig, configSource).ToPointer(); BorderConfig * borderConfig = (BorderConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BorderConfig, configSource).ToPointer(); UIRenderBoxWriters.WriteCharRenderBoxes(statePtr, configPtr + nodeInfo->nodeOffset, backgroundConfig, borderConfig, fontConfig, textConfig, vertexDataPtr, context); }
public static void Render(IntPtr configPtr, NodeInfo *nodeInfo, UIPassState *statePtr, UIVertexData *vertexDataPtr, UIContextData *context) { IntPtr configSource = configPtr + nodeInfo->configOffset; BoxModelConfig * boxConfig = (BoxModelConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxModelConfig, configSource).ToPointer(); BackgroundConfig *backgroundConfig = (BackgroundConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BackgroundConfig, configSource).ToPointer(); BorderConfig * borderConfig = (BorderConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BorderConfig, configSource).ToPointer(); SizeConfig * sizeConfig = (SizeConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.SizeConfig, configSource).ToPointer(); BoxLayoutConfig * sequentialLayoutConfig = (BoxLayoutConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxLayoutConfig, configSource).ToPointer(); HeaderConfig * headerConfig = (HeaderConfig *)(configPtr + nodeInfo->nodeOffset); UIRenderBoxWriters.WriteRenderBox(statePtr, backgroundConfig, borderConfig, vertexDataPtr, context); }
public static void Layout(int childIndex, IntPtr configPtr, NodeInfo *nodeInfo, IntPtr statePtr, UIContextData *context) { if (childIndex < 0) { UIPassState * selfPtr = (UIPassState *)(statePtr + (UnsafeUtility.SizeOf <UIPassState>() * nodeInfo->index)).ToPointer(); IntPtr configSource = configPtr + nodeInfo->configOffset; TextConfig * textConfig = (TextConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.TextConfig, configSource).ToPointer(); BackgroundConfig *backgroundConfig = (BackgroundConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BackgroundConfig, configSource).ToPointer(); FontConfig * fontConfig = (FontConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.FontConfig, configSource).ToPointer(); BorderConfig * borderConfig = (BorderConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BorderConfig, configSource).ToPointer(); SizeText(selfPtr, configPtr + nodeInfo->nodeOffset, textConfig, fontConfig, context); } }
public static void WriteCharRenderBoxes(UIPassState *state, IntPtr config, BackgroundConfig *backgroundConfig, BorderConfig *borderConfig, FontConfig *fontConfig, TextConfig *textConfig, UIVertexData *vertexPtr, UIContextData *context) { var height = fontConfig->size.Normalize(*context); var fontSizeScale = (height / textConfig->fontInfo.lineHeight) * textConfig->fontInfo.scale; float offsetX = state->globalBox.x; float offsetY = state->globalBox.y; var nullBg = new float3(float.NaN, float.NaN, float.NaN); float width = 0f; for (int i = 1; i < textConfig->text.length + 1; i++) { var charInfo = textConfig->GetCharInfo(config, i - 1); UnsafeUtility.WriteArrayElement(vertexPtr, i * 4, new UIVertexData { position = new float3(offsetX + (charInfo.metrics.horizontalBearingX * fontSizeScale), offsetY + (-textConfig->fontInfo.descentLine * fontSizeScale) + ((charInfo.metrics.horizontalBearingY - charInfo.metrics.height) * fontSizeScale), -0.002f), normals = new float3(0, 0, -1), background = nullBg, foreground = new float3(charInfo.uvs.x, charInfo.uvs.y, charInfo.index), color = fontConfig->color }); UnsafeUtility.WriteArrayElement(vertexPtr, (i * 4) + 1, new UIVertexData { position = new float3(offsetX + ((charInfo.metrics.horizontalBearingX + charInfo.metrics.width) * fontSizeScale), offsetY + (-textConfig->fontInfo.descentLine * fontSizeScale) + ((charInfo.metrics.horizontalBearingY - charInfo.metrics.height) * fontSizeScale), -0.002f), normals = new float3(0, 0, -1), background = nullBg, foreground = new float3(charInfo.uvs.x + charInfo.uvs.z, charInfo.uvs.y, charInfo.index), color = fontConfig->color }); UnsafeUtility.WriteArrayElement(vertexPtr, (i * 4) + 2, new UIVertexData { position = new float3(offsetX + (charInfo.metrics.horizontalBearingX * fontSizeScale), offsetY + (-textConfig->fontInfo.descentLine * fontSizeScale) + ((charInfo.metrics.horizontalBearingY - charInfo.metrics.height) * fontSizeScale) + (charInfo.metrics.height * fontSizeScale), -0.002f), normals = new float3(0, 0, -1), background = nullBg, foreground = new float3(charInfo.uvs.x, charInfo.uvs.y + charInfo.uvs.w, charInfo.index), color = fontConfig->color }); UnsafeUtility.WriteArrayElement(vertexPtr, (i * 4) + 3, new UIVertexData { position = new float3(offsetX + ((charInfo.metrics.horizontalBearingX + charInfo.metrics.width) * fontSizeScale), offsetY + (-textConfig->fontInfo.descentLine * fontSizeScale) + ((charInfo.metrics.horizontalBearingY - charInfo.metrics.height) * fontSizeScale) + (charInfo.metrics.height * fontSizeScale), -0.002f), normals = new float3(0, 0, -1), background = nullBg, foreground = new float3(charInfo.uvs.x + charInfo.uvs.z, charInfo.uvs.y + charInfo.uvs.w, charInfo.index), color = fontConfig->color }); offsetX += (charInfo.metrics.horizontalBearingX + charInfo.metrics.horizontalAdvance) * fontSizeScale; width += (charInfo.metrics.horizontalBearingX + charInfo.metrics.horizontalAdvance) * fontSizeScale; } //Write BG Box based on box defined by chars UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 0, new UIVertexData { background = new float3(backgroundConfig->image.value.x, backgroundConfig->image.value.y - backgroundConfig->image.value.w, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x, state->globalBox.y, -0.001f), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.top.Normalize(*context), borderConfig->width.left.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.left.Normalize(*context), borderConfig->width.top.Normalize(*context))), borderConfig->radius.topLeft.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 1, new UIVertexData { background = new float3(backgroundConfig->image.value.x + backgroundConfig->image.value.z, backgroundConfig->image.value.y - backgroundConfig->image.value.w, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x + width, state->globalBox.y, -0.001f), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.top.Normalize(*context), borderConfig->width.right.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.right.Normalize(*context), borderConfig->width.top.Normalize(*context))), borderConfig->radius.topRight.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 2, new UIVertexData { background = new float3(backgroundConfig->image.value.x, backgroundConfig->image.value.y, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x, state->globalBox.y + height, -0.001f), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.bottom.Normalize(*context), borderConfig->width.left.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.left.Normalize(*context), borderConfig->width.bottom.Normalize(*context))), borderConfig->radius.bottomLeft.Normalize(*context)), }); UnsafeUtility.WriteArrayElement <UIVertexData>(vertexPtr, 3, new UIVertexData { background = new float3(backgroundConfig->image.value.x + backgroundConfig->image.value.z, backgroundConfig->image.value.y, 0f), color = backgroundConfig->color, position = new float3(state->globalBox.x + width, state->globalBox.y + height, -0.001f), normals = new float3(0, 0, -1), border = new float3(math.atan2(borderConfig->width.bottom.Normalize(*context), borderConfig->width.right.Normalize(*context)), math.distance(float2.zero, new float2(borderConfig->width.right.Normalize(*context), borderConfig->width.bottom.Normalize(*context))), borderConfig->radius.bottomRight.Normalize(*context)), }); }
public override unsafe byte PreInit(BackgroundConfig *value, ulong mask, ref UIPropertyWriterContext context) { value->color = Color.white; value->imageTint = Color.white; return(0); }
public override unsafe byte PostInit(BackgroundConfig *value, IntPtr config, ulong mask, MemoryBinaryWriter extraBytesStream, long extraByteStreamOffset, UIPropertyWriterContext context) { return(0); }
public static void Layout(int childIndex, IntPtr configPtr, NodeInfo *nodeInfo, IntPtr statePtr, UIContextData *context) { if (childIndex < 0) { UIPassState * selfPtr = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * nodeInfo->index)).ToPointer(); IntPtr configSource = configPtr + nodeInfo->configOffset; BoxModelConfig * boxConfig = (BoxModelConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxModelConfig, configSource).ToPointer(); BackgroundConfig *backgroundConfig = (BackgroundConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BackgroundConfig, configSource).ToPointer(); BorderConfig * borderConfig = (BorderConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BorderConfig, configSource).ToPointer(); SizeConfig * sizeConfig = (SizeConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.SizeConfig, configSource).ToPointer(); BoxLayoutConfig *boxLayoutConfig = (BoxLayoutConfig *)UIConfigUtility.GetConfig(nodeInfo->configurationMask, UIConfigLayoutTable.BoxLayoutConfig, configSource).ToPointer(); HeaderConfig * headerConfig = (HeaderConfig *)(configPtr + nodeInfo->nodeOffset); float height = 0f; float width = 0f; float2 childrenSize = default; int4 multiplier = default; //float4 padding = boxConfig->padding.Normalize(*context); float4 constraints = new float4( sizeConfig->minWidth.Normalize(*context), sizeConfig->maxWidth.Normalize(*context), sizeConfig->minHeight.Normalize(*context), sizeConfig->maxHeight.Normalize(*context) ); var spacing = boxLayoutConfig->spacing.Normalize(*context); switch (boxLayoutConfig->direction) { case Direction.Left: for (int i = 0; i < headerConfig->childCount; i++) { var childState = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), headerConfig->childCount - 1 - i))).ToPointer(); LayoutHorizontal(childState, ref width, ref height); if (i + 1 < headerConfig->childCount) { width += spacing; } } multiplier = new int4(1, 0, 0, 1); break; case Direction.Right: for (int i = 0; i < headerConfig->childCount; i++) { var childState = (UIPassState *)(statePtr + (UnsafeUtility.SizeOf <UIPassState>() * (UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), i)))).ToPointer(); LayoutHorizontal(childState, ref width, ref height); if (i + 1 < headerConfig->childCount) { width += spacing; } } multiplier = new int4(1, 0, 0, 1); break; case Direction.Up: for (int i = 0; i < headerConfig->childCount; i++) { var childState = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), i))).ToPointer(); LayoutVertical(childState, ref height, ref width); if (i + 1 < headerConfig->childCount) { height += spacing; } } multiplier = new int4(0, 1, 1, 0); break; case Direction.Down: for (int i = 0; i < headerConfig->childCount; i++) { var childState = (UIPassState *)(((IntPtr)statePtr) + (UnsafeUtility.SizeOf <UIPassState>() * UnsafeUtility.ReadArrayElement <int>((configPtr + nodeInfo->childrenOffset).ToPointer(), headerConfig->childCount - 1 - i))).ToPointer(); LayoutVertical(childState, ref height, ref width); if (i + 1 < headerConfig->childCount) { height += spacing; } } multiplier = new int4(0, 1, 1, 0); break; } childrenSize = new float2(width, height); selfPtr->size = new float2( math.clamp(childrenSize.x, constraints.x, constraints.y), math.clamp(childrenSize.y, constraints.z, constraints.w) );; UIJobUtility.AdjustPosition(childrenSize, constraints, boxLayoutConfig, selfPtr, statePtr, headerConfig->childCount, (configPtr + nodeInfo->childrenOffset).ToPointer(), multiplier); //Debug.Log(selfPtr->size); } }