From e754c2c24867b31d9d08795a92cfcd5f6d40e5c4 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Mon, 22 Jul 2024 15:22:34 +0200 Subject: [PATCH] Add input event and type classes --- .../GraphicsSubsystemConfiguration.java | 20 +- .../graphics/events/input/KeyInputEvent.java | 52 ++ .../events/input/MouseInputEvent.java | 22 + .../sosengine/graphics/types/input/Key.java | 492 ++++++++++++++++++ .../graphics/types/input/KeyState.java | 42 ++ graphics/src/main/java/module-info.java | 4 + 6 files changed, 631 insertions(+), 1 deletion(-) create mode 100644 graphics/src/main/java/de/staropensource/sosengine/graphics/events/input/KeyInputEvent.java create mode 100644 graphics/src/main/java/de/staropensource/sosengine/graphics/events/input/MouseInputEvent.java create mode 100644 graphics/src/main/java/de/staropensource/sosengine/graphics/types/input/Key.java create mode 100644 graphics/src/main/java/de/staropensource/sosengine/graphics/types/input/KeyState.java diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/GraphicsSubsystemConfiguration.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/GraphicsSubsystemConfiguration.java index 13c7ddd..4f5d6ba 100644 --- a/graphics/src/main/java/de/staropensource/sosengine/graphics/GraphicsSubsystemConfiguration.java +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/GraphicsSubsystemConfiguration.java @@ -83,6 +83,20 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat */ private boolean debug; + /** + * If enabled, will log all keys being pressed or released. + * + * @since v1-alpha2 + * + * -- GETTER -- + * Gets the value for {@link #debugInput}. + * + * @return variable value + * @see GraphicsSubsystemConfiguration#debugInput + * @since v1-alpha2 + */ + private boolean debugInput; + /** * If enabled, graphical errors thrown by GLFW will be printed to the log by the subsystem. * @@ -160,6 +174,7 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat try { switch (property) { case "debug" -> debug = parser.getBoolean(group + property); + case "debugInput" -> debugInput = parser.getBoolean(group + property); case "errorGraphicsError" -> errorGraphicsError = parser.getBoolean(group + property); @@ -169,7 +184,8 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat } // Disable all debug options if 'debug' is disabled - //if (!debug) {} + if (!debug) + debugInput = false; } /** {@inheritDoc} */ @@ -180,6 +196,7 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat /** {@inheritDoc} */ public void loadDefaultConfiguration() { debug = false; + debugInput = false; errorGraphicsError = true; @@ -191,6 +208,7 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat public Object getSetting(@NotNull String setting) { switch (setting) { case "debug" -> { return debug; } + case "debugInput" -> { return debugInput; } case "errorGraphicsError" -> { return errorGraphicsError; } diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/events/input/KeyInputEvent.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/events/input/KeyInputEvent.java new file mode 100644 index 0000000..5d9c890 --- /dev/null +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/events/input/KeyInputEvent.java @@ -0,0 +1,52 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.sosengine.graphics.events.input; + +import de.staropensource.sosengine.base.classes.Event; +import de.staropensource.sosengine.base.classes.helpers.EventHelper; +import de.staropensource.sosengine.graphics.types.input.Key; +import de.staropensource.sosengine.graphics.types.input.KeyState; +import org.jetbrains.annotations.NotNull; + +/** + * Called when a key is pressed. + * + * @since v1-alpha2 + */ +@SuppressWarnings({ "unused" }) +public class KeyInputEvent implements Event { + /** + * {@inheritDoc} + * @see #callEvent(Key, KeyState) + * @deprecated use {@link #callEvent(Key, KeyState)} + */ + @Deprecated + @Override + public void callEvent() {} + + /** + * Calls the event and notifies all annotated methods. + * + * @since v1-alpha0 + */ + public void callEvent(@NotNull Key key, @NotNull KeyState state) { + EventHelper.invokeAnnotatedMethods(getClass(), key, state); + } +} diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/events/input/MouseInputEvent.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/events/input/MouseInputEvent.java new file mode 100644 index 0000000..d8bb951 --- /dev/null +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/events/input/MouseInputEvent.java @@ -0,0 +1,22 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.sosengine.graphics.events.input; + +public class MouseInputEvent {} diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/types/input/Key.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/types/input/Key.java new file mode 100644 index 0000000..6a90203 --- /dev/null +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/types/input/Key.java @@ -0,0 +1,492 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.sosengine.graphics.types.input; + +/** + * Contains a list of keys which + * can be recognized by the engine. + * + * @since v1-alpha2 + */ +@SuppressWarnings({ "unused" }) +public enum Key { + /** + * The {@code ALT} modifier key. + */ + ALT, + /** + * The {@code '} key. + */ + APOSTROPHE, + /** + * The {@code DOWN} arrow key. + */ + ARROW_DOWN, + /** + * The {@code LEFT} arrow key. + */ + ARROW_LEFT, + /** + * The {@code RIGHT} arrow key. + */ + ARROW_RIGHT, + /** + * The {@code UP} arrow key. + */ + ARROW_UP, + /** + * The {@code \} key. + */ + BACKSLASH, + /** + * The {@code BACKSPACE} key. + */ + BACKSPACE, + /** + * The left {@code [} key. + */ + BRACKET_LEFT, + /** + * The right {@code ]} key. + */ + BRACKET_RIGHT, + /** + * THE {@code CAPSLOCK} KEY. + */ + CAPS_LOCK, + /** + * The {@code ,} key. + */ + COMMA, + /** + * The left {@code CTRL} modifier key. + */ + CONTROL_LEFT, + /** + * The right {@code CTRL} modifier key. + */ + CONTROL_RIGHT, + /** + * The {@code DEL} key. + */ + DELETE, + /** + * The {@code END} key. + */ + END, + /** + * The {@code ENTER} key. + */ + ENTER, + /** + * The {@code =} key. + */ + EQUAL, + /** + * The {@code ESC} key. + */ + ESCAPE, + /** + * The {@code F1} key. + */ + FUNCTION_1, + /** + * The {@code F2} key. + */ + FUNCTION_2, + /** + * The {@code F3} key. + */ + FUNCTION_3, + /** + * The {@code F4} key. + */ + FUNCTION_4, + /** + * The {@code F5} key. + */ + FUNCTION_5, + /** + * The {@code F6} key. + */ + FUNCTION_6, + /** + * The {@code F7} key. + */ + FUNCTION_7, + /** + * The {@code F8} key. + */ + FUNCTION_8, + /** + * The {@code F9} key. + */ + FUNCTION_9, + /** + * The {@code F10} key. + */ + FUNCTION_10, + /** + * The {@code F11} key. + */ + FUNCTION_11, + /** + * The {@code F12} key. + */ + FUNCTION_12, + /** + * The {@code F13} key. + */ + FUNCTION_13, + /** + * The {@code F14} key. + */ + FUNCTION_14, + /** + * The {@code F15} key. + */ + FUNCTION_15, + /** + * The {@code F16} key. + */ + FUNCTION_16, + /** + * The {@code F17} key. + */ + FUNCTION_17, + /** + * The {@code F18} key. + */ + FUNCTION_18, + /** + * The {@code F19} key. + */ + FUNCTION_19, + /** + * The {@code F20} key. + */ + FUNCTION_20, + /** + * The {@code F21} key. + */ + FUNCTION_21, + /** + * The {@code F22} key. + */ + FUNCTION_22, + /** + * The {@code F23} key. + */ + FUNCTION_23, + /** + * The {@code F24} key. + */ + FUNCTION_24, + /** + * The {@code F25} key. + */ + FUNCTION_25, + /** + * The {@code `} key. + */ + GRAVE, + /** + * The {@code HOME} key. + */ + HOME, + /** + * THe {@code INS} key. + */ + INSERT, + /** + * The {@code +} key on your keypad. + */ + KEYPAD_ADD, + /** + * The {@code -} key on your keypad. + */ + KEYPAD_DECIMAL, + /** + * The {@code /} key on your keypad. + */ + KEYPAD_DIVIDE, + /** + * The {@code ENTER} key on your keypad. + */ + KEYPAD_ENTER, + /** + * The {@code =} key on your keypad. + */ + KEYPAD_EQUAL, + /** + * The {@code *} key on your keypad. + */ + KEYPAD_MULTIPLY, + /** + * The number {@code 0} key on your keypad. + */ + KEYPAD_NUMBER_0, + /** + * The number {@code 1} key on your keypad. + */ + KEYPAD_NUMBER_1, + /** + * The number {@code 2} key on your keypad. + */ + KEYPAD_NUMBER_2, + /** + * The number {@code 3} key on your keypad. + */ + KEYPAD_NUMBER_3, + /** + * The number {@code 4} key on your keypad. + */ + KEYPAD_NUMBER_4, + /** + * The number {@code 5} key on your keypad. + */ + KEYPAD_NUMBER_5, + /** + * The number {@code 6} key on your keypad. + */ + KEYPAD_NUMBER_6, + /** + * The number {@code 7} key on your keypad. + */ + KEYPAD_NUMBER_7, + /** + * The number {@code 8} key on your keypad. + */ + KEYPAD_NUMBER_8, + /** + * The number {@code 9} key on your keypad. + */ + KEYPAD_NUMBER_9, + /** + * The {@code -} key on your keypad. + */ + KEYPAD_SUBTRACT, + /** + * The letter {@code A} key. + */ + LETTER_A, + /** + * The letter {@code B} key. + */ + LETTER_B, + /** + * The letter {@code C} key. + */ + LETTER_C, + /** + * The letter {@code D} key. + */ + LETTER_D, + /** + * The letter {@code E} key. + */ + LETTER_E, + /** + * The letter {@code F} key. + */ + LETTER_F, + /** + * The letter {@code G} key. + */ + LETTER_G, + /** + * The letter {@code H} key. + */ + LETTER_H, + /** + * The letter {@code I} key. + */ + LETTER_I, + /** + * The letter {@code J} key. + */ + LETTER_J, + /** + * The letter {@code K} key. + */ + LETTER_K, + /** + * The letter {@code L} key. + */ + LETTER_L, + /** + * The letter {@code M} key. + */ + LETTER_M, + /** + * The letter {@code N} key. + */ + LETTER_N, + /** + * The letter {@code O} key. + */ + LETTER_O, + /** + * The letter {@code P} key. + */ + LETTER_P, + /** + * The letter {@code Q} key. + */ + LETTER_Q, + /** + * The letter {@code R} key. + */ + LETTER_R, + /** + * The letter {@code S} key. + */ + LETTER_S, + /** + * The letter {@code T} key. + */ + LETTER_T, + /** + * The letter {@code U} key. + */ + LETTER_U, + /** + * The letter {@code V} key. + */ + LETTER_V, + /** + * The letter {@code W} key. + */ + LETTER_W, + /** + * The letter {@code X} key. + */ + LETTER_X, + /** + * The letter {@code Y} key. + */ + LETTER_Y, + /** + * The letter {@code Z} key. + */ + LETTER_Z, + /** + * The {@code MENU} key, which brings up the right click menu. + */ + MENU, + /** + * The {@code META} key, also known as the {@code SUPER} key. + *

+ * Windows users will recognize this key as the Windows key. + */ + META, + /** + * The {@code -} key. + */ + MINUS, + /** + * The number {@code 0}. + */ + NUMBER_0, + /** + * The number {@code 1}. + */ + NUMBER_1, + /** + * The number {@code 2}. + */ + NUMBER_2, + /** + * The number {@code 3}. + */ + NUMBER_3, + /** + * The number {@code 4}. + */ + NUMBER_4, + /** + * The number {@code 5}. + */ + NUMBER_5, + /** + * The number {@code 6}. + */ + NUMBER_6, + /** + * The number {@code 7}. + */ + NUMBER_7, + /** + * The number {@code 8}. + */ + NUMBER_8, + /** + * The number {@code 9}. + */ + NUMBER_9, + /** + * The {@code NUM} key. + */ + NUM_LOCK, + /** + * The {@code PAGE DOWN} key. + */ + PAGE_DOWN, + /** + * The {@code PAGE UP} key. + */ + PAGE_UP, + /** + * The {@code PAUSE} key. + */ + PAUSE, + /** + * The {@code .} key. + */ + PERIOD, + /** + * The {@code PRINT} key. + */ + PRINT, + /** + * The {@code SCROLL} key. + */ + SCROLL_LOCK, + /** + * The {@code ;} key. + */ + SEMICOLON, + /** + * The left {@code SHIFT} modifier key. + */ + SHIFT_LEFT, + /** + * The right {@code SHIFT} modifier key. + */ + SHIFT_RIGHT, + /** + * The {@code /} key. + */ + SLASH, + /** + * The {@code TAB} key. + */ + TAB, +} diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/types/input/KeyState.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/types/input/KeyState.java new file mode 100644 index 0000000..343864f --- /dev/null +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/types/input/KeyState.java @@ -0,0 +1,42 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.sosengine.graphics.types.input; + +/** + * Indicates how a key is pressed. + * + * @since v1-alpha2 + */ +@SuppressWarnings({ "unused" }) +public enum KeyState { + /** + * Indicates that a key is pressed. + * + * @since v1-alpha2 + */ + PRESSED, + + /** + * Indicates that a key is released. + * + * @since v1-alpha2 + */ + RELEASED, +} diff --git a/graphics/src/main/java/module-info.java b/graphics/src/main/java/module-info.java index e54f085..adefbc4 100644 --- a/graphics/src/main/java/module-info.java +++ b/graphics/src/main/java/module-info.java @@ -15,11 +15,15 @@ module sosengine.graphics { exports de.staropensource.sosengine.graphics; exports de.staropensource.sosengine.graphics.classes; exports de.staropensource.sosengine.graphics.events; + exports de.staropensource.sosengine.graphics.events.input; + exports de.staropensource.sosengine.graphics.types.input; exports de.staropensource.sosengine.graphics.types.window; // Reflection access opens de.staropensource.sosengine.graphics; opens de.staropensource.sosengine.graphics.classes; opens de.staropensource.sosengine.graphics.events; + opens de.staropensource.sosengine.graphics.events.input; + opens de.staropensource.sosengine.graphics.types.input; opens de.staropensource.sosengine.graphics.types.window; }