Java Code Examples for net.minecraft.client.gui.FontRenderer#getStringWidth()

The following examples show how to use net.minecraft.client.gui.FontRenderer#getStringWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GuiComponentTextButton.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void renderContents(int offsetX, int offsetY, int mouseX, int mouseY, boolean pressed) {
	final FontRenderer fontRenderer = parent.getFontRenderer();
	int textWidth = fontRenderer.getStringWidth(text);
	int offX = ((width - textWidth) / 2) + 1;
	int offY = 3;
	if (buttonEnabled && pressed) {
		offY++;
		offX++;
	}
	fontRenderer.drawString(text, offsetX + x + offX, offsetY + y + offY, 4210752);
}
 
Example 2
Source File: SimpleTextWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void updateSize() {
    FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
    int stringWidth = fontRenderer.getStringWidth(lastText);
    setSize(new Size(stringWidth, fontRenderer.FONT_HEIGHT));
    if (uiAccess != null) {
        uiAccess.notifySizeChange();
    }
}
 
Example 3
Source File: AdvancedTextWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected ITextComponent getTextUnderMouse(int mouseX, int mouseY) {
    FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
    Position position = getPosition();
    int selectedLine = (mouseY - position.y) / (fontRenderer.FONT_HEIGHT + 2);
    if (mouseX >= position.x && selectedLine >= 0 && selectedLine < displayText.size()) {
        ITextComponent selectedComponent = displayText.get(selectedLine);
        int mouseOffset = mouseX - position.x;
        int currentOffset = 0;
        for (ITextComponent lineComponent : selectedComponent) {
            currentOffset += fontRenderer.getStringWidth(lineComponent.getUnformattedComponentText());
            if (currentOffset >= mouseOffset) {
                return lineComponent;
            }
        }
    }
    return null;
}
 
Example 4
Source File: Widget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
protected void drawStringSized(String text, double x, double y, int color, boolean dropShadow, float scale, boolean center) {
    GlStateManager.pushMatrix();
    FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
    double scaledTextWidth = center ? fontRenderer.getStringWidth(text) * scale : 0.0;
    GlStateManager.translate(x + scaledTextWidth / 2.0, y, 0.0f);
    GlStateManager.scale(scale, scale, scale);
    fontRenderer.drawString(text, 0, 0, color, dropShadow);
    GlStateManager.popMatrix();
}
 
Example 5
Source File: MachineRecipe.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void drawInfo(Minecraft minecraft, int recipeWidth,
		int recipeHeight, int mouseX, int mouseY) {
	
		String powerString = String.format("Power: %d RF/t", energy);
		FontRenderer fontRendererObj = minecraft.fontRenderer;
		int stringWidth = fontRendererObj.getStringWidth(powerString);
		fontRendererObj.drawString(powerString, 0, 55, Color.black.getRGB());
		
		String timeString = String.format("Time: %d s", time/20);
		stringWidth = fontRendererObj.getStringWidth(powerString);
		fontRendererObj.drawString(timeString, recipeWidth - 55, 55, Color.black.getRGB());
}
 
Example 6
Source File: AbstractRenderer.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
void renderText(OffsetPoint offsetPoint, String... texts) {
    FontRenderer fontRenderer = Minecraft.getInstance().fontRenderer;

    RenderHelper.beforeRenderFont(offsetPoint);
    float top = -(fontRenderer.FONT_HEIGHT * texts.length) / 2f;
    for (String text : texts) {
        float left = fontRenderer.getStringWidth(text) / 2f;
        fontRenderer.drawString(text, -left, top, -1);
        top += fontRenderer.FONT_HEIGHT;
    }
    RenderHelper.afterRenderFont();
}
 
Example 7
Source File: TileEntityLiftLever.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public void renderPilotText(FontRenderer renderer, ScaledResolution gameResolution) {
    // White text.
    int color = 0xFFFFFF;
    // Extra spaces so the that the text is closer to the middle when rendered.
    String message = "Target Altitude:    ";
    int i = gameResolution.getScaledWidth();
    int height = gameResolution.getScaledHeight() - 35;
    float middle = (float) (i / 2 - renderer.getStringWidth(message) / 2);
    message = "Target Altitude: " + Math.round(targetYPosition);
    renderer.drawStringWithShadow(message, middle, height, color);
}
 
Example 8
Source File: AboveHeadRenderer.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void renderName(RenderPlayerEvent event, LevelheadTag tag, EntityPlayer player, double x, double y, double z) {
    FontRenderer fontrenderer = event.getRenderManager().getFontRenderer();
    float f = (float) (1.6F * Levelhead.getInstance().getDisplayManager().getMasterConfig().getFontSize());
    float f1 = 0.016666668F * f;
    GlStateManager.pushMatrix();
    GlStateManager.translate((float) x + 0.0F, (float) y + player.height + 0.5F, (float) z);
    GL11.glNormal3f(0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(-event.getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(event.getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
    GlStateManager.scale(-f1, -f1, f1);
    GlStateManager.disableLighting();
    GlStateManager.depthMask(false);
    GlStateManager.disableDepth();
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
    Tessellator tessellator = Tessellator.getInstance();
    WorldRenderer worldrenderer = tessellator.getWorldRenderer();
    int i = 0;

    int j = fontrenderer.getStringWidth(tag.getString()) / 2;
    GlStateManager.disableTexture2D();
    worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
    worldrenderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    worldrenderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    worldrenderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    worldrenderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    tessellator.draw();
    GlStateManager.enableTexture2D();

    renderString(fontrenderer, tag);

    GlStateManager.enableLighting();
    GlStateManager.disableBlend();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.popMatrix();
}
 
Example 9
Source File: ComponentRenderer.java    From AgriCraft with MIT License 5 votes vote down vote up
public static void renderComponentText(AgriGuiWrapper gui, GuiComponent<String> component, Color color, boolean shadow) {
    final FontRenderer fontRenderer = gui.getFontRenderer();

    String text = AgriCore.getTranslator().translate(component.getComponent());
    text = GuiHelper.splitInLines(gui.getFontRenderer(), text, 95, component.getScale());
    List<String> write = GuiHelper.getLinesFromData(text);
    float vertOffset = component.isCenteredVertically() ? (component.getBounds().height - write.size() * fontRenderer.FONT_HEIGHT) / 2f : 0;
    for (int i = 0; i < write.size(); i++) {
        String line = write.get(i);
        float xOffset = component.isCenteredHorizontally() ? (component.getBounds().width - fontRenderer.getStringWidth(line)) / 2f : 0;
        float yOffset = vertOffset + i * fontRenderer.FONT_HEIGHT;
        fontRenderer.drawString(line, xOffset, yOffset, color.hashCode(), shadow);
    }
}
 
Example 10
Source File: MultiblockInfoRecipeWrapper.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void drawText(Minecraft minecraft, int recipeWidth) {
    String localizedName = I18n.format(infoPage.getController().getMetaFullName());
    GTUtility.drawCenteredSizedText(recipeWidth / 2, 0, localizedName, 0x333333, 1.3);
    FontRenderer fontRenderer = minecraft.fontRenderer;
    List<String> lines = Arrays.stream(infoPage.getDescription())
        .flatMap(s -> fontRenderer.listFormattedStringToWidth(s, recipeWidth).stream())
        .collect(Collectors.toList());
    for (int i = 0; i < lines.size(); i++) {
        String lineText = lines.get(i);
        int x = (recipeWidth - fontRenderer.getStringWidth(lineText)) / 2;
        int y = 8 + i * fontRenderer.FONT_HEIGHT;
        fontRenderer.drawString(lineText, x, y, 0x333333);
    }
    GlStateManager.color(1.0f, 1.0f, 1.0f);
}
 
Example 11
Source File: TESRBarrel.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void renderText(String text, double x, double y, double z, EnumFacing side, EnumFacing barrelFront)
{
    FontRenderer fontRenderer = this.mc.fontRenderer;
    int strLenHalved = fontRenderer.getStringWidth(text) / 2;

    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);

    if (side == EnumFacing.UP || side == EnumFacing.DOWN)
    {
        GlStateManager.rotate(LABEL_ROT_SIDE_Y[barrelFront.getIndex()], 0, 1, 0);
        GlStateManager.rotate(90f * side.getYOffset(), 1, 0, 0);
    }
    else
    {
        GlStateManager.rotate(LABEL_ROT_SIDE_Y[side.getIndex()], 0, 1, 0);
    }

    GlStateManager.translate(0, 0.48, 0);
    GlStateManager.scale(-0.01F, -0.01F, 0.01F);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

    GlStateManager.disableLighting();
    GlStateManager.enablePolygonOffset();
    GlStateManager.depthMask(false);
    GlStateManager.enableBlend();
    GlStateManager.doPolygonOffset(-1, -20);

    this.getFontRenderer().drawString(text, -strLenHalved, 0, 0xFFFFFFFF);

    GlStateManager.disableBlend();
    GlStateManager.depthMask(true);
    GlStateManager.disablePolygonOffset();
    GlStateManager.enableLighting();

    GlStateManager.popMatrix();
}
 
Example 12
Source File: BlockListEditButton.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
public BlockListEditButton(BlockListSetting setting)
{
	this.setting = setting;
	
	FontRenderer fr = WMinecraft.getFontRenderer();
	buttonWidth = fr.getStringWidth("Edit...");
	
	setWidth(getDefaultWidth());
	setHeight(getDefaultHeight());
}
 
Example 13
Source File: GuiButtonGlyph.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
protected void drawButtonForeground(boolean isHighlighted, float partialTicks) {
	String text = getText();
	FontRenderer fontRenderer = getFontRenderer();
	
	int contentWidth = getGlyphWidth();
	if (!text.isEmpty()) {
		int textWidth = fontRenderer.getStringWidth(text);
		int maxTextWidth = getWidth() - getGlyphWidth() - GLYPH_SPACING - MIN_TEXT_PADDING;
		if ((textWidth > maxTextWidth) && (textWidth > ELLIPSIS_WIDTH)) {
			text = fontRenderer.trimStringToWidth(text, maxTextWidth - ELLIPSIS_WIDTH).trim() + ELLIPSIS;
			textWidth = fontRenderer.getStringWidth(text);
		}
		contentWidth += GLYPH_SPACING + textWidth;
	}
	
	float scale = getGlyphScale();
	GlStateManager.pushMatrix();
	GlStateManager.scale(scale, scale, 1.0F);
	fontRenderer.drawStringWithShadow(getGlyph(),
		(int)((getWidth() - contentWidth) / 2 / scale),
		(int)((((getHeight() - 8) / scale / 2) - 1) / scale), getTextColor(isHighlighted));
	GlStateManager.popMatrix();
	
	if (!text.isEmpty())
		fontRenderer.drawStringWithShadow(text,
			(getWidth() - contentWidth) / 2 + getGlyphWidth() + GLYPH_SPACING,
			(getHeight() - 8) / 2, getTextColor(isHighlighted));
}
 
Example 14
Source File: RenderCodex.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String[] getSpellStructureLines(ItemStack stack) {
	NBTTagList moduleList = NBTHelper.getList(stack, NBTConstants.NBT.SPELL, net.minecraftforge.common.util.Constants.NBT.TAG_STRING);
	if (moduleList == null) return new String[0];

	List<List<ModuleInstance>> spellModules = SpellUtils.deserializeModuleList(moduleList);
	spellModules = SpellUtils.getEssentialModules(spellModules);
	int page = NBTHelper.getInt(stack, "page", 0);

	FontRenderer fr = Minecraft.getMinecraft().fontRenderer;

	int widthOfSpace = fr.getStringWidth(" ");
	StringBuilder builder = new StringBuilder("Spell Structure:\n");
	for (List<ModuleInstance> spellModuleList : spellModules) {
		String margin = null;
		for (ModuleInstance module : spellModuleList) {
			if (margin == null) {
				margin = " - ";
				builder.append(margin).append(module.getReadableName()).append("\n");
			} else {
				int realLength = fr.getStringWidth(margin);
				int nbOfSpace = MathHelper.clamp(realLength / widthOfSpace, 0, 17);
				margin = StringUtils.repeat(" ", nbOfSpace) + "|_ ";
				builder.append(margin).append(module.getReadableName()).append("\n");

				if (nbOfSpace >= 16) {
					builder.append("   ________________|")
							.append("\n");
					margin = "   ";
				}
			}
		}
	}

	String[] lines = builder.toString().split("\n");
	StringBuilder pageChunk = new StringBuilder();
	int count = 0;
	int currentPage = 0;
	for (String line : lines) {
		pageChunk.append(line).append("\n");

		if (++count >= 16) {
			count = 0;

			if (currentPage >= page) return pageChunk.toString().split("\n");
			pageChunk = new StringBuilder();
		}
	}

	return pageChunk.toString().split("\n");
}
 
Example 15
Source File: MoCRenderShark.java    From mocreaturesdev with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void doRenderLiving(EntityLiving entityliving, double d, double d1, double d2, float f, float f1)
{
    MoCEntityShark entityshark = (MoCEntityShark) entityliving;
    super.doRenderLiving(entityshark, d, d1, d2, f, f1);
    boolean flag = MoCreatures.proxy.getDisplayPetName() && !(entityshark.getName()).isEmpty();
    boolean flag1 = MoCreatures.proxy.getDisplayPetHealth();
    boolean flag2 = MoCreatures.proxy.getDisplayPetIcons();
    if (entityshark.renderName())
    {
        float f2 = 1.6F;
        float f3 = 0.01666667F * f2;
        float f4 = entityshark.getDistanceToEntity(renderManager.livingPlayer);
        if (f4 < 16F)
        {
            String s = "";
            s = (new StringBuilder()).append(s).append(entityshark.getName()).toString();
            float f5 = 0.1F;
            FontRenderer fontrenderer = getFontRendererFromRenderManager();
            GL11.glPushMatrix();
            GL11.glTranslatef((float) d + 0.0F, (float) d1 + f5, (float) d2);
            GL11.glNormal3f(0.0F, 1.0F, 0.0F);
            GL11.glRotatef(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
            GL11.glScalef(-f3, -f3, f3);
            GL11.glDisable(2896 /* GL_LIGHTING */);
            Tessellator tessellator = Tessellator.instance;
            byte byte0 = -50;
            if (flag1)
            {
                GL11.glDisable(3553 /* GL_TEXTURE_2D */);
                if (!flag)
                {
                    byte0 += 8;
                }
                tessellator.startDrawingQuads();
                // might break SSP
                float f6 = entityshark.getHealth();
                float f7 = entityshark.getMaxHealth();
                float f8 = f6 / f7;
                float f9 = 40F * f8;
                tessellator.setColorRGBA_F(0.7F, 0.0F, 0.0F, 1.0F);
                tessellator.addVertex(-20F + f9, -10 + byte0, 0.0D);
                tessellator.addVertex(-20F + f9, -6 + byte0, 0.0D);
                tessellator.addVertex(20D, -6 + byte0, 0.0D);
                tessellator.addVertex(20D, -10 + byte0, 0.0D);
                tessellator.setColorRGBA_F(0.0F, 0.7F, 0.0F, 1.0F);
                tessellator.addVertex(-20D, -10 + byte0, 0.0D);
                tessellator.addVertex(-20D, -6 + byte0, 0.0D);
                tessellator.addVertex(f9 - 20F, -6 + byte0, 0.0D);
                tessellator.addVertex(f9 - 20F, -10 + byte0, 0.0D);
                tessellator.draw();
                GL11.glEnable(3553 /* GL_TEXTURE_2D */);
            }
            if (flag)
            {
                GL11.glDepthMask(false);
                GL11.glDisable(2929 /* GL_DEPTH_TEST */);
                GL11.glEnable(3042 /* GL_BLEND */);
                GL11.glBlendFunc(770, 771);
                GL11.glDisable(3553 /* GL_TEXTURE_2D */);
                tessellator.startDrawingQuads();
                int i = fontrenderer.getStringWidth(s) / 2;
                tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.25F);
                tessellator.addVertex(-i - 1, -1 + byte0, 0.0D);
                tessellator.addVertex(-i - 1, 8 + byte0, 0.0D);
                tessellator.addVertex(i + 1, 8 + byte0, 0.0D);
                tessellator.addVertex(i + 1, -1 + byte0, 0.0D);
                tessellator.draw();
                GL11.glEnable(3553 /* GL_TEXTURE_2D */);
                fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, byte0, 0x20ffffff);
                GL11.glEnable(2929 /* GL_DEPTH_TEST */);
                GL11.glDepthMask(true);
                fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, byte0, -1);
                GL11.glDisable(3042 /* GL_BLEND */);
                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            }
            GL11.glEnable(2896 /* GL_LIGHTING */);
            GL11.glPopMatrix();
        }
    }
}
 
Example 16
Source File: WidgetFluidModes.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
protected void drawHoveringText(List list, int x, int y, FontRenderer fontrenderer)
{
	if (!list.isEmpty())
	{
		GL11.glDisable(GL12.GL_RESCALE_NORMAL);
		RenderHelper.disableStandardItemLighting();
		GL11.glDisable(GL11.GL_LIGHTING);
		GL11.glDisable(GL11.GL_DEPTH_TEST);
		int k = 0;
		Iterator iterator = list.iterator();

		while (iterator.hasNext())
		{
			String s = (String) iterator.next();
			int l = fontrenderer.getStringWidth(s);

			if (l > k)
			{
				k = l;
			}
		}

		int i1 = x + 12;
		int j1 = y - 12;
		int k1 = 8;

		if (list.size() > 1)
		{
			k1 += 2 + (list.size() - 1) * 10;
		}

		this.zLevel = 300.0F;
		int l1 = -267386864;
		this.drawGradientRect(i1 - 3, j1 - 4, i1 + k + 3, j1 - 3, l1, l1);
		this.drawGradientRect(i1 - 3, j1 + k1 + 3, i1 + k + 3, j1 + k1 + 4, l1, l1);
		this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 + k1 + 3, l1, l1);
		this.drawGradientRect(i1 - 4, j1 - 3, i1 - 3, j1 + k1 + 3, l1, l1);
		this.drawGradientRect(i1 + k + 3, j1 - 3, i1 + k + 4, j1 + k1 + 3, l1, l1);
		int i2 = 1347420415;
		int j2 = (i2 & 16711422) >> 1 | i2 & -16777216;
		this.drawGradientRect(i1 - 3, j1 - 3 + 1, i1 - 3 + 1, j1 + k1 + 3 - 1, i2, j2);
		this.drawGradientRect(i1 + k + 2, j1 - 3 + 1, i1 + k + 3, j1 + k1 + 3 - 1, i2, j2);
		this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 - 3 + 1, i2, i2);
		this.drawGradientRect(i1 - 3, j1 + k1 + 2, i1 + k + 3, j1 + k1 + 3, j2, j2);

		for (int k2 = 0; k2 < list.size(); ++k2)
		{
			String s1 = (String) list.get(k2);
			fontrenderer.drawStringWithShadow(s1, i1, j1, -1);

			if (k2 == 0)
			{
				j1 += 2;
			}

			j1 += 10;
		}

		this.zLevel = 0.0F;
		GL11.glEnable(GL11.GL_LIGHTING);
		GL11.glEnable(GL11.GL_DEPTH_TEST);
		RenderHelper.enableStandardItemLighting();
		GL11.glEnable(GL12.GL_RESCALE_NORMAL);
	}
}
 
Example 17
Source File: GuiSidebar.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void drawSidebar(ScoreObjective sidebar, ScaledResolution res) {
    if (!enabled) {
        return;
    }
    FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
    Scoreboard scoreboard = sidebar.getScoreboard();
    List<Score> scores = new ArrayList<>();
    sidebarWidth = fr.getStringWidth(sidebar.getDisplayName());

    for (Score score : scoreboard.getSortedScores(sidebar)) {
        String name = score.getPlayerName();
        if (scores.size() < 15 && name != null && !name.startsWith("#")) {
            Team team = scoreboard.getPlayersTeam(name);
            String s2 = redNumbers ? (": " + EnumChatFormatting.RED + score.getScorePoints()) : "";
            String str = ScorePlayerTeam.formatPlayerName(team, name) + s2;
            sidebarWidth = Math.max(sidebarWidth, fr.getStringWidth(str));
            scores.add(score);
        }
    }

    sidebarHeight = scores.size() * fr.FONT_HEIGHT;
    sidebarX = res.getScaledWidth() - sidebarWidth - 3 + offsetX;
    sidebarY = res.getScaledHeight() / 2 + sidebarHeight / 3 + offsetY;
    int scalePointX = sidebarX + sidebarWidth;
    int scalePointY = sidebarY - sidebarHeight / 2;
    float mscale = scale - 1.0f;

    GlStateManager.translate(-scalePointX * mscale, -scalePointY * mscale, 0.0f);
    GlStateManager.scale(scale, scale, 1.0F);

    int index = 0;
    for (Score score2 : scores) {
        ++index;
        ScorePlayerTeam team2 = scoreboard.getPlayersTeam(score2.getPlayerName());
        String s3 = ScorePlayerTeam.formatPlayerName(team2, score2.getPlayerName());
        String s4 = EnumChatFormatting.RED + "" + score2.getScorePoints();

        if (!redNumbers) {
            s4 = "";
        }

        int scoreX = sidebarX + sidebarWidth + 1;
        int scoreY = sidebarY - index * fr.FONT_HEIGHT;
        drawRect(sidebarX - 2, scoreY, scoreX, scoreY + fr.FONT_HEIGHT, getColor(false, true));
        drawString(s3, sidebarX, scoreY, getColor(false, false));
        drawString(s4, scoreX - fr.getStringWidth(s4), scoreY, getColor(false, false));
        if (index == scores.size()) {
            String s5 = sidebar.getDisplayName();
            drawRect(sidebarX - 2, scoreY - fr.FONT_HEIGHT - 1, scoreX, scoreY - 1, getColor(true, true));
            drawRect(sidebarX - 2, scoreY - 1, scoreX, scoreY, getColor(false, true));

            drawString(s5, sidebarX + (sidebarWidth - fr.getStringWidth(s5)) / 2, scoreY - fr.FONT_HEIGHT,
                chromaEnabled ? getColor(false, false) : 553648127);
        }
    }

    GlStateManager.scale(1.0F / scale, 1.0F / scale, 1.0F);
    GlStateManager.translate(scalePointX * mscale, scalePointY * mscale, 0.0f);
}
 
Example 18
Source File: GuiCustomButton.java    From Custom-Main-Menu with MIT License 4 votes vote down vote up
protected void drawHoveringText(Minecraft mc, List textLines, int x, int y, FontRenderer font)
{
	if (!textLines.isEmpty())
	{
		int width = mc.currentScreen.width;
		int height = mc.currentScreen.height;
		GlStateManager.disableDepth();
		int k = 0;
		Iterator iterator = textLines.iterator();

		while (iterator.hasNext())
		{
			String s = (String) iterator.next();
			int l = font.getStringWidth(s);

			if (l > k)
			{
				k = l;
			}
		}

		int j2 = x + 12;
		int k2 = y - 12;
		int i1 = 8;

		if (textLines.size() > 1)
		{
			i1 += 2 + (textLines.size() - 1) * 10;
		}

		if (j2 + k > width)
		{
			j2 -= 28 + k;
		}

		if (k2 + i1 + 6 > height)
		{
			k2 = this.height - i1 - 6;
		}

		this.zLevel = 300.0F;
		int j1 = -267386864;
		this.drawGradientRect(j2 - 3, k2 - 4, j2 + k + 3, k2 - 3, j1, j1);
		this.drawGradientRect(j2 - 3, k2 + i1 + 3, j2 + k + 3, k2 + i1 + 4, j1, j1);
		this.drawGradientRect(j2 - 3, k2 - 3, j2 + k + 3, k2 + i1 + 3, j1, j1);
		this.drawGradientRect(j2 - 4, k2 - 3, j2 - 3, k2 + i1 + 3, j1, j1);
		this.drawGradientRect(j2 + k + 3, k2 - 3, j2 + k + 4, k2 + i1 + 3, j1, j1);
		int k1 = 1347420415;
		int l1 = (k1 & 16711422) >> 1 | k1 & -16777216;
		this.drawGradientRect(j2 - 3, k2 - 3 + 1, j2 - 3 + 1, k2 + i1 + 3 - 1, k1, l1);
		this.drawGradientRect(j2 + k + 2, k2 - 3 + 1, j2 + k + 3, k2 + i1 + 3 - 1, k1, l1);
		this.drawGradientRect(j2 - 3, k2 - 3, j2 + k + 3, k2 - 3 + 1, k1, k1);
		this.drawGradientRect(j2 - 3, k2 + i1 + 2, j2 + k + 3, k2 + i1 + 3, l1, l1);

		for (int i2 = 0; i2 < textLines.size(); ++i2)
		{
			String s1 = (String) textLines.get(i2);
			font.drawStringWithShadow(s1, j2, k2, -1);

			if (i2 == 0)
			{
				k2 += 2;
			}

			k2 += 10;
		}

		this.zLevel = 0.0F;
		GlStateManager.enableDepth();
	}
}
 
Example 19
Source File: AbstractFluidWidget.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
protected void drawHoveringText(List list, int x, int y, FontRenderer fontrenderer)
{
	if (!list.isEmpty())
	{
		GL11.glDisable(GL12.GL_RESCALE_NORMAL);
		RenderHelper.disableStandardItemLighting();
		GL11.glDisable(GL11.GL_LIGHTING);
		GL11.glDisable(GL11.GL_DEPTH_TEST);
		int k = 0;

		for (Object string : list)
		{
			String s = (String) string;
			int l = fontrenderer.getStringWidth(s);

			if (l > k)
			{
				k = l;
			}
		}

		int i1 = x + 12;
		int j1 = y - 12;
		int k1 = 8;

		if (list.size() > 1)
		{
			k1 += 2 + (list.size() - 1) * 10;
		}

		this.zLevel = 300.0F;
		int l1 = -267386864;
		this.drawGradientRect(i1 - 3, j1 - 4, i1 + k + 3, j1 - 3, l1, l1);
		this.drawGradientRect(i1 - 3, j1 + k1 + 3, i1 + k + 3, j1 + k1 + 4, l1, l1);
		this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 + k1 + 3, l1, l1);
		this.drawGradientRect(i1 - 4, j1 - 3, i1 - 3, j1 + k1 + 3, l1, l1);
		this.drawGradientRect(i1 + k + 3, j1 - 3, i1 + k + 4, j1 + k1 + 3, l1, l1);
		int i2 = 1347420415;
		int j2 = (i2 & 16711422) >> 1 | i2 & -16777216;
		this.drawGradientRect(i1 - 3, j1 - 3 + 1, i1 - 3 + 1, j1 + k1 + 3 - 1, i2, j2);
		this.drawGradientRect(i1 + k + 2, j1 - 3 + 1, i1 + k + 3, j1 + k1 + 3 - 1, i2, j2);
		this.drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 - 3 + 1, i2, i2);
		this.drawGradientRect(i1 - 3, j1 + k1 + 2, i1 + k + 3, j1 + k1 + 3, j2, j2);

		for (int k2 = 0; k2 < list.size(); ++k2)
		{
			String s1 = (String) list.get(k2);
			fontrenderer.drawStringWithShadow(s1, i1, j1, -1);

			if (k2 == 0)
			{
				j1 += 2;
			}

			j1 += 10;
		}

		this.zLevel = 0.0F;
		GL11.glEnable(GL11.GL_LIGHTING);
		GL11.glEnable(GL11.GL_DEPTH_TEST);
		RenderHelper.enableStandardItemLighting();
		GL11.glEnable(GL12.GL_RESCALE_NORMAL);
	}
}
 
Example 20
Source File: RenderEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void renderLabel(String text, double x, double y, double z, float angleH, float angleV)
{
    boolean flag = false; // sneaking
    FontRenderer fontrenderer = this.mc.fontRenderer;

    GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F);
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    GlStateManager.glNormal3f(0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(-angleH, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(-angleV, 1.0F, 0.0F, 0.0F);
    GlStateManager.scale(-0.025F, -0.025F, 0.025F);
    GlStateManager.disableLighting();
    GlStateManager.depthMask(false);
    GlStateManager.disableDepth();

    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
            GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    GlStateManager.disableTexture2D();

    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder vertexbuffer = tessellator.getBuffer();
    int strLenHalved = fontrenderer.getStringWidth(text) / 2;

    vertexbuffer.begin(7, DefaultVertexFormats.POSITION_COLOR);
    vertexbuffer.pos(-strLenHalved - 1, -1, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    vertexbuffer.pos(-strLenHalved - 1,  8, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    vertexbuffer.pos( strLenHalved + 1,  8, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    vertexbuffer.pos( strLenHalved + 1, -1, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    tessellator.draw();

    GlStateManager.enableTexture2D();

    fontrenderer.drawString(text, -strLenHalved, 0, 0x20FFFFFF);
    GlStateManager.enableDepth();

    GlStateManager.depthMask(true);
    fontrenderer.drawString(text, -strLenHalved, 0, flag ? 0x20FFFFFF : 0xFFFFFFFF);

    GlStateManager.disableBlend();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.popMatrix();
}