How to remove the mouse pointer when playing

Started by Melssj5, March 03, 2008, 06:12:59 PM

Previous topic - Next topic

Melssj5

Hi, Is there anyway to remove the windows mouse pointer?????
Nada por ahora

EgonOlsen

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.

Melssj5

Nada por ahora

EgonOlsen

AWT-version:


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:


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:


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!