Search in sources :

Example 56 with FontRenderer

use of net.minecraft.client.gui.FontRenderer in project EnderIO by SleepyTrousers.

the class GuiPowerMonitor method drawControls.

private void drawControls(int sx, int sy) {
    FontRenderer fr = getFontRenderer();
    int textColor = ColorUtil.getRGB(engineControlEnabled.isSelected() ? Color.black : Color.darkGray);
    int x0 = sx + TEXT_MARGIN_LEFT;
    int y0 = sy + TEXT_MARGIN_TOP;
    // Emit signal when storage less
    String engineTxt1 = Lang.GUI_POWER_MONITOR_ENGINE_1.get().trim();
    // than
    String engineTxt2 = Lang.GUI_POWER_MONITOR_ENGINE_2.get().trim();
    // % full.
    String engineTxt3 = Lang.GUI_POWER_MONITOR_ENGINE_3.get().trim();
    // Stop when storage greater than
    String engineTxt4 = Lang.GUI_POWER_MONITOR_ENGINE_4.get().trim();
    // or equal to
    String engineTxt5 = Lang.GUI_POWER_MONITOR_ENGINE_5.get().trim();
    List<Object> elems = new ArrayList<Object>();
    elems.add(engineControlEnabled);
    elems.addAll(Arrays.asList(engineTxt1.split("(\\s+)")));
    elems.addAll(Arrays.asList(engineTxt2.split("(\\s+)")));
    elems.add(engineControlStart);
    elems.addAll(Arrays.asList(engineTxt3.split("(\\s+)")));
    elems.addAll(Arrays.asList(engineTxt4.split("(\\s+)")));
    elems.addAll(Arrays.asList(engineTxt5.split("(\\s+)")));
    elems.add(engineControlStop);
    elems.addAll(Arrays.asList(engineTxt3.split("(\\s+)")));
    int x = 0, y = 0;
    for (Object elem : elems) {
        int elemWidth = 0;
        if (elem instanceof String) {
            elemWidth = fr.getStringWidth((String) elem);
        } else if (elem instanceof CheckBox) {
            elemWidth = ((CheckBox) elem).width;
        } else if (elem instanceof TextFieldEnder) {
            elemWidth = ((TextFieldEnder) elem).width;
        }
        if (x + elemWidth > TEXT_WIDTH) {
            x = 0;
            y += CONTROL_LF_PX;
            if (" ".equals(elem)) {
                continue;
            }
        }
        if (elem instanceof String) {
            fr.drawString((String) elem, x0 + x, y0 + y + TEXT_Y_OFFSET, textColor);
        } else if (elem instanceof CheckBox) {
            ((CheckBox) elem).x = x0 + x;
            ((CheckBox) elem).y = y0 + y;
        } else if (elem instanceof TextFieldEnder) {
            ((TextFieldEnder) elem).x = x0 + x;
            ((TextFieldEnder) elem).y = y0 + y;
        }
        x += elemWidth + fr.getStringWidth(" ");
    }
}
Also used : CheckBox(com.enderio.core.client.gui.button.CheckBox) ArrayList(java.util.ArrayList) PowerToolObject(crazypants.enderio.powertools.init.PowerToolObject) ConduitObject(crazypants.enderio.conduits.init.ConduitObject) FontRenderer(net.minecraft.client.gui.FontRenderer) TextFieldEnder(com.enderio.core.client.gui.widget.TextFieldEnder)

Example 57 with FontRenderer

use of net.minecraft.client.gui.FontRenderer in project Wurst-MC-1.12 by Wurst-Imperium.

the class Checkbox method render.

