diff options
author | Brady <thatgravyboat@gmail.com> | 2024-07-28 08:04:52 -0230 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-28 12:34:52 +0200 |
commit | a41214df4d112444eca29fe60684cc051382a33c (patch) | |
tree | 2de4a300be9592090aacf3615fd9f5881a77e9f8 /src/main/java/at/hannibal2/skyhanni/utils | |
parent | 32d3a6ae845475284cc5f72dac5649d732c223b5 (diff) | |
download | skyhanni-a41214df4d112444eca29fe60684cc051382a33c.tar.gz skyhanni-a41214df4d112444eca29fe60684cc051382a33c.tar.bz2 skyhanni-a41214df4d112444eca29fe60684cc051382a33c.zip |
Improvement: Apply border radius to scoreboard texture (#2228)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt | 43 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt | 2 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index d32ff9ea9..9ff6053e7 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.RenderGuiItemOverlayEvent import at.hannibal2.skyhanni.features.misc.RoundedRectangleOutlineShader import at.hannibal2.skyhanni.features.misc.RoundedRectangleShader +import at.hannibal2.skyhanni.features.misc.RoundedTextureShader import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.CollectionUtils.zipWithNext3 import at.hannibal2.skyhanni.utils.ColorUtils.getFirstColorCode @@ -1719,6 +1720,48 @@ object RenderUtils { GlStateManager.enableDepth() } + + /** + * Method to draw a rounded textured rect. + * + * **NOTE:** If you are using [GlStateManager.translate] or [GlStateManager.scale] + * with this method, ensure they are invoked in the correct order if you use both. That is, [GlStateManager.translate] + * is called **BEFORE** [GlStateManager.scale], otherwise the textured rect will not be rendered correctly + * + * @param filter the texture filter to use + * @param radius the radius of the corners (default 10), NOTE: If you pass less than 1 it will just draw as a normal textured rect + * @param smoothness how smooth the corners will appear (default 1). NOTE: This does very + * little to the smoothness of the corners in reality due to how the final pixel color is calculated. + * It is best kept at its default. + */ + fun drawRoundTexturedRect(x: Int, y: Int, width: Int, height: Int, filter: Int, radius: Int = 10, smoothness: Int = 1) { + // if radius is 0 then just draw a normal textured rect + if (radius <= 0) { + Utils.drawTexturedRect(x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), filter) + return + } + + val scaledRes = ScaledResolution(Minecraft.getMinecraft()) + val widthIn = width * scaledRes.scaleFactor + val heightIn = height * scaledRes.scaleFactor + val xIn = x * scaledRes.scaleFactor + val yIn = y * scaledRes.scaleFactor + + RoundedTextureShader.scaleFactor = scaledRes.scaleFactor.toFloat() + RoundedTextureShader.radius = radius.toFloat() + RoundedTextureShader.smoothness = smoothness.toFloat() + RoundedTextureShader.halfSize = floatArrayOf(widthIn / 2f, heightIn / 2f) + RoundedTextureShader.centerPos = floatArrayOf(xIn + (widthIn / 2f), yIn + (heightIn / 2f)) + + GlStateManager.pushMatrix() + ShaderManager.enableShader(ShaderManager.Shaders.ROUNDED_TEXTURE) + + Utils.drawTexturedRect(x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), filter) + + ShaderManager.disableShader() + GlStateManager.popMatrix() + } + /** * Method to draw a rounded rectangle. * diff --git a/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt index 39a2fe302..ed4dbabdf 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/shader/ShaderManager.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.features.chroma.TexturedChromaShader import at.hannibal2.skyhanni.features.misc.DarkenShader import at.hannibal2.skyhanni.features.misc.RoundedRectangleOutlineShader import at.hannibal2.skyhanni.features.misc.RoundedRectangleShader +import at.hannibal2.skyhanni.features.misc.RoundedTextureShader import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.client.Minecraft @@ -28,6 +29,7 @@ object ShaderManager { TEXTURED_CHROMA(TexturedChromaShader.INSTANCE), ROUNDED_RECTANGLE(RoundedRectangleShader.INSTANCE), ROUNDED_RECT_OUTLINE(RoundedRectangleOutlineShader.INSTANCE), + ROUNDED_TEXTURE(RoundedTextureShader.INSTANCE), DARKEN(DarkenShader.INSTANCE) ; |