Package com.avrix.ui
Class NanoDrawer
java.lang.Object
com.avrix.ui.NanoDrawer
A set of tools for rendering NanoVG elements
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
drawArc
(int x, int y, float radius, float thickness, float startAngle, float endAngle, NanoColor color) Draws an arc segment with the specified center, radius, start angle, end angle, and thickness.static void
Draws an arc segment with the specified center, radius, start angle, and end angle.static void
drawCircle
(int x, int y, float radius, NanoColor color) Draws a circle at the specified position with the given radius and color.static void
drawEllipse
(int x, int y, int width, int height, NanoColor color) Draws an ellipse at the specified position with the given size and color.static void
drawImage
(int imageId, int x, int y, int width, int height, float opacity) Draws an image at the specified position with the given size.static void
Draws a line from (x1, y1) to (x2, y2) with the specified color and thickness.static void
Draws a filled rectangle with the specified position, size, and color.static void
drawRectOutline
(int x, int y, int width, int height, float lineWidth, NanoColor color) Draws a rectangle with a stroke and no fillstatic void
drawRoundedRect
(int x, int y, int width, int height, float radius, NanoColor color) Draws a filled rectangle with rounded corners with the specified position, size, radius, and color.static void
drawRoundedRectOutline
(int x, int y, int width, int height, int radius, float lineWidth, NanoColor color) Draws a rectangle with rounded corners and a stroke without fill.static void
Draws text on the screen using NanoVG.static org.joml.Vector2f
getTextSize
(String text, String fontName, int fontSize) Calculates the width and height of the given text when rendered with the specified font and size.static void
intersectScissor
(int x, int y, int width, int height) Intersects current scissor rectangle with the specified rectangle.static void
Resets current render state to default values.static void
Resets and disables scissoring.static void
Pops and restores current render state.static void
Pushes and saves the current render state into a state stack.static void
scissor
(int x, int y, int width, int height) Sets the current scissor rectangle.static String
truncateText
(String text, String fontName, int fontSize, int maxWidth) Truncates the given text with an ellipsis if it exceeds the specified width.
-
Constructor Details
-
NanoDrawer
public NanoDrawer()
-
-
Method Details
-
truncateText
Truncates the given text with an ellipsis if it exceeds the specified width.- Parameters:
text
- the text to be truncatedfontName
- text font namefontSize
- drawable text sizemaxWidth
- the maximum width available for the text- Returns:
- the truncated text with an ellipsis if it exceeds the maximum width
-
scissor
public static void scissor(int x, int y, int width, int height) Sets the current scissor rectangle. The scissor rectangle is transformed by the current transform.- Parameters:
x
- absolute x-coordinate of the scissor region.y
- absolute y-coordinate of the scissor region.width
- the width of the scissor region.height
- the height of the scissor region.
-
intersectScissor
public static void intersectScissor(int x, int y, int width, int height) Intersects current scissor rectangle with the specified rectangle. The scissor rectangle is transformed by the current transform. Note: in case the rotation of previous scissor rect differs from the current one, the intersection will be done between the specified rectangle and the previous scissor rectangle transformed in the current transform space. The resulting shape is always rectangle.- Parameters:
x
- absolute x-coordinate of the intersecting scissor region.y
- absolute y-coordinate of the intersecting scissor region.width
- the width of the intersecting scissor region.height
- the height of the intersecting scissor region.
-
resetScissor
public static void resetScissor()Resets and disables scissoring. -
saveRenderState
public static void saveRenderState()Pushes and saves the current render state into a state stack. A matchingrestoreRenderState()
must be used to restore the state. -
restoreRenderState
public static void restoreRenderState()Pops and restores current render state. -
resetRenderState
public static void resetRenderState()Resets current render state to default values. Does not affect the render state stack. -
drawRectOutline
public static void drawRectOutline(int x, int y, int width, int height, float lineWidth, NanoColor color) Draws a rectangle with a stroke and no fill- Parameters:
x
- absolute X coordinate of the top left corner of the rectangley
- absolute Y coordinate of the top left corner of the rectanglewidth
- the width of the rectangleheight
- height of the rectanglelineWidth
- the width of the stroke line in pixelscolor
- the color of the outline
-
drawRoundedRectOutline
public static void drawRoundedRectOutline(int x, int y, int width, int height, int radius, float lineWidth, NanoColor color) Draws a rectangle with rounded corners and a stroke without fill.- Parameters:
x
- absolute X coordinate of the top left corner of the rectangley
- absolute Y coordinate of the top left corner of the rectanglewidth
- the width of the rectangleheight
- height of the rectangleradius
- corner radiuslineWidth
- the width of the stroke line in pixelscolor
- the color of the outline
-
drawRect
Draws a filled rectangle with the specified position, size, and color.- Parameters:
x
- absolute x-coordinate of the top-left corner of the rectangley
- absolute y-coordinate of the top-left corner of the rectanglewidth
- the width of the rectangleheight
- the height of the rectanglecolor
- the color to fill the rectangle with
-
drawText
public static void drawText(String text, String fontName, int x, int y, int fontSize, NanoColor color) Draws text on the screen using NanoVG.- Parameters:
text
- the text to be drawnfontName
- the name of the font to be usedx
- absolute x-coordinate of the text's positiony
- absolute y-coordinate of the text's positionfontSize
- the size of the fontcolor
- the color of the text
-
getTextSize
Calculates the width and height of the given text when rendered with the specified font and size.- Parameters:
text
- the text whose dimensions are to be calculatedfontName
- the name of the font to usefontSize
- the size of the font- Returns:
- an array containing two elements: the width (index 0) and the height (index 1) of the text
-
drawRoundedRect
public static void drawRoundedRect(int x, int y, int width, int height, float radius, NanoColor color) Draws a filled rectangle with rounded corners with the specified position, size, radius, and color.- Parameters:
x
- absolute x-coordinate of the top-left corner of the rectangley
- absolute y-coordinate of the top-left corner of the rectanglewidth
- the width of the rectangleheight
- the height of the rectangleradius
- the radius of the cornerscolor
- the color to fill the rectangle with
-
drawEllipse
Draws an ellipse at the specified position with the given size and color.- Parameters:
x
- absolute x-coordinate of the ellipse's centery
- absolute y-coordinate of the ellipse's centerwidth
- the width of the ellipseheight
- the height of the ellipsecolor
- the color of the ellipse
-
drawLine
Draws a line from (x1, y1) to (x2, y2) with the specified color and thickness.- Parameters:
x1
- absolute x-coordinate of the start point of the liney1
- absolute y-coordinate of the start point of the linex2
- absolute x-coordinate of the end point of the liney2
- absolute y-coordinate of the end point of the linewidth
- the thickness of the linecolor
- the color of the line
-
drawCircle
Draws a circle at the specified position with the given radius and color.- Parameters:
x
- absolute x-coordinate of the circle's centery
- absolute y-coordinate of the circle's centerradius
- the radius of the circlecolor
- the color of the circle
-
drawArc
public static void drawArc(int x, int y, float radius, float startAngle, float endAngle, NanoColor color) Draws an arc segment with the specified center, radius, start angle, and end angle.- Parameters:
x
- absolute x-coordinate of the center of the arcy
- absolute y-coordinate of the center of the arcradius
- the radius of the arcstartAngle
- the starting angle of the arc (in radians)endAngle
- the ending angle of the arc (in radians)color
- the color of the arc segment
-
drawArc
public static void drawArc(int x, int y, float radius, float thickness, float startAngle, float endAngle, NanoColor color) Draws an arc segment with the specified center, radius, start angle, end angle, and thickness.- Parameters:
x
- absolute x-coordinate of the center of the arcy
- absolute y-coordinate of the center of the arcradius
- the radius of the arcstartAngle
- the starting angle of the arc (in radians)endAngle
- the ending angle of the arc (in radians)thickness
- the thickness of the arc segmentcolor
- the color of the arc segment
-
drawImage
public static void drawImage(int imageId, int x, int y, int width, int height, float opacity) Draws an image at the specified position with the given size.- Parameters:
imageId
- the identifier of the image to drawx
- absolute x-coordinate of the image's positiony
- absolute y-coordinate of the image's positionwidth
- the width of the imageheight
- the height of the imageopacity
- image opacity (from 0 to 1)
-