@Override
public void render(int mouseX, int mouseY) {
    ClickGui gui = WurstClient.INSTANCE.getGui();
    float[] bgColor = gui.getBgColor();
    float[] acColor = gui.getAcColor();
    int x1 = getX();
    int x2 = x1 + getWidth();
    int x3 = x1 + 11;
    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;
    // tooltip
    String tooltip = setting.getDescription();
    if (setting.isLocked()) {
        if (tooltip == null)
            tooltip = "";
        else
            tooltip += "\n\n";
        tooltip += "This checkbox is locked to " + setting.isChecked() + ".";
    }
    if (hovering && mouseX >= x3)
        gui.setTooltip(tooltip);
    if (setting.isLocked())
        hovering = false;
    // background
    GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], 0.5F);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x3, y1);
    GL11.glVertex2i(x3, y2);
    GL11.glVertex2i(x2, y2);
    GL11.glVertex2i(x2, y1);
    GL11.glEnd();
    // box
    GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], hovering ? 0.75F : 0.5F);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x1, y1);
    GL11.glVertex2i(x1, y2);
    GL11.glVertex2i(x3, y2);
    GL11.glVertex2i(x3, y1);
    GL11.glEnd();
    GL11.glColor4f(acColor[0], acColor[1], acColor[2], 0.5F);
    GL11.glBegin(GL11.GL_LINE_LOOP);
    GL11.glVertex2i(x1, y1);
    GL11.glVertex2i(x1, y2);
    GL11.glVertex2i(x3, y2);
    GL11.glVertex2i(x3, y1);
    GL11.glEnd();
    if (setting.isChecked()) {
        double xc1 = x1 + 2.5;
        double xc2 = x1 + 3.5;
        double xc3 = x1 + 4.5;
        double xc4 = x1 + 7.5;
        double xc5 = x1 + 8.5;
        double yc1 = y1 + 2.5;
        double yc2 = y1 + 3.5;
        double yc3 = y1 + 5.5;
        double yc4 = y1 + 6.5;
        double yc5 = y1 + 8.5;
        // check
        if (setting.isLocked())
            GL11.glColor4f(0.5F, 0.5F, 0.5F, 0.75F);
        else
            GL11.glColor4f(0, hovering ? 1 : 0.85F, 0, 1);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glVertex2d(xc2, yc3);
        GL11.glVertex2d(xc3, yc4);
        GL11.glVertex2d(xc3, yc5);
        GL11.glVertex2d(xc1, yc4);
        GL11.glVertex2d(xc4, yc1);
        GL11.glVertex2d(xc5, yc2);
        GL11.glVertex2d(xc3, yc5);
        GL11.glVertex2d(xc3, yc4);
        GL11.glEnd();
        // outline
        GL11.glColor4f(0.0625F, 0.0625F, 0.0625F, 0.5F);
        GL11.glBegin(GL11.GL_LINE_LOOP);
        GL11.glVertex2d(xc2, yc3);
        GL11.glVertex2d(xc3, yc4);
        GL11.glVertex2d(xc4, yc1);
        GL11.glVertex2d(xc5, yc2);
        GL11.glVertex2d(xc3, yc5);
        GL11.glVertex2d(xc1, yc4);
        GL11.glEnd();
    }
    // checkbox name
    GL11.glColor4f(1, 1, 1, 1);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    FontRenderer fr = Fonts.segoe18;
    fr.drawString(setting.getName(), x3 + 2, y1 - 1, setting.isLocked() ? 0xaaaaaa : 0xf0f0f0);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
}
Also used : FontRenderer(net.minecraft.client.gui.FontRenderer)

Example 58 with FontRenderer

use of net.minecraft.client.gui.FontRenderer in project Wurst-MC-1.12 by Wurst-Imperium.

the class ClickGui method renderPopupsAndTooltip.

public void renderPopupsAndTooltip(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(cMouseX, cMouseY);
        GL11.glPopMatrix();
    }
    // tooltip
    if (tooltip != null) {
        String[] lines = tooltip.split("\n");
        Minecraft mc = Minecraft.getMinecraft();
        FontRenderer fr = Fonts.segoe15;
        int tw = 0;
        int th = lines.length * fr.FONT_HEIGHT;
        for (String line : lines) {
            int lw = fr.getStringWidth(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;
        // 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.drawString(lines[i], xt1 + 2, yt1 - 1 + i * fr.FONT_HEIGHT, 0xffffff);
    }
}
Also used : FontRenderer(net.minecraft.client.gui.FontRenderer) Minecraft(net.minecraft.client.Minecraft)

Example 59 with FontRenderer

use of net.minecraft.client.gui.FontRenderer in project Wurst-MC-1.12 by Wurst-Imperium.

the class ClickGui method renderWindow.

private void renderWindow(Window window, int mouseX, int mouseY) {
    int x1 = window.getX();
    int y1 = window.getY();
    int x2 = x1 + window.getWidth();
    int y2 = y1 + window.getHeight();
    int y3 = y1 + 13;
    if (window.isMinimized())
        y2 = y3;
    if (mouseX >= x1 && mouseY >= y1 && mouseX < x2 && mouseY < y2)
        tooltip = null;
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    if (!window.isMinimized()) {
        window.validate();
        // scrollbar
        if (window.isScrollingEnabled()) {
            int xs1 = x2 - 3;
            int xs2 = xs1 + 2;
            int xs3 = x2;
            double outerHeight = y2 - y3;
            double innerHeight = window.getInnerHeight();
            double maxScrollbarHeight = outerHeight - 2;
            double scrollbarY = outerHeight * (-window.getScrollOffset() / innerHeight) + 1;
            double scrollbarHeight = maxScrollbarHeight * outerHeight / innerHeight;
            int ys1 = y3;
            int ys2 = y2;
            int ys3 = ys1 + (int) scrollbarY;
            int ys4 = ys3 + (int) scrollbarHeight;
            // window background
            GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], 0.5F);
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glVertex2i(xs2, ys1);
            GL11.glVertex2i(xs2, ys2);
            GL11.glVertex2i(xs3, ys2);
            GL11.glVertex2i(xs3, ys1);
            GL11.glVertex2i(xs1, ys1);
            GL11.glVertex2i(xs1, ys3);
            GL11.glVertex2i(xs2, ys3);
            GL11.glVertex2i(xs2, ys1);
            GL11.glVertex2i(xs1, ys4);
            GL11.glVertex2i(xs1, ys2);
            GL11.glVertex2i(xs2, ys2);
            GL11.glVertex2i(xs2, ys4);
            GL11.glEnd();
            boolean hovering = mouseX >= xs1 && mouseY >= ys3 && mouseX < xs2 && mouseY < ys4;
            // scrollbar
            GL11.glColor4f(acColor[0], acColor[1], acColor[2], hovering ? 0.75F : 0.5F);
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glVertex2i(xs1, ys3);
            GL11.glVertex2i(xs1, ys4);
            GL11.glVertex2i(xs2, ys4);
            GL11.glVertex2i(xs2, ys3);
            GL11.glEnd();
            // outline
            GL11.glColor4f(acColor[0], acColor[1], acColor[2], 0.5F);
            GL11.glBegin(GL11.GL_LINE_LOOP);
            GL11.glVertex2i(xs1, ys3);
            GL11.glVertex2i(xs1, ys4);
            GL11.glVertex2i(xs2, ys4);
            GL11.glVertex2i(xs2, ys3);
            GL11.glEnd();
        }
        int x3 = x1 + 2;
        int x4 = window.isScrollingEnabled() ? x2 - 3 : x2;
        int x5 = x4 - 2;
        int y4 = y3 + window.getScrollOffset();
        // window background
        // left & right
        GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], 0.5F);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glVertex2i(x1, y3);
        GL11.glVertex2i(x1, y2);
        GL11.glVertex2i(x3, y2);
        GL11.glVertex2i(x3, y3);
        GL11.glVertex2i(x5, y3);
        GL11.glVertex2i(x5, y2);
        GL11.glVertex2i(x4, y2);
        GL11.glVertex2i(x4, y3);
        GL11.glEnd();
        ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
        int sf = sr.getScaleFactor();
        GL11.glScissor(x1 * sf, (int) ((sr.getScaledHeight_double() - y2) * sf), window.getWidth() * sf, (y2 - y3) * sf);
        GL11.glEnable(GL11.GL_SCISSOR_TEST);
        GL11.glPushMatrix();
        GL11.glTranslated(x1, y4, 0);
        GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], 0.5F);
        GL11.glBegin(GL11.GL_QUADS);
        // window background
        // between children
        int xc1 = 2;
        int xc2 = x5 - x1;
        for (int i = 0; i < window.countChildren(); i++) {
            int yc1 = window.getChild(i).getY();
            int yc2 = yc1 - 2;
            GL11.glVertex2i(xc1, yc2);
            GL11.glVertex2i(xc1, yc1);
            GL11.glVertex2i(xc2, yc1);
            GL11.glVertex2i(xc2, yc2);
        }
        // window background
        // bottom
        int yc1;
        if (window.countChildren() == 0)
            yc1 = 0;
        else {
            Component lastChild = window.getChild(window.countChildren() - 1);
            yc1 = lastChild.getY() + lastChild.getHeight();
        }
        int yc2 = yc1 + 2;
        GL11.glVertex2i(xc1, yc2);
        GL11.glVertex2i(xc1, yc1);
        GL11.glVertex2i(xc2, yc1);
        GL11.glVertex2i(xc2, yc2);
        GL11.glEnd();
        // render children
        int cMouseX = mouseX - x1;
        int cMouseY = mouseY - y4;
        for (int i = 0; i < window.countChildren(); i++) window.getChild(i).render(cMouseX, cMouseY);
        GL11.glPopMatrix();
        GL11.glDisable(GL11.GL_SCISSOR_TEST);
    }
    // window outline
    GL11.glColor4f(acColor[0], acColor[1], acColor[2], 0.5F);
    GL11.glBegin(GL11.GL_LINE_LOOP);
    GL11.glVertex2i(x1, y1);
    GL11.glVertex2i(x1, y2);
    GL11.glVertex2i(x2, y2);
    GL11.glVertex2i(x2, y1);
    GL11.glEnd();
    if (!window.isMinimized()) {
        // title bar outline
        GL11.glBegin(GL11.GL_LINES);
        GL11.glVertex2i(x1, y3);
        GL11.glVertex2i(x2, y3);
        GL11.glEnd();
    }
    // title bar buttons
    int x3 = x2;
    int y4 = y1 + 2;
    int y5 = y3 - 2;
    boolean hoveringY = mouseY >= y4 && mouseY < y5;
    if (window.isClosable()) {
        x3 -= 11;
        int x4 = x3 + 9;
        boolean hovering = hoveringY && mouseX >= x3 && mouseX < x4;
        renderCloseButton(x3, y4, x4, y5, hovering);
    }
    if (window.isPinnable()) {
        x3 -= 11;
        int x4 = x3 + 9;
        boolean hovering = hoveringY && mouseX >= x3 && mouseX < x4;
        renderPinButton(x3, y4, x4, y5, hovering, window.isPinned());
    }
    if (window.isMinimizable()) {
        x3 -= 11;
        int x4 = x3 + 9;
        boolean hovering = hoveringY && mouseX >= x3 && mouseX < x4;
        renderMinimizeButton(x3, y4, x4, y5, hovering, window.isMinimized());
    }
    // title bar background
    // above & below buttons
    GL11.glColor4f(acColor[0], acColor[1], acColor[2], 0.5F);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x3, y1);
    GL11.glVertex2i(x3, y4);
    GL11.glVertex2i(x2, y4);
    GL11.glVertex2i(x2, y1);
    GL11.glVertex2i(x3, y5);
    GL11.glVertex2i(x3, y3);
    GL11.glVertex2i(x2, y3);
    GL11.glVertex2i(x2, y5);
    GL11.glEnd();
    // title bar background
    // behind title
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x1, y1);
    GL11.glVertex2i(x1, y3);
    GL11.glVertex2i(x3, y3);
    GL11.glVertex2i(x3, y1);
    GL11.glEnd();
    // window title
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glColor4f(1, 1, 1, 1);
    FontRenderer fr = Fonts.segoe18;
    String title = fr.trimStringToWidth(window.getTitle(), x3 - x1);
    fr.drawString(title, x1 + 2, y1, 0xf0f0f0);
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) FontRenderer(net.minecraft.client.gui.FontRenderer)

