Interface Renderer

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    
    public interface Renderer
     implements AutoCloseable
                        

    The renderer is responsible for drawing all components to the screen, handling frame buffers, and more. Please make sure to implement all the functions in this class, and you may want to familiarize yourself with how org.polyfrost.polyui.PolyUI works.

    It is also responsible for loading and caching all images and fonts, but this is down to you as a rendering implementation to implement. for these functions, such as image and text, an initialized Font or PolyImage instance will be given. You can access the data using Resource.stream, and cache it for future use (ideally).

    • Constructor Detail

    • Method Detail

      • init

         abstract Unit init()

        This function is called during very early initialization, and should be used to prepare the renderer for use. This is always the first function called.

        Since:

        0.21.2

      • endFrame

         abstract Unit endFrame()

        End a frame. this is called after all drawing calls.

      • globalAlpha

         abstract Unit globalAlpha(Float alpha)

        Set the alpha for all future draw calls, in the range (0-1), until reset.

      • translate

         abstract Unit translate(Float x, Float y)

        translate the origin of all future draw calls by the given amount.

        you must do all your transforms inside a push, pop pair!

      • skewX

         abstract Unit skewX(Double angleRadians, Float px, Float py)

        Skew all future draw calls by the given amount, around the given point, px and py (if supported)

        you must do all your transforms inside a push, pop pair!

        Since:

        0.16.1

      • skewY

         abstract Unit skewY(Double angleRadians, Float px, Float py)

        Skew all future draw calls by the given amount, around the given point, px and py (if supported)

        you must do all your transforms inside a push, pop pair!

        Since:

        0.16.1

      • pushScissor

         abstract Unit pushScissor(Float x, Float y, Float width, Float height)

        begin a scissor rectangle, that will clip rendering to the given rectangle.

        The scissor is affected by translate, scale, and rotate, and is intersected with the previous scissor.

        you must call popScissor after you are done with this scissor!

      • pushScissorIntersecting

         abstract Unit pushScissorIntersecting(Float x, Float y, Float width, Float height)

        begin a scissor rectangle, that will clip rendering to the given rectangle. The rectangle is intersected with the previous scissor.

        The scissor is affected by translate, scale, and rotate, and is intersected with the previous scissor.

        you must call popScissor after you are done with this scissor!

      • push

         abstract Unit push()

        Push the current state, saving all the current transforms before creating a new one with the same parameters as the current one.

        This is also called saveState or pushMatrix in many frameworks.

        pop - you must call this after you are finished!

        Since:

        0.17.2

      • pop

         abstract Unit pop()

        pop the current state, reverting all transforms to the previous values.

        This is also called restoreState or popMatrix in many frameworks.

        push - you must call this before you are begin!

        Since:

        0.17.2

      • text

         abstract Unit text(Font font, Float x, Float y, String text, PolyColor color, Float fontSize)

        draw text to the screen, per the given parameters. The string will already be wrapped to the given width.

      • textBounds

         abstract Vec2 textBounds(Font font, String text, Float fontSize)

        calculate the bounds of this text, per the given parameters.

        Returns:

        a Vec2 containing the width and height of the given string. If your API does not support returning string heights, just return the font size. The discrepancy should be negligible.

      • initImage

         abstract Unit initImage(PolyImage image, Vec2 size)

        Function that can be called to explicitly initialize an image. This is used mainly for getting the size of an image, or to ensure an SVG has been rasterized.

      • rect

         abstract Unit rect(Float x, Float y, Float width, Float height, PolyColor color, Float topLeftRadius, Float topRightRadius, Float bottomLeftRadius, Float bottomRightRadius)

        draw a rectangle to the screen, per the given parameters.

        If the radii are 0, this will just draw a normal rectangle. If they are not 0, it will draw a rounded rectangle.

      • line

         abstract Unit line(Float x1, Float y1, Float x2, Float y2, PolyColor color, Float width)

        Draws a line between two points with the specified color and width.

        Parameters:
        x1 - The x-coordinate of the starting point.
        y1 - The y-coordinate of the starting point.
        x2 - The x-coordinate of the ending point.
        y2 - The y-coordinate of the ending point.
        color - The color of the line.
        width - The width of the line.
      • delete

         abstract Unit delete(Font font)

        Delete the given font. Use this to free any native resources.

        Since:

        0.20.1

      • delete

         abstract Unit delete(PolyImage image)

        Delete the given image. Use this to free any native resources.

        Since:

        0.20.1

      • cleanup

         abstract Unit cleanup()

        Cleanup this renderer. Use this to free any native resources.