28package com.jogamp.graph.ui.shapes;
30import com.jogamp.opengl.GL2ES2;
31import com.jogamp.opengl.GLProfile;
32import com.jogamp.graph.curve.OutlineShape;
33import com.jogamp.graph.curve.Region;
34import com.jogamp.graph.curve.opengl.GLRegion;
35import com.jogamp.graph.curve.opengl.RegionRenderer;
36import com.jogamp.graph.curve.opengl.TextRegionUtil;
37import com.jogamp.graph.font.Font;
38import com.jogamp.graph.ui.GraphShape;
39import com.jogamp.graph.ui.Scene;
40import com.jogamp.graph.ui.Shape;
41import com.jogamp.math.FloatUtil;
42import com.jogamp.math.Vec2f;
43import com.jogamp.math.Vec3f;
44import com.jogamp.math.Vec4f;
45import com.jogamp.math.geom.AABBox;
46import com.jogamp.math.geom.plane.AffineTransform;
47import com.jogamp.opengl.util.texture.TextureSequence;
49import jogamp.graph.ui.shapes.Label0;
80 private float labelZOffset;
82 private final Label0 labelOff, labelOn;
83 private volatile Label0 labelNow;
85 private final Vec2f fixedLabelSize =
new Vec2f(0, 0);
117 final float width,
final float height,
final float zOffset) {
136 public Button(
final int renderModes,
final Font labelFont,
final CharSequence labelTextOff,
final CharSequence labelTextOn,
137 final float width,
final float height,
final float zOffset) {
139 this.labelZOffset = zOffset;
140 this.labelOff =
new Label0(labelFont, labelTextOff,
new Vec4f( 1.66f, 1.66f, 1.66f, 1.0f ));
141 this.labelNow = this.labelOff;
142 if(
null != labelTextOn ) {
143 this.labelOn =
new Label0(labelFont, labelTextOn,
new Vec4f( 1.66f, 1.66f, 1.66f, 1.0f ));
152 if(
null != labelOn ) {
166 public CharSequence
getText() {
return labelNow.getText(); }
174 super.draw(gl, renderer);
191 resetGLRegion(glp, gl,
null, vertIndexCount[0], vertIndexCount[1]);
196 final AABBox lbox0_em = labelNow.getFont().getGlyphBounds(labelNow.getText(), tempT1, tempT2);
197 final float lw =
box.
getWidth() * ( 1f - spacing.x() ) ;
198 final float lsx = lw / Math.max(fixedLabelSize.x(), lbox0_em.
getWidth());
199 final float lh =
box.
getHeight() * ( 1f - spacing.y() ) ;
200 final float lsy = lh / Math.max(fixedLabelSize.y(), lbox0_em.
getHeight());
201 final float lScale = lsx < lsy ? lsx : lsy;
208 final Vec2f ltxy =
new Vec2f(ctr.x() - lctr.x(), ctr.y() - lctr.y() );
211 System.err.println(
"Button: dim "+
width+
" x "+
height+
", spacing "+spacing+
", fixedLabelSize "+fixedLabelSize);
212 System.err.println(
"Button: text0_em "+lbox0_em+
" em, "+labelNow.getText());
213 System.err.println(
"Button: shape "+
box);
214 System.err.println(
"Button: text-space "+lw+
" x "+lh);
215 System.err.println(
"Button: lscale "+lsx+
" x "+lsy+
" -> "+lScale);
216 System.err.printf (
"Button: text0_s %s%n", lbox0_s);
217 System.err.printf (
"Button: ltxy %s, %f / %f%n", ltxy, ltxy.x() * lScale, ltxy.y() * lScale);
222 System.err.printf(
"Button.X: lbox3 %s%n", lbox3);
225 final AABBox lbox2 = labelNow.addShapeToRegion(lScale,
region, ltxy, tempT1, tempT2, tempT3);
228 System.err.printf(
"Button.X: lbox2 %s%n", lbox2);
229 System.err.printf(
"Button.X: shape %s%n",
box);
281 Math.max(0f, Math.min(1f, w)),
282 Math.max(0f, Math.min(1f, h)) );
302 Math.max(0f, Math.min(1f, spacingX)),
303 Math.max(0f, Math.min(1f, spacingY)) );
329 return labelNow.getColor();
335 if(
null != labelOn ) {
345 if(
null != labelOn ) {
354 if( !labelOff.getFont().equals(labelFont) ) {
358 if(
null != labelOn ) {
359 if( !labelOn.getFont().equals(labelFont) ) {
360 labelOn.setFont(labelFont);
369 if( !labelNow.getText().equals(labelText) ) {
378 if( !labelNow.getText().equals(labelText) || !labelNow.getFont().equals(labelFont) ) {
388 final String onS =
null != labelOn ? ( labelOn + (labelNow == labelOn ?
"*" :
"" ) +
", " ) :
"";
389 final String offS = labelOff + (labelNow == labelOff ?
"*" :
"" ) +
", ";
390 final String flsS = fixedLabelSize.
isZero() ?
"" :
"fixedLabelSize["+fixedLabelSize+
"], ";
391 return super.getSubString()+
", "+ offS + onS +
"spacing["+spacing+
"], "+flsS+
"zOff "+labelZOffset;
A Generic shape objects which is defined by a list of Outlines.
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
final void addOutlineShape(final OutlineShape shape, final AffineTransform t, final Vec4f rgbaColor)
Add the given OutlineShape to this region with the given optional AffineTransform.
static final int COLORCHANNEL_RENDERING_BIT
Rendering-Mode bit for Region to optionally enable a color-channel per vertex.
static final int[] countOutlineShape(final OutlineShape shape, final int[] vertIndexCount)
Count required number of vertices and indices adding to given int[2] vertIndexCount array.
Text Type Rendering Utility Class adding the Font.Glyphs OutlineShape to a GLRegion.
static int[] countStringRegion(final Font font, final CharSequence str, final int[] vertIndexCount)
Count required number of vertices and indices adding to given int[2] vertIndexCount array.
final void resetGLRegion(final GLProfile glp, final GL2ES2 gl, final TextureSequence colorTexSeq, int vertexCount, int indexCount)
Reset the GLRegion and reserving its buffers to have a free capacity for vertexCount and indexCount e...
static void addRectangle(final Region region, final float sharpness, final AABBox box, final Padding padding, final float borderThickness, final Vec4f color)
Shape setColor(final float r, final float g, final float b, final float a)
Set base color.
static final boolean DEBUG_DRAW
final void markShapeDirty()
Marks the shape dirty, causing next draw() to recreate the Graph shape and reset the region.
final Vec4f rgbaColor
Default base-color w/o color channel, will be modulated w/ pressed- and toggle color.
final Shape setRotationPivot(final float px, final float py, final float pz)
Set unscaled rotation origin, aka pivot.
final Shape setToggleable(final boolean toggleable)
Set this shape toggleable, default is off.
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 boolean isZero(final float a, final float epsilon)
Returns true if value is zero, i.e.
2D Vector based upon two float components.
boolean isZero()
Return true if all components are zero, i.e.
void set(final Vec2f o)
this = o, returns this.
3D Vector based upon three float components.
4D Vector based upon four float components.
Axis Aligned Bounding Box.
final AABBox scale2(final float s)
Scale this AABBox by a constant, recomputing center.
final AABBox resize(final AABBox newBox)
Resize the AABBox to encapsulate another AABox.
final Vec3f getCenter()
Returns computed center of this AABBox of getLow() and getHigh().
Specifies the the OpenGL profile.
Interface wrapper for font implementation.