net.peanuuutz.fork.ui.scene.screen.NativeCanvasHelper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fork-ui Show documentation
Show all versions of fork-ui Show documentation
Comprehensive API designed for Minecraft modders
The newest version!
package net.peanuuutz.fork.ui.scene.screen
import net.minecraft.client.gl.ShaderProgram
import net.minecraft.client.render.GameRenderer
import net.peanuuutz.fork.ui.scene.base.MatrixStackCanvas
import net.peanuuutz.fork.ui.ui.draw.canvas.BlendMode
import net.peanuuutz.fork.ui.ui.draw.canvas.Canvas
import net.peanuuutz.fork.ui.ui.draw.canvas.ClipSave
import net.peanuuutz.fork.ui.ui.draw.canvas.Paint
import net.peanuuutz.fork.ui.ui.draw.canvas.PosColorTexVertices
import net.peanuuutz.fork.ui.ui.draw.canvas.PosColorVertices
import net.peanuuutz.fork.ui.ui.draw.canvas.PosTexVertices
// -------- Context --------
context(MatrixStackCanvas)
fun nSaveClip(clip: ClipSave) {
nSaveClipImpl(clip)
}
context(MatrixStackCanvas)
fun nRestoreClip(clip: ClipSave) {
nRestoreClipImpl(clip)
}
context(Canvas)
fun nSaveAlpha(alpha: Float) {
nSaveAlphaImpl(alpha)
}
context(Canvas)
fun nRestoreAlpha(alpha: Float) {
nRestoreAlphaImpl(alpha)
}
context(Canvas)
fun nSaveBlendMode(blendMode: BlendMode) {
nSaveBlendModeImpl(blendMode)
}
context(Canvas)
fun nRestoreBlendMode(blendMode: BlendMode) {
nRestoreBlendModeImpl(blendMode)
}
context(Canvas)
inline fun Paint.applyTo(onDraw: Paint.() -> Unit) {
val alpha = alpha
val blendMode = blendMode
nSaveAlpha(alpha)
nSaveBlendMode(blendMode)
onDraw()
nRestoreBlendMode(blendMode)
nRestoreAlpha(alpha)
}
// -------- Draw --------
context(MatrixStackCanvas)
fun nDrawVertices(
vertices: PosColorVertices,
shaderProgram: ShaderProgram = GameRenderer.getPositionColorProgram()!!
) {
nDrawVerticesImpl(vertices, shaderProgram)
}
context(MatrixStackCanvas)
fun nDrawVertices(
vertices: PosTexVertices,
shaderProgram: ShaderProgram = GameRenderer.getPositionTexProgram()!!
) {
nDrawVerticesImpl(vertices, shaderProgram)
}
context(MatrixStackCanvas)
fun nDrawVertices(
vertices: PosColorTexVertices,
shaderProgram: ShaderProgram = GameRenderer.getPositionColorTexProgram()!!
) {
nDrawVerticesImpl(vertices, shaderProgram)
}