Class Shape

  • Direct Known Subclasses:
    GraphShape, Group

    public abstract class Shape
    extends Object
    Generic Shape, potentially using a Graph via GraphShape or other means of representing content.

    A shape includes the following build-in user-interactions - drag shape w/ 1-pointer click, see setDraggable(boolean) - resize shape w/ 1-pointer click and drag in 1/4th bottom-left and bottom-right corner, see setResizable(boolean).

    A shape is expected to have its 0/0 origin in its bottom-left corner, otherwise the drag-zoom sticky-edge will not work as expected.

    A shape's getBounds() includes its optional getPadding() and optional getBorderThickness().

    GraphUI is GPU based and resolution independent.

    GraphUI is intended to become an immediate- and retained-mode API.

    Default colors (toggle-off is full color): - non-toggle: 0.6 * color, static -> 0.6 - pressed: 0.8 * color, static -> 0.5 - toggle-off: 1.0 * color, static -> 0.6 - toggle-on: 0.8 * color

    See Also:
    Scene
    • Field Detail

      • ZAscendingComparator

        public static Comparator<Shape> ZAscendingComparator
      • ZDescendingComparator

        public static Comparator<Shape> ZDescendingComparator
    • Method Detail

      • getParent

        public Group getParent()
        Returns the last parent container Group this shape has been added to or null.

        Since a shape can be added to multiple container (DAG), usability of this information depends on usage.

      • setID

        public final Shape setID​(int id)
        Set a symbolic ID for this shape for identification. Default is -1 for noname.
      • getID

        public final int getID()
        Return the optional symbolic ID for this shape.
      • setName

        public Shape setName​(String name)
        Set a symbolic name for this shape for identification. Default is `noname`.
      • getName

        public final String getName()
        Return the optional symbolic name for this shape, defaults to `noname`.
      • isGroup

        public boolean isGroup()
        Returns true if this shape denotes a Group, otherwise false.
      • isVisible

        public final boolean isVisible()
        Returns true if this shape is set visible by the user, otherwise false. Defaults to true.

        Note that invisible shapes are not considered for picking/activation.

        See Also:
        isInteractive()
      • setVisible

        public final Shape setVisible​(boolean v)
        Enable (default) or disable this shape's visibility.

        Note that invisible shapes are not considered for picking/activation.

        This visibility flag is toggled by the user only.

      • hasBorder

        public final boolean hasBorder()
        Returns true if a border has been enabled via #setBorder(float, Padding).
      • getBorderThickness

        public final float getBorderThickness()
        Returns the border thickness, see #setBorder(float, Padding).
      • runSynced

        public final void runSynced​(Runnable action)
        Perform given Runnable action synchronized
      • clear

        public final void clear​(GL2ES2 gl,
                                RegionRenderer renderer)
        Clears all data and reset all states as if this instance was newly created
        Parameters:
        gl - current GL2ES2 instance used to release GPU resources
        renderer - RegionRenderer used to release GPU resources
      • destroy

        public final void destroy​(GL2ES2 gl,
                                  RegionRenderer renderer)
        Destroys all data
        Parameters:
        gl - current GL2ES2 instance used to release GPU resources
        renderer - RegionRenderer used to release GPU resources
      • onDraw

        public final void onDraw​(Shape.DrawListener l)
        Set a user one-shot initializer callback or custom draw(GL2ES2, RegionRenderer) hook.

        #run(Shape, GL2ES2, RegionRenderer) is called at draw(GL2ES2, RegionRenderer) and if returning true, the listener will be removed. Otherwise kept calling.

        This instrument allows the user either to be signaled when initialization of this Shape is completed, or just too hook-up custom draw(GL2ES2, RegionRenderer) actions.

        Parameters:
        l - callback, which shall return true to be removed, i.e. user initialization is done.
      • onHover

        public final void onHover​(Shape.PointerListener l)
        Set user callback to be notified when a pointer/mouse is moving over this shape
      • addActivationListener

        public final Shape addActivationListener​(Shape.Listener l)
        Add user callback to be notified when shape is activated (pointer-over and/or click) or de-activated (pointer left).

        Use isActive() to retrieve the state.

      • moveTo

        public final Shape moveTo​(float tx,
                                  float ty,
                                  float tz)
        Move to scaled position. Position ends up in PMVMatrix4f unmodified. No Shape.MoveListener notification will occur.
      • moveTo

        public final Shape moveTo​(com.jogamp.math.Vec3f t)
        Move to scaled position. Position ends up in PMVMatrix4f unmodified. No Shape.MoveListener notification will occur.
      • move

        public final Shape move​(float dtx,
                                float dty,
                                float dtz)
        Move about scaled distance. Position ends up in PMVMatrix4f unmodified. No Shape.MoveListener notification will occur.
      • move

        public final Shape move​(com.jogamp.math.Vec3f dt)
        Move about scaled distance. Position ends up in PMVMatrix4f unmodified. No Shape.MoveListener notification will occur.
      • getRotation

        public final com.jogamp.math.Quaternion getRotation()
        Returns Quaternion for rotation.
      • setRotation

        public final Shape setRotation​(com.jogamp.math.Quaternion q)
        Sets the rotation Quaternion.
        Returns:
        this shape for chaining
      • setRotationPivot

        public final Shape setRotationPivot​(float px,
                                            float py,
                                            float pz)
        Set unscaled rotation origin, aka pivot. Usually the getBounds() center and should be set while validateImpl(GL2ES2, GLProfile).
        Returns:
        this shape for chaining
      • setRotationPivot

        public final Shape setRotationPivot​(com.jogamp.math.Vec3f pivot)
        Set unscaled rotation origin, aka pivot. Usually the getBounds() center and should be set while validateImpl(GL2ES2, GLProfile).
        Parameters:
        pivot - rotation origin
        Returns:
        this shape for chaining
      • setScale

        public final Shape setScale​(com.jogamp.math.Vec3f s)
        Set scale factor to given scale.
        See Also:
        scale(Vec3f), getScale()
      • markShapeDirty

        public final void markShapeDirty()
        Marks the shape dirty, causing next draw() to recreate the Graph shape and reset the region.
      • markStateDirty

        public final void markStateDirty()
        Marks the rendering state dirty, causing next draw() to notify the Graph region to reselect shader and repaint potentially used FBOs.
      • getBounds

        public final com.jogamp.math.geom.AABBox getBounds()
        Returns the unscaled bounding AABBox for this shape, borrowing internal instance. The returned AABBox will cover the unscaled shape as well as its optional getPadding() and optional getBorderThickness(). The returned AABBox is only valid after an initial call to draw(..) or validate(GL2ES2).
        See Also:
        getBounds(GLProfile)
      • getScaledWidth

        public final float getScaledWidth()
        Returns the scaled width of the bounding AABBox for this shape. The returned width will cover the scaled shape as well as its optional scaled getPadding() and optional scaled getBorderThickness(). The returned width is only valid after an initial call to draw(..) or validate(GL2ES2).
        See Also:
        getBounds()
      • getScaledHeight

        public final float getScaledHeight()
        Returns the scaled height of the bounding AABBox for this shape. The returned height will cover the scaled shape as well as its optional scaled getPadding() and optional scaled getBorderThickness(). The returned height is only valid after an initial call to draw(..) or validate(GL2ES2).
        See Also:
        getBounds()
      • getScaledDepth

        public final float getScaledDepth()
      • getBounds

        public final com.jogamp.math.geom.AABBox getBounds​(GLProfile glp)
        Returns the unscaled bounding AABBox for this shape. This variant differs from getBounds() as it returns a valid AABBox even before draw(..) and having an OpenGL instance available.
        See Also:
        getBounds()
      • drawToSelect

        public void drawToSelect​(GL2ES2 gl,
                                 RegionRenderer renderer)
        Experimental selection draw command used by Scene.
      • validate

        public final Shape validate​(GL2ES2 gl)
        Validates the shape's underlying GLRegion.

        If the region is dirty, it gets cleared and is reused.

        Parameters:
        gl - current GL2ES2 object
        See Also:
        validate(GLProfile)
      • validate

        public final Shape validate​(GLProfile glp)
        Validates the shape's underlying GLRegion w/o a current GL2ES2 object

        If the region is dirty a new region is created and the old one gets pushed to a dirty-list to get disposed when a GL context is available.

        See Also:
        validate(GL2ES2)
      • applyMatToMv

        public final void applyMatToMv​(com.jogamp.math.util.PMVMatrix4f pmv)
        Applies the internal Matrix4f to the given modelview matrix, i.e. pmv.mulMv( getMat() ).

        Calls updateMat() if dirty.

        In case isMatIdentity() is true, implementation is a no-operation.

        Parameters:
        pmv - the matrix
        See Also:
        isMatIdentity(), updateMat(), getMat(), PMVMatrix4f.mulMv(Matrix4f)
      • isMatIdentity

        public final boolean isMatIdentity()
        Returns true if getMat() has not been mutated, i.e. contains identity.
        See Also:
        updateMat()
      • getSurfacePort

        public final com.jogamp.math.Recti getSurfacePort​(com.jogamp.math.util.PMVMatrix4f pmv,
                                                          com.jogamp.math.Recti viewport,
                                                          com.jogamp.math.Recti surfacePort)
        Retrieve surface (view) port of this shape, i.e. lower x/y position and size.

        The given PMVMatrix4f has to be setup properly for this object, i.e. its GLMatrixFunc.GL_PROJECTION and GLMatrixFunc.GL_MODELVIEW for the surrounding scene including this shape's applyMatToMv(PMVMatrix4f). See setPMVMatrix(Scene, PMVMatrix4f).

        Parameters:
        pmv - well formed PMVMatrix4f, e.g. could have been setup via setPMVMatrix(Scene, PMVMatrix4f).
        viewport - the int[4] viewport
        surfacePort - Recti target surface port
        Returns:
        given Recti surfacePort for successful gluProject(..) operation, otherwise null
      • shapeToWinCoord

        public final int[] shapeToWinCoord​(com.jogamp.math.util.PMVMatrix4f pmv,
                                           com.jogamp.math.Recti viewport,
                                           com.jogamp.math.Vec3f objPos,
                                           int[] glWinPos)
        Map given object coordinate relative to this shape to window coordinates.

        The given PMVMatrix4f has to be setup properly for this object, i.e. its GLMatrixFunc.GL_PROJECTION and GLMatrixFunc.GL_MODELVIEW for the surrounding scene including this shape's applyMatToMv(PMVMatrix4f). See setPMVMatrix(Scene, PMVMatrix4f).

        Parameters:
        pmv - well formed PMVMatrix4f, e.g. could have been setup via setPMVMatrix(Scene, PMVMatrix4f).
        viewport - the viewport
        objPos - object position relative to this shape's center
        glWinPos - int[2] target window position of objPos relative to this shape
        Returns:
        given int[2] glWinPos for successful gluProject(..) operation, otherwise null
        See Also:
        #shapeToWinCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, float[], PMVMatrix4f, int[]), #shapeToWinCoord(Scene, float[], PMVMatrix4f, int[])
      • shapeToWinCoord

        public final int[] shapeToWinCoord​(Scene.PMVMatrixSetup pmvMatrixSetup,
                                           com.jogamp.math.Recti viewport,
                                           com.jogamp.math.Vec3f objPos,
                                           com.jogamp.math.util.PMVMatrix4f pmv,
                                           int[] glWinPos)
        Map given object coordinate relative to this shape to window coordinates.

        The given PMVMatrix4f will be setup properly for this shape including this shape's applyMatToMv(PMVMatrix4f).

        Parameters:
        pmvMatrixSetup - Scene.PMVMatrixSetup to setup given PMVMatrix4f pmv.
        viewport - used viewport for PMVMatrix4f.mapObjToWin(Vec3f, Recti, Vec3f)
        objPos - object position relative to this shape's center
        pmv - a new PMVMatrix4f which will be setup, shape-transformed and can be reused by the caller.
        glWinPos - int[2] target window position of objPos relative to this shape
        Returns:
        given int[2] glWinPos for successful gluProject(..) operation, otherwise null
        See Also:
        #shapeToWinCoord(PMVMatrix4f, Recti, float[], int[]), #shapeToWinCoord(Scene, float[], PMVMatrix4f, int[])
      • shapeToWinCoord

        public final int[] shapeToWinCoord​(Scene scene,
                                           com.jogamp.math.Vec3f objPos,
                                           com.jogamp.math.util.PMVMatrix4f pmv,
                                           int[] glWinPos)
        Map given object coordinate relative to this shape to window coordinates.

        The given PMVMatrix4f will be setup properly for this shape including this shape's applyMatToMv(PMVMatrix4f).

        Parameters:
        scene - Scene to retrieve Scene.PMVMatrixSetup and the viewport.
        objPos - object position relative to this shape's center
        pmv - a new PMVMatrix4f which will be setup, shape-transformed and can be reused by the caller.
        glWinPos - int[2] target window position of objPos relative to this shape
        Returns:
        given int[2] glWinPos for successful gluProject(..) operation, otherwise null
        See Also:
        #shapeToWinCoord(PMVMatrix4f, Recti, float[], int[]), #shapeToWinCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, float[], PMVMatrix4f, int[])
      • winToShapeCoord

        public final com.jogamp.math.Vec3f winToShapeCoord​(com.jogamp.math.util.PMVMatrix4f pmv,
                                                           com.jogamp.math.Recti viewport,
                                                           int glWinX,
                                                           int glWinY,
                                                           com.jogamp.math.Vec3f objPos)
        Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate.

        The given PMVMatrix4f has to be setup properly for this object, i.e. its GLMatrixFunc.GL_PROJECTION and GLMatrixFunc.GL_MODELVIEW for the surrounding scene including this shape's applyMatToMv(PMVMatrix4f). See setPMVMatrix(Scene, PMVMatrix4f).

        Parameters:
        pmv - well formed PMVMatrix4f, e.g. could have been setup via setPMVMatrix(Scene, PMVMatrix4f).
        viewport - the Rect4i viewport
        glWinX - in GL window coordinates, origin bottom-left
        glWinY - in GL window coordinates, origin bottom-left
        objPos - target object position of glWinX/glWinY relative to this shape
        Returns:
        given objPos for successful gluProject(..) and gluUnProject(..) operation, otherwise null
        See Also:
        #winToShapeCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, int, int, PMVMatrix4f, float[]), #winToShapeCoord(Scene, int, int, PMVMatrix4f, float[])
      • winToShapeCoord

        public final com.jogamp.math.Vec3f winToShapeCoord​(Scene.PMVMatrixSetup pmvMatrixSetup,
                                                           com.jogamp.math.Recti viewport,
                                                           int glWinX,
                                                           int glWinY,
                                                           com.jogamp.math.util.PMVMatrix4f pmv,
                                                           com.jogamp.math.Vec3f objPos)
        Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate.

        The given PMVMatrix4f will be setup properly for this shape including this shape's applyMatToMv(PMVMatrix4f).

        Parameters:
        pmvMatrixSetup - Scene.PMVMatrixSetup to setup given PMVMatrix4f pmv.
        viewport - used viewport for PMVMatrix4f.mapWinToObj(float, float, float, Recti, Vec3f)
        glWinX - in GL window coordinates, origin bottom-left
        glWinY - in GL window coordinates, origin bottom-left
        pmv - a new PMVMatrix4f which will be setup, shape-transformed and can be reused by the caller.
        objPos - target object position of glWinX/glWinY relative to this shape
        Returns:
        given objPos for successful gluProject(..) and gluUnProject(..) operation, otherwise null
        See Also:
        #winToShapeCoord(PMVMatrix4f, Recti, int, int, float[]), #winToShapeCoord(Scene, int, int, PMVMatrix4f, float[])
      • winToShapeCoord

        public final com.jogamp.math.Vec3f winToShapeCoord​(Scene scene,
                                                           int glWinX,
                                                           int glWinY,
                                                           com.jogamp.math.util.PMVMatrix4f pmv,
                                                           com.jogamp.math.Vec3f objPos)
        Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate.

        The given PMVMatrix4f will be setup properly for this shape including this shape's applyMatToMv(PMVMatrix4f).

        Parameters:
        scene - Scene to retrieve Scene.PMVMatrixSetup and the viewport.
        glWinX - in GL window coordinates, origin bottom-left
        glWinY - in GL window coordinates, origin bottom-left
        pmv - a new PMVMatrix4f which will be setup, shape-transformed and can be reused by the caller.
        objPos - target object position of glWinX/glWinY relative to this shape
        Returns:
        given objPos for successful gluProject(..) and gluUnProject(..) operation, otherwise null
        See Also:
        #winToShapeCoord(PMVMatrix4f, Recti, int, int, float[]), #winToShapeCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, int, int, PMVMatrix4f, float[])
      • getPressedColorMod

        public final com.jogamp.math.Vec4f getPressedColorMod()
        Returns modulation color when isPressed().
      • getToggleOnColorMod

        public final com.jogamp.math.Vec4f getToggleOnColorMod()
        Returns modulation color when isToggleOn().
      • getToggleOffColorMod

        public final com.jogamp.math.Vec4f getToggleOffColorMod()
        Returns modulation color when not isToggleOn().
      • getActiveColorMod

        public final com.jogamp.math.Vec4f getActiveColorMod()
        Returns modulation color when isActive().
      • setColor

        public Shape setColor​(float r,
                              float g,
                              float b,
                              float a)
        Set base color.

        Base color w/o color channel, will be modulated w/ pressed- and toggle color

        Default RGBA value is 0.60f, 0.60f, 0.60f, 1.0f

        Method issues markShapeDirty().

        See Also:
        markShapeDirty()
      • setColor

        public Shape setColor​(com.jogamp.math.Vec4f c)
        Set base color.

        Default base-color w/o color channel, will be modulated w/ pressed- and toggle color

        Default RGBA value is 0.60f, 0.60f, 0.60f, 1.0f

        Method issues markShapeDirty().

        See Also:
        markShapeDirty()
      • setPressedColorMod

        public Shape setPressedColorMod​(float r,
                                        float g,
                                        float b,
                                        float a)
        Set pressed color, modulating getColor() if isPressed().

        Default pressed color, modulation -factor w/o color channel, modulated base-color. ~0.65 (due to alpha)

        Default RGBA value is 0.70f, 0.70f, 0.70f, 0.8f

      • setToggleOnColorMod

        public final Shape setToggleOnColorMod​(float r,
                                               float g,
                                               float b,
                                               float a)
        Set toggle-on color, modulating getColor() if isToggleOn() and setToggleable(boolean)

        Default toggle-on color-factor w/o color channel, modulated base-color. 0.60 * 0.83 ~= 0.50

        Default RGBA value is 0.83f, 0.83f, 0.83f, 1.0f

      • setToggleOffColorMod

        public final Shape setToggleOffColorMod​(float r,
                                                float g,
                                                float b,
                                                float a)
        Set toggle-off color, modulating getColor() if !isToggleOn() and setToggleable(boolean)

        Default toggle-off color-factor w/o color channel, modulated base-color. 0.60 * 1.00 ~= 0.60

        Default RGBA value is 1.00f, 1.00f, 1.00f, 1.0f

      • setActiveColorMod

        public final Shape setActiveColorMod​(com.jogamp.math.Vec4f c)
        Enable active color, modulation getColor() if isActive() with passing c != null, disable with passing c == null.

        Default active color-factor w/o color channel, modulated base-color. 0.60 * 0.25 ~= 0.15

        Default is disabled.

      • getBorderColor

        public final com.jogamp.math.Vec4f getBorderColor()
      • getSubString

        public String getSubString()
      • setPressed

        public final Shape setPressed​(boolean b)
      • isPressed

        public final boolean isPressed()
      • setToggleable

        public final Shape setToggleable​(boolean toggleable)
        Set this shape toggleable, default is off.
        Parameters:
        toggleable -
        See Also:
        isInteractive()
      • setToggle

        public final Shape setToggle​(boolean v)
        Set this shape's toggle state, default is off.
        Parameters:
        v -
        Returns:
      • toggle

        public final Shape toggle()
      • isToggleOn

        public final boolean isToggleOn()
        Returns true this shape's toggle state.
      • isActive

        public final boolean isActive()
        Returns true of this shape is active
      • getAdjustedZ

        public final float getAdjustedZ()
      • setToolTip

        public Tooltip setToolTip​(Tooltip newTooltip)
        Set's a new Tooltip for this shape.

        The Shape must be set interactive to receive the mouse-over signal, i.e. being picked.

      • removeToolTip

        public void removeToolTip()
      • getTooltip

        public Tooltip getTooltip()
      • setActivable

        public final Shape setActivable​(boolean v)
        Set whether this shape is allowed to be activated, i.e become isActive().

        A non activable shape still allows a shape to be dragged or resized, it just can't gain the main focus.

      • isActivable

        public final boolean isActivable()
        Returns if this shape is allowed to be activated, i.e become isActive().
      • setDiscarded

        public final Shape setDiscarded​(boolean v)
        Set whether this shape is discarded in last draw(GL2ES2, RegionRenderer), i.e. culled via frustum or occlusion criteria.
      • isDiscarded

        public final boolean isDiscarded()
        Returns whether this shape is discarded in last draw(GL2ES2, RegionRenderer), i.e. culled via frustum or occlusion criteria.
      • isDraggable

        public final boolean isDraggable()
        Returns if this shape is draggable, a user interaction.
        See Also:
        setDraggable(boolean)
      • isResizable

        public final boolean isResizable()
        Returns if this shape is resizable, a user interaction.
        See Also:
        setResizable(boolean)
      • hasColorChannel

        public abstract boolean hasColorChannel()
        Returns true if implementation uses an extra color channel or texture which will be modulated with the passed rgba color #drawImpl0(GL2ES2, RegionRenderer, float[]). Otherwise the base color will be modulated and passed to #drawImpl0(GL2ES2, RegionRenderer, float[]).