mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
Infdev cursor grab: the Pojav part
Also featuring: Window resize on first key even poll
This commit is contained in:
parent
328581c2a9
commit
693cff45b0
Binary file not shown.
@ -1 +1 @@
|
||||
HEllo PeoplE
|
||||
HEllo PeopLE
|
@ -252,11 +252,14 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNI
|
||||
return pasteDst;
|
||||
}
|
||||
|
||||
void Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(JNIEnv* env, jclass clazz, jint width, jint height);
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputReady(JNIEnv* env, jclass clazz, jboolean inputReady) {
|
||||
#ifdef DEBUG
|
||||
LOGD("Debug: Changing input state, isReady=%d, isUseStackQueueCall=%d\n", inputReady, isUseStackQueueCall);
|
||||
#endif
|
||||
isInputReady = inputReady;
|
||||
if(isInputReady) Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(NULL, NULL, savedWidth, savedHeight);
|
||||
return isUseStackQueueCall;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ jar {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
}
|
||||
}
|
||||
exclude 'net/java/openjdk/cacio/ctc/**'
|
||||
}
|
||||
|
||||
java {
|
||||
|
@ -0,0 +1,6 @@
|
||||
package net.java.openjdk.cacio.ctc;
|
||||
|
||||
public interface ExternalMouseReader {
|
||||
int getX();
|
||||
int getY();
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package net.java.openjdk.cacio.ctc;
|
||||
|
||||
public class InfdevGrabHandler {
|
||||
public static void setMouseReader(ExternalMouseReader reader) {
|
||||
|
||||
}
|
||||
public static void setGrabbed(boolean grabbed) {
|
||||
|
||||
}
|
||||
}
|
@ -29,6 +29,9 @@ public class Cursor {
|
||||
/** Flag set when the cursor has been destroyed */
|
||||
private boolean destroyed;
|
||||
|
||||
/** Flag set if the cursor is empty */
|
||||
private boolean isEmpty;
|
||||
|
||||
/**
|
||||
* Constructs a new Cursor, with the given parameters. Mouse must have been
|
||||
* created before you can create Cursor objects. Cursor images are in ARGB
|
||||
@ -59,14 +62,19 @@ public class Cursor {
|
||||
*/
|
||||
public Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays)
|
||||
throws LWJGLException {
|
||||
|
||||
cursors = new CursorElement[numImages];
|
||||
|
||||
IntBuffer flippedImages = BufferUtils.createIntBuffer(images.limit());
|
||||
flipImages(width, height, numImages, images, flippedImages);
|
||||
|
||||
ByteBuffer pixels = convertARGBIntBuffertoRGBAByteBuffer(width, height, flippedImages);
|
||||
|
||||
if(numImages == 1) {
|
||||
isEmpty = true;
|
||||
for(int i = 0; i < width*height; i++) if(pixels.get(i) != 0) {
|
||||
System.out.println("Encountered non-zero byte at "+i+", custom cursor is not empty!");
|
||||
isEmpty = false;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < numImages; i++) {
|
||||
int size = width * height;
|
||||
ByteBuffer image = BufferUtils.createByteBuffer(size);
|
||||
@ -248,6 +256,14 @@ public class Cursor {
|
||||
index = ++index % cursors.length;
|
||||
}
|
||||
|
||||
/**
|
||||
/* Returns wheteher the cursor image is empty or not
|
||||
*/
|
||||
|
||||
/*package-private*/ boolean isEmpty() {
|
||||
return isEmpty;
|
||||
}
|
||||
|
||||
/**
|
||||
* A single cursor element, used when animating
|
||||
*/
|
||||
@ -266,5 +282,4 @@ public class Cursor {
|
||||
throw new RuntimeException("Error creating GLFW cursor");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package org.lwjgl.input;
|
||||
|
||||
import net.java.openjdk.cacio.ctc.ExternalMouseReader;
|
||||
import net.java.openjdk.cacio.ctc.InfdevGrabHandler;
|
||||
|
||||
public class InfdevMouse implements ExternalMouseReader, Mouse.EmptyCursorGrabListener {
|
||||
static {
|
||||
InfdevGrabHandler.setMouseReader(new InfdevMouse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return Mouse.getAbsoluteX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return Mouse.getAbsoluteY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGrab(boolean grabbing) {
|
||||
InfdevGrabHandler.setGrabbed(grabbing);
|
||||
}
|
||||
}
|
@ -31,6 +31,7 @@
|
||||
*/
|
||||
package org.lwjgl.input;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.security.AccessController;
|
||||
@ -144,6 +145,7 @@ public class Mouse {
|
||||
private static boolean isGrabbed;
|
||||
|
||||
private static InputImplementation implementation;
|
||||
private static EmptyCursorGrabListener grabListener = null;
|
||||
|
||||
/** Whether we need cursor animation emulation */
|
||||
private static final boolean emulateCursorAnimation = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS ||
|
||||
@ -151,6 +153,16 @@ public class Mouse {
|
||||
|
||||
private static boolean clipMouseCoordinatesToWindow = !getPrivilegedBoolean("org.lwjgl.input.Mouse.allowNegativeMouseCoords");
|
||||
|
||||
static {
|
||||
try {
|
||||
Class infdevMouse = Class.forName("org.lwjgl.input.InfdevMouse");
|
||||
Constructor constructor = infdevMouse.getConstructor();
|
||||
grabListener = (EmptyCursorGrabListener) constructor.newInstance();
|
||||
}catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mouse cannot be constructed.
|
||||
*/
|
||||
@ -164,7 +176,6 @@ public class Mouse {
|
||||
*/
|
||||
public static Cursor getNativeCursor() {
|
||||
return currentCursor;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,6 +192,14 @@ public class Mouse {
|
||||
*/
|
||||
public static Cursor setNativeCursor(Cursor cursor) throws LWJGLException {
|
||||
//dummy
|
||||
if(cursor == null && currentCursor.isEmpty()) {
|
||||
Mouse.setGrabbed(false);
|
||||
if(grabListener != null) grabListener.onGrab(false);
|
||||
}
|
||||
if(cursor != null && cursor.isEmpty()) {
|
||||
Mouse.setGrabbed(true);
|
||||
if(grabListener != null) grabListener.onGrab(true);
|
||||
}
|
||||
currentCursor = cursor;
|
||||
return currentCursor;
|
||||
}
|
||||
@ -625,4 +644,18 @@ public class Mouse {
|
||||
public static boolean isInsideWindow() {
|
||||
return implementation.isInsideWindow();
|
||||
}
|
||||
|
||||
/*
|
||||
* Package private methods to get the absolute unclipped X/Y coordiates
|
||||
*/
|
||||
/*package-private*/ static int getAbsoluteX() {
|
||||
return absolute_x;
|
||||
}
|
||||
/*package-private*/ static int getAbsoluteY() {
|
||||
return absolute_y;
|
||||
}
|
||||
|
||||
interface EmptyCursorGrabListener {
|
||||
void onGrab(boolean grabbing);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user