Search in sources :

Example 1 with Dimension

use of com.jogamp.nativewindow.util.Dimension 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 Dimension

use of com.jogamp.nativewindow.util.Dimension in project jmonkeyengine by jMonkeyEngine.

the class JoglNewtDisplay method applySettings.

protected void applySettings(AppSettings settings) {
    active.set(true);
    canvas.addWindowListener(new WindowAdapter() {

        @Override
        public void windowDestroyNotify(WindowEvent e) {
            windowCloseRequest.set(true);
        }

        @Override
        public void windowGainedFocus(WindowEvent e) {
            active.set(true);
        }

        @Override
        public void windowLostFocus(WindowEvent e) {
            active.set(false);
        }
    });
    canvas.setSize(settings.getWidth(), settings.getHeight());
    canvas.setUndecorated(settings.isFullscreen());
    canvas.setFullscreen(settings.isFullscreen());
    /**
         * uses the filtering relying on resolution with the size to fetch only
         * the screen mode matching with the current resolution
         */
    Screen screen = canvas.getScreen();
    /**
         * The creation of native resources is lazy in JogAmp, i.e they are 
         * created only when they are used for the first time. When the GLWindow
         * is not yet visible, its screen might have been unused for now and 
         * then its native counterpart has not yet been created. That's why 
         * forcing the creation of this resource is necessary
         */
    screen.addReference();
    if (settings.isFullscreen()) {
        List<MonitorMode> screenModes = canvas.getMainMonitor().getSupportedModes();
        //the resolution is provided by the user
        Dimension dimension = new Dimension(settings.getWidth(), settings.getHeight());
        screenModes = MonitorModeUtil.filterByResolution(screenModes, dimension);
        screenModes = MonitorModeUtil.getHighestAvailableBpp(screenModes);
        if (settings.getFrequency() > 0) {
            screenModes = MonitorModeUtil.filterByRate(screenModes, settings.getFrequency());
        } else {
            screenModes = MonitorModeUtil.getHighestAvailableRate(screenModes);
        }
        canvas.getMainMonitor().setCurrentMode(screenModes.get(0));
    }
    MonitorMode currentScreenMode = canvas.getMainMonitor().getCurrentMode();
    logger.log(Level.FINE, "Selected display mode: {0}x{1}x{2} @{3}", new Object[] { currentScreenMode.getRotatedWidth(), currentScreenMode.getRotatedHeight(), currentScreenMode.getSurfaceSize().getBitsPerPixel(), currentScreenMode.getRefreshRate() });
}
Also used : MonitorMode(com.jogamp.newt.MonitorMode) Screen(com.jogamp.newt.Screen) WindowEvent(com.jogamp.newt.event.WindowEvent) WindowAdapter(com.jogamp.newt.event.WindowAdapter) Dimension(com.jogamp.nativewindow.util.Dimension)

Example 3 with Dimension

use of com.jogamp.nativewindow.util.Dimension 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)3 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 MonitorMode (com.jogamp.newt.MonitorMode)1 Screen (com.jogamp.newt.Screen)1 WindowAdapter (com.jogamp.newt.event.WindowAdapter)1 WindowEvent (com.jogamp.newt.event.WindowEvent)1 BufferedImage (java.awt.image.BufferedImage)1 DataBufferInt (java.awt.image.DataBufferInt)1