diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/util/Easing.java | 23 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java | 43 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java b/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java index da41927..4146900 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java +++ b/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java @@ -1,5 +1,7 @@ package com.anthonyhilyard.iceberg.util; +import net.minecraft.util.text.Color; + /** * Helper functions for smooth easing/interpolation. If you need linear, use net.minecraft.util.math.MathHelper.lerp instead. */ @@ -8,6 +10,7 @@ public final class Easing public static enum EasingType { None, // Produces step-wise interpolation. + Linear, Quad, Cubic } @@ -29,6 +32,19 @@ public final class Easing return Ease(a, b, t, type, EasingDirection.InOut); } + public static Color Ease(Color a, Color b, float t, EasingType type) + { + // Helper function to ease between colors. + // Ease each component individually. + int aV = a.getValue(), bV = b.getValue(); + int aA = (aV >> 24) & 0xFF, aR = (aV >> 16) & 0xFF, aG = (aV >> 8) & 0xFF, aB = (aV >> 0) & 0xFF, + bA = (bV >> 24) & 0xFF, bR = (bV >> 16) & 0xFF, bG = (bV >> 8) & 0xFF, bB = (bV >> 0) & 0xFF; + return Color.fromRgb((int)Ease(aA, bA, t, type) << 24 | + (int)Ease(aR, bR, t, type) << 16 | + (int)Ease(aG, bG, t, type) << 8 | + (int)Ease(aB, bB, t, type) << 0); + } + public static float Ease(float a, float b, float t, EasingType type, EasingDirection direction) { switch (type) @@ -36,6 +52,8 @@ public final class Easing case None: default: return None(a, b, t); + case Linear: + return Linear(a, b, t); case Quad: return Quad(a, b, t, direction); case Cubic: @@ -55,6 +73,11 @@ public final class Easing } } + private static float Linear(float a, float b, float t) + { + return a + (b - a) * t; + } + private static float Quad(float a, float b, float t, EasingDirection direction) { switch (direction) diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java b/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java new file mode 100644 index 0000000..4325ebe --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java @@ -0,0 +1,43 @@ +package com.anthonyhilyard.iceberg.util; + +import org.lwjgl.opengl.GL11; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.math.vector.Matrix4f; + +public class GuiHelper +{ + @SuppressWarnings("deprecation") + public static void drawGradientRectHorizontal(Matrix4f mat, int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) + { + float startAlpha = (float)(startColor >> 24 & 255) / 255.0F; + float startRed = (float)(startColor >> 16 & 255) / 255.0F; + float startGreen = (float)(startColor >> 8 & 255) / 255.0F; + float startBlue = (float)(startColor & 255) / 255.0F; + float endAlpha = (float)(endColor >> 24 & 255) / 255.0F; + float endRed = (float)(endColor >> 16 & 255) / 255.0F; + float endGreen = (float)(endColor >> 8 & 255) / 255.0F; + float endBlue = (float)(endColor & 255) / 255.0F; + + RenderSystem.enableDepthTest(); + RenderSystem.disableTexture(); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + RenderSystem.shadeModel(GL11.GL_SMOOTH); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuilder(); + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); + buffer.vertex(mat, right, top, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex(); + buffer.vertex(mat, left, top, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); + buffer.vertex(mat, left, bottom, zLevel).color(startRed, startGreen, startBlue, startAlpha).endVertex(); + buffer.vertex(mat, right, bottom, zLevel).color( endRed, endGreen, endBlue, endAlpha).endVertex(); + tessellator.end(); + + RenderSystem.shadeModel(GL11.GL_FLAT); + RenderSystem.disableBlend(); + RenderSystem.enableTexture(); + } +} |