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.BoxLayout;
41import com.jogamp.graph.ui.layout.GridLayout;
42import com.jogamp.graph.ui.shapes.Label;
43import com.jogamp.graph.ui.shapes.Rectangle;
44import com.jogamp.math.FloatUtil;
45import com.jogamp.math.Vec3f;
46import com.jogamp.math.Vec4f;
47import com.jogamp.math.geom.AABBox;
48import com.jogamp.math.geom.plane.AffineTransform;
49import com.jogamp.newt.event.WindowAdapter;
50import com.jogamp.newt.event.WindowEvent;
51import com.jogamp.newt.opengl.GLWindow;
52import com.jogamp.opengl.GL;
53import com.jogamp.opengl.GLCapabilities;
54import com.jogamp.opengl.GLProfile;
55import com.jogamp.opengl.demos.graph.ui.util.Tooltips;
56import com.jogamp.opengl.demos.util.CommandlineOptions;
57import com.jogamp.opengl.util.Animator;
59import jogamp.graph.ui.TreeTool;
72 static boolean reLayout =
true;
73 static final int reLayoutSleep = 500;
75 private static final Vec4f groupBorderColor =
new Vec4f(0, 0, 1f, 0.6f);
76 private static final float borderThickness = 0.01f;
78 public static void main(
final String[] args)
throws IOException {
79 if( 0 != args.length ) {
80 final int[] idx = { 0 };
81 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
82 if( options.
parse(args, idx) ) {
84 }
else if (args[idx[0]].equals(
"-no_relayout")) {
89 System.err.println(options);
92 System.out.println(
"Requested: " + reqCaps);
105 public void windowDestroyNotify(
final WindowEvent e) {
111 final int zBits = 16;
116 System.err.println(
"Z16-Precision: current "+scene.
getZEpsilon(zBits));
125 animator.
add(window);
136 System.err.println(
"SceneBox "+sceneBox+
", zEps "+zEps);
138 final float cellGapX = sceneBox.
getWidth() / 6f;
139 final float cellGapY = sceneBox.
getHeight() * 0.40f;
141 final float sxy = 1/12f * sceneBox.
getWidth();
146 final float minX = 0.00f, minY = 0.00f, width = 0.5f, height = 0.5f, lineWidth = 0.05f;
150 sxy, nextPos, cellGapX,
152 (
final Group gp) -> {
153 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
155 nextPos.
setX( nextPos.x() + cellGapX );
159 final float minX = 0.125f, minY = 0.125f, width = 0.5f, height = 0.5f, lineWidth = 0.05f;
163 sxy, nextPos, cellGapX,
165 (
final Group gp) -> {
166 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
168 nextPos.
setX( nextPos.x() + cellGapX );
173 sxy, nextPos, cellGapX,
175 (
final Group gp) -> {
176 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
178 nextPos.
setX( nextPos.x() + cellGapX );
183 sxy, nextPos, cellGapX,
185 (
final Group gp) -> {
186 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
188 nextPos.
setX( nextPos.x() + cellGapX );
193 sxy, nextPos, cellGapX,
195 (
final Group gp) -> {
196 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
198 nextPos.
setX( nextPos.x() + cellGapX );
206 nextPos.
set(0, nextPos.y() + cellGapY / 2f, 0 );
209 final float minX = 0.000f, minY = 0.000f, width = 0.5f, height = 0.5f, lineWidth = 0.05f;
213 sxy, nextPos, cellGapX,
215 (
final Group gp) -> {
216 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
217 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
218 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
220 nextPos.
setX( nextPos.x() + cellGapX );
224 final float minX = 0.125f, minY = 0.125f, width = 0.5f, height = 0.5f, lineWidth = 0.05f;
228 sxy, nextPos, cellGapX,
230 (
final Group gp) -> {
231 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
232 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
233 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
235 nextPos.
setX( nextPos.x() + cellGapX );
240 sxy, nextPos, cellGapX,
242 (
final Group gp) -> {
243 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
244 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
245 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
247 nextPos.
setX( nextPos.x() + cellGapX );
252 sxy, nextPos, cellGapX,
254 (
final Group gp) -> {
255 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
256 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
257 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
259 nextPos.
setX( nextPos.x() + cellGapX );
264 sxy, nextPos, cellGapX,
266 (
final Group gp) -> {
267 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
268 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
269 gp.addShape( new Rectangle(options.renderModes, minX, minY, width, height, lineWidth, 0).setDragAndResizable(false) );
271 nextPos.
setX( nextPos.x() + cellGapX );
276 nextPos.
set(0, nextPos.y() + cellGapY, 0 );
282 final String text =
" Press group description to magnify! ";
287 .scale(l_sxy, l_sxy, 1).moveTo(sceneDim.
getLow())
292 try { Thread.sleep(1000); }
catch (
final InterruptedException e1) { }
299 static interface GroupMod {
300 void mod(
Group group);
302 static Group setupGroup(
final Group g,
final GLProfile reqGLP,
final Scene scene,
final float zEps,
303 final float sxy,
final Vec3f nextPos,
final float cellGap,
304 final Font font,
final int id,
305 final GroupMod modImpl,
final float offX,
final float offY) {
306 final String suffix = String.format(
"%2d",
id);
308 final AABBox sceneBox = scene.getBounds();
310 g.setBorder(borderThickness).setBorderColor(groupBorderColor);
311 g.scale(sxy, sxy, 1);
312 g.setInteractive(
true);
314 g.moveTo(sceneBox.
getLow()).move(nextPos);
315 System.err.println(
"Group-"+suffix+
" "+g);
316 System.err.println(
"Group-"+suffix+
" Layout "+g.getLayout());
317 TreeTool.forAll(g, (shape) -> { System.err.println(
"Shape... "+shape);
return false; });
326 final String fixed_text =
"Gap[r 0.1, c 0.1], Align [CenterHoriz, CenterVert, Fi";
327 final float l_sxy = g.getScaledWidth() / font.
getGlyphBounds(fixed_text,
new AffineTransform(),
new AffineTransform()).
getWidth();
330 final Group.Layout l = g.getLayout();
331 if( l instanceof GridLayout ) {
332 final GridLayout gl = (GridLayout)l;
333 text = String.format(
"Grid %2d, off %.3f/%.3f, size[total %.1f x %.1f, cell %.1f x %.1f]%n%s%n%s, Align %s",
334 id, offX, offY, g.getBounds().getWidth(), g.getBounds().getHeight(), gl.getCellSize().x(), gl.getCellSize().y(),
335 (
null == gl.getPadding() || gl.getPadding().zeroSize() ) ?
"Padding none" : gl.getPadding().toString(),
336 gl.getGap().zeroSumSize() ?
"Gap none" : gl.getGap().toString(),
338 }
else if( l instanceof BoxLayout ){
339 final BoxLayout bl = (BoxLayout)l;
340 text = String.format(
"Box %2d, off %.3f/%.3f, size[total %.1f x %.1f, cell %.1f x %.1f]%n%s%n%s, Align %s",
341 id, offX, offY, g.getBounds().getWidth(), g.getBounds().getHeight(), bl.getCellSize().x(), bl.getCellSize().y(),
342 (
null == bl.getPadding() || bl.getPadding().zeroSize() ) ?
"Padding none" : bl.getPadding().toString(),
343 bl.getMargin().zeroSize() ?
"Margin none" : bl.getMargin().toString(),
346 text = String.format(
"Layout %2d, off %.3f/%.3f, size[total %.1f x %.1f",
id, offX, offY, g.getBounds().getWidth(), g.getBounds().getHeight());
348 final Shape label =
new Label(options.
renderModes, font, text).setColor(0, 0, 0, 1).validate(reqGLP);
349 label.scale(l_sxy, l_sxy, 1).moveTo(sceneBox.
getLow()).move(nextPos).move(l_sxy*X_width, g.getScaledHeight(), 0)
350 .addMouseListener(
new Tooltips.ZoomLabelOnClickListener(scene, options.
renderModes, 1/6f)).setDragAndResizable(
false);
351 scene.addShape(label);
354 try { Thread.sleep(reLayoutSleep); }
catch (
final InterruptedException e1) { }
357 System.err.println(
"Group-"+suffix+
".2 "+g);
358 System.err.println(
"Group-"+suffix+
" Layout.2 "+g.getLayout());
359 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:
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.
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 None
No alignment constant.
static final Alignment FillCenter
Bit#Fill, Bit#CenterHoriz and Bit#CenterVert alignment constant.
GraphUI Stack Group.Layout.
GraphUI Grid Group.Layout.
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.
3D Vector based upon three float components.
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.
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 with offset (not starting at origin) in a Group using BoxLayout and GridLayout...
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.
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...