Class UIPainter2D
java.lang.Object
net.risingworld.api.ui.UIElement
net.risingworld.api.ui.UIPainter2D
A simplified version of the
All methods record drawing commands which are executed in the same order on the client. Style settings (colors, line width etc.) apply to all subsequent
Please note that most style properties have no impact on the element!
Another note: Unity internally has a hard-coded mesh vertex limit of 65535 for UI elements. If the amount of vertices exceed this value, the UI element can no longer be rendered. Unfortunately there is no workaround available yet, so if your painter element becomes too complex, it could be necessary to split it into multiple instances (or use a
UIMesh element. It enables you to create custom shapes and elements, but instead
of providing individual vertices, this class uses a Vector API to creates lines and shapes more easily. All methods record drawing commands which are executed in the same order on the client. Style settings (colors, line width etc.) apply to all subsequent
fill(FillRule) and stroke() calls. Positions are in pixels and relative to the upper
left corner of the element (x pointing right, y pointing down). The commands are only sent to the clients once you call
update() (or when the element is added to a player), every update transmits all commands. Please note that most style properties have no impact on the element!
Another note: Unity internally has a hard-coded mesh vertex limit of 65535 for UI elements. If the amount of vertices exceed this value, the UI element can no longer be rendered. Unfortunately there is no workaround available yet, so if your painter element becomes too complex, it could be necessary to split it into multiple instances (or use a
UIMesh,
which is not limited).- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enumstatic enumstatic enum -
Field Summary
Fields inherited from class UIElement
hoverStyle, style -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidarc(Vector2f center, float radius, float startAngle, float endAngle, UIPainter2D.ArcDirection direction) Adds an arc to the current sub-path.voidarc(Vector2f center, float radius, int startAngle, int endAngle, UIPainter2D.ArcDirection direction) Adds an arc to the current sub-path.voidAdds a circular arc to the current sub-path, using the current position, two control points and a radius (connected to the current position by a straight line if necessary).voidBegins a new path, i.e. discards all previous sub-paths (already filled or stroked shapes remain visible).voidbezierCurveTo(Vector2f p1, Vector2f p2, Vector2f p3) Adds a cubic bezier curve from the current position to the end point.voidclear()Removes all recorded commands.voidCloses the current sub-path with a straight line to its start point.voidfill(UIPainter2D.FillRule fillRule) Fills the current path with the current fill color (seesetFillColor(float, float, float, float)).voidAdds a straight line from the current position to the provided position.voidBegins a new sub-path at the provided position (without drawing a line).voidquadraticCurveTo(Vector2f p1, Vector2f p2) Adds a quadratic bezier curve from the current position to the end point.voidsetFillColor(float r, float g, float b, float a) Sets the color for subsequentfill(FillRule)calls.voidsetLineCap(UIPainter2D.LineCap lineCap) Sets the shape of the line ends for subsequentstroke()calls.voidsetLineJoin(UIPainter2D.LineJoin lineJoin) Sets the shape of the corners between connected line segments for subsequentstroke()calls.voidsetLineWidth(float lineWidth) Sets the line width for subsequentstroke()calls.voidsetMiterLimit(float miterLimit) Sets the miter limit for subsequentstroke()calls.voidsetStrokeColor(float r, float g, float b, float a) Sets the color for subsequentstroke()calls.voidstroke()Draws the outline of the current path with the current stroke settings (color, line width, line cap and line join).voidupdate()Sends all recorded commands to all players who have this element.Methods inherited from class UIElement
addChild, addStyleSheet, addToClassList, getChildCount, getChilds, getID, getParent, getPluginID, isClickable, isDroppable, isPickable, onClick, onDropItem, removeAllChilds, removeChild, removeFromClassList, removeFromParent, removeStyleSheet, resetPivot, resetPosition, setBackgroundColor, setBackgroundColor, setBorder, setBorderColor, setBorderColor, setBorderEdgeRadius, setClickable, setDroppable, setOpacity, setPickable, setPivot, setPosition, setSize, setTextTooltip, setTextTooltip, setVisible, updateStyle
-
Constructor Details
-
UIPainter2D
public UIPainter2D()
-
-
Method Details
-
arc
public void arc(Vector2f center, float radius, int startAngle, int endAngle, UIPainter2D.ArcDirection direction) Adds an arc to the current sub-path.- Parameters:
center- the center of the arc (in pixels).radius- the radius of the arc (in pixels).startAngle- the start angle of the arc (in degrees).endAngle- the end angle of the arc (in degrees).direction- the direction in which the arc is drawn.
-
arc
public void arc(Vector2f center, float radius, float startAngle, float endAngle, UIPainter2D.ArcDirection direction) Adds an arc to the current sub-path.- Parameters:
center- the center of the arc (in pixels).radius- the radius of the arc (in pixels).startAngle- the start angle of the arc (in degrees).endAngle- the end angle of the arc (in degrees).direction- the direction in which the arc is drawn.
-
arcTo
Adds a circular arc to the current sub-path, using the current position, two control points and a radius (connected to the current position by a straight line if necessary).- Parameters:
p1- the first control point (in pixels).p2- the second control point (in pixels).radius- the radius of the arc (in pixels).
-
bezierCurveTo
-
beginPath
public void beginPath()Begins a new path, i.e. discards all previous sub-paths (already filled or stroked shapes remain visible). -
closePath
public void closePath()Closes the current sub-path with a straight line to its start point. -
fill
Fills the current path with the current fill color (seesetFillColor(float, float, float, float)).- Parameters:
fillRule- the rule which determines whether a point is inside the shape (relevant for overlapping or self-intersecting paths).
-
lineTo
Adds a straight line from the current position to the provided position.- Parameters:
pos- the end point of the line (in pixels).
-
moveTo
Begins a new sub-path at the provided position (without drawing a line).- Parameters:
pos- the new position (in pixels).
-
quadraticCurveTo
-
stroke
public void stroke()Draws the outline of the current path with the current stroke settings (color, line width, line cap and line join). -
setFillColor
public void setFillColor(float r, float g, float b, float a) Sets the color for subsequentfill(FillRule)calls.- Parameters:
r- the red component (0-1).g- the green component (0-1).b- the blue component (0-1).a- the alpha component (0-1).
-
setLineCap
Sets the shape of the line ends for subsequentstroke()calls.- Parameters:
lineCap- the line cap.
-
setLineJoin
Sets the shape of the corners between connected line segments for subsequentstroke()calls.- Parameters:
lineJoin- the line join.
-
setLineWidth
public void setLineWidth(float lineWidth) Sets the line width for subsequentstroke()calls.- Parameters:
lineWidth- the line width (in pixels).
-
setMiterLimit
public void setMiterLimit(float miterLimit) Sets the miter limit for subsequentstroke()calls. If the miter length of a corner exceeds this limit (relative to the line width), the corner is beveled instead (only relevant forUIPainter2D.LineJoin.Miter).- Parameters:
miterLimit- the miter limit.
-
setStrokeColor
public void setStrokeColor(float r, float g, float b, float a) Sets the color for subsequentstroke()calls.- Parameters:
r- the red component (0-1).g- the green component (0-1).b- the blue component (0-1).a- the alpha component (0-1).
-
clear
public void clear()Removes all recorded commands. Callupdate()afterwards to apply the changes. -
update
public void update()Sends all recorded commands to all players who have this element. Call this method once after you have finished drawing.
-