summaryrefslogtreecommitdiffstats
path: root/src/newt/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-10-10 05:10:26 +0200
committerSven Gothel <[email protected]>2011-10-10 05:10:26 +0200
commit24e0591b6be036d5389cc1eb986ed5e86043ba65 (patch)
treee9abb4999bad2f01860490338b0dc588818ee495 /src/newt/classes/jogamp
parent51a9f23d629cd4e6b22d7afaf009bb96b2ed270f (diff)
NEWT: Add pointer features: visibility, confined and warp (move)
visibility: - set pointer visible or invisible confined: - confine pointer to window, or not warp: - set mouse position within the window Implemented for X11, tested manually with TestGearsES2NEWT (see code for action keys). TODO: Windows, MaxOSX and Android (limited)
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r--src/newt/classes/jogamp/newt/DisplayImpl.java8
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java72
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Screen.java28
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Window.java36
4 files changed, 108 insertions, 36 deletions
diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java
index 2d251614b..908a44ea2 100644
--- a/src/newt/classes/jogamp/newt/DisplayImpl.java
+++ b/src/newt/classes/jogamp/newt/DisplayImpl.java
@@ -438,15 +438,15 @@ public abstract class DisplayImpl extends Display {
}
}
- public interface DisplayRunnable {
- Object run(long dpy);
+ public interface DisplayRunnable<T> {
+ T run(long dpy);
}
- public final Object runWithLockedDisplayHandle(DisplayRunnable action) {
+ public final <T> T runWithLockedDisplayHandle(DisplayRunnable<T> action) {
final AbstractGraphicsDevice aDevice = getGraphicsDevice();
if(null == aDevice) {
throw new RuntimeException("null device - not initialized: "+this);
}
- Object res;
+ T res;
aDevice.lock();
try {
res = action.run(aDevice.getHandle());
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 00911443a..7bef0b564 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -96,6 +96,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
protected String title = "Newt Window";
protected boolean undecorated = false;
protected boolean alwaysOnTop = false;
+ private boolean pointerVisible = true;
+ private boolean pointerConfined = false;
private LifecycleHook lifecycleHook = null;
private DestroyAction destroyAction = new DestroyAction();
@@ -280,6 +282,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
createNativeImpl();
screen.addScreenModeListener(screenModeListenerImpl);
setTitleImpl(title);
+ setPointerVisibleImpl(pointerVisible);
+ confinePointerImpl(pointerConfined);
if(waitForVisible(true, false)) {
if(isFullscreen()) {
fullscreen = false;
@@ -522,6 +526,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
*/
protected abstract void updateInsetsImpl(Insets insets);
+ protected boolean setPointerVisibleImpl(boolean pointerVisible) { return false; }
+ protected boolean confinePointerImpl(boolean confine) { return false; }
+ protected void warpPointerImpl(int x, int y) { }
+
//----------------------------------------------------------------------
// NativeSurface
//
@@ -1216,20 +1224,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return capsRequested;
}
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- if (title == null) {
- title = "";
- }
- this.title = title;
- if(0 != getWindowHandle()) {
- setTitleImpl(title);
- }
- }
-
private class DecorationActionImpl implements Runnable {
boolean undecorated;
@@ -1328,6 +1322,55 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return alwaysOnTop || fullscreen ;
}
+ public String getTitle() {
+ return title;
+ }
+ public void setTitle(String title) {
+ if (title == null) {
+ title = "";
+ }
+ this.title = title;
+ if(0 != getWindowHandle()) {
+ setTitleImpl(title);
+ }
+ }
+
+ public boolean isPointerVisible() {
+ return pointerVisible;
+ }
+ public void setPointerVisible(boolean pointerVisible) {
+ if(this.pointerVisible != pointerVisible) {
+ boolean setVal = 0 == getWindowHandle();
+ if(!setVal) {
+ setVal = setPointerVisibleImpl(pointerVisible);
+ }
+ if(setVal) {
+ this.pointerVisible = pointerVisible;
+ }
+ }
+ }
+ public boolean isPointerConfined() {
+ return pointerConfined;
+ }
+
+ public void confinePointer(boolean confine) {
+ if(this.pointerConfined != confine) {
+ boolean setVal = 0 == getWindowHandle();
+ if(!setVal) {
+ setVal = confinePointerImpl(confine);
+ }
+ if(setVal) {
+ this.pointerConfined = confine;
+ }
+ }
+ }
+
+ public void warpPointer(int x, int y) {
+ if(0 != getWindowHandle()) {
+ warpPointerImpl(x, y);
+ }
+ }
+
public void requestFocus() {
enqueueRequestFocus(true);
}
@@ -1368,7 +1411,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return fullscreen;
}
-
//----------------------------------------------------------------------
// Window
//
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java b/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java
index a67352138..af96dc460 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java
@@ -53,8 +53,8 @@ public class X11Screen extends ScreenImpl {
protected void createNativeImpl() {
// validate screen index
- Long handle = (Long) display.runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
- public Object run(long dpy) {
+ Long handle = display.runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Long>() {
+ public Long run(long dpy) {
long handle = GetScreen0(dpy, screen_idx);
if(0 != handle) {
setScreenSize(getWidth0(dpy, screen_idx), getHeight0(dpy, screen_idx));
@@ -79,8 +79,8 @@ public class X11Screen extends ScreenImpl {
private int nmode_number;
protected int[] getScreenModeFirstImpl() {
- return (int[]) runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
- public Object run(long dpy) {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<int[]>() {
+ public int[] run(long dpy) {
// initialize iterators and static data
nrotations = getAvailableScreenModeRotations0(dpy, screen_idx);
if(null==nrotations || 0==nrotations.length) {
@@ -108,8 +108,8 @@ public class X11Screen extends ScreenImpl {
protected int[] getScreenModeNextImpl() {
// assemble: w x h x bpp x f x r
- return (int[]) runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
- public Object run(long dpy) {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<int[]>() {
+ public int[] run(long dpy) {
/**
System.err.println("******** mode: "+nmode_number);
System.err.println("rot "+nrotation_index);
@@ -172,8 +172,8 @@ public class X11Screen extends ScreenImpl {
}
protected ScreenMode getCurrentScreenModeImpl() {
- return (ScreenMode) runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
- public Object run(long dpy) {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<ScreenMode>() {
+ public ScreenMode run(long dpy) {
int resNumber = getNumScreenModeResolutions0(dpy, screen_idx);
if(0==resNumber) {
return null;
@@ -222,8 +222,8 @@ public class X11Screen extends ScreenImpl {
throw new RuntimeException("ScreenMode not element of ScreenMode list: "+screenMode);
}
final long t0 = System.currentTimeMillis();
- Boolean done = (Boolean) runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
- public Object run(long dpy) {
+ boolean done = runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Boolean>() {
+ public Boolean run(long dpy) {
boolean done = false;
int resNumber = getNumScreenModeResolutions0(dpy, screen_idx);
int resIdx = getScreenModesIdx2NativeIdx().get(screenModeIdx);
@@ -243,19 +243,19 @@ public class X11Screen extends ScreenImpl {
}
return Boolean.valueOf(done);
}
- });
+ }).booleanValue();
- if(!done.booleanValue()) {
+ if(done) {
System.err.println("X11Screen.setCurrentScreenModeImpl: TO ("+SCREEN_MODE_CHANGE_TIMEOUT+") reached: "+
(System.currentTimeMillis()-t0)+"ms");
}
- return done.booleanValue();
+ return done;
}
//----------------------------------------------------------------------
// Internals only
//
- private final Object runWithLockedDisplayHandle(DisplayRunnable action) {
+ private final <T> T runWithLockedDisplayHandle(DisplayRunnable<T> action) {
return display.runWithLockedDisplayHandle(action);
// return runWithTempDisplayHandle(action);
}
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
index dfb84f6f8..c435f993c 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
@@ -129,14 +129,41 @@ public class X11Window extends WindowImpl {
@Override
protected void setTitleImpl(final String title) {
- runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
+ runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Object>() {
public Object run(long dpy) {
setTitle0(dpy, getWindowHandle(), title);
return null;
}
});
}
+
+ @Override
+ protected boolean setPointerVisibleImpl(final boolean pointerVisible) {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Boolean>() {
+ public Boolean run(long dpy) {
+ return Boolean.valueOf(setPointerVisible0(getDisplayEDTHandle(), getWindowHandle(), pointerVisible));
+ }
+ }).booleanValue();
+ }
+ @Override
+ protected boolean confinePointerImpl(final boolean confine) {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Boolean>() {
+ public Boolean run(long dpy) {
+ return Boolean.valueOf(confinePointer0(getDisplayEDTHandle(), getWindowHandle(), confine));
+ }
+ }).booleanValue();
+ }
+
+ @Override
+ protected void warpPointerImpl(final int x, final int y) {
+ runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Boolean>() {
+ public Boolean run(long dpy) {
+ return Boolean.valueOf(warpPointer0(getDisplayEDTHandle(), getWindowHandle(), x, y));
+ }
+ });
+ }
+
protected Point getLocationOnScreenImpl(final int x, final int y) {
// X11Util.GetRelativeLocation: locks display already !
return X11Util.GetRelativeLocation( getScreen().getDisplay().getHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y);
@@ -153,7 +180,7 @@ public class X11Window extends WindowImpl {
private final long getDisplayEDTHandle() {
return ((X11Display) getScreen().getDisplay()).getEDTHandle();
}
- private final Object runWithLockedDisplayHandle(DisplayRunnable action) {
+ private final <T> T runWithLockedDisplayHandle(DisplayRunnable<T> action) {
return ((DisplayImpl) getScreen().getDisplay()).runWithLockedDisplayHandle(action);
// return runWithTempDisplayHandle(action);
}
@@ -168,6 +195,9 @@ public class X11Window extends WindowImpl {
private native void setTitle0(long display, long windowHandle, String title);
private native void requestFocus0(long display, long windowHandle, boolean force);
private native long getParentWindow0(long display, long windowHandle);
-
+ private native boolean setPointerVisible0(long display, long windowHandle, boolean visible);
+ private native boolean confinePointer0(long display, long windowHandle, boolean grab);
+ private native boolean warpPointer0(long display, long windowHandle, int x, int y);
+
private long windowHandleClose;
}