use of net.minecraft.client.gui.FontRenderer in project DynamicSurroundings by OreCruncher.
the class PotionHUD method doRender.
@Override
public void doRender(final RenderGameOverlayEvent.Pre event) {
if (ModOptions.player.potionHUD.potionHudNone && event.getType() == ElementType.POTION_ICONS) {
event.setCanceled(true);
return;
}
if (event.getType() != ElementType.POTION_ICONS || this.potions.size() == 0) {
return;
}
event.setCanceled(true);
final ScaledResolution resolution = event.getResolution();
final float GUITOP = ModOptions.player.potionHUD.potionHudTopOffset;
final float GUILEFT = ModOptions.player.potionHUD.potionHudAnchor == 0 ? ModOptions.player.potionHUD.potionHudLeftOffset : resolution.getScaledWidth() - ModOptions.player.potionHUD.potionHudLeftOffset - 120 * ModOptions.player.potionHUD.potionHudScale;
final float SCALE = ModOptions.player.potionHUD.potionHudScale;
final Minecraft mc = Minecraft.getMinecraft();
final FontRenderer font = mc.fontRenderer;
final int guiLeft = 2;
int guiTop = 2;
GlStateManager.pushMatrix();
GlStateManager.translate(GUILEFT, GUITOP, 0.0F);
GlStateManager.scale(SCALE, SCALE, SCALE);
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
int k = 33;
if (this.potions.size() > 7) {
k = 198 / (this.potions.size() - 1);
}
for (final PotionInfo potion : this.potions) {
mc.getTextureManager().bindTexture(GuiContainer.INVENTORY_BACKGROUND);
GlStateManager.color(1.0F, 1.0F, 1.0F, ModOptions.player.potionHUD.potionHudTransparency);
this.drawTexturedModalRect(guiLeft, guiTop, 0, 166, 140, 32);
if (potion.hasStatusIcon()) {
final int l = potion.getStatusIconIndex();
this.drawTexturedModalRect(guiLeft + 6, guiTop + 7, 0 + l % 8 * 18, 198 + l / 8 * 18, 18, 18);
}
try {
potion.getPotion().renderInventoryEffect(guiLeft, guiTop, potion.getPotionEffect(), mc);
} catch (final Exception ex) {
;
}
final String potionText = potion.getEffectText();
final String durationText = potion.getDurationText();
if (potionText != null) {
font.drawStringWithShadow(potionText, guiLeft + 10 + 18, guiTop + 6, potion.getEffectColor());
font.drawStringWithShadow(durationText, guiLeft + 10 + 18, guiTop + 6 + 10, potion.getDurationColor());
}
guiTop += k;
}
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
use of net.minecraft.client.gui.FontRenderer in project Traverse by ProfessorProspector.
the class TraverseClient method tooltip.
@SubscribeEvent
public void tooltip(RenderTooltipEvent.Pre event) {
boolean render = false;
ItemStack stack = event.getStack();
if (stack.getItem() instanceof ItemBlock) {
if (((ItemBlock) stack.getItem()).getBlock() instanceof BlockSapling)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() instanceof BlockLeaves)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() instanceof BlockFlower)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() instanceof BlockDoublePlant)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() == Blocks.WATERLILY)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() == Blocks.VINE)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() == Blocks.TALLGRASS)
render = true;
if (((ItemBlock) stack.getItem()).getBlock() == Blocks.DEADBUSH)
render = true;
} else {
}
if (!render)
return;
;
event.setCanceled(true);
List<String> textLines = new ArrayList<>();
textLines.addAll(event.getLines());
int mouseX = event.getX();
int mouseY = event.getY();
int screenWidth = event.getScreenWidth();
int screenHeight = event.getScreenHeight();
int maxTextWidth = event.getMaxWidth();
FontRenderer font = event.getFontRenderer();
GlStateManager.disableRescaleNormal();
RenderHelper.disableStandardItemLighting();
GlStateManager.disableLighting();
GlStateManager.disableDepth();
int tooltipTextWidth = 0;
for (String textLine : textLines) {
int textLineWidth = font.getStringWidth(textLine);
if (textLineWidth > tooltipTextWidth) {
tooltipTextWidth = textLineWidth;
}
}
boolean needsWrap = false;
int titleLinesCount = 1;
int tooltipX = mouseX + 12;
if (tooltipX + tooltipTextWidth + 4 > screenWidth) {
tooltipX = mouseX - 16 - tooltipTextWidth;
if (// if the tooltip doesn't fit on the screen
tooltipX < 4) {
if (mouseX > screenWidth / 2) {
tooltipTextWidth = mouseX - 12 - 8;
} else {
tooltipTextWidth = screenWidth - 16 - mouseX;
}
needsWrap = true;
}
}
if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) {
tooltipTextWidth = maxTextWidth;
needsWrap = true;
}
if (needsWrap) {
int wrappedTooltipWidth = 0;
List<String> wrappedTextLines = new ArrayList<>();
for (int i = 0; i < textLines.size(); i++) {
String textLine = textLines.get(i);
List<String> wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth);
if (i == 0) {
titleLinesCount = wrappedLine.size();
}
for (String line : wrappedLine) {
int lineWidth = font.getStringWidth(line);
if (lineWidth > wrappedTooltipWidth) {
wrappedTooltipWidth = lineWidth;
}
wrappedTextLines.add(line);
}
}
tooltipTextWidth = wrappedTooltipWidth;
textLines = wrappedTextLines;
if (mouseX > screenWidth / 2) {
tooltipX = mouseX - 16 - tooltipTextWidth;
} else {
tooltipX = mouseX + 12;
}
}
int tooltipY = mouseY - 12;
int tooltipHeight = 8;
if (textLines.size() > 1) {
tooltipHeight += (textLines.size() - 1) * 10;
if (textLines.size() > titleLinesCount) {
// gap between title lines and next lines
tooltipHeight += 2;
}
}
if (tooltipY + tooltipHeight + 6 > screenHeight) {
tooltipY = screenHeight - tooltipHeight - 6;
}
final int zLevel = 300;
int backgroundX = tooltipX - 3;
int backgroundY = tooltipY - 3;
int backgroundWidth = tooltipTextWidth + 5;
int backgroundHeight = tooltipHeight + 6;
final int backgroundColor = 0xF0100010;
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
GuiUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor);
final int borderColorStart = new Color(0x24B528).getRGB();
final int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000;
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
GuiUtils.drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart);
GuiUtils.drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd);
int tooltipTop = tooltipY;
for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) {
String line = textLines.get(lineNumber);
font.drawStringWithShadow(line, tooltipX, tooltipY, -1);
if (lineNumber + 1 == titleLinesCount) {
tooltipY += 2;
}
tooltipY += 10;
}
MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(event.getStack(), textLines, tooltipX, tooltipTop, font, tooltipTextWidth, tooltipHeight));
GlStateManager.enableLighting();
GlStateManager.enableDepth();
RenderHelper.enableStandardItemLighting();
GlStateManager.enableRescaleNormal();
}
use of net.minecraft.client.gui.FontRenderer in project BuildCraft by BuildCraft.
the class GuiElementText method draw.
private void draw() {
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
if (centered) {
String str = text.get();
int width = fr.getStringWidth(str);
double x = getX() - width / 2;
fr.drawString(str, (float) x, (float) getY(), colour.getAsInt(), dropShadow);
} else {
fr.drawString(text.get(), (float) getX(), (float) getY(), colour.getAsInt(), dropShadow);
}
RenderUtil.setGLColorFromInt(-1);
}
use of net.minecraft.client.gui.FontRenderer in project BuildCraft by BuildCraft.
the class GuiMultiButton method drawButton.
@Override
public void drawButton(Minecraft minecraft, int x, int y) {
if (!visible) {
return;
}
FontRenderer fontrenderer = minecraft.fontRendererObj;
bindButtonTextures(minecraft);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
IMultiButtonState state = control.getButtonState();
IButtonTextureSet tex = state.getTextureSet();
int xOffset = tex.getX();
int yOffset = tex.getY();
int h = tex.getHeight();
int w = tex.getWidth();
boolean flag = x >= xPosition && y >= yPosition && x < xPosition + width && y < yPosition + h;
int hoverState = getHoverState(flag);
drawTexturedModalRect(xPosition, yPosition, xOffset, yOffset + hoverState * h, width / 2, h);
drawTexturedModalRect(xPosition + width / 2, yPosition, xOffset + w - width / 2, yOffset + hoverState * h, width / 2, h);
mouseDragged(minecraft, x, y);
displayString = state.getLabel();
if (!"".equals(displayString)) {
if (!enabled) {
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (h - 8) / 2, 0xffa0a0a0);
} else if (flag) {
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (h - 8) / 2, 0xffffa0);
} else {
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (h - 8) / 2, 0xe0e0e0);
}
}
}
use of net.minecraft.client.gui.FontRenderer in project BuildCraft by BuildCraft.
the class GuidePartItem method drawItemStack.
protected void drawItemStack(ItemStack stack, int x, int y) {
if (stack != null && !stack.isEmpty()) {
GlStateManager.color(1, 1, 1);
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
gui.mc.getRenderItem().renderItemIntoGUI(stack, x, y);
gui.mc.getRenderItem().renderItemOverlays(fr, stack, x, y);
if (STACK_RECT.offset(x, y).contains(gui.mouse)) {
gui.tooltipStack = stack;
}
GlStateManager.color(1, 1, 1);
}
}
Aggregations