Java Code Examples for org.lwjgl.input.Mouse#getX()

The following examples show how to use org.lwjgl.input.Mouse#getX() . 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: MenuButton.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public void beginStep() {
	int mX = Mouse.getX() / Game.getScaleX();
	int mY = (Game.getWindowHeight() - Mouse.getY()) / Game.getScaleY();
	boolean newHover = (mX >= x && mX < x + width && mY >= y && mY < y + height);
	if(newHover && !hover) {
		onEnter();
		hover = true;
	} else if(!newHover && hover) {
		onExit();
		hover = false;
	}
	List<MouseEvent> mouseEvents = Game.getMouseEvents();
	for(MouseEvent event : mouseEvents) {
		if(hover && event.button == 0 && event.state) {
			onClick();
			break;
		}
	}
}
 
Example 2
Source File: DefaultController.java    From Slyther with MIT License 6 votes vote down vote up
@Override
public void update(SlytherClient client) {
    ClientSnake player = client.player;
    accelerating = Mouse.isButtonDown(0) || Mouse.isButtonDown(1);
    int mouseX = Mouse.getX() - (Display.getWidth() / 2);
    int mouseY = (Display.getHeight() - Mouse.getY()) - (Display.getHeight() / 2);
    if (mouseX != lastMouseX || mouseY != lastMouseY) {
        lastMouseX = mouseX;
        lastMouseY = mouseY;
        int dist = mouseX * mouseX + mouseY * mouseY;
        if (dist > 256) {
            targetAngle = (float) Math.atan2(mouseY, mouseX);
            player.eyeAngle = targetAngle;
        } else {
            targetAngle = player.wantedAngle;
        }
    }
}
 
Example 3
Source File: HyperiumOverlay.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void handleMouseInput() {
    ScaledResolution sr = ResolutionUtil.current();
    int sw = sr.getScaledWidth();
    int sh = sr.getScaledHeight();
    int mx = Mouse.getX() * sw / Minecraft.getMinecraft().displayWidth;
    int my = sh - Mouse.getY() * sh / Minecraft.getMinecraft().displayHeight - 1;

    Integer[] counter = new Integer[]{0};

    components.forEach(c -> c.handleMouseInput(mx, my, sr.getScaledWidth() / 6 * 2,
        sr.getScaledHeight() / 4 + 20 * counter[0]++ + offsetY, sr.getScaledWidth() / 6 * 2, 20));

    int i = Mouse.getEventDWheel();
    if (i > 0 && offsetY != 0) offsetY += 5;
    else if (i < 0) offsetY -= 5;
}
 
Example 4
Source File: ButtonResize.java    From SkyblockAddons with MIT License 5 votes vote down vote up
@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 5
Source File: RenderUtil.java    From Minecraft-GUI-API with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Point calculateMouseLocation() {
	Minecraft minecraft = Minecraft.getMinecraft();
	int scale = minecraft.gameSettings.guiScale;
	if(scale == 0)
		scale = 1000;
	int scaleFactor = 0;
	while(scaleFactor < scale && minecraft.displayWidth / (scaleFactor + 1) >= 320 && minecraft.displayHeight / (scaleFactor + 1) >= 240)
		scaleFactor++;
	return new Point(Mouse.getX() / scaleFactor, minecraft.displayHeight / scaleFactor - Mouse.getY() / scaleFactor - 1);
}
 
Example 6
Source File: GuiContainerScreen.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
public void updateScreen() {
	int mouseX = Mouse.getX() * width / mc.displayWidth;
	int mouseY = height - Mouse.getY() * height / mc.displayHeight - 1;
	
	// Handle onMouseMove.
	if ((mouseX != _lastMouseX) || (mouseY != _lastMouseY)) {
		GuiElementBase pressed = context.getPressed();
		if (pressed != null) {
			ElementInfo info = ElementInfo.getElementHierarchy(pressed).getFirst();
			pressed.onMouseMove(mouseX - info.globalX, mouseY - info.globalY);
		} else if (container.contains(mouseX, mouseY))
			container.onMouseMove(mouseX, mouseY);
		_lastMouseX = mouseX;
		_lastMouseY = mouseY;
	}
	
	// Handle tooltips.
	GuiElementBase tooltipElement = new ElementInfo(container)
		.getElementsAt(mouseX, mouseY)
		.map(info -> info.element)
		.filter(element -> element.hasTooltip())
		.reduce((first, second) -> second) // Get the last element.
		.orElse(null);
	if (tooltipElement != _tooltipElement)
		_tooltipTime = Minecraft.getSystemTime();
	_tooltipElement = tooltipElement;
}
 
