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

The following examples show how to use org.lwjgl.input.Mouse#setNativeCursor() . 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: Utils.java    From Hyperium with GNU Lesser General Public License v3.0 7 votes vote down vote up
public void setCursor(ResourceLocation cursor) {
    try {
        BufferedImage image = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(cursor).getInputStream());
        int w = image.getWidth();
        int h = image.getHeight();
        int[] pixels = new int[(w * h)];
        image.getRGB(0, 0, w, h, pixels, 0, w);
        ByteBuffer buffer = BufferUtils.createByteBuffer(w * h * 4);

        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                int pixel = pixels[(h - 1 - y) * w + x];
                buffer.put((byte) (pixel & 0xFF));
                buffer.put((byte) (pixel >> 8 & 0xFF));
                buffer.put((byte) (pixel >> 16 & 0xFF));
                buffer.put((byte) (pixel >> 24 & 0xFF));
            }
        }

        buffer.flip();
        Mouse.setNativeCursor(new Cursor(w, h, 0, h - 1, 1, buffer.asIntBuffer(), null));
    } catch (Exception ignored) {
    }
}
 
Example 2
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
  * {@inheritDoc}
  */
 public void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException {
     try {
        Image temp = new Image(get2Fold(image.getWidth()), get2Fold(image.getHeight()));
        Graphics g = temp.getGraphics();
        
        ByteBuffer buffer = BufferUtils.createByteBuffer(temp.getWidth() * temp.getHeight() * 4);
        g.drawImage(image.getFlippedCopy(false, true), 0, 0);
        g.flush();
        g.getArea(0,0,temp.getWidth(),temp.getHeight(),buffer);
        
        Cursor cursor = CursorLoader.get().getCursor(buffer, hotSpotX, hotSpotY,temp.getWidth(),temp.getHeight());
        Mouse.setNativeCursor(cursor);
     } catch (Throwable e) {
        Log.error("Failed to load and apply cursor.", e);
throw new SlickException("Failed to set mouse cursor", e);
     }
  }
 
Example 3
Source File: AppGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.GameContainer#setMouseCursor(org.newdawn.slick.Image, int, int)
 */
public void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException {
	try {
		Image temp = new Image(get2Fold(image.getWidth()), get2Fold(image.getHeight()));
		Graphics g = temp.getGraphics();
		
		ByteBuffer buffer = BufferUtils.createByteBuffer(temp.getWidth() * temp.getHeight() * 4);
		g.drawImage(image.getFlippedCopy(false, true), 0, 0);
		g.flush();
		g.getArea(0,0,temp.getWidth(),temp.getHeight(),buffer);
		
		Cursor cursor = CursorLoader.get().getCursor(buffer, hotSpotX, hotSpotY,temp.getWidth(),temp.getHeight());
		Mouse.setNativeCursor(cursor);
	} catch (Throwable e) {
		Log.error("Failed to load and apply cursor.", e);
		throw new SlickException("Failed to set mouse cursor", e);
	}
}
 
Example 4
Source File: GLHelper.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
public static void hideNativeCursor()
{
	try {
		int min = Cursor.getMinCursorSize();
		IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
		Mouse.setNativeCursor(new Cursor(min, min, min / 2, min / 2, 1, tmp, null));
	} catch (LWJGLException e) {
		softErr(e, "Could not hide native cursor");
	}
}
 
Example 5
Source File: GLHelper.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
public static void showNativeCursor()
{
	try {
		Mouse.setNativeCursor(null);
	} catch (LWJGLException e) {
		softErr(e, "Could not re-show native cursor");
	}
}
 
Example 6
Source File: PointerInput.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final static void doSetActiveCursor(Cursor cursor) {
	active_cursor = cursor;
	try {
		Mouse.setNativeCursor(LocalEventQueue.getQueue().getDeterministic().isPlayback() ? debug_cursor.getCursor() : cursor);
	} catch (LWJGLException e) {
		throw new RuntimeException(e);
	}
}
 
Example 7
Source File: DesktopLauncher.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
private void hideCursor() {
	Cursor emptyCursor;

	int min = org.lwjgl.input.Cursor.getMinCursorSize();
	IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
	try {
		emptyCursor = new org.lwjgl.input.Cursor(min, min, min / 2,
				min / 2, 1, tmp, null);

		Mouse.setNativeCursor(emptyCursor);
	} catch (LWJGLException e) {
		EditorLogger.printStackTrace(e);
	}

}
 
Example 8
Source File: SeventhGame.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Hide the Mouse cursor
 * 
 * @param visible
 */
