Search in sources :

Example 1 with Cursor

use of org.lwjgl.input.Cursor in project Voxel_Game by ASasseCreations.

the class MouseSystem method getCursor.

public static final Cursor getCursor(final BufferedImage img) throws LWJGLException {
    final int w = img.getWidth();
    final int h = img.getHeight();
    final int[] rgbData = new int[w * h];
    for (int i = 0; i < rgbData.length; i++) {
        final int x = i % w;
        final int y = h - 1 - i / w;
        rgbData[i] = img.getRGB(x, y);
    }
    final IntBuffer buffer = BufferUtils.createIntBuffer(w * h);
    buffer.put(rgbData);
    buffer.rewind();
    return new Cursor(w, h, 0, h - 1, 1, buffer, null);
}
Also used : IntBuffer(java.nio.IntBuffer) Cursor(org.lwjgl.input.Cursor)

Example 2 with Cursor

use of org.lwjgl.input.Cursor in project Catacomb-Snatch by Catacomb-Snatch.

the class DesktopLauncher method main.

public static void main(String[] arg) {
    System.out.println("Starting game in DESKTOP mode!");
    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    // TODO Re-enable if it got fixed on all systems (currently throws a shader error)
    // config.useGL30 = true;
    config.title = "Catacomb Snatch";
    config.width = GAME_WIDTH;
    config.height = GAME_HEIGHT;
    new LwjglApplication(new CatacombSnatch(new PlatformDependent() {

        @Override
        public void create() {
            // Set game cursor
            try {
                int size = 16, center = (size / 2);
                IntBuffer buffer = BufferUtils.newIntBuffer(size * size);
                int x = 0, y = 0;
                for (int n = 0; n < buffer.limit(); n++) {
                    if ((x == center || y == center) && (x < center - 1 || y < center - 1 || x > center + 1 || y > center + 1)) {
                        buffer = buffer.put(n, 0xFFFFFFFF);
                    }
                    x++;
                    if (x == size) {
                        x = 0;
                        y++;
                    }
                }
                Mouse.setNativeCursor(new Cursor(size, size, center, center, 1, buffer, null));
            } catch (LWJGLException e) {
                System.err.print("Error setting native cursor!\n" + e);
            }
        }

        @Override
        public Object[] createPlatformObjects() {
            throw new UnsupportedOperationException("Unimplemented");
        }

        @Override
        public void dispose() {
        }
    }), config);
}
Also used : PlatformDependent(net.catacombsnatch.game.PlatformDependent) LwjglApplication(com.badlogic.gdx.backends.lwjgl.LwjglApplication) CatacombSnatch(net.catacombsnatch.game.CatacombSnatch) IntBuffer(java.nio.IntBuffer) LwjglApplicationConfiguration(com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration) Cursor(org.lwjgl.input.Cursor) LWJGLException(org.lwjgl.LWJGLException)

Example 3 with Cursor

use of org.lwjgl.input.Cursor in project jmonkeyengine by jMonkeyEngine.

the class LwjglMouseInput method setNativeCursor.

public void setNativeCursor(JmeCursor jmeCursor) {
    try {
        Cursor newCursor = null;
        if (jmeCursor != null) {
            newCursor = cursorMap.get(jmeCursor);
            if (newCursor == null) {
                newCursor = new Cursor(jmeCursor.getWidth(), jmeCursor.getHeight(), jmeCursor.getXHotSpot(), jmeCursor.getYHotSpot(), jmeCursor.getNumImages(), jmeCursor.getImagesData(), jmeCursor.getImagesDelay());
                // Add to cache
                cursorMap.put(jmeCursor, newCursor);
            }
        }
        Mouse.setNativeCursor(newCursor);
    } catch (LWJGLException ex) {
        Logger.getLogger(LwjglMouseInput.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : JmeCursor(com.jme3.cursors.plugins.JmeCursor) Cursor(org.lwjgl.input.Cursor) LWJGLException(org.lwjgl.LWJGLException)

Example 4 with Cursor

use of org.lwjgl.input.Cursor in project jmonkeyengine by jMonkeyEngine.

the class LwjglMouseInput method destroy.

public void destroy() {
    if (!context.isRenderable())
        return;
    Mouse.destroy();
    // Destroy the cursor cache
    for (Cursor cursor : cursorMap.values()) {
        cursor.destroy();
    }
    cursorMap.clear();
    logger.fine("Mouse destroyed.");
}
Also used : JmeCursor(com.jme3.cursors.plugins.JmeCursor) Cursor(org.lwjgl.input.Cursor)

Example 5 with Cursor

use of org.lwjgl.input.Cursor in project lwjgl by LWJGL.

the class HWCursorTest method processKeyboard.

/**
	 * Processes keyboard input
	 */
private void processKeyboard() {
    //check for fullscreen key
    if (Keyboard.isKeyDown(Keyboard.KEY_F)) {
        try {
            try {
                Mouse.setNativeCursor(null);
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
            for (Cursor aCursor : cursors) {
                aCursor.destroy();
            }
            Display.setFullscreen(true);
            glInit();
            initNativeCursors();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //check for window key
    if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
        try {
            try {
                Mouse.setNativeCursor(null);
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
            for (Cursor cursor : cursors) {
                cursor.destroy();
            }
            Display.setFullscreen(false);
            glInit();
            initNativeCursors();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_M)) {
        try {
            Mouse.setNativeCursor(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_N)) {
        switchCursor();
    }
    while (Keyboard.next()) {
        if (Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState()) {
            Mouse.setGrabbed(!Mouse.isGrabbed());
        }
    }
}
Also used : Cursor(org.lwjgl.input.Cursor)

Aggregations

Cursor (org.lwjgl.input.Cursor)6 IntBuffer (java.nio.IntBuffer)3 JmeCursor (com.jme3.cursors.plugins.JmeCursor)2 LWJGLException (org.lwjgl.LWJGLException)2 LwjglApplication (com.badlogic.gdx.backends.lwjgl.LwjglApplication)1 LwjglApplicationConfiguration (com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration)1 CatacombSnatch (net.catacombsnatch.game.CatacombSnatch)1 PlatformDependent (net.catacombsnatch.game.PlatformDependent)1