aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-08-09 20:22:34 +0200
committerSven Gothel <[email protected]>2011-08-09 20:22:34 +0200
commitfefadb609d1135b0d5e13e9e872ca82fc2d7613c (patch)
treec31a8b9c664f28888a489e5f705ad124679b4c70
parent78c66acc25a89687ae898a52f885de8dd8909dd7 (diff)
parent5500015001d6e6043959f5f0252c254632f0d381 (diff)
Merge remote-tracking branch 'rsantina/master'
-rw-r--r--src/jogl/classes/javax/media/opengl/GLRunnable.java6
-rw-r--r--src/jogl/classes/jogamp/opengl/GLDrawableHelper.java30
-rw-r--r--src/jogl/classes/jogamp/opengl/GLRunnableTask.java8
-rw-r--r--src/newt/classes/com/jogamp/newt/event/MouseEvent.java48
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java27
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUGraphGLListenerMT.java377
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUTextNewtDemoMobile01.java49
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java14
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java139
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java245
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java13
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java54
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java6
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java9
16 files changed, 942 insertions, 99 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLRunnable.java b/src/jogl/classes/javax/media/opengl/GLRunnable.java
index de0f5df48..cbd086c77 100644
--- a/src/jogl/classes/javax/media/opengl/GLRunnable.java
+++ b/src/jogl/classes/javax/media/opengl/GLRunnable.java
@@ -41,7 +41,11 @@ public interface GLRunnable {
/**
* Called by the drawable to initiate one-shot OpenGL commands by the
* client, like {@link GLEventListener#display(GLAutoDrawable)}.
+ *
+ * @param drawable the associated drawable the implementation shall use
+ * @return false if impl invalidates the back buffers, hence {@link GLAutoDrawable#display()} will
+ * issue another {@link GLEventListener#display(GLAutoDrawable)} call. Otherwise true.
*/
- void run(GLAutoDrawable drawable);
+ boolean run(GLAutoDrawable drawable);
}
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
index 887e571cc..9353479ab 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
@@ -156,16 +156,21 @@ public class GLDrawableHelper {
}
public final void display(GLAutoDrawable drawable) {
- synchronized(listenersLock) {
- for (int i=0; i < listeners.size(); i++) {
- final GLEventListener listener = listeners.get(i) ;
- // GLEventListener may need to be init,
- // in case this one is added after the realization of the GLAutoDrawable
- init( listener, drawable, true ) ;
- listener.display(drawable);
- }
+ displayImpl(drawable);
+ if(!execGLRunnables(drawable)) {
+ displayImpl(drawable);
}
- execGLRunnables(drawable);
+ }
+ private void displayImpl(GLAutoDrawable drawable) {
+ synchronized(listenersLock) {
+ for (int i=0; i < listeners.size(); i++) {
+ final GLEventListener listener = listeners.get(i) ;
+ // GLEventListener may need to be init,
+ // in case this one is added after the realization of the GLAutoDrawable
+ init( listener, drawable, true ) ;
+ listener.display(drawable);
+ }
+ }
}
private void reshape(GLEventListener listener, GLAutoDrawable drawable,
@@ -184,7 +189,8 @@ public class GLDrawableHelper {
}
}
- private void execGLRunnables(GLAutoDrawable drawable) {
+ private boolean execGLRunnables(GLAutoDrawable drawable) {
+ boolean res = true;
if(glRunnables.size()>0) {
// swap one-shot list asap
ArrayList<GLRunnable> _glRunnables = null;
@@ -194,12 +200,14 @@ public class GLDrawableHelper {
glRunnables = new ArrayList<GLRunnable>();
}
}
+
if(null!=_glRunnables) {
for (int i=0; i < _glRunnables.size(); i++) {
- _glRunnables.get(i).run(drawable);
+ res = _glRunnables.get(i).run(drawable) && res;
}
}
}
+ return res;
}
public final void setAnimator(GLAnimatorControl animator) throws GLException {
diff --git a/src/jogl/classes/jogamp/opengl/GLRunnableTask.java b/src/jogl/classes/jogamp/opengl/GLRunnableTask.java
index e5b66b985..448f68423 100644
--- a/src/jogl/classes/jogamp/opengl/GLRunnableTask.java
+++ b/src/jogl/classes/jogamp/opengl/GLRunnableTask.java
@@ -50,10 +50,11 @@ public class GLRunnableTask implements GLRunnable {
isExecuted = false;
}
- public void run(GLAutoDrawable drawable) {
+ public boolean run(GLAutoDrawable drawable) {
+ boolean res = true;
if(null == notifyObject) {
try {
- runnable.run(drawable);
+ res = runnable.run(drawable);
} catch (Throwable t) {
runnableException = t;
if(catchExceptions) {
@@ -67,7 +68,7 @@ public class GLRunnableTask implements GLRunnable {
} else {
synchronized (notifyObject) {
try {
- runnable.run(drawable);
+ res = runnable.run(drawable);
} catch (Throwable t) {
runnableException = t;
if(catchExceptions) {
@@ -81,6 +82,7 @@ public class GLRunnableTask implements GLRunnable {
}
}
}
+ return res;
}
public boolean isExecuted() { return isExecuted; }
diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
index 7ad7d6e2d..62a8941d7 100644
--- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
@@ -56,33 +56,47 @@ public class MouseEvent extends InputEvent
this.x = new int[]{x};
this.y = new int[]{y};
this.pressure = new float[]{0};
-
+ this.pointerids = new int[]{-1};
this.clickCount=clickCount;
this.button=button;
this.wheelRotation = rotation;
}
public MouseEvent(int eventType, Object source, long when,
- int modifiers, int[] x, int[] y, float[] pressure, int clickCount, int button,
+ int modifiers, int[] x, int[] y, float[] pressure, int[] pointerids, int clickCount, int button,
int rotation)
{
super(eventType, source, when, modifiers);
this.x = x;
this.y = y;
this.pressure = pressure;
-
+ this.pointerids = pointerids;
this.clickCount=clickCount;
this.button=button;
this.wheelRotation = rotation;
}
+ /**
+ * @return the count of pointers involved in this event
+ */
public int getPointerCount() {
return x.length;
}
+ /**
+ * @return the pointer id for the data at index.
+ * return -1 if index not available.
+ */
+ public int getPointerId(int index) {
+ if(index >= pointerids.length)
+ return -1;
+ return pointerids[index];
+ }
+
public int getButton() {
return button;
}
+
public int getClickCount() {
return clickCount;
}
@@ -94,20 +108,29 @@ public class MouseEvent extends InputEvent
return y[0];
}
- public int getX(int pointer) {
- return x[pointer];
+ /**
+ * @return x-coord at index where index refers to the
+ * data coming from a pointer.
+ * @see getPointerId(index)
+ */
+ public int getX(int index) {
+ return x[index];
}
- public int getY(int pointer) {
- return y[pointer];
+ public int getY(int index) {
+ return y[index];
}
public float getPressure(){
return pressure[0];
}
- public float getPressure(int pointer){
- return pressure[pointer];
+ /**
+ * @return the pressure associated with the pointer at index.
+ * the value of zero is return if not available.
+ */
+ public float getPressure(int index){
+ return pressure[index];
}
public int getWheelRotation() {
@@ -131,14 +154,13 @@ public class MouseEvent extends InputEvent
case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED";
case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED";
case EVENT_MOUSE_WHEEL_MOVED: return "EVENT_MOUSE_WHEEL_MOVED";
- case EVENT_MOUSE_PRESSED_MINOR: return "EVENT_MOUSE_PRESSED_MINOR";
- case EVENT_MOUSE_RELEASED_MINOR: return "EVENT_MOUSE_RELEASED_MINOR";
default: return "unknown (" + type + ")";
}
}
private final int x[], y[], clickCount, button, wheelRotation;
private final float pressure[];
-
+ private final int pointerids[];
+
public static final int EVENT_MOUSE_CLICKED = 200;
public static final int EVENT_MOUSE_ENTERED = 201;
public static final int EVENT_MOUSE_EXITED = 202;
@@ -147,6 +169,4 @@ public class MouseEvent extends InputEvent
public static final int EVENT_MOUSE_MOVED = 205;
public static final int EVENT_MOUSE_DRAGGED = 206;
public static final int EVENT_MOUSE_WHEEL_MOVED = 207;
- public static final int EVENT_MOUSE_PRESSED_MINOR = 208;
- public static final int EVENT_MOUSE_RELEASED_MINOR = 209;
}
diff --git a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
index 5439c5c9e..75b9f8642 100644
--- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
@@ -48,8 +48,8 @@ public class AndroidNewtEventFactory {
map.put(android.view.MotionEvent.ACTION_MOVE, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED);
map.put(android.view.MotionEvent.ACTION_OUTSIDE, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED);
- map.put(android.view.MotionEvent.ACTION_POINTER_DOWN, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED_MINOR);
- map.put(android.view.MotionEvent.ACTION_POINTER_UP, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED_MINOR);
+ map.put(android.view.MotionEvent.ACTION_POINTER_DOWN, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED);
+ map.put(android.view.MotionEvent.ACTION_POINTER_UP, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED);
map.put(android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
@@ -127,21 +127,6 @@ public class AndroidNewtEventFactory {
}
return null;
}
-
- public static final int androidActionPointer2Newt(android.view.MotionEvent event) {
- int action = event.getAction();
- int androidMods = event.getMetaState();
-
- if ((android.view.MotionEvent.ACTION_POINTER_UP != action)
- || (android.view.MotionEvent.ACTION_POINTER_DOWN != action)) {
- return 0;
- }
-
- int pointerIndex = (androidMods & android.view.MotionEvent.ACTION_POINTER_INDEX_MASK);
- pointerIndex = pointerIndex >> android.view.MotionEvent.ACTION_POINTER_INDEX_SHIFT;
-
- return event.getPointerId(pointerIndex);
- }
public static final com.jogamp.newt.event.MouseEvent createMouseEvent(android.view.MotionEvent event, com.jogamp.newt.Window newtSource) {
int type = eventTypeANDROID2NEWT.get(event.getAction());
@@ -153,21 +138,21 @@ public class AndroidNewtEventFactory {
int[] x = new int[event.getPointerCount()];
int[] y = new int[event.getPointerCount()];
float[] pressure = new float[event.getPointerCount()];
-
+ int[] pointers = new int[event.getPointerCount()];
int index = 0;
while(index < event.getPointerCount()) {
x[index] = (int)event.getX(index);
y[index] = (int)event.getY(index);
pressure[index] = event.getPressure(index);
+ pointers[index] = event.getPointerId(index);
index++;
}
- int pointer = androidActionPointer2Newt(event);
return new com.jogamp.newt.event.MouseEvent(
type, (null==newtSource)?null:(Object)newtSource, event.getEventTime(),
modifiers ,
- x, y, pressure, clickCount,
- pointer+1, rotation);
+ x, y, pressure, pointers, clickCount,
+ 0, rotation);
}
return null; // no mapping ..
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java
index a837c56f8..7a10c4950 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java
@@ -254,7 +254,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
else if(arg0.getKeyCode() == KeyEvent.VK_V) {
if(null != autoDrawable) {
autoDrawable.invoke(false, new GLRunnable() {
- public void run(GLAutoDrawable drawable) {
+ public boolean run(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
int i = gl.getSwapInterval();
i = i==0 ? 1 : 0;
@@ -267,6 +267,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
((FPSCounter)drawable).resetFPSCounter();
}
System.err.println("Swap Interval: "+i);
+ return true;
}
});
}
@@ -275,7 +276,7 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
rotate(-1);
if(null != autoDrawable) {
autoDrawable.invoke(false, new GLRunnable() {
- public void run(GLAutoDrawable drawable) {
+ public boolean run(GLAutoDrawable drawable) {
try {
final String type = Region.isVBAA(renderModes) ? "vbaa0-msaa1" : "vbaa1-msaa0" + ( Region.isNonUniformWeight(renderModes) ? "-vc" : "-uc" ) ;
printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false);
@@ -284,7 +285,8 @@ public abstract class GPURendererListenerBase01 implements GLEventListener {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
- }
+ }
+ return true;
}
});
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUGraphGLListenerMT.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUGraphGLListenerMT.java
new file mode 100644
index 000000000..dc0bc68fd
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUGraphGLListenerMT.java
@@ -0,0 +1,377 @@
+package com.jogamp.opengl.test.junit.graph.demos.mobile;
+
+import javax.media.opengl.FPSCounter;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLAnimatorControl;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLPipelineFactory;
+import javax.media.opengl.GLRunnable;
+
+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.opengl.SVertex;
+import com.jogamp.newt.event.MouseEvent;
+import com.jogamp.newt.event.MouseListener;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.graph.demos.ui.Label;
+import com.jogamp.opengl.test.junit.graph.demos.ui.RIButton;
+import com.jogamp.opengl.test.junit.graph.demos.ui.SceneUIController;
+import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion;
+
+public class GPUGraphGLListenerMT implements GLEventListener {
+
+ private boolean debug = false;
+ private boolean trace = false;
+
+ private RegionRenderer regionRenderer;
+ private RenderState rs;
+
+ int fontSet = FontFactory.UBUNTU;
+ Font font;
+ final int fontSizeFixed = 6;
+
+ private float xTran = 0;
+ private float yTran = 0;
+ private float ang = 0f;
+ private float zoom = -200f;
+ private float zoomText = 1f;
+ private int currentText = 0;
+
+ private Label[] labels = null;
+ private String[] strings = null;
+ private UIRegion[] labelRegions;
+ private UIRegion fpsRegion = null;
+ private UIRegion jogampRegion = null;
+ private RIButton[] buttons = null;
+
+ private int numSelectable = 6;
+
+ private int mouseX, mouseY;
+ private SceneUIController sceneUIController = null;
+
+ private boolean showFPS = false;
+ private GLAutoDrawable cDrawable;
+ private float fps = 0;
+
+ private String jogamp = "JogAmp - Jogl Graph Module Demo";
+ private float angText = 0;
+
+ public GPUGraphGLListenerMT(RenderState rs, boolean debug, boolean trace) {
+ this.rs = rs;
+
+ this.debug = debug;
+ this.trace = trace;
+ font = FontFactory.get(FontFactory.UBUNTU).getDefault();
+ labelRegions = new UIRegion[3];
+ }
+
+ private void initButtons(int width, int height) {
+ buttons = new RIButton[numSelectable];
+ int xaxis = -110;
+ float xSize = 40f;
+ float ySize = 16f;
+
+ int start = 50;
+ int diff = (int)ySize + 5;
+
+ buttons[0] = new RIButton(SVertex.factory(), font, "Next Text", xSize, ySize){
+ public void onClick() {
+ currentText = (currentText+1)%3;
+ }
+ public void onPressed() { }
+ public void onRelease() { }
+ };
+
+ buttons[0].setPosition(xaxis,start,0);
+
+ buttons[1] = new RIButton(SVertex.factory(), font, "Show FPS", xSize, ySize){
+ public void onClick() {
+ showFPS = !showFPS;
+ }
+ public void onPressed() { }
+ public void onRelease() { }
+ };
+ buttons[1].setPosition(xaxis,start - diff,0);
+ buttons[1].setToggleable(true);
+
+ buttons[2] = new RIButton(SVertex.factory(), font, "v-sync", xSize, ySize){
+ public void onClick() {
+ cDrawable.invoke(false, new GLRunnable() {
+ public boolean run(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
+ int i = gl.getSwapInterval();
+ i = i==0 ? 1 : 0;
+ gl.setSwapInterval(i);
+ final GLAnimatorControl a = drawable.getAnimator();
+ if( null != a ) {
+ a.resetFPSCounter();
+ }
+ return true;
+ }
+ });
+ }
+ public void onPressed() { }
+ public void onRelease() { }
+ };
+ buttons[2].setPosition(xaxis,start-diff*2,0);
+ buttons[2].setToggleable(true);
+
+ buttons[3] = new RIButton(SVertex.factory(), font, "Tilt +Y", xSize, ySize) {
+ public void onClick() {
+ ang+=10;
+ }
+ public void onPressed() {
+
+ }
+ public void onRelease() { }
+ };
+ buttons[3].setPosition(xaxis,start-diff*3,0);
+
+ buttons[4] = new RIButton(SVertex.factory(), font, "Tilt -Y", xSize, ySize){
+ public void onClick() {
+ ang-=10;
+ }
+ public void onPressed() { }
+ public void onRelease() { }
+ };
+ buttons[4].setPosition(xaxis,start-diff*4,0);
+
+ buttons[5] = new RIButton(SVertex.factory(), font, "Quit", xSize, ySize){
+ public void onClick() {
+ cDrawable.destroy();
+ }
+ public void onPressed() { }
+ public void onRelease() { }
+ };
+ buttons[5].setPosition(xaxis,start-diff*5,0);
+ buttons[5].setButtonColor(0.8f, 0.0f, 0.0f);
+ buttons[5].setLabelColor(1.0f, 1.0f, 1.0f);
+
+ buttons[5].setButtonSelectedColor(0.8f, 0.8f, 0.8f);
+ buttons[5].setLabelSelectedColor(0.8f, 0.0f, 0.0f);
+ }
+
+ private void initTexts() {
+ strings = new String[3];
+
+ strings[0] = "abcdefghijklmn\nopqrstuvwxyz\nABCDEFGHIJKL\nMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]";
+ strings[1] = "The quick brown fox\njumps over the lazy\ndog";
+
+ strings[2] =
+ "Lorem ipsum dolor sit amet, consectetur\n"+
+ "Ut purus odio, rhoncus sit amet com\n"+
+ "quam iaculis urna cursus ornare. Nullam\n"+
+ "In hac habitasse platea dictumst. Vivam\n"+
+ "Morbi quis bibendum nibh. Donec lectus\n"+
+ "Donec ut dolor et nulla tristique variu\n"+
+ "in lorem. Maecenas in ipsum ac justo sc\n";
+
+ labels = new Label[3];
+ }
+
+ @Override
+ public void init(GLAutoDrawable drawable) {
+ final int width = drawable.getWidth();
+ final int height = drawable.getHeight();
+ cDrawable = drawable;
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+ if(debug) {
+ gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, gl, null) ).getGL2ES2();
+ }
+ if(trace) {
+ gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2();
+ }
+
+ this.font = FontFactory.get(fontSet).getDefault();
+ regionRenderer = RegionRenderer.create(rs, 0);
+
+ gl.setSwapInterval(1);
+ gl.glEnable(GL2ES2.GL_DEPTH_TEST);
+ gl.glEnable(GL2ES2.GL_BLEND);
+
+ regionRenderer.init(gl);
+ regionRenderer.setAlpha(gl, 1.0f);
+ regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+
+ initTexts();
+ initButtons(width, height);
+
+ sceneUIController.setRenderer(regionRenderer, rs);
+ sceneUIController.addShape(buttons[0]);
+ sceneUIController.addShape(buttons[1]);
+ sceneUIController.addShape(buttons[2]);
+ sceneUIController.addShape(buttons[3]);
+ sceneUIController.addShape(buttons[4]);
+ sceneUIController.addShape(buttons[5]);
+
+ Label jlabel = new Label(SVertex.factory(), font, fontSizeFixed, jogamp){
+ public void onClick() { }
+ public void onPressed() { }
+ public void onRelease() { }
+ };
+
+ jogampRegion = new UIRegion(jlabel);
+ }
+
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+ sceneUIController = null;
+ regionRenderer.destroy(gl);
+ }
+
+ @Override
+ public void display(GLAutoDrawable drawable) {
+ final int width = drawable.getWidth();
+ final int height = drawable.getHeight();
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+
+ regionRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);
+ sceneUIController.setTranslate(xTran, yTran, zoom);
+ sceneUIController.setRotation(0, ang, 0);
+
+ renderScene(drawable);
+ }
+
+ private void renderScene(GLAutoDrawable drawable) {
+ final int width = drawable.getWidth();
+ final int height = drawable.getHeight();
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ regionRenderer.resetModelview(null);
+ regionRenderer.translate(null, xTran-50, yTran+43, zoom);
+ regionRenderer.translate(gl, 0, 30, 0);
+ regionRenderer.scale(null, zoomText, zoomText, 1);
+ regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f);
+ regionRenderer.rotate(gl, angText , 0, 1, 0);
+ regionRenderer.setColorStatic(gl, 0.0f, 1.0f, 0.0f);
+ regionRenderer.draw(gl, jogampRegion.getRegion(gl, rs, 0), new float[]{0,0,0}, 0);
+
+ if(null == labelRegions[currentText]) {
+ if( null == labels[currentText]) {
+ labels[currentText] = new Label(SVertex.factory(), font, fontSizeFixed, strings[currentText]){
+ public void onClick() { }
+ public void onPressed() { }
+ public void onRelease() { }
+ };
+ }
+ labelRegions[currentText] = new UIRegion(labels[currentText]);
+ }
+
+ regionRenderer.resetModelview(null);
+ regionRenderer.translate(null, xTran-50, yTran, zoom);
+ regionRenderer.translate(gl, 0, 30, 0);
+ regionRenderer.scale(null, zoomText, zoomText, 1);
+ regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f);
+ regionRenderer.rotate(gl, zoomText, 0, 1, 0);
+
+ regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
+ regionRenderer.draw(gl, labelRegions[currentText].getRegion(gl, rs, 0), new float[]{0,0,0}, 0);
+
+ final GLAnimatorControl animator = drawable.getAnimator();
+ final boolean _drawFPS = showFPS && null != animator;
+
+ if(_drawFPS && fps != animator.getTotalFPS()) {
+ if(null != fpsRegion) {
+ fpsRegion.destroy(gl, rs);
+ }
+ fps = animator.getTotalFPS();
+ final String fpsS = String.valueOf(fps);
+ final int fpsSp = fpsS.indexOf('.');
+
+ Label fpsLabel = new Label(SVertex.factory(), font, fontSizeFixed, fpsS.substring(0, fpsSp+2)+" fps"){
+ public void onClick() { }
+ public void onPressed() { }
+ public void onRelease() { }
+ };
+ fpsRegion = new UIRegion(fpsLabel);
+ }
+ if(showFPS && null != fpsRegion) {
+ regionRenderer.translate(gl, 0, -60, 0);
+ regionRenderer.scale(null, zoomText, zoomText, 1);
+ regionRenderer.draw(gl, fpsRegion.getRegion(gl, rs, 0), new float[]{0,0,0}, 0);
+ }
+ }
+
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width,
+ int height) {
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ gl.glViewport(x, y, width, height);
+ regionRenderer.reshapePerspective(gl, 45.0f, width, height, 5f, 70.0f);
+ }
+
+ public void attachInputListenerTo(GLWindow window) {
+ MultiTouchListener multiTouchListener = new MultiTouchListener();
+ window.addMouseListener(multiTouchListener);
+ sceneUIController = new SceneUIController();
+ window.addGLEventListener(sceneUIController);
+ sceneUIController.attachInputListenerTo(window);
+ }
+
+ private class MultiTouchListener implements MouseListener {
+ int lx = 0;
+ int ly = 0;
+
+ boolean first = false;
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ first = true;
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ first = false;
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ if(first) {
+ lx = e.getX();
+ ly = e.getY();
+ first=false;
+ return;
+ }
+ int dx = lx - e.getX();
+ int dy = e.getY() - ly;
+ if(Math.abs(dx) < Math.abs(dy)) {
+ zoom += Math.signum(dy);
+ } else {
+ xTran += Math.signum(dx);
+ }
+
+ lx = e.getX();
+ ly = e.getY();
+ }
+
+ @Override
+ public void mouseWheelMoved(MouseEvent e) {
+
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUTextNewtDemoMobile01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUTextNewtDemoMobile01.java
new file mode 100644
index 000000000..66f709595
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUTextNewtDemoMobile01.java
@@ -0,0 +1,49 @@
+package com.jogamp.opengl.test.junit.graph.demos.mobile;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.geom.opengl.SVertex;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+public class GPUTextNewtDemoMobile01 {
+ static final boolean DEBUG = false;
+ static final boolean TRACE = false;
+
+ public static void main(String[] args) {
+ GLProfile.initSingleton(true);
+ GLProfile glp = GLProfile.getGL2ES2();
+ GLCapabilities caps = new GLCapabilities(glp);
+ caps.setAlphaBits(4);
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(4);
+
+ final GLWindow window = GLWindow.create(caps);
+ window.setPosition(10, 10);
+ window.setSize(680, 480);
+ window.setTitle("GraphUI Newt Demo");
+
+ final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
+ GPUGraphGLListenerMT textGLListener = new GPUGraphGLListenerMT(rs, DEBUG, TRACE);
+ window.addGLEventListener(textGLListener);
+ textGLListener.attachInputListenerTo(window);
+
+ final Animator animator = new Animator();
+ animator.setUpdateFPSFrames(10, null);
+ animator.add(window);
+
+ window.addWindowListener(new WindowAdapter() {
+ public void windowDestroyed(WindowEvent e) {
+ animator.stop();
+ }
+ });
+
+ window.setVisible(true);
+ animator.start();
+ }
+}
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 70dd489b0..83fc08b86 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
@@ -27,13 +27,17 @@
*/
package com.jogamp.opengl.test.junit.graph.demos.ui;
+import javax.media.opengl.GL2ES2;
+
import jogamp.graph.curve.text.GlyphString;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
-public class Label extends UIShape implements UITextShape {
+public abstract class Label extends UIShape implements UITextShape {
protected Font font;
protected int size;
protected String text;
@@ -50,7 +54,7 @@ public class Label extends UIShape implements UITextShape {
return glyphString;
}
- public String getText(){
+ public String getText() {
return text;
}
@@ -93,4 +97,10 @@ public class Label extends UIShape implements UITextShape {
clearImpl();
glyphString = GlyphString.createString(shape, getVertexFactory(), font, size, text);
}
+
+ @Override
+ public void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer,
+ boolean selection) {
+
+ }
}
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 e9296752e..60f79e2d7 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
@@ -27,32 +27,42 @@
*/
package com.jogamp.opengl.test.junit.graph.demos.ui;
+import javax.media.opengl.GL2ES2;
+
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.geom.AABBox;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
+import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion;
/** GPU based resolution independent Button impl
*/
-public class RIButton extends UIShape {
+public abstract class RIButton extends UIShape {
private float width, height;
private Label label;
- private float spacing = 2.0f;
- private float[] scale = new float[]{1.0f,1.0f};
+ private float spacing = 4.0f;
private float corner = 1.0f;
private float labelZOffset = -0.05f;
private float[] buttonColor = {0.6f, 0.6f, 0.6f};
+ private float[] buttonSelectedColor = {0.8f,0.8f,0.8f};
private float[] labelColor = {1.0f, 1.0f, 1.0f};
+ private float[] labelSelectedColor = {0.1f, 0.1f, 0.1f};
+
public RIButton(Factory<? extends Vertex> factory, Font labelFont, String labelText, float width, float height) {
- // w 4.0f, h 3.0f
- // FontFactory.get(FontFactory.UBUNTU).getDefault()
super(factory);
// FIXME: Determine font size - PMV Matrix relation ?
// this.label = new Label(factory, labelFont, (int)(height - 2f * spacing), labelText);
- this.label = new Label(factory, labelFont, 10, labelText);
+ this.label = new Label(factory, labelFont, 10, labelText){
+ public void onClick() { }
+ public void onPressed() { }
+ public void onRelease() { }
+ };
+
this.width = width;
this.height = height;
}
@@ -60,7 +70,6 @@ public class RIButton extends UIShape {
public final float getWidth() { return width; }
public final float getHeight() { return height; }
public float getCorner() { return corner; }
- public float[] getScale() { return scale; }
public Label getLabel() { return label; }
public void setDimension(int width, int height) {
@@ -68,7 +77,7 @@ public class RIButton extends UIShape {
this.height = height;
dirty |= DIRTY_SHAPE;
}
-
+
@Override
protected void clearImpl() {
label.clear();
@@ -88,21 +97,26 @@ public class RIButton extends UIShape {
} else {
createCurvedOutline(lbox);
}
- scale[0] = getWidth() / ( 2f*spacing + lbox.getWidth() );
- scale[1] = getHeight() / ( 2f*spacing + lbox.getHeight() );
+ float sx = getWidth() / ( 2f*spacing + lbox.getWidth() );
+ float sy = getHeight() / ( 2f*spacing + lbox.getHeight() );
+
+ setScale(sx, sy, 1);
}
private void createSharpOutline(AABBox lbox) {
float th = (2f*spacing) + lbox.getHeight();
float tw = (2f*spacing) + lbox.getWidth();
+
+ float[] pos = getPosition();
float minX = lbox.getMinX()-spacing;
float minY = lbox.getMinY()-spacing;
+ float minZ = labelZOffset;
- shape.addVertex(minX, minY, labelZOffset, true);
- shape.addVertex(minX+tw, minY, labelZOffset, true);
- shape.addVertex(minX+tw, minY + th, labelZOffset, true);
- shape.addVertex(minX, minY + th, labelZOffset, true);
+ shape.addVertex(minX, minY, minZ, true);
+ shape.addVertex(minX+tw, minY, minZ, true);
+ shape.addVertex(minX+tw, minY + th, minZ, true);
+ shape.addVertex(minX, minY + th, minZ, true);
shape.closeLastOutline();
}
@@ -113,25 +127,25 @@ public class RIButton extends UIShape {
float cw = 0.5f*corner*Math.min(tw, th);
float ch = 0.5f*corner*Math.min(tw, th);
+ float[] pos = getPosition();
float minX = lbox.getMinX()-spacing;
float minY = lbox.getMinY()-spacing;
-
- shape.addVertex(minX, minY + ch, labelZOffset, true);
- shape.addVertex(minX, minY, labelZOffset, false);
- shape.addVertex(minX + cw, minY, labelZOffset, true);
- shape.addVertex(minX + tw - cw, minY, labelZOffset, true);
- shape.addVertex(minX + tw, minY, labelZOffset, false);
- shape.addVertex(minX + tw, minY + ch, labelZOffset, true);
- shape.addVertex(minX + tw, minY + th- ch, labelZOffset, true);
- shape.addVertex(minX + tw, minY + th, labelZOffset, false);
- shape.addVertex(minX + tw - cw, minY + th, labelZOffset, true);
- shape.addVertex(minX + cw, minY + th, labelZOffset, true);
- shape.addVertex(minX, minY + th, labelZOffset, false);
- shape.addVertex(minX, minY + th - ch, labelZOffset, true);
+ float minZ = labelZOffset;
+ shape.addVertex(minX, minY + ch, minZ, true);
+ shape.addVertex(minX, minY, minZ, false);
+ shape.addVertex(minX + cw, minY, minZ, true);
+ shape.addVertex(minX + tw - cw, minY, minZ, true);
+ shape.addVertex(minX + tw, minY, minZ, false);
+ shape.addVertex(minX + tw, minY + ch, minZ, true);
+ shape.addVertex(minX + tw, minY + th- ch, minZ, true);
+ shape.addVertex(minX + tw, minY + th, minZ, false);
+ shape.addVertex(minX + tw - cw, minY + th, minZ, true);
+ shape.addVertex(minX + cw, minY + th, minZ, true);
+ shape.addVertex(minX, minY + th, minZ, false);
+ shape.addVertex(minX, minY + th - ch, minZ, true);
shape.closeLastOutline();
}
-
-
+
public void setCorner(float corner) {
if(corner > 1.0f){
this.corner = 1.0f;
@@ -172,6 +186,7 @@ public class RIButton extends UIShape {
}
public void setButtonColor(float r, float g, float b) {
+ this.buttonColor = new float[3];
this.buttonColor[0] = r;
this.buttonColor[1] = g;
this.buttonColor[2] = b;
@@ -180,16 +195,80 @@ public class RIButton extends UIShape {
public float[] getLabelColor() {
return labelColor;
}
+
+ private UIRegion buttonRegion = null;
+ private UIRegion labelRegion = null;
+ private boolean toggle =false;
+ private boolean toggleable = false;
+
+ public void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer, boolean selection) {
+ if(null == buttonRegion) {
+ buttonRegion = new UIRegion(this);
+ labelRegion = new UIRegion(getLabel());
+ }
+
+ gl.glEnable(GL2ES2.GL_POLYGON_OFFSET_FILL);
+ gl.glPolygonOffset(0.0f, 1f);
+
+ float[] bColor = buttonColor;
+ if(isPressed() || toggle){
+ bColor = buttonSelectedColor;
+ }
+ if(!selection){
+ renderer.setColorStatic(gl, bColor[0], bColor[1], bColor[2]);
+ }
+ renderer.draw(gl, buttonRegion.getRegion(gl, rs, 0), getPosition(), 0);
+ gl.glDisable(GL2ES2.GL_POLYGON_OFFSET_FILL);
+
+ float[] lColor = labelColor;
+ if(isPressed() || toggle ){
+ lColor = labelSelectedColor;
+ }
+ if(!selection){
+ renderer.setColorStatic(gl, lColor[0], lColor[1], lColor[2]);
+ }
+ renderer.draw(gl, labelRegion.getRegion(gl, rs, 0), getPosition(), 0);
+ }
+ public void setPressed(boolean b) {
+ super.setPressed(b);
+ if(isToggleable() && b) {
+ toggle = !toggle;
+ }
+ }
+
public void setLabelColor(float r, float g, float b) {
+ this.labelColor = new float[3];
this.labelColor[0] = r;
this.labelColor[1] = g;
this.labelColor[2] = b;
}
+ public void setButtonSelectedColor(float r, float g, float b){
+ this.buttonSelectedColor = new float[3];
+ this.buttonSelectedColor[0] = r;
+ this.buttonSelectedColor[1] = g;
+ this.buttonSelectedColor[2] = b;
+ }
+
+ public void setLabelSelectedColor(float r, float g, float b){
+ this.labelSelectedColor = new float[3];
+ this.labelSelectedColor[0] = r;
+ this.labelSelectedColor[1] = g;
+ this.labelSelectedColor[2] = b;
+ }
+
+ public boolean isToggleable() {
+ return toggleable;
+ }
+
+ public void setToggleable(boolean toggleable) {
+ this.toggleable = toggleable;
+ }
+
public String toString() {
return "RIButton [" + getWidth() + "x" + getHeight() + ", "
- + getLabel() + "," + "spacing: " + spacing
+ + getLabel() + ", " + "spacing: " + spacing
+ ", " + "corner: " + corner + ", " + "shapeOffset: " + labelZOffset + " ]";
}
}
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
new file mode 100644
index 000000000..d3b1de827
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java
@@ -0,0 +1,245 @@
+package com.jogamp.opengl.test.junit.graph.demos.ui;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+import java.util.ArrayList;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLRunnable;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.newt.event.MouseEvent;
+import com.jogamp.newt.event.MouseListener;
+import com.jogamp.newt.opengl.GLWindow;
+
+public class SceneUIController implements GLEventListener{
+ private ArrayList<UIShape> shapes = new ArrayList<UIShape>();
+
+ private int count = 0;
+ private RegionRenderer renderer = null;
+ private RenderState rs = null;
+
+ private float[] translate = new float[3];
+ private float[] scale = new float[3];
+ private float[] rotation = new float[3];
+
+ private float[] sceneClearColor = new float[]{0,0,0,1};
+
+ private int activeId = -1;
+
+ private SBCMouseListener sbcMouseListener = null;
+
+ private GLAutoDrawable cDrawable = null;
+
+ public SceneUIController() {
+
+ }
+
+ public void setRenderer(RegionRenderer renderer, RenderState rs) {
+ this.renderer = renderer;
+ this.rs = rs;
+ }
+
+ public SceneUIController(RegionRenderer renderer, RenderState rs) {
+ this.renderer = renderer;
+ this.rs = rs;
+ }
+
+ public void attachInputListenerTo(GLWindow window) {
+ sbcMouseListener = new SBCMouseListener();;
+ window.addMouseListener(sbcMouseListener);
+ }
+
+ public ArrayList<UIShape> getShapes() {
+ return shapes;
+ }
+ public void addShape(UIShape b) {
+ shapes.add(b);
+ count++;
+ }
+
+ public void removeShape(UIShape b) {
+ boolean found = shapes.remove(b);
+ if(found) {
+ count--;
+ }
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ cDrawable = drawable;
+ }
+ public void display(GLAutoDrawable drawable) {
+ final int width = drawable.getWidth();
+ final int height = drawable.getHeight();
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ render(gl, width, height,false);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width,
+ int height) {
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+ renderer.reshapePerspective(gl, 45.0f, width, height, 5f, 70.0f);
+ }
+
+ public UIShape getShape(GLAutoDrawable drawable,int x, int y) {
+ final int width = drawable.getWidth();
+ final int height = drawable.getHeight();
+ GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ int index = checkSelection(gl, x, y, width, height);
+ if(index == -1)
+ return null;
+ return shapes.get(index);
+ }
+
+ public UIShape getActiveUI() {
+ if(activeId == -1)
+ return null;
+ return shapes.get(activeId);
+ }
+
+ public void release() {
+ activeId = -1;
+ }
+
+ private int checkSelection(GL2ES2 gl,int x, int y, int width, int height) {
+ gl.glPixelStorei(GL2ES2.GL_PACK_ALIGNMENT, 4);
+ gl.glPixelStorei(GL2ES2.GL_UNPACK_ALIGNMENT, 4);
+ gl.glClearColor(sceneClearColor[0], sceneClearColor[1], sceneClearColor[2], sceneClearColor[3]);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+
+ render(gl, width, height,true);
+ ByteBuffer pixel = Buffers.newDirectByteBuffer(4);
+ pixel.order(ByteOrder.nativeOrder());
+ IntBuffer viewport = IntBuffer.allocate(4);
+ gl.glGetIntegerv(GL2ES2.GL_VIEWPORT, viewport);
+ gl.glReadPixels(x, viewport.get(3) - y, 1, 1, GL2ES2.GL_RGBA,
+ GL2ES2.GL_UNSIGNED_BYTE, pixel);
+
+ int qp = pixel.get(0) & 0xFF;
+ int index = Math.round(((qp/255.0f)*(count+2))-1);
+ if(index < 0 || index >= count)
+ return -1;
+ return index;
+ }
+
+ private void render(GL2ES2 gl, int width, int height, boolean select) {
+ renderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);
+
+ for(int index=0; index < count;index++){
+ if(select) {
+ float color= index+1;
+ renderer.setColorStatic(gl, color/(count+2), color/(count+2), color/(count+2));
+ }
+ float[] s = shapes.get(index).getScale();
+ float[] p = shapes.get(index).getPosition();
+ renderer.resetModelview(null);
+ renderer.translate(null, translate[0]+p[0], translate[1]+p[1], translate[2]+p[2]);
+ renderer.scale(gl, s[0], s[1], s[2]);
+ renderer.rotate(gl, rotation[0], 1, 0, 0);
+ renderer.rotate(gl, rotation[1], 0, 1, 0);
+ renderer.rotate(gl, rotation[2], 0, 0, 1);
+
+ shapes.get(index).render(gl, rs, renderer,select);
+ renderer.rotate(gl, -rotation[0], 1, 0, 0);
+ renderer.rotate(gl, -rotation[1], 0, 1, 0);
+ renderer.rotate(gl, -rotation[2], 0, 0, 1);
+ }
+ }
+
+ public void setTranslate(float x, float y, float z) {
+ this.translate[0] = x;
+ this.translate[1] = y;
+ this.translate[2] = z;
+ }
+
+ public void setScale(float x, float y, float z) {
+ this.scale[0] = x;
+ this.scale[1] = y;
+ this.scale[2] = z;
+ }
+
+ public void setRotation(float x, float y, float z) {
+ this.rotation[0] = x;
+ this.rotation[1] = y;
+ this.rotation[2] = z;
+ }
+ public float[] getSceneClearColor() {
+ return sceneClearColor;
+ }
+
+ public void setSceneClearColor(float r, float g, float b, float a) {
+ this.sceneClearColor[0] = r;
+ this.sceneClearColor[1] = g;
+ this.sceneClearColor[2] = b;
+ this.sceneClearColor[3] = a;
+ }
+
+ private class SBCMouseListener implements MouseListener {
+ int lx = 0;
+ int ly = 0;
+ boolean selection = false;
+ int mouseX = -1;
+ int mouseY = -1;
+
+ public void mouseClicked(MouseEvent e) {
+ UIShape uiShape = getActiveUI();
+ if(uiShape != null){
+ uiShape.onClick();
+ }
+ }
+
+ public void mousePressed(MouseEvent e) {
+ selection = true;
+ mouseX = e.getX();
+ mouseY = e.getY();
+
+ GLRunnable runnable = new GLRunnable() {
+ public boolean run(GLAutoDrawable drawable) {
+ UIShape s = getShape(drawable, mouseX, mouseY);
+ if(null != s) {
+ activeId = getShapes().indexOf(s);
+ }
+ else {
+ activeId = -1;
+ }
+ return false;
+ }
+ };
+ cDrawable.invoke(true, runnable);
+
+ UIShape uiShape = getActiveUI();
+
+ if(uiShape != null) {
+ uiShape.setPressed(true);
+ uiShape.onPressed();
+ }
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ UIShape uiShape = getActiveUI();
+ if(uiShape != null){
+ uiShape.setPressed(false);
+ uiShape.onRelease();
+ }
+ }
+
+ public void mouseMoved(MouseEvent e) { }
+ public void mouseEntered(MouseEvent e) { }
+ public void mouseExited(MouseEvent e) { }
+ public void mouseDragged(MouseEvent e) { }
+ public void mouseWheelMoved(MouseEvent e) { }
+
+ }
+} \ No newline at end of file
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 2ae7d1f30..6768eccca 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
@@ -51,7 +51,16 @@ public class UIGLListener01 extends UIListenerBase01 {
super(RegionRenderer.create(rs, 0), debug, trace);
setMatrix(-20, 00, 0f, -50);
final Font font = FontFactory.get(FontFactory.UBUNTU).getDefault();
- button = new RIButton(SVertex.factory(), font, "Click me!", 4f, 3f);
+ button = new RIButton(SVertex.factory(), font, "Click me!", 4f, 3f){
+ public void onClick() {
+ }
+ public void onPressed() {
+ }
+ public void onRelease() {
+ }
+
+ };
+ button.setPosition(2,1,0);
/** Button defaults !
button.setLabelColor(1.0f,1.0f,1.0f);
button.setButtonColor(0.6f,0.6f,0.6f);
@@ -99,7 +108,7 @@ public class UIGLListener01 extends UIListenerBase01 {
regionRenderer.setColorStatic(gl, bColor[0], bColor[1], bColor[2]);
regionRenderer.draw(gl, regionButton.getRegion(gl, rs, 0), getPosition(), 0);
-
+// regionRenderer.translate(gl, button.getPosition()[0], button.getPosition()[1], button.getPosition()[2]);
regionRenderer.setColorStatic(gl, lColor[0], lColor[1], lColor[2]);
regionRenderer.draw(gl, regionLabel.getRegion(gl, rs, 0), getPosition(), 0);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java
index b89f87be4..0fe48e550 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java
@@ -281,7 +281,7 @@ public abstract class UIListenerBase01 implements GLEventListener {
else if(arg0.getKeyCode() == KeyEvent.VK_V) {
if(null != autoDrawable) {
autoDrawable.invoke(false, new GLRunnable() {
- public void run(GLAutoDrawable drawable) {
+ public boolean run(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
int i = gl.getSwapInterval();
i = i==0 ? 1 : 0;
@@ -291,6 +291,7 @@ public abstract class UIListenerBase01 implements GLEventListener {
a.resetFPSCounter();
}
System.err.println("Swap Interval: "+i);
+ return true;
}
});
}
@@ -299,7 +300,7 @@ public abstract class UIListenerBase01 implements GLEventListener {
rotate(-1);
if(null != autoDrawable) {
autoDrawable.invoke(false, new GLRunnable() {
- public void run(GLAutoDrawable drawable) {
+ public boolean run(GLAutoDrawable drawable) {
try {
final String type = ( 1 == rRenderer.getRenderModes() ) ? "r2t0-msaa1" : "r2t1-msaa0" ;
printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false);
@@ -308,7 +309,8 @@ public abstract class UIListenerBase01 implements GLEventListener {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
- }
+ }
+ return true;
}
});
}
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 7e3d26775..ebed0f7aa 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
@@ -27,7 +27,11 @@
*/
package com.jogamp.opengl.test.junit.graph.demos.ui;
+import javax.media.opengl.GL2ES2;
+
import com.jogamp.graph.curve.OutlineShape;
+import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.geom.AABBox;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
@@ -38,6 +42,8 @@ public abstract class UIShape {
protected static final int DIRTY_SHAPE = 1 << 0 ;
protected int dirty = DIRTY_SHAPE;
+
+ private boolean down = false;
public UIShape(Factory<? extends Vertex> factory) {
this.vertexFactory = factory;
@@ -48,6 +54,39 @@ public abstract class UIShape {
clearImpl();
shape.clear();
}
+
+ public abstract void render(GL2ES2 gl, RenderState rs, RegionRenderer renderer, boolean selection);
+
+ protected boolean positionDirty = false;
+
+ private float[] position = new float[]{0,0,0};
+ private float[] scale = new float[]{1.0f,1.0f,1.0f};
+ public void setScale(float x, float y, float z){
+ scale[0] = x;
+ scale[1] = y;
+ scale[2] = z;
+ }
+
+ public void setPosition(float x, float y, float z) {
+ this.position[0] = x;
+ this.position[1] = y;
+ this.position[2] = z;
+ positionDirty = true;
+ }
+
+ private void updatePosition () {
+ float minX = shape.getBounds().getLow()[0];
+ float minY = shape.getBounds().getLow()[1];
+ float minZ = shape.getBounds().getLow()[2];
+ System.out.println("Position was: " + (position[0]) + " " + (position[1]) + " " + (position[2]));
+ System.out.println("Position became: " + (position[0] - minX) + " " + (position[1] - minY) + " " + (position[2] - minZ));
+ setPosition(position[0] - minX, position[1] - minY, position[2] - minZ);
+ positionDirty = false;
+ }
+
+ public float[] getScale() { return scale; }
+ public float[] getPosition() { return position; }
+
protected abstract void clearImpl();
protected abstract void createShape();
@@ -56,6 +95,9 @@ public abstract class UIShape {
if( isShapeDirty() ) {
shape.clear();
createShape();
+ if(positionDirty){
+ updatePosition();
+ }
dirty &= ~DIRTY_SHAPE;
return true;
}
@@ -73,4 +115,16 @@ public abstract class UIShape {
public boolean isShapeDirty() {
return 0 != ( dirty & DIRTY_SHAPE ) ;
}
+
+ public void setPressed(boolean b) {
+ this.down = b;
+ }
+
+ public boolean isPressed() {
+ return this.down;
+ }
+
+ public abstract void onClick();
+ public abstract void onPressed();
+ public abstract void onRelease();
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java
index 9a6548dd4..afddb5676 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java
@@ -92,11 +92,12 @@ public class TestGLDebug01NEWT extends UITestCase {
Assert.assertEquals((null == glDebugExt) ? false : enable, ctx.isGLDebugMessageEnabled());
if(ctx.isGLDebugMessageEnabled() && null != dbgTstMsg && 0 <= dbgTstId) {
window.invoke(true, new GLRunnable() {
- public void run(GLAutoDrawable drawable) {
+ public boolean run(GLAutoDrawable drawable) {
drawable.getContext().glDebugMessageInsert(GL2GL3.GL_DEBUG_SOURCE_APPLICATION_ARB,
GL2GL3.GL_DEBUG_TYPE_OTHER_ARB,
dbgTstId,
GL2GL3.GL_DEBUG_SEVERITY_MEDIUM_ARB, dbgTstMsg);
+ return true;
}
});
Assert.assertEquals(true, myGLDebugListener.received());
@@ -128,8 +129,9 @@ public class TestGLDebug01NEWT extends UITestCase {
window.getContext().addGLDebugListener(myGLDebugListener);
window.invoke(true, new GLRunnable() {
- public void run(GLAutoDrawable drawable) {
+ public boolean run(GLAutoDrawable drawable) {
drawable.getGL().glBindFramebuffer(-1, -1); // ERROR !
+ return true;
}
} );
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java
index 620219dc7..1ca74774b 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/GLRunnableDummy.java
@@ -28,12 +28,6 @@
package com.jogamp.opengl.test.junit.newt.parenting;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.AfterClass;
-import org.junit.Test;
-
import javax.media.opengl.*;
public class GLRunnableDummy implements GLRunnable {
@@ -42,7 +36,7 @@ public class GLRunnableDummy implements GLRunnable {
float b=0.0f;
float d=0.1f;
- public void run(GLAutoDrawable drawable) {
+ public boolean run(GLAutoDrawable drawable) {
GL2ES1 gl = drawable.getGL().getGL2ES1();
gl.glClearColor(r, g, b, 1f);
r+=d;
@@ -53,5 +47,6 @@ public class GLRunnableDummy implements GLRunnable {
r=0f;
d*=-1f;
}
+ return true;
}
}