Search in sources :

Example 1 with PointerIcon

use of com.jogamp.newt.Display.PointerIcon in project jmonkeyengine by jMonkeyEngine.

the class NewtMouseInput method setNativeCursor.

@Override
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.getHeight() - cursor.getYHotSpot());
    component.setPointerIcon(joglCursor);
}
Also used : DimensionImmutable(com.jogamp.nativewindow.util.DimensionImmutable) PixelRectangle(com.jogamp.nativewindow.util.PixelRectangle) PixelFormat(com.jogamp.nativewindow.util.PixelFormat) Dimension(com.jogamp.nativewindow.util.Dimension) ByteBuffer(java.nio.ByteBuffer) PointerIcon(com.jogamp.newt.Display.PointerIcon)

Example 2 with PointerIcon

use of com.jogamp.newt.Display.PointerIcon in project processing by processing.

the class PSurfaceJOGL method setCursor.

public void setCursor(PImage image, int hotspotX, int hotspotY) {
    Display disp = window.getScreen().getDisplay();
    BufferedImage bimg = (BufferedImage) image.getNative();
    DataBufferInt dbuf = (DataBufferInt) bimg.getData().getDataBuffer();
    int[] ipix = dbuf.getData();
    ByteBuffer pixels = ByteBuffer.allocate(ipix.length * 4);
    pixels.asIntBuffer().put(ipix);
    PixelFormat format = PixelFormat.ARGB8888;
    final Dimension size = new Dimension(bimg.getWidth(), bimg.getHeight());
    PixelRectangle pixelrect = new PixelRectangle.GenericPixelRect(format, size, 0, false, pixels);
    final PointerIcon pi = disp.createPointerIcon(pixelrect, hotspotX, hotspotY);
    display.getEDTUtil().invoke(false, new Runnable() {

        @Override
        public void run() {
            window.setPointerIcon(pi);
        }
    });
}
Also used : PixelRectangle(com.jogamp.nativewindow.util.PixelRectangle) PixelFormat(com.jogamp.nativewindow.util.PixelFormat) DataBufferInt(java.awt.image.DataBufferInt) Dimension(com.jogamp.nativewindow.util.Dimension) ByteBuffer(java.nio.ByteBuffer) BufferedImage(java.awt.image.BufferedImage) PointerIcon(com.jogamp.newt.Display.PointerIcon) Display(com.jogamp.newt.Display)

Aggregations

Dimension (com.jogamp.nativewindow.util.Dimension)2 PixelFormat (com.jogamp.nativewindow.util.PixelFormat)2 PixelRectangle (com.jogamp.nativewindow.util.PixelRectangle)2 PointerIcon (com.jogamp.newt.Display.PointerIcon)2 ByteBuffer (java.nio.ByteBuffer)2 DimensionImmutable (com.jogamp.nativewindow.util.DimensionImmutable)1 Display (com.jogamp.newt.Display)1 BufferedImage (java.awt.image.BufferedImage)1 DataBufferInt (java.awt.image.DataBufferInt)1