Example 7
Source File: HyperiumOverlay.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void mouseClicked() {
    ScaledResolution sr = ResolutionUtil.current();
    int sw = sr.getScaledWidth();
    int sh = sr.getScaledHeight();
    int mx = Mouse.getX() * sw / Minecraft.getMinecraft().displayWidth;
    int my = sh - Mouse.getY() * sh / Minecraft.getMinecraft().displayHeight - 1;

    Integer[] counter = new Integer[]{0};

    components.forEach(c -> c.mouseClicked(mx, my, sr.getScaledWidth() / 6 * 2,
        sr.getScaledHeight() / 4 + 20 * counter[0]++ + offsetY, sr.getScaledWidth() / 6 * 2, 20));
}
 
Example 8
Source File: Utils.java    From ClientBase with MIT License 5 votes vote down vote up
public static Point calculateMouseLocation() {
    Minecraft minecraft = Minecraft.getMinecraft();
    int scale = minecraft.gameSettings.guiScale;
    if (scale == 0)
        scale = 1000;
    int scaleFactor = 0;
    while (scaleFactor < scale && minecraft.displayWidth / (scaleFactor + 1) >= 320 && minecraft.displayHeight / (scaleFactor + 1) >= 240)
        scaleFactor++;
    return new Point(Mouse.getX() / scaleFactor, minecraft.displayHeight / scaleFactor - Mouse.getY() / scaleFactor - 1);
}
 
Example 9
Source File: WorldSceneRenderer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Vec2f setupCamera(int x, int y, int width, int height, int skyColor) {
    Minecraft mc = Minecraft.getMinecraft();
    ScaledResolution resolution = new ScaledResolution(mc);

    GlStateManager.pushAttrib();
    mc.entityRenderer.disableLightmap();
    GlStateManager.disableLighting();
    GlStateManager.enableDepth();
    GlStateManager.enableBlend();

    //compute window size from scaled width & height
    int windowWidth = (int) (width / (resolution.getScaledWidth() * 1.0) * mc.displayWidth);
    int windowHeight = (int) (height / (resolution.getScaledHeight() * 1.0) * mc.displayHeight);

    //translate gui coordinates to window's ones (y is inverted)
    int windowX = (int) (x / (resolution.getScaledWidth() * 1.0) * mc.displayWidth);
    int windowY = mc.displayHeight - (int) (y / (resolution.getScaledHeight() * 1.0) * mc.displayHeight) - windowHeight;

    int mouseX = Mouse.getX();
    int mouseY = Mouse.getY();
    Vec2f mousePosition = null;
    //compute mouse position only if inside viewport
    if (mouseX >= windowX && mouseY >= windowY && mouseX - windowX < windowWidth && mouseY - windowY < windowHeight) {
        mousePosition = new Vec2f(mouseX, mouseY);
    }

    //setup viewport and clear GL buffers
    GlStateManager.viewport(windowX, windowY, windowWidth, windowHeight);

    if (skyColor >= 0) {
        GL11.glEnable(GL11.GL_SCISSOR_TEST);
        GL11.glScissor(windowX, windowY, windowWidth, windowHeight);
        RenderUtil.setGlClearColorFromInt(skyColor, 255);
        GlStateManager.clear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glDisable(GL11.GL_SCISSOR_TEST);
    }

    //setup projection matrix to perspective
    GlStateManager.matrixMode(GL11.GL_PROJECTION);
    GlStateManager.pushMatrix();
    GlStateManager.loadIdentity();

    float aspectRatio = width / (height * 1.0f);
    GLU.gluPerspective(60.0f, aspectRatio, 0.1f, 10000.0f);

    //setup modelview matrix
    GlStateManager.matrixMode(GL11.GL_MODELVIEW);
    GlStateManager.pushMatrix();
    GlStateManager.loadIdentity();
    GLU.gluLookAt(0.0f, 0.0f, -10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    return mousePosition;
}
 
Example 10
Source File: ButtonLocation.java    From SkyblockAddons with MIT License 5 votes vote down vote up
/**
 * 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 11
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 12
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 13
Source File: AbstractTab.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Render - Renders the Tab
 *
 * @param x      - Given X Position
 * @param y      - Given Y Position
 * @param width  - Given Width
 * @param height - Given Height
 */
public void render(int x, int y, int width, int height) {

    ScaledResolution sr = ResolutionUtil.current();
    int sw = sr.getScaledWidth();
    int sh = sr.getScaledHeight();
    int xg = width / 9;   // X grid

    /* Begin new scissor state */
    ScissorState.scissor(x, y, width, height, true);

    /* Get mouse X and Y */
    final int mx = Mouse.getX() * sw / Minecraft.getMinecraft().displayWidth;           // Mouse X
    final int my = sh - Mouse.getY() * sh / Minecraft.getMinecraft().displayHeight - 1; // Mouse Y

    if (scrollAnim.getValue() != scroll * 18 && scrollAnim.isFinished()) {
        scrollAnim = new SimpleAnimValue(1000L, scrollAnim.getValue(), scroll * 18);
    }

    y += scrollAnim.getValue();
    /* Render each tab component */
    for (AbstractTabComponent comp : filter == null ? components : components.stream().filter(c -> c.filter(filter)).collect(Collectors.toList())) {
        comp.render(x, y, width, mx, my);

        /* If mouse is over component, set as hovered */
        if (mx >= x && mx <= x + width && my > y && my <= y + comp.getHeight()) {
            comp.hover = true;
            //For slider
            comp.mouseEvent(mx - xg, my - y /* Make the Y relevant to the component */);
            if (Mouse.isButtonDown(0)) {
                if (!clickStates.computeIfAbsent(comp, ignored -> false)) {
                    comp.onClick(mx, my - y /* Make the Y relevant to the component */);
                    clickStates.put(comp, true);
                }
            } else if (clickStates.computeIfAbsent(comp, ignored -> false))
                clickStates.put(comp, false);
        } else {
            comp.hover = false;
        }

        y += comp.getHeight();
    }

    /* End scissor state */
    ScissorState.endScissor();
}
 
Example 14
Source File: CellViewer.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
@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 15
Source File: MixinMinecraft.java    From VanillaFix with MIT License 4 votes vote down vote up
private void runGUILoop(GuiScreen screen) throws IOException {
    displayGuiScreen(screen);
    while (running && currentScreen != null && !(currentScreen instanceof GuiMainMenu) && !(Loader.isModLoaded("custommainmenu") && currentScreen instanceof GuiCustom)) {
        if (Display.isCreated() && Display.isCloseRequested()) System.exit(0);
        leftClickCounter = 10000;
        currentScreen.handleInput();
        currentScreen.updateScreen();

        GlStateManager.pushMatrix();
        GlStateManager.clear(16640);
        framebuffer.bindFramebuffer(true);
        GlStateManager.enableTexture2D();

        GlStateManager.viewport(0, 0, displayWidth, displayHeight);

        // EntityRenderer.setupOverlayRendering
        ScaledResolution scaledResolution = new ScaledResolution((Minecraft) (Object) this);
        GlStateManager.clear(256);
        GlStateManager.matrixMode(5889);
        GlStateManager.loadIdentity();
        GlStateManager.ortho(0.0D, scaledResolution.getScaledWidth_double(), scaledResolution.getScaledHeight_double(), 0, 1000, 3000);
        GlStateManager.matrixMode(5888);
        GlStateManager.loadIdentity();
        GlStateManager.translate(0, 0, -2000);
        GlStateManager.clear(256);

        int width = scaledResolution.getScaledWidth();
        int height = scaledResolution.getScaledHeight();
        int mouseX = Mouse.getX() * width / displayWidth;
        int mouseY = height - Mouse.getY() * height / displayHeight - 1;
        currentScreen.drawScreen(mouseX, mouseY, 0);

        framebuffer.unbindFramebuffer();
        GlStateManager.popMatrix();

        GlStateManager.pushMatrix();
        framebuffer.framebufferRender(displayWidth, displayHeight);
        GlStateManager.popMatrix();

        updateDisplay();
        Thread.yield();
        Display.sync(60);
        checkGLError("VanillaFix GUI Loop");
    }
}
 
Example 16
Source File: Utils.java    From ClientBase with MIT License 4 votes vote down vote up
public static Point calculateMouseLocation() {
    Minecraft minecraft = Minecraft.getMinecraft();
    int scale = minecraft.gameSettings.guiScale;
    if (scale == 0)
        scale = 1000;
    int scaleFactor = 0;
    while (scaleFactor < scale && minecraft.displayWidth / (scaleFactor + 1) >= 320 && minecraft.displayHeight / (scaleFactor + 1) >= 240)
        scaleFactor++;
    return new Point(Mouse.getX() / scaleFactor, minecraft.displayHeight / scaleFactor - Mouse.getY() / scaleFactor - 1);
}
 
Example 17
Source File: LwJglRenderingEngine.java    From Gaalop with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Poll all inputs of the keyboard<br>
 * F3:Start recording
 * F4:Stop recording
 * ESC: Close window
 */
private void pollInput() {
    
    if (Keyboard.isKeyDown(Keyboard.KEY_F3)) {
        //Start recording
        if (recorder == null) {
            recorder = new GIFRecorder();
            recorder.startRecording();
        }
    }
    
    if (Keyboard.isKeyDown(Keyboard.KEY_F4)) {
        //Stop recording
        if (recorder != null) {
            recorder.stopRecording();
            recorder = null;
        }
    }
    
    if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        if (recorder != null) 
            recorder.stopRecording();
        Display.destroy();
        System.exit(0);

    }

    int x = Mouse.getX();
    int y = Mouse.getY();

    for (int button = 0; button <= 2; button++) {
        if (Mouse.isButtonDown(button)) {
            if (!buttonDown[button]) {
                mouseAction(button, STATE_DOWN, x, y);
            } else {
                mouseMoved(x, y);
            }
            buttonDown[button] = true;
        } else {
            if (buttonDown[button]) {
                mouseAction(button, STATE_UP, x, y);
            }
            buttonDown[button] = false;
        }
    }
}
 
Example 18
Source File: RocketEventHandler.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@SubscribeEvent
public void mouseInputEvent(MouseInputEvent event) {
	if(!Configuration.lockUI && !Mouse.isGrabbed()) {

		if(Mouse.isButtonDown(2)) {
			ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft());
			int i = scaledresolution.getScaledWidth();
			int j = scaledresolution.getScaledHeight();
			int mouseX =  Mouse.getX() * i / Minecraft.getMinecraft().displayWidth;
			int mouseY = j - Mouse.getY() * j / Minecraft.getMinecraft().displayHeight - 1;

			if(currentlySelectedBox == null && mouseX >= suitPanel.getX(i) && mouseX < suitPanel.getX(i) + suitPanel.sizeX &&
					mouseY >= suitPanel.getY(j) && mouseY < suitPanel.getY(j) + suitPanel.sizeY) {
				currentlySelectedBox = suitPanel;
			}

			if(currentlySelectedBox == null && mouseX >= oxygenBar.getX(i) && mouseX < oxygenBar.getX(i) + oxygenBar.sizeX &&
					mouseY >= oxygenBar.getY(j) && mouseY < oxygenBar.getY(j) + oxygenBar.sizeY) {
				currentlySelectedBox = oxygenBar;
			}

			if(currentlySelectedBox == null && mouseX >= hydrogenBar.getX(i) && mouseX < hydrogenBar.getX(i) + hydrogenBar.sizeX &&
					mouseY >= hydrogenBar.getY(j) && mouseY < hydrogenBar.getY(j) + hydrogenBar.sizeY) {
				currentlySelectedBox = hydrogenBar;
			}
			
			if(currentlySelectedBox == null && mouseX >= atmBar.getX(i) && mouseX < atmBar.getX(i) + atmBar.sizeX &&
					mouseY >= atmBar.getY(j) && mouseY < atmBar.getY(j) + atmBar.sizeY) {
				currentlySelectedBox = atmBar;
			}
			
			if(currentlySelectedBox != null) {

				currentlySelectedBox.setRenderX(mouseX, i);
				currentlySelectedBox.setRenderY(mouseY, j);
			}
		}
		else
			currentlySelectedBox = null;
	}
}
 
Example 19
Source File: WidgetFluidModes.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@Override
public void drawButton(Minecraft minecraftInstance, int x, int y)
{
	if (drawButton)
	{
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		this.mouseDragged(minecraftInstance, x, y);

		minecraftInstance.getTextureManager().bindTexture(new ResourceLocation("extracells", "textures/gui/fluidmodes.png"));
		drawTexturedModalRect(xPosition, yPosition, 0, 16, 16, 16);

		switch (fluidMode)
		{
		case DROPS:
			drawTexturedModalRect(xPosition, yPosition, 0, 0, 16, 16);
			break;
		case QUART:
			drawTexturedModalRect(xPosition, yPosition, 16, 0, 16, 16);
			break;
		case BUCKETS:
			drawTexturedModalRect(xPosition, yPosition, 32, 0, 16, 16);
			break;
		default:
			break;
		}

		Minecraft mc = Minecraft.getMinecraft();
		ScaledResolution scaledresolution = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);

		int mouseX = Mouse.getX() * scaledresolution.getScaledWidth() / mc.displayWidth;
		int mouseY = scaledresolution.getScaledHeight() - Mouse.getY() * scaledresolution.getScaledHeight() / mc.displayHeight - 1;

		if (mouseX >= xPosition && mouseX <= xPosition + width && mouseY >= yPosition && mouseY <= yPosition + height)
		{
			List<String> description = new ArrayList<String>();
			description.add(StatCollector.translateToLocal("tooltip.fluidmode"));
			description.add(String.format(StatCollector.translateToLocal("tooltip.fluidmode.move"), fluidMode.getAmount(), fluidMode.getAmount() * 20));
			description.add(String.format(StatCollector.translateToLocal("tooltip.fluidmode.cost"), fluidMode.getCost()));
			drawHoveringText(description, mouseX, mouseY, mc.fontRenderer);
		}
	}
}
 
Example 20
Source File: Input.java    From opsu with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the absolute x position of the mouse cursor within the container
 * 
 * @return The absolute x position of the mouse cursor
 */
public int getAbsoluteMouseX() {
	return Mouse.getX();
}