diff options
Diffstat (limited to 'src/newt')
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java | 81 | ||||
-rw-r--r-- | src/newt/native/bcm_vc_iv.c | 2 |
2 files changed, 78 insertions, 5 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java index 29c7f9898..93c28d370 100644 --- a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java @@ -37,7 +37,8 @@ import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.nativewindow.VisualIDHolder; import com.jogamp.nativewindow.util.Insets; import com.jogamp.nativewindow.util.Point; - +import com.jogamp.nativewindow.util.Rectangle; +import com.jogamp.nativewindow.util.RectangleImmutable; import com.jogamp.common.util.IntBitfield; import com.jogamp.nativewindow.egl.EGLGraphicsDevice; import com.jogamp.newt.event.MouseEvent; @@ -63,6 +64,75 @@ public class WindowDriver extends WindowImpl { windowHandleClose = 0; } + /** + * Clamp given rectangle to given screen bounds. + * + * @param screen + * @param rect the {@link RectangleImmutable} in pixel units + * @param definePosSize if {@code true} issue {@link #definePosition(int, int)} and {@link #defineSize(int, int)} + * if either has changed. + * @return If position or size has been clamped a new {@link RectangleImmutable} instance w/ clamped values + * will be returned, otherwise the given {@code rect} is returned. + */ + private RectangleImmutable clampRect(final ScreenDriver screen, final RectangleImmutable rect, final boolean definePosSize) { + int x = rect.getX(); + int y = rect.getY(); + int w = rect.getWidth(); + int h = rect.getHeight(); + final int s_w = screen.getWidth(); + final int s_h = screen.getHeight(); + boolean modPos = false; + boolean modSize = false; + if( 0 > x ) { + x = 0; + modPos = true; + } + if( 0 > y ) { + y = 0; + modPos = true; + } + if( s_w < x + w ) { + if( 0 < x ) { + x = 0; + modPos = true; + } + if( s_w < w ) { + w = s_w; + modSize = true; + } + } + if( s_h < y + h ) { + if( 0 < y ) { + y = 0; + modPos = true; + } + if( s_h < h ) { + h = s_h; + modSize = true; + } + } + if( modPos || modSize ) { + if( definePosSize ) { + if( modPos ) { + definePosition(x, y); + } + if( modSize ) { + defineSize(w, h); + } + } + return new Rectangle(x, y, w, h); + } else { + return rect; + } + } + + @Override + protected boolean canCreateNativeImpl() { + // clamp if required incl. redefinition of position and size + clampRect((ScreenDriver) getScreen(), new Rectangle(getX(), getY(), getWidth(), getHeight()), true); + return true; // default: always able to be created + } + @Override protected void createNativeImpl() { if(0!=getParentWindowHandle()) { @@ -110,7 +180,8 @@ public class WindowDriver extends WindowImpl { chosenCaps.setBackgroundOpaque(capsRequested.isBackgroundOpaque()); } setGraphicsConfiguration(cfg); - nativeWindowHandle = CreateWindow0(display.getBCMHandle(), layer, getX(), getY(), getWidth(), getHeight(), + nativeWindowHandle = CreateWindow0(display.getBCMHandle(), layer, + getX(), getY(), getWidth(), getHeight(), chosenCaps.isBackgroundOpaque(), chosenCaps.getAlphaBits()); if (nativeWindowHandle == 0) { throw new NativeWindowException("Error creating egl window: "+cfg); @@ -155,7 +226,9 @@ public class WindowDriver extends WindowImpl { @Override protected boolean reconfigureWindowImpl(final int x, final int y, final int width, final int height, final int flags) { - reconfigure0(nativeWindowHandle, x, y, width, height, flags); + final RectangleImmutable rect = clampRect((ScreenDriver) getScreen(), new Rectangle(x, y, width, height), false); + // reconfigure0 will issue position/size changed events if required + reconfigure0(nativeWindowHandle, rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(), flags); return true; } @@ -174,7 +247,7 @@ public class WindowDriver extends WindowImpl { final int x, final int y, final short button, final float[] rotationXYZ, final float rotationScale) { if( MouseEvent.EVENT_MOUSE_MOVED == eventType ) { final DisplayDriver display = (DisplayDriver) getScreen().getDisplay(); - display.moveActivePointerIcon(x, y); + display.moveActivePointerIcon(getX() + x, getY() + y); } super.doMouseEvent(enqueue, wait, eventType, modifiers, x, y, button, rotationXYZ, rotationScale); } diff --git a/src/newt/native/bcm_vc_iv.c b/src/newt/native/bcm_vc_iv.c index 6b1ee3aaf..611dd5a4a 100644 --- a/src/newt/native/bcm_vc_iv.c +++ b/src/newt/native/bcm_vc_iv.c @@ -457,7 +457,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_bcm_vc_iv_WindowDriver_reconfigur (*env)->CallVoidMethod(env, obj, positionChangedID, JNI_FALSE, x, y); } if( sizeChanged ) { - (*env)->CallVoidMethod(env, obj, sizeChangedID, JNI_FALSE, (jint) width, (jint) height, JNI_FALSE); + (*env)->CallVoidMethod(env, obj, sizeChangedID, JNI_FALSE, width, height, JNI_FALSE); } } |