private void drawFov(ScaledResolution resolution) { double aspectRatio = resolution.getScaledWidth_double() / resolution.getScaledHeight_double(); float angleAdd = (float) 180; float fovAngle = mc.gameSettings.fovSetting * 0.5f * (float) aspectRatio; glBegin(GL_LINE_STRIP); glVertex3d(0, 0, 0); glVertex3d(Math.sin(Math.toRadians(fovAngle + angleAdd)) * RADIUS, Math.cos(Math.toRadians(fovAngle + angleAdd)) * RADIUS, 0); glVertex3d(0, 0, 0); glVertex3d(Math.sin(Math.toRadians(-fovAngle + angleAdd)) * RADIUS, Math.cos(Math.toRadians(-fovAngle + angleAdd)) * RADIUS, 0); glEnd(); }
@Nullable public HUDElement getHoveredElement(int mouseX, int mouseY) { for (HUDElement element : ElementRegistry.getElements()) { ResourceLocation key = ElementRegistry.getKey(element); Vector2f position = currentOverrides.getOrDefault(key, ElementRegistry.getPosition(key)); ScaledResolution resolution = new ScaledResolution(mc); int xPos = (int) (resolution.getScaledWidth_double() * position.x); int yPos = (int) (resolution.getScaledHeight_double() * position.y); if (mouseX < xPos || mouseX > xPos + element.getWidth()) continue; if (mouseY < yPos || mouseY > yPos + element.getHeight()) continue; return element; } return null; }
@Override protected void mouseReleased(int mouseX, int mouseY, int state) { if (dragged != null) { ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); Point bounded = getBoundedDrag(resolution, mouseX, mouseY); float xPos = (float) ((bounded.x) / resolution.getScaledWidth_double()); float yPos = (float) ((bounded.y) / resolution.getScaledHeight_double()); currentOverrides.put(ElementRegistry.getKey(dragged), new Vector2f(xPos, yPos)); changes = true; dragged = null; return; } super.mouseReleased(mouseX, mouseY, state); }
protected void resetCamera() { ScaledResolution scaledresolution = new ScaledResolution(mc); GL11.glViewport(0, 0, mc.displayWidth, mc.displayHeight); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); }
public static void renderOverlay(IOverlayStyle style, IProbeInfo probeInfo) { GlStateManager.pushMatrix(); double scale = Config.tooltipScale; Minecraft minecraft = Minecraft.getMinecraft(); ScaledResolution scaledresolution = new ScaledResolution(minecraft); double sw = scaledresolution.getScaledWidth_double(); double sh = scaledresolution.getScaledHeight_double(); setupOverlayRendering(sw * scale, sh * scale); renderElements((ProbeInfo) probeInfo, style, sw * scale, sh * scale, null); setupOverlayRendering(sw, sh); GlStateManager.popMatrix(); }
@Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { drawDefaultBackground(); super.drawScreen(mouseX, mouseY, partialTicks); ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); for (HUDElement element : ElementRegistry.getElements()) { if (dragged == element) continue; ResourceLocation key = ElementRegistry.getKey(element); Vector2f position = currentOverrides.getOrDefault(key, ElementRegistry.getPosition(key)); int xPos = (int) (resolution.getScaledWidth_double() * position.x); int yPos = (int) (resolution.getScaledHeight_double() * position.y); drawWithBox(resolution, element, partialTicks, xPos, yPos); } if (dragged != null) { Point bounded = getBoundedDrag(resolution, mouseX, mouseY); drawWithBox(resolution, dragged, partialTicks, bounded.x, bounded.y); } }
@SideOnly(Side.CLIENT) @SubscribeEvent public static void onRenderOverlay(RenderGameOverlayEvent.Pre event) { if (event.getType() == RenderGameOverlayEvent.ElementType.HOTBAR) { ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); for (HUDElement element : HUD_ELEMENTS.values()) { if (!element.shouldRender(Minecraft.getMinecraft())) continue; Vector2f position = ELEMENT_INFO.get(getKey(element)).getPosition(); int xPos = (int) (resolution.getScaledWidth_double() * position.x); if (xPos - element.getWidth() < 0) xPos *= 2; if (xPos + element.getWidth() > resolution.getScaledWidth()) xPos -= element.getWidth(); int yPos = (int) (resolution.getScaledHeight_double() * position.y); if (yPos - element.getHeight() < 0) yPos *= 2; if (yPos + element.getHeight() > resolution.getScaledHeight()) yPos -= element.getHeight(); element.draw(event.getResolution(), event.getPartialTicks(), xPos, yPos); } } }
private void renderOverlay(int mx, int my) { Rectangle vp = camera.getViewport(); ScaledResolution scaledresolution = new ScaledResolution(mc); int vpx = vp.x / scaledresolution.getScaleFactor(); int vph = vp.height / scaledresolution.getScaleFactor(); int vpw = vp.width / scaledresolution.getScaleFactor(); int vpy = (int) ((float) (vp.y + vp.height - 4) / (float) scaledresolution.getScaleFactor()); GL11.glViewport(0, 0, mc.displayWidth, mc.displayHeight); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution .getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glTranslatef(vpx, vpy, -2000.0F); GlStateManager.disableLighting(); }
double sw = scaledresolution.getScaledWidth_double(); double sh = scaledresolution.getScaledHeight_double(); double sw = scaledresolution.getScaledWidth_double(); double sh = scaledresolution.getScaledHeight_double();
@Override public final void draw(int mouseX, int mouseY) { if (!isVisible()) { return; } GlStateManager.pushMatrix(); GlStateManager.translate(getX(), getY(), 0.0F); if (isCropped()) { GL11.glEnable(GL11.GL_SCISSOR_TEST); Minecraft mc = Minecraft.getMinecraft(); ScaledResolution res = new ScaledResolution(mc); double scaleWidth = mc.displayWidth / res.getScaledWidth_double(); double scaleHeight = mc.displayHeight / res.getScaledHeight_double(); IGuiElement cropRelative = cropElement != null ? cropElement : this; int posX = cropRelative.getAbsoluteX(); int posY = cropRelative.getAbsoluteY(); GL11.glScissor((int) ((posX + cropX) * scaleWidth), (int) (mc.displayHeight - ((posY + cropY + cropHeight) * scaleHeight)), (int) (cropWidth * scaleWidth), (int) (cropHeight * scaleHeight)); } drawElement(mouseX, mouseY); if (isCropped()) { GL11.glDisable(GL11.GL_SCISSOR_TEST); } GlStateManager.popMatrix(); }
@SubscribeEvent @SideOnly(Side.CLIENT) public void render2DOverlay(RenderGameOverlayEvent.Post event) { if (event.getType() != RenderGameOverlayEvent.ElementType.HELMET) return; CanvasClient canvas = getCanvas(); if (canvas == null) return; // If we've no font renderer then we're probably not quite ready yet Minecraft mc = Minecraft.getMinecraft(); if (mc.fontRenderer == null) return; GlStateManager.pushMatrix(); // The hotbar renders at -90 (See GuiIngame#renderTooltip) GlStateManager.translate(0, 0, -100); ScaledResolution resolution = event.getResolution(); GlStateManager.scale(resolution.getScaledWidth_double() / WIDTH, resolution.getScaledHeight_double() / HEIGHT, 2); synchronized (canvas) { canvas.drawChildren(canvas.getChildren(ID_2D).iterator()); } GlStateManager.color(1.0f, 1.0f, 1.0f); GlStateManager.enableTexture2D(); GlStateManager.enableCull(); GlStateManager.popMatrix(); }
GlStateManager.matrixMode(5889); GlStateManager.loadIdentity(); GlStateManager.ortho(0.0D, scaledResolution.getScaledWidth_double(), scaledResolution.getScaledHeight_double(), 0, 1000, 3000); GlStateManager.matrixMode(5888); GlStateManager.loadIdentity();
GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity();
GlStateManager.matrixMode(GL11.GL_PROJECTION); GlStateManager.loadIdentity(); GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1D, -1D); GlStateManager.matrixMode(GL11.GL_MODELVIEW);
GlStateManager.pushMatrix(); int elementWidth = (int) (element.getWidth(event.getResolution(), android) * element.getPosition().x); GlStateManager.translate(element.getPosition().x * event.getResolution().getScaledWidth_double() - elementWidth, element.getPosition().y * event.getResolution().getScaledHeight_double() - element.getHeight(event.getResolution(), android) * element.getPosition().y, 0); element.setBaseColor(baseGuiColor); element.setBackgroundAlpha(opacityBackground);