Java Code Examples for net.minecraft.client.gui.ScaledResolution#getScaledHeight_double()

The following examples show how to use net.minecraft.client.gui.ScaledResolution#getScaledHeight_double() . 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: DisplayElement.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void drawForConfig() {
    recalculateColor();
    width = 0;
    height = 0;
    ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
    double addy = 0;
    int x = (int) (xloc * resolution.getScaledWidth_double());
    double y = (int) (yloc * resolution.getScaledHeight_double());

    for (DisplayItem iDisplayItem : displayItems) {
        iDisplayItem.draw(x, y, true);
        y += iDisplayItem.getHeight() * ElementRenderer.getCurrentScale();
        addy += iDisplayItem.getHeight() * ElementRenderer.getCurrentScale();
        width = (int) Math.max(iDisplayItem.getWidth() * ElementRenderer.getCurrentScale(), width);

    }
    height = addy;

}
 
Example 2
Source File: DisplayElement.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void renderEditView() {
    ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
    int x = (int) (.8 * resolution.getScaledWidth_double());
    if (rightSided) {
        x += getDimensions().getWidth();
        if (x > resolution.getScaledWidth())
            x = resolution.getScaledWidth();
    } else {
        if (x + getDimensions().getWidth() > resolution.getScaledWidth()) {
            x = (int) (resolution.getScaledWidth() - getDimensions().getWidth());
        }
    }

    double y = (int) (.2 * resolution.getScaledHeight_double());

    for (DisplayItem iDisplayItem : displayItems) {
        iDisplayItem.draw(x, y, false);
        y += iDisplayItem.getHeight() * ElementRenderer.getCurrentScale();
    }
}
 
