Added Mouse Scroll Wheel Support
This commit is contained in:
parent
f6d521fe8a
commit
da61f834e5
3
.gitignore
vendored
3
.gitignore
vendored
@ -14,4 +14,5 @@ bin
|
||||
**/Thumbs.db
|
||||
|
||||
# Ignore MacOS
|
||||
**/.DS_Store
|
||||
**/.DS_Store
|
||||
.idea/
|
||||
|
@ -25,6 +25,31 @@ import ru.windcorp.optica.client.graphics.input.*;
|
||||
public class InputHandler {
|
||||
|
||||
private static final EventBus INPUT_EVENT_BUS = new EventBus("Input");
|
||||
|
||||
// ScrollEvent Start
|
||||
|
||||
private static class ModifiableWheelScrollEvent extends WheelScrollEvent {
|
||||
|
||||
public void initialize(double xoffset, double yoffset) {
|
||||
this.xoffset = xoffset;
|
||||
this.yoffset = yoffset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final ModifiableWheelScrollEvent THE_SCROLL_EVENT = new ModifiableWheelScrollEvent();
|
||||
|
||||
static void handleMouseWheel(
|
||||
long window,
|
||||
double xoffset,
|
||||
double yoffset
|
||||
) {
|
||||
if (GraphicsBackend.getWindowHandle() != window) return;
|
||||
THE_SCROLL_EVENT.initialize(xoffset, yoffset);
|
||||
dispatch(THE_SCROLL_EVENT);
|
||||
}
|
||||
|
||||
// KeyEvent Start
|
||||
|
||||
private static class ModifiableKeyEvent extends KeyEvent {
|
||||
|
||||
@ -36,7 +61,7 @@ public class InputHandler {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static final ModifiableKeyEvent THE_KEY_EVENT = new ModifiableKeyEvent();
|
||||
|
||||
static void handleKeyInput(
|
||||
@ -50,6 +75,8 @@ public class InputHandler {
|
||||
THE_KEY_EVENT.initialize(key, scancode, action, mods);
|
||||
dispatch(THE_KEY_EVENT);
|
||||
}
|
||||
|
||||
// CursorEvent Start
|
||||
|
||||
private static class ModifiableCursorMoveEvent extends CursorMoveEvent {
|
||||
|
||||
|
@ -86,12 +86,14 @@ class LWJGLInitializer {
|
||||
|
||||
private static void setupWindowCallbacks() {
|
||||
long handle = GraphicsBackend.getWindowHandle();
|
||||
|
||||
|
||||
glfwSetFramebufferSizeCallback(handle,
|
||||
GraphicsBackend::onFramebufferResized);
|
||||
|
||||
glfwSetKeyCallback(handle, InputHandler::handleKeyInput);
|
||||
glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput);
|
||||
|
||||
glfwSetScrollCallback(handle, InputHandler::handleMouseWheel);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,12 +39,14 @@ public class LayerTestUI extends AssembledFlatLayer {
|
||||
}
|
||||
|
||||
private boolean flag = false;
|
||||
|
||||
|
||||
private static int width = 512 + 256;
|
||||
private static final int height = 64;
|
||||
private static final int border = 5;
|
||||
|
||||
@Override
|
||||
protected void assemble(RenderTarget target) {
|
||||
final int width = 512 + 256;
|
||||
final int height = 64;
|
||||
final int border = 5;
|
||||
|
||||
|
||||
final int boxColor = flag ? 0xEE8888 : 0xEEEE88;
|
||||
final int borderColor = flag ? 0xAA4444 : 0xAAAA44;
|
||||
|
@ -27,7 +27,6 @@ public class KeyEvent extends InputEvent {
|
||||
protected int mods;
|
||||
|
||||
protected KeyEvent(int key, int scancode, int action, int mods) {
|
||||
this();
|
||||
this.key = key;
|
||||
this.scancode = scancode;
|
||||
this.action = action;
|
||||
|
@ -0,0 +1,7 @@
|
||||
package ru.windcorp.optica.client.graphics.input;
|
||||
|
||||
public abstract class WheelEvent extends InputEvent {
|
||||
|
||||
@Override
|
||||
public abstract WheelEvent snapshot();
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package ru.windcorp.optica.client.graphics.input;
|
||||
|
||||
import glm.vec._2.d.Vec2d;
|
||||
|
||||
public class WheelScrollEvent extends WheelEvent {
|
||||
|
||||
protected double xoffset;
|
||||
protected double yoffset;
|
||||
|
||||
protected WheelScrollEvent(double xoffset, double yoffset) {
|
||||
this.xoffset = xoffset;
|
||||
this.yoffset = yoffset;
|
||||
}
|
||||
|
||||
protected WheelScrollEvent() {}
|
||||
|
||||
public boolean isUp() { return yoffset > 0; }
|
||||
|
||||
public boolean isDown() { return yoffset < 0; }
|
||||
|
||||
public boolean isRight() { return xoffset > 0; }
|
||||
|
||||
public boolean isLeft() { return xoffset < 0; }
|
||||
|
||||
public boolean hasVerticalMovement() { return yoffset != 0; }
|
||||
|
||||
public boolean hasHorizontalMovement() { return xoffset != 0; }
|
||||
|
||||
public double getX() { return xoffset; }
|
||||
|
||||
public double getY() { return yoffset; }
|
||||
|
||||
@Override
|
||||
public WheelEvent snapshot() {
|
||||
return new StaticWheelScrollEvent(xoffset, yoffset, getTime());
|
||||
}
|
||||
|
||||
private class StaticWheelScrollEvent extends WheelScrollEvent {
|
||||
|
||||
private final double time;
|
||||
|
||||
public StaticWheelScrollEvent(double xoffset, double yoffset, double time) {
|
||||
super(xoffset, yoffset);
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTime() { return time; }
|
||||
|
||||
@Override
|
||||
public WheelEvent snapshot() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user