Class Drawable

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public abstract class Drawable
    extends RefCnt

    Base class for objects that draw into Canvas.

    The object has a generation id, which is guaranteed to be unique across all drawables. To allow for clients of the drawable that may want to cache the results, the drawable must change its generation id whenever its internal state changes such that it will draw differently.

    • Field Detail

      • _bounds

        @Internal
        public io.github.humbleui.types.Rect _bounds
    • Constructor Detail

      • Drawable

        public Drawable()
    • Method Detail

      • draw

        @NonExtendable
        public Drawable draw​(Canvas canvas)
        Draws into the specified content. The drawing sequence will be balanced upon return (i.e. the saveLevel() on the canvas will match what it was when draw() was called, and the current matrix and clip settings will not be changed.
      • draw

        @NonExtendable
        public Drawable draw​(Canvas canvas,
                             float x,
                             float y)
        Draws into the specified content. The drawing sequence will be balanced upon return (i.e. the saveLevel() on the canvas will match what it was when draw() was called, and the current matrix and clip settings will not be changed.
      • draw

        @NonExtendable
        public Drawable draw​(Canvas canvas,
                             @Nullable
                             @Nullable Matrix33 matrix)
        Draws into the specified content. The drawing sequence will be balanced upon return (i.e. the saveLevel() on the canvas will match what it was when draw() was called, and the current matrix and clip settings will not be changed.
      • makePictureSnapshot

        @NonExtendable
        public Picture makePictureSnapshot()
      • getGenerationId

        public int getGenerationId()

        Return a unique value for this instance. If two calls to this return the same value, it is presumed that calling the draw() method will render the same thing as well.

        Subclasses that change their state should call notifyDrawingChanged() to ensure that a new value will be returned the next time it is called.

      • getBounds

        @NonExtendable
        @NotNull
        public @NotNull io.github.humbleui.types.Rect getBounds()
        Return the (conservative) bounds of what the drawable will draw. If the drawable can change what it draws (e.g. animation or in response to some external change), then this must return a bounds that is always valid for all possible states.
      • notifyDrawingChanged

        @NonExtendable
        public Drawable notifyDrawingChanged()
        Calling this invalidates the previous generation ID, and causes a new one to be computed the next time getGenerationId() is called. Typically this is called by the object itself, in response to its internal state changing.
      • onDraw

        @OverrideOnly
        public abstract void onDraw​(Canvas canvas)
      • onGetBounds

        @OverrideOnly
        @NotNull
        public abstract @NotNull io.github.humbleui.types.Rect onGetBounds()
      • _onDraw

        @Internal
        public void _onDraw​(long canvasPtr)
      • _nMake

        @Internal
        public static long _nMake()
      • _nInit

        @Internal
        public void _nInit​(long ptr)
      • _nDraw

        @Internal
        public static void _nDraw​(long ptr,
                                  long canvasPtr,
                                  float[] matrix)
      • _nMakePictureSnapshot

        @Internal
        public static long _nMakePictureSnapshot​(long ptr)
      • _nGetGenerationId

        @Internal
        public static int _nGetGenerationId​(long ptr)
      • _nNotifyDrawingChanged

        @Internal
        public static void _nNotifyDrawingChanged​(long ptr)