aboutsummaryrefslogtreecommitdiffstats
path: root/src/demos
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-09-26 05:34:24 +0200
committerSven Gothel <[email protected]>2023-09-26 05:34:24 +0200
commit893903d2ece1193aa87257bd6162754dfb89f9f9 (patch)
treec3b96a3a489f3442000aac8aef2c4350ef2529f5 /src/demos
parent3025466c5c79ffb06c761dbfa380e643d562994a (diff)
GraphUI Button: Support toggle'ed labels and fixed font size scaling for symbols (see setFixedLabelSize()),
This allows convenient instantiation of a Button changing its text (or symbol) when toggled, e.g.: UISceneDemo03: + final Button button = new Button(options.renderModes, fontSymbols, + fontSymbols.getUTF16String("play_arrow"), fontSymbols.getUTF16String("pause"), + buttonWidth, buttonHeight, buttonZOffset); + button.setSpacing(symSpacing, fixedSymSize); +++ setFixedLabelSize(..): Sets fixed label font size clipped to range [0 .. 1], defaults to {@code 0, 0}. Use {@code w=0, h=1} when using single symbols from fixed sized symbol fonts! Use {@link #setSpacing(Vec2f, Vec2f)} to also set spacing. The fixed label font size is used as the denominator when scaling.{@code max(fixedLabelSize, fontLabelSize)}, hence reasonable values are either {@code 1} to enable using the given font-size for the axis or {@code 0} to scale up/down the font to match the button box less spacing for the axis.
Diffstat (limited to 'src/demos')
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java3
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java61
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java24
-rw-r--r--src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java8
4 files changed, 59 insertions, 37 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java
index 99d491ae8..36f7eb90e 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/FontView01.java
@@ -485,6 +485,7 @@ public class FontView01 {
final Font fontStatus, final Font fontInfo, final Shape.MouseGestureListener glyphMouseListener) {
gridDim.nextLine = Math.min(gridDim.start + gridDim.columns, gridDim.contourChars.size()-1);
gridDim.nextPage = Math.min(gridDim.start + gridDim.elemCount, gridDim.contourChars.size()-1);
+ final AABBox tmpBox = new AABBox();
for(int idx = gridDim.start; idx < gridDim.nextPage; ++idx) {
final char codepoint = gridDim.contourChars.get(idx);
final Font.Glyph fg = font.getGlyph(codepoint);
@@ -495,7 +496,7 @@ public class FontView01 {
// grid.addShape( g ); // GridLayout handles bottom-left offset and scale
// Group each GlyphShape with its bounding box Rectangle
- final AABBox gbox = fg.getBounds(); // g.getBounds(glp);
+ final AABBox gbox = fg.getBounds(tmpBox); // g.getBounds(glp);
final boolean addUnderline = showUnderline && gbox.getMinY() < 0f;
final Group c1 = new Group( new BoxLayout( 1f, 1f, addUnderline ? Alignment.None : Alignment.Center) );
c1.setBorder(0.02f).setBorderColor(0, 0, 0, 1).setInteractive(true).setDragAndResizeable(false);
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java
index 9e0ac22ff..061cc4de1 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java
@@ -52,6 +52,7 @@ import com.jogamp.graph.ui.shapes.Label;
import com.jogamp.graph.ui.shapes.Rectangle;
import com.jogamp.math.FloatUtil;
import com.jogamp.math.Quaternion;
+import com.jogamp.math.Vec2f;
import com.jogamp.math.Vec3f;
import com.jogamp.math.Vec4f;
import com.jogamp.math.geom.AABBox;
@@ -605,28 +606,37 @@ public class UISceneDemo03 {
final float buttonWidth = sceneBox.getWidth() * 0.09f;
final float buttonHeight = buttonWidth / 3.0f;
+ final float buttonZOffset = scene.getZEpsilon(16);
+ final Vec2f fixedSymSize = new Vec2f(0.0f, 1.0f);
+ final Vec2f symSpacing = new Vec2f(0f, 0.2f);
buttonsRight.setLayout(new GridLayout(buttonWidth, buttonHeight, Alignment.Fill, new Gap(buttonHeight*0.50f, buttonWidth*0.10f), 7));
{
- final Button button = new Button(options.renderModes, fontSymbols, " "+fontSymbols.getUTF16String("pause")+" ", buttonWidth, buttonHeight); // pause
- button.setToggleable(true);
- button.addMouseListener(new Shape.MouseGestureAdapter() {
- @Override
- public void mouseClicked(final MouseEvent e) {
- animGroup.setTickPaused ( !animGroup.getTickPaused() );
- System.err.println("Tick Paused: "+animGroup.getTickPaused());
+ final Button button = new Button(options.renderModes, fontSymbols,
+ fontSymbols.getUTF16String("play_arrow"), fontSymbols.getUTF16String("pause"),
+ buttonWidth, buttonHeight, buttonZOffset);
+ button.setSpacing(symSpacing, fixedSymSize);
+ button.onToggle((final Shape s) -> {
+ System.err.println("Play/Pause "+s);
+ animGroup.setTickPaused ( s.isToggleOn() );
+ if( s.isToggleOn() ) {
+ animGroup.setTickPaused ( false );
if( null != mPlayer ) {
- if( animGroup.getTickPaused() ) {
- mPlayer.pause(false);
- } else {
- mPlayer.resume();
- }
+ mPlayer.resume();
}
- } } );
+ } else {
+ animGroup.setTickPaused ( true );
+ if( null != mPlayer ) {
+ mPlayer.pause(false);
+ }
+ }
+ });
+ button.setToggle(true); // on == play
buttonsRight.addShape(button);
}
{
- final Button button = new Button(options.renderModes, fontSymbols, " "+fontSymbols.getUTF16String("fast_forward")+" ", buttonWidth, buttonHeight); // next (ffwd)
+ final Button button = new Button(options.renderModes, fontSymbols, fontSymbols.getUTF16String("fast_forward"), buttonWidth, buttonHeight, buttonZOffset); // next (ffwd)
+ button.setSpacing(symSpacing, fixedSymSize);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
@@ -638,17 +648,18 @@ public class UISceneDemo03 {
buttonsRight.addShape(button);
}
{
- final Button button = new Button(options.renderModes, fontSymbols, " "+fontSymbols.getUTF16String("replay")+" ", buttonWidth, buttonHeight); // rotate (replay)
+ final Button button = new Button(options.renderModes, fontSymbols,
+ fontSymbols.getUTF16String("rotate_right"), fontSymbols.getUTF16String("stop_circle"),
+ buttonWidth, buttonHeight, buttonZOffset); // rotate (replay)
+ button.setSpacing(symSpacing, fixedSymSize);
button.setToggleable(true);
- button.addMouseListener(new Shape.MouseGestureAdapter() {
- @Override
- public void mouseClicked(final MouseEvent e) {
- animGroup.toggle();
- } } );
+ button.onToggle((final Shape s) -> {
+ animGroup.toggle();
+ });
buttonsRight.addShape(button);
}
{
- final Button button = new Button(options.renderModes, fontButtons, " < Rot > ", buttonWidth, buttonHeight);
+ final Button button = new Button(options.renderModes, fontButtons, " < Rot > ", buttonWidth, buttonHeight, buttonZOffset);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
@@ -668,7 +679,7 @@ public class UISceneDemo03 {
buttonsRight.addShape(button);
}
{
- final Button button = new Button(options.renderModes, fontButtons, " < Velo > ", buttonWidth, buttonHeight);
+ final Button button = new Button(options.renderModes, fontButtons, " < Velo > ", buttonWidth, buttonHeight, buttonZOffset);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
@@ -687,7 +698,8 @@ public class UISceneDemo03 {
buttonsRight.addShape(button);
}
{
- final Button button = new Button(options.renderModes, fontSymbols, " "+fontSymbols.getUTF16String("camera")+" ", buttonWidth, buttonHeight); // snapshot (camera)
+ final Button button = new Button(options.renderModes, fontSymbols, fontSymbols.getUTF16String("camera"), buttonWidth, buttonHeight, buttonZOffset); // snapshot (camera)
+ button.setSpacing(symSpacing, fixedSymSize);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
@@ -697,7 +709,8 @@ public class UISceneDemo03 {
buttonsRight.addShape(button);
}
{
- final Button button = new Button(options.renderModes, fontSymbols, " "+fontSymbols.getUTF16String("power_settings_new")+" ", buttonWidth, buttonHeight); // exit (power_settings_new)
+ final Button button = new Button(options.renderModes, fontSymbols, fontSymbols.getUTF16String("power_settings_new"), buttonWidth, buttonHeight, buttonZOffset); // exit (power_settings_new)
+ button.setSpacing(symSpacing, fixedSymSize);
button.setColor(0.7f, 0.3f, 0.3f, 1.0f);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java
index e25ea15a6..beda2d528 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java
@@ -57,6 +57,7 @@ import com.jogamp.graph.ui.shapes.ImageButton;
import com.jogamp.graph.ui.shapes.Label;
import com.jogamp.graph.ui.shapes.MediaButton;
import com.jogamp.math.FloatUtil;
+import com.jogamp.math.Vec2f;
import com.jogamp.math.Vec3f;
import com.jogamp.math.geom.AABBox;
import com.jogamp.math.util.PMVMatrix4f;
@@ -335,7 +336,7 @@ public class UISceneDemo20 implements GLEventListener {
for(final Shape s : sl) {
if( s instanceof Button ) {
final Button lb = (Button) s;
- final float sx = lb.getSpacingX()+dx, sy = lb.getSpacingY()+dy;
+ final float sx = lb.getSpacing().x()+dx, sy = lb.getSpacing().y()+dy;
System.err.println("Spacing: X "+sx+", Y "+sy);
lb.setSpacing(sx, sy);
}
@@ -476,9 +477,12 @@ public class UISceneDemo20 implements GLEventListener {
buttonsRight.setLayout(new GridLayout(1, buttonRWidth, buttonRHeight, Alignment.Fill, new Gap(buttonLHeight*0.50f, buttonLWidth*0.10f)));
System.err.println("Button Size: "+buttonLWidth+" x "+buttonLHeight);
+ final Vec2f fixedSymSize = new Vec2f(0.0f, 1.0f);
+ final Vec2f symSpacing = new Vec2f(0f, 0.2f);
BaseButton button;
- button = new Button(renderModes, fontSymbols, " "+fontSymbols.getUTF16String("fast_forward")+" ", buttonLWidth, buttonLHeight); // next (ffwd)
+ button = new Button(renderModes, fontSymbols, fontSymbols.getUTF16String("fast_forward"), buttonLWidth, buttonLHeight); // next (ffwd)
+ ((Button)button).setSpacing(symSpacing, fixedSymSize);
button.setName(BUTTON_NEXTTEXT);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
@@ -533,7 +537,7 @@ public class UISceneDemo20 implements GLEventListener {
button.addMouseListener(dragZoomRotateListener);
buttonsLeft.addShape(button);
- button = new Button(renderModes, fontButtons, "< Tilt >", buttonLWidth, buttonLHeight);
+ button = new Button(renderModes, fontButtons, " < Tilt > ", buttonLWidth, buttonLHeight);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
@@ -595,7 +599,8 @@ public class UISceneDemo20 implements GLEventListener {
buttonsLeft.addShape(button);
}
- button = new Button(renderModes, fontSymbols, " "+fontSymbols.getUTF16String("power_settings_new")+" ", buttonLWidth, buttonLHeight); // exit (power_settings_new)
+ button = new Button(renderModes, fontSymbols, fontSymbols.getUTF16String("power_settings_new"), buttonLWidth, buttonLHeight); // exit (power_settings_new)
+ ((Button)button).setSpacing(symSpacing, fixedSymSize);
button.setName(BUTTON_QUIT);
button.setColor(0.7f, 0.3f, 0.3f, 1.0f);
((Button)button).setLabelColor(1.2f, 1.2f, 1.2f);
@@ -610,7 +615,8 @@ public class UISceneDemo20 implements GLEventListener {
// second column to the left
{
- button = new Button(renderModes, fontSymbols, " "+fontSymbols.getUTF16String("flip")+" ", buttonLWidth, buttonLHeight); // Y Flip (flip)
+ button = new Button(renderModes, fontSymbols, fontSymbols.getUTF16String("flip"), buttonLWidth, buttonLHeight); // Y Flip (flip)
+ ((Button)button).setSpacing(symSpacing, fixedSymSize);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
@@ -619,7 +625,7 @@ public class UISceneDemo20 implements GLEventListener {
button.addMouseListener(dragZoomRotateListener);
buttonsLeft.addShape(button);
- button = new Button(renderModes, fontButtons, "X Flip", buttonLWidth, buttonLHeight);
+ button = new Button(renderModes, fontButtons, " X Flip ", buttonLWidth, buttonLHeight);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
@@ -666,7 +672,8 @@ public class UISceneDemo20 implements GLEventListener {
} } );
buttonsLeft.addShape(button);
- button = new Button(renderModes, fontSymbols, " "+fontSymbols.getUTF16String("undo")+" ", buttonLWidth, buttonLHeight); // reset (undo)
+ button = new Button(renderModes, fontSymbols, fontSymbols.getUTF16String("undo"), buttonLWidth, buttonLHeight); // reset (undo)
+ ((Button)button).setSpacing(symSpacing, fixedSymSize);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
@@ -675,7 +682,8 @@ public class UISceneDemo20 implements GLEventListener {
button.addMouseListener(dragZoomRotateListener);
buttonsLeft.addShape(button);
- button = new Button(renderModes, fontSymbols, " "+fontSymbols.getUTF16String("camera")+" ", buttonLWidth, buttonLHeight); // snapshot (camera)
+ button = new Button(renderModes, fontSymbols, fontSymbols.getUTF16String("camera"), buttonLWidth, buttonLHeight); // snapshot (camera)
+ ((Button)button).setSpacing(symSpacing, fixedSymSize);
button.addMouseListener(new Shape.MouseGestureAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java
index 124a9aeda..dc36f9fbb 100644
--- a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java
+++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java
@@ -487,12 +487,12 @@ public class UIShapeDemo01 implements GLEventListener {
button.move(button.getWidth()/10f, 0f, 0f);
}
else if(arg0.getKeyCode() == KeyEvent.VK_4){
- button.setSpacing(button.getSpacingX()-0.01f, button.getSpacingY()-0.005f);
- System.err.println("Button Spacing: " + button.getSpacingX());
+ button.setSpacing(button.getSpacing().x()-0.01f, button.getSpacing().y()-0.005f);
+ System.err.println("Button Spacing: " + button.getSpacing());
}
else if(arg0.getKeyCode() == KeyEvent.VK_5){
- button.setSpacing(button.getSpacingX()+0.01f, button.getSpacingY()+0.005f);
- System.err.println("Button Spacing: " + button.getSpacingX());
+ button.setSpacing(button.getSpacing().x()+0.01f, button.getSpacing().y()+0.005f);
+ System.err.println("Button Spacing: " + button.getSpacing());
}
else if(arg0.getKeyCode() == KeyEvent.VK_6){
button.setCorner(button.getCorner()-0.01f);