mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
wip text scaling
This commit is contained in:
parent
fd7c55c750
commit
f1ca745c50
@ -43,10 +43,10 @@ class CharData(
|
||||
uvEnd = uvEnd * texture.textureArrayUV
|
||||
}
|
||||
|
||||
fun render(position: Vec2i, z: Int, style: TextStyle, consumer: GUIVertexConsumer, options: GUIVertexOptions?) {
|
||||
render(position, z + 2, false, style, consumer, options)
|
||||
fun render(position: Vec2i, z: Int, style: TextStyle, consumer: GUIVertexConsumer, options: GUIVertexOptions?, scale: Float) {
|
||||
render(position, z + 2, false, style, consumer, options, scale)
|
||||
if (style.formatting.contains(PreChatFormattingCodes.SHADOWED)) {
|
||||
render(position, z, true, style, consumer, options)
|
||||
render(position, z, true, style, consumer, options, scale)
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ class CharData(
|
||||
}
|
||||
}
|
||||
|
||||
private fun render(position: Vec2i, z: Int, shadow: Boolean, style: TextStyle, vertexConsumer: GUIVertexConsumer, options: GUIVertexOptions?) {
|
||||
private fun render(position: Vec2i, z: Int, shadow: Boolean, style: TextStyle, vertexConsumer: GUIVertexConsumer, options: GUIVertexOptions?, scale: Float) {
|
||||
var color = style.color ?: ChatColors.WHITE
|
||||
|
||||
|
||||
@ -83,12 +83,15 @@ class CharData(
|
||||
var boldOffset = 0.0f
|
||||
|
||||
if (style.formatting.contains(PreChatFormattingCodes.BOLD)) {
|
||||
boldOffset = BOLD_OFFSET
|
||||
boldOffset = BOLD_OFFSET * scale
|
||||
}
|
||||
val charHeight = Font.CHAR_HEIGHT * scale
|
||||
val horizontalSpacing = Font.HORIZONTAL_SPACING * scale
|
||||
val verticalSpacing = Font.VERTICAL_SPACING * scale
|
||||
|
||||
|
||||
val startPosition = Vec2(position) + shadowOffset
|
||||
val endPosition = startPosition + Vec2(scaledWidth, Font.CHAR_HEIGHT.toFloat())
|
||||
val startPosition = Vec2(position) + (shadowOffset * scale)
|
||||
val endPosition = startPosition + (Vec2(scaledWidth * scale, charHeight))
|
||||
|
||||
|
||||
val italic = style.formatting.contains(PreChatFormattingCodes.ITALIC)
|
||||
@ -101,23 +104,23 @@ class CharData(
|
||||
}
|
||||
|
||||
if (style.formatting.contains(PreChatFormattingCodes.STRIKETHROUGH)) {
|
||||
vertexConsumer.addQuad(startPosition + Vec2(-Font.HORIZONTAL_SPACING, Font.CHAR_HEIGHT / 2.0f), Vec2(endPosition.x + Font.HORIZONTAL_SPACING, startPosition.y + Font.CHAR_HEIGHT / 2.0f + 1.0f), z + 1, renderWindow.WHITE_TEXTURE.texture, renderWindow.WHITE_TEXTURE.uvStart, renderWindow.WHITE_TEXTURE.uvEnd, italic, color, options)
|
||||
vertexConsumer.addQuad(startPosition + Vec2(-horizontalSpacing, charHeight / 2.0f - scale / 2), Vec2(endPosition.x + horizontalSpacing, startPosition.y + charHeight / 2.0f + scale / 2), z + 1, renderWindow.WHITE_TEXTURE.texture, renderWindow.WHITE_TEXTURE.uvStart, renderWindow.WHITE_TEXTURE.uvEnd, italic, color, options)
|
||||
}
|
||||
|
||||
if (style.formatting.contains(PreChatFormattingCodes.UNDERLINED)) {
|
||||
vertexConsumer.addQuad(startPosition + Vec2i(-Font.HORIZONTAL_SPACING, Font.CHAR_HEIGHT), Vec2i(endPosition.x + boldOffset + Font.HORIZONTAL_SPACING, startPosition.y + Font.CHAR_HEIGHT + Font.VERTICAL_SPACING / 2.0f), z, renderWindow.WHITE_TEXTURE.texture, renderWindow.WHITE_TEXTURE.uvStart, renderWindow.WHITE_TEXTURE.uvEnd, italic, color, options)
|
||||
vertexConsumer.addQuad(startPosition + Vec2i(-horizontalSpacing, charHeight), Vec2i(endPosition.x + boldOffset + horizontalSpacing, startPosition.y + charHeight + verticalSpacing / 2.0f), z, renderWindow.WHITE_TEXTURE.texture, renderWindow.WHITE_TEXTURE.uvStart, renderWindow.WHITE_TEXTURE.uvEnd, italic, color, options)
|
||||
}
|
||||
|
||||
// ToDo: Obfuscated
|
||||
}
|
||||
|
||||
fun calculateWidth(style: TextStyle): Int {
|
||||
fun calculateWidth(style: TextStyle, scale: Float): Int {
|
||||
var width = scaledWidth.toFloat()
|
||||
if (style.formatting.contains(PreChatFormattingCodes.SHADOWED)) {
|
||||
width += SHADOW_OFFSET
|
||||
}
|
||||
|
||||
return width.ceil
|
||||
return (width * scale).ceil
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,7 +72,7 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
|
||||
}
|
||||
|
||||
fun wrap(): Boolean {
|
||||
if (addY(Font.TOTAL_CHAR_HEIGHT)) {
|
||||
if (addY(renderInfo.charHeight)) {
|
||||
return true
|
||||
}
|
||||
pushLine()
|
||||
@ -134,18 +134,18 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
|
||||
|
||||
val charData = renderWindow.font[char] ?: continue
|
||||
|
||||
val charWidth = charData.calculateWidth(text)
|
||||
val charWidth = charData.calculateWidth(text, renderInfo.scale)
|
||||
var width = charWidth
|
||||
|
||||
if (offset.x != initialOffset.x + renderInfo.charMargin) {
|
||||
// add spacing between letters
|
||||
width += if (bold) {
|
||||
width += (if (bold) {
|
||||
Font.HORIZONTAL_SPACING_BOLD
|
||||
} else if (shadow) {
|
||||
Font.HORIZONTAL_SPACING_SHADOW
|
||||
} else {
|
||||
Font.HORIZONTAL_SPACING
|
||||
}
|
||||
} * renderInfo.scale).toInt()
|
||||
}
|
||||
val previousY = offset.y
|
||||
|
||||
@ -163,7 +163,7 @@ object TextComponentRenderer : ChatComponentRenderer<TextComponent> {
|
||||
// ToDo: Remove Font.HORIZONTAL_SPACING
|
||||
}
|
||||
|
||||
consumer?.let { charData.render(letterOffset, z, text, it, options) }
|
||||
consumer?.let { charData.render(letterOffset, z, text, it, options, renderInfo.scale) }
|
||||
|
||||
if (consumer == null) {
|
||||
currentLineText += char
|
||||
|
@ -23,6 +23,7 @@ class TextRenderInfo(
|
||||
val fontAlignment: HorizontalAlignments,
|
||||
val charHeight: Int,
|
||||
val charMargin: Int,
|
||||
val scale: Float,
|
||||
val lines: MutableList<TextLineInfo> = mutableListOf(),
|
||||
var currentLineNumber: Int = 0,
|
||||
) {
|
||||
|
@ -39,11 +39,21 @@ open class TextElement(
|
||||
var backgroundColor: RGBColor = RenderConstants.TEXT_BACKGROUND_COLOR,
|
||||
noBorder: Boolean = false,
|
||||
parent: Element? = null,
|
||||
scale: Float = 1.0f,
|
||||
) : LabeledElement(hudRenderer) {
|
||||
lateinit var renderInfo: TextRenderInfo
|
||||
private set
|
||||
|
||||
// ToDo: Reapply if backgroundColor or fontAlignment changes
|
||||
|
||||
var scale: Float = scale
|
||||
set(value) {
|
||||
if (field == value) {
|
||||
return
|
||||
}
|
||||
field = value
|
||||
cacheUpToDate = false
|
||||
}
|
||||
var background: Boolean = background
|
||||
set(value) {
|
||||
if (field == value) {
|
||||
@ -58,8 +68,8 @@ open class TextElement(
|
||||
return
|
||||
}
|
||||
field = value
|
||||
charHeight = value.decide(Font.CHAR_HEIGHT, Font.TOTAL_CHAR_HEIGHT)
|
||||
charMargin = value.decide(0, Font.CHAR_MARGIN)
|
||||
charHeight = (value.decide(Font.CHAR_HEIGHT, Font.TOTAL_CHAR_HEIGHT) * scale).toInt()
|
||||
charMargin = (value.decide(0, Font.CHAR_MARGIN) * scale).toInt()
|
||||
forceApply()
|
||||
}
|
||||
var charHeight: Int = 0
|
||||
@ -88,6 +98,7 @@ open class TextElement(
|
||||
fontAlignment = fontAlignment,
|
||||
charHeight = charHeight,
|
||||
charMargin = charMargin,
|
||||
scale = scale,
|
||||
)
|
||||
ChatComponentRenderer.render(Vec2i.EMPTY, Vec2i.EMPTY, prefSize, 0, InfiniteSizeElement(hudRenderer), renderWindow, null, null, renderInfo, value)
|
||||
}
|
||||
@ -107,6 +118,7 @@ open class TextElement(
|
||||
fontAlignment = fontAlignment,
|
||||
charHeight = charHeight,
|
||||
charMargin = charMargin,
|
||||
scale = scale,
|
||||
)
|
||||
if (!emptyMessage) {
|
||||
ChatComponentRenderer.render(Vec2i.EMPTY, Vec2i.EMPTY, size, 0, this, renderWindow, null, null, renderInfo, chatComponent)
|
||||
|
@ -22,7 +22,7 @@ import de.bixilon.minosoft.util.MMath.round10
|
||||
import glm_.vec2.Vec2i
|
||||
|
||||
class WorldInfoHUDElement(hudRenderer: HUDRenderer) : HUDElement<TextElement>(hudRenderer), Pollable {
|
||||
override val layout: TextElement = TextElement(hudRenderer, "")
|
||||
override val layout: TextElement = TextElement(hudRenderer, "", scale = 3.0f)
|
||||
|
||||
override val layoutOffset: Vec2i = Vec2i(2, 2)
|
||||
|
||||
@ -53,7 +53,7 @@ class WorldInfoHUDElement(hudRenderer: HUDRenderer) : HUDElement<TextElement>(hu
|
||||
layout.text = if (hide) {
|
||||
""
|
||||
} else {
|
||||
"FPS $fps"
|
||||
"§aFPS $fps"
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user