From a41214df4d112444eca29fe60684cc051382a33c Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 28 Jul 2024 08:04:52 -0230 Subject: Improvement: Apply border radius to scoreboard texture (#2228) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../gui/customscoreboard/RenderBackground.kt | 20 ++++++------ .../features/misc/RoundedRectangleShader.kt | 28 ---------------- .../skyhanni/features/misc/RoundedShader.kt | 37 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 38 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/RoundedRectangleShader.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/RoundedShader.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt index 3d4e6daad..ebbb7fa30 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/RenderBackground.kt @@ -7,7 +7,6 @@ import at.hannibal2.skyhanni.data.GuiEditManager.getAbsY import at.hannibal2.skyhanni.data.GuiEditManager.getDummySize import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor import at.hannibal2.skyhanni.utils.RenderUtils -import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.client.Minecraft import net.minecraft.client.gui.ScaledResolution import net.minecraft.client.renderer.GlStateManager @@ -49,12 +48,13 @@ class RenderBackground { val textureLocation = ResourceLocation("skyhanni", "scoreboard.png") Minecraft.getMinecraft().textureManager.bindTexture(textureLocation) - Utils.drawTexturedRect( - (x - border).toFloat(), - (y - border).toFloat(), - (elementWidth + border * 3).toFloat(), - (elementHeight + border * 2).toFloat(), - GL11.GL_NEAREST + RenderUtils.drawRoundTexturedRect( + x - border, + y - border, + elementWidth + border * 3, + elementHeight + border * 2, + GL11.GL_NEAREST, + backgroundConfig.roundedCornerSmoothness, ) } else { RenderUtils.drawRoundRect( @@ -63,7 +63,7 @@ class RenderBackground { elementWidth + border * 3, elementHeight + border * 2, backgroundConfig.color.toChromaColor().rgb, - backgroundConfig.roundedCornerSmoothness + backgroundConfig.roundedCornerSmoothness, ) } if (outlineConfig.enabled) { @@ -76,7 +76,7 @@ class RenderBackground { outlineConfig.colorBottom.toChromaColor().rgb, outlineConfig.thickness, backgroundConfig.roundedCornerSmoothness, - outlineConfig.blur + outlineConfig.blur, ) } } @@ -133,7 +133,7 @@ class RenderBackground { newX, newY, position.getScale(), - position.isCenter + position.isCenter, ) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/RoundedRectangleShader.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/RoundedRectangleShader.kt deleted file mode 100644 index 9ce2d0ce7..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/RoundedRectangleShader.kt +++ /dev/null @@ -1,28 +0,0 @@ -package at.hannibal2.skyhanni.features.misc - -import at.hannibal2.skyhanni.utils.shader.Shader -import at.hannibal2.skyhanni.utils.shader.Uniform -import net.minecraft.client.Minecraft - -object RoundedRectangleShader : Shader("rounded_rect", "rounded_rect") { - - val INSTANCE: RoundedRectangleShader - get() = this - - var scaleFactor: Float = 0f - var radius: Float = 0f - var smoothness: Float = 0f - var halfSize: FloatArray = floatArrayOf(0f, 0f) - var centerPos: FloatArray = floatArrayOf(0f, 0f) - set(value) { - field = floatArrayOf(value[0], Minecraft.getMinecraft().displayHeight - value[1]) - } - - override fun registerUniforms() { - registerUniform(Uniform.UniformType.FLOAT, "scaleFactor") { scaleFactor } - registerUniform(Uniform.UniformType.FLOAT, "radius") { radius } - registerUniform(Uniform.UniformType.FLOAT, "smoothness") { smoothness } - registerUniform(Uniform.UniformType.VEC2, "halfSize") { halfSize } - registerUniform(Uniform.UniformType.VEC2, "centerPos") { centerPos } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/RoundedShader.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/RoundedShader.kt new file mode 100644 index 000000000..ab4b1165c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/RoundedShader.kt @@ -0,0 +1,37 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.utils.shader.Shader +import at.hannibal2.skyhanni.utils.shader.Uniform +import net.minecraft.client.Minecraft + +abstract class RoundedShader(vertex: String, fragment: String) : Shader(vertex, fragment) { + + var scaleFactor: Float = 0f + var radius: Float = 0f + var smoothness: Float = 0f + var halfSize: FloatArray = floatArrayOf(0f, 0f) + var centerPos: FloatArray = floatArrayOf(0f, 0f) + set(value) { + field = floatArrayOf(value[0], Minecraft.getMinecraft().displayHeight - value[1]) + } + + override fun registerUniforms() { + registerUniform(Uniform.UniformType.FLOAT, "scaleFactor") { scaleFactor } + registerUniform(Uniform.UniformType.FLOAT, "radius") { radius } + registerUniform(Uniform.UniformType.FLOAT, "smoothness") { smoothness } + registerUniform(Uniform.UniformType.VEC2, "halfSize") { halfSize } + registerUniform(Uniform.UniformType.VEC2, "centerPos") { centerPos } + } +} + +object RoundedRectangleShader : RoundedShader("rounded_rect", "rounded_rect") { + + val INSTANCE: RoundedRectangleShader + get() = this +} + +object RoundedTextureShader : RoundedShader("rounded_texture", "rounded_texture") { + + val INSTANCE: RoundedTextureShader + get() = this +} -- cgit