Java Code Examples for org.lwjgl.input.Mouse.getEventButtonState()

The following are Jave code examples for showing how to use getEventButtonState() of the org.lwjgl.input.Mouse class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: HCMIU_PlantsAndZombies   File: GameOver.java   Source Code and License Vote up 6 votes
private void showExitGameButton(GameContainer gc, Graphics g) throws SlickException {
	float rate = 1.14f;
	float posX = 885 * PZGUI.getResolutionRateWidth();
	float posY = 430 * PZGUI.getResolutionRateHeight();
	float width = newGameButton.getWidth() * PZGUI.getResolutionRateWidth() * rate;
	float height = newGameButton.getHeight() * PZGUI.getResolutionRateHeight() * rate;
	
	exitGameButton.draw(posX, posY, width, height);
	
	if (Controller.mouseInArea(posX, posY, posX + width, posY + height)) {
		exitGameButton.draw(posX, posY, width, height, new Color(0, 0, 0, 100));
		if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) {
			gc.exit();
			try {
				TimeUnit.MILLISECONDS.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 2
Project: HCMIU_PlantsAndZombies   File: PlayUI.java   Source Code and License Vote up 6 votes
/**
 * Draw Pause button
 * @param gc	GameContainer
 * @param g	Graphics
 * @throws SlickException
 */
public static void showPauseButton(GameContainer gc, Graphics g) throws SlickException {
	pauseButton.draw(pauseButtonPosX, pauseButtonPosY, pauseButtonWidth, pauseButtonHeight);

	if (Controller.mouseInArea(pauseButtonPosX, pauseButtonPosY, pauseButtonPosX + pauseButtonHeight,
								pauseButtonPosY + pauseButtonHeight)) {
		pauseButton.draw(pauseButtonPosX, pauseButtonPosY, pauseButtonWidth, pauseButtonHeight, new Color(0, 0, 0, 50));

		if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) {
			gc.setPaused(!gc.isPaused());
			try {
				TimeUnit.MILLISECONDS.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 3
Project: HCMIU_PlantsAndZombies   File: PlayUI.java   Source Code and License Vote up 6 votes
/**
 * Show speedUp button
 * @param gc	GameContainer
 * @param g	Graphics
 * @throws SlickException
 */
public static void showSpeedUpButton(GameContainer gc, Graphics g) throws SlickException {
	speedUpButton.draw(speedUpButtonPosX, speedUpButtonPosY, speedUpButtonWidth, speedUpButtonHeight);
	
	if (Controller.mouseInArea(speedUpButtonPosX, speedUpButtonPosY, speedUpButtonPosX + speedUpButtonWidth,
								speedUpButtonPosY + speedUpButtonHeight)) {
		speedUpButton.draw(speedUpButtonPosX, speedUpButtonPosY, speedUpButtonWidth, speedUpButtonHeight,
							new Color(0, 0, 0, 50));
		if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) {
			gc.setTargetFrameRate(isSpeedUpClicked==false?180:60);
			gc.setVSync(isSpeedUpClicked);
			isSpeedUpClicked = !isSpeedUpClicked;
			try {
				TimeUnit.MILLISECONDS.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	if (isSpeedUpClicked == false) {
		speedUpButton.draw(speedUpButtonPosX, speedUpButtonPosY, speedUpButtonWidth, speedUpButtonHeight, new Color(0, 0, 0, 100));
	}
	
}
 
Example 4
Project: betaexpansion   File: GuiScreen.java   Source Code and License Vote up 5 votes
public void handleMouseInput()
{
    if(Mouse.getEventButtonState())
    {
        int i = (Mouse.getEventX() * width) / mc.displayWidth;
        int k = height - (Mouse.getEventY() * height) / mc.displayHeight - 1;
        mouseClicked(i, k, Mouse.getEventButton());
    } else
    {
        int j = (Mouse.getEventX() * width) / mc.displayWidth;
        int l = height - (Mouse.getEventY() * height) / mc.displayHeight - 1;
        mouseMovedOrUp(j, l, Mouse.getEventButton());
    }
}
 
Example 5
Project: DankNull   File: GuiDankNull.java   Source Code and License Vote up 5 votes
@Override
public void handleMouseInput() throws IOException {
	int mouseX = Mouse.getEventX() * width / mc.displayWidth;
	int mouseY = height - Mouse.getEventY() * height / mc.displayHeight - 1;
	int button = Mouse.getEventButton();

	if (Mouse.getEventButtonState()) {
		//if (GuiScreen.isCtrlKeyDown()) {
		if (GuiScreen.isAltKeyDown()) {
			if (button == 0) {
				Slot slot = getSlotAtPos(mouseX, mouseY);
				if (slot != null && !slot.getStack().isEmpty()) {
					if (!ItemUtils.areItemsEqual(DankNullUtils.getSelectedStack(getDankNullInventory()), slot.getStack())) {
						int count = 0;
						for (Slot slotHovered : inventorySlots.inventorySlots) {
							count++;
							if (slotHovered.equals(slot)) {
								DankNullUtils.setSelectedStackIndex(getDankNullInventory(), (count - 1) - 36);
								return;
							}
						}
					}
				}
			}
			//}
		}
	}
	super.handleMouseInput();
}
 
Example 6
Project: ForgeHax   File: MinecraftGuiProxy.java   Source Code and License Vote up 5 votes
@Override
public void handleMouseInput() throws IOException {
    int mouseCode = Mouse.getEventButton();
    if(mouseCode < 0 || mouseCode >= Mouse.getButtonCount()) return; // only allow number of buttons supported by mouse (for mouse event, 0 is not an unknown button)

    InputEntry entry = inputs.computeIfAbsent(Keyboard.KEYBOARD_SIZE + 1 + mouseCode, i -> new InputEntry(InputEntry.MOUSE, mouseCode));

    boolean down = Mouse.getEventButtonState();
    long currentTimeMS = System.currentTimeMillis();

    GuiMouseEvent.Type type;
    if(entry.getTicks() < 0) { // initially pressed
        if(!down) return; // stop executing if key hasnt been initially pressed AND the key is being released (double release event)
        type = GuiMouseEvent.Type.PRESSED;
        entry.setTimePressed(currentTimeMS); // update last click time
    } else {
        type = down ? GuiMouseEvent.Type.DOWN : GuiMouseEvent.Type.RELEASED;
    }

    // update ticks
    entry.incrementTicks();

    int[] mpos = getMousePos();
    element.onMouseEvent(new GuiMouseEvent(
            type,
            mouseCode,
            mpos[0], mpos[1],
            Mouse.getEventDWheel(),
            entry.getTime(),
            currentTimeMS - entry.getTimePressed())
    );

    if(type == GuiMouseEvent.Type.RELEASED) {
        entry.setTime(entry.getTimePressed());
        entry.setTimePressed(-1);
        entry.resetTicks(); // reset ticks after event
    }

    super.handleMouseInput();
}
 
Example 7
Project: CustomWorldGen   File: GuiScreen.java   Source Code and License Vote up 5 votes
/**
 * Handles mouse input.
 */
public void handleMouseInput() throws IOException
{
    int i = Mouse.getEventX() * this.width / this.mc.displayWidth;
    int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
    int k = Mouse.getEventButton();

    if (Mouse.getEventButtonState())
    {
        if (this.mc.gameSettings.touchscreen && this.touchValue++ > 0)
        {
            return;
        }

        this.eventButton = k;
        this.lastMouseEvent = Minecraft.getSystemTime();
        this.mouseClicked(i, j, this.eventButton);
    }
    else if (k != -1)
    {
        if (this.mc.gameSettings.touchscreen && --this.touchValue > 0)
        {
            return;
        }

        this.eventButton = -1;
        this.mouseReleased(i, j, k);
    }
    else if (this.eventButton != -1 && this.lastMouseEvent > 0L)
    {
        long l = Minecraft.getSystemTime() - this.lastMouseEvent;
        this.mouseClickMove(i, j, this.eventButton, l);
    }
}
 
Example 8
Project: DecompiledMinecraft   File: GuiClickableScrolledSelectionListProxy.java   Source Code and License Vote up 5 votes
public void handleMouseInput()
{
    super.handleMouseInput();

    if (this.scrollMultiplier > 0.0F && Mouse.getEventButtonState())
    {
        this.field_178046_u.customMouseEvent(this.top, this.bottom, this.headerPadding, this.amountScrolled, this.slotHeight);
    }
}
 
Example 9
Project: DecompiledMinecraft   File: GuiScreen.java   Source Code and License Vote up 5 votes
/**
 * Handles mouse input.
 */
public void handleMouseInput() throws IOException
{
    int i = Mouse.getEventX() * this.width / this.mc.displayWidth;
    int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
    int k = Mouse.getEventButton();

    if (Mouse.getEventButtonState())
    {
        if (this.mc.gameSettings.touchscreen && this.touchValue++ > 0)
        {
            return;
        }

        this.eventButton = k;
        this.lastMouseEvent = Minecraft.getSystemTime();
        this.mouseClicked(i, j, this.eventButton);
    }
    else if (k != -1)
    {
        if (this.mc.gameSettings.touchscreen && --this.touchValue > 0)
        {
            return;
        }

        this.eventButton = -1;
        this.mouseReleased(i, j, k);
    }
    else if (this.eventButton != -1 && this.lastMouseEvent > 0L)
    {
        long l = Minecraft.getSystemTime() - this.lastMouseEvent;
        this.mouseClickMove(i, j, this.eventButton, l);
    }
}
 
Example 10
Project: Twitchy   File: TCDrawScreen.java   Source Code and License Vote up 5 votes
@SubscribeEvent
public static void mouseClick(GuiScreenEvent.MouseInputEvent.Pre event)
{
    if(mc.player != null && Mouse.getEventButton() == 0 && Mouse.getEventButtonState()) {
        //Get mouse position
        ScaledResolution sr = new ScaledResolution(mc);
        int srHeight = sr.getScaledHeight();
        int mouseX = Mouse.getX() * sr.getScaledWidth() / mc.displayWidth;
        int mouseY = srHeight - Mouse.getY() * srHeight / mc.displayHeight - 1;

        if (twitchRect.contains(mouseX, mouseY))
            openTwitchStream();
    }
}
 
Example 11
Project: BaseClient   File: GuiClickableScrolledSelectionListProxy.java   Source Code and License Vote up 5 votes
public void handleMouseInput()
{
    super.handleMouseInput();

    if (this.scrollMultiplier > 0.0F && Mouse.getEventButtonState())
    {
        this.field_178046_u.customMouseEvent(this.top, this.bottom, this.headerPadding, this.amountScrolled, this.slotHeight);
    }
}
 
Example 12
Project: BaseClient   File: GuiScreen.java   Source Code and License Vote up 5 votes
/**
 * Handles mouse input.
 */
public void handleMouseInput() throws IOException
{
    int i = Mouse.getEventX() * this.width / this.mc.displayWidth;
    int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
    int k = Mouse.getEventButton();

    if (Mouse.getEventButtonState())
    {
        if (this.mc.gameSettings.touchscreen && this.touchValue++ > 0)
        {
            return;
        }

        this.eventButton = k;
        this.lastMouseEvent = Minecraft.getSystemTime();
        this.mouseClicked(i, j, this.eventButton);
    }
    else if (k != -1)
    {
        if (this.mc.gameSettings.touchscreen && --this.touchValue > 0)
        {
            return;
        }

        this.eventButton = -1;
        this.mouseReleased(i, j, k);
    }
    else if (this.eventButton != -1 && this.lastMouseEvent > 0L)
    {
        long l = Minecraft.getSystemTime() - this.lastMouseEvent;
        this.mouseClickMove(i, j, this.eventButton, l);
    }
}
 
Example 13
Project: BaseClient   File: GuiClickableScrolledSelectionListProxy.java   Source Code and License Vote up 5 votes
public void handleMouseInput()
{
    super.handleMouseInput();

    if (this.scrollMultiplier > 0.0F && Mouse.getEventButtonState())
    {
        this.field_178046_u.customMouseEvent(this.top, this.bottom, this.headerPadding, this.amountScrolled, this.slotHeight);
    }
}
 
Example 14
Project: BaseClient   File: GuiScreen.java   Source Code and License Vote up 5 votes
/**
 * Handles mouse input.
 */
public void handleMouseInput() throws IOException
{
    int i = Mouse.getEventX() * this.width / this.mc.displayWidth;
    int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
    int k = Mouse.getEventButton();

    if (Mouse.getEventButtonState())
    {
        if (this.mc.gameSettings.touchscreen && this.touchValue++ > 0)
        {
            return;
        }

        this.eventButton = k;
        this.lastMouseEvent = Minecraft.getSystemTime();
        this.mouseClicked(i, j, this.eventButton);
    }
    else if (k != -1)
    {
        if (this.mc.gameSettings.touchscreen && --this.touchValue > 0)
        {
            return;
        }

        this.eventButton = -1;
        this.mouseReleased(i, j, k);
    }
    else if (this.eventButton != -1 && this.lastMouseEvent > 0L)
    {
        long l = Minecraft.getSystemTime() - this.lastMouseEvent;
        this.mouseClickMove(i, j, this.eventButton, l);
    }
}
 
Example 15
Project: CustomWorldGen   File: GuiClickableScrolledSelectionListProxy.java   Source Code and License Vote up 5 votes
public void handleMouseInput()
{
    super.handleMouseInput();

    if (this.scrollMultiplier > 0.0F && Mouse.getEventButtonState())
    {
        this.proxy.customMouseEvent(this.top, this.bottom, this.headerPadding, this.amountScrolled, this.slotHeight);
    }
}
 
Example 16
Project: Backmemed   File: GuiScreen.java   Source Code and License Vote up 5 votes
/**
 * Handles mouse input.
 */
public void handleMouseInput() throws IOException
{
    int i = Mouse.getEventX() * this.width / this.mc.displayWidth;
    int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
    int k = Mouse.getEventButton();

    if (Mouse.getEventButtonState())
    {
        if (this.mc.gameSettings.touchscreen && this.touchValue++ > 0)
        {
            return;
        }

        this.eventButton = k;
        this.lastMouseEvent = Minecraft.getSystemTime();
        this.mouseClicked(i, j, this.eventButton);
    }
    else if (k != -1)
    {
        if (this.mc.gameSettings.touchscreen && --this.touchValue > 0)
        {
            return;
        }

        this.eventButton = -1;
        this.mouseReleased(i, j, k);
    }
    else if (this.eventButton != -1 && this.lastMouseEvent > 0L)
    {
        long l = Minecraft.getSystemTime() - this.lastMouseEvent;
        this.mouseClickMove(i, j, this.eventButton, l);
    }
}
 
Example 17
Project: CustomWorldGen   File: MouseEvent.java   Source Code and License Vote up 5 votes
public MouseEvent()
{
    this.x = Mouse.getEventX();
    this.y = Mouse.getEventY();
    this.dx = Mouse.getEventDX();
    this.dy = Mouse.getEventDY();
    this.dwheel = Mouse.getEventDWheel();
    this.button = Mouse.getEventButton();
    this.buttonstate = Mouse.getEventButtonState();
    this.nanoseconds = Mouse.getEventNanoseconds();
}
 
Example 18
Project: CustomWorldGen   File: Minecraft.java   Source Code and License Vote up 4 votes
private void runTickMouse() throws IOException
{
    while (Mouse.next())
    {
        if (net.minecraftforge.client.ForgeHooksClient.postMouseEvent()) continue;

        int i = Mouse.getEventButton();
        KeyBinding.setKeyBindState(i - 100, Mouse.getEventButtonState());

        if (Mouse.getEventButtonState())
        {
            if (this.thePlayer.isSpectator() && i == 2)
            {
                this.ingameGUI.getSpectatorGui().onMiddleClick();
            }
            else
            {
                KeyBinding.onTick(i - 100);
            }
        }

        long j = getSystemTime() - this.systemTime;

        if (j <= 200L)
        {
            int k = Mouse.getEventDWheel();

            if (k != 0)
            {
                if (this.thePlayer.isSpectator())
                {
                    k = k < 0 ? -1 : 1;

                    if (this.ingameGUI.getSpectatorGui().isMenuActive())
                    {
                        this.ingameGUI.getSpectatorGui().onMouseScroll(-k);
                    }
                    else
                    {
                        float f = MathHelper.clamp_float(this.thePlayer.capabilities.getFlySpeed() + (float)k * 0.005F, 0.0F, 0.2F);
                        this.thePlayer.capabilities.setFlySpeed(f);
                    }
                }
                else
                {
                    this.thePlayer.inventory.changeCurrentItem(k);
                }
            }

            if (this.currentScreen == null)
            {
                if (!this.inGameHasFocus && Mouse.getEventButtonState())
                {
                    this.setIngameFocus();
                }
            }
            else if (this.currentScreen != null)
            {
                this.currentScreen.handleMouseInput();
            }
        }
    }
}
 
Example 19
Project: Zombe-Modpack   File: Minecraft.java   Source Code and License Vote up 4 votes
private void runTickMouse() throws IOException
{
    while (Mouse.next())
    {
        int i = Mouse.getEventButton();
        KeyBinding.setKeyBindState(i - 100, Mouse.getEventButtonState());

        if (Mouse.getEventButtonState())
        {
            if (this.player.isSpectator() && i == 2)
            {
                this.ingameGUI.getSpectatorGui().onMiddleClick();
            }
            else
            {
                KeyBinding.onTick(i - 100);
            }
        }

        long j = getSystemTime() - this.systemTime;

        if (j <= 200L)
        {
            int k = Mouse.getEventDWheel();

            if (k != 0)
            {
                if (this.player.isSpectator())
                {
                    k = k < 0 ? -1 : 1;

                    if (this.ingameGUI.getSpectatorGui().isMenuActive())
                    {
                        this.ingameGUI.getSpectatorGui().onMouseScroll(-k);
                    }
                    else
                    {
                        float f = MathHelper.clamp(this.player.capabilities.getFlySpeed() + (float)k * 0.005F, 0.0F, 0.2F);
                        this.player.capabilities.setFlySpeed(f);
                    }
                }
                else
                {
                    this.player.inventory.changeCurrentItem(k);
                }
            }

            if (this.currentScreen == null)
            {
                if (!this.inGameHasFocus && Mouse.getEventButtonState())
                {
                    this.setIngameFocus();
                }
            }
            else if (this.currentScreen != null)
            {
                this.currentScreen.handleMouseInput();
            }
        }
    }
}
 
Example 20
Project: Backmemed   File: Minecraft.java   Source Code and License Vote up 4 votes
private void runTickMouse() throws IOException
{
    while (Mouse.next())
    {
        int i = Mouse.getEventButton();
        KeyBinding.setKeyBindState(i - 100, Mouse.getEventButtonState());

        if (Mouse.getEventButtonState())
        {
            if (this.player.isSpectator() && i == 2)
            {
                this.ingameGUI.getSpectatorGui().onMiddleClick();
            }
            else
            {
                KeyBinding.onTick(i - 100);
            }
        }

        long j = getSystemTime() - this.systemTime;

        if (j <= 200L)
        {
            int k = Mouse.getEventDWheel();

            if (k != 0)
            {
                if (this.player.isSpectator())
                {
                    k = k < 0 ? -1 : 1;

                    if (this.ingameGUI.getSpectatorGui().isMenuActive())
                    {
                        this.ingameGUI.getSpectatorGui().onMouseScroll(-k);
                    }
                    else
                    {
                        float f = MathHelper.clamp(this.player.capabilities.getFlySpeed() + (float)k * 0.005F, 0.0F, 0.2F);
                        this.player.capabilities.setFlySpeed(f);
                    }
                }
                else
                {
                    this.player.inventory.changeCurrentItem(k);
                }
            }

            if (this.currentScreen == null)
            {
                if (!this.inGameHasFocus && Mouse.getEventButtonState())
                {
                    this.setIngameFocus();
                }
            }
            else if (this.currentScreen != null)
            {
                this.currentScreen.handleMouseInput();
            }
        }
    }
}