28package com.jogamp.opengl.demos.graph.ui;
30import java.io.IOException;
31import java.util.ArrayList;
34import com.jogamp.graph.curve.Region;
35import com.jogamp.graph.font.Font;
36import com.jogamp.graph.font.FontFactory;
37import com.jogamp.graph.font.FontSet;
38import com.jogamp.graph.ui.Group;
39import com.jogamp.graph.ui.Scene;
40import com.jogamp.graph.ui.Shape;
41import com.jogamp.graph.ui.layout.Alignment;
42import com.jogamp.graph.ui.layout.BoxLayout;
43import com.jogamp.graph.ui.layout.Margin;
44import com.jogamp.graph.ui.layout.Padding;
45import com.jogamp.graph.ui.shapes.Button;
46import com.jogamp.graph.ui.shapes.Label;
47import com.jogamp.math.FloatUtil;
48import com.jogamp.math.Vec3f;
49import com.jogamp.math.Vec4f;
50import com.jogamp.math.geom.AABBox;
51import com.jogamp.math.geom.plane.AffineTransform;
52import com.jogamp.graph.ui.shapes.BaseButton;
53import com.jogamp.newt.event.MouseEvent;
54import com.jogamp.newt.event.WindowAdapter;
55import com.jogamp.newt.event.WindowEvent;
56import com.jogamp.newt.opengl.GLWindow;
57import com.jogamp.opengl.GL;
58import com.jogamp.opengl.GLAutoDrawable;
59import com.jogamp.opengl.GLCapabilities;
60import com.jogamp.opengl.GLProfile;
61import com.jogamp.opengl.demos.graph.ui.util.Tooltips;
62import com.jogamp.opengl.demos.util.CommandlineOptions;
63import com.jogamp.opengl.util.Animator;
65import jogamp.graph.ui.TreeTool;
77 static boolean reLayout =
true;
78 static final int reLayoutSleep = 500;
80 public static void main(
final String[] args)
throws IOException {
81 if( 0 != args.length ) {
82 final int[] idx = { 0 };
83 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
84 if( options.
parse(args, idx) ) {
86 }
else if (args[idx[0]].equals(
"-no_relayout")) {
91 System.err.println(options);
94 System.out.println(
"Requested: " + reqCaps);
107 public void windowDestroyNotify(
final WindowEvent e) {
113 final int zBits = 16;
118 System.err.println(
"Z16-Precision: current "+scene.
getZEpsilon(zBits));
127 animator.
add(window);
136 public void mouseWheelMoved(
final MouseEvent e) {
138 final Shape shape = shapeEvent.shape;
141 final float tmp = rot.x(); rot.
setX( rot.y() ); rot.
setY( tmp );
154 System.err.println(
"SceneBox "+sceneBox+
", zEps "+zEps);
156 final float cellGap = 1.5f;
157 final float sxy = 1/8.5f * sceneBox.
getWidth();
158 System.err.println(
"Scale xy "+sxy);
160 final List<Group> groups =
new ArrayList<Group>();
165 fillDemoScene(groups, reqCaps.
getGLProfile(), scene, zEps, sxy, nextPos, cellGap,
166 new Margin(0.04f, 0.04f, 0.10f, 0.10f),
167 new Padding(0.03f, 0.03f, 0.07f, 0.07f), font, dragZoomRotateListener);
170 try { Thread.sleep(reLayoutSleep); }
catch (
final InterruptedException e1) { }
172 for(
final Group g : groups) {
173 System.err.println(
"Group["+idx+
"].2.0 "+g);
174 System.err.println(
"Group["+idx+
"].2.0 "+g.getLayout());
177 System.err.println(
"Group["+idx+
"].2.1 "+g);
178 System.err.println(
"Group["+idx+
"].2.1 "+g.getLayout());
183 try { Thread.sleep(1000); }
catch (
final InterruptedException e1) { }
187 for(
final Group g : groups) {
188 System.err.println(
"Group["+idx+
"].2.0 "+g);
189 System.err.println(
"Group["+idx+
"].2.0 "+g.getLayout());
202 nextPos.
set(0, 0, 0);
204 fillDemoScene(groups, reqCaps.
getGLProfile(), scene, zEps, sxy, nextPos, cellGap,
206 new Padding(0.10f, 0.10f), font, dragZoomRotateListener);
209 try { Thread.sleep(reLayoutSleep); }
catch (
final InterruptedException e1) { }
211 for(
final Group g : groups) {
212 System.err.println(
"Group["+idx+
"].2.0 "+g);
213 System.err.println(
"Group["+idx+
"].2.0 "+g.getLayout());
216 System.err.println(
"Group["+idx+
"].2.1 "+g);
217 System.err.println(
"Group["+idx+
"].2.1 "+g.getLayout());
222 try { Thread.sleep(1000); }
catch (
final InterruptedException e1) { }
226 for(
final Group g : groups) {
227 System.err.println(
"Group["+idx+
"].3.0 "+g);
228 System.err.println(
"Group["+idx+
"].3.0 "+g.getLayout());
238 @SuppressWarnings(
"unused")
239 static
void fillDemoScene(final List<
Group> groups, final
GLProfile reqGLP, final
Scene scene,
240 final
float zEps, final
float sxy, final
Vec3f nextPos, final
float cellGap,
242 final
Font font, final
Shape.MouseGestureListener dragZoomRotateListener)
251 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
254 nextPos.setX( nextPos.x() + sxy * cellGap );
259 final Group g = fillDemoGroup(
new Group(
new BoxLayout( padding ) ),
260 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
263 nextPos.setX( nextPos.x() + sxy * cellGap );
268 final Group g = fillDemoGroup(
new Group(
new BoxLayout(1f, 1f, Alignment.None) ),
269 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
272 nextPos.setX( nextPos.x() + sxy * cellGap );
277 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, margin ) ),
278 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
281 nextPos.setX( nextPos.x() + sxy * cellGap );
286 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, padding ) ),
287 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
290 nextPos.setX( nextPos.x() + sxy * cellGap );
295 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, margin, padding ) ),
296 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
300 nextPos.set(0, nextPos.y() + sxy * cellGap, 0);
307 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f,
new Alignment(Alignment.Bit.CenterHoriz) ) ),
308 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
311 nextPos.setX( nextPos.x() + sxy * cellGap );
315 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f,
new Alignment(Alignment.Bit.CenterVert) ) ),
316 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
319 nextPos.setX( nextPos.x() + sxy * cellGap );
323 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, Alignment.Center ) ),
324 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
327 nextPos.setX( nextPos.x() + sxy * cellGap );
331 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, Alignment.Fill ) ),
332 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
335 nextPos.setX( nextPos.x() + sxy * cellGap );
339 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, Alignment.FillCenter ) ),
340 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
344 nextPos.setX( nextPos.x() + sxy * cellGap );
347 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, Alignment.FillCenter, margin,
null ) ),
348 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
351 nextPos.set(0, nextPos.y() + sxy * cellGap, 0);
359 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, Alignment.Center, margin,
null ) ),
360 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
363 nextPos.setX( nextPos.x() + sxy * cellGap );
367 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, Alignment.Center, Margin.None, padding ) ),
368 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
371 nextPos.setX( nextPos.x() + sxy * cellGap );
375 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, Alignment.Center, margin, padding ) ),
376 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
379 nextPos.setX( nextPos.x() + sxy * cellGap );
383 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, Alignment.Fill, margin,
null ) ),
384 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
387 nextPos.setX( nextPos.x() + sxy * cellGap );
391 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, Alignment.Fill, margin, padding ) ),
392 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
395 nextPos.setX( nextPos.x() + sxy * cellGap );
399 final Group g = fillDemoGroup(
new Group(
new BoxLayout( 1f, 1f, Alignment.FillCenter, margin, padding ) ),
400 reqGLP, scene, zEps, sxy, nextPos, font,
id, dragZoomRotateListener);
404 nextPos.set(0, nextPos.y() + sxy * cellGap, 0);
407 final AABBox sceneDim = scene.getBounds();
408 final String text =
" Press group description to magnify! ";
409 final AABBox textDim = font.getGlyphBounds(text,
new AffineTransform(),
new AffineTransform());
410 final float l_sxy = 1/4f * sceneDim.getWidth() / textDim.getWidth();
412 final Shape label =
new Label(options.
renderModes, font, text).setColor(0, 0, 0, 1).setInteractive(
false)
413 .scale(l_sxy, l_sxy, 1).moveTo(sceneDim.getLow())
414 .move(0, sceneDim.getHeight() - textDim.getHeight()*l_sxy, 0);
415 scene.addShape(label);
419 private static final Vec4f groupBorderColor =
new Vec4f(0, 0, 1f, 0.6f);
420 private static final float borderThickness = 0.01f;
422 static Group fillDemoGroup(
final Group g,
final GLProfile reqGLP,
final Scene scene,
final float zEps,
final float sxy,
final Vec3f nextPos,
423 final Font font,
final int id,
424 final Shape.MouseGestureListener dragZoomRotateListener)
426 final String suffix = String.format(
"%2d",
id);
428 final AABBox sceneBox = scene.getBounds();
430 g.addShape(
new BaseButton(options.
renderModes, 0.70f, 0.70f).setPerp().setColor(0, 1, 0, 1).setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
431 g.addShape(
new Button(options.
renderModes, font,
"stack-"+suffix, 0.50f, 0.50f/2f, zEps).setPerp().move(0, 0, zEps).setInteractive(
false) );
432 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) );
434 g.scale(sxy, sxy, 1);
435 g.moveTo(sceneBox.getLow()).move(nextPos);
436 g.setBorder(borderThickness).setBorderColor(groupBorderColor);
438 System.err.println(
"Group-A"+suffix+
" "+g);
439 System.err.println(
"Group-A"+suffix+
" Layout "+g.getLayout());
440 TreeTool.forAll(g, (shape) -> { System.err.println(
"Shape... "+shape);
return false; });
443 final float X_width = font.getGlyph(
' ' ).getAdvanceWidth();
450 final String fixed_text =
"G 23, size[total 2.1 x 1.7, cell 1.0";
452 final float l_sxy = sxy / font.getGlyphBounds(fixed_text,
new AffineTransform(),
new AffineTransform()).getWidth();
454 final BoxLayout l = (BoxLayout)g.getLayout();
455 final String text = String.format(
"G %2d, size[total %.1f x %.1f, cell %.1f x %.1f]%n%s%n%s%nAlign %s",
456 id, g.getBounds().getWidth(), g.getBounds().getHeight(), l.getCellSize().x(), l.getCellSize().y(),
457 (
null == l.getPadding() || l.getPadding().zeroSize() ) ?
"Padding none" : l.getPadding().toString(),
458 l.getMargin().zeroSize() ?
"Margin none" : l.getMargin().toString(),
460 final Shape label =
new Label(options.
renderModes, font, text).setColor(0, 0, 0, 1).validate(reqGLP);
461 label.scale(l_sxy, l_sxy, 1).moveTo(sceneBox.getLow()).move(nextPos).move(l_sxy*X_width, g.getScaledHeight(), 0)
462 .addMouseListener(
new Tooltips.ZoomLabelOnClickListener(scene, options.
renderModes, 1/4f)).setDragAndResizable(
false);
463 scene.addShape(label);
464 System.err.println(
"ID "+
id+
": "+label);
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
The optional property jogamp.graph.font.ctor allows user to specify the FontConstructor implementatio...
static final FontSet get(final int font)
static final int UBUNTU
Ubuntu is the default font family, {@value}.
Group of Shapes, optionally utilizing a Group.Layout.
Default implementation of Scene.PMVMatrixSetup, implementing Scene.PMVMatrixSetup#set(PMVMatrix4f,...
final void setClearParams(final float[] clearColor, final int clearMask)
Sets the clear parameter for glClearColor(..) and glClear(..) to be issued at display(GLAutoDrawable)...
final void setPMvCullingEnabled(final boolean v)
Enable or disable Project-Modelview (PMv) frustum culling per Shape for this container.
void waitUntilDisplayed()
Blocks until first display(GLAutoDrawable) has completed after construction or dispose(GLAutoDrawable...
final void setPMVMatrixSetup(final PMVMatrixSetup setup)
Set a custom PMVMatrixSetup.
void removeAllShapes(final GL2ES2 gl, final RegionRenderer renderer)
Removes all contained shapes with Shape#destroy(GL2ES2, RegionRenderer).
static final float DEFAULT_Z16_EPSILON
Default Z precision on 16-bit depth buffer using DEFAULT_SCENE_DIST z-position and DEFAULT_ZNEAR.
static float getZEpsilon(final int zBits, final PMVMatrixSetup setup)
Default Z precision on 16-bit depth buffer using -1 z-position and DEFAULT_ZNEAR.
AABBox getBounds(final PMVMatrix4f pmv, final Shape shape)
Returns AABBox dimension of given Shape from this container's perspective, i.e.
synchronized void attachInputListenerTo(final GLWindow window)
File nextScreenshotFile(final String dir, final String prefix, final int renderModes, final GLCapabilitiesImmutable caps, final String contentDetail)
Return the unique next technical screenshot PNG File instance as follows:
Shape event info for propagated NEWTEvents containing reference of the intended shape as well as the ...
Convenient adapter combining dummy implementation for MouseListener and GestureListener.
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
final Quaternion getRotation()
Returns Quaternion for rotation.
final Shape setRotation(final Quaternion q)
Sets the rotation Quaternion.
GraphUI Stack Group.Layout.
GraphUI CSS property Margin, scaled space between or around elements and not included in the element'...
GraphUI CSS property Padding, unscaled space belonging to the element and included in the element's s...
Basic Float math utility functions.
static float getZBufferEpsilon(final int zBits, final float z, final float zNear)
Returns resolution of Z buffer of given parameter, see Love Your Z-Buffer.
static final float PI
The value PI, i.e.
final Quaternion rotateByEuler(final Vec3f angradXYZ)
Rotates this quaternion from the given Euler rotation array angradXYZ in radians.
3D Vector based upon three float components.
Vec3f scale(final float s)
this = this * s, returns this.
Vec3f set(final Vec3f o)
this = o, returns this.
Axis Aligned Bounding Box.
Pointer event of type PointerType.
final float[] getRotation()
Returns a 3-component float array filled with the values of the rotational axis in the following orde...
final Object getAttachment()
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void setTitle(final String title)
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
final GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
Specifies the the OpenGL profile.
Res independent Shapes in a Group using a BoxLayout, contained within a Scene attached to GLWindow.
static void main(final String[] args)
GLCapabilities getGLCaps()
int graphAASamples
Sample count for Graph Region AA render-modes: Region#VBAA_RENDERING_BIT or Region#MSAA_RENDERING_BIT...
void parse(final String[] args)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
static final int FAMILY_LIGHT
Font family LIGHT, {@value}.
Font get(int family, int stylebits)
static final int STYLE_SERIF
SERIF style/family bit flag.
Interface wrapper for font implementation.
String getFullFamilyName()
Shall return the family and subfamily name, separated a dash.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
boolean invoke(boolean wait, GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all regis...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...