Move tessellator use to its own helper file

Because drawing a textured quad requires thinking and thinking is hard
This commit is contained in:
Firenoo committed 2023-03-21 19:32:26 -07:00
1 parent 0c61ee40aa
commit f3a35c4540
3 files changed
+49 -30

No files matched your search

@@ -272,29 +272,23 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
bindTexture(MODID, "textures/gui/advanced_memory_card.png")
val tessellator = Tessellator.instance
// Draw the top part
tessellator.startDrawingQuads()
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop + 60.0, 0.0, 0.0, 60.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(((guiLeft + GUI_WIDTH).toDouble()), guiTop + 60.0, 0.0, 1.0, 60.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV((guiLeft + GUI_WIDTH).toDouble(), guiTop.toDouble(), 0.0, 1.0, 0.0)
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop.toDouble(), 0.0, 0.0, 0.0)
tessellator.draw()
drawTexturedQuad(tessellator, guiLeft.toDouble(), guiTop.toDouble(),
(guiLeft + GUI_WIDTH).toDouble(), guiTop + 60.0,
u0 = 0.0, v0 = 0.0,
u1 = 1.0, v1 = 60.0 / GUI_TEX_HEIGHT)
// Draw P2P segments
val p2pHeight = P2P_ENTRY_HEIGHT + 1.0
for (i in 0 until scale.size(ySize - 75) - 2) {
tessellator.startDrawingQuads()
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop + 60.0 + p2pHeight * (i + 1), 0.0, 0.0, 102.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(((guiLeft + GUI_WIDTH).toDouble()), guiTop + 60.0 + p2pHeight * (i + 1), 0.0, 1.0, 102.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV((guiLeft + GUI_WIDTH).toDouble(), guiTop + 60.0 + p2pHeight * i, 0.0, 1.0, 60.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop + 60.0 + p2pHeight * i, 0.0, 0.0, 60.0 / GUI_TEX_HEIGHT)
tessellator.draw()
drawTexturedQuad(tessellator, guiLeft.toDouble(), guiTop + 60.0 + p2pHeight * i,
(guiLeft + GUI_WIDTH).toDouble(), guiTop + 60.0 + p2pHeight * (i + 1),
u0 = 0.0, v0 = 60.0 / GUI_TEX_HEIGHT,
u1 = 1.0, v1 = 102.0 / GUI_TEX_HEIGHT)
}
// Draw Bottom
tessellator.startDrawingQuads()
tessellator.addVertexWithUV(guiLeft.toDouble(), (guiTop + ySize).toDouble(), 0.0, 0.0, 200.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(((guiLeft + GUI_WIDTH).toDouble()), (guiTop + ySize).toDouble(), 0.0, 1.0, 200.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV((guiLeft + GUI_WIDTH).toDouble(), guiTop + ySize - 98.0, 0.0, 1.0, 102.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop + ySize - 98.0, 0.0, 0.0, 102.0 / GUI_TEX_HEIGHT)
tessellator.draw()
drawTexturedQuad(tessellator, guiLeft.toDouble(), guiTop + ySize - 98.0,
(guiLeft + GUI_WIDTH).toDouble(), (guiTop + ySize).toDouble(),
u0 = 0.0, v0 = 102.0 / GUI_TEX_HEIGHT,
u1 = 1.0, v1 = 200.0 / GUI_TEX_HEIGHT)
}
override fun doesGuiPauseGame(): Boolean {
@@ -0,0 +1,25 @@
package com.projecturanus.betterp2p.client.gui
import net.minecraft.client.renderer.Tessellator
import net.minecraft.util.ResourceLocation
fun bindTexture(loc: ResourceLocation) {
}
/**
* Draws a textured quad.
*
* x0, y0 - top left corner
* x1, y1 - bottom right corner
* u0, v0 - top left texture corner
* u1, v1 - bottom right texture corner
*/
fun drawTexturedQuad(tessellator: Tessellator, x0 : Double, y0: Double, x1: Double, y1: Double, u0: Double, v0: Double, u1: Double, v1: Double) {
tessellator.startDrawingQuads()
tessellator.addVertexWithUV(x0, y1, 0.0, u0, v1)
tessellator.addVertexWithUV(x1, y1, 0.0, u1, v1)
tessellator.addVertexWithUV(x1, y0, 0.0, u1, v0)
tessellator.addVertexWithUV(x0, y0, 0.0, u0, v0)
tessellator.draw()
}
@@ -4,6 +4,7 @@ import com.projecturanus.betterp2p.MODID
import com.projecturanus.betterp2p.client.gui.GUI_TEX_HEIGHT
import com.projecturanus.betterp2p.client.gui.GUI_WIDTH
import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard
import com.projecturanus.betterp2p.client.gui.drawTexturedQuad
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.renderer.OpenGlHelper
@@ -35,18 +36,17 @@ abstract class WidgetButton(val gui: GuiAdvancedMemoryCard, x: Int, y: Int, widt
GL11.glEnable(GL11.GL_BLEND)
OpenGlHelper.glBlendFunc(770, 771, 1, 0)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
tessellator.startDrawingQuads()
tessellator.addVertexWithUV(xPosition.toDouble(), (yPosition + height).toDouble(), 0.0, (32.0 * k) / GUI_WIDTH, (232.0 + height) / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(((xPosition + width).toDouble()), (yPosition + height).toDouble(), 0.0, (32.0 * (k + 1)) / GUI_WIDTH, (232.0 + height) / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV((xPosition + width).toDouble(), yPosition.toDouble(), 0.0, (32.0 * (k + 1)) / GUI_WIDTH, 232.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(xPosition.toDouble(), yPosition.toDouble(), 0.0, (32.0 * k) / GUI_WIDTH, 232.0 / GUI_TEX_HEIGHT)
tessellator.draw()
tessellator.startDrawingQuads()
tessellator.addVertexWithUV(xPosition.toDouble(), (yPosition + height).toDouble(), 0.0, texX / GUI_WIDTH, (texY + height) / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(((xPosition + width).toDouble()), (yPosition + height).toDouble(), 0.0, (texX + width) / GUI_WIDTH, (texY + height) / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV((xPosition + width).toDouble(), yPosition.toDouble(), 0.0, (texX + width) / GUI_WIDTH, texY / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(xPosition.toDouble(), yPosition.toDouble(), 0.0, texX / GUI_WIDTH, texY / GUI_TEX_HEIGHT)
tessellator.draw()
// Draw button backdrop
drawTexturedQuad(tessellator, xPosition.toDouble(), yPosition.toDouble(),
(xPosition + width).toDouble(), (yPosition + height).toDouble(),
u0 = (32.0 * k) / GUI_WIDTH, v0 = (232.0) / GUI_TEX_HEIGHT,
u1 = (32.0 * (k + 1)) / GUI_WIDTH, v1 = (232.0 + height) / GUI_TEX_HEIGHT)
// Draw button icon
drawTexturedQuad(tessellator, xPosition.toDouble(), yPosition.toDouble(),
(xPosition + width).toDouble(), (yPosition + height).toDouble(),
u0 = texX / GUI_WIDTH, v0 = texY / GUI_TEX_HEIGHT,
u1 = (texX + width) / GUI_WIDTH, v1 = (texY + height) / GUI_TEX_HEIGHT)
}
fun setPosition(x: Int, y: Int) {
this.xPosition = x