mirror of
https://github.com/GTNewHorizons/lwjgl3ify.git
synced 2026-11-23 13:39:55 +00:00
Add scrollwheel support
This commit is contained in:
1 parent
0a2257aca2
commit
46e135ecf4
2 files changed
+34
-3
No files matched your search
@@ -24,6 +24,7 @@ public class Mouse {
|
||||
private static boolean[] buttonEventStates = new boolean[queue.getMaxEvents()];
|
||||
private static int[] xEvents = new int[queue.getMaxEvents()];
|
||||
private static int[] yEvents = new int[queue.getMaxEvents()];
|
||||
private static int[] wheelEvents = new int[queue.getMaxEvents()];
|
||||
private static int[] lastxEvents = new int[queue.getMaxEvents()];
|
||||
private static int[] lastyEvents = new int[queue.getMaxEvents()];
|
||||
private static long[] nanoTimeEvents = new long[queue.getMaxEvents()];
|
||||
@@ -40,6 +41,8 @@ public class Mouse {
|
||||
xEvents[queue.getNextPos()] = latestX;
|
||||
yEvents[queue.getNextPos()] = latestY;
|
||||
|
||||
wheelEvents[queue.getNextPos()] = 0;
|
||||
|
||||
buttonEvents[queue.getNextPos()] = -1;
|
||||
buttonEventStates[queue.getNextPos()] = false;
|
||||
|
||||
@@ -55,6 +58,8 @@ public class Mouse {
|
||||
xEvents[queue.getNextPos()] = latestX;
|
||||
yEvents[queue.getNextPos()] = latestY;
|
||||
|
||||
wheelEvents[queue.getNextPos()] = 0;
|
||||
|
||||
buttonEvents[queue.getNextPos()] = button;
|
||||
buttonEventStates[queue.getNextPos()] = pressed;
|
||||
|
||||
@@ -63,6 +68,23 @@ public class Mouse {
|
||||
queue.add();
|
||||
}
|
||||
|
||||
public static void addWheelEvent(int dwheel) {
|
||||
lastxEvents[queue.getNextPos()] = xEvents[queue.getNextPos()];
|
||||
lastyEvents[queue.getNextPos()] = yEvents[queue.getNextPos()];
|
||||
|
||||
xEvents[queue.getNextPos()] = latestX;
|
||||
yEvents[queue.getNextPos()] = latestY;
|
||||
|
||||
wheelEvents[queue.getNextPos()] = dwheel;
|
||||
|
||||
buttonEvents[queue.getNextPos()] = -1;
|
||||
buttonEventStates[queue.getNextPos()] = false;
|
||||
|
||||
nanoTimeEvents[queue.getNextPos()] = Sys.getNanoTime();
|
||||
|
||||
queue.add();
|
||||
}
|
||||
|
||||
public static void poll() {
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
@@ -131,7 +153,7 @@ public class Mouse {
|
||||
}
|
||||
|
||||
public static int getEventDWheel() {
|
||||
return 0; // TODO
|
||||
return wheelEvents[queue.getCurrentPos()];
|
||||
}
|
||||
|
||||
public static int getX() {
|
||||
@@ -151,8 +173,7 @@ public class Mouse {
|
||||
}
|
||||
|
||||
public static int getDWheel() {
|
||||
// TODO
|
||||
return 0;
|
||||
return getEventDWheel();
|
||||
}
|
||||
|
||||
public static int getButtonCount() {
|
||||
|
||||
@@ -153,6 +153,13 @@ public class Display {
|
||||
}
|
||||
};
|
||||
|
||||
Window.scrollCallback = new GLFWScrollCallback() {
|
||||
@Override
|
||||
public void invoke(long window, double xoffset, double yoffset) {
|
||||
Mouse.addWheelEvent((int) Math.round(yoffset));
|
||||
}
|
||||
};
|
||||
|
||||
Window.windowFocusCallback = new GLFWWindowFocusCallback() {
|
||||
@Override
|
||||
public void close() {
|
||||
@@ -499,6 +506,7 @@ public class Display {
|
||||
static GLFWCharCallback charCallback;
|
||||
static GLFWCursorPosCallback cursorPosCallback;
|
||||
static GLFWMouseButtonCallback mouseButtonCallback;
|
||||
static GLFWScrollCallback scrollCallback;
|
||||
static GLFWWindowFocusCallback windowFocusCallback;
|
||||
static GLFWWindowIconifyCallback windowIconifyCallback;
|
||||
static GLFWWindowSizeCallback windowSizeCallback;
|
||||
@@ -511,6 +519,7 @@ public class Display {
|
||||
GLFW.glfwSetCharCallback(handle, charCallback);
|
||||
GLFW.glfwSetCursorPosCallback(handle, cursorPosCallback);
|
||||
GLFW.glfwSetMouseButtonCallback(handle, mouseButtonCallback);
|
||||
GLFW.glfwSetScrollCallback(handle, scrollCallback);
|
||||
GLFW.glfwSetWindowFocusCallback(handle, windowFocusCallback);
|
||||
GLFW.glfwSetWindowIconifyCallback(handle, windowIconifyCallback);
|
||||
GLFW.glfwSetWindowSizeCallback(handle, windowSizeCallback);
|
||||
@@ -524,6 +533,7 @@ public class Display {
|
||||
charCallback.free();
|
||||
cursorPosCallback.free();
|
||||
mouseButtonCallback.free();
|
||||
scrollCallback.free();
|
||||
windowFocusCallback.free();
|
||||
windowIconifyCallback.free();
|
||||
windowSizeCallback.free();
|
||||
|
||||
Reference in new issue
Block a user