Example 60 with FontRenderer

use of net.minecraft.client.gui.FontRenderer in project Wurst-MC-1.12 by Wurst-Imperium.

the class ComboBox method render.

@Override
public void render(int mouseX, int mouseY) {
    ClickGui gui = WurstClient.INSTANCE.getGui();
    float[] bgColor = gui.getBgColor();
    float[] acColor = gui.getAcColor();
    int x1 = getX();
    int x2 = x1 + getWidth();
    int x3 = x2 - 11;
    int x4 = x3 - popupWidth - 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 < x4;
    boolean hBox = hovering && mouseX >= x4;
    // tooltip
    if (hText)
        gui.setTooltip(setting.getDescription());
    // background
    GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], 0.5F);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x1, y1);
    GL11.glVertex2i(x1, y2);
    GL11.glVertex2i(x4, y2);
    GL11.glVertex2i(x4, y1);
    GL11.glEnd();
    // box
    GL11.glColor4f(bgColor[0], bgColor[1], bgColor[2], hBox ? 0.75F : 0.5F);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x4, y1);
    GL11.glVertex2i(x4, 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(x4, y1);
    GL11.glVertex2i(x4, y2);
    GL11.glVertex2i(x2, y2);
    GL11.glVertex2i(x2, y1);
    GL11.glEnd();
    // separator
    GL11.glBegin(GL11.GL_LINES);
    GL11.glVertex2i(x3, y1);
    GL11.glVertex2i(x3, y2);
    GL11.glEnd();
    double xa1 = x3 + 1;
    double xa2 = (x3 + x2) / 2.0;
    double xa3 = x2 - 1;
    double ya1;
    double ya2;
    if (popup != null && !popup.isClosing()) {
        ya1 = y2 - 3.5;
        ya2 = y1 + 3;
        GL11.glColor4f(hBox ? 1 : 0.85F, 0, 0, 1);
    } else {
        ya1 = y1 + 3.5;
        ya2 = y2 - 3;
        GL11.glColor4f(0, hBox ? 1 : 0.85F, 0, 1);
    }
    // arrow
    GL11.glBegin(GL11.GL_TRIANGLES);
    GL11.glVertex2d(xa1, ya1);
    GL11.glVertex2d(xa3, ya1);
    GL11.glVertex2d(xa2, ya2);
    GL11.glEnd();
    // outline
    GL11.glColor4f(0.0625F, 0.0625F, 0.0625F, 0.5F);
    GL11.glBegin(GL11.GL_LINE_LOOP);
    GL11.glVertex2d(xa1, ya1);
    GL11.glVertex2d(xa3, ya1);
    GL11.glVertex2d(xa2, ya2);
    GL11.glEnd();
    // setting name
    GL11.glColor4f(1, 1, 1, 1);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    FontRenderer fr = Fonts.segoe18;
    fr.drawString(setting.getName(), x1, y1 - 1, 0xf0f0f0);
    fr.drawString(setting.getSelected().toString(), x4 + 2, y1 - 1, 0xf0f0f0);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
}
Also used : FontRenderer(net.minecraft.client.gui.FontRenderer)

Aggregations

FontRenderer (net.minecraft.client.gui.FontRenderer)266 ScaledResolution (net.minecraft.client.gui.ScaledResolution)45 Minecraft (net.minecraft.client.Minecraft)39 ItemStack (net.minecraft.item.ItemStack)30 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)13 ArrayList (java.util.ArrayList)12 Tessellator (net.minecraft.client.renderer.Tessellator)11 RenderItem (net.minecraft.client.renderer.RenderItem)10 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)10 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)7 IBlockState (net.minecraft.block.state.IBlockState)6 Block (net.minecraft.block.Block)5 GuiButton (net.minecraft.client.gui.GuiButton)5 List (java.util.List)4 RenderManager (net.minecraft.client.renderer.entity.RenderManager)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 IGuiRect (betterquesting.api2.client.gui.misc.IGuiRect)3 Bounds (ivorius.reccomplex.gui.table.Bounds)3 Item (net.minecraft.item.Item)3