Renderer/src/main/java/electrosphere/controls/MouseCallback.java
austin 7c8e536f80
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
bare minimum working ui update
2024-04-04 18:15:10 -04:00

45 lines
1.4 KiB
Java

package electrosphere.controls;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWMouseButtonCallback;
import electrosphere.logger.LoggerInterface;
/**
* A callback for mouse functions
*/
public class MouseCallback extends GLFWMouseButtonCallback {
//the number of buttons available
static final short KEY_VALUE_ARRAY_SIZE = 512;
//current value of all buttons pressed
boolean[] buttonValues = new boolean[KEY_VALUE_ARRAY_SIZE];
@Override
public void invoke(long window, int button, int action, int mods) {
if(button >= 0 && button < KEY_VALUE_ARRAY_SIZE){
if(action == GLFW.GLFW_PRESS || action == GLFW.GLFW_REPEAT){
buttonValues[button] = true;
} else {
buttonValues[button] = false;
}
}
}
/**
* !!!WARNING!!!, will silently fail if opengl elements not defined or keycode is outside of key value array size or is not in main rendering thread
* @param keycode The keycode
* @return The button's pressed state
*/
public boolean getButton(int keycode){
if(keycode >= 0 && keycode < KEY_VALUE_ARRAY_SIZE){
return buttonValues[keycode];
} else {
LoggerInterface.loggerEngine.WARNING("Trying to get button state where keycode is undefined (<0 or >400)");
}
return false;
}
}