All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.ru.casperix.multiplatform.text.TextRenderer.kt Maven / Gradle / Ivy

The newest version!
package ru.casperix.multiplatform.text


import ru.casperix.math.color.Color
import ru.casperix.math.color.Colors
import ru.casperix.math.quad_matrix.float32.Matrix3f
import ru.casperix.math.vector.float32.Vector2f
import ru.casperix.multiplatform.font.FontReference
import ru.casperix.multiplatform.text.impl.TextScheme
import ru.casperix.multiplatform.text.impl.TextView
import ru.casperix.renderer.Renderer2D
import ru.casperix.renderer.misc.AlignMode
import ru.casperix.renderer.vector.VectorGraphic


expect val textRenderer: TextRendererApi

fun Renderer2D.drawText(
    scheme: TextScheme,
    transform: Matrix3f = Matrix3f.IDENTITY,
    showText: Boolean = true,
    showMetrics: Boolean = false,
) {
    if (showMetrics) {
        val graphic = textRenderer.getTextMetricGraphic(scheme)
        drawGraphic(graphic, transform)
    }
    if (showText) {
        val graphic = textRenderer.getTextGraphic(scheme)
        drawGraphic(graphic, transform)
    }
}


fun Renderer2D.drawText(
    text: String,
    reference: FontReference,
    transform: Matrix3f,
    availableArea: Vector2f = Vector2f(Float.POSITIVE_INFINITY),
    color: Color = Colors.WHITE,
    backgroundColor: Color? = null,
    showText: Boolean = true,
    showMetrics: Boolean = false,
): TextScheme {
    return drawText(
        listOf(TextView(text, reference, color, backgroundColor)),
        transform,
        availableArea,
        showText,
        showMetrics
    )
}

fun Renderer2D.drawText(
    blocks: List,
    transform: Matrix3f,
    availableArea: Vector2f = Vector2f(Float.POSITIVE_INFINITY),
    showText: Boolean = true,
    showMetrics: Boolean = false,
): TextScheme {
    val scheme = textRenderer.getTextScheme(blocks, availableArea)
    drawText(scheme, transform, showText, showMetrics)
    return scheme
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy