diff options
6 files changed, 196 insertions, 128 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java index c377bb71c..1102f2d7d 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java @@ -11,8 +11,8 @@ import javax.media.opengl.GLPipelineFactory; import javax.media.opengl.GLRunnable; import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.geom.SVertex; @@ -52,7 +52,8 @@ public class GPUUISceneGLListener0A implements GLEventListener { private float xTran = 0f; private float yTran = 0; private float zTran = 0f; - private float rotY = 0f; + private float rotButtonsY = 0f; + private float rotTextY = 0f; private final float zoomText = 1f; private int currentText = 0; @@ -68,7 +69,6 @@ public class GPUUISceneGLListener0A implements GLEventListener { private GLAutoDrawable cDrawable; private final String jogamp = "JogAmp - Jogl Graph Module Demo"; - private final float angText = 0; public GPUUISceneGLListener0A() { this(0); @@ -96,24 +96,28 @@ public class GPUUISceneGLListener0A implements GLEventListener { nearPlane1Box = new AABBox(); } - private void initButtons(int width, int height) { + final float buttonXSize = 84f; + final float buttonYSize = buttonXSize/2.5f; + + private void initButtons() { buttons = new RIButton[numSelectable]; - float xaxis = 20f; - float xSize = 50f; - float ySize = xSize/2.5f; - float ystart = 25; - float diff = ySize + 5; + final float xstart = 0f; + final float ystart = 0f; + final float diff = 1.5f * buttonYSize; - buttons[0] = new RIButton(SVertex.factory(), font, "Next Text", xSize, ySize){ - public void onClick() { + buttons[0] = new RIButton(SVertex.factory(), font, "Next Text", buttonXSize, buttonYSize){ + @Override + public void onClick(MouseEvent e) { currentText = (currentText+1)%3; } }; - buttons[0].translate(xaxis,ystart); + buttons[0].translate(xstart,ystart); + buttons[0].setLabelColor(1.0f, 1.0f, 1.0f); - buttons[1] = new RIButton(SVertex.factory(), font, "Show FPS", xSize, ySize){ - public void onClick() { + buttons[1] = new RIButton(SVertex.factory(), font, "Show FPS", buttonXSize, buttonYSize){ + @Override + public void onClick(MouseEvent e) { final GLAnimatorControl a = cDrawable.getAnimator(); if( null != a ) { a.resetFPSCounter(); @@ -121,12 +125,15 @@ public class GPUUISceneGLListener0A implements GLEventListener { showFPS = !showFPS; } }; - buttons[1].translate(xaxis,ystart - diff); + buttons[1].translate(xstart,ystart - diff); buttons[1].setToggleable(true); + buttons[1].setLabelColor(1.0f, 1.0f, 1.0f); - buttons[2] = new RIButton(SVertex.factory(), font, "v-sync", xSize, ySize){ - public void onClick() { + buttons[2] = new RIButton(SVertex.factory(), font, "v-sync", buttonXSize, buttonYSize){ + @Override + public void onClick(MouseEvent e) { cDrawable.invoke(false, new GLRunnable() { + @Override public boolean run(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.setSwapInterval(gl.getSwapInterval()<=0?1:0); @@ -139,32 +146,43 @@ public class GPUUISceneGLListener0A implements GLEventListener { }); } }; - buttons[2].translate(xaxis,ystart-diff*2); + buttons[2].translate(xstart,ystart-diff*2); buttons[2].setToggleable(true); buttons[2].setLabelColor(1.0f, 1.0f, 1.0f); - buttons[3] = new RIButton(SVertex.factory(), font, "Tilt +Y", xSize, ySize) { - public void onClick() { - rotY+=10; + buttons[3] = new RIButton(SVertex.factory(), font, "Tilt +Y", buttonXSize, buttonYSize) { + @Override + public void onClick(MouseEvent e) { + if( e.isShiftDown() ) { + rotButtonsY+=5; + } else { + rotTextY+=5f; + } } }; - buttons[3].translate(xaxis,ystart-diff*3); + buttons[3].translate(xstart,ystart-diff*3); buttons[3].setLabelColor(1.0f, 1.0f, 1.0f); - buttons[4] = new RIButton(SVertex.factory(), font, "Tilt -Y", xSize, ySize){ - public void onClick() { - rotY-=10; + buttons[4] = new RIButton(SVertex.factory(), font, "Tilt -Y", buttonXSize, buttonYSize){ + @Override + public void onClick(MouseEvent e) { + if( e.isShiftDown() ) { + rotButtonsY-=5f; + } else { + rotTextY-=5f; + } } }; - buttons[4].translate(xaxis,ystart-diff*4); + buttons[4].translate(xstart,ystart-diff*4); buttons[4].setLabelColor(1.0f, 1.0f, 1.0f); - buttons[5] = new RIButton(SVertex.factory(), font, "Quit", xSize, ySize){ - public void onClick() { + buttons[5] = new RIButton(SVertex.factory(), font, "Quit", buttonXSize, buttonYSize){ + @Override + public void onClick(MouseEvent e) { cDrawable.destroy(); } }; - buttons[5].translate(xaxis,ystart-diff*5); + buttons[5].translate(xstart,ystart-diff*5); buttons[5].setColor(0.8f, 0.0f, 0.0f); buttons[5].setLabelColor(1.0f, 1.0f, 1.0f); @@ -196,6 +214,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { labels = new Label[3]; } + @Override public void init(GLAutoDrawable drawable) { final Object upObj = drawable.getUpstreamWidget(); if( upObj instanceof Window ) { @@ -210,8 +229,6 @@ public class GPUUISceneGLListener0A implements GLEventListener { } else { System.err.println("GPUUISceneGLListener0A: init (0)"); } - final int width = drawable.getWidth(); - final int height = drawable.getHeight(); cDrawable = drawable; GL2ES2 gl = drawable.getGL().getGL2ES2(); if(debug) { @@ -238,7 +255,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); initTexts(); - initButtons(width, height); + initButtons(); sceneUIController.setRenderer(renderer, renderModes, sampleCount); sceneUIController.addShape(buttons[0]); @@ -257,6 +274,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { } } + @Override public void dispose(GLAutoDrawable drawable) { if(drawable instanceof GLWindow) { System.err.println("GPUUISceneGLListener0A: dispose (1)"); @@ -272,6 +290,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { renderer.destroy(gl); } + @Override public void display(GLAutoDrawable drawable) { // System.err.println("GPUUISceneGLListener0A: display"); final GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -283,32 +302,39 @@ public class GPUUISceneGLListener0A implements GLEventListener { final float pixelSizeFixed = font.getPixelSize(fontSizeFixed, dpiH); + float dx = width * 1f/6f; + float dy = height - height/6f; + renderer.resetModelview(null); - sceneUIController.setTranslate(nearPlaneX0+xTran, nearPlaneY0+yTran, nearPlaneZ0+zTran); + // Keep Buttons static .. + // sceneUIController.setTranslate(nearPlaneX0+xTran+(dx*nearPlaneSx), nearPlaneY0+yTran+((dy-buttonYSize)*nearPlaneSy), nearPlaneZ0+zTran); + sceneUIController.setTranslate(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+((dy-buttonYSize)*nearPlaneSy), nearPlaneZ0); sceneUIController.setScale(nearPlaneSx, nearPlaneSy, 1f); - sceneUIController.setRotation(0, rotY, 0); + sceneUIController.setRotation(0, rotButtonsY, 0); sceneUIController.display(drawable); - float dx = width * 1f/3f; - float dy = height - 10f - jogampLabel.getLineHeight(); + dx = width * 1f/3f; renderer.resetModelview(null); renderer.translate(null, nearPlaneX0+xTran+(dx*nearPlaneSx), nearPlaneY0+yTran+(dy*nearPlaneSy), nearPlaneZ0+zTran); + renderer.rotate(null, rotTextY , 0, 1, 0); renderer.scale(null, nearPlaneSx*zoomText, nearPlaneSy*zoomText, 1f); - renderer.rotate(gl, angText , 0, 1, 0); + renderer.updateMatrix(gl); renderer.setColorStatic(gl, 0.0f, 1.0f, 0.0f); jogampLabel.drawShape(gl, renderer, sampleCount, false); + dy -= 3f * jogampLabel.getLineHeight(); if(null == labels[currentText]) { labels[currentText] = new Label(SVertex.factory(), font, pixelSizeFixed, strings[currentText]); labels[currentText].setColor(0, 0, 0); } labels[currentText].validate(gl, renderer); - dy -= labels[currentText].getBounds().getHeight(); + renderer.resetModelview(null); renderer.translate(null, nearPlaneX0+xTran+(dx*nearPlaneSx), nearPlaneY0+yTran+(dy*nearPlaneSy), nearPlaneZ0+zTran); + renderer.rotate(null, rotTextY, 0, 1, 0); renderer.scale(null, nearPlaneSx*zoomText, nearPlaneSy*zoomText, 1f); - renderer.rotate(gl, angText, 0, 1, 0); + renderer.updateMatrix(gl); renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); labels[currentText].drawShape(gl, renderer, sampleCount, false); @@ -337,7 +363,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { fpsLabel = new Label(renderer.getRenderState().getVertexFactory(), font, pixelSizeFPS, text); } renderer.resetModelview(null); - renderer.translate(null, nearPlaneX0, nearPlaneY0+(nearPlaneS * pixelSizeFPS / 2f), nearPlaneZ0); + renderer.translate(null, nearPlaneX0, nearPlaneY0+(nearPlaneSy * pixelSizeFPS / 2f), nearPlaneZ0); renderer.scale(null, nearPlaneSx, nearPlaneSy, 1f); renderer.updateMatrix(gl); fpsLabel.drawShape(gl, renderer, sampleCount, false); @@ -352,6 +378,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { pmv.gluUnProject(orthoX, orthoY, winZ[0], view, 0, objPos, 0); } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { System.err.println("GPUUISceneGLListener0A: reshape"); GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -393,10 +420,9 @@ public class GPUUISceneGLListener0A implements GLEventListener { final float yd = nearPlane1Box.getHeight() * dist; nearPlaneSx = xd / width; nearPlaneSy = yd / height; - nearPlaneS = nearPlaneSy; - System.err.printf("Scale: [%f x %f] / [%d x %d] = [%f, %f] -> %f%n", xd, yd, width, height, nearPlaneSx, nearPlaneSy, nearPlaneS); + System.err.printf("Scale: [%f x %f] / [%d x %d] = [%f, %f]%n", xd, yd, width, height, nearPlaneSx, nearPlaneSy); } - float nearPlaneX0, nearPlaneY0, nearPlaneZ0, nearPlaneSx, nearPlaneSy, nearPlaneS; + float nearPlaneX0, nearPlaneY0, nearPlaneZ0, nearPlaneSx, nearPlaneSy; public void attachInputListenerTo(GLWindow window) { if ( null == multiTouchListener ) { diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java index 99ac2bd51..16ee148e8 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java @@ -38,7 +38,6 @@ import com.jogamp.graph.curve.opengl.TextRegionUtil; import com.jogamp.graph.font.Font; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Vertex.Factory; -import com.jogamp.opengl.math.geom.AABBox; public class Label extends UIShape { protected Font font; @@ -91,16 +90,13 @@ public class Label extends UIShape { protected void destroyImpl(GL2ES2 gl, RegionRenderer renderer) { } + private final float[] tmpV3 = new float[3]; + private final TextRegionUtil.ShapeVisitor shapeVisitor = new TextRegionUtil.ShapeVisitor() { - final float[] tmp = new float[3]; @Override public void visit(OutlineShape shape, AffineTransform t) { shapes.add(new OutlineShapeXForm(shape, new AffineTransform(t))); - final AABBox sbox = shape.getBounds(); - t.transform(sbox.getLow(), tmp); - box.resize(tmp, 0); - t.transform(sbox.getHigh(), tmp); - box.resize(tmp, 0); + box.resize(shape.getBounds(), t, tmpV3); } }; diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java index c1f984519..7e4d5ec62 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java @@ -97,33 +97,30 @@ public abstract class RIButton extends UIShape { @Override protected void createShape(GL2ES2 gl, RegionRenderer renderer) { - // label.createShape(gl, renderer); - // final AABBox lbox = label.getBounds(); - - final float lw = getWidth() * ( 1f - spacingSx*spacing ); + // Precompute text-box size .. guessing pixelSize + final float lw = getWidth() * ( 1f - spacingSx*spacing ); final float lh = getHeight() * ( 1f - spacingSy*spacing ); final AABBox lbox0 = label.font.getStringBounds(label.text, lh); final float lsx = lw / lbox0.getWidth(); final float lsy = lh / lbox0.getHeight(); - final float ls = Math.min(lsx, lsy); - - final float sx = getWidth() / ( ( spacingSx*spacing + 1f ) * lbox0.getWidth() * ls ); - final float sy = getHeight() / ( ( spacingSy*spacing + 1f ) * lbox0.getHeight() * ls ); - System.err.printf("RIButton: bsize %f x %f, lsize %f x %f, lbox0 %f x %f -> ls %f x %f, bs %f x %f .... %s%n", - getWidth(), getHeight(), lw, lh, lbox0.getWidth(), lbox0.getHeight(), lsx, lsy, sx, sy, this.label.text); + if( DRAW_DEBUG_BOX ) { + final float sx = getWidth() / ( ( spacingSx*spacing + 1f ) * lbox0.getWidth() * lsx ); + final float sy = getHeight() / ( ( spacingSy*spacing + 1f ) * lbox0.getHeight() * lsy ); + System.err.printf("RIButton: bsize %f x %f, lsize %f x %f, lbox0 %f x %f -> ls %f x %f, bs %f x %f .... %s%n", + getWidth(), getHeight(), lw, lh, lbox0.getWidth(), lbox0.getHeight(), lsx, lsy, sx, sy, this.label.text); + } - final float lPixelSize1 = lh * ls; + // Setting pixelSize based on actual text-box size + final float lPixelSize1 = lh * lsy; label.setPixelSize(lPixelSize1); label.createShape(gl, renderer); final AABBox lbox1 = label.getBounds(); - final float lsx1 = lw / lbox1.getWidth(); - final float lsy1 = lh / lbox1.getHeight(); - // final float ls1 = Math.min(lsx1, lsy1); - System.err.printf("RIButton: ls %f x %f, lbox1 %s .... %s%n", - lsx1, lsy1, lbox1, this.label.text); - // label.scale(ls1, ls1); - // scale(sx, sy); - // box.resize(lbox1); + if( DRAW_DEBUG_BOX ) { + final float lsx1 = lw / lbox1.getWidth(); + final float lsy1 = lh / lbox1.getHeight(); + System.err.printf("RIButton: ls %f x %f, lbox1 %s .... %s%n", + lsx1, lsy1, lbox1, this.label.text); + } final OutlineShape shape = new OutlineShape(renderer.getRenderState().getVertexFactory()); if(corner == 0.0f) { @@ -133,11 +130,15 @@ public abstract class RIButton extends UIShape { } box.resize(shape.getBounds()); - label.locTranslate( ( box.getWidth() - lbox1.getWidth() ) / 1f, - -1f * ( box.getHeight() - lbox1.getHeight() ) / 1f ); + // Center text .. + final float[] lctr = lbox1.getCenter(); + final float[] ctr = box.getCenter(); + label.translateShape( ctr[0] - lctr[0], ctr[1] - lctr[1] ); shapes.add(new OutlineShapeXForm(shape, null)); - System.err.println("XXX.UIShape.RIButton: Added Shape: "+shape+", "+box); + if( DRAW_DEBUG_BOX ) { + System.err.println("XXX.UIShape.RIButton: Added Shape: "+shape+", "+box); + } } private void createSharpOutline(OutlineShape shape, AABBox lbox) { final float tw = getWidth(); // ( spacingSx*spacing + 1f ) * lbox.getWidth(); @@ -229,6 +230,7 @@ public abstract class RIButton extends UIShape { label.setSelectedColor(r, g, b); } + @Override public String toString() { return "RIButton [" + getWidth() + "x" + getHeight() + ", " + getLabel() + ", " + "spacing: " + spacing diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java index 7691126a6..c1149227f 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java @@ -17,6 +17,8 @@ import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.MouseListener; import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.Quaternion; import com.jogamp.opengl.util.PMVMatrix; public class SceneUIController implements GLEventListener{ @@ -29,7 +31,7 @@ public class SceneUIController implements GLEventListener{ private final float[] translate = new float[3]; private final float[] scale = new float[3]; - private final float[] rotation = new float[3]; + private final Quaternion quaternion = new Quaternion(); private final float[] sceneClearColor = new float[]{0,0,0,0}; @@ -86,10 +88,12 @@ public class SceneUIController implements GLEventListener{ } } + @Override public void init(GLAutoDrawable drawable) { System.err.println("SceneUIController: init"); cDrawable = drawable; } + @Override public void display(GLAutoDrawable drawable) { // System.err.println("SceneUIController: display"); final int width = drawable.getWidth(); @@ -99,11 +103,13 @@ public class SceneUIController implements GLEventListener{ render(gl, width, height, renderModes, sampleCount, false); } + @Override public void dispose(GLAutoDrawable drawable) { System.err.println("SceneUIController: dispose"); cDrawable = null; } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } @@ -153,13 +159,11 @@ public class SceneUIController implements GLEventListener{ final PMVMatrix pmv = renderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); - System.err.printf("SceneUICtrl.render.1.0: scale.0: %f, %f, %f%n", scale[0], scale[1], scale[2]); - System.err.printf("SceneUICtrl.render.1.0: translate.0: %f, %f, %f%n", translate[0], translate[1], translate[2]); + // System.err.printf("SceneUICtrl.render.1.0: scale.0: %f, %f, %f%n", scale[0], scale[1], scale[2]); + // System.err.printf("SceneUICtrl.render.1.0: translate.0: %f, %f, %f%n", translate[0], translate[1], translate[2]); pmv.glTranslatef(translate[0], translate[1], translate[2]); + pmv.glRotate(quaternion); pmv.glScalef(scale[0], scale[1], scale[2]); - pmv.glRotatef(rotation[0], 1, 0, 0); - pmv.glRotatef(rotation[1], 0, 1, 0); - pmv.glRotatef(rotation[2], 0, 0, 1); for(int index=0; index < count;index++){ if(select) { @@ -171,7 +175,7 @@ public class SceneUIController implements GLEventListener{ final float[] uiTranslate = uiShape.getTranslate(); pmv.glPushMatrix(); - System.err.printf("SceneUICtrl.render.1.0: translate.1: %f, %f%n", uiTranslate[0], uiTranslate[1]); + // System.err.printf("SceneUICtrl.render.1.0: translate.1: %f, %f%n", uiTranslate[0], uiTranslate[1]); pmv.glTranslatef(uiTranslate[0], uiTranslate[1], 0f); renderer.updateMatrix(gl); uiShape.drawShape(gl, renderer, sampleCount, select); @@ -192,9 +196,9 @@ public class SceneUIController implements GLEventListener{ } public void setRotation(float x, float y, float z) { - this.rotation[0] = x; - this.rotation[1] = y; - this.rotation[2] = z; + quaternion.setFromEuler(x * FloatUtil.PI / 180.0f, + y * FloatUtil.PI / 180.0f, + z * FloatUtil.PI / 180.0f); } public float[] getSceneClearColor() { return sceneClearColor; @@ -211,13 +215,15 @@ public class SceneUIController implements GLEventListener{ int mouseX = -1; int mouseY = -1; + @Override public void mouseClicked(MouseEvent e) { UIShape uiShape = getActiveUI(); if(uiShape != null){ - uiShape.onClick(); + uiShape.onClick(e); } } + @Override public void mousePressed(MouseEvent e) { if(null==cDrawable) { return; @@ -226,6 +232,7 @@ public class SceneUIController implements GLEventListener{ mouseY = e.getY(); GLRunnable runnable = new GLRunnable() { + @Override public boolean run(GLAutoDrawable drawable) { UIShape s = getShape(drawable, mouseX, mouseY); if(null != s) { @@ -243,22 +250,28 @@ public class SceneUIController implements GLEventListener{ if(uiShape != null) { uiShape.setPressed(true); - uiShape.onPressed(); + uiShape.onPressed(e); } } + @Override public void mouseReleased(MouseEvent e) { UIShape uiShape = getActiveUI(); if(uiShape != null){ uiShape.setPressed(false); - uiShape.onRelease(); + uiShape.onRelease(e); } } + @Override public void mouseMoved(MouseEvent e) { } + @Override public void mouseEntered(MouseEvent e) { } + @Override public void mouseExited(MouseEvent e) { } + @Override public void mouseDragged(MouseEvent e) { } + @Override public void mouseWheelMoved(MouseEvent e) { } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java index 108aad879..65d8baa01 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java @@ -34,11 +34,12 @@ import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAutoDrawable; -import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.geom.SVertex; +import com.jogamp.newt.event.MouseEvent; import com.jogamp.opengl.test.junit.graph.demos.MSAATool; public class UIGLListener01 extends UIListenerBase01 { @@ -49,11 +50,14 @@ public class UIGLListener01 extends UIListenerBase01 { try { final Font font = FontFactory.get(FontFactory.UBUNTU).getDefault(); button = new RIButton(SVertex.factory(), font, "Click me!", 4f, 3f){ - public void onClick() { + @Override + public void onClick(MouseEvent e) { } - public void onPressed() { + @Override + public void onPressed(MouseEvent e) { } - public void onRelease() { + @Override + public void onRelease(MouseEvent e) { } }; @@ -71,6 +75,7 @@ public class UIGLListener01 extends UIListenerBase01 { } } + @Override public void init(GLAutoDrawable drawable) { super.init(drawable); @@ -83,6 +88,7 @@ public class UIGLListener01 extends UIListenerBase01 { MSAATool.dump(drawable); } + @Override public void display(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -102,6 +108,7 @@ public class UIGLListener01 extends UIListenerBase01 { button.drawShape(gl, regionRenderer, sampleCount, false); } + @Override public void dispose(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); button.destroy(gl, getRegionRenderer()); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java index 0768601bf..715beecca 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java @@ -34,16 +34,19 @@ import javax.media.opengl.GL2ES2; import jogamp.graph.geom.plane.AffineTransform; import com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.OutlineShapeXForm; +import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Vertex.Factory; +import com.jogamp.newt.event.MouseEvent; import com.jogamp.opengl.math.geom.AABBox; public abstract class UIShape { + public static final boolean DRAW_DEBUG_BOX = false; + private final Factory<? extends Vertex> vertexFactory; protected final ArrayList<OutlineShapeXForm> shapes; @@ -55,8 +58,8 @@ public abstract class UIShape { protected final AABBox box; protected final float[] translate = new float[] { 0f, 0f }; - protected final float[] ltranslate = new float[] { 0f, 0f }; - protected final float[] lscale = new float[] { 1f, 1f }; + protected final float[] shapeTranslate = new float[] { 0f, 0f }; + protected final float[] shapeScale = new float[] { 1f, 1f }; private GLRegion region = null; protected final float[] color = {0.6f, 0.6f, 0.6f}; @@ -84,10 +87,10 @@ public abstract class UIShape { shapes.clear(); translate[0] = 0f; translate[1] = 0f; - ltranslate[0] = 0f; - ltranslate[1] = 0f; - lscale[0] = 1f; - lscale[1] = 1f; + shapeTranslate[0] = 0f; + shapeTranslate[1] = 0f; + shapeScale[0] = 1f; + shapeScale[1] = 1f; box.reset(); dirty = DIRTY_SHAPE | DIRTY_POSITION | DIRTY_REGION; } @@ -102,10 +105,10 @@ public abstract class UIShape { shapes.clear(); translate[0] = 0f; translate[1] = 0f; - ltranslate[0] = 0f; - ltranslate[1] = 0f; - lscale[0] = 1f; - lscale[1] = 1f; + shapeTranslate[0] = 0f; + shapeTranslate[1] = 0f; + shapeScale[0] = 1f; + shapeScale[1] = 1f; box.reset(); dirty = DIRTY_SHAPE | DIRTY_POSITION | DIRTY_REGION; } @@ -122,13 +125,13 @@ public abstract class UIShape { return translate; } - public final void locTranslate(float tx, float ty) { - ltranslate[0] += tx; - ltranslate[1] += ty; + public final void translateShape(float tx, float ty) { + shapeTranslate[0] += tx; + shapeTranslate[1] += ty; } - public final void locScale(float sx, float sy) { - lscale[0] *= sx; - lscale[1] *= sy; + public final void scaleShape(float sx, float sy) { + shapeScale[0] *= sx; + shapeScale[1] *= sy; } public final boolean isShapeDirty() { @@ -157,7 +160,7 @@ public abstract class UIShape { } addToRegion(region); dirty &= ~DIRTY_REGION; - System.err.println("XXX.UIShape: updated: "+region); + // System.err.println("XXX.UIShape: updated: "+region); } return region; } @@ -173,9 +176,12 @@ public abstract class UIShape { * @param select */ public void drawShape(GL2ES2 gl, RegionRenderer renderer, int[] sampleCount, boolean select) { - float[] _color = color; + final float[] _color; if( isPressed() || toggle ){ _color = selectedColor; + } else { + _color = color; + } if(!select){ if( renderer.getRenderState().isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED) ) { @@ -192,11 +198,17 @@ public abstract class UIShape { } return true; } + private final boolean validateShape(GL2ES2 gl, RegionRenderer renderer) { if( isShapeDirty() ) { shapes.clear(); box.reset(); createShape(gl, renderer); + if( DRAW_DEBUG_BOX ) { + shapes.clear(); + final OutlineShape shape = new OutlineShape(renderer.getRenderState().getVertexFactory()); + shapes.add(new OutlineShapeXForm(createDebugOutline(shape, box), null)); + } dirty &= ~DIRTY_SHAPE; dirty |= DIRTY_REGION; validatePosition(); @@ -210,9 +222,9 @@ public abstract class UIShape { final AABBox box = getBounds(); final float minX = box.getMinX(); final float minY = box.getMinY(); - System.err.println("XXX.UIShape: Position pre: " + translate[0] + " " + translate[1] + ", sbox "+box); + // System.err.println("XXX.UIShape: Position pre: " + translate[0] + " " + translate[1] + ", sbox "+box); translate(-minX, -minY); - System.err.println("XXX.UIShape: Position post: " + translate[0] + " " + translate[1] + ", sbox "+box); + // System.err.println("XXX.UIShape: Position post: " + translate[0] + " " + translate[1] + ", sbox "+box); dirty &= ~DIRTY_POSITION; return true; } @@ -220,21 +232,18 @@ public abstract class UIShape { } private final void addToRegion(Region region) { + final boolean hasLocTrans = 0f != shapeTranslate[0] || 0f != shapeTranslate[1]; + final boolean hasLocScale = 1f != shapeScale[0] || 1f != shapeScale[1]; final AffineTransform t; - final boolean hasLocTrans = 0f != ltranslate[0] || 0f != ltranslate[1]; - final boolean hasLocScale = 1f != lscale[0] || 1f != lscale[1]; - if( hasLocTrans || hasLocScale ) { - System.err.printf("UIShape.addToRegion: locTranslate %f x %f, locScale %f x %f%n", - ltranslate[0], ltranslate[1], lscale[0], lscale[1]); + if( hasLocScale || hasLocTrans ) { + // System.err.printf("UIShape.addToRegion: locTranslate %f x %f, locScale %f x %f%n", + // shapeTranslate[0], shapeTranslate[1], shapeScale[0], shapeScale[1]); + t = new AffineTransform(); if( hasLocTrans ) { - t = AffineTransform.getTranslateInstance(ltranslate[0], ltranslate[1]); - if( hasLocScale ) { - t.scale(lscale[0], lscale[1]); - } - } else if( hasLocScale ) { - t = AffineTransform.getScaleInstance(lscale[0], lscale[1]); - } else { - t = null; // unreachable! + t.translate(shapeTranslate[0], shapeTranslate[1]); + } + if( hasLocScale ) { + t.scale(shapeScale[0], shapeScale[1]); } } else { t = null; @@ -245,8 +254,7 @@ public abstract class UIShape { final AffineTransform t2; if( null != tshape.t ) { if( null != t ) { - t2 = new AffineTransform(t); - t2.concatenate(tshape.t); + t2 = new AffineTransform(t).concatenate(tshape.t); } else { t2 = tshape.t; } @@ -295,9 +303,9 @@ public abstract class UIShape { this.toggleable = toggleable; } - public void onClick() { } - public void onPressed() { } - public void onRelease() { } + public void onClick(MouseEvent e) { } + public void onPressed(MouseEvent e) { } + public void onRelease(MouseEvent e) { } // // @@ -311,4 +319,20 @@ public abstract class UIShape { // // + protected OutlineShape createDebugOutline(OutlineShape shape, AABBox box) { + final float tw = box.getWidth(); + final float th = box.getHeight(); + + final float minX = box.getMinX(); + final float minY = box.getMinY(); + final float z = box.getMinZ() + 0.025f; + + shape.addVertex(minX, minY, z, true); + shape.addVertex(minX+tw, minY, z, true); + shape.addVertex(minX+tw, minY + th, z, true); + shape.addVertex(minX, minY + th, z, true); + shape.closeLastOutline(true); + return shape; + } + } |