mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-06 06:53:59 +00:00
Mac OS X: Moved mouse handling from MacOSXDisplay to MacOSXMouseEventQueue
This commit is contained in:
parent
24e913477f
commit
a47e419168
5 changed files with 36 additions and 26 deletions
|
|
@ -69,7 +69,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
private static final int GAMMA_LENGTH = 256;
|
||||
|
||||
private MacOSXFrame frame;
|
||||
private MouseEventQueue mouse_queue;
|
||||
private MacOSXMouseEventQueue mouse_queue;
|
||||
private KeyboardEventQueue keyboard_queue;
|
||||
private java.awt.DisplayMode requested_mode;
|
||||
|
||||
|
|
@ -256,17 +256,8 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
GL11.glGetInteger(GL11.GL_VIEWPORT, current_viewport);
|
||||
GL11.glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3));
|
||||
}
|
||||
if (frame.syncShouldWarpCursor()) {
|
||||
warpCursor();
|
||||
}
|
||||
}
|
||||
|
||||
private void warpCursor() {
|
||||
if (mouse_queue != null && mouse_queue.isGrabbed()) {
|
||||
Rectangle bounds = frame.syncGetBounds();
|
||||
int x = bounds.x + bounds.width/2;
|
||||
int y = bounds.y + bounds.height/2;
|
||||
nWarpCursor(x, y);
|
||||
if (frame.syncShouldWarpCursor() && mouse_queue != null) {
|
||||
mouse_queue.warpCursor();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -286,8 +277,6 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
|
||||
private native void nHideUI(boolean hide);
|
||||
|
||||
native void getMouseDeltas(IntBuffer delta_buffer);
|
||||
|
||||
public void reshape(int x, int y, int width, int height) {
|
||||
frame.resize(x, y, width, height);
|
||||
}
|
||||
|
|
@ -323,14 +312,8 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
|
||||
public void grabMouse(boolean grab) {
|
||||
mouse_queue.setGrabbed(grab);
|
||||
warpCursor();
|
||||
nGrabMouse(grab);
|
||||
}
|
||||
|
||||
private native void nWarpCursor(int x, int y);
|
||||
|
||||
private native void nGrabMouse(boolean grab);
|
||||
|
||||
public int getNativeCursorCapabilities() {
|
||||
return AWTUtil.getNativeCursorCapabilities();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import java.awt.event.MouseMotionListener;
|
|||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.Component;
|
||||
import java.awt.Rectangle;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
|
|
@ -55,16 +56,22 @@ final class MacOSXMouseEventQueue extends MouseEventQueue {
|
|||
super(component);
|
||||
}
|
||||
|
||||
public void setGrabbed(boolean grab) {
|
||||
super.setGrabbed(grab);
|
||||
warpCursor();
|
||||
nGrabMouse(grab);
|
||||
}
|
||||
|
||||
protected void resetCursorToCenter() {
|
||||
super.resetCursorToCenter();
|
||||
/* Clear accumulated deltas */
|
||||
((MacOSXDisplay)Display.getImplementation()).getMouseDeltas(delta_buffer);
|
||||
getMouseDeltas(delta_buffer);
|
||||
}
|
||||
|
||||
protected void updateDeltas(long nanos) {
|
||||
super.updateDeltas(nanos);
|
||||
synchronized ( this ) {
|
||||
((MacOSXDisplay)Display.getImplementation()).getMouseDeltas(delta_buffer);
|
||||
getMouseDeltas(delta_buffer);
|
||||
int dx = delta_buffer.get(0);
|
||||
int dy = -delta_buffer.get(1);
|
||||
if ( dx != 0 || dy != 0 ) {
|
||||
|
|
@ -73,4 +80,19 @@ final class MacOSXMouseEventQueue extends MouseEventQueue {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void warpCursor() {
|
||||
if (isGrabbed()) {
|
||||
Rectangle bounds = getComponent().getBounds();
|
||||
int x = bounds.x + bounds.width/2;
|
||||
int y = bounds.y + bounds.height/2;
|
||||
nWarpCursor(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
private static native void getMouseDeltas(IntBuffer delta_buffer);
|
||||
|
||||
private static native void nWarpCursor(int x, int y);
|
||||
|
||||
private static native void nGrabMouse(boolean grab);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ class MouseEventQueue extends EventQueue implements MouseListener, MouseMotionLi
|
|||
|
||||
private boolean grabbed;
|
||||
|
||||
|
||||
/** The accumulated mouse deltas returned by poll() */
|
||||
private int accum_dx;
|
||||
private int accum_dy;
|
||||
|
|
@ -93,6 +92,10 @@ class MouseEventQueue extends EventQueue implements MouseListener, MouseMotionLi
|
|||
component.removeMouseWheelListener(this);
|
||||
}
|
||||
|
||||
protected Component getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
public synchronized void setGrabbed(boolean grabbed) {
|
||||
this.grabbed = grabbed;
|
||||
resetCursorToCenter();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue