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
    • Constructor Detail

      • Shape

        public Shape()
    • Method Detail

      • setName

        public final Shape setName​(int name)
        Set a symbolic name for this shape for identification. Default is -1 for noname.
      • getName

        public final int getName()
        Return the optional symbolic name for this shape.
      • isEnabled

        public final boolean isEnabled()
        Returns true if this shape is enabled and hence visible, otherwise false.
      • setEnabled

        public final Shape setEnabled​(boolean v)
        Enable or disable this shape, i.e. its visibility.
      • setPaddding

        public final Shape setPaddding​(Padding padding)
        Sets the padding for this shape, which is included in {@link #getBounds()B} and also includes the border. Default is zero. Method issues markShapeDirty().
        Parameters:
        padding - distance of shape to the border, i.e. padding
        Returns:
        this shape for chaining
        See Also:
        getPadding(), hasPadding()
      • setBorder

        public final Shape setBorder​(float thickness)
        Sets the thickness of the border, which is included in getBounds() and is outside of getPadding(). Default is zero for no border. Method issues markShapeDirty().
        Parameters:
        thickness - border thickness, zero for no border
        Returns:
        this shape for chaining
      • 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).
      • 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 - TODO
        renderer - TODO
      • destroy

        public final void destroy​(GL2ES2 gl,
                                  RegionRenderer renderer)
        Destroys all data
        Parameters:
        gl -
        renderer -
      • moveTo

        public final Shape moveTo​(float tx,
                                  float ty,
                                  float tz)
        Move to scaled position. Position ends up in PMVMatrix unmodified.
      • moveTo

        public final Shape moveTo​(Vec3f t)
        Move to scaled position. Position ends up in PMVMatrix unmodified.
      • move

        public final Shape move​(float dtx,
                                float dty,
                                float dtz)
        Move about scaled distance. Position ends up in PMVMatrix unmodified.
      • move

        public final Shape move​(Vec3f dt)
        Move about scaled distance. Position ends up in PMVMatrix unmodified.
      • getRotationPivot

        public final Vec3f getRotationPivot()
        Return unscaled rotation origin, aka pivot. Null if not set via getRotationPivot().
      • 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(GLProfile, GL2ES2).
        Returns:
        this shape for chaining
      • setRotationPivot

        public final Shape setRotationPivot​(Vec3f pivot)
        Set unscaled rotation origin, aka pivot. Usually the getBounds() center and should be set while validateImpl(GLProfile, GL2ES2).
        Parameters:
        pivot - rotation origin
        Returns:
        this shape for chaining
      • 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.
      • 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()
      • drawToSelect

        public void drawToSelect​(GL2ES2 gl,
                                 RegionRenderer renderer,
                                 int[] sampleCount)
        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)
      • shapeToWinCoord

        public int[] shapeToWinCoord​(PMVMatrix pmv,
                                     Recti viewport,
                                     Vec3f objPos,
                                     int[] glWinPos)
        Map given object coordinate relative to this shape to window coordinates.

        The given PMVMatrix 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 setTransform(PMVMatrix).

        Parameters:
        pmv - well formed PMVMatrix, e.g. could have been setup via setupMatrix(..) and setTransform(PMVMatrix).
        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[], PMVMatrix, int[]), #shapeToWinCoord(Scene, float[], PMVMatrix, int[])
      • shapeToWinCoord

        public int[] shapeToWinCoord​(Scene scene,
                                     Vec3f objPos,
                                     PMVMatrix pmv,
                                     int[] glWinPos)
        Map given object coordinate relative to this shape to window coordinates.

        The given PMVMatrix will be setup properly for this shape including this shape's setTransform(PMVMatrix).

        Parameters:
        scene - Scene to retrieve Scene.PMVMatrixSetup and the viewport.
        objPos - object position relative to this shape's center
        pmv - a new PMVMatrix 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(PMVMatrix, Recti, float[], int[]), #shapeToWinCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, float[], PMVMatrix, int[])
      • winToShapeCoord

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

        The given PMVMatrix 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 setTransform(PMVMatrix).

        Parameters:
        pmv - well formed PMVMatrix, e.g. could have been setup via setupMatrix(..) and setTransform(PMVMatrix).
        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, PMVMatrix, float[]), #winToShapeCoord(Scene, int, int, PMVMatrix, float[])
      • winToShapeCoord

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

        The given PMVMatrix will be setup properly for this shape including this shape's setTransform(PMVMatrix).

        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 PMVMatrix 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(PMVMatrix, Recti, int, int, float[]), #winToShapeCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, int, int, PMVMatrix, float[])
      • getColor

        public Vec4f getColor()
      • setColor

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

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

      • setColor

        public final Shape setColor​(Vec4f c)
        Set base color.

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

      • setPressedColorMod

        public final Shape setPressedColorMod​(float r,
                                              float g,
                                              float b,
                                              float a)
        Set pressed color.

        Default pressed color-factor w/o color channel, modulated base-color. 0.75 * 1.2 = 0.9

      • setToggleOnColorMod

        public final Shape setToggleOnColorMod​(float r,
                                               float g,
                                               float b,
                                               float a)
        Set toggle-on color.

        Default toggle-on color-factor w/o color channel, modulated base-color. 0.75 * 1.13 ~ 0.85

      • setToggleOffColorMod

        public final Shape setToggleOffColorMod​(float r,
                                                float g,
                                                float b,
                                                float a)
        Set toggle-off color.

        Default toggle-off color-factor w/o color channel, modulated base-color. 0.75 * 0.86 ~ 0.65

      • getBorderColor

        public Vec4f getBorderColor()
      • setBorderColor

        public final Shape setBorderColor​(float r,
                                          float g,
                                          float b,
                                          float a)
        Set border color.
      • setBorderColor

        public final Shape setBorderColor​(Vec4f c)
        Set border color.
      • getSubString

        public String getSubString()
      • setPressed

        public Shape setPressed​(boolean b)
      • isPressed

        public boolean isPressed()
      • setToggleable

        public Shape setToggleable​(boolean toggleable)
        Parameters:
        toggleable -
        See Also:
        isInteractive()
      • setToggle

        public Shape setToggle​(boolean v)
      • toggle

        public Shape toggle()
      • isToggleOn

        public boolean isToggleOn()
      • setDraggable

        public Shape setDraggable​(boolean draggable)
        Set whether this shape is draggable, i.e. translated by 1-pointer-click and drag.

        Default draggable is true.

        See Also:
        isInteractive()
      • isDraggable

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

        public Shape setResizable​(boolean resizable)
        Set whether this shape is resizable, i.e. zoomed by 1-pointer-click and drag in 1/4th bottom-left and bottom-right corner.

        Default resizable is true.

        See Also:
        isInteractive()
      • isResizable

        public boolean isResizable()
        Returns if this shape is resiable, a user interaction.
        See Also:
        isInteractive()
      • 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, int[], float[]). Otherwise the base color will be modulated and passed to #drawImpl0(GL2ES2, RegionRenderer, int[], float[]).