mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-05 06:25:46 +00:00
Moved native cursors to DisplayImplementation
This commit is contained in:
parent
a46706b752
commit
5b1b513aab
6 changed files with 49 additions and 27 deletions
|
|
@ -38,6 +38,7 @@ import org.lwjgl.LWJGLException;
|
|||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.BufferChecks;
|
||||
import org.lwjgl.Sys;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
|
|
@ -50,7 +51,6 @@ import org.lwjgl.Sys;
|
|||
*/
|
||||
|
||||
public class Cursor {
|
||||
private final static int HANDLE_SIZE = 8;
|
||||
/** First element to display */
|
||||
private final CursorElement[] cursors;
|
||||
|
||||
|
|
@ -115,8 +115,7 @@ public class Cursor {
|
|||
// create our cursor elements
|
||||
cursors = new CursorElement[numImages];
|
||||
for(int i=0; i<numImages; i++) {
|
||||
ByteBuffer handle = BufferUtils.createByteBuffer(HANDLE_SIZE);
|
||||
nCreateCursor(handle, width, height, xHotspot, yHotspot, 1, images_copy, images_copy.position(), null, 0);
|
||||
Object handle = Display.getImplementation().createCursor(width, height, xHotspot, yHotspot, 1, images_copy, null);
|
||||
long delay = (delays != null) ? delays.get(i) : 0;
|
||||
long timeout = System.currentTimeMillis();
|
||||
cursors[i] = new CursorElement(handle, delay, timeout);
|
||||
|
|
@ -126,8 +125,7 @@ public class Cursor {
|
|||
}
|
||||
} else if (osName.startsWith("Lin")) {
|
||||
// create our cursor elements
|
||||
ByteBuffer handle = BufferUtils.createByteBuffer(HANDLE_SIZE);
|
||||
nCreateCursor(handle, width, height, xHotspot, yHotspot, numImages, images_copy, images_copy.position(), delays, delays != null ? delays.position() : -1);
|
||||
Object handle = Display.getImplementation().createCursor(width, height, xHotspot, yHotspot, numImages, images_copy, delays);
|
||||
CursorElement cursor_element = new CursorElement(handle, -1, -1);
|
||||
cursors = new CursorElement[]{cursor_element};
|
||||
} else {
|
||||
|
|
@ -176,7 +174,7 @@ public class Cursor {
|
|||
/**
|
||||
* Gets the native handle associated with the cursor object.
|
||||
*/
|
||||
ByteBuffer getHandle() {
|
||||
Object getHandle() {
|
||||
return cursors[index].cursorHandle;
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +192,7 @@ public class Cursor {
|
|||
}
|
||||
}
|
||||
for(int i=0; i<cursors.length; i++) {
|
||||
nDestroyCursor(cursors[i].cursorHandle);
|
||||
Display.getImplementation().destroyCursor(cursors[i].cursorHandle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -220,22 +218,12 @@ public class Cursor {
|
|||
index = ++index % cursors.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Native method to create a native cursor
|
||||
*/
|
||||
private static native void nCreateCursor(ByteBuffer handle, int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException;
|
||||
|
||||
/**
|
||||
* Native method to destroy a native cursor
|
||||
*/
|
||||
private static native void nDestroyCursor(ByteBuffer cursorHandle);
|
||||
|
||||
/**
|
||||
* A single cursor element, used when animating
|
||||
*/
|
||||
private static class CursorElement {
|
||||
/** Handle to cursor */
|
||||
final ByteBuffer cursorHandle;
|
||||
final Object cursorHandle;
|
||||
|
||||
/** How long a delay this element should have */
|
||||
final long delay;
|
||||
|
|
@ -243,7 +231,7 @@ public class Cursor {
|
|||
/** Absolute time this element times out */
|
||||
long timeout;
|
||||
|
||||
CursorElement(ByteBuffer cursorHandle, long delay, long timeout) {
|
||||
CursorElement(Object cursorHandle, long delay, long timeout) {
|
||||
this.cursorHandle = cursorHandle;
|
||||
this.delay = delay;
|
||||
this.timeout = timeout;
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ public interface DisplayImplementation {
|
|||
public int getNativeCursorCaps();
|
||||
|
||||
/** Native method to set the native cursor */
|
||||
public void setNativeCursor(ByteBuffer handle) throws LWJGLException;
|
||||
public void setNativeCursor(Object handle) throws LWJGLException;
|
||||
|
||||
/** Native method returning the minimum cursor size */
|
||||
public int getMinCursorSize();
|
||||
|
|
@ -229,4 +229,9 @@ public interface DisplayImplementation {
|
|||
public void enableKeyboardBuffer() throws LWJGLException;
|
||||
|
||||
public int isStateKeySet(int key);
|
||||
|
||||
/** Native cursor handles */
|
||||
public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException;
|
||||
|
||||
public void destroyCursor(Object cursor_handle);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,10 +41,14 @@ package org.lwjgl.opengl;
|
|||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
final class LinuxDisplay implements DisplayImplementation {
|
||||
private final static int CURSOR_HANDLE_SIZE = 8;
|
||||
|
||||
public native void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException;
|
||||
public native void destroyWindow();
|
||||
public native void switchDisplayMode(DisplayMode mode) throws LWJGLException;
|
||||
|
|
@ -77,7 +81,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
public native int readMouse(IntBuffer buffer, int buffer_position);
|
||||
public native void grabMouse(boolean grab);
|
||||
public native int getNativeCursorCaps();
|
||||
public native void setNativeCursor(ByteBuffer handle) throws LWJGLException;
|
||||
public native void setNativeCursor(Object handle) throws LWJGLException;
|
||||
public native int getMinCursorSize();
|
||||
public native int getMaxCursorSize();
|
||||
/* Keyboard */
|
||||
|
|
@ -88,4 +92,14 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
public native void enableTranslation() throws LWJGLException;
|
||||
public native void enableKeyboardBuffer() throws LWJGLException;
|
||||
public native int isStateKeySet(int key);
|
||||
|
||||
public native void nCreateCursor(ByteBuffer handle, int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException;
|
||||
|
||||
public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
|
||||
ByteBuffer handle = BufferUtils.createByteBuffer(CURSOR_HANDLE_SIZE);
|
||||
nCreateCursor(handle, width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1);
|
||||
return handle;
|
||||
}
|
||||
|
||||
public native void destroyCursor(Object cursorHandle);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,10 +41,14 @@ package org.lwjgl.opengl;
|
|||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
final class Win32Display implements DisplayImplementation {
|
||||
private final static int CURSOR_HANDLE_SIZE = 8;
|
||||
|
||||
public native void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException;
|
||||
public native void destroyWindow();
|
||||
public native void switchDisplayMode(DisplayMode mode) throws LWJGLException;
|
||||
|
|
@ -77,7 +81,7 @@ final class Win32Display implements DisplayImplementation {
|
|||
public native int readMouse(IntBuffer buffer, int buffer_position);
|
||||
public native void grabMouse(boolean grab);
|
||||
public native int getNativeCursorCaps();
|
||||
public native void setNativeCursor(ByteBuffer handle) throws LWJGLException;
|
||||
public native void setNativeCursor(Object handle) throws LWJGLException;
|
||||
public native int getMinCursorSize();
|
||||
public native int getMaxCursorSize();
|
||||
/* Keyboard */
|
||||
|
|
@ -88,4 +92,14 @@ final class Win32Display implements DisplayImplementation {
|
|||
public native void enableTranslation() throws LWJGLException;
|
||||
public native void enableKeyboardBuffer() throws LWJGLException;
|
||||
public native int isStateKeySet(int key);
|
||||
|
||||
public native void nCreateCursor(ByteBuffer handle, int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException;
|
||||
|
||||
public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
|
||||
ByteBuffer handle = BufferUtils.createByteBuffer(CURSOR_HANDLE_SIZE);
|
||||
nCreateCursor(handle, width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1);
|
||||
return handle;
|
||||
}
|
||||
|
||||
public native void destroyCursor(Object cursorHandle);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue