From e5f0c32fe317e53e942944afe7a85281beada255 Mon Sep 17 00:00:00 2001 From: "jul..om" Date: Fri, 10 Jan 2014 18:35:33 +0000 Subject: [PATCH] Adds the support of the native cursor into the JOGL NEWT backend (not tested) git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10977 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/input/jogl/NewtMouseInput.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/engine/src/jogl/com/jme3/input/jogl/NewtMouseInput.java b/engine/src/jogl/com/jme3/input/jogl/NewtMouseInput.java index 65c749f10..d50017ccc 100644 --- a/engine/src/jogl/com/jme3/input/jogl/NewtMouseInput.java +++ b/engine/src/jogl/com/jme3/input/jogl/NewtMouseInput.java @@ -37,11 +37,18 @@ import com.jme3.input.MouseInput; import com.jme3.input.RawInputListener; import com.jme3.input.event.MouseButtonEvent; import com.jme3.input.event.MouseMotionEvent; +import com.jogamp.common.nio.Buffers; +import com.jogamp.newt.Display.PointerIcon; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.MouseListener; import com.jogamp.newt.opengl.GLWindow; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.logging.Logger; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.DimensionImmutable; +import javax.media.nativewindow.util.PixelFormat; +import javax.media.nativewindow.util.PixelRectangle; import javax.media.nativewindow.util.Point; public class NewtMouseInput implements MouseInput, MouseListener { @@ -175,9 +182,9 @@ public class NewtMouseInput implements MouseInput, MouseListener { // listener.onMouseButtonEvent(evt); } - public void mousePressed(MouseEvent awtEvt) { - MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), true, awtEvt.getX(), awtEvt.getY()); - evt.setTime(awtEvt.getWhen()); + public void mousePressed(MouseEvent newtEvt) { + MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(newtEvt), true, newtEvt.getX(), newtEvt.getY()); + evt.setTime(newtEvt.getWhen()); synchronized (eventQueue) { eventQueue.add(evt); } @@ -281,5 +288,11 @@ public class NewtMouseInput implements MouseInput, MouseListener { } public void setNativeCursor(JmeCursor cursor) { + final ByteBuffer pixels = Buffers.copyIntBufferAsByteBuffer(cursor.getImagesData()); + final DimensionImmutable size = new Dimension(cursor.getWidth(), cursor.getHeight()); + final PixelFormat pixFormat = PixelFormat.RGBA8888; + final PixelRectangle.GenericPixelRect rec = new PixelRectangle.GenericPixelRect(pixFormat, size, 0, true, pixels); + final PointerIcon joglCursor = component.getScreen().getDisplay().createPointerIcon(rec, cursor.getXHotSpot(), cursor.getYHotSpot()); + component.setPointerIcon(joglCursor); } } \ No newline at end of file