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

The following examples show how to use org.lwjgl.input.Mouse#setGrabbed() . 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: LwjglCanvas.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void pauseCanvas(){
    if (Mouse.isCreated()){
        if (Mouse.isGrabbed()){
            Mouse.setGrabbed(false);
            mouseWasGrabbed = true;
        }
        mouseWasCreated = true;
        Mouse.destroy();
    }
    if (Keyboard.isCreated()){
        keyboardWasCreated = true;
        Keyboard.destroy();
    }

    renderable.set(false);
    destroyContext();
}
 
Example 2
Source File: LwjglCanvas.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void pauseCanvas(){
    if (Mouse.isCreated()){
        if (Mouse.isGrabbed()){
            Mouse.setGrabbed(false);
            mouseWasGrabbed = true;
        }
        mouseWasCreated = true;
        Mouse.destroy();
    }
    if (Keyboard.isCreated()){
        keyboardWasCreated = true;
        Keyboard.destroy();
    }

    renderable.set(false);
    destroyContext();
}
 
Example 3
Source File: LwjglMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void initialize() {
    if (!context.isRenderable())
        return;

    try {
        Mouse.create();
        logger.fine("Mouse created.");
        supportHardwareCursor = (Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0;

        // Recall state that was set before initialization
        Mouse.setGrabbed(!cursorVisible);
    } catch (LWJGLException ex) {
        logger.log(Level.SEVERE, "Error while creating mouse", ex);
    }

    if (listener != null) {
        sendFirstMouseEvent();
    }
}
 
Example 4
Source File: MalmoModClient.java    From malmo with MIT License 6 votes vote down vote up
@Override
public void mouseXYChange()
{
    if (this.isOverriding)
    {
        this.deltaX = 0;
        this.deltaY = 0;
        if (Mouse.isGrabbed())
            Mouse.setGrabbed(false);
    }
    else
    {
        super.mouseXYChange();
        if (this.observer != null)
            this.observer.onXYZChange(this.deltaX, this.deltaY, Mouse.getDWheel());
    }
}
 
Example 5
Source File: MalmoModClient.java    From malmo with MIT License 5 votes vote down vote up
@Override
/**
 * Ungrabs the mouse cursor so it can be moved and set it to the center of the screen
 */
public void ungrabMouseCursor()
{
    // Vanilla Minecraft calls Mouse.setCursorPosition(Display.getWidth() / 2, Display.getHeight() / 2) at this point...
    // but it's seriously annoying, so we don't.
    Mouse.setGrabbed(false);
}
 
Example 6
Source File: PointerInput.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final static void setActiveCursor(Cursor cursor) {
	if (cursor != null && Mouse.isGrabbed()) {
		Mouse.setGrabbed(false);
		resetCursorPos();
	} else if (cursor == null && !Mouse.isGrabbed()) {
		Mouse.setGrabbed(true);
		resetCursorPos();
	}
	if (active_cursor != cursor) {
		doSetActiveCursor(cursor);
	}
}
 
Example 7
Source File: Camera.java    From OpenRS with GNU General Public License v3.0 5 votes vote down vote up
public static void acceptInputGrab() {
    if(Mouse.isInsideWindow() && Mouse.isButtonDown(0)) {
        Mouse.setGrabbed(true);
    }
    if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        Mouse.setGrabbed(false);
    }
}
 
Example 8
Source File: LwjglMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setCursorVisible(boolean visible){
    cursorVisible = visible;
    if (!context.isRenderable())
        return;

    Mouse.setGrabbed(!visible);
}
 
Example 9
Source File: MouseHelperHook.java    From SkyblockAddons with MIT License 5 votes vote down vote up
public static void ungrabMouseCursor(int new_x, int new_y) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    if (main.getConfigValues().isDisabled(Feature.DONT_RESET_CURSOR_INVENTORY) || main.getPlayerListener().shouldResetMouse()) {
        Mouse.setCursorPosition(new_x, new_y);
        Mouse.setGrabbed(false);
    }
}
 
Example 10
Source File: LwjglMouseInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void initialize() {
    if (!context.isRenderable())
        return;

    try {
        Mouse.create();
        logger.info("Mouse created.");
        supportHardwareCursor = (Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0;
        
        // Recall state that was set before initialization
        Mouse.setGrabbed(!cursorVisible);
    } catch (LWJGLException ex) {
        logger.log(Level.SEVERE, "Error while creating mouse", ex);
    }
}
 
Example 11
Source File: LwjglMouseInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setCursorVisible(boolean visible){
    cursorVisible = visible;
    if (!context.isRenderable())
        return;
    
    Mouse.setGrabbed(!visible);
}
 
Example 12
Source File: GuiMoveModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onUpdate(EventPlayerUpdate event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        final Minecraft mc = Minecraft.getMinecraft();

        if (mc.currentScreen instanceof GuiChat || mc.currentScreen == null) {
            return;
        }

        final int[] keys = new int[]{mc.gameSettings.keyBindForward.getKeyCode(), mc.gameSettings.keyBindLeft.getKeyCode(), mc.gameSettings.keyBindRight.getKeyCode(), mc.gameSettings.keyBindBack.getKeyCode()};

        for (int keyCode : keys) {
            if (Keyboard.isKeyDown(keyCode)) {
                KeyBinding.setKeyBindState(keyCode, true);
            } else {
                KeyBinding.setKeyBindState(keyCode, false);
            }
        }

        if (Keyboard.isKeyDown(mc.gameSettings.keyBindJump.getKeyCode())) {
            if (mc.player.isInLava() || mc.player.isInWater()) {
                mc.player.motionY += 0.039f;
            } else {
                if (mc.player.onGround) {
                    mc.player.jump();
                }
            }
        }

        if (Mouse.isButtonDown(2)) {
            Mouse.setGrabbed(true);
            mc.inGameHasFocus = true;
        } else {
            Mouse.setGrabbed(false);
            mc.inGameHasFocus = false;
        }
    }
}
 
Example 13
Source File: Test.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Test() {
	super("Test", 1024, 768, true);
	
	Mouse.setGrabbed(true);
}
 
Example 14
Source File: Test.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void keyPressed(int key, char c) {
	if(key == Keyboard.KEY_M)
		Mouse.setGrabbed(!Mouse.isGrabbed());
}
 
Example 15
Source File: Input.java    From 3DGameEngine with Apache License 2.0 4 votes vote down vote up
public static void SetCursor(boolean enabled)
{
	Mouse.setGrabbed(!enabled);
}
 
Example 16
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see org.newdawn.slick.GameContainer#setMouseGrabbed(boolean)
 */
public void setMouseGrabbed(boolean grabbed) {
   Mouse.setGrabbed(grabbed);
}
 
Example 17
Source File: AppGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see org.newdawn.slick.GameContainer#setMouseGrabbed(boolean)
 */
public void setMouseGrabbed(boolean grabbed) {
	Mouse.setGrabbed(grabbed);
}