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).
-
-
Method Summary
Modifier and Type Method Description abstract Unitinit()This function is called during very early initialization, and should be used to prepare the renderer for use. abstract UnitbeginFrame(Float width, Float height, Float pixelRatio)Begin a frame. abstract UnitendFrame()End a frame. abstract UnitglobalAlpha(Float alpha)Set the alpha for all future draw calls, in the range (0-1), until reset. UnitresetGlobalAlpha()reset the global alpha to normal. abstract Unittranslate(Float x, Float y)translate the origin of all future draw calls by the given amount. abstract Unitscale(Float sx, Float sy, Float px, Float py)scales 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! abstract Unitrotate(Double angleRadians, Float px, Float py)rotate 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! abstract UnitskewX(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! abstract UnitskewY(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! abstract UnitpushScissor(Float x, Float y, Float width, Float height)begin a scissor rectangle, that will clip rendering to the given rectangle. abstract UnitpushScissorIntersecting(Float x, Float y, Float width, Float height)begin a scissor rectangle, that will clip rendering to the given rectangle. abstract UnitpopScissor()end a scissor. abstract Unitpush()Push the current state, saving all the current transforms before creating a new one with the same parameters as the current one. abstract Unitpop()pop the current state, reverting all transforms to the previous values. abstract Unittext(Font font, Float x, Float y, String text, PolyColor color, Float fontSize)draw text to the screen, per the given parameters. abstract Vec2textBounds(Font font, String text, Float fontSize)calculate the bounds of this text, per the given parameters. abstract UnitinitImage(PolyImage image)Function that can be called to explicitly initialize an image. abstract Unitimage(PolyImage image, Float x, Float y, Float width, Float height, Integer colorMask, Float topLeftRadius, Float topRightRadius, Float bottomLeftRadius, Float bottomRightRadius)Draw an image to the screen, per the given parameters. Unitimage(PolyImage image, Float x, Float y, Float width, Float height, Float radius, Integer colorMask)Unitimage(PolyImage image, Float x, Float y, Float width, Float height, FloatArray radii, Integer colorMask)abstract Unitrect(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. Unitrect(Float x, Float y, Float width, Float height, PolyColor color, Float radius)Unitrect(Float x, Float y, Float width, Float height, PolyColor color, FloatArray radii)abstract UnithollowRect(Float x, Float y, Float width, Float height, PolyColor color, Float lineWidth, Float topLeftRadius, Float topRightRadius, Float bottomLeftRadius, Float bottomRightRadius)draw a hollow rectangle to the screen, per the given parameters. UnithollowRect(Float x, Float y, Float width, Float height, PolyColor color, Float lineWidth, Float radius)UnithollowRect(Float x, Float y, Float width, Float height, PolyColor color, Float lineWidth, FloatArray radii)abstract Unitline(Float x1, Float y1, Float x2, Float y2, PolyColor color, Float width)Draws a line between two points with the specified color and width. abstract UnitdropShadow(Float x, Float y, Float width, Float height, Float blur, Float spread, Float radius)Draw a drop shadow to the screen, per the given parameters. abstract BooleansupportsFramebuffers()Return true if your rendering implementation supports usage of framebuffers. abstract BooleantransformsWithPoint()Return trueif your rendering implementation supports usage ofxandyparameters on scale, rotate, skewX, and skewY.abstract FramebuffercreateFramebuffer(Float width, Float height)Create a new framebuffer. abstract UnitbindFramebuffer(Framebuffer fbo)Bind the given framebuffer. abstract UnitunbindFramebuffer()Unbind the currently bound framebuffer. abstract UnitdrawFramebuffer(Framebuffer fbo, Float x, Float y, Float width, Float height)draw the given framebuffer to the screen. abstract Unitdelete(Framebuffer fbo)Delete the given framebuffer. abstract Unitdelete(Font font)Delete the given font. abstract Unitdelete(PolyImage image)Delete the given image. abstract Unitcleanup()Cleanup this renderer. Unitclose()-
-
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
-
beginFrame
abstract Unit beginFrame(Float width, Float height, Float pixelRatio)
Begin a frame. this is called before all drawing calls.
-
globalAlpha
abstract Unit globalAlpha(Float alpha)
Set the alpha for all future draw calls, in the range (0-1), until reset.
-
resetGlobalAlpha
Unit resetGlobalAlpha()
reset the global alpha to normal.
-
translate
abstract Unit translate(Float x, Float y)
translate the origin of all future draw calls by the given amount.
-
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!
-
popScissor
abstract Unit popScissor()
end a 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
saveStateorpushMatrixin 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
restoreStateorpopMatrixin 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)
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.
-
image
abstract Unit image(PolyImage image, Float x, Float y, Float width, Float height, Integer colorMask, Float topLeftRadius, Float topRightRadius, Float bottomLeftRadius, Float bottomRightRadius)
Draw an image to the screen, per the given parameters.
-
image
Unit image(PolyImage image, Float x, Float y, Float width, Float height, Float radius, Integer colorMask)
-
image
Unit image(PolyImage image, Float x, Float y, Float width, Float height, FloatArray radii, Integer colorMask)
-
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.
-
hollowRect
abstract Unit hollowRect(Float x, Float y, Float width, Float height, PolyColor color, Float lineWidth, Float topLeftRadius, Float topRightRadius, Float bottomLeftRadius, Float bottomRightRadius)
draw a hollow rectangle to the screen, per the given parameters.
-
hollowRect
Unit hollowRect(Float x, Float y, Float width, Float height, PolyColor color, Float lineWidth, Float radius)
-
hollowRect
Unit hollowRect(Float x, Float y, Float width, Float height, PolyColor color, Float lineWidth, FloatArray radii)
-
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.
-
dropShadow
abstract Unit dropShadow(Float x, Float y, Float width, Float height, Float blur, Float spread, Float radius)
Draw a drop shadow to the screen, per the given parameters.
-
supportsFramebuffers
abstract Boolean supportsFramebuffers()
Return true if your rendering implementation supports usage of framebuffers.
If this method returns
false, you can be safe that createFramebuffer and bindFramebuffer, etc. will never be called.- Since:
0.25.1
-
transformsWithPoint
abstract Boolean transformsWithPoint()
Return
trueif your rendering implementation supports usage ofxandyparameters on scale, rotate, skewX, and skewY.If you return
false, PolyUI will automatically using translate to mimic this behavior.- Since:
1.0.8
-
createFramebuffer
abstract Framebuffer createFramebuffer(Float width, Float height)
Create a new framebuffer. It is down to you (as a rendering implementation) to cache this, and dispose of it as necessary.
- Returns:
a PolyUI framebuffer object using the width and height passed to this method. This is used by PolyUI to identify it.
-
bindFramebuffer
abstract Unit bindFramebuffer(Framebuffer fbo)
Bind the given framebuffer.
-
unbindFramebuffer
abstract Unit unbindFramebuffer()
Unbind the currently bound framebuffer.
-
drawFramebuffer
abstract Unit drawFramebuffer(Framebuffer fbo, Float x, Float y, Float width, Float height)
draw the given framebuffer to the screen.
-
delete
abstract Unit delete(Framebuffer fbo)
Delete the given framebuffer. Ignore if null.
-
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
-
-
-
-