diff options
author | Sven Gothel <[email protected]> | 2023-02-15 06:58:54 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-02-15 06:58:54 +0100 |
commit | 8d598ac75213a7d298b2633bf5d84b215339769e (patch) | |
tree | e57c676204f6901689030af6bb38916cf0ad9fb2 /src/test/com/jogamp/opengl | |
parent | f8d23faf8655453c65ccc0262697676ca47e91c1 (diff) |
Graph: TextRegionUtil: Make addStringToRegion(..) versatile/usable w/ optional AffineTransform (see Label0)
Diffstat (limited to 'src/test/com/jogamp/opengl')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label0.java | 31 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java | 36 |
2 files changed, 22 insertions, 45 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label0.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label0.java index c30c75959..5cf0f9af5 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label0.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label0.java @@ -27,8 +27,8 @@ */ package com.jogamp.opengl.test.junit.graph.demos.ui; -import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.TextRegionUtil; import com.jogamp.graph.font.Font; import com.jogamp.graph.geom.plane.AffineTransform; import com.jogamp.opengl.math.geom.AABBox; @@ -37,13 +37,11 @@ public class Label0 { protected Font font; protected String text; protected final float[] rgbaColor; - protected final AABBox box; public Label0(final Font font, final String text, final float[] rgbaColor) { this.font = font; this.text = text; this.rgbaColor = rgbaColor; - this.box = new AABBox(); } public final String getText() { return text; } @@ -67,31 +65,10 @@ public class Label0 { this.font = font; } - public final AABBox getBounds() { return box; } - - private final float[] tmpV3 = new float[3]; - private final AffineTransform tempT1 = new AffineTransform(); - private final AffineTransform tempT2 = new AffineTransform(); - - private final OutlineShape.Visitor shapeVisitor = new OutlineShape.Visitor() { - @Override - public void visit(final OutlineShape shape, final AffineTransform t) { - region.addOutlineShape(shape, t, rgbaColor); - box.resize(shape.getBounds(), t, tmpV3); - } - }; - - private Region region; - - public final AABBox addShapeToRegion(final float pixelSize, final Region region, final AffineTransform tLeft) { - box.reset(); - this.region = region; + public final AABBox addShapeToRegion(final float scale, final Region region, final AffineTransform tLeft) { final AffineTransform t_sxy = new AffineTransform(tLeft); - final AffineTransform tmp = new AffineTransform(); - t_sxy.scale(pixelSize, pixelSize, tmp); - font.processString(shapeVisitor, t_sxy, text, tempT1, tempT2); - this.region = null; - return box; + t_sxy.scale(scale, scale, new AffineTransform()); + return TextRegionUtil.addStringToRegion(region, font, t_sxy, text, rgbaColor); } @Override diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java index db1ec239a..4d62cb2b1 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java @@ -47,7 +47,7 @@ public class LabelButton extends RoundButton { /** {@value} */ public static final float DEFAULT_SPACING_Y = 0.40f; - private static final float DEFAULT_2PASS_LABEL_ZOFFSET = -0.05f; + private static final float DEFAULT_2PASS_LABEL_ZOFFSET = -0.005f; // -0.05f; private final Label0 label; private float spacingX = DEFAULT_SPACING_X; @@ -64,6 +64,8 @@ public class LabelButton extends RoundButton { setToggleOnColorMod(0.85f, 0.85f, 0.85f, 1.0f); } + public Font getFont() { return label.font; } + @Override public void drawShape(final GL2ES2 gl, final RegionRenderer renderer, final int[] sampleCount) { if( false ) { @@ -91,35 +93,33 @@ public class LabelButton extends RoundButton { box.resize(shape.getBounds()); // Precompute text-box size .. guessing pixelSize - final float lPixelSize0 = 10f; final float lw = width * ( 1f - spacingX ) ; final float lh = height * ( 1f - spacingY ) ; - final AABBox lbox0_em = label.font.getMetricBounds(label.text); + final AABBox lbox0_em = label.font.getPointsBounds(null, label.text); final float lsx = lw / lbox0_em.getWidth(); final float lsy = lh / lbox0_em.getHeight(); - final float lPixelSize1 = lsx < lsy ? lsx : lsy; - if( DRAW_DEBUG_BOX ) { - final AABBox lbox0_px = new AABBox(lbox0_em).scale2(lPixelSize0, new float[3]); - System.err.println("RIButton: dim "+width+" x "+height+", spacing "+spacingX+", "+spacingY); - System.err.println("RIButton: net-text "+lw+" x "+lh+" px"); - System.err.println("RIButton: shape "+box+" px"); - System.err.println("RIButton: text "+lbox0_em+" em, "+label.text); - System.err.println("RIButton: text "+lbox0_px+" px, "+label.text); - System.err.println("RIButton: lscale "+lsx+" x "+lsy+": pixelSize "+lPixelSize0+" -> "+lPixelSize1); - } + final float lScale = lsx < lsy ? lsx : lsy; // Setting left-corner transform using text-box in font em-size [0..1] - final AABBox lbox1_s = label.font.getPointsBounds(null, label.text).scale2(lPixelSize1, new float[3]); + final AABBox lbox1_s = new AABBox(lbox0_em).scale2(lScale, new float[3]); // Center text .. (share same center w/ button) final float[] lctr = lbox1_s.getCenter(); final float[] ctr = box.getCenter(); final float[] ltx = new float[] { ctr[0] - lctr[0], ctr[1] - lctr[1], 0f }; - final AABBox lbox2 = label.addShapeToRegion(lPixelSize1, region, tempT1.setToTranslation(ltx[0], ltx[1])); if( DRAW_DEBUG_BOX ) { - System.err.printf("RIButton.0: tleft %f / %f, %f / %f%n", ltx[0], ltx[1], ltx[0] * lPixelSize1, ltx[1] * lPixelSize1); - System.err.printf("RIButton.0: lbox1 %s scaled%n", lbox1_s); - System.err.printf("RIButton.0: lbox2 %s%n", lbox2); + System.err.println("RIButton: dim "+width+" x "+height+", spacing "+spacingX+", "+spacingY); + System.err.println("RIButton: net-text "+lw+" x "+lh); + System.err.println("RIButton: shape "+box); + System.err.println("RIButton: text_em "+lbox0_em+" em, "+label.text); + System.err.println("RIButton: lscale "+lsx+" x "+lsy+" -> "+lScale); + System.err.printf ("RIButton: text_s %s%n", lbox1_s); + System.err.printf ("RIButton: tleft %f / %f, %f / %f%n", ltx[0], ltx[1], ltx[0] * lScale, ltx[1] * lScale); + } + + final AABBox lbox2 = label.addShapeToRegion(lScale, region, tempT1.setToTranslation(ltx[0], ltx[1])); + if( DRAW_DEBUG_BOX ) { + System.err.printf("RIButton.X: lbox2 %s%n", lbox2); } setRotationOrigin( ctr[0], ctr[1], ctr[2]); |