private void setHWCursorVisible(boolean visible) {
    if (Gdx.app.getType() != ApplicationType.Desktop && Gdx.app instanceof LwjglApplication) {
        return;
    }

    try {
        /* make sure the mouse doesn't move off the screen */
        seventh.client.gfx.Cursor cursor = this.uiManager.getCursor();
        cursor.setClampEnabled(config.getVideo().isFullscreen());
        Gdx.input.setCursorCatched(config.getVideo().isFullscreen());
        
        //Gdx.input.setCursorCatched(true);
        //Gdx.input.setCursorPosition(getScreenWidth()/2, getScreenHeight()/2);
        
        Cursor emptyCursor = null;
        if (Mouse.isCreated()) {
            int min = org.lwjgl.input.Cursor.getMinCursorSize();
            IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
            emptyCursor = new org.lwjgl.input.Cursor(min, min, min / 2, min / 2, 1, tmp, null);
        } else {
            Cons.println("Could not create empty cursor before Mouse object is created");
        }
    
        if (/*Mouse.isInsideWindow() &&*/ emptyCursor != null) {
            Mouse.setNativeCursor(visible ? null : emptyCursor);
        }
    }
    catch(LWJGLException e) {
        Cons.println("*** Unable to hide cursor: " + e);
    }
}
 
Example 9
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
* @see org.newdawn.slick.GameContainer#setMouseCursor(java.lang.String,
*      int, int)
*/
   public void setMouseCursor(String ref, int hotSpotX, int hotSpotY) throws SlickException {
      try {
         Cursor cursor = CursorLoader.get().getCursor(ref, hotSpotX, hotSpotY);
         Mouse.setNativeCursor(cursor);
      } catch (Throwable e) {
         Log.error("Failed to load and apply cursor.", e);
throw new SlickException("Failed to set mouse cursor", e);
      }
   }
 
Example 10
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
    * @see org.newdawn.slick.GameContainer#setMouseCursor(org.newdawn.slick.opengl.ImageData, int, int)
    */
   public void setMouseCursor(ImageData data, int hotSpotX, int hotSpotY) throws SlickException {
      try {
         Cursor cursor = CursorLoader.get().getCursor(data, hotSpotX, hotSpotY);
         Mouse.setNativeCursor(cursor);
      } catch (Throwable e) {
         Log.error("Failed to load and apply cursor.", e);
throw new SlickException("Failed to set mouse cursor", e);
      }
   }
 
Example 11
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
    * @see org.newdawn.slick.GameContainer#setMouseCursor(org.lwjgl.input.Cursor, int, int)
    */
   public void setMouseCursor(Cursor cursor, int hotSpotX, int hotSpotY) throws SlickException {
      try {
         Mouse.setNativeCursor(cursor);
      } catch (Throwable e) {
         Log.error("Failed to load and apply cursor.", e);
throw new SlickException("Failed to set mouse cursor", e);
      }
   }
 
Example 12
Source File: AppGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.GameContainer#setMouseCursor(java.lang.String, int, int)
 */
public void setMouseCursor(String ref, int hotSpotX, int hotSpotY) throws SlickException {
	try {
		Cursor cursor = CursorLoader.get().getCursor(ref, hotSpotX, hotSpotY);
		Mouse.setNativeCursor(cursor);
	} catch (Throwable e) {
		Log.error("Failed to load and apply cursor.", e);
		throw new SlickException("Failed to set mouse cursor", e);
	}
}
 
Example 13
Source File: AppGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.GameContainer#setMouseCursor(org.newdawn.slick.opengl.ImageData, int, int)
 */
public void setMouseCursor(ImageData data, int hotSpotX, int hotSpotY) throws SlickException {
	try {
		Cursor cursor = CursorLoader.get().getCursor(data, hotSpotX, hotSpotY);
		Mouse.setNativeCursor(cursor);
	} catch (Throwable e) {
		Log.error("Failed to load and apply cursor.", e);
		throw new SlickException("Failed to set mouse cursor", e);
	}
}
 
Example 14
Source File: AppGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.GameContainer#setMouseCursor(org.lwjgl.input.Cursor, int, int)
 */
public void setMouseCursor(Cursor cursor, int hotSpotX, int hotSpotY) throws SlickException {
	try {
		Mouse.setNativeCursor(cursor);
	} catch (Throwable e) {
		Log.error("Failed to load and apply cursor.", e);
		throw new SlickException("Failed to set mouse cursor", e);
	}
}
 
Example 15
Source File: AppGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.GameContainer#setDefaultMouseCursor()
 */
public void setDefaultMouseCursor() {
	try {
		Mouse.setNativeCursor(null);
	} catch (LWJGLException e) {
		Log.error("Failed to reset mouse cursor", e);
	}
}