diff --git a/.gitignore b/.gitignore index dfbf4ee..9edc0b1 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ bin **/Thumbs.db # Ignore MacOS -**/.DS_Store \ No newline at end of file +**/.DS_Store +.idea/ diff --git a/src/main/java/ru/windcorp/optica/client/graphics/backend/InputHandler.java b/src/main/java/ru/windcorp/optica/client/graphics/backend/InputHandler.java index f990463..38e835a 100644 --- a/src/main/java/ru/windcorp/optica/client/graphics/backend/InputHandler.java +++ b/src/main/java/ru/windcorp/optica/client/graphics/backend/InputHandler.java @@ -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 { diff --git a/src/main/java/ru/windcorp/optica/client/graphics/backend/LWJGLInitializer.java b/src/main/java/ru/windcorp/optica/client/graphics/backend/LWJGLInitializer.java index dd69d0f..0d5edeb 100644 --- a/src/main/java/ru/windcorp/optica/client/graphics/backend/LWJGLInitializer.java +++ b/src/main/java/ru/windcorp/optica/client/graphics/backend/LWJGLInitializer.java @@ -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); } } diff --git a/src/main/java/ru/windcorp/optica/client/graphics/flat/LayerTestUI.java b/src/main/java/ru/windcorp/optica/client/graphics/flat/LayerTestUI.java index fcad0b9..1afc76e 100644 --- a/src/main/java/ru/windcorp/optica/client/graphics/flat/LayerTestUI.java +++ b/src/main/java/ru/windcorp/optica/client/graphics/flat/LayerTestUI.java @@ -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; diff --git a/src/main/java/ru/windcorp/optica/client/graphics/input/KeyEvent.java b/src/main/java/ru/windcorp/optica/client/graphics/input/KeyEvent.java index 8c9fe89..4493f57 100644 --- a/src/main/java/ru/windcorp/optica/client/graphics/input/KeyEvent.java +++ b/src/main/java/ru/windcorp/optica/client/graphics/input/KeyEvent.java @@ -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; diff --git a/src/main/java/ru/windcorp/optica/client/graphics/input/WheelEvent.java b/src/main/java/ru/windcorp/optica/client/graphics/input/WheelEvent.java new file mode 100644 index 0000000..f21b088 --- /dev/null +++ b/src/main/java/ru/windcorp/optica/client/graphics/input/WheelEvent.java @@ -0,0 +1,7 @@ +package ru.windcorp.optica.client.graphics.input; + +public abstract class WheelEvent extends InputEvent { + + @Override + public abstract WheelEvent snapshot(); +} diff --git a/src/main/java/ru/windcorp/optica/client/graphics/input/WheelScrollEvent.java b/src/main/java/ru/windcorp/optica/client/graphics/input/WheelScrollEvent.java new file mode 100644 index 0000000..f8c36b9 --- /dev/null +++ b/src/main/java/ru/windcorp/optica/client/graphics/input/WheelScrollEvent.java @@ -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; + } + + } +}