JZY-254. Improve listener support

This commit is contained in:
valb3r 2022-04-30 14:41:43 +03:00
parent e05b5982c9
commit a79b55f1d9
2 changed files with 21 additions and 2 deletions

View File

@ -44,6 +44,7 @@ import jgl.wt.awt.listener.callbacks.KeyboardCallback;
import jgl.wt.awt.listener.callbacks.MotionCallback;
import jgl.wt.awt.listener.callbacks.MouseCallback;
import jgl.wt.awt.listener.callbacks.ReshapeCallback;
import sun.jvm.hotspot.runtime.JavaThread;
/**
* GLUT is the glut class of jGL 2.4.
@ -89,6 +90,20 @@ public class GLUT implements Runnable {
* @param listener Listener that receives callbacks on GL events.
*/
public void glutSetListener(GLUTListener listener) {
// By default - enable everything possible
glut_enable_events(AWTEvent.COMPONENT_EVENT_MASK, true);
if (listener.hasKeyboardCallback()) {
glut_enable_events(AWTEvent.KEY_EVENT_MASK, true);
}
if (listener.hasMouseCallback()) {
glut_enable_events(AWTEvent.MOUSE_EVENT_MASK, true);
glut_enable_events(AWTEvent.MOUSE_MOTION_EVENT_MASK, true);
}
if (JavaThread == null || !JavaThread.isAlive()) {
JavaThread = new Thread(this);
JavaThread.start();
}
this.glutListener = listener;
}

View File

@ -108,7 +108,9 @@ public interface GLUTListener {
/**
* Indicates where the listener has usable {@link this#onMouse(Component, int, int, int, int)}
*/
boolean hasMouseCallback();
default boolean hasMouseCallback() {
return true;
}
/**
* Indicates where the listener has any of usable
@ -116,5 +118,7 @@ public interface GLUTListener {
* {@link this#onSpecialKey(Component, char, int, int)}
* {@link this#onSpecialKeyUp(Component, char, int, int)} (Component, char, int, int)}
*/
boolean hasKeyboardCallback();
default boolean hasKeyboardCallback() {
return true;
}
}