Author Topic: How to remove the mouse pointer when playing  (Read 1994 times)

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
How to remove the mouse pointer when playing
« on: March 03, 2008, 06:12:59 pm »
Hi, Is there anyway to remove the windows mouse pointer?????
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to remove the mouse pointer when playing
« Reply #1 on: March 04, 2008, 12:14:52 pm »
When using the OpenGL renderer, you can use Mouse.getGrabbed(true) from LWJGL's Mouse class. If this is not what you want, you can set the Mouse-cursor to an empty image. This is possible in LWJGL as well as with the AWTGLRenderer and the software renderer, but the code differs. I have some code to do this somewhere. If you need it, i can search for it.

Offline Melssj5

  • double
  • *****
  • Posts: 715
    • View Profile
Re: How to remove the mouse pointer when playing
« Reply #2 on: March 04, 2008, 11:16:23 pm »
Yes please
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to remove the mouse pointer when playing
« Reply #3 on: March 05, 2008, 06:12:59 pm »
AWT-version:

Code: [Select]
java.awt.Cursor oldCursor=frame.getCursor();
int[] pixels=new int[16*16];
Image cursor=Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));
java.awt.Cursor cur=Toolkit.getDefaultToolkit().createCustomCursor(cursor, new Point(0, 0), "hidden");
frame.setCursor(cur);

LWJGL-version:

Code: [Select]
org.lwjgl.input.Cursor oldCursor=Mouse.getNativeCursor();
int[] pixels=new int[16*16];
Image cursor=Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));
int maxSize=org.lwjgl.input.Cursor.getMaxCursorSize();
if (maxSize<=cursor.getWidth(null)) {
    org.lwjgl.input.Cursor cur=new org.lwjgl.input.Cursor(16, 16, 0, 0, 1, createBuffer(cursor), null);
    Mouse.setNativeCursor(cur);
}

with createBuffer() being:

Code: [Select]
private IntBuffer createBuffer(Image img) {
      int len=img.getHeight(null)*img.getWidth(null);
      ByteBuffer temp=ByteBuffer.allocateDirect(len<<2);;
      temp.order(ByteOrder.LITTLE_ENDIAN);

      int[] pixels=new int[len];

      PixelGrabber pg=new PixelGrabber(img, 0, 0, img.getWidth(null), img.getHeight(null), pixels, 0, img.getWidth(null));

      try {
         pg.grabPixels();
      } catch (InterruptedException e) {
         Logger.log("Could not grab pixels from image!", Logger.ERROR);
      }

      for (int i=0; i<len; i++) {
         int pos=i<<2;
         int texel=pixels[i];
         if (texel!=0) {
            texel|=0xff000000;
         }
         temp.putInt(pos, texel);
      }

      return temp.asIntBuffer();
}

Don't forget to restore the saved oldCursor on exit. I don't know why i took a MemoryImageSource and not a BufferedImage. I may had a reason, but i think it should work with any kind of Image.

Hope this helps!