Search in sources :

Example 41 with TextRenderer

use of net.minecraft.client.font.TextRenderer in project BleachHack by BleachDrinker420.

the class WindowCheckboxWidget method render.

@Override
public void render(MatrixStack matrices, int windowX, int windowY, int mouseX, int mouseY) {
    super.render(matrices, windowX, windowY, mouseX, mouseY);
    TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
    int x = windowX + x1;
    int y = windowY + y1;
    int color = mouseX >= x && mouseX <= x + 10 && mouseY >= y && mouseY <= y + 10 ? 0x906060ff : 0x9040409f;
    Window.fill(matrices, x, y, x + 11, y + 11, color);
    if (checked) {
        textRenderer.draw(matrices, "\u2714", x + 2, y + 2, 0xffeeff);
    // fill(matrix, x + 3, y + 3, x + 7, y + 7, 0xffffffff);
    }
    textRenderer.drawWithShadow(matrices, text, x + 15, y + 2, 0xc0c0c0);
}
Also used : TextRenderer(net.minecraft.client.font.TextRenderer)

Example 42 with TextRenderer

use of net.minecraft.client.font.TextRenderer in project Moonfix by Kingdom-of-Moon.

the class InputEntry method render.

@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
    // text
    TextRenderer textRenderer = client.textRenderer;
    int posY = y + entryHeight / 2;
    if (this.field.isFocused() && this.inputType == ConfigManager.InputType.HEX_COLOR) {
        Text text = new LiteralText("").append(this.title).append(" (").append(this.field.getText()).append(")");
        textRenderer.draw(matrices, text, (float) x, (float) (posY - 9 / 2), 0xFFFFFF);
    } else {
        textRenderer.draw(matrices, this.title, (float) x, (float) (posY - 9 / 2), 0xFFFFFF);
    }
    // reset button
    this.reset.x = x + 260;
    this.reset.y = y;
    this.reset.active = !this.config.configValue.equals(this.config.defaultValue + "");
    this.reset.render(matrices, mouseX, mouseY, tickDelta);
    // text field
    this.field.y = y + 2;
    // focused size
    int extraWidth = 0;
    if (this.field.isFocused() && !field.getText().isBlank())
        extraWidth = MathHelper.clamp(textRenderer.getWidth(field.getText()) - 50, 0, 177);
    // set size
    this.field.setWidth(76 + extraWidth);
    this.field.x = x + 177 - extraWidth;
    // set text color
    int color = 0xFFFFFF;
    if (!this.config.configValue.equals(this.initValue + ""))
        if (this.inputType == ConfigManager.InputType.HEX_COLOR)
            color = hexToInt(this.field.getText());
        else
            color = ConfigManager.ACCENT_COLOR.apply(Style.EMPTY).getColor().getRgb();
    if (!inputType.validator.test(field.getText())) {
        color = 0xFF5555;
    }
    this.field.setEditableColor(color);
    // render
    this.field.render(matrices, mouseX, mouseY, tickDelta);
}
Also used : LiteralText(net.minecraft.text.LiteralText) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) TextRenderer(net.minecraft.client.font.TextRenderer) LiteralText(net.minecraft.text.LiteralText)

Example 43 with TextRenderer

use of net.minecraft.client.font.TextRenderer in project Moonfix by Kingdom-of-Moon.

the class KeyBindEntry method render.

@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
    // text
    TextRenderer textRenderer = client.textRenderer;
    int posY = y + entryHeight / 2;
    textRenderer.draw(matrices, this.title, (float) x, (float) (posY - 9 / 2), 0xFFFFFF);
    // reset button
    this.reset.x = x + 260;
    this.reset.y = y;
    this.reset.active = !this.binding.isDefault();
    this.reset.render(matrices, mouseX, mouseY, tickDelta);
    // toggle button
    this.toggle.x = x + 175;
    this.toggle.y = y;
    this.toggle.setMessage(this.binding.getBoundKeyLocalizedText());
    if (parent.focusedBinding == this.binding) {
        this.toggle.setMessage(new LiteralText("> ").styled(ConfigManager.ACCENT_COLOR).append(this.toggle.getMessage()).append(" <"));
    } else if (!this.binding.isUnbound()) {
        for (KeyBinding key : MinecraftClient.getInstance().options.allKeys) {
            if (key != this.binding && this.binding.equals(key)) {
                this.toggle.setMessage(this.toggle.getMessage().shallowCopy().formatted(Formatting.RED));
                break;
            }
        }
    }
    this.toggle.render(matrices, mouseX, mouseY, tickDelta);
}
Also used : KeyBinding(net.minecraft.client.option.KeyBinding) TextRenderer(net.minecraft.client.font.TextRenderer) LiteralText(net.minecraft.text.LiteralText)

Example 44 with TextRenderer

use of net.minecraft.client.font.TextRenderer in project RPG-Hud by KurodaAkira.

the class GuiScreenTooltip method drawTooltip.

/**
 * Checks if a tooltip should be rendered and if so renders it on the screen.
 */
