Package com.avrix.ui

Class NanoDrawer

java.lang.Object
com.avrix.ui.NanoDrawer

public class NanoDrawer extends Object
A set of tools for rendering NanoVG elements
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    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
    drawLine(int x1, int y1, int x2, int y2, float width, NanoColor color)
    Draws a line from (x1, y1) to (x2, y2) with the specified color and thickness.
    static void
    drawRect(int x, int y, int width, int height, NanoColor color)
    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 fill
    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.
    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
    drawText(String text, String fontName, int x, int y, int fontSize, NanoColor color)
    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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NanoDrawer

      public NanoDrawer()
  • Method Details

    • truncateText

      public static String truncateText(String text, String fontName, int fontSize, int maxWidth)
      Truncates the given text with an ellipsis if it exceeds the specified width.
      Parameters:
      text - the text to be truncated
      fontName - text font name
      fontSize - drawable text size
      maxWidth - 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 matching restoreRenderState() 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 rectangle
      y - absolute Y coordinate of the top left corner of the rectangle
      width - the width of the rectangle
      height - height of the rectangle
      lineWidth - the width of the stroke line in pixels
      color - 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 rectangle
      y - absolute Y coordinate of the top left corner of the rectangle
      width - the width of the rectangle
      height - height of the rectangle
      radius - corner radius
      lineWidth - the width of the stroke line in pixels
      color - the color of the outline
    • drawRect

      public static void drawRect(int x, int y, int width, int height, NanoColor color)
      Draws a filled rectangle with the specified position, size, and color.
      Parameters:
      x - absolute x-coordinate of the top-left corner of the rectangle
      y - absolute y-coordinate of the top-left corner of the rectangle
      width - the width of the rectangle
      height - the height of the rectangle
      color - 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 drawn
      fontName - the name of the font to be used
      x - absolute x-coordinate of the text's position
      y - absolute y-coordinate of the text's position
      fontSize - the size of the font
      color - the color of the text
    • getTextSize

      public 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.
      Parameters:
      text - the text whose dimensions are to be calculated
      fontName - the name of the font to use
      fontSize - 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 rectangle
      y - absolute y-coordinate of the top-left corner of the rectangle
      width - the width of the rectangle
      height - the height of the rectangle
      radius - the radius of the corners
      color - the color to fill the rectangle with
    • drawEllipse

      public 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.
      Parameters:
      x - absolute x-coordinate of the ellipse's center
      y - absolute y-coordinate of the ellipse's center
      width - the width of the ellipse
      height - the height of the ellipse
      color - the color of the ellipse
    • drawLine

      public static void drawLine(int x1, int y1, int x2, int y2, float width, NanoColor color)
      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 line
      y1 - absolute y-coordinate of the start point of the line
      x2 - absolute x-coordinate of the end point of the line
      y2 - absolute y-coordinate of the end point of the line
      width - the thickness of the line
      color - the color of the line
    • drawCircle

      public static void drawCircle(int x, int y, float radius, NanoColor color)
      Draws a circle at the specified position with the given radius and color.
      Parameters:
      x - absolute x-coordinate of the circle's center
      y - absolute y-coordinate of the circle's center
      radius - the radius of the circle
      color - 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 arc
      y - absolute y-coordinate of the center of the arc
      radius - the radius of the arc
      startAngle - 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 arc
      y - absolute y-coordinate of the center of the arc
      radius - the radius of the arc
      startAngle - the starting angle of the arc (in radians)
      endAngle - the ending angle of the arc (in radians)
      thickness - the thickness of the arc segment
      color - 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 draw
      x - absolute x-coordinate of the image's position
      y - absolute y-coordinate of the image's position
      width - the width of the image
      height - the height of the image
      opacity - image opacity (from 0 to 1)