Search in sources :

Example 1 with PixelRectangle

use of com.jogamp.nativewindow.util.PixelRectangle 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)1 PixelFormat (com.jogamp.nativewindow.util.PixelFormat)1 PixelRectangle (com.jogamp.nativewindow.util.PixelRectangle)1 Display (com.jogamp.newt.Display)1 PointerIcon (com.jogamp.newt.Display.PointerIcon)1 BufferedImage (java.awt.image.BufferedImage)1 DataBufferInt (java.awt.image.DataBufferInt)1 ByteBuffer (java.nio.ByteBuffer)1