28package com.jogamp.opengl.demos.graph.ui;
30import java.io.IOException;
32import com.jogamp.graph.curve.Region;
33import com.jogamp.graph.font.Font;
34import com.jogamp.graph.font.FontFactory;
35import com.jogamp.graph.font.FontSet;
36import com.jogamp.graph.ui.Group;
37import com.jogamp.graph.ui.Scene;
38import com.jogamp.graph.ui.Shape;
39import com.jogamp.graph.ui.layout.Alignment;
40import com.jogamp.graph.ui.layout.Gap;
41import com.jogamp.graph.ui.layout.GridLayout;
42import com.jogamp.graph.ui.layout.Padding;
43import com.jogamp.graph.ui.shapes.Button;
44import com.jogamp.graph.ui.shapes.Label;
45import com.jogamp.math.FloatUtil;
46import com.jogamp.math.Vec3f;
47import com.jogamp.math.Vec4f;
48import com.jogamp.math.geom.AABBox;
49import com.jogamp.math.geom.plane.AffineTransform;
50import com.jogamp.newt.event.MouseEvent;
51import com.jogamp.newt.event.WindowAdapter;
52import com.jogamp.newt.event.WindowEvent;
53import com.jogamp.newt.opengl.GLWindow;
54import com.jogamp.opengl.GL;
55import com.jogamp.opengl.GLCapabilities;
56import com.jogamp.opengl.GLProfile;
57import com.jogamp.opengl.demos.graph.ui.util.Tooltips;
58import com.jogamp.opengl.demos.util.CommandlineOptions;
59import com.jogamp.opengl.util.Animator;
61import jogamp.graph.ui.TreeTool;
73 static boolean reLayout =
true;
74 static final int reLayoutSleep = 500;
76 private static final Vec4f groupBorderColor =
new Vec4f(0, 0, 1f, 0.6f);
77 private static final float borderThickness = 0.01f;
79 public static void main(
final String[] args)
throws IOException {
80 if( 0 != args.length ) {
81 final int[] idx = { 0 };
82 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
83 if( options.
parse(args, idx) ) {
85 }
else if (args[idx[0]].equals(
"-no_relayout")) {
90 System.err.println(options);
93 System.out.println(
"Requested: " + reqCaps);
106 public void windowDestroyNotify(
final WindowEvent e) {
112 final int zBits = 16;
117 System.err.println(
"Z16-Precision: current "+scene.
getZEpsilon(zBits));
126 animator.
add(window);
135 public void mouseWheelMoved(
final MouseEvent e) {
137 final Shape shape = shapeEvent.shape;
140 final float tmp = rot.x(); rot.
setX( rot.y() ); rot.
setY( tmp );
153 System.err.println(
"SceneBox "+sceneBox+
", zEps "+zEps);
155 final float cellGap = 1.1f;
157 final float sxy = 1/12f * sceneBox.
getWidth();
164 sxy, nextPos, cellGap,
166 (
final Group gp) -> {
167 gp.addShape( new Button(options.renderModes, font,
"ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
175 sxy, nextPos, cellGap,
177 (
final Group gp) -> {
178 gp.addShape( new Button(options.renderModes, font,
"ro co", 1f, 1/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
179 gp.addShape( new Button(options.renderModes, font,
"r1 r1", 1f, 1/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
187 sxy, nextPos, cellGap,
189 (
final Group gp) -> {
190 gp.addShape( new Button(options.renderModes, font,
"ro co", 1f, 1/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
191 gp.addShape( new Button(options.renderModes, font,
"r1 c1", 1f, 1/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
199 sxy, nextPos, cellGap,
201 (
final Group gp) -> {
202 gp.addShape( new Button(options.renderModes, font,
"ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
203 gp.addShape( new Button(options.renderModes, font,
"r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
204 gp.addShape( new Button(options.renderModes, font,
"r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
205 gp.addShape( new Button(options.renderModes, font,
"r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
213 sxy, nextPos, cellGap,
215 (
final Group gp) -> {
216 gp.addShape( new Button(options.renderModes, font,
"ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
217 gp.addShape( new Button(options.renderModes, font,
"r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
218 gp.addShape( new Button(options.renderModes, font,
"r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
219 gp.addShape( new Button(options.renderModes, font,
"r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
220 gp.addShape( new Button(options.renderModes, font,
"r3 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
228 sxy, nextPos, cellGap,
230 (
final Group gp) -> {
231 gp.addShape( new Button(options.renderModes, font,
"ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
232 gp.addShape( new Button(options.renderModes, font,
"r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
233 gp.addShape( new Button(options.renderModes, font,
"r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
234 gp.addShape( new Button(options.renderModes, font,
"r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
235 gp.addShape( new Button(options.renderModes, font,
"r3 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
243 nextPos.
set(0, nextPos.y() + sceneBox.
getHeight()/3f, 0 );
248 sxy, nextPos, cellGap,
250 (
final Group gp) -> {
251 gp.addShape( new Button(options.renderModes, font,
"ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
252 gp.addShape( new Button(options.renderModes, font,
"r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
253 gp.addShape( new Button(options.renderModes, font,
"r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
254 gp.addShape( new Button(options.renderModes, font,
"r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
255 gp.addShape( new Button(options.renderModes, font,
"r3 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
263 sxy, nextPos, cellGap,
265 (
final Group gp) -> {
266 gp.addShape( new Button(options.renderModes, font,
"ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
267 gp.addShape( new Button(options.renderModes, font,
"r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
268 gp.addShape( new Button(options.renderModes, font,
"r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
269 gp.addShape( new Button(options.renderModes, font,
"r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
270 gp.addShape( new Button(options.renderModes, font,
"r3 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
278 sxy, nextPos, cellGap,
280 (
final Group gp) -> {
281 gp.addShape( new Button(options.renderModes, font,
"ro co", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
282 gp.addShape( new Button(options.renderModes, font,
"r1 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
283 gp.addShape( new Button(options.renderModes, font,
"r2 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
284 gp.addShape( new Button(options.renderModes, font,
"r2 c2", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
285 gp.addShape( new Button(options.renderModes, font,
"r3 c1", 1f, 1f/2f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
291 final float bw = 0.5f, bh = bw/2f;
295 sxy, nextPos, cellGap,
297 (
final Group gp) -> {
298 gp.addShape( new Button(options.renderModes, font,
"ro co", bw, bh, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
299 gp.addShape( new Button(options.renderModes, font,
"r1 c2", bw, bh, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
300 gp.addShape( new Button(options.renderModes, font,
"r2 c1", bw, bh, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
301 gp.addShape( new Button(options.renderModes, font,
"r2 c2", bw, bh, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
302 gp.addShape( new Button(options.renderModes, font,
"r3 c1", bw, bh, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
307 final float bw = 0.5f, bh = bw/2f;
311 sxy, nextPos, cellGap,
313 (
final Group gp) -> {
314 gp.addShape( new Button(options.renderModes, font,
"ro co", bw, bh, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
315 gp.addShape( new Button(options.renderModes, font,
"r1 c2", bw, bh, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
316 gp.addShape( new Button(options.renderModes, font,
"r2 c1", bw, bh, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
317 gp.addShape( new Button(options.renderModes, font,
"r2 c2", bw, bh, zEps).setPerp().setBorder(borderThickness).addMouseListener(dragZoomRotateListener) );
318 gp.addShape( new Button(options.renderModes, font,
"r3 c1", bw, bh, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
324 nextPos.
set(0, nextPos.y() + sceneBox.
getHeight()/3f, 0 );
329 2*sxy, nextPos, cellGap,
331 (
final Group gp) -> {
332 final Group glyphGrid = new Group(new GridLayout(2, 0.3f, 0.3f, Alignment.Fill, new Gap(0.3f * 0.10f)));
333 glyphGrid.addShape( new Button(options.renderModes, font,
"0.0", 1f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
334 glyphGrid.addShape( new Button(options.renderModes, font,
"0.1", 1f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
335 glyphGrid.addShape( new Button(options.renderModes, font,
"1.0", 1f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
336 glyphGrid.addShape( new Button(options.renderModes, font,
"1.1", 1f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
337 gp.addShape(glyphGrid.setBorder(borderThickness));
339 final Group infoGrid = new Group(new GridLayout(1, 1/4f, 1/2.2f, Alignment.Fill, new Gap(0.02f)));
344 infoGrid.addShape(new Button(options.renderModes, font,
" S ", 1/2f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
349 infoGrid.addShape(new Button(options.renderModes, font,
" Info ", 1/2f, 1f, zEps).setPerp().setBorder(borderThickness).setDragAndResizable(false) );
350 gp.addShape(infoGrid.setBorder(borderThickness));
357 final float bw = 0.5f, bh = bw/2f;
360 sxy, nextPos, cellGap,
362 (
final Group gp) -> {
363 gp.addShape( new Button(options.renderModes, font,
"ro co", bw, bh, zEps).setPerp().setBorder(sxy*borderThickness).addMouseListener(dragZoomRotateListener) );
364 gp.addShape( new Button(options.renderModes, font,
"r1 c2", bw, bh, zEps).setPerp().setBorder(sxy*borderThickness).setDragAndResizable(false) );
365 gp.addShape( new Button(options.renderModes, font,
"r2 c1", bw, bh, zEps).setPerp().setBorder(sxy*borderThickness).setDragAndResizable(false) );
366 gp.addShape( new Button(options.renderModes, font,
"r2 c2", bw, bh, zEps).setPerp().setBorder(sxy*borderThickness).addMouseListener(dragZoomRotateListener) );
367 gp.addShape( new Button(options.renderModes, font,
"r3 c1", bw, bh, zEps).setPerp().setBorder(sxy*borderThickness).addMouseListener(dragZoomRotateListener) );
373 final String text =
" Press group description to magnify! ";
378 .scale(l_sxy, l_sxy, 1).moveTo(sceneDim.
getLow())
383 try { Thread.sleep(1000); }
catch (
final InterruptedException e1) { }
390 static interface GroupMod {
391 void mod(
Group group);
393 static Group setupGroup(
final Group g,
final GLProfile reqGLP,
final Scene scene,
final float zEps,
394 final float sxy,
final Vec3f nextPos,
final float cellGap,
395 final Font font,
final int id,
396 final GroupMod modImpl) {
397 final String suffix = String.format(
"%2d",
id);
399 final AABBox sceneBox = scene.getBounds();
401 g.setBorder(borderThickness).setBorderColor(groupBorderColor);
402 g.scale(sxy, sxy, 1);
403 g.setInteractive(
true);
405 g.moveTo(sceneBox.
getLow()).move(nextPos);
406 System.err.println(
"Group-"+suffix+
" "+g);
407 System.err.println(
"Group-"+suffix+
" Layout "+g.getLayout());
408 TreeTool.forAll(g, (shape) -> { System.err.println(
"Shape... "+shape);
return false; });
417 final String fixed_text =
"Gap[r 0.1, c 0.1], Align [CenterHoriz, CenterVert, Fi";
418 final float l_sxy = g.getScaledWidth() / font.
getGlyphBounds(fixed_text,
new AffineTransform(),
new AffineTransform()).
getWidth();
420 final GridLayout l = (GridLayout)g.getLayout();
421 final String text = String.format(
"G %2d, size[total %.1f x %.1f, cell %.1f x %.1f]%n%s%n%s, Align %s",
422 id, g.getBounds().getWidth(), g.getBounds().getHeight(), l.getCellSize().x(), l.getCellSize().y(),
423 (
null == l.getPadding() || l.getPadding().zeroSize() ) ?
"Padding none" : l.getPadding().toString(),
424 l.getGap().zeroSumSize() ?
"Gap none" : l.getGap().toString(),
426 final Shape label =
new Label(options.
renderModes, font, text).setColor(0, 0, 0, 1).validate(reqGLP);
427 label.scale(l_sxy, l_sxy, 1).moveTo(sceneBox.
getLow()).move(nextPos).move(l_sxy*X_width, g.getScaledHeight(), 0)
428 .addMouseListener(
new Tooltips.ZoomLabelOnClickListener(scene, options.
renderModes, 1/6f)).setDragAndResizable(
false);
429 scene.addShape(label);
432 try { Thread.sleep(reLayoutSleep); }
catch (
final InterruptedException e1) { }
435 System.err.println(
"Group-"+suffix+
".2 "+g);
436 System.err.println(
"Group-"+suffix+
" Layout.2 "+g.getLayout());
437 TreeTool.forAll(g, (shape) -> { System.err.println(
"Shape... "+shape);
return false; });
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,...
void addShape(final Shape s)
Adds a Shape.
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.
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.
Shape setColor(final float r, final float g, final float b, final float a)
Set base color.
final Shape setInteractive(final boolean v)
Set whether this shape is interactive in general, i.e.
final float getScaledWidth()
Returns the scaled width of the bounding AABBox for this shape.
final Quaternion getRotation()
Returns Quaternion for rotation.
final Shape setRotation(final Quaternion q)
Sets the rotation Quaternion.
Immutable layout alignment options, including Bit#Fill.
static final Alignment Fill
Bit#Fill alignment constant.
static final Alignment Center
Bit#CenterHoriz and Bit#CenterVert alignment constant.
static final Alignment FillCenter
Bit#Fill, Bit#CenterHoriz and Bit#CenterVert alignment constant.
GraphUI CSS property Gap, scaled spacing between (grid) cells not belonging to the cell element.
GraphUI Grid Group.Layout.
GraphUI CSS property Padding, unscaled space belonging to the element and included in the element's s...
A GraphUI text label GraphShape.
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.
4D Vector based upon four float components.
Axis Aligned Bounding Box.
final Vec3f getLow()
Returns the minimum left-bottom-far (xyz) coordinate.
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 GridLayout, 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.
CenterHoriz
Horizontal center alignment.
CenterVert
Vertical center alignment.
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.
float getAdvanceWidth()
Returns advance in font em-size [0..1], sourced from hmtx table.
Interface wrapper for font implementation.
Glyph getGlyph(final String name)
Returns the Glyph mapped to given name.
String getFullFamilyName()
Shall return the family and subfamily name, separated a dash.
AABBox getGlyphBounds(final CharSequence string)
Try using getGlyphBounds(CharSequence, AffineTransform, AffineTransform) to reuse AffineTransform ins...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
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...