diff options
Diffstat (limited to 'src')
7 files changed, 950 insertions, 577 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java index 8d8a995d9..70db5d696 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutBox01.java @@ -28,28 +28,33 @@ package com.jogamp.opengl.demos.graph.ui; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import com.jogamp.graph.curve.Region; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.font.FontSet; +import com.jogamp.graph.geom.plane.AffineTransform; import com.jogamp.graph.ui.Group; import com.jogamp.graph.ui.Scene; import com.jogamp.graph.ui.Shape; +import com.jogamp.graph.ui.layout.Alignment; import com.jogamp.graph.ui.layout.BoxLayout; import com.jogamp.graph.ui.layout.Margin; import com.jogamp.graph.ui.layout.Padding; import com.jogamp.graph.ui.shapes.Button; import com.jogamp.graph.ui.shapes.Label; -import com.jogamp.graph.ui.shapes.Rectangle; import com.jogamp.graph.ui.shapes.BaseButton; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.GL; +import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.demos.graph.ui.util.Tooltips; import com.jogamp.opengl.demos.util.CommandlineOptions; import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.Vec3f; @@ -64,9 +69,10 @@ import com.jogamp.opengl.util.Animator; * </p> */ public class UILayoutBox01 { - static CommandlineOptions options = new CommandlineOptions(1280, 720, Region.VBAA_RENDERING_BIT); + static CommandlineOptions options = new CommandlineOptions(1920, 1080, Region.VBAA_RENDERING_BIT); - static final boolean reLayout = false; + static boolean reLayout = true; + static final int reLayoutSleep = 500; public static void main(final String[] args) throws IOException { if( 0 != args.length ) { @@ -109,8 +115,12 @@ public class UILayoutBox01 { }); + final int zBits = 16; final Scene scene = new Scene(options.graphAASamples); scene.setPMVMatrixSetup(new Scene.DefaultPMVMatrixSetup(-1f)); + System.err.println("Z16-Precision: default "+Scene.DEFAULT_Z16_EPSILON); + System.err.println("Z16-Precision: zDist -1f, zNear 0.1f "+FloatUtil.getZBufferEpsilon(zBits, -1f, 0.1f)); + System.err.println("Z16-Precision: current "+scene.getZEpsilon(zBits)); scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); scene.setFrustumCullingEnabled(true); scene.attachInputListenerTo(window); @@ -145,124 +155,308 @@ public class UILayoutBox01 { System.err.println("Font: "+font.getFullFamilyName()); final AABBox sceneBox = scene.getBounds(); - System.err.println("SceneBox "+sceneBox); + final float zEps = scene.getZEpsilon(zBits); // Z Epsilon, i.e. minimum recognized delta (resolution) + System.err.println("SceneBox "+sceneBox+", zEps "+zEps); - final float sxy = 1/8f * sceneBox.getWidth(); + final float cellGap = 1.5f; + final float sxy = 1/8.5f * sceneBox.getWidth(); System.err.println("Scale xy "+sxy); - float nextPos = 0; + final Vec3f nextPos = new Vec3f(); + final List<Group> groups = new ArrayList<Group>(); - final Group groupA0 = new Group(new BoxLayout( new Padding(0.15f, 0.15f) ) ); - { - groupA0.addShape( new BaseButton(options.renderModes, 0.70f, 0.70f).setCorner(0f).setInteractive(false).setColor(0, 1, 0, 1) ); - groupA0.addShape( new Button(options.renderModes, font, "stack-0", 0.50f, 0.50f/2f).setCorner(0f).setDragAndResizeable(false) ); - groupA0.addShape( new Label(options.renderModes, font, 0.70f/4f, "A0 pajq").setDragAndResizeable(false).setColor(0, 0, 1, 1) ); + // + // + // + fillDemoScene(groups, reqGLP, scene, zEps, sxy, nextPos, cellGap, + new Margin(0.04f, 0.04f, 0.10f, 0.10f), + new Padding(0.03f, 0.03f, 0.07f, 0.07f), font, dragZoomRotateListener); + + if( reLayout ) { + try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } + int idx = 0; + for(final Group g : groups) { + System.err.println("Group["+idx+"].2.0 "+g); + System.err.println("Group["+idx+"].2.0 "+g.getLayout()); + g.markShapeDirty(); + g.validate(reqGLP); + System.err.println("Group["+idx+"].2.1 "+g); + System.err.println("Group["+idx+"].2.1 "+g.getLayout()); + ++idx; + } } - groupA0.setInteractive(true); - groupA0.addMouseListener(dragZoomRotateListener); - groupA0.scale(sxy, sxy, 1); - groupA0.moveTo(sceneBox.getLow()).move(nextPos, 0, 0); - groupA0.validate(reqGLP); - System.err.println("Group-A0 "+groupA0); - System.err.println("Group-A0 Layout "+groupA0.getLayout()); - groupA0.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupA0); - scene.addShape( new Rectangle(options.renderModes, 1f, 1f, 0.01f).scale(sxy, sxy, 1).moveTo(sceneBox.getLow()).move(nextPos, 0, 0).setInteractive(false).setColor(0, 0, 0, 1) ); - nextPos = groupA0.getScaledWidth() * 1.5f; - - final Group groupA1 = new Group(new BoxLayout( 1f, 1f, new Margin(0.05f, 0.05f), new Padding(0.10f, 0.10f) ) ); + + try { Thread.sleep(1000); } catch (final InterruptedException e1) { } + scene.screenshot(true, scene.nextScreenshotFile(null, UILayoutBox01.class.getSimpleName(), options.renderModes, caps, null)); { - // groupA1.addShape( new BaseButton(options.renderModes, 0.70f, 0.70f).setCorner(0f).setInteractive(false).setColor(0, 1, 0, 1) ); - groupA1.addShape( new BaseButton(options.renderModes, 0.70f, 0.70f).setCorner(0f).setInteractive(false).setColor(0, 1, 0, 1) - .setBorder(0.01f).setPaddding(new Padding(0.0f)) ); - groupA1.addShape( new Button(options.renderModes, font, "stack-1", 0.50f, 0.50f/2f).setCorner(0f).addMouseListener(dragZoomRotateListener) ); - groupA1.addShape( new Label(options.renderModes, font, 0.70f/4f, "A1 pajq").setDragAndResizeable(false).setColor(0, 0, 1, 1) ); + int idx = 0; + for(final Group g : groups) { + System.err.println("Group["+idx+"].2.0 "+g); + System.err.println("Group["+idx+"].2.0 "+g.getLayout()); + ++idx; + } } - // groupA1.setInteractive(true); - groupA1.scale(sxy, sxy, 1); - groupA1.moveTo(sceneBox.getLow()).move(nextPos, 0, 0); - groupA1.validate(reqGLP); - System.err.println("Group-A1 "+groupA1); - System.err.println("Group-A1 Layout "+groupA1.getLayout()); - groupA1.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupA1); - // scene.addShape( new Rectangle(options.renderModes, 1f, 1f, 0.01f).scale(sxy, sxy, 1).moveTo(sceneBox.getLow()).move(nextPos, 0, 0).setInteractive(false).setColor(0, 0, 0, 1) ); - scene.addShape( new Button(options.renderModes, font, "stack-1b", 0.50f, 0.50f/2f).setCorner(0f) - .scale(sxy, sxy, 1f).moveTo(sceneBox.getLow()).move(nextPos, groupA1.getScaledHeight(), 0) - .addMouseListener(dragZoomRotateListener) ); - - nextPos += groupA1.getScaledWidth() * 1.5f; - - final Group groupA2 = new Group(new BoxLayout( 1f, 1f, new Margin(0.10f, Margin.CENTER), new Padding(0.05f, 0) ) ); - { - // groupA2.addShape( new BaseButton(options.renderModes, 0.70f, 0.70f).setCorner(0f).setInteractive(false).setColor(0, 1, 0, 1) ); - groupA2.addShape( new BaseButton(options.renderModes, 0.70f, 0.70f).setCorner(0f).setInteractive(false).setColor(0, 1, 0, 1) - .setBorder(0.01f).setPaddding(new Padding(0.0f)).setBorderColor(1, 0, 0, 1) ); - groupA2.addShape( new Button(options.renderModes, font, "stack-2", 0.50f, 0.50f/2f).setCorner(0f).setDragAndResizeable(false) ); - groupA2.addShape( new Label(options.renderModes, font, 0.70f/4f, "A2 pajq").setDragAndResizeable(false).setColor(0, 0, 1, 1) ); + window.invoke(true, (final GLAutoDrawable drawable) -> { + scene.removeAllShapes(drawable.getGL().getGL2ES2()); + return true; + }); + groups.clear(); + + // + // + // + nextPos.set(0, 0, 0); + + fillDemoScene(groups, reqGLP, scene, zEps, sxy, nextPos, cellGap, + new Margin(0.07f, 0.07f), + new Padding(0.10f, 0.10f), font, dragZoomRotateListener); + + if( reLayout ) { + try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } + int idx = 0; + for(final Group g : groups) { + System.err.println("Group["+idx+"].2.0 "+g); + System.err.println("Group["+idx+"].2.0 "+g.getLayout()); + g.markShapeDirty(); + g.validate(reqGLP); + System.err.println("Group["+idx+"].2.1 "+g); + System.err.println("Group["+idx+"].2.1 "+g.getLayout()); + ++idx; + } } - groupA2.setInteractive(true); - groupA2.scale(sxy, sxy, 1); - groupA2.moveTo(sceneBox.getLow()).move(nextPos, 0, 0); - groupA2.validate(reqGLP); - System.err.println("Group-A2 "+groupA2); - System.err.println("Group-A2 Layout "+groupA2.getLayout()); - groupA2.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupA2); - // scene.addShape( new Rectangle(options.renderModes, 1f, 1f, 0.01f).scale(sxy, sxy, 1).moveTo(sceneBox.getLow()).move(nextPos, 0, 0).setInteractive(false).setColor(0, 0, 0, 1) ); - nextPos += groupA2.getScaledWidth() * 1.5f; - - final Group groupA3 = new Group(new BoxLayout( 1f, 1f, new Margin(0.10f, Margin.CENTER), new Padding(0.05f, 0f) ) ); + + try { Thread.sleep(1000); } catch (final InterruptedException e1) { } + scene.screenshot(true, scene.nextScreenshotFile(null, UILayoutBox01.class.getSimpleName(), options.renderModes, caps, null)); { - // groupA3.addShape( new BaseButton(options.renderModes, 0.70f, 0.70f).setCorner(0f).setInteractive(false).setColor(0, 1, 0, 1) ); - groupA3.addShape( new BaseButton(options.renderModes, 0.70f, 0.70f).setCorner(0f).setInteractive(false).setColor(0, 1, 0, 1) - .setBorder(0.01f).setPaddding(new Padding(0.0f)).setBorderColor(0, 0, 1, 1) ); - groupA3.addShape( new Button(options.renderModes, font, "stack-3", 0.50f, 0.50f/2f).setCorner(0f).setDragAndResizeable(false) ); - groupA3.addShape( new Label(options.renderModes, font, 0.70f/4f, "A3 pajq").setDragAndResizeable(false).setColor(0, 0, 1, 1) ); + int idx = 0; + for(final Group g : groups) { + System.err.println("Group["+idx+"].3.0 "+g); + System.err.println("Group["+idx+"].3.0 "+g.getLayout()); + ++idx; + } } - groupA3.scale(sxy, sxy, 1); - groupA3.moveTo(sceneBox.getLow()).move(nextPos, 0, 0); - groupA3.validate(reqGLP); - System.err.println("Group-A3 "+groupA3); - System.err.println("Group-A3 Layout "+groupA3.getLayout()); - groupA3.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupA3); - // scene.addShape( new Rectangle(options.renderModes, 1f, 1f, 0.01f).scale(sxy, sxy, 1).moveTo(sceneBox.getLow()).move(nextPos, 0, 0).setInteractive(false).setColor(0, 0, 0, 1) ); - nextPos += groupA3.getScaledWidth() * 1.5f; - - final Group groupA4 = new Group(new BoxLayout( 1f, 1f, new Margin(Margin.CENTER), new Padding(0.0f, 0f) ) ); - { - // groupA4.addShape( new BaseButton(options.renderModes, 0.70f, 0.70f).setCorner(0f).setInteractive(false).setColor(0, 1, 0, 1) ); - groupA4.addShape( new BaseButton(options.renderModes, 0.70f, 0.70f).setCorner(0f).setInteractive(false).setColor(0, 1, 0, 1) - .setBorder(0.01f).setPaddding(new Padding(0.0f)).setBorderColor(0f, 0f, 0f, 1) ); - groupA4.addShape( new Button(options.renderModes, font, "stack-4", 0.50f, 0.50f/2f).setCorner(0f).setDragAndResizeable(false) ); - groupA4.addShape( new Label(options.renderModes, font, 0.70f/4f, "A4 pajq").setDragAndResizeable(false).setColor(0, 0, 1, 1) ); + + if( !options.stayOpen ) { + window.destroy(); } - groupA4.scale(sxy, sxy, 1); - groupA4.moveTo(sceneBox.getLow()).move(nextPos, 0, 0); - groupA4.validate(reqGLP); - System.err.println("Group-A4 "+groupA4); - System.err.println("Group-A4 Layout "+groupA4.getLayout()); - groupA4.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupA4); - // scene.addShape( new Rectangle(options.renderModes, 1f, 1f, 0.01f).scale(sxy, sxy, 1).moveTo(sceneBox.getLow()).move(nextPos, 0, 0).setInteractive(false).setColor(0, 0, 0, 1) ); - nextPos += groupA4.getScaledWidth() * 1.5f; + } - if( reLayout ) { - try { Thread.sleep(1000); } catch (final InterruptedException e1) { } - groupA4.markShapeDirty(); - groupA4.validate(reqGLP); - System.err.println("Group-A4.2 "+groupA4); - System.err.println("Group-A4 Layout.2 "+groupA4.getLayout()); + @SuppressWarnings("unused") + static void fillDemoScene(final List<Group> groups, final GLProfile reqGLP, final Scene scene, + final float zEps, final float sxy, final Vec3f nextPos, final float cellGap, + final Margin margin, final Padding padding, + final Font font, final Shape.MouseGestureListener dragZoomRotateListener) + { + // + // 1. Row + // + int id = 11; + if( true ) { + // 11 + final Group g = fillDemoGroup(new Group( new BoxLayout() ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + // 12 + final Group g = fillDemoGroup(new Group( new BoxLayout( padding ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + // 13 + final Group g = fillDemoGroup(new Group( new BoxLayout(1f, 1f) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + // 14 + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, margin ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + // 15 + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, padding ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + // 16 + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, margin, padding ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); } + ++id; + nextPos.set(0, nextPos.y() + sxy * cellGap, 0); // + // 2. Row // + id = 21; + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, new Alignment(Alignment.Bit.CenterHoriz) ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, new Alignment(Alignment.Bit.CenterVert) ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, Alignment.Center ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, Alignment.Fill ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, Alignment.FillCenter ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + ++id; + nextPos.set(0, nextPos.y() + sxy * cellGap, 0); + // - nextPos = 0; + // 3. Row + // + id = 31; + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, Alignment.Center, margin, null ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; - try { Thread.sleep(1000); } catch (final InterruptedException e1) { } - if( !options.stayOpen ) { - window.destroy(); + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, Alignment.Center, new Margin(), padding ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, Alignment.Center, margin, padding ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, Alignment.Fill, margin, null ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, Alignment.Fill, new Margin(), padding ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + nextPos.setX( nextPos.x() + sxy * cellGap ); + ++id; + + if( true ) { + final Group g = fillDemoGroup(new Group( new BoxLayout( 1f, 1f, Alignment.Fill, margin, padding ) ), + reqGLP, scene, zEps, sxy, nextPos, font, id, dragZoomRotateListener); + groups.add(g); + } + ++id; + nextPos.set(0, nextPos.y() + sxy * cellGap, 0); + + { + final AABBox sceneDim = scene.getBounds(); + final String text = " Press group description to magnify! "; + final AABBox textDim = font.getGlyphBounds(text, new AffineTransform(), new AffineTransform()); + final float l_sxy = 1/4f * sceneDim.getWidth() / textDim.getWidth(); + + final Shape label = new Label(options.renderModes, font, text).setColor(0, 0, 0, 1).setInteractive(false) + .scale(l_sxy, l_sxy, 1).moveTo(sceneDim.getLow()) + .move(0, sceneDim.getHeight() - textDim.getHeight()*l_sxy, 0); + scene.addShape(label); + } + + } + static Group fillDemoGroup(final Group g, final GLProfile reqGLP, final Scene scene, final float zEps, final float sxy, final Vec3f nextPos, + final Font font, final int id, + final Shape.MouseGestureListener dragZoomRotateListener) + { + final String suffix = String.format("%2d", id); + g.setName(id); + final AABBox sceneBox = scene.getBounds(); + { + g.addShape( new BaseButton(options.renderModes, 0.70f, 0.70f).setPerp().setColor(0, 1, 0, 1).setBorder(0.01f).setBorderColor(0, 0, 1, 1.0f).addMouseListener(dragZoomRotateListener) ); + g.addShape( new Button(options.renderModes, font, "stack-"+suffix, 0.50f, 0.50f/2f, zEps).setPerp().move(0, 0, zEps).setInteractive(false) ); + g.addShape( new Label(options.renderModes, font, 0.70f/4f, "A"+suffix+" pajq").setColor(0, 0, 1, 1).move(0, 0, 2*zEps).setInteractive(false) ); + } + g.scale(sxy, sxy, 1); + g.moveTo(sceneBox.getLow()).move(nextPos); + g.setBorder(0.01f).setBorderColor(0, 0, 0, 0.6f); + g.validate(reqGLP); + System.err.println("Group-A"+suffix+" "+g); + System.err.println("Group-A"+suffix+" Layout "+g.getLayout()); + g.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + scene.addShape(g); + { + final float X_width = font.getGlyph(font.getGlyphID(' ')).getAdvance(); + /** + * G 23, size[total 2.1 x 1.7, cell 1.0 x 0.5] + * Padding[t 0.05, r 0.05, b 0.05, l 0.05] + * Margin[t 0.05, r 0.05, b 0.05, l 0.05] + * Align [CenterHoriz, CenterVert, Fill] + */ + final String fixed_text = "G 23, size[total 2.1 x 1.7, cell 1.0"; + // final float l_sxy = g.getScaledWidth() / font.getGlyphBounds(fixed_text, new AffineTransform(), new AffineTransform()).getWidth(); + final float l_sxy = sxy / font.getGlyphBounds(fixed_text, new AffineTransform(), new AffineTransform()).getWidth(); + + final BoxLayout l = (BoxLayout)g.getLayout(); + final String text = String.format("G %2d, size[total %.1f x %.1f, cell %.1f x %.1f]%n%s%n%s%nAlign %s", + id, g.getBounds().getWidth(), g.getBounds().getHeight(), l.getCellSize().x(), l.getCellSize().y(), + ( null == l.getPadding() || l.getPadding().zeroSumSize() ) ? "Padding none" : l.getPadding().toString(), + l.getMargin().zeroSumSize() ? "Margin none" : l.getMargin().toString(), + l.getAlignment() ); + final Shape label = new Label(options.renderModes, font, text).setColor(0, 0, 0, 1).validate(reqGLP); + label.scale(l_sxy, l_sxy, 1).moveTo(sceneBox.getLow()).move(nextPos).move(l_sxy*X_width, g.getScaledHeight(), 0) + .addMouseListener(new Tooltips.ZoomLabelOnClickListener(scene, options.renderModes, 1/4f)).setDragAndResizeable(false); + scene.addShape(label); + System.err.println("ID "+id+": "+label); } + return g; } } diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java index 8fe989344..1a5881d00 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UILayoutGrid01.java @@ -33,6 +33,7 @@ import com.jogamp.graph.curve.Region; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.font.FontSet; +import com.jogamp.graph.geom.plane.AffineTransform; import com.jogamp.graph.ui.Group; import com.jogamp.graph.ui.Scene; import com.jogamp.graph.ui.Shape; @@ -41,13 +42,16 @@ import com.jogamp.graph.ui.layout.Gap; import com.jogamp.graph.ui.layout.GridLayout; import com.jogamp.graph.ui.layout.Padding; import com.jogamp.graph.ui.shapes.Button; +import com.jogamp.graph.ui.shapes.Label; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.GL; +import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.demos.graph.ui.util.Tooltips; import com.jogamp.opengl.demos.util.CommandlineOptions; import com.jogamp.opengl.math.FloatUtil; import com.jogamp.opengl.math.Vec3f; @@ -63,7 +67,7 @@ import com.jogamp.opengl.util.Animator; * </p> */ public class UILayoutGrid01 { - static CommandlineOptions options = new CommandlineOptions(1280, 720, Region.VBAA_RENDERING_BIT); + static CommandlineOptions options = new CommandlineOptions(1920, 1080, Region.VBAA_RENDERING_BIT); static boolean reLayout = true; static final int reLayoutSleep = 500; @@ -109,8 +113,12 @@ public class UILayoutGrid01 { }); + final int zBits = 16; final Scene scene = new Scene(options.graphAASamples); scene.setPMVMatrixSetup(new Scene.DefaultPMVMatrixSetup(-1f)); + System.err.println("Z16-Precision: default "+Scene.DEFAULT_Z16_EPSILON); + System.err.println("Z16-Precision: zDist -1f, zNear 0.1f "+FloatUtil.getZBufferEpsilon(zBits, -1f, 0.1f)); + System.err.println("Z16-Precision: current "+scene.getZEpsilon(zBits)); scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); scene.setFrustumCullingEnabled(true); scene.attachInputListenerTo(window); @@ -145,318 +153,203 @@ public class UILayoutGrid01 { System.err.println("Font: "+font.getFullFamilyName()); final AABBox sceneBox = scene.getBounds(); - System.err.println("SceneBox "+sceneBox); + final float zEps = scene.getZEpsilon(zBits); // Z Epsilon, i.e. minimum recognized delta (resolution) + System.err.println("SceneBox "+sceneBox+", zEps "+zEps); + final float cellGap = 1.1f; final Vec4f borderColor = new Vec4f(0, 0, 1f, 0.6f); final float borderThickness = 0.01f; - final float sxy = 1/10f * sceneBox.getWidth(); - float nextXPos = 0, nextYTop = sceneBox.getHeight(); - - final Group groupA0 = new Group(new GridLayout(1, 1f, 1/2f, Alignment.Fill, new Gap(0.10f))); - groupA0.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); - groupA0.setBorder(borderThickness).setBorderColor(borderColor); - groupA0.scale(sxy, sxy, 1); - groupA0.setInteractive(true); - groupA0.validate(reqGLP); - groupA0.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupA0.getScaledHeight(), 0); - System.err.println("Group-A0 "+groupA0); - System.err.println("Group-A0 Layout "+groupA0.getLayout()); - groupA0.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupA0); - nextXPos += groupA0.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupA0.markShapeDirty(); - groupA0.validate(reqGLP); - System.err.println("Group-A0.2 "+groupA0); - System.err.println("Group-A0 Layout.2 "+groupA0.getLayout()); - groupA0.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + // final float sxy = 1/10f * sceneBox.getWidth(); + final float sxy = 1/11f * sceneBox.getWidth(); + // final float sxy = 1/4f * sceneBox.getHeight(); + final Vec3f nextPos = new Vec3f(); + + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(1, 1f, 1/2f, Alignment.Fill, new Gap(0.10f))), + reqGLP, scene, zEps, + sxy, nextPos, cellGap, + font, 11, + borderThickness, borderColor, (final Group gp) -> { + gp.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } - final Group groupA1 = new Group(new GridLayout(1, 1, 1/2f, Alignment.Fill, new Gap(0.10f))); - groupA1.addShape( new Button(options.renderModes, font, "ro co", 1f, 1/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupA1.addShape( new Button(options.renderModes, font, "r1 r1", 1f, 1/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupA1.setBorder(sxy*borderThickness).setBorderColor(borderColor); - groupA1.scale(sxy, sxy, 1); - groupA1.setInteractive(true); - groupA1.validate(reqGLP); - groupA1.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupA1.getScaledHeight(), 0); - System.err.println("Group-A1 "+groupA1); - System.err.println("Group-A1 Layout "+groupA1.getLayout()); - groupA1.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupA1); - nextXPos += groupA1.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupA1.markShapeDirty(); - groupA1.validate(reqGLP); - System.err.println("Group-A1.2 "+groupA1); - System.err.println("Group-A1 Layout.2 "+groupA1.getLayout()); - groupA1.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(1, 1f, 1/2f, Alignment.Fill, new Gap(0.10f))), + reqGLP, scene, zEps, + sxy, nextPos, cellGap, + font, 12, + borderThickness, borderColor, (final Group gp) -> { + gp.addShape( new Button(options.renderModes, font, "ro co", 1f, 1/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r1 r1", 1f, 1/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } - final Group groupA2 = new Group(new GridLayout(1, 1/2f, Alignment.Fill, new Gap(0.10f), 1)); - groupA2.addShape( new Button(options.renderModes, font, "ro co", 1f, 1/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupA2.addShape( new Button(options.renderModes, font, "r1 c1", 1f, 1/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupA2.setBorder(sxy*borderThickness).setBorderColor(borderColor); - groupA2.scale(sxy, sxy, 1); - groupA2.setInteractive(true); - groupA2.validate(reqGLP); - groupA2.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupA2.getScaledHeight(), 0); - System.err.println("Group-A2 "+groupA2); - System.err.println("Group-A2 Layout "+groupA2.getLayout()); - groupA2.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupA2); - nextXPos += groupA2.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupA2.markShapeDirty(); - groupA2.validate(reqGLP); - System.err.println("Group-A2.2 "+groupA2); - System.err.println("Group-A2 Layout.2 "+groupA2.getLayout()); - groupA2.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(1f, 1/2f, Alignment.Fill, new Gap(0.10f), 1)), + reqGLP, scene, zEps, + sxy, nextPos, cellGap, + font, 13, + borderThickness, borderColor, (final Group gp) -> { + gp.addShape( new Button(options.renderModes, font, "ro co", 1f, 1/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r1 c1", 1f, 1/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } - final Group groupA3 = new Group(new GridLayout(2, 1f, 1/2f, Alignment.Fill, new Gap(0.10f))); - { - groupA3.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); - groupA3.addShape( new Button(options.renderModes, font, "r1 c2", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupA3.addShape( new Button(options.renderModes, font, "r2 c1", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupA3.addShape( new Button(options.renderModes, font, "r2 c2", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); - } - groupA3.setBorder(borderThickness).setBorderColor(borderColor); - groupA3.scale(sxy, sxy, 1); - groupA3.setInteractive(true); - groupA3.validate(reqGLP); - groupA3.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupA3.getScaledHeight(), 0); - System.err.println("Group-A3 "+groupA3); - System.err.println("Group-A3 Layout "+groupA3.getLayout()); - groupA3.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupA3); - nextXPos += groupA3.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupA3.markShapeDirty(); - groupA3.validate(reqGLP); - System.err.println("Group-A3.2 "+groupA3); - System.err.println("Group-A3 Layout.2 "+groupA3.getLayout()); - groupA3.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(2, 1f, 1/2f, Alignment.Fill, new Gap(0.10f))), + reqGLP, scene, zEps, + sxy, nextPos, cellGap, + font, 14, + borderThickness, borderColor, (final Group gp) -> { + gp.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } - final Group groupA4 = new Group(new GridLayout(2, 1f, 1/2f, Alignment.Fill, new Gap(0.10f))); - { - groupA4.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); - groupA4.addShape( new Button(options.renderModes, font, "r1 c2", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupA4.addShape( new Button(options.renderModes, font, "r2 c1", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupA4.addShape( new Button(options.renderModes, font, "r2 c2", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); - groupA4.addShape( new Button(options.renderModes, font, "r3 c1", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - } - groupA4.setBorder(borderThickness).setBorderColor(borderColor); - groupA4.scale(sxy, sxy, 1); - groupA4.setInteractive(true); - groupA4.validate(reqGLP); - groupA4.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupA4.getScaledHeight(), 0); - System.err.println("Group-A4 "+groupA4); - System.err.println("Group-A4 Layout "+groupA4.getLayout()); - groupA4.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupA4); - nextXPos += groupA4.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupA4.markShapeDirty(); - groupA4.validate(reqGLP); - System.err.println("Group-A4.2 "+groupA4); - System.err.println("Group-A4 Layout.2 "+groupA4.getLayout()); - groupA4.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(2, 1f, 1/2f, Alignment.Fill, new Gap(0.10f))), + reqGLP, scene, zEps, + sxy, nextPos, cellGap, + font, 15, + borderThickness, borderColor, (final Group gp) -> { + gp.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r3 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } + // + // // next line - nextXPos = 0; - nextYTop = 2f*sceneBox.getHeight()/3f; - - final Group groupB0 = new Group(new GridLayout(2, sxy, sxy/2f, Alignment.Fill, new Gap(sxy*0.10f))); - { - groupB0.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); - groupB0.addShape( new Button(options.renderModes, font, "r1 c2", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupB0.addShape( new Button(options.renderModes, font, "r2 c1", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupB0.addShape( new Button(options.renderModes, font, "r2 c2", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); - groupB0.addShape( new Button(options.renderModes, font, "r3 c1", 1f, 1f/2f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - } - groupB0.setBorder(sxy*borderThickness).setBorderColor(borderColor); - // groupB0.scale(2*sxy, 2*sxy, 1); - groupB0.setInteractive(true); - groupB0.validate(reqGLP); - groupB0.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupB0.getScaledHeight(), 0); - System.err.println("Group-B0 "+groupB0); - System.err.println("Group-B0 Layout "+groupB0.getLayout()); - groupB0.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupB0); - nextXPos += groupB0.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupB0.markShapeDirty(); - groupB0.validate(reqGLP); - System.err.println("Group-B0.2 "+groupB0); - System.err.println("Group-B0 Layout.2 "+groupB0.getLayout()); - groupB0.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + nextPos.set(0, nextPos.y() + sceneBox.getHeight()/3f, 0 ); + + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(2, 1f, 1/2f, Alignment.Fill, new Gap(0.10f))), + reqGLP, scene, zEps, + sxy, nextPos, cellGap, + font, 21, + sxy*borderThickness, borderColor, (final Group gp) -> { + gp.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r3 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } - final Group groupB1 = new Group(new GridLayout(2, sxy, sxy/2f, Alignment.FillCenter, new Gap(sxy*0.10f))); - { - final Padding p = new Padding(0.05f); - groupB1.addShape( new Button(options.renderModes, font, "ro co", 1, 1/2f).setCorner(0f).setPaddding(p).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); - groupB1.addShape( new Button(options.renderModes, font, "r1 c2", 1, 1/2f).setCorner(0f).setPaddding(p).setBorder(borderThickness).setDragAndResizeable(false) ); - groupB1.addShape( new Button(options.renderModes, font, "r2 c1", 1, 1/2f).setCorner(0f).setPaddding(p).setBorder(borderThickness).setDragAndResizeable(false) ); - groupB1.addShape( new Button(options.renderModes, font, "r2 c2", 1, 1/2f).setCorner(0f).setPaddding(p).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); - groupB1.addShape( new Button(options.renderModes, font, "r3 c1", 1, 1/2f).setCorner(0f).setPaddding(p).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); - } - groupB1.setBorder(sxy*borderThickness).setBorderColor(borderColor); - // groupB1.scale(2*sxy, 2*sxy, 1); - groupB1.setInteractive(true); - groupB1.validate(reqGLP); - groupB1.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupB1.getScaledHeight(), 0); - System.err.println("Group-B1 "+groupB1); - System.err.println("Group-B1 Layout "+groupB1.getLayout()); - groupB1.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupB1); - nextXPos += groupB1.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupB1.markShapeDirty(); - groupB1.validate(reqGLP); - System.err.println("Group-B1.2 "+groupB1); - System.err.println("Group-B1 Layout.2 "+groupB1.getLayout()); - groupB1.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(2, 1f, 1/2f, Alignment.FillCenter, new Gap(0.10f), new Padding(0.05f))), + reqGLP, scene, zEps, + sxy, nextPos, cellGap, + font, 22, + borderThickness, borderColor, (final Group gp) -> { + gp.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r3 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } - final Group groupB2 = new Group(new GridLayout(2, sxy, sxy/2f, Alignment.FillCenter, new Gap(sxy*0.10f))); - { - final Padding p = new Padding(sxy/2f*0.05f); - groupB2.addShape( new Button(options.renderModes, font, "ro co", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy/2f*borderThickness).addMouseListener(dragZoomRotateListener) ); - groupB2.addShape( new Button(options.renderModes, font, "r1 c2", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy/2f*borderThickness).setDragAndResizeable(false) ); - groupB2.addShape( new Button(options.renderModes, font, "r2 c1", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy/2f*borderThickness).setDragAndResizeable(false) ); - groupB2.addShape( new Button(options.renderModes, font, "r2 c2", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy/2f*borderThickness).addMouseListener(dragZoomRotateListener) ); - groupB2.addShape( new Button(options.renderModes, font, "r3 c1", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy/2f*borderThickness).addMouseListener(dragZoomRotateListener) ); - } - groupB2.setBorder(sxy*borderThickness).setBorderColor(borderColor); - // groupB2.scale(2*sxy, 2*sxy, 1); - groupB2.setInteractive(true); - groupB2.validate(reqGLP); - groupB2.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupB2.getScaledHeight(), 0); - System.err.println("Group-B2 "+groupB2); - System.err.println("Group-B2 Layout "+groupB2.getLayout()); - groupB2.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupB2); - nextXPos += groupB2.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupB2.markShapeDirty(); - groupB2.validate(reqGLP); - System.err.println("Group-B2.2 "+groupB2); - System.err.println("Group-B2 Layout.2 "+groupB2.getLayout()); - groupB2.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(2, 1f, 1/2f, Alignment.FillCenter, new Gap(0.10f), new Padding(0.05f))), + reqGLP, scene, zEps, + sxy, nextPos, cellGap, + font, 23, + borderThickness, borderColor, (final Group gp) -> { + gp.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r3 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } - final Group groupB3 = new Group(new GridLayout(2, sxy, sxy/2f, Alignment.Fill, new Gap(sxy*0.10f))); - { - final Padding p = new Padding(sxy/2f*0.05f); - groupB3.addShape( new Button(options.renderModes, font, "ro co", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy/2f*borderThickness).addMouseListener(dragZoomRotateListener) ); - groupB3.addShape( new Button(options.renderModes, font, "r1 c2", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy/2f*borderThickness).setDragAndResizeable(false) ); - groupB3.addShape( new Button(options.renderModes, font, "r2 c1", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy/2f*borderThickness).setDragAndResizeable(false) ); - groupB3.addShape( new Button(options.renderModes, font, "r2 c2", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy/2f*borderThickness).addMouseListener(dragZoomRotateListener) ); - groupB3.addShape( new Button(options.renderModes, font, "r3 c1", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy/2f*borderThickness).addMouseListener(dragZoomRotateListener) ); - } - groupB3.setBorder(sxy*borderThickness).setBorderColor(borderColor); - // groupB3.scale(2*sxy, 2*sxy, 1); - groupB3.setInteractive(true); - groupB3.validate(reqGLP); - groupB3.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupB3.getScaledHeight(), 0); - System.err.println("Group-B3 "+groupB3); - System.err.println("Group-B3 Layout "+groupB3.getLayout()); - groupB3.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupB3); - nextXPos += groupB3.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupB3.markShapeDirty(); - groupB3.validate(reqGLP); - System.err.println("Group-B3.2 "+groupB3); - System.err.println("Group-B3 Layout.2 "+groupB3.getLayout()); - groupB3.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(2, 1f, 1/2f, Alignment.Fill, new Gap(0.10f), new Padding(0.05f))), + reqGLP, scene, zEps, + sxy, nextPos, cellGap, + font, 24, + borderThickness, borderColor, (final Group gp) -> { + gp.addShape( new Button(options.renderModes, font, "ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r3 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } // next line - nextXPos = 0; - nextYTop = sceneBox.getHeight()/3f; - - final Group groupC0 = new Group(new GridLayout(2, 0, 0, Alignment.Fill, new Gap(0.03f))); - { - final Group glyphGrid = new Group(new GridLayout(2, 0.3f, 0.3f, Alignment.Fill, new Gap(0.3f * 0.10f))); - glyphGrid.addShape( new Button(options.renderModes, font, "0.0", 1f, 1f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - glyphGrid.addShape( new Button(options.renderModes, font, "0.1", 1f, 1f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - glyphGrid.addShape( new Button(options.renderModes, font, "1.0", 1f, 1f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - glyphGrid.addShape( new Button(options.renderModes, font, "1.1", 1f, 1f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupC0.addShape(glyphGrid.setBorder(borderThickness)); - - final Group infoGrid = new Group(new GridLayout(1, 1/4f, 1/2f, Alignment.Fill, new Gap(0.02f))); - // final Group glyphView = new Group(); - // glyphView.addShape(new Rectangle(options.renderModes, 1f, 1f, 0.005f).setInteractive(false)); - // glyphView.addShape(new Button(options.renderModes, font, "S", 1f, 1f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - // infoGrid.addShape(glyphView.setBorder(borderThickness)); - infoGrid.addShape(new Button(options.renderModes, font, " S ", 1/2f, 1f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - - // final Group infoView = new Group(); - // infoView.addShape(new Button(options.renderModes, font, "Info", 1f, 1f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - // infoGrid.addShape(infoView.setBorder(borderThickness)); - infoGrid.addShape(new Button(options.renderModes, font, " Info ", 1/2f, 1f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - groupC0.addShape(infoGrid.setBorder(borderThickness)); - // groupC0.addShape(new Button(options.renderModes, font, "S", 1/4f, 0.5f).setCorner(0f).setBorder(borderThickness).setDragAndResizeable(false) ); - } - groupC0.setBorder(sxy*borderThickness).setBorderColor(borderColor); - groupC0.scale(2*sxy, 2*sxy, 1); - groupC0.setInteractive(true); - groupC0.validate(reqGLP); - groupC0.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupC0.getScaledHeight(), 0); - System.err.println("Group-C0 "+groupC0); - System.err.println("Group-C0 Layout "+groupC0.getLayout()); - groupC0.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupC0); - nextXPos += groupC0.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupC0.markShapeDirty(); - groupC0.validate(reqGLP); - System.err.println("Group-C0.2 "+groupC0); - System.err.println("Group-C0 Layout.2 "+groupC0.getLayout()); - groupC0.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + nextPos.set(0, nextPos.y() + sceneBox.getHeight()/3f, 0 ); + + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(2, 0, 0, Alignment.Fill, new Gap(0.03f))), + reqGLP, scene, zEps, + 2*sxy, nextPos, cellGap, + font, 31, + borderThickness, borderColor, (final Group gp) -> { + final Group glyphGrid = new Group(new GridLayout(2, 0.3f, 0.3f, Alignment.Fill, new Gap(0.3f * 0.10f))); + glyphGrid.addShape( new Button(options.renderModes, font, "0.0", 1f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + glyphGrid.addShape( new Button(options.renderModes, font, "0.1", 1f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + glyphGrid.addShape( new Button(options.renderModes, font, "1.0", 1f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + glyphGrid.addShape( new Button(options.renderModes, font, "1.1", 1f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape(glyphGrid.setBorder(borderThickness)); + + final Group infoGrid = new Group(new GridLayout(1, 1/4f, 1/2.2f, Alignment.Fill, new Gap(0.02f))); + // final Group glyphView = new Group(); + // glyphView.addShape(new Rectangle(options.renderModes, 1f, 1f, 0.005f).setInteractive(false)); + // glyphView.addShape(new Button(options.renderModes, font, "S", 1f, 1f).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + // infoGrid.addShape(glyphView.setBorder(borderThickness)); + infoGrid.addShape(new Button(options.renderModes, font, " S ", 1/2f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + + // final Group infoView = new Group(); + // infoView.addShape(new Button(options.renderModes, font, "Info", 1f, 1f).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + // infoGrid.addShape(infoView.setBorder(borderThickness)); + infoGrid.addShape(new Button(options.renderModes, font, " Info ", 1/2f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + gp.addShape(infoGrid.setBorder(borderThickness)); + // groupC0.addShape(new Button(options.renderModes, font, "S", 1/4f, 0.5f).setPerp().setBorder(borderThickness).setDragAndResizeable(false) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } - final Group groupC3 = new Group(new GridLayout(2, sxy, sxy/2f, Alignment.Center, new Gap(sxy*0.10f))); - { - final Padding p = new Padding(sxy*0.05f); - groupC3.addShape( new Button(options.renderModes, font, "ro co", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy*borderThickness).addMouseListener(dragZoomRotateListener) ); - groupC3.addShape( new Button(options.renderModes, font, "r1 c2", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy*borderThickness).setDragAndResizeable(false) ); - groupC3.addShape( new Button(options.renderModes, font, "r2 c1", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy*borderThickness).setDragAndResizeable(false) ); - groupC3.addShape( new Button(options.renderModes, font, "r2 c2", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy*borderThickness).addMouseListener(dragZoomRotateListener) ); - groupC3.addShape( new Button(options.renderModes, font, "r3 c1", sxy/2f, sxy/4f).setCorner(0f).setPaddding(p).setBorder(sxy*borderThickness).addMouseListener(dragZoomRotateListener) ); + if( true ) { + final Group g = setupGroup(new Group(new GridLayout(2, 1, 1/2f, Alignment.Center, new Gap(0.10f), new Padding(0.05f))), + reqGLP, scene, zEps, + sxy, nextPos, cellGap, + font, 32, + borderThickness, borderColor, (final Group gp) -> { + gp.addShape( new Button(options.renderModes, font, "ro co", 1/2f, 1/4.1f, zEps).setPerp().setBorder(sxy*borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r1 c2", 1/2f, 1/4.1f, zEps).setPerp().setBorder(sxy*borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c1", 1/2f, 1/4.1f, zEps).setPerp().setBorder(sxy*borderThickness).setDragAndResizeable(false) ); + gp.addShape( new Button(options.renderModes, font, "r2 c2", 1/2f, 1/4.1f, zEps).setPerp().setBorder(sxy*borderThickness).addMouseListener(dragZoomRotateListener) ); + gp.addShape( new Button(options.renderModes, font, "r3 c1", 1/2f, 1/4.1f, zEps).setPerp().setBorder(sxy*borderThickness).addMouseListener(dragZoomRotateListener) ); + } ); + nextPos.setX( nextPos.x() + g.getScaledWidth() * cellGap ); } - groupC3.setBorder(sxy*borderThickness).setBorderColor(borderColor); - // groupC3.scale(2*sxy, 2*sxy, 1); - groupC3.setInteractive(true); - groupC3.validate(reqGLP); - groupC3.moveTo(sceneBox.getLow()).move(nextXPos, nextYTop-groupC3.getScaledHeight(), 0); - System.err.println("Group-C3 "+groupC3); - System.err.println("Group-C3 Layout "+groupC3.getLayout()); - groupC3.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); - scene.addShape(groupC3); - nextXPos += groupC3.getScaledWidth() * 1.1f; - if( reLayout ) { - try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } - groupC3.markShapeDirty(); - groupC3.validate(reqGLP); - System.err.println("Group-C3.2 "+groupC3); - System.err.println("Group-C3 Layout.2 "+groupC3.getLayout()); - groupC3.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + { + final AABBox sceneDim = scene.getBounds(); + final String text = " Press group description to magnify! "; + final AABBox textDim = font.getGlyphBounds(text, new AffineTransform(), new AffineTransform()); + final float l_sxy = 1/4f * sceneDim.getWidth() / textDim.getWidth(); + + final Shape label = new Label(options.renderModes, font, text).setColor(0, 0, 0, 1).setInteractive(false) + .scale(l_sxy, l_sxy, 1).moveTo(sceneDim.getLow()) + .move(sceneDim.getWidth() - textDim.getWidth()*l_sxy, sceneDim.getHeight() - textDim.getHeight()*l_sxy, 0); + scene.addShape(label); } try { Thread.sleep(1000); } catch (final InterruptedException e1) { } @@ -465,4 +358,57 @@ public class UILayoutGrid01 { window.destroy(); } } + + static interface GroupMod { + void mod(Group group); + } + static Group setupGroup(final Group g, final GLProfile reqGLP, final Scene scene, final float zEps, + final float sxy, final Vec3f nextPos, final float cellGap, + final Font font, final int id, + final float borderThickness, final Vec4f borderColor, final GroupMod modImpl) { + final String suffix = String.format("%2d", id); + g.setName(id); + final AABBox sceneBox = scene.getBounds(); + modImpl.mod(g); + g.setBorder(borderThickness).setBorderColor(borderColor); + g.scale(sxy, sxy, 1); + g.setInteractive(true); + g.validate(reqGLP); + g.moveTo(sceneBox.getLow()).move(nextPos); + System.err.println("Group-"+suffix+" "+g); + System.err.println("Group-"+suffix+" Layout "+g.getLayout()); + g.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + scene.addShape(g); + { + final float X_width = font.getGlyph(font.getGlyphID(' ')).getAdvance(); + /** + * ID 23: G 23, size[total 2.1 x 1.7, cell 1.0 x 0.5] + * Padding[t 0.05, r 0.05, b 0.05, l 0.05] + * Gap[r 0.1, c 0.1], Align [CenterHoriz, CenterVert, Fill] + */ + final String fixed_text = "Gap[r 0.1, c 0.1], Align [CenterHoriz, CenterVert, Fi"; + final float l_sxy = g.getScaledWidth() / font.getGlyphBounds(fixed_text, new AffineTransform(), new AffineTransform()).getWidth(); + + final GridLayout l = (GridLayout)g.getLayout(); + final String text = String.format("G %2d, size[total %.1f x %.1f, cell %.1f x %.1f]%n%s%n%s, Align %s", + id, g.getBounds().getWidth(), g.getBounds().getHeight(), l.getCellSize().x(), l.getCellSize().y(), + ( null == l.getPadding() || l.getPadding().zeroSumSize() ) ? "Padding none" : l.getPadding().toString(), + l.getGap().zeroSumSize() ? "Gap none" : l.getGap().toString(), + l.getAlignment() ); + final Shape label = new Label(options.renderModes, font, text).setColor(0, 0, 0, 1).validate(reqGLP); + label.scale(l_sxy, l_sxy, 1).moveTo(sceneBox.getLow()).move(nextPos).move(l_sxy*X_width, g.getScaledHeight(), 0) + .addMouseListener(new Tooltips.ZoomLabelOnClickListener(scene, options.renderModes, 1/6f)).setDragAndResizeable(false); + scene.addShape(label); + } + if( reLayout ) { + try { Thread.sleep(reLayoutSleep); } catch (final InterruptedException e1) { } + g.markShapeDirty(); + g.validate(reqGLP); + System.err.println("Group-"+suffix+".2 "+g); + System.err.println("Group-"+suffix+" Layout.2 "+g.getLayout()); + g.forAll( (shape) -> { System.err.println("Shape... "+shape); return false; }); + } + return g; + } + } diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/util/Tooltips.java b/src/demos/com/jogamp/opengl/demos/graph/ui/util/Tooltips.java new file mode 100644 index 000000000..aaf1bba20 --- /dev/null +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/util/Tooltips.java @@ -0,0 +1,109 @@ +/** + * Copyright 2023 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.demos.graph.ui.util; + +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.ui.Scene; +import com.jogamp.graph.ui.Shape; +import com.jogamp.graph.ui.shapes.Button; +import com.jogamp.graph.ui.shapes.Label; +import com.jogamp.newt.event.MouseEvent; +import com.jogamp.opengl.GLAutoDrawable; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.math.geom.AABBox; +import com.jogamp.opengl.util.texture.TextureSequence; + +public class Tooltips { + /** + * Shows the {@link Label#getText()} within a given proportion of {@link Scene#getBounds()} height within a rectangular {@link Button} tool-tip on click. + * <p> + * This {@link Shape.MouseGestureAdapter} must be {@link Shape#addMouseListener(com.jogamp.graph.ui.Shape.MouseGestureListener) added} + * to a {@link Label} to be functional. + * </p> + */ + public static class ZoomLabelOnClickListener extends Shape.MouseGestureAdapter { + private final Scene scene; + private final int renderModes; + private final float sceneHeightScale; + private Button buttonLabel = null; + + /** + * Ctor of {@link ZoomLabelOnClickListener}. + * @param scene the {@link Scene} to be attached to while pressed + * @param renderModes Graph's {@link Region} render modes, see {@link GLRegion#create(GLProfile, int, TextureSequence) create(..)}. + * @param sceneHeightScale proportion of {@link Scene#getBounds()} height to cover with this tool-tip + */ + public ZoomLabelOnClickListener(final Scene scene, final int renderModes, final float sceneHeightScale) { + this.scene = scene; + this.renderModes = renderModes; + this.sceneHeightScale = sceneHeightScale; + } + + @Override + public void mousePressed(final MouseEvent e) { + final AABBox sceneDim = scene.getBounds(); + final float zEps = scene.getZEpsilon(16); + + final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); + if( !( shapeEvent.shape instanceof Label ) ) { + return; + } + final Label label = (Label)shapeEvent.shape; + final AABBox textDim = label.getBounds(); + final float l_sxy = sceneHeightScale * sceneDim.getHeight() / textDim.getHeight(); // text width independent + buttonLabel = (Button) new Button(renderModes, label.getFont(), label.getText(), textDim.getWidth(), textDim.getHeight(), zEps) + .setPerp().scale(l_sxy, l_sxy, 1).move(0, 0, 10*zEps) + .setColor(0.97f, 0.97f, 0.97f, 0.92f).setBorder(0.05f).setBorderColor(0, 0, 0, 1) + .setInteractive(false); + buttonLabel.setLabelColor(0, 0, 0); + buttonLabel.setSpacing(Button.DEFAULT_SPACING_X, Button.DEFAULT_SPACING_X); + final Shape s = buttonLabel; + scene.invoke(false, (final GLAutoDrawable drawable) -> { + s.validate(drawable.getGL().getGL2ES2()); + s.move(-s.getScaledWidth()/2f, -s.getScaledHeight()/2f, 0); + // System.err.println("Add "+s); + scene.addShape(s); + return true; + }); + } + @Override + public void mouseReleased(final MouseEvent e) { + if( null != buttonLabel ) { + final Shape s = buttonLabel; + buttonLabel = null; + scene.invoke(false, (final GLAutoDrawable drawable) -> { + // System.err.println("Remove "+s); + scene.removeShape(drawable.getGL().getGL2ES2(), s); + return true; + }); + } + } + }; + +} diff --git a/src/graphui/classes/com/jogamp/graph/ui/Group.java b/src/graphui/classes/com/jogamp/graph/ui/Group.java index 6e181a0a1..b131e8863 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Group.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java @@ -55,6 +55,9 @@ import jogamp.graph.ui.TreeTool; public class Group extends Shape implements Container { /** Layout for the GraphUI {@link Group}, called @ {@link Shape#validate(GL2ES2)} or {@link Shape#validate(GLProfile)}. */ public static interface Layout { + /** Prepare given {@link Shape} before {@link Shape#validate(GL2ES2) validation}, e.g. {@link Shape#setPaddding(Padding)}. */ + void preValidate(final Shape s); + /** * Performing the layout of {@link Group#getShapes()}, called @ {@link Shape#validate(GL2ES2)} or {@link Shape#validate(GLProfile)}. * <p> @@ -241,6 +244,7 @@ public class Group extends Shape implements Container { final PMVMatrix pmv = new PMVMatrix(); if( null != layouter ) { for(final Shape s : shapes) { + layouter.preValidate(s); if( null != gl ) { s.validate(gl); } else { diff --git a/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java b/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java index acd58d0ab..57a83b4e7 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java +++ b/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java @@ -32,6 +32,8 @@ import java.util.List; import com.jogamp.graph.ui.Group; import com.jogamp.graph.ui.Shape; import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.Vec2f; +import com.jogamp.opengl.math.Vec3f; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.PMVMatrix; @@ -39,23 +41,70 @@ import com.jogamp.opengl.util.PMVMatrix; * GraphUI Stack {@link Group.Layout}. * <p> * A stack of {@link Shape}s - * - Size kept unscaled - * - Position depends on {@Link Padding} and {@link Margin} - * - Cell size can be set + * <ul> + * <li>Optionally centered {@link Alignment.Bit#CenterHoriz horizontally}, {@link Alignment.Bit#CenterVert vertically} or {@link Alignment#Center both}.</li> + * <li>Optionally scaled to cell-size if given and {@link Alignment#Fill}</li> + * <li>Padding is applied to each {@Shape} via {@link Shape#setPaddding(Padding)} if passed in constructor</li> + * <li>Margin is ignored on dimension with center {@link Alignment}</li> + * <li>Not implemented {@link Alignment}: {@link Alignment.Bit#Top Top}, {@link Alignment.Bit#Right Right}, {@link Alignment.Bit#Bottom Bottom}, {@link Alignment.Bit#Left Left}</li> + * </ul> * </p> */ public class BoxLayout implements Group.Layout { - private final float cellWidth, cellHeight; + private final Vec2f cellSize; + private final Alignment alignment; private final Margin margin; private final Padding padding; private static final boolean TRACE_LAYOUT = false; + + /** + */ + public BoxLayout() { + this(0f, 0f, new Alignment(), new Margin(), null); + } + + /** + * + * @param padding {@link Padding} applied to each {@Shape} via {@link Shape#setPaddding(Padding)} + */ public BoxLayout(final Padding padding) { - this(0f, 0f, new Margin(), padding); + this(0f, 0f, new Alignment(), new Margin(), padding); + } + + public BoxLayout(final float width, final float height) { + this(width, height, new Alignment(), new Margin(), null); + } + + /** + * + * @param width + * @param height + * @param alignment + */ + public BoxLayout(final float width, final float height, final Alignment alignment) { + this(width, height, alignment, new Margin(), null); } + + /** + * + * @param width + * @param height + * @param margin + */ public BoxLayout(final float width, final float height, final Margin margin) { - this(width, height, margin, new Padding()); + this(width, height, new Alignment(), margin, null); + } + + /** + * + * @param width + * @param height + * @param padding {@link Padding} applied to each {@Shape} via {@link Shape#setPaddding(Padding)} + */ + public BoxLayout(final float width, final float height, final Padding padding) { + this(width, height, new Alignment(), new Margin(), padding); } /** @@ -63,22 +112,62 @@ public class BoxLayout implements Group.Layout { * @param width * @param height * @param margin - * @param padding + * @param padding {@link Padding} applied to each {@Shape} via {@link Shape#setPaddding(Padding)} */ public BoxLayout(final float width, final float height, final Margin margin, final Padding padding) { - this.cellWidth = Math.max(0f, width); - this.cellHeight = Math.max(0f, height); + this(width, height, new Alignment(), margin, padding); + } + + /** + * + * @param width + * @param height + * @param margin + */ + public BoxLayout(final float width, final float height, final Alignment alignment, final Margin margin) { + this(width, height, alignment, margin, null); + } + + /** + * + * @param width + * @param height + * @param alignment + * @param margin + * @param padding {@link Padding} applied to each {@Shape} via {@link Shape#setPaddding(Padding)} + */ + public BoxLayout(final float width, final float height, final Alignment alignment, final Margin margin, final Padding padding) { + this.cellSize = new Vec2f(Math.max(0f, width), Math.max(0f, height)); + this.alignment = alignment; this.margin = margin; this.padding = padding; } - public Padding getPadding() { return padding; } + /** Returns the preset cell size */ + public Vec2f getCellSize() { return cellSize; } + /** Returns given {@link Alignment}. */ + public Alignment getAlignment() { return alignment; } + /** Returns given {@link Margin}. */ public Margin getMargin() { return margin; } + /** Returns given {@link Padding}, may be {@code null} if not given via constructor. */ + public Padding getPadding() { return padding; } + + @Override + public void preValidate(final Shape s) { + if( null != padding ) { + s.setPaddding(padding); + } + } @Override public void layout(final Group g, final AABBox box, final PMVMatrix pmv) { - final boolean hasCellWidth = !FloatUtil.isZero(cellWidth); - final boolean hasCellHeight = !FloatUtil.isZero(cellHeight); + final Vec3f zeroVec3 = new Vec3f(); + final boolean hasCellWidth = !FloatUtil.isZero(cellSize.x()); + final boolean hasCellHeight = !FloatUtil.isZero(cellSize.y()); + final boolean isCenteredHoriz = hasCellWidth && alignment.isSet(Alignment.Bit.CenterHoriz); + final boolean isCenteredVert = hasCellHeight && alignment.isSet(Alignment.Bit.CenterVert); + final boolean isScaled = alignment.isSet(Alignment.Bit.Fill) && ( hasCellWidth || hasCellHeight ); + final List<Shape> shapes = g.getShapes(); final AABBox sbox = new AABBox(); for(int i=0; i < shapes.size(); ++i) { @@ -90,48 +179,97 @@ public class BoxLayout implements Group.Layout { s.getBounds().transformMv(pmv, sbox); pmv.glPopMatrix(); - // adjust size and position (centered) - final float paddedWidth = sbox.getWidth() + padding.width(); - final float paddedHeight = sbox.getHeight() + padding.height(); - final float cellWidth2 = hasCellWidth ? cellWidth : paddedWidth; - final float cellHeight2 = hasCellHeight ? cellHeight : paddedHeight; - float x = margin.left; - float y = margin.bottom; - if( !margin.isCenteredHoriz() && paddedWidth <= cellWidth2 ) { - x += padding.left; - } - if( !margin.isCenteredVert() && paddedHeight <= cellHeight2 ) { - y += padding.bottom; + final int x = 0, y = 0; + if( TRACE_LAYOUT ) { + System.err.println("bl("+i+").0: sbox "+sbox+", s "+s); } - final float dxh, dyh; - if( margin.isCenteredHoriz() ) { - dxh = 0.5f * ( cellWidth2 - paddedWidth ); // actual horiz-centered + + // IF isScaled: Uniform scale w/ lowest axis scale and center position on lower-scale axis + final float shapeWidthU = sbox.getWidth() + margin.width(); + final float shapeWidthU_LH = ( sbox.getWidth() * 0.5f ) + margin.left; // left-half + final float shapeHeightU = sbox.getHeight() + margin.height(); + final float shapeHeightU_BH = ( sbox.getHeight() * 0.5f ) + margin.bottom; // bottom-half + final float sxy; + float dxh = 0, dyh = 0; + if( isScaled ) { + // scaling to cell size, implies center (horiz + vert) + final float cellWidth2 = hasCellWidth ? cellSize.x() : shapeWidthU; + final float cellHeight2 = hasCellHeight ? cellSize.y() : shapeHeightU; + final float sx = cellWidth2 / shapeWidthU; + final float sy = cellHeight2/ shapeHeightU; + sxy = sx < sy ? sx : sy; + dxh += sxy * margin.left + shapeWidthU_LH * ( sx - sxy ); // adjustment for scale-axis + dyh += sxy * margin.bottom + shapeHeightU_BH * ( sy - sxy ); // ditto + if( TRACE_LAYOUT ) { + System.err.println("bl("+i+").s: "+sx+" x "+sy+" -> "+sxy+": +"+dxh+" / "+dyh+", U: s "+shapeWidthU+" x "+shapeHeightU+", sz "+cellWidth2+" x "+cellHeight2); + } } else { - dxh = 0; + sxy = 1; } - if( margin.isCenteredVert() ) { - dyh = 0.5f * ( cellHeight2 - paddedHeight ); // actual vert-centered - } else { - dyh = 0; + final float shapeWidthS = sxy * shapeWidthU; + final float shapeHeightS = sxy * shapeHeightU; + final float cellWidthS = hasCellWidth ? cellSize.x() : shapeWidthS; + final float cellHeightS = hasCellHeight ? cellSize.y() : shapeHeightS; + + if( !isScaled ) { + // Use half delta of net-size to center, margin is ignored when centering + final float shapeWidthS_H = sxy * sbox.getWidth() * 0.5f; + final float shapeHeightS_H = sxy * sbox.getHeight() * 0.5f; + final float cellWidthS_H = hasCellWidth ? cellSize.x() * 0.5f : shapeWidthS_H; + final float cellHeightS_H = hasCellHeight ? cellSize.y() * 0.5f : shapeHeightS_H; + if( isCenteredHoriz ) { + dxh += cellWidthS_H - shapeWidthS_H; // horiz-center + } else { + dxh += sxy * margin.left; + } + if( isCenteredVert ) { + dyh += cellHeightS_H - shapeHeightS_H; // vert-center + } else { + dyh += sxy * margin.bottom; + } } if( TRACE_LAYOUT ) { - System.err.println("bl["+i+"].0: @ "+s.getPosition()+", sbox "+sbox); - System.err.println("bl["+i+"].m: "+x+" / "+y+" + "+dxh+" / "+dyh+", p "+paddedWidth+" x "+paddedHeight+", sz "+cellWidth2+" x "+cellHeight2+", box "+box.getWidth()+" x "+box.getHeight()); + System.err.println("bl("+i+").m: "+x+" / "+y+" + "+dxh+" / "+dyh+", sxy "+sxy+", S: s "+shapeWidthS+" x "+shapeHeightS+", sz "+cellWidthS+" x "+cellHeightS); } - s.move( x + dxh, y + dyh, 0f ); // center the scaled artifact - s.move( sbox.getLow().mul(-1f) ); // remove the bottom-left delta - // resize bounds including padding, excluding margin - box.resize( x + sbox.getWidth() + padding.right, y + sbox.getHeight() + padding.top, 0); - box.resize( x - padding.left, y - padding.bottom, 0); + // Position and scale shape + { + // New shape position, relative to previous position + final float aX = x + dxh; + final float aY = y + dyh; + s.moveTo( aX, aY, s.getPosition().z() ); + + // remove the bottom-left delta + final Vec3f diffBL = new Vec3f(); + final AABBox sbox0 = s.getBounds(); + if( !diffBL.set( sbox0.getLow().x(), sbox0.getLow().y(), 0).min( zeroVec3 ).isZero() ) { + // pmv.mulMvMatVec3f(diffBL).scale(-1f, -1f, 0f); + final Vec3f ss = s.getScale(); + diffBL.scale(-1f*ss.x(), -1f*ss.y(), 0f); + } + if( TRACE_LAYOUT ) { + System.err.println("bl("+i+").bl: sbox0 "+sbox0+", diffBL "+diffBL); + } + s.move( diffBL.scale(sxy) ); + + // resize bounds + box.resize( x, y, sbox.getMinZ()); + box.resize( x + cellWidthS, y + cellHeightS, sbox.getMaxZ()); + } + s.scale( sxy, sxy, 1f); + if( TRACE_LAYOUT ) { - System.err.println("bl["+i+"].x: "+x+" / "+y+" + "+dxh+" / "+dyh+" -> "+s.getPosition()+", p "+paddedWidth+" x "+paddedHeight+", sz "+cellWidth2+" x "+cellHeight2+", box "+box.getWidth()+" x "+box.getHeight()); + System.err.println("bl("+i+").x: "+dxh+" / "+dyh+" -> "+s.getPosition()+", p3 "+shapeWidthS+" x "+shapeHeightS+", sz3 "+cellWidthS+" x "+cellHeightS+", box "+box.getWidth()+" x "+box.getHeight()); + System.err.println("bl("+i+").x: "+s); + System.err.println("bl("+i+").x: "+box); } } } @Override public String toString() { - return "Box[cell["+cellWidth+" x "+cellHeight+"], "+margin+", "+padding+"]"; + final String p_s = ( null == padding || padding.zeroSumSize() ) ? "" : ", "+padding.toString(); + final String m_s = margin.zeroSumSize() ? "" : ", "+margin.toString(); + return "Box[cell "+cellSize+", a "+alignment+m_s+p_s+"]"; } } diff --git a/src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java b/src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java index d4a976012..8f83678c1 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java +++ b/src/graphui/classes/com/jogamp/graph/ui/layout/GridLayout.java @@ -32,6 +32,7 @@ import java.util.List; import com.jogamp.graph.ui.Group; import com.jogamp.graph.ui.Shape; import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.Vec2f; import com.jogamp.opengl.math.Vec3f; import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.PMVMatrix; @@ -40,10 +41,15 @@ import com.jogamp.opengl.util.PMVMatrix; * GraphUI Grid {@link Group.Layout}. * <p> * A grid of {@link Shape}s - * - Optional cell-size with {@link Alignment#Fill} and or {@link Alignment#Center} - * - Without cell-size behaves like a grid bag using individual shape sizes including padding - * - Can be filled in {@link Order#COLUMN} or {@link Order#ROW} major-order. - * - .. + * <ul> + * <li>Optionally centered {@link Alignment.Bit#CenterHoriz horizontally}, {@link Alignment.Bit#CenterVert vertically} or {@link Alignment#Center both}.</li> + * <li>Optionally scaled to cell-size if given and {@link Alignment#Fill}</li> + * <li>Padding is applied to each {@Shape} via {@link Shape#setPaddding(Padding)} if passed in constructor</li> + * <li>Without cell-size behaves like a grid bag using individual shape sizes including padding</li> + * <li>Can be filled in {@link Order#COLUMN} or {@link Order#ROW} major-order.</li> + * <li>Not implemented {@link Alignment}: {@link Alignment.Bit#Top Top}, {@link Alignment.Bit#Right Right}, {@link Alignment.Bit#Bottom Bottom}, {@link Alignment.Bit#Left Left}</li> + * <li>..</li> + * </ul> * </p> */ public class GridLayout implements Group.Layout { @@ -57,9 +63,10 @@ public class GridLayout implements Group.Layout { private final Order order; private final int col_limit; private final int row_limit; - private final float cellWidth, cellHeight; + private final Vec2f cellSize; private final Alignment alignment; private final Gap gap; + private final Padding padding; private int row_count, col_count; private static final boolean TRACE_LAYOUT = false; @@ -72,7 +79,7 @@ public class GridLayout implements Group.Layout { * @param alignment TODO */ public GridLayout(final int column_limit, final float cellWidth, final float cellHeight, final Alignment alignment) { - this(alignment, Math.max(1, column_limit), -1, cellWidth, cellHeight, new Gap()); + this(alignment, Math.max(1, column_limit), -1, cellWidth, cellHeight, new Gap(), null); } /** @@ -84,7 +91,20 @@ public class GridLayout implements Group.Layout { * @param gap */ public GridLayout(final int column_limit, final float cellWidth, final float cellHeight, final Alignment alignment, final Gap gap) { - this(alignment, Math.max(1, column_limit), -1, cellWidth, cellHeight, gap); + this(alignment, Math.max(1, column_limit), -1, cellWidth, cellHeight, gap, null); + } + + /** + * Default layout order of {@link Group#getShapes()}} is {@link Order#COLUMN}. + * @param column_limit [1..inf) + * @param cellWidth + * @param cellHeight + * @param alignment TODO + * @param gap + * @param padding {@link Padding} applied to each {@Shape} via {@link Shape#setPaddding(Padding)} + */ + public GridLayout(final int column_limit, final float cellWidth, final float cellHeight, final Alignment alignment, final Gap gap, final Padding padding) { + this(alignment, Math.max(1, column_limit), -1, cellWidth, cellHeight, gap, padding); } /** @@ -96,33 +116,64 @@ public class GridLayout implements Group.Layout { * @param row_limit [1..inf) */ public GridLayout(final float cellWidth, final float cellHeight, final Alignment alignment, final Gap gap, final int row_limit) { - this(alignment, -1, Math.max(1, row_limit), cellWidth, cellHeight, gap); + this(alignment, -1, Math.max(1, row_limit), cellWidth, cellHeight, gap, null); } - private GridLayout(final Alignment alignment, final int column_limit, final int row_limit, final float cellWidth, final float cellHeight, final Gap gap) { + /** + * Default layout order of {@link Group#getShapes()}} is {@link Order#ROW}. + * @param cellWidth + * @param cellHeight + * @param alignment TODO + * @param gap + * @param padding {@link Padding} applied to each {@Shape} via {@link Shape#setPaddding(Padding)} + * @param row_limit [1..inf) + */ + public GridLayout(final float cellWidth, final float cellHeight, final Alignment alignment, final Gap gap, final Padding padding, final int row_limit) { + this(alignment, -1, Math.max(1, row_limit), cellWidth, cellHeight, gap, padding); + } + + private GridLayout(final Alignment alignment, final int column_limit, final int row_limit, final float cellWidth, final float cellHeight, + final Gap gap, final Padding padding) { this.order = 0 < column_limit ? Order.COLUMN : Order.ROW; this.col_limit = column_limit; this.row_limit = row_limit; - this.cellWidth = cellWidth; - this.cellHeight = cellHeight; + this.cellSize = new Vec2f(Math.max(0f, cellWidth), Math.max(0f, cellHeight)); this.alignment = alignment; this.gap = gap; + this.padding = padding; row_count = 0; col_count = 0; } + /** Returns given {@link Order}. */ public Order getOrder() { return order; } + /** Returns column count after {@link #layout(Group, AABBox, PMVMatrix)}. */ public int getColumnCount() { return col_count; } + /** Returns row count after {@link #layout(Group, AABBox, PMVMatrix)}. */ public int getRowCount() { return row_count; } + /** Returns the preset cell size */ + public Vec2f getCellSize() { return cellSize; } + /** Returns given {@link Alignment}. */ + public Alignment getAlignment() { return alignment; } + /** Returns given {@link Gap}. */ public Gap getGap() { return gap; } + /** Returns given {@link Padding}, may be {@code null} if not given via constructor. */ + public Padding getPadding() { return padding; } + + @Override + public void preValidate(final Shape s) { + if( null != padding ) { + s.setPaddding(padding); + } + } @Override public void layout(final Group g, final AABBox box, final PMVMatrix pmv) { final Vec3f zeroVec3 = new Vec3f(); - final boolean hasCellWidth = !FloatUtil.isZero(cellWidth); - final boolean hasCellHeight = !FloatUtil.isZero(cellHeight); - final boolean isCenteredHoriz = hasCellWidth && alignment.isSet(Alignment.Bit.Center); - final boolean isCenteredVert = hasCellHeight && alignment.isSet(Alignment.Bit.Center); + final boolean hasCellWidth = !FloatUtil.isZero(cellSize.x()); + final boolean hasCellHeight = !FloatUtil.isZero(cellSize.y()); + final boolean isCenteredHoriz = hasCellWidth && alignment.isSet(Alignment.Bit.CenterHoriz); + final boolean isCenteredVert = hasCellHeight && alignment.isSet(Alignment.Bit.CenterVert); final boolean isScaled = alignment.isSet(Alignment.Bit.Fill) && ( hasCellWidth || hasCellHeight ); final List<Shape> shapes = g.getShapes(); if( Order.COLUMN == order ) { @@ -159,8 +210,8 @@ public class GridLayout implements Group.Layout { // scaling to cell size final float shapeWidthU = sbox.getWidth(); final float shapeHeightU = sbox.getHeight(); - final float cellWidthU = hasCellWidth ? cellWidth : shapeWidthU; - final float cellHeightU = hasCellHeight ? cellHeight : shapeHeightU; + final float cellWidthU = hasCellWidth ? cellSize.x() : shapeWidthU; + final float cellHeightU = hasCellHeight ? cellSize.y() : shapeHeightU; final float sx = cellWidthU / shapeWidthU; final float sy = cellHeightU/ shapeHeightU; sxy = sx < sy ? sx : sy; @@ -169,8 +220,8 @@ public class GridLayout implements Group.Layout { } final float shapeWidthS = sxy*sbox.getWidth(); final float shapeHeightS = sxy*sbox.getHeight(); - final float cellWidthS = hasCellWidth ? cellWidth : shapeWidthS; - final float cellHeightS = hasCellHeight ? cellHeight : shapeHeightS; + final float cellWidthS = hasCellWidth ? cellSize.x() : shapeWidthS; + final float cellHeightS = hasCellHeight ? cellSize.y() : shapeHeightS; // bottom y_pos, top to bottom, to be subtracted from totalHeight final float y0 = y + cellHeightS; @@ -217,21 +268,9 @@ public class GridLayout implements Group.Layout { for(int i=0; i < shapes.size(); ++i) { final Shape s = shapes.get(i); final AABBox sbox = sboxes[i]; - final float zPos = sbox.getCenter().z(); - final Vec3f diffBL = new Vec3f(); - - { - final AABBox sbox0 = s.getBounds(); - if( !diffBL.set( sbox0.getLow().x(), sbox0.getLow().y(), 0).min( zeroVec3 ).isZero() ) { - // pmv.mulMvMatVec3f(diffBL).scale(-1f, -1f, 0f); - final Vec3f ss = s.getScale(); - diffBL.scale(-1f*ss.x(), -1f*ss.y(), 0f); - } - } if( TRACE_LAYOUT ) { - System.err.println("gl("+i+")["+col_i+"]["+row_i+"].0: "+s); - System.err.println("gl("+i+")["+col_i+"]["+row_i+"].0: sbox "+sbox+", diffBL "+diffBL); + System.err.println("gl("+i+")["+col_i+"]["+row_i+"].0: sbox "+sbox+", s "+s); } // IF isScaled: Uniform scale w/ lowest axis scale and center position on lower-scale axis @@ -241,8 +280,8 @@ public class GridLayout implements Group.Layout { // scaling to cell size final float shapeWidthU = sbox.getWidth(); final float shapeHeightU = sbox.getHeight(); - final float cellWidth2 = hasCellWidth ? cellWidth : shapeWidthU; - final float cellHeight2 = hasCellHeight ? cellHeight : shapeHeightU; + final float cellWidth2 = hasCellWidth ? cellSize.x() : shapeWidthU; + final float cellHeight2 = hasCellHeight ? cellSize.y() : shapeHeightU; final float sx = cellWidth2 / shapeWidthU; final float sy = cellHeight2/ shapeHeightU; sxy = sx < sy ? sx : sy; @@ -256,36 +295,52 @@ public class GridLayout implements Group.Layout { } final float shapeWidthS = sxy*sbox.getWidth(); final float shapeHeightS = sxy*sbox.getHeight(); - final float cellWidthS = hasCellWidth ? cellWidth : shapeWidthS; - final float cellHeightS = hasCellHeight ? cellHeight : shapeHeightS; + final float cellWidthS = hasCellWidth ? cellSize.x() : shapeWidthS; + final float cellHeightS = hasCellHeight ? cellSize.y() : shapeHeightS; y = totalHeight - y_pos[col_count * row_i + col_i]; if( isCenteredHoriz ) { - dxh += 0.5f * ( cellWidthS - shapeWidthS ); // actual horiz-centered + dxh += 0.5f * ( cellWidthS - shapeWidthS ); // horiz-center } if( isCenteredVert ) { - dyh += 0.5f * ( cellHeightS - shapeHeightS ); // actual vert-centered + dyh += 0.5f * ( cellHeightS - shapeHeightS ); // vert-center } if( TRACE_LAYOUT ) { System.err.println("gl("+i+")["+col_i+"]["+row_i+"].m: "+x+" / "+y+" + "+dxh+" / "+dyh+", S: s "+shapeWidthS+" x "+shapeHeightS+", sz "+cellWidthS+" x "+cellHeightS); } + // Position and scale shape { // New shape position, relative to previous position final float aX = x + dxh; final float aY = y + dyh; - s.moveTo( aX, aY, 0f ); - s.move( diffBL.scale(sxy) ); // remove the bottom-left delta + s.moveTo( aX, aY, s.getPosition().z() ); + + // Remove the bottom-left delta + final Vec3f diffBL = new Vec3f(); + { + final AABBox sbox0 = s.getBounds(); + if( !diffBL.set( sbox0.getLow().x(), sbox0.getLow().y(), 0).min( zeroVec3 ).isZero() ) { + // pmv.mulMvMatVec3f(diffBL_).scale(-1f, -1f, 0f); + final Vec3f ss = s.getScale(); + diffBL.scale(-1f*ss.x(), -1f*ss.y(), 0f); + } + if( TRACE_LAYOUT ) { + System.err.println("gl("+i+")["+col_i+"]["+row_i+"].bl: sbox0 "+sbox0+", diffBL_ "+diffBL); + } + } + s.move( diffBL.scale(sxy) ); - // resize bounds including padding, excluding margin - box.resize( x, y, zPos); - box.resize( aX + cellWidthS, aY + cellHeightS, zPos); + // resize bounds + box.resize( x, y, sbox.getMinZ()); + box.resize( x + cellWidthS, y + cellHeightS, sbox.getMaxZ()); } s.scale( sxy, sxy, 1f); if( TRACE_LAYOUT ) { System.err.println("gl("+i+")["+col_i+"]["+row_i+"].x: "+x+" / "+y+" + "+dxh+" / "+dyh+" -> "+s.getPosition()+", p3 "+shapeWidthS+" x "+shapeHeightS+", sz3 "+cellWidthS+" x "+cellHeightS+", box "+box.getWidth()+" x "+box.getHeight()); System.err.println("gl("+i+")["+col_i+"]["+row_i+"].x: "+s); + System.err.println("gl("+i+")["+col_i+"]["+row_i+"].x: "+box); } if( i + 1 < shapes.size() ) { @@ -318,7 +373,9 @@ public class GridLayout implements Group.Layout { @Override public String toString() { - return "Grid["+col_count+"x"+row_count+", "+order+", cell["+cellWidth+" x "+cellHeight+", a "+alignment+"], "+gap+"]"; + final String p_s = ( null == padding || padding.zeroSumSize() ) ? "" : ", "+padding.toString(); + final String g_s = gap.zeroSumSize() ? "" : ", "+gap.toString(); + return "Grid["+col_count+"x"+row_count+", "+order+", cell "+cellSize+", a "+alignment+g_s+p_s+"]"; } } diff --git a/src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java b/src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java index 240053cb5..6e4bef169 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java +++ b/src/graphui/classes/com/jogamp/graph/ui/layout/Margin.java @@ -31,16 +31,14 @@ import com.jogamp.opengl.math.FloatUtil; /** * GraphUI CSS property Margin, space between or around elements and not included in the element's size. - * + * <p> * The CSS margin properties are used to create space around elements, outside of any defined borders. - * - * {@link Margin#CENTER} is mapped to `zero` while earmarking {@link #isCenteredHoriz()} and {@link #isCenteredVert()}. - * The container must be sized via its layout horizontally and/or vertically matching the centered axis, similar to CSS. + * </p> + * <p> + * Center alignment is defined via {@link Alignment} and {@link Margin} ignored on centered dimension. + * </p> */ public class Margin { - /** Auto margin value to horizontally and/or vertically center an element within its sized-layout container, value if {@link Float#NaN}. */ - public static final float CENTER = Float.NaN; - /** Top value */ public final float top; /** Right value */ @@ -50,20 +48,6 @@ public class Margin { /** Left value */ public final float left; - private final int bits; - static private final int CENTER_HORIZ = 1 << 0; - static private final int CENTER_VERT = 1 << 1; - static private int getBits(final float top, final float right, final float bottom, final float left) { - int b = 0; - if( FloatUtil.isEqual(CENTER, left) && FloatUtil.isEqual(CENTER, right) ) { - b |= CENTER_HORIZ; - } - if( FloatUtil.isEqual(CENTER, top) && FloatUtil.isEqual(CENTER, bottom) ) { - b |= CENTER_VERT; - } - return b; - } - /** * Ctor w/ zero values */ @@ -79,105 +63,46 @@ public class Margin { * @param left left value */ public Margin(final float top, final float right, final float bottom, final float left) { - this.bits = getBits(top, right, bottom, left); - if( isCenteredVert() ) { - this.top = 0; - this.bottom = 0; - } else { - this.top = top; - this.bottom = bottom; - } - if( isCenteredHoriz() ) { - this.right = 0; - this.left = 0; - } else { - this.right = right; - this.left = left; - } + this.top = top; + this.bottom = bottom; + this.right = right; + this.left = left; } /** * Ctor * @param top top value - * @param rl right and left value, use {@link #CENTER} to horizontally center the element in its container + * @param rl right and left value * @param bottom bottom value */ public Margin(final float top, final float rl, final float bottom) { - this.bits = getBits(top, rl, bottom, rl); - if( isCenteredVert() ) { - this.top = 0; - this.bottom = 0; - } else { - this.top = top; - this.bottom = bottom; - } - if( isCenteredHoriz() ) { - this.right = 0; - this.left = 0; - } else { - this.right = rl; - this.left = rl; - } + this.top = top; + this.bottom = bottom; + this.right = rl; + this.left = rl; } /** * Ctor - * @param tb top and bottom value, use {@link #CENTER} to vertically center the element in its container - * @param rl right and left value, use {@link #CENTER} to horizontally center the element in its container + * @param tb top and bottom value + * @param rl right and left value */ public Margin(final float tb, final float rl) { - this.bits = getBits(tb, rl, tb, rl); - if( isCenteredVert() ) { - this.top = 0; - this.bottom = 0; - } else { - this.top = tb; - this.bottom = tb; - } - if( isCenteredHoriz() ) { - this.right = 0; - this.left = 0; - } else { - this.right = rl; - this.left = rl; - } + this.top = tb; + this.bottom = tb; + this.right = rl; + this.left = rl; } /** * Ctor - * @param trbl top, right, bottom and left value, use {@link #CENTER} to horizontally and vertically center the element in its container. + * @param trbl top, right, bottom and left value */ public Margin(final float trbl) { - this.bits = getBits(trbl, trbl, trbl, trbl); - if( isCenteredVert() ) { - this.top = 0; - this.bottom = 0; - } else { - this.top = trbl; - this.bottom = trbl; - } - if( isCenteredHoriz() ) { - this.right = 0; - this.left = 0; - } else { - this.right = trbl; - this.left = trbl; - } - } - - /** Returns true if {@link #left} and {@link #right} is {@link #CENTER}. */ - public boolean isCenteredHoriz() { - return 0 != ( CENTER_HORIZ & bits ); - } - - /** Returns true if {@link #top} and {@link #bottom} is {@link #CENTER}. */ - public boolean isCenteredVert() { - return 0 != ( CENTER_VERT & bits ); - } - - /** Returns true if {@link #isCenteredHoriz()} and {@link #isCenteredVert()} is true, i.e. for horizontal and vertical center. */ - public boolean isCentered() { - return 0 != ( ( CENTER_VERT | CENTER_HORIZ ) & bits ); + this.top = trbl; + this.bottom = trbl; + this.right = trbl; + this.left = trbl; } /** Return width of horizontal values top + right. Zero if {@link #isCenteredHoriz()}. */ @@ -193,5 +118,5 @@ public class Margin { public boolean zeroSumSize() { return zeroSumWidth() && zeroSumHeight(); } @Override - public String toString() { return "Margin[t "+top+", r "+right+", b "+bottom+", l "+left+", ctr[h "+isCenteredHoriz()+", v "+isCenteredVert()+"]]"; } + public String toString() { return "Margin[t "+top+", r "+right+", b "+bottom+", l "+left+"]"; } } |