Renderer

Renderer

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).

Functions

Link copied to clipboard
abstract fun beginFrame(width: Float, height: Float, pixelRatio: Float)

Begin a frame. this is called before all drawing calls.

Link copied to clipboard
abstract fun cleanup()

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

Link copied to clipboard
open override fun close()
Link copied to clipboard
abstract fun delete(font: Font?)

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

abstract fun delete(image: PolyImage?)

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

Link copied to clipboard
abstract fun dropShadow(x: Float, y: Float, width: Float, height: Float, blur: Float, spread: Float, radius: Float)

Draw a drop shadow to the screen, per the given parameters.

Link copied to clipboard
abstract fun endFrame()

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

Link copied to clipboard
abstract fun globalAlpha(alpha: Float)

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

Link copied to clipboard
open fun hollowRect(x: Float, y: Float, width: Float, height: Float, color: Color, lineWidth: Float, radius: Float = 0.0f)
open fun hollowRect(x: Float, y: Float, width: Float, height: Float, color: Color, lineWidth: Float, radii: FloatArray)

abstract fun hollowRect(x: Float, y: Float, width: Float, height: Float, color: Color, lineWidth: Float, topLeftRadius: Float, topRightRadius: Float, bottomLeftRadius: Float, bottomRightRadius: Float)

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

Link copied to clipboard
open fun image(image: PolyImage, x: Float, y: Float, width: Float, height: Float, radius: Float = 0.0f, colorMask: Int = 0)
open fun image(image: PolyImage, x: Float, y: Float, width: Float, height: Float, radii: FloatArray, colorMask: Int = 0)

abstract fun image(image: PolyImage, x: Float, y: Float, width: Float, height: Float, colorMask: Int = 0, topLeftRadius: Float, topRightRadius: Float, bottomLeftRadius: Float, bottomRightRadius: Float)

Draw an image to the screen, per the given parameters.

Link copied to clipboard
abstract fun 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.

Link copied to clipboard
abstract fun initImage(image: PolyImage, size: Vec2)

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.

Link copied to clipboard
abstract fun line(x1: Float, y1: Float, x2: Float, y2: Float, color: Color, width: Float)

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

Link copied to clipboard
abstract fun pop()

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

Link copied to clipboard
abstract fun popScissor()

end a scissor.

Link copied to clipboard
abstract fun push()

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

Link copied to clipboard
abstract fun pushScissor(x: Float, y: Float, width: Float, height: Float)

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

Link copied to clipboard
abstract fun pushScissorIntersecting(x: Float, y: Float, width: Float, height: Float)

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

Link copied to clipboard
open fun rect(x: Float, y: Float, width: Float, height: Float, color: Color, radius: Float = 0.0f)
open fun rect(x: Float, y: Float, width: Float, height: Float, color: Color, radii: FloatArray)

abstract fun rect(x: Float, y: Float, width: Float, height: Float, color: Color, topLeftRadius: Float, topRightRadius: Float, bottomLeftRadius: Float, bottomRightRadius: Float)

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

Link copied to clipboard
open fun resetGlobalAlpha()

reset the global alpha to normal.

Link copied to clipboard
abstract fun rotate(angleRadians: Double, px: Float, py: Float)

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

Link copied to clipboard
abstract fun scale(sx: Float, sy: Float, px: Float, py: Float)

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

Link copied to clipboard
abstract fun skewX(angleRadians: Double, px: Float, py: Float)

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

Link copied to clipboard
abstract fun skewY(angleRadians: Double, px: Float, py: Float)

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

Link copied to clipboard
abstract fun text(font: Font, x: Float, y: Float, text: String, color: Color, fontSize: Float)

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

Link copied to clipboard
abstract fun textBounds(font: Font, text: String, fontSize: Float): Vec2

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

Link copied to clipboard

Return true if your rendering implementation supports usage of x and y parameters on scale, rotate, skewX, and skewY.

Link copied to clipboard
abstract fun translate(x: Float, y: Float)

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