mirror of
https://github.com/GTNewHorizons/lwjgl3ify.git
synced 2026-11-21 04:32:30 +00:00
Fix fractional scrolling, add scroll inversion and speed controls
This commit is contained in:
1 parent
56e3a91419
commit
9fe911bd6f
3 files changed
+39
-11
No files matched your search
@@ -61,6 +61,9 @@ public class Config {
|
||||
public static boolean OPENGL_DOUBLEBUFFER = true;
|
||||
public static boolean OPENGL_CONTEXT_NO_ERROR = false;
|
||||
|
||||
public static boolean INPUT_INVERT_WHEEL = false;
|
||||
public static double INPUT_SCROLL_SPEED = 1.0;
|
||||
|
||||
public static String X11_CLASS_NAME = "minecraft";
|
||||
public static String COCOA_FRAME_NAME = "minecraft";
|
||||
|
||||
@@ -79,6 +82,7 @@ public class Config {
|
||||
final Configuration config = new Configuration(configFile);
|
||||
final String CATEGORY_CORE = "core";
|
||||
final String CATEGORY_WINDOW = "window";
|
||||
final String CATEGORY_INPUT = "input";
|
||||
final String CATEGORY_GLCONTEXT = "openglContext";
|
||||
EXTENSIBLE_ENUMS.addAll(Arrays.asList(config.get(
|
||||
CATEGORY_CORE,
|
||||
@@ -114,6 +118,16 @@ public class Config {
|
||||
COCOA_FRAME_NAME,
|
||||
"OSX-only - identifier used to save and restore the window position and size");
|
||||
|
||||
INPUT_INVERT_WHEEL = config.getBoolean(
|
||||
"invertScrollWheel", CATEGORY_INPUT, INPUT_INVERT_WHEEL, "Invert scrolling direction");
|
||||
INPUT_SCROLL_SPEED = (double) config.getFloat(
|
||||
"scrollSpeedMultiplier",
|
||||
CATEGORY_INPUT,
|
||||
(float) INPUT_SCROLL_SPEED,
|
||||
+0.05f,
|
||||
+20.0f,
|
||||
"Scrolling speed multiplier");
|
||||
|
||||
OPENGL_DEBUG_CONTEXT = config.getBoolean(
|
||||
"debugContext",
|
||||
CATEGORY_GLCONTEXT,
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.lwjglx.input;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import me.eigenraven.lwjgl3ify.core.Config;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
@@ -86,21 +87,34 @@ public class Mouse {
|
||||
queue.add();
|
||||
}
|
||||
|
||||
public static void addWheelEvent(int dwheel) {
|
||||
lastxEvents[queue.getNextPos()] = xEvents[queue.getNextPos()];
|
||||
lastyEvents[queue.getNextPos()] = yEvents[queue.getNextPos()];
|
||||
static double fractionalWheelPosition = 0.0;
|
||||
|
||||
xEvents[queue.getNextPos()] = latestX;
|
||||
yEvents[queue.getNextPos()] = latestY;
|
||||
public static void addWheelEvent(double dwheel) {
|
||||
if (Config.INPUT_INVERT_WHEEL) {
|
||||
dwheel = -dwheel;
|
||||
}
|
||||
dwheel *= Config.INPUT_SCROLL_SPEED;
|
||||
|
||||
wheelEvents[queue.getNextPos()] = dwheel;
|
||||
final int lastWheel = (int) fractionalWheelPosition;
|
||||
fractionalWheelPosition += dwheel;
|
||||
final int newWheel = (int) fractionalWheelPosition;
|
||||
if (newWheel != lastWheel) {
|
||||
lastxEvents[queue.getNextPos()] = xEvents[queue.getNextPos()];
|
||||
lastyEvents[queue.getNextPos()] = yEvents[queue.getNextPos()];
|
||||
|
||||
buttonEvents[queue.getNextPos()] = -1;
|
||||
buttonEventStates[queue.getNextPos()] = false;
|
||||
xEvents[queue.getNextPos()] = latestX;
|
||||
yEvents[queue.getNextPos()] = latestY;
|
||||
|
||||
nanoTimeEvents[queue.getNextPos()] = Sys.getNanoTime();
|
||||
wheelEvents[queue.getNextPos()] = newWheel - lastWheel;
|
||||
|
||||
queue.add();
|
||||
buttonEvents[queue.getNextPos()] = -1;
|
||||
buttonEventStates[queue.getNextPos()] = false;
|
||||
|
||||
nanoTimeEvents[queue.getNextPos()] = Sys.getNanoTime();
|
||||
|
||||
queue.add();
|
||||
}
|
||||
fractionalWheelPosition = fractionalWheelPosition % 1;
|
||||
}
|
||||
|
||||
public static void poll() {
|
||||
|
||||
@@ -176,7 +176,7 @@ public class Display {
|
||||
Window.scrollCallback = new GLFWScrollCallback() {
|
||||
@Override
|
||||
public void invoke(long window, double xoffset, double yoffset) {
|
||||
Mouse.addWheelEvent((int) Math.round(yoffset));
|
||||
Mouse.addWheelEvent(yoffset);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user