Java Code Examples for net.minecraft.client.gui.ScaledResolution#getScaleFactor()
The following examples show how to use
net.minecraft.client.gui.ScaledResolution#getScaleFactor() .
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: ButtonLocation.java From SkyblockAddons with MIT License | 5 votes |
/** * This just updates the hovered status and draws the box around each feature. To avoid repetitive code. */ public void checkHoveredAndDrawBox(float boxXOne, float boxXTwo, float boxYOne, float boxYTwo, float scale) { ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); float minecraftScale = sr.getScaleFactor(); float floatMouseX = Mouse.getX() / minecraftScale; float floatMouseY = (Minecraft.getMinecraft().displayHeight - Mouse.getY()) / minecraftScale; hovered = floatMouseX >= boxXOne * scale && floatMouseY >= boxYOne * scale && floatMouseX < boxXTwo * scale && floatMouseY < boxYTwo * scale; int boxAlpha = 70; if (hovered) { boxAlpha = 120; } int boxColor = ChatFormatting.GRAY.getColor(boxAlpha).getRGB(); main.getUtils().drawRect(boxXOne, boxYOne, boxXTwo, boxYTwo, boxColor); this.boxXOne = boxXOne; this.boxXTwo = boxXTwo; this.boxYOne = boxYOne; this.boxYTwo = boxYTwo; if (this.feature == Feature.DEFENCE_ICON) { this.boxXOne *= scale; this.boxXTwo *= scale; this.boxYOne *= scale; this.boxYTwo *= scale; } this.scale = scale; }
Example 2
Source File: ButtonResize.java From SkyblockAddons with MIT License | 5 votes |
@Override public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { ScaledResolution sr = new ScaledResolution(mc); float minecraftScale = sr.getScaleFactor(); float floatMouseX = Mouse.getX() / minecraftScale; float floatMouseY = (mc.displayHeight - Mouse.getY()) / minecraftScale; cornerOffsetX = floatMouseX; cornerOffsetY = floatMouseY; return hovered; }
Example 3
Source File: RenderUtil.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private static void applyScissor(int x, int y, int w, int h) { //translate upper-left to bottom-left ScaledResolution r = ((GuiIngameForge) Minecraft.getMinecraft().ingameGUI).getResolution(); int s = r.getScaleFactor(); int translatedY = r.getScaledHeight() - y - h; GL11.glScissor(x*s, translatedY*s, w*s, h*s); }
Example 4
Source File: HyperiumFontRenderer.java From Hyperium with GNU Lesser General Public License v3.0 | 5 votes |
public HyperiumFontRenderer(String fontName, float fontSize) { name = fontName; size = fontSize; ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); try { prevScaleFactor = resolution.getScaleFactor(); unicodeFont = new UnicodeFont(getFontByName(fontName).deriveFont(fontSize * prevScaleFactor / 2)); unicodeFont.addAsciiGlyphs(); unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.WHITE)); unicodeFont.loadGlyphs(); } catch (FontFormatException | IOException | SlickException e) { e.printStackTrace(); } this.antiAliasingFactor = resolution.getScaleFactor(); }
Example 5
Source File: GuiSurgery.java From Cyberware with MIT License | 5 votes |
private void scissor(int x, int y, int xSize, int ySize) { ScaledResolution res = new ScaledResolution(mc); x = x * res.getScaleFactor(); ySize = ySize * res.getScaleFactor(); y = mc.displayHeight - (y * res.getScaleFactor()) - ySize; xSize = xSize * res.getScaleFactor(); GL11.glScissor(x, y, xSize, ySize); }
Example 6
Source File: RenderUtil.java From Minecraft-GUI-API with BSD 2-Clause "Simplified" License | 5 votes |
public static void scissorBox(int x, int y, int xend, int yend) { int width = xend - x; int height = yend - y; ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight); int factor = sr.getScaleFactor(); int bottomY = Minecraft.getMinecraft().currentScreen.height - yend; glScissor(x * factor, bottomY * factor, width * factor, height * factor); }
Example 7
Source File: IslandWarpGui.java From SkyblockAddons with MIT License | 4 votes |
@Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { ScaledResolution sr = new ScaledResolution(mc); int guiScale = sr.getScaleFactor(); int startColor = new Color(0,0, 0, Math.round(255/3F)).getRGB(); int endColor = new Color(0,0, 0, Math.round(255/2F)).getRGB(); drawGradientRect(0, 0, sr.getScaledWidth(), sr.getScaledHeight(), startColor, endColor); drawCenteredString(mc.fontRendererObj, "Click a warp point to travel there!", sr.getScaledWidth()/2, 10, 0xFFFFFFFF); drawCenteredString(mc.fontRendererObj, "Must have the specific scroll unlocked.", sr.getScaledWidth()/2, 20, 0xFFFFFFFF); GlStateManager.pushMatrix(); ISLAND_SCALE = 0.7F/1080*mc.displayHeight; float scale = ISLAND_SCALE; GlStateManager.scale(1F/guiScale, 1F/guiScale, 1); GlStateManager.scale(scale, scale, 1); float totalWidth = TOTAL_WIDTH*scale; float totalHeight = TOTAL_HEIGHT*scale; SHIFT_LEFT = (mc.displayWidth/2F-totalWidth/2F)/scale; SHIFT_TOP = (mc.displayHeight/2F-totalHeight/2F)/scale; GlStateManager.translate(SHIFT_LEFT, SHIFT_TOP, 0); GlStateManager.enableAlpha(); GlStateManager.enableBlend(); IslandButton lastHoveredButton = null; for (GuiButton button : buttonList) { if (button instanceof IslandButton) { IslandButton islandButton = (IslandButton)button; // Call this just so it calculates the hover, don't actually draw. islandButton.drawButton(mc, mouseX, mouseY, false); if (islandButton.isHovering()) { if (lastHoveredButton != null) { lastHoveredButton.setDisableHover(true); } lastHoveredButton = islandButton; } } } for (GuiButton guiButton : this.buttonList) { guiButton.drawButton(this.mc, mouseX, mouseY); } int x = Math.round(mc.displayWidth/ISLAND_SCALE-SHIFT_LEFT-500); int y = Math.round(mc.displayHeight/ISLAND_SCALE-SHIFT_TOP); GlStateManager.pushMatrix(); float textScale = 3F; GlStateManager.scale(textScale, textScale, 1); if (guiIsActualWarpMenu) { mc.fontRendererObj.drawStringWithShadow(Feature.WARP_ADVANCED_MODE.getMessage(), x / textScale + 50, (y - 30 - 60 * 3) / textScale + 5, 0xFFFFFFFF); mc.fontRendererObj.drawStringWithShadow(Feature.FANCY_WARP_MENU.getMessage(), x / textScale + 50, (y - 30 - 60 * 2) / textScale + 5, 0xFFFFFFFF); } mc.fontRendererObj.drawStringWithShadow(Feature.DOUBLE_WARP.getMessage(), x / textScale + 50, (y - 30 - 60) / textScale + 5, 0xFFFFFFFF); GlStateManager.popMatrix(); GlStateManager.popMatrix(); detectClosestMarker(mouseX, mouseY); }
Example 8
Source File: RenderUtils.java From LiquidBounce with GNU General Public License v3.0 | 4 votes |
public static void makeScissorBox(final float x, final float y, final float x2, final float y2) { final ScaledResolution scaledResolution = new ScaledResolution(mc); final int factor = scaledResolution.getScaleFactor(); glScissor((int) (x * factor), (int) ((scaledResolution.getScaledHeight() - y2) * factor), (int) ((x2 - x) * factor), (int) ((y2 - y) * factor)); }
Example 9
Source File: HyperiumFontRenderer.java From Hyperium with GNU Lesser General Public License v3.0 | 4 votes |
public int drawString(String text, float x, float y, int color) { if (text == null) return 0; ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); try { if (resolution.getScaleFactor() != prevScaleFactor) { prevScaleFactor = resolution.getScaleFactor(); unicodeFont = new UnicodeFont(getFontByName(name).deriveFont(size * prevScaleFactor / 2)); unicodeFont.addAsciiGlyphs(); unicodeFont.getEffects().add(new ColorEffect(java.awt.Color.WHITE)); unicodeFont.loadGlyphs(); } } catch (FontFormatException | IOException | SlickException e) { e.printStackTrace(); } this.antiAliasingFactor = resolution.getScaleFactor(); GL11.glPushMatrix(); GlStateManager.scale(1 / antiAliasingFactor, 1 / antiAliasingFactor, 1 / antiAliasingFactor); x *= antiAliasingFactor; y *= antiAliasingFactor; float originalX = x; float red = (float) (color >> 16 & 255) / 255.0F; float green = (float) (color >> 8 & 255) / 255.0F; float blue = (float) (color & 255) / 255.0F; float alpha = (float) (color >> 24 & 255) / 255.0F; GlStateManager.color(red, green, blue, alpha); int currentColor = color; char[] characters = text.toCharArray(); GlStateManager.disableLighting(); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); String[] parts = COLOR_CODE_PATTERN.split(text); int index = 0; for (String s : parts) { for (String s2 : s.split("\n")) { for (String s3 : s2.split("\r")) { unicodeFont.drawString(x, y, s3, new org.newdawn.slick.Color(currentColor)); x += unicodeFont.getWidth(s3); index += s3.length(); if (index < characters.length && characters[index ] == '\r') { x = originalX; index++; } } if (index < characters.length && characters[index] == '\n') { x = originalX; y += getHeight(s2) * 2; index++; } } if (index < characters.length) { char colorCode = characters[index]; if (colorCode == 'ยง') { char colorChar = characters[index + 1]; int codeIndex = ("0123456789" + "abcdef").indexOf(colorChar); if (codeIndex < 0) { if (colorChar == 'r') { currentColor = color; } } else { currentColor = colorCodes[codeIndex]; } index += 2; } } } GlStateManager.color(1F, 1F, 1F, 1F); GlStateManager.bindTexture(0); GlStateManager.popMatrix(); return (int) x; }
Example 10
Source File: MixinLoadingScreenRenderer.java From Hyperium with GNU Lesser General Public License v3.0 | 4 votes |
/** * @author ConorTheDev * @reason Custom screen when loading to a new world */ @Inject(method = "setLoadingProgress", at = @At("HEAD"), cancellable = true) private void setLoadingProgress(CallbackInfo ci) { if (Settings.HYPERIUM_LOADING_SCREEN) { long nanoTime = Minecraft.getSystemTime(); if (nanoTime - systemTime >= 100L) { systemTime = nanoTime; ScaledResolution scaledresolution = new ScaledResolution(mc); int scaleFactor = scaledresolution.getScaleFactor(); int scaledWidth = scaledresolution.getScaledWidth(); int scaledHeight = scaledresolution.getScaledHeight(); if (OpenGlHelper.isFramebufferEnabled()) { framebuffer.framebufferClear(); } else { GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT); } framebuffer.bindFramebuffer(false); GlStateManager.matrixMode(GL11.GL_PROJECTION); GlStateManager.loadIdentity(); GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 100.0D, 300.0D); GlStateManager.matrixMode(GL11.GL_MODELVIEW); GlStateManager.loadIdentity(); GlStateManager.translate(0.0F, 0.0F, -200.0F); if (!OpenGlHelper.isFramebufferEnabled()) GlStateManager.clear(16640); Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); mc.getTextureManager().bindTexture(new ResourceLocation("textures/world-loading.png")); Gui.drawModalRectWithCustomSizedTexture(0, 0, 0.0f, 0.0f, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight()); int progress; if ("Loading world".equals(currentlyDisplayedText)) { if (message.isEmpty()) { progress = 33; } else if (message.equals("Converting world")) { progress = 66; } else if (message.equals("Building terrain")) { progress = 90; } else { progress = 100; } } else { progress = -1; } if (progress >= 0) { int maxProgress = 100; int barTop = 2; int barHeight = scaledResolution.getScaledHeight() - 15; GlStateManager.disableTexture2D(); worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); worldrenderer.pos(maxProgress, barHeight, 0.0D).color(128, 128, 128, 255).endVertex(); worldrenderer.pos(maxProgress, barHeight + barTop, 0.0D).color(128, 128, 128, 255).endVertex(); worldrenderer.pos(maxProgress + maxProgress, barHeight + barTop, 0.0D).color(128, 128, 128, 255).endVertex(); worldrenderer.pos(maxProgress + maxProgress, barHeight, 0.0D).color(128, 128, 128, 255).endVertex(); worldrenderer.pos(maxProgress, barHeight, 0.0D).color(128, 255, 128, 255).endVertex(); worldrenderer.pos(maxProgress, barHeight + barTop, 0.0D).color(128, 255, 128, 255).endVertex(); worldrenderer.pos(maxProgress + progress, barHeight + barTop, 0.0D).color(128, 255, 128, 255).endVertex(); worldrenderer.pos(maxProgress + progress, barHeight, 0.0D).color(128, 255, 128, 255).endVertex(); tessellator.draw(); GlStateManager.enableAlpha(); GlStateManager.enableBlend(); Gui.drawRect(0, scaledResolution.getScaledHeight() - 35, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), new Color(0, 0, 0, 50).getRGB()); GlStateManager.disableAlpha(); GlStateManager.disableBlend(); GlStateManager.enableTexture2D(); } GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); mc.fontRendererObj.drawString(currentlyDisplayedText, 5, scaledResolution.getScaledHeight() - 30, -1); mc.fontRendererObj.drawString(message, 5, scaledResolution.getScaledHeight() - 15, -1); framebuffer.unbindFramebuffer(); if (OpenGlHelper.isFramebufferEnabled()) { framebuffer.framebufferRender(scaledWidth * scaleFactor, scaledHeight * scaleFactor); } mc.updateDisplay(); try { Thread.yield(); } catch (Exception ignored) { } } ci.cancel(); } }
Example 11
Source File: ConsoleGui.java From ehacks-pro with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") public IChatComponent getChatComponent(int mouseX, int mouseY) { if (!this.getChatOpen()) { return null; } else { ScaledResolution scaledresolution = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); int k = scaledresolution.getScaleFactor(); float f = this.getChatScale(); int l = mouseX / k - 3; int i1 = mouseY / k - 27; l = MathHelper.floor_float(l / f); i1 = MathHelper.floor_float(i1 / f); if (l >= 0 && i1 >= 0) { int j1 = Math.min(this.getLineCount(), this.drawnChatLines.size()); if (l <= MathHelper.floor_float(this.getChatWidth() / this.getChatScale()) && i1 < this.mc.fontRenderer.FONT_HEIGHT * j1 + j1) { int k1 = i1 / this.mc.fontRenderer.FONT_HEIGHT + this.scrollPos; if (k1 >= 0 && k1 < this.drawnChatLines.size()) { ChatLine chatline = this.drawnChatLines.get(k1); int l1 = 0; for (Object iChatComponent : chatline.func_151461_a()) { if (iChatComponent instanceof ChatComponentText) { l1 += this.mc.fontRenderer.getStringWidth(this.func_146235_b(((ChatComponentText) iChatComponent).getChatComponentText_TextValue())); if (l1 > l) { return (IChatComponent) iChatComponent; } } } } return null; } else { return null; } } else { return null; } } }
Example 12
Source File: CellViewer.java From ehacks-pro with GNU General Public License v3.0 | 4 votes |
@Override public void onTicks() { try { boolean newState = Keyboard.isKeyDown(OpenAE2ViewerKeybind.getKey()); if (newState && !prevState) { prevState = newState; GuiScreen screen = Wrapper.INSTANCE.mc().currentScreen; ItemStack cell = null; if (screen instanceof GuiContainer) { try { ScaledResolution get = new ScaledResolution(Wrapper.INSTANCE.mc(), Wrapper.INSTANCE.mc().displayWidth, Wrapper.INSTANCE.mc().displayHeight); int mouseX = Mouse.getX() / get.getScaleFactor(); int mouseY = Mouse.getY() / get.getScaleFactor(); GuiContainer container = (GuiContainer) screen; Method isMouseOverSlot = GuiContainer.class.getDeclaredMethod(Mappings.isMouseOverSlot, Slot.class, Integer.TYPE, Integer.TYPE); isMouseOverSlot.setAccessible(true); for (int i = 0; i < container.inventorySlots.inventorySlots.size(); i++) { //noinspection JavaReflectionInvocation if ((Boolean) isMouseOverSlot.invoke(container, container.inventorySlots.inventorySlots.get(i), mouseX, get.getScaledHeight() - mouseY)) { cell = container.inventorySlots.inventorySlots.get(i) == null ? null : ((Slot) container.inventorySlots.inventorySlots.get(i)).getStack(); } } } catch (Exception ex) { InteropUtils.log("&cError", this); } } if (cell == null) { return; } if (!(Class.forName("appeng.items.storage.ItemBasicStorageCell").isInstance(cell.getItem()))) { InteropUtils.log("&cNot a cell", this); return; } NBTTagCompound tag = cell.stackTagCompound; if (tag == null) { InteropUtils.log("&cCell is empty (new)", this); return; } try { ArrayList<ItemStack> stacks = new ArrayList<>(); int count = tag.getShort("it"); for (int i = 0; i < count; i++) { ItemStack stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("#" + i)); stack.stackSize = (int) tag.getCompoundTag("#" + i).getLong("Cnt"); if (stack.stackTagCompound == null) { stack.stackTagCompound = new NBTTagCompound(); stack.stackTagCompound.setString("render-cellviewer", "ok"); } stacks.add(stack); } Wrapper.INSTANCE.mc().displayGuiScreen(new CellViewerGui(new CellViewerContainer(stacks.toArray(new ItemStack[stacks.size()]), cell.getDisplayName()))); } catch (Exception e) { InteropUtils.log("&cError", this); } } prevState = newState; } catch (Exception ignored) { } }
Example 13
Source File: FontHelper.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
public static void drawString(String s, float x, float y, TrueTypeFont font, float scaleX, float scaleY, float rotationZ, float... rgba){ Minecraft mc = Minecraft.getMinecraft(); ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); if(mc.gameSettings.hideGUI){ return; } float amt = 2F / sr.getScaleFactor(); if(sr.getScaleFactor() == 1){ amt = 2; } FloatBuffer matrixData = BufferUtils.createFloatBuffer(16); GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, matrixData); FontHelper.set2DMode(matrixData); GL11.glPushMatrix(); y = mc.displayHeight-(y*sr.getScaleFactor())-(((font.getLineHeight()/amt))); float tx = (x*sr.getScaleFactor())+(font.getWidth(s)/2); float tranx = tx+2; float trany = y+(font.getLineHeight()/2); GL11.glTranslatef(tranx,trany,0); GL11.glRotatef(rotationZ, 0f, 0f, 1f); GL11.glTranslatef(-tranx,-trany,0); GL11.glEnable(GL11.GL_BLEND); if(s.contains(formatEscape)){ String[] pars = s.split(formatEscape); float totalOffset = 0; for(int i = 0; i < pars.length; i++){ String par = pars[i]; float[] c = rgba; if(i > 0){ c = Formatter.getFormatted(par.charAt(0)); par = par.substring(1, par.length()); } font.drawString((x*sr.getScaleFactor()+totalOffset), y, par, scaleX/amt, scaleY/amt, c); totalOffset += font.getWidth(par); } }else{ font.drawString((x*sr.getScaleFactor()), y, s, scaleX/amt, scaleY/amt, rgba); } GL11.glPopMatrix(); GL11.glDisable(GL11.GL_BLEND); FontHelper.set3DMode(); }