diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-01-26 16:34:35 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-01-26 16:34:35 +0200 |
commit | 4127f58f05488037a590fd29b38bdf654e02a7d5 (patch) | |
tree | 275a71bfc861fdbe8fd62766b67fe533962c4c4f /src/main/java/io | |
parent | 6cb43704d06df2177e188c090a652f7e4f80a661 (diff) | |
download | LibGui-4127f58f05488037a590fd29b38bdf654e02a7d5.tar.gz LibGui-4127f58f05488037a590fd29b38bdf654e02a7d5.tar.bz2 LibGui-4127f58f05488037a590fd29b38bdf654e02a7d5.zip |
ScreenDrawing javadocs
Diffstat (limited to 'src/main/java/io')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java | 162 |
1 files changed, 127 insertions, 35 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java index 6caadcd..0cfac29 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java @@ -18,19 +18,43 @@ import net.minecraft.util.Identifier; */ public class ScreenDrawing { private ScreenDrawing() {} - + + /** + * Draws a textured rectangle. + * + * @param x the x coordinate of the box on-screen + * @param y the y coordinate of the box on-screen + * @param width the width of the box on-screen + * @param height the height of the box on-screen + * @param texture the Identifier for the texture + * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint + */ public static void texturedRect(int x, int y, int width, int height, Identifier texture, int color) { texturedRect(x, y, width, height, texture, 0, 0, 1, 1, color); } - + + /** + * Draws a textured rectangle. + * + * @param x the x coordinate of the box on-screen + * @param y the y coordinate of the box on-screen + * @param width the width of the box on-screen + * @param height the height of the box on-screen + * @param texture the Identifier for the texture + * @param u1 the left edge of the texture + * @param v1 the top edge of the texture + * @param u2 the right edge of the texture + * @param v2 the bottom edge of the texture + * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint + */ public static void texturedRect(int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color) { MinecraftClient.getInstance().getTextureManager().bindTexture(texture); - + //float scale = 0.00390625F; - + if (width <= 0) width = 1; if (height <= 0) height = 1; - + float r = (color >> 16 & 255) / 255.0F; float g = (color >> 8 & 255) / 255.0F; float b = (color & 255) / 255.0F; @@ -49,9 +73,11 @@ public class ScreenDrawing { //GlStateManager.enableTexture2D(); RenderSystem.disableBlend(); } - + /** - * If the texture is 256x256, this draws the texture at one pixel per texel. + * Draws a textured rectangle with UV values based on the width and height. + * + * <p>If the texture is 256x256, this draws the texture at one pixel per texel. * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -65,18 +91,30 @@ public class ScreenDrawing { float px = 1/256f; texturedRect(x, y, width, height, texture, textureX*px, textureY*px, (textureX+width)*px, (textureY+height)*px, color); } - + + /** + * Draws a textured rectangle with UV values based on the width and height. + * + * <p>If the texture is 256x256, this draws the texture at one pixel per texel. + * + * @param left the x coordinate of the box on-screen + * @param top the y coordinate of the box on-screen + * @param width the width of the box on-screen + * @param height the height of the box on-screen + * @param texture the Identifier for the texture + * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint + */ public static void texturedGuiRect(int left, int top, int width, int height, Identifier texture, int color) { texturedGuiRect(left, top, width, height, texture, 0, 0, color); } - + /** * Draws an untextured rectangle of the specified RGB color. */ public static void coloredRect(int left, int top, int width, int height, int color) { if (width <= 0) width = 1; if (height <= 0) height = 1; - + float a = (color >> 24 & 255) / 255.0F; float r = (color >> 16 & 255) / 255.0F; float g = (color >> 8 & 255) / 255.0F; @@ -96,17 +134,17 @@ public class ScreenDrawing { RenderSystem.enableTexture(); RenderSystem.disableBlend(); } - + public static void maskedRect(Identifier mask, Identifier texture, int left, int top, int width, int height) { - - + + texturedRect(left, top, width, height, mask, 0, 0, 1, 1, 0xFFFFFFFF); //TODO: 7 Z - + RenderSystem.enableDepthTest(); RenderSystem.depthFunc(GL11.GL_EQUAL); - + texturedRect(left, top, width, height, texture, 0, 0, 1, 1, 0xFFFFFFFF); //, 7); - + RenderSystem.depthFunc(GL11.GL_LESS); RenderSystem.disableDepthTest(); } @@ -148,25 +186,51 @@ public class ScreenDrawing { public static void rect(Fluid fluid, int left, int top, int width, int height, int color) { rect(fluid, left, top, width, height, 0, 0, 16, 16, color); }*/ - + /** * Draws a beveled, round rectangle that is substantially similar to default Minecraft UI panels. + * + * @param x the X position of the panel + * @param y the Y position of the panel + * @param width the width of the panel + * @param height the height of the panel */ public static void drawGuiPanel(int x, int y, int width, int height) { if (LibGuiClient.config.darkMode) drawGuiPanel(x, y, width, height, 0xFF0B0B0B, 0xFF2F2F2F, 0xFF414141, 0xFF000000); else drawGuiPanel(x, y, width, height, 0xFF555555, 0xFFC6C6C6, 0xFFFFFFFF, 0xFF000000); } - + + /** + * Draws a beveled, round, and colored rectangle that is substantially similar to default Minecraft UI panels. + * + * @param x the X position of the panel + * @param y the Y position of the panel + * @param width the width of the panel + * @param height the height of the panel + * @param panelColor the panel ARGB color + */ public static void drawGuiPanel(int x, int y, int width, int height, int panelColor) { int shadowColor = multiplyColor(panelColor, 0.50f); int hilightColor = multiplyColor(panelColor, 1.25f); - + drawGuiPanel(x, y, width, height, shadowColor, panelColor, hilightColor, 0xFF000000); } - + + /** + * Draws a beveled, round rectangle with custom edge colors that is substantially similar to default Minecraft UI panels. + * + * @param x the X position of the panel + * @param y the Y position of the panel + * @param width the width of the panel + * @param height the height of the panel + * @param shadow the bottom/right shadow ARGB color + * @param panel the center ARGB color + * @param hilight the top/left hilight ARGB color + * @param outline the outline ARGB color + */ public static void drawGuiPanel(int x, int y, int width, int height, int shadow, int panel, int hilight, int outline) { coloredRect(x + 3, y + 3, width - 6, height - 6, panel); //Main panel area - + coloredRect(x + 2, y + 1, width - 4, 2, hilight); //Top hilight coloredRect(x + 2, y + height - 3, width - 4, 2, shadow); //Bottom shadow coloredRect(x + 1, y + 2, 2, height - 4, hilight); //Left hilight @@ -175,7 +239,7 @@ public class ScreenDrawing { coloredRect(x + 2, y + height - 3, 1, 1, panel); //Bottomleft non-hilight/non-shadow transition pixel coloredRect(x + 3, y + 3, 1, 1, hilight); //Topleft round hilight pixel coloredRect(x + width - 4, y + height - 4, 1, 1, shadow); //Bottomright round shadow pixel - + coloredRect(x + 2, y, width - 4, 1, outline); //Top outline coloredRect(x, y + 2, 1, height - 4, outline); //Left outline coloredRect(x + width - 1, y + 2, 1, height - 4, outline); //Right outline @@ -192,14 +256,14 @@ public class ScreenDrawing { public static void drawBeveledPanel(int x, int y) { drawBeveledPanel(x, y, 18, 18, 0xFF373737, 0xFF8b8b8b, 0xFFFFFFFF); } - + /** * Draws a default-color recessed itemslot panel of variable size */ public static void drawBeveledPanel(int x, int y, int width, int height) { drawBeveledPanel(x, y, width, height, 0xFF373737, 0xFF8b8b8b, 0xFFFFFFFF); } - + /** * Draws a generalized-case beveled panel. Can be inset or outset depending on arguments. * @param x x coordinate of the topleft corner @@ -217,7 +281,17 @@ public class ScreenDrawing { coloredRect(x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight coloredRect(x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight } - + + /** + * Draws a string with a custom alignment. + * + * @param s the string + * @param align the alignment of the string + * @param x the X position + * @param y the Y position + * @param width the width of the string, used for aligning + * @param color the text color + */ public static void drawString(String s, Alignment align, int x, int y, int width, int color) { switch(align) { case LEFT: { @@ -238,7 +312,17 @@ public class ScreenDrawing { break; } } - + + /** + * Draws a shadowed string. + * + * @param s the string + * @param align the alignment of the string + * @param x the X position + * @param y the Y position + * @param width the width of the string, used for aligning + * @param color the text color + */ public static void drawStringWithShadow(String s, Alignment align, int x, int y, int width, int color) { switch(align) { case LEFT: { @@ -259,11 +343,19 @@ public class ScreenDrawing { break; } } - + + /** + * Draws a left-aligned string. + * + * @param s the string + * @param x the X position + * @param y the Y position + * @param color the text color + */ public static void drawString(String s, int x, int y, int color) { MinecraftClient.getInstance().textRenderer.draw(s, x, y, color); } - + /** * @deprecated for removal; please use {@link #drawStringWithShadow(String, Alignment, int, int, int, int)} */ @@ -272,30 +364,30 @@ public class ScreenDrawing { TextRenderer render = MinecraftClient.getInstance().getFontManager().getTextRenderer(MinecraftClient.DEFAULT_TEXT_RENDERER_ID); render.drawWithShadow(s, (float)(x - render.getStringWidth(s) / 2), (float)y, color); } - + public static int colorAtOpacity(int opaque, float opacity) { if (opacity<0.0f) opacity=0.0f; if (opacity>1.0f) opacity=1.0f; - + int a = (int)(opacity * 255.0f); - + return (opaque & 0xFFFFFF) | (a << 24); } - + public static int multiplyColor(int color, float amount) { int a = color & 0xFF000000; float r = (color >> 16 & 255) / 255.0F; float g = (color >> 8 & 255) / 255.0F; float b = (color & 255) / 255.0F; - + r = Math.min(r*amount, 1.0f); g = Math.min(g*amount, 1.0f); b = Math.min(b*amount, 1.0f); - + int ir = (int)(r*255); int ig = (int)(g*255); int ib = (int)(b*255); - + return a | (ir << 16) | |