Example 3
Source File: DisplayElement.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void draw() {
    ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
    int x = (int) (xloc * resolution.getScaledWidth_double());
    double y = (int) (yloc * resolution.getScaledHeight_double());

    for (DisplayItem iDisplayItem : displayItems) {
        try {
            iDisplayItem.draw(x, y, false);
            y += iDisplayItem.getHeight() * ElementRenderer.getCurrentScale();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
 
Example 4
Source File: MoveElementGui.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    ScaledResolution current = ResolutionUtil.current();
    drawRect(0, 0, current.getScaledWidth(), current.getScaledHeight(), new Color(0, 0, 0, 150).getRGB());
    mouseLock = mouseLock && Mouse.isButtonDown(0);
    super.drawScreen(mouseX, mouseY, partialTicks);
    ElementRenderer.startDrawing(element);
    element.drawForConfig();
    ElementRenderer.endDrawing(element);
    ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
    double offset = element.isRightSided() ? element.getDimensions().getWidth() : 0;
    double x1 = element.getXloc() * resolution.getScaledWidth_double() - offset;
    double x2 = element.getXloc() * resolution.getScaledWidth_double() + element.getDimensions().getWidth() - offset;
    double y1 = element.getYloc() * resolution.getScaledHeight_double();
    double y2 = element.getYloc() * resolution.getScaledHeight_double() + element.getDimensions().getHeight();
    //Left top right bottom

    //Outline
    drawHorizontalLine((int) (x1 - 5), (int) (x2 + 5), (int) y1 - 5, Color.RED.getRGB());
    drawHorizontalLine((int) (x1 - 5), (int) (x2 + 5), (int) y2 + 5, Color.RED.getRGB());
    drawVerticalLine((int) x1 - 5, (int) (y1 - 5), (int) (y2 + 5), Color.RED.getRGB());
    drawVerticalLine((int) x2 + 5, (int) (y1 - 5), (int) (y2 + 5), Color.RED.getRGB());
    int propX = (int) x1 - 5;
    int propY = (int) y1 - 30;

    if (propX < 10 || propX > resolution.getScaledWidth() - 200) propX = resolution.getScaledWidth() / 2;
    if (propY > resolution.getScaledHeight() - 5 || propY < 0) propY = resolution.getScaledHeight() / 2;

    edit.xPosition = propX;
    edit.yPosition = propY;

    if (Mouse.isButtonDown(0) && !mouseLock) {
        if (mouseX > x1 - 2 && mouseX < x2 + 2 && mouseY > y1 - 2 && mouseY < y2 + 2 || lastD) {
            //inside
            double x3 = Mouse.getX() / ResolutionUtil.current().getScaledWidth_double();
            double y3 = Mouse.getY() / ResolutionUtil.current().getScaledHeight_double();
            element.setXloc(element.getXloc() - (lastX - x3) / ((double) ResolutionUtil.current().getScaleFactor()));
            element.setYloc(element.getYloc() + (lastY - y3) / ((double) ResolutionUtil.current().getScaleFactor()));

            //Math to keep it inside screen
            if (element.getXloc() * resolution.getScaledWidth_double() - offset < 0) {
                if (element.isRightSided())
                    element.setXloc(offset / resolution.getScaledWidth_double());
                else
                    element.setXloc(0);
            }

            if (element.getYloc() < 0) element.setYloc(0);
            if (element.getXloc() * resolution.getScaledWidth() + element.getDimensions().getWidth() - offset > resolution.getScaledWidth()) {
                element.setXloc(element.isRightSided() ? 1.0 : (resolution.getScaledWidth_double() - element.getDimensions().getWidth()) / resolution.getScaledWidth_double());
            }

            if (element.getYloc() * resolution.getScaledHeight() + element.getDimensions().getHeight() > resolution.getScaledHeight()) {
                element.setYloc((resolution.getScaledHeight_double() - element.getDimensions().getHeight()) / resolution.getScaledHeight_double());
            }

            lastD = true;
        }
    } else {
        lastD = false;
    }

    lastX = Mouse.getX() / ResolutionUtil.current().getScaledWidth_double();
    lastY = Mouse.getY() / ResolutionUtil.current().getScaledHeight_double();
}
 
Example 5
Source File: GeneralConfigGui.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("Duplicates")
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    ScaledResolution current = ResolutionUtil.current();
    drawRect(0, 0, current.getScaledWidth(), current.getScaledHeight(), new Color(0, 0, 0, 150).getRGB());
    super.drawScreen(mouseX, mouseY, partialTicks);
    List<DisplayElement> elementList = mod.getDisplayElements();
    elementList.stream().filter(element -> currentElement == null || currentElement != element).forEach(element -> {
        ElementRenderer.startDrawing(element);
        try {
            element.drawForConfig();
        } catch (Exception e) {
            e.printStackTrace();
        }
        ElementRenderer.endDrawing(element);
    });

    if (currentElement != null) {
        ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft());
        double offset = currentElement.isRightSided() ? currentElement.getDimensions().getWidth() : 0;

        // Left top right bottom
        double x1 = currentElement.getXloc() * resolution.getScaledWidth_double() - offset;
        double x2 = currentElement.getXloc() * resolution.getScaledWidth_double() + currentElement.getDimensions().getWidth() - offset;
        double y1 = currentElement.getYloc() * resolution.getScaledHeight_double();
        double y2 = currentElement.getYloc() * resolution.getScaledHeight_double() + currentElement.getDimensions().getHeight();

        // Chroma selection background
        if (currentElement.isSelected()) {
            HyperiumGui.drawChromaBox((int) x1 - 2, (int) y1 - 2, (int) x2 + 2, (int) y2 - 2, 0.2F);
        }

        ElementRenderer.startDrawing(currentElement);

        // Draw the element after the background
        currentElement.drawForConfig();

        ElementRenderer.endDrawing(currentElement);

        // Turns the edit image on
        edit.visible = true;

        int propX = (int) x1 - 5;
        int propY = (int) y1 - 20;
        if (propX < 10 || propX > resolution.getScaledWidth() - 200) {
            propX = resolution.getScaledWidth() / 2;
        }
        if (propY > resolution.getScaledHeight() - 5 || propY < 0)
            propY = resolution.getScaledHeight() / 2;
        edit.xPosition = propX;
        edit.yPosition = propY;
        // moving the thing
        if (Mouse.isButtonDown(0)) {
            if (mouseX > x1 - 2 && mouseX < x2 + 2 && mouseY > y1 - 2 && mouseY < y2 + 2 || lastD) {
                //inside
                double x3 = Mouse.getX() / ResolutionUtil.current().getScaledWidth_double();
                double y3 = Mouse.getY() / ResolutionUtil.current().getScaledHeight_double();
                currentElement.setXloc(currentElement.getXloc() - (lastX - x3) / ((double) ResolutionUtil.current().getScaleFactor()));
                currentElement.setYloc(currentElement.getYloc() + (lastY - y3) / ((double) ResolutionUtil.current().getScaleFactor()));
                //Math to keep it inside screen
                if (currentElement.getXloc() * resolution.getScaledWidth_double() - offset < 0) {
                    if (currentElement.isRightSided())
                        currentElement.setXloc(offset / resolution.getScaledWidth_double());
                    else
                        currentElement.setXloc(0);
                }
                if (currentElement.getYloc() < 0) currentElement.setYloc(0);
                if (currentElement.getXloc() * resolution.getScaledWidth() + currentElement.getDimensions().getWidth() - offset > resolution.getScaledWidth()) {
                    currentElement.setXloc(currentElement.isRightSided() ? 1.0 :
                        (resolution.getScaledWidth_double() - currentElement.getDimensions().getWidth()) / resolution.getScaledWidth_double());
                }

                if (currentElement.getYloc() * resolution.getScaledHeight() + currentElement.getDimensions().getHeight() > resolution.getScaledHeight()) {
                    currentElement.setYloc((resolution.getScaledHeight_double() - currentElement.getDimensions().getHeight()) / resolution.getScaledHeight_double());
                }

                lastD = true;
            }
        } else {
            lastD = false;
        }
    } else {
        edit.visible = false;
    }

    lastX = Mouse.getX() / ResolutionUtil.current().getScaledWidth_double();
    lastY = Mouse.getY() / ResolutionUtil.current().getScaledHeight_double();
    if (dTick <= 0 && pastClick) pastClick = false;
    if (pastClick) dTick--;
}
 
Example 6
Source File: ScoreboardRenderer.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void render(ScoreObjective objective, ScaledResolution resolution) {
    RenderScoreboardEvent renderEvent = new RenderScoreboardEvent(xLocation, yLocation, objective, resolution);
    EventBus.INSTANCE.post(renderEvent);
    if (!renderEvent.isCancelled()) {
        Scoreboard scoreboard = objective.getScoreboard();
        Collection<Score> collection = scoreboard.getSortedScores(objective);
        List<Score> list = collection.stream().filter(p_apply_1_ -> p_apply_1_.getPlayerName() != null
            && !p_apply_1_.getPlayerName().startsWith("#")).collect(Collectors.toList());

        collection = list.size() > 15 ? Lists.newArrayList(Iterables.skip(list, collection.size() - 15)) : list;
        int i = getFontRenderer().getStringWidth(objective.getDisplayName());

        for (Score score : collection) {
            ScorePlayerTeam scoreplayerteam = scoreboard.getPlayersTeam(score.getPlayerName());
            String s = ScorePlayerTeam.formatPlayerName(scoreplayerteam, score.getPlayerName()) + ": " + EnumChatFormatting.RED + score.getScorePoints();
            i = Math.max(i, getFontRenderer().getStringWidth(s));
        }

        int i1 = collection.size() * getFontRenderer().FONT_HEIGHT;
        int j1 = (int) (resolution.getScaledHeight_double() * yLocation) + i1 / 3;
        int k1 = 3;
        int l1 = (int) (resolution.getScaledWidth_double() * xLocation) - i - k1;
        int j = 0;

        for (Score score1 : collection) {
            ++j;
            ScorePlayerTeam scoreplayerteam1 = scoreboard.getPlayersTeam(score1.getPlayerName());
            String s1 = ScorePlayerTeam.formatPlayerName(scoreplayerteam1, score1.getPlayerName());
            String s2 = EnumChatFormatting.RED.toString() + score1.getScorePoints();
            int k = j1 - j * getFontRenderer().FONT_HEIGHT;
            int l = (int) (resolution.getScaledWidth_double() * xLocation) - k1 + 2;
            RenderUtils.drawRect(l1 - 2, k, l, k + getFontRenderer().FONT_HEIGHT, 1342177280);
            getFontRenderer().drawString(s1, l1, k, 553648127);
            getFontRenderer().drawString(s2, l - getFontRenderer().getStringWidth(s2), k, 553648127);

            if (j == collection.size()) {
                String s3 = objective.getDisplayName();
                RenderUtils.drawRect(l1 - 2, k - getFontRenderer().FONT_HEIGHT - 1, l, k - 1, 1610612736);
                RenderUtils.drawRect(l1 - 2, k - 1, l, k, 1342177280);
                getFontRenderer().drawString(s3, l1 + i / 2 - getFontRenderer().getStringWidth(s3) / 2, k - getFontRenderer().FONT_HEIGHT, 553648127);
            }
        }
    }
}