private void drawTooltip(MatrixStack ms, int mouseX, int mouseY) {
    MinecraftClient mc = MinecraftClient.getInstance();
    TextRenderer fontRenderer = mc.textRenderer;
    GuiScreenTooltip gui = null;
    if (mc.currentScreen instanceof GuiScreenTooltip)
        gui = (GuiScreenTooltip) mc.currentScreen;
    else
        return;
    boolean shouldRenderTooltip = false;
    GuiButtonTooltip button = null;
    for (int x = 0; x < this.children().size(); x++) {
        Element b = this.children().get(x);
        if (b instanceof GuiButtonTooltip)
            button = (GuiButtonTooltip) b;
        if (button != null) {
            if (button.isHovered()) {
                shouldRenderTooltip = true;
                break;
            }
        }
    }
    if (shouldRenderTooltip) {
        int posX = mouseX + 5;
        int posY = mouseY + 5;
        int totalWidth = 0;
        boolean reverseY = false;
        String[] tooltip = button.getTooltip();
        if (!(tooltip == null)) {
            int counter = 0;
            for (int id = 0; id < tooltip.length; id++) {
                int width = fontRenderer.getWidth(tooltip[id]);
                if (totalWidth < width)
                    totalWidth = fontRenderer.getWidth(tooltip[id]);
                counter++;
            }
            posX -= totalWidth / 2;
            if ((posX + totalWidth + 10) > gui.width)
                posX -= (posX + totalWidth + 10) - gui.width;
            if (posX < 0)
                posX = 0;
            if ((posY + 3 + tooltip.length * 12 + 2) > gui.height)
                reverseY = true;
            if (reverseY)
                fill(ms, posX, posY - 3 - tooltip.length * 12 - 2, posX + totalWidth + 10, posY, 0xA0000000);
            else
                fill(ms, posX, posY, posX + totalWidth + 10, posY + 3 + tooltip.length * 12 + 2, 0xA0000000);
            for (int id = 0; id < tooltip.length; id++) {
                if (!tooltip[id].isEmpty()) {
                    if (reverseY)
                        DrawableHelper.drawStringWithShadow(ms, fontRenderer, tooltip[id], posX + 5, posY - 2 - 12 * (counter - id - 1) - 10, 0xBBBBBB);
                    else
                        DrawableHelper.drawStringWithShadow(ms, fontRenderer, tooltip[id], posX + 5, posY + 5 + 12 * id, 0xBBBBBB);
                }
            }
        }
    }
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) Element(net.minecraft.client.gui.Element) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 45 with TextRenderer

use of net.minecraft.client.font.TextRenderer in project RPG-Hud by KurodaAkira.

the class GuiSettingsModColor method render.

@Override
public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
    TextRenderer textRenderer = client.textRenderer;
    this.renderBackground(ms);
    DrawableHelper.drawCenteredText(ms, textRenderer, this.title, this.width / 2, 12, -1);
    DrawableHelper.drawCenteredText(ms, textRenderer, I18n.translate("color.red", new Object[0]), this.width / 2, 40 - 9, -1);
    DrawableHelper.drawCenteredText(ms, textRenderer, I18n.translate("color.green", new Object[0]), this.width / 2, 65 - 9, -1);
    DrawableHelper.drawCenteredText(ms, textRenderer, I18n.translate("color.blue", new Object[0]), this.width / 2, 90 - 9, -1);
    this.colorCodeField.render(ms, mouseX, mouseY, partialTicks);
    DrawableHelper.drawCenteredText(ms, textRenderer, I18n.translate("gui.rpg.result", new Object[0]) + ": " + Settings.intToHexString(this.color), this.width / 2, 141, -1);
    super.render(ms, mouseX, mouseY, partialTicks);
    HudElement.drawCustomBar(ms, this.width / 2 - 75, 149, 150, 16, 100D, 0, 0, this.color, HudElement.offsetColorPercent(this.color, HudElement.OFFSET_PERCENT), true);
}
Also used : TextRenderer(net.minecraft.client.font.TextRenderer)

Aggregations

TextRenderer (net.minecraft.client.font.TextRenderer)45 Point (de.johni0702.minecraft.gui.utils.lwjgl.Point)9 ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)9 MinecraftClient (net.minecraft.client.MinecraftClient)7 LiteralText (net.minecraft.text.LiteralText)7 Dimension (de.johni0702.minecraft.gui.utils.lwjgl.Dimension)6 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)6 TranslatableText (net.minecraft.text.TranslatableText)5 ReadableColor (de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor)3 GameRenderer (net.minecraft.client.render.GameRenderer)3 MatrixStack (net.minecraft.client.util.math.MatrixStack)3 Text (net.minecraft.text.Text)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Environment (net.fabricmc.api.Environment)2 InGameHud (net.minecraft.client.gui.hud.InGameHud)2 Screen (net.minecraft.client.gui.screen.Screen)2 BufferBuilder (net.minecraft.client.render.BufferBuilder)2 I18n (net.minecraft.client.resource.language.I18n)2 Sprite (net.minecraft.client.texture.Sprite)2