aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
diff options
context:
space:
mode:
authorAnthony Hilyard <anthony.hilyard@gmail.com>2021-11-26 14:44:47 -0800
committerAnthony Hilyard <anthony.hilyard@gmail.com>2021-11-26 14:44:47 -0800
commit36a1f98bba70892f4e06c3df8b2b0bb4d0d5fe03 (patch)
treee75a485a3bb1825abec59b7a8f9c81247dbf0c90 /src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
parent3f1f8379cf9826c3c7d7340a1ed9242d7dce287f (diff)
downloadIceberg-36a1f98bba70892f4e06c3df8b2b0bb4d0d5fe03.tar.gz
Iceberg-36a1f98bba70892f4e06c3df8b2b0bb4d0d5fe03.tar.bz2
Iceberg-36a1f98bba70892f4e06c3df8b2b0bb4d0d5fe03.zip
Added minimum width constrain option for tooltip rendering.
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java')
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
index fe24e44..bea4b5a 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
@@ -88,18 +88,25 @@ public class Tooltips
}
}
- public static void renderItemTooltip(@Nonnull final ItemStack stack, PoseStack mStack, TooltipInfo info,
+ public static void renderItemTooltip(@Nonnull final ItemStack stack, PoseStack poseStack, TooltipInfo info,
Rect2i rect, int screenWidth, int screenHeight,
int backgroundColor, int borderColorStart, int borderColorEnd)
{
- renderItemTooltip(stack, mStack, info, rect, screenWidth, screenHeight, backgroundColor, borderColorStart, borderColorEnd, false);
+ renderItemTooltip(stack, poseStack, info, rect, screenWidth, screenHeight, backgroundColor, borderColorStart, borderColorEnd, false);
}
- @SuppressWarnings("removal")
- public static void renderItemTooltip(@Nonnull final ItemStack stack, PoseStack mStack, TooltipInfo info,
+ public static void renderItemTooltip(@Nonnull final ItemStack stack, PoseStack poseStack, TooltipInfo info,
Rect2i rect, int screenWidth, int screenHeight,
int backgroundColor, int borderColorStart, int borderColorEnd, boolean comparison)
{
+ renderItemTooltip(stack, poseStack, info, rect, screenWidth, screenHeight, backgroundColor, borderColorStart, borderColorEnd, comparison, false);
+ }
+
+ @SuppressWarnings("removal")
+ public static void renderItemTooltip(@Nonnull final ItemStack stack, PoseStack poseStack, TooltipInfo info,
+ Rect2i rect, int screenWidth, int screenHeight,
+ int backgroundColor, int borderColorStart, int borderColorEnd, boolean comparison, boolean constrain)
+ {
if (info.getLines().isEmpty())
{
return;
@@ -109,7 +116,7 @@ public class Tooltips
int rectY = rect.getY() + 18;
int maxTextWidth = rect.getWidth() - 8;
- RenderTooltipExtEvent.Pre event = new RenderTooltipExtEvent.Pre(stack, info.getLines(), mStack, rectX, rectY, screenWidth, screenHeight, maxTextWidth, info.getFont(), comparison);
+ RenderTooltipExtEvent.Pre event = new RenderTooltipExtEvent.Pre(stack, info.getLines(), poseStack, rectX, rectY, screenWidth, screenHeight, maxTextWidth, info.getFont(), comparison);
if (MinecraftForge.EVENT_BUS.post(event))
{
return;
@@ -125,6 +132,12 @@ public class Tooltips
RenderSystem.disableDepthTest();
int tooltipTextWidth = info.getMaxLineWidth();
+ // Constrain the minimum width to the rect.
+ if (constrain)
+ {
+ tooltipTextWidth = Math.max(info.getMaxLineWidth(), rect.getWidth() - 8);
+ }
+
boolean needsWrap = false;
int tooltipX = rectX + 12;
@@ -180,14 +193,14 @@ public class Tooltips
}
final int zLevel = 400;
- RenderTooltipExtEvent.Color colorEvent = new RenderTooltipExtEvent.Color(stack, info.getLines(), mStack, tooltipX, tooltipY, info.getFont(), backgroundColor, borderColorStart, borderColorEnd, comparison);
+ RenderTooltipExtEvent.Color colorEvent = new RenderTooltipExtEvent.Color(stack, info.getLines(), poseStack, tooltipX, tooltipY, info.getFont(), backgroundColor, borderColorStart, borderColorEnd, comparison);
MinecraftForge.EVENT_BUS.post(colorEvent);
backgroundColor = colorEvent.getBackground();
borderColorStart = colorEvent.getBorderStart();
borderColorEnd = colorEvent.getBorderEnd();
- mStack.pushPose();
- Matrix4f mat = mStack.last().pose();
+ poseStack.pushPose();
+ Matrix4f mat = poseStack.last().pose();
GuiUtils.drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor);
@@ -199,10 +212,10 @@ public class Tooltips
GuiUtils.drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart);
GuiUtils.drawGradientRect(mat, zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd);
- MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(stack, info.getLines(), mStack, tooltipX, tooltipY, info.getFont(), tooltipTextWidth, tooltipHeight));
+ MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(stack, info.getLines(), poseStack, tooltipX, tooltipY, info.getFont(), tooltipTextWidth, tooltipHeight));
BufferSource renderType = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
- mStack.translate(0.0D, 0.0D, zLevel);
+ poseStack.translate(0.0D, 0.0D, zLevel);
int tooltipTop = tooltipY;
@@ -223,15 +236,15 @@ public class Tooltips
}
renderType.endBatch();
- mStack.popPose();
+ poseStack.popPose();
- MinecraftForge.EVENT_BUS.post(new RenderTooltipExtEvent.PostText(stack, info.getLines(), mStack, tooltipX, tooltipTop, info.getFont(), tooltipTextWidth, tooltipHeight, comparison));
+ MinecraftForge.EVENT_BUS.post(new RenderTooltipExtEvent.PostText(stack, info.getLines(), poseStack, tooltipX, tooltipTop, info.getFont(), tooltipTextWidth, tooltipHeight, comparison));
RenderSystem.enableDepthTest();
}
@SuppressWarnings("removal")
- public static Rect2i calculateRect(final ItemStack stack, PoseStack mStack, List<? extends FormattedText> textLines, int mouseX, int mouseY,
+ public static Rect2i calculateRect(final ItemStack stack, PoseStack poseStack, List<? extends FormattedText> textLines, int mouseX, int mouseY,
int screenWidth, int screenHeight, int maxTextWidth, Font font)
{
Rect2i rect = new Rect2i(0, 0, 0, 0);
@@ -241,7 +254,7 @@ public class Tooltips
}
// Generate a tooltip event even though we aren't rendering anything in case the event handlers are modifying the input values.
- RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(stack, textLines, mStack, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth, font);
+ RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(stack, textLines, poseStack, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth, font);
if (MinecraftForge.EVENT_BUS.post(event))
{
return rect;