diff options
author | Sven Gothel <[email protected]> | 2020-01-06 18:58:01 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-01-06 18:58:01 +0100 |
commit | 141fa0fba0f47851f20acfcb078e11659ebc74cc (patch) | |
tree | f48b53ab99bc6682aaadc81abcbf0b3801ed8984 /src/newt/classes/com | |
parent | 0209655c26e9240639c5f0a76ca6ca54ae0584b1 (diff) |
Bug 1421: Tackle wrong position of TabFolder, SashForm etc
getClientArea() on MacOS produces a 'difficult' result regarding the position,
which usually is returned as zero.
Using a zero position issues the bug w/ SashForm, where the offset doesn't seems
to be covered by the native NSView nor an SWT parent Composition.
Then using the getLocation() as is (i.e. the view's frame position)
may also cause issues with the TabFolder, as it includes the tab's trimming.
Here the native NSView 's position includes the tab's trimming,
gladly the parent (TabFolder or a Composition)'s clientArea includes this offset.
Therefor, as a testbed - on OSX, getClientArea2(..) returns
- position: getLocation() - getParent().getClientArea().position
- size: getSize()
This at least works OK'sh using
- no special layout parent
- TabFolder
- SashForm
++++
Unit test TestGLCanvasSWTNewtCanvasSWTPosInTabs: Adding 'addComposite' to test matrix.
'addComposite' wraps our GLCanvas or NewtCanvasSWT into a Composite instead of
adding it directly into the layouting parent.
It demonstrates an issue with the new test 'test32_NewtCanvasSWTTabSashGLWComp',
i.e. the NewtCanvasSWT is shown on the left as the SashForm's offset is being dropped.
Summary:
- No more issues with High-DPI pixelScale observed!
- GLCanvas is being most well layouted, no issues in tests
- NewtCanvasSWT may show severe positioning issues -> test32_NewtCanvasSWTTabSashGLWComp
- NewtCanvasSWT always shows a small positioning offset into the lower-right corner w/ overlapping
- NewtCanvasSWT overall positioning is not perfectly understood
- NewtCanvasSWT misses to hide the NEWT child when changing tabs in TabFolder
Diffstat (limited to 'src/newt/classes/com')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java | 82 |
1 files changed, 66 insertions, 16 deletions
diff --git a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java index fe1dab3c3..35458b9cc 100644 --- a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java +++ b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java @@ -55,6 +55,7 @@ import jogamp.newt.swt.SWTEDTUtil; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.internal.DPIUtil; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; @@ -131,8 +132,8 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC SWTAccessor.setRealized(this, true); - clientAreaPixels = SWTAccessor.getClientAreaInPixels(this); - clientAreaWindow = getClientArea(); + clientAreaPixels = getClientArea2InPixels(); + clientAreaWindow = getClientArea2(); if( 0 < clientAreaWindow.width && 0 < clientAreaWindow.height ) { pixelScale[0] = clientAreaPixels.width / clientAreaWindow.width; pixelScale[1] = clientAreaPixels.height / clientAreaWindow.height; @@ -215,6 +216,50 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC addListener (SWT.Dispose, listener); } + private Rectangle getClientArea2() { + final Rectangle r = this.getClientArea(); + if( SWTAccessor.isOSX ) { + // On MacOS SWT implementation is as follows: + // Scrollable.getClientArea(): + // - Either using scrollView.contenview.bounds.position and scrollView.contentSize + // - Or using 0/0 and view.bounds.size + // + // Control's getSize() and getLocation() uses position and size of topView().frame() + // + final Rectangle parentClientArea = getParent().getClientArea(); + final org.eclipse.swt.graphics.Point l = getLocation(); + final org.eclipse.swt.graphics.Point s = getSize(); + if( DEBUG ) { + System.err.println("XXX parent.clientArea: "+parentClientArea); + System.err.println("XXX clientArea: "+r); + System.err.println("XXX location: "+l); + System.err.println("XXX size: "+s); + } + // Bug 1421 + // Subtracting parentClientArea's position fixes using: + // - CTabFolder parent: y-position no more pushed down about tab-height (parentClientArea.x/y) + // - SashForm parent: Offset is preserved, as it is not part of parentClientArea.x/y + // Notable, this almost mimics the original 'getClientArea()' but + // preserves SashForm's offset. + // + // The resulting offset still shows a 1-2 pixel x/y + // lower-left corner overlap .. + // Our GLCanvas doesn't show this behavior. + r.x = l.x - parentClientArea.x; // FIXME +1? + r.y = l.y - parentClientArea.y; // FIXME -1? + r.width = s.x; + r.height = s.y; + if( DEBUG ) { + System.err.println("XXX clientArea2:"+r); + } + } + return r; + } + private Rectangle getClientArea2InPixels() { + // SWTAccessor.getClientAreaInPixels(this); + return DPIUtil.autoScaleUp(getClientArea2()); + } + @Override public void setBounds(final int x, final int y, final int width, final int height) { super.setBounds(x, y, width, height); @@ -270,38 +315,40 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC } protected final void updatePosSizeCheck(final boolean updatePos) { + final Rectangle oClientAreaWindow = clientAreaWindow; + final Rectangle nClientAreaPixels = getClientArea2InPixels(); + final Rectangle nClientAreaWindow = getClientArea2(); final boolean sizeChanged, posChanged; - Rectangle nClientAreaPixels = SWTAccessor.getClientAreaInPixels(this); { - final Rectangle oClientAreaPixels = clientAreaPixels; - sizeChanged = nClientAreaPixels.width != oClientAreaPixels.width || nClientAreaPixels.height != oClientAreaPixels.height; - posChanged = nClientAreaPixels.x != oClientAreaPixels.x || nClientAreaPixels.y != oClientAreaPixels.y; + sizeChanged = nClientAreaWindow.width != oClientAreaWindow.width || nClientAreaWindow.height != oClientAreaWindow.height; + posChanged = nClientAreaWindow.x != oClientAreaWindow.x || nClientAreaWindow.y != oClientAreaWindow.y; if( sizeChanged || posChanged ) { clientAreaPixels = nClientAreaPixels; - clientAreaWindow = getClientArea(); - if( 0 < clientAreaWindow.width && 0 < clientAreaWindow.height ) { - pixelScale[0] = clientAreaPixels.width / clientAreaWindow.width; - pixelScale[1] = clientAreaPixels.height / clientAreaWindow.height; + clientAreaWindow = nClientAreaWindow; + if( 0 < nClientAreaWindow.width && 0 < nClientAreaWindow.height ) { + pixelScale[0] = nClientAreaPixels.width / nClientAreaWindow.width; + pixelScale[1] = nClientAreaPixels.height / nClientAreaWindow.height; } else { pixelScale[0] = 1f; pixelScale[1] = 1f; } - } else { - nClientAreaPixels = clientAreaPixels; } } if(DEBUG) { final long nsh = newtChildReady ? newtChild.getSurfaceHandle() : 0; System.err.println("NewtCanvasSWT.updatePosSizeCheck: sizeChanged "+sizeChanged+", posChanged "+posChanged+", updatePos "+updatePos+ ", ("+Thread.currentThread().getName()+"): newtChildReady "+newtChildReady+ - ", pixel "+clientAreaPixels.x+"/"+clientAreaPixels.y+" "+clientAreaPixels.width+"x"+clientAreaPixels.height+ - ", window "+clientAreaWindow.x+"/"+clientAreaWindow.y+" "+clientAreaWindow.width+"x"+clientAreaWindow.height+ + ", pixel "+nClientAreaPixels.x+"/"+nClientAreaPixels.y+" "+nClientAreaPixels.width+"x"+nClientAreaPixels.height+ + ", window "+nClientAreaWindow.x+"/"+nClientAreaWindow.y+" "+nClientAreaWindow.width+"x"+nClientAreaWindow.height+ ", scale "+pixelScale[0]+"/"+pixelScale[1]+ " - surfaceHandle 0x"+Long.toHexString(nsh)); + System.err.println("NewtCanvasSWT.updatePosSizeCheck.self: pixel-units pos "+SWTAccessor.getLocationInPixels(this)+", size "+SWTAccessor.getSizeInPixels(this)); + System.err.println("NewtCanvasSWT.updatePosSizeCheck.self: window-units pos "+this.getLocation()+", size "+this.getSize()); + System.err.println("NewtCanvasSWT.updatePosSizeCheck.self: LOS.0: "+SWTAccessor.getLocationOnScreen(new Point(), this)); } if( sizeChanged ) { if( newtChildReady ) { - newtChild.setSize(clientAreaWindow.width, clientAreaWindow.height); + newtChild.setSize(nClientAreaWindow.width, nClientAreaWindow.height); newtChild.setSurfaceScale(pixelScale); } else { postSetSize = true; @@ -309,11 +356,14 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC } if( updatePos && posChanged ) { if( newtChildReady ) { - newtChild.setPosition(clientAreaWindow.x, clientAreaWindow.y); + newtChild.setPosition(nClientAreaWindow.x, nClientAreaWindow.y); } else { postSetPos = true; } } + if( DEBUG ) { + System.err.println("NewtCanvasSWT.updatePosSizeCheck.X END"); + } } @Override |