Java Code Examples for net.minecraft.client.font.TextRenderer#getWidth()
The following examples show how to use
net.minecraft.client.font.TextRenderer#getWidth() .
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: HackListHUD.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private void drawString(MatrixStack matrixStack, String s) { TextRenderer tr = WurstClient.MC.textRenderer; int posX; if(otf.getPosition() == Position.LEFT) posX = 2; else { int screenWidth = WurstClient.MC.getWindow().getScaledWidth(); int stringWidth = tr.getWidth(s); posX = screenWidth - stringWidth - 2; } tr.draw(matrixStack, s, posX + 1, posY + 1, 0xff000000); tr.draw(matrixStack, s, posX, posY, textColor | 0xff000000); posY += 9; }
Example 2
Source File: HackListHUD.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private void drawWithOffset(MatrixStack matrixStack, HackListEntry e, float partialTicks) { TextRenderer tr = WurstClient.MC.textRenderer; String s = e.hack.getRenderName(); float offset = e.offset * partialTicks + e.prevOffset * (1 - partialTicks); float posX; if(otf.getPosition() == Position.LEFT) posX = 2 - 5 * offset; else { int screenWidth = WurstClient.MC.getWindow().getScaledWidth(); int stringWidth = tr.getWidth(s); posX = screenWidth - stringWidth - 2 + 5 * offset; } int alpha = (int)(255 * (1 - offset / 4)) << 24; tr.draw(matrixStack, s, posX + 1, posY + 1, 0x04000000 | alpha); tr.draw(matrixStack, s, posX, posY, textColor | alpha); posY += 9; }
Example 3
Source File: WTextField.java From LibGui with MIT License | 6 votes |
/** * From an X offset past the left edge of a TextRenderer.draw, finds out what the closest caret * position (division between letters) is. * @param s * @param x * @return */ @Environment(EnvType.CLIENT) public static int getCaretPos(String s, int x) { if (x<=0) return 0; TextRenderer font = MinecraftClient.getInstance().textRenderer; int lastAdvance = 0; for(int i=0; i<s.length()-1; i++) { int advance = font.getWidth(s.substring(0,i+1)); int charAdvance = advance-lastAdvance; if (x<advance + (charAdvance/2)) return i+1; lastAdvance = advance; } return s.length(); }
Example 4
Source File: SliderComponent.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private void drawNameAndValue(MatrixStack matrixStack, int x1, int x2, int y1, boolean renderAsDisabled) { GL11.glColor4f(1, 1, 1, 1); GL11.glEnable(GL11.GL_TEXTURE_2D); TextRenderer tr = MC.textRenderer; String name = setting.getName(); String value = setting.getValueString(); int valueWidth = tr.getWidth(value); int color = renderAsDisabled ? 0xAAAAAA : 0xF0F0F0; tr.draw(matrixStack, name, x1, y1 + 2, color); tr.draw(matrixStack, value, x2 - valueWidth, y1 + 2, color); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); }
Example 5
Source File: FeatureButton.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
private void drawName(MatrixStack matrixStack, int x1, int x3, int y1) { GL11.glColor4f(1, 1, 1, 1); GL11.glEnable(GL11.GL_TEXTURE_2D); TextRenderer tr = MC.textRenderer; String name = feature.getName(); int nameWidth = tr.getWidth(name); int tx = x1 + (x3 - x1 - nameWidth) / 2; int ty = y1 + 2; tr.draw(matrixStack, name, tx, ty, 0xF0F0F0); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); }
Example 6
Source File: WTextField.java From LibGui with MIT License | 5 votes |
/** * From a caret position, finds out what the x-offset to draw the caret is. * @param s * @param pos * @return */ @Environment(EnvType.CLIENT) public static int getCaretOffset(String s, int pos) { if (pos==0) return 0;//-1; TextRenderer font = MinecraftClient.getInstance().textRenderer; int ofs = font.getWidth(s.substring(0, pos))+1; return ofs; //(font.isRightToLeft()) ? -ofs : ofs; }
Example 7
Source File: ItemListEditButton.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
@Override public int getDefaultWidth() { TextRenderer fr = WurstClient.MC.textRenderer; String text = setting.getName() + ": " + setting.getItemNames().size(); return fr.getWidth(text) + buttonWidth + 6; }
Example 8
Source File: ItemListEditButton.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
public ItemListEditButton(ItemListSetting setting) { this.setting = setting; TextRenderer fr = WurstClient.MC.textRenderer; buttonWidth = fr.getWidth("Edit..."); setWidth(getDefaultWidth()); setHeight(getDefaultHeight()); }
Example 9
Source File: FeatureButton.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
@Override public int getDefaultWidth() { String name = feature.getName(); TextRenderer tr = MC.textRenderer; int width = tr.getWidth(name) + 4; if(hasSettings) width += 11; return width; }
Example 10
Source File: FileComponent.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
@Override public int getDefaultWidth() { TextRenderer fr = WurstClient.MC.textRenderer; String text = setting.getName() + ": "; int buttonWidth = fr.getWidth(setting.getSelectedFileName()); return fr.getWidth(text) + buttonWidth + 6; }
Example 11
Source File: FileComponent.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
@Override public void handleMouseClick(double mouseX, double mouseY, int mouseButton) { if(mouseButton != 0) return; TextRenderer fr = WurstClient.MC.textRenderer; int buttonWidth = fr.getWidth(setting.getSelectedFileName()); if(mouseX < getX() + getWidth() - buttonWidth - 4) return; WurstClient.MC.openScreen( new SelectFileScreen(WurstClient.MC.currentScreen, setting)); }
Example 12
Source File: SliderComponent.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
@Override public int getDefaultWidth() { TextRenderer tr = MC.textRenderer; int nameWitdh = tr.getWidth(setting.getName()); int valueWidth = tr.getWidth(setting.getValueString()); return nameWitdh + valueWidth + 6; }
Example 13
Source File: BlockListEditButton.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
@Override public int getDefaultWidth() { TextRenderer fr = WurstClient.MC.textRenderer; String text = setting.getName() + ": " + setting.getBlockNames().size(); return fr.getWidth(text) + buttonWidth + 6; }
Example 14
Source File: BlockListEditButton.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
public BlockListEditButton(BlockListSetting setting) { this.setting = setting; TextRenderer fr = WurstClient.MC.textRenderer; buttonWidth = fr.getWidth("Edit..."); setWidth(getDefaultWidth()); setHeight(getDefaultHeight()); }
Example 15
Source File: BlockComponent.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
@Override public int getDefaultWidth() { TextRenderer tr = WurstClient.MC.textRenderer; String text = setting.getName() + ":"; return tr.getWidth(text) + BLOCK_WITDH + 4; }
Example 16
Source File: FileComponent.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
@Override public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { ClickGui gui = WurstClient.INSTANCE.getGui(); float[] bgColor = gui.getBgColor(); float[] acColor = gui.getAcColor(); float opacity = gui.getOpacity(); TextRenderer fr = WurstClient.MC.textRenderer; int buttonWidth = fr.getWidth(setting.getSelectedFileName()); int x1 = getX(); int x2 = x1 + getWidth(); int x3 = x2 - buttonWidth - 4; int y1 = getY(); int y2 = y1 + getHeight(); int scroll = getParent().isScrollingEnabled() ? getParent().getScrollOffset() : 0; boolean hovering = mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2 && mouseY >= -scroll && mouseY < getParent().getHeight() - 13 - scroll; boolean hText = hovering && mouseX < x3; boolean hBox = hovering && mouseX >= x3; // tooltip if(hText) gui.setTooltip(setting.getDescription()); else if(hBox) { String tooltip = "\u00a7e[left-click]\u00a7r to select file"; gui.setTooltip(tooltip); } // background GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], opacity); GL11.glBegin(GL11.GL_QUADS); GL11.glVertex2i(x1, y1); GL11.glVertex2i(x1, y2); GL11.glVertex2i(x3, y2); GL11.glVertex2i(x3, y1); GL11.glEnd(); // box GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], hBox ? opacity * 1.5F : opacity); GL11.glBegin(GL11.GL_QUADS); GL11.glVertex2i(x3, y1); GL11.glVertex2i(x3, y2); GL11.glVertex2i(x2, y2); GL11.glVertex2i(x2, y1); GL11.glEnd(); GL11.glColor4f(acColor[0], acColor[1], acColor[2], 0.5F); GL11.glBegin(GL11.GL_LINE_LOOP); GL11.glVertex2i(x3, y1); GL11.glVertex2i(x3, y2); GL11.glVertex2i(x2, y2); GL11.glVertex2i(x2, y1); GL11.glEnd(); // setting name GL11.glColor4f(1, 1, 1, 1); GL11.glEnable(GL11.GL_TEXTURE_2D); String text = setting.getName() + ": "; fr.draw(matrixStack, text, x1, y1 + 2, 0xf0f0f0); fr.draw(matrixStack, setting.getSelectedFileName(), x3 + 2, y1 + 2, 0xf0f0f0); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); }
Example 17
Source File: EntityRendererMixin.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
/** * Copy of renderLabelIfPresent() since calling the original would result in * an infinite loop. Also makes it easier to modify. */ protected void wurstRenderLabelIfPresent(T entity, Text text, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) { double d = this.dispatcher.getSquaredDistanceToCamera(entity); if(d > 4096) return; NameTagsHack nameTagsHack = WurstClient.INSTANCE.getHax().nameTagsHack; boolean bl = !entity.isSneaky() || nameTagsHack.isEnabled(); float f = entity.getHeight() + 0.5F; int j = "deadmau5".equals(text.getString()) ? -10 : 0; matrixStack.push(); matrixStack.translate(0.0D, f, 0.0D); matrixStack.multiply(this.dispatcher.getRotation()); float scale = 0.025F; if(nameTagsHack.isEnabled()) { double distance = WurstClient.MC.player.distanceTo(entity); if(distance > 10) scale *= distance / 10; } matrixStack.scale(-scale, -scale, scale); Matrix4f matrix4f = matrixStack.peek().getModel(); float g = WurstClient.MC.options.getTextBackgroundOpacity(0.25F); int k = (int)(g * 255.0F) << 24; TextRenderer textRenderer = this.getFontRenderer(); float h = -textRenderer.getWidth(text) / 2; textRenderer.draw(text, h, j, 553648127, false, matrix4f, vertexConsumerProvider, bl, k, i); if(bl) textRenderer.draw(text, h, j, -1, false, matrix4f, vertexConsumerProvider, false, 0, i); matrixStack.pop(); }
Example 18
Source File: ClickGui.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
public void renderPopupsAndTooltip(MatrixStack matrixStack, int mouseX, int mouseY) { // popups for(Popup popup : popups) { Component owner = popup.getOwner(); Window parent = owner.getParent(); int x1 = parent.getX() + owner.getX(); int y1 = parent.getY() + 13 + parent.getScrollOffset() + owner.getY(); GL11.glPushMatrix(); GL11.glTranslated(x1, y1, 0); int cMouseX = mouseX - x1; int cMouseY = mouseY - y1; popup.render(matrixStack, cMouseX, cMouseY); GL11.glPopMatrix(); } // tooltip if(!tooltip.isEmpty()) { String[] lines = tooltip.split("\n"); TextRenderer fr = MC.textRenderer; int tw = 0; int th = lines.length * fr.fontHeight; for(String line : lines) { int lw = fr.getWidth(line); if(lw > tw) tw = lw; } int sw = MC.currentScreen.width; int sh = MC.currentScreen.height; int xt1 = mouseX + tw + 11 <= sw ? mouseX + 8 : mouseX - tw - 8; int xt2 = xt1 + tw + 3; int yt1 = mouseY + th - 2 <= sh ? mouseY - 4 : mouseY - th - 4; int yt2 = yt1 + th + 2; GL11.glPushMatrix(); GL11.glTranslated(0, 0, 300); // background GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], 0.75F); GL11.glBegin(GL11.GL_QUADS); GL11.glVertex2i(xt1, yt1); GL11.glVertex2i(xt1, yt2); GL11.glVertex2i(xt2, yt2); GL11.glVertex2i(xt2, yt1); GL11.glEnd(); // outline GL11.glColor4f(acColor[0], acColor[1], acColor[2], 0.5F); GL11.glBegin(GL11.GL_LINE_LOOP); GL11.glVertex2i(xt1, yt1); GL11.glVertex2i(xt1, yt2); GL11.glVertex2i(xt2, yt2); GL11.glVertex2i(xt2, yt1); GL11.glEnd(); // text GL11.glEnable(GL11.GL_TEXTURE_2D); for(int i = 0; i < lines.length; i++) fr.draw(matrixStack, lines[i], xt1 + 2, yt1 + 2 + i * fr.fontHeight, 0xffffff); GL11.glEnable(GL11.GL_BLEND); GL11.glPopMatrix(); } }
Example 19
Source File: ExcavatorHack.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
@Override public void onRenderGUI(MatrixStack matrixStack, float partialTicks) { // GL settings GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glPushMatrix(); String message; if(step.selectPos && step.pos != null) message = "Press enter to confirm, or select a different position."; else message = step.message; TextRenderer tr = MC.textRenderer; // translate to center Window sr = MC.getWindow(); int msgWidth = tr.getWidth(message); GL11.glTranslated(sr.getScaledWidth() / 2 - msgWidth / 2, sr.getScaledHeight() / 2 + 1, 0); // background GL11.glColor4f(0, 0, 0, 0.5F); GL11.glBegin(GL11.GL_QUADS); { GL11.glVertex2d(0, 0); GL11.glVertex2d(msgWidth + 2, 0); GL11.glVertex2d(msgWidth + 2, 10); GL11.glVertex2d(0, 10); } GL11.glEnd(); // text GL11.glEnable(GL11.GL_TEXTURE_2D); tr.draw(matrixStack, message, 2, 1, 0xffffffff); GL11.glPopMatrix(); // GL resets GL11.glEnable(GL11.GL_CULL_FACE); GL11.glDisable(GL11.GL_BLEND); }