Package ej.microui.display

## Class Painter

- java.lang.Object
- - ej.microui.display.Painter

-     public class Painter
      extends Object

  The `Painter` class provides static methods to draw basic shapes such as lines, rectangles, circles, characters and images.

  Every method uses the color, the translation and the clip which are set in the given `GraphicsContext`. The background color and the ellipsis width are only used by a few methods.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Painter()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `drawChar​(GraphicsContext gc, char character, Font font, int x, int y)` | Draws a character.
    `static void` | `drawCircle​(GraphicsContext gc, int x, int y, int diameter)` | Draws a circle.
    `static void` | `drawCircleArc​(GraphicsContext gc, int x, int y, int diameter, float startAngle, float arcAngle)` | Draws a circle arc.
    `static void` | `drawDisplayRegion​(GraphicsContext gc, int xSource, int ySource, int width, int height, int xDestination, int yDestination)` | Draws a region of the display.
    `static void` | `drawDisplayRegion​(GraphicsContext gc, int xSource, int ySource, int width, int height, int xDestination, int yDestination, int alpha)` | Draws a region of the display.
    `static void` | `drawEllipse​(GraphicsContext gc, int x, int y, int width, int height)` | Draws an ellipse.
    `static void` | `drawEllipseArc​(GraphicsContext gc, int x, int y, int width, int height, float startAngle, float arcAngle)` | Draws an ellipse arc.
    `static void` | `drawHorizontalLine​(GraphicsContext gc, int x, int y, int length)` | Draws an horizontal line between two points.
    `static void` | `drawImage​(GraphicsContext gc, Image image, int x, int y)` | Draws the image at the given anchor top-left point.
    `static void` | `drawImage​(GraphicsContext gc, Image image, int x, int y, int alpha)` | Draws the image at the given anchor top-left point.
    `static void` | `drawImageRegion​(GraphicsContext gc, Image image, int xSource, int ySource, int width, int height, int xDestination, int yDestination)` | Draws a region of the image.
    `static void` | `drawImageRegion​(GraphicsContext gc, Image image, int xSource, int ySource, int width, int height, int xDestination, int yDestination, int alpha)` | Draws a region of an image.
    `static void` | `drawLine​(GraphicsContext gc, int startX, int startY, int endX, int endY)` | Draws a line between two points.
    `static void` | `drawRectangle​(GraphicsContext gc, int x, int y, int width, int height)` | Draws an orthogonal rectangle.
    `static void` | `drawRenderableString​(GraphicsContext gc, RenderableString string, int x, int y)` | Draws the string using the font and given graphics context color.
    `static void` | `drawRoundedRectangle​(GraphicsContext gc, int x, int y, int width, int height, int cornerEllipseWidth, int cornerEllipseHeight)` | Draws an orthogonal rectangle with rounded corners.
    `static void` | `drawString​(GraphicsContext gc, String string, Font font, int x, int y)` | Draws a string.
    `static void` | `drawSubstring​(GraphicsContext gc, String string, int offset, int length, Font font, int x, int y)` | Draws a subset of a string.
    `static void` | `drawVerticalLine​(GraphicsContext gc, int x, int y, int length)` | Draws a vertical line between two points.
    `static void` | `fillCircle​(GraphicsContext gc, int x, int y, int diameter)` | Fills a circle.
    `static void` | `fillCircleArc​(GraphicsContext gc, int x, int y, int diameter, float startAngle, float arcAngle)` | Fills a circle arc.
    `static void` | `fillEllipse​(GraphicsContext gc, int x, int y, int width, int height)` | Fills an ellipse.
    `static void` | `fillEllipseArc​(GraphicsContext gc, int x, int y, int width, int height, float startAngle, float arcAngle)` | Fills an ellipse arc.
    `static void` | `fillRectangle​(GraphicsContext gc, int x, int y, int width, int height)` | Fills an orthogonal rectangle.
    `static void` | `fillRoundedRectangle​(GraphicsContext gc, int x, int y, int width, int height, int cornerEllipseWidth, int cornerEllipseHeight)` | Fills an orthogonal rectangle with rounded corners.
    `static void` | `writePixel​(GraphicsContext gc, int x, int y)` | Draws the pixel at the given coordinates.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Painter

          public Painter()

  - ### Method Detail

    - #### writePixel

          public static void writePixel​(GraphicsContext gc,
                                        int x,
                                        int y)

      Draws the pixel at the given coordinates.
      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the pixel.
        `y` - the y coordinate of the pixel.

    - #### drawHorizontalLine

          public static void drawHorizontalLine​(GraphicsContext gc,
                                                int x,
                                                int y,
                                                int length)

      Draws an horizontal line between two points.

      The line is drawn from the point with the `(x,y)` coordinates to the point with the `(x+length-1,y)` coordinates. The drawn line is composed of `length` pixels. If `length` is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the first point of the line.
        `y` - the y coordinate of the two points line.
        `length` - the length of the line.

    - #### drawVerticalLine

          public static void drawVerticalLine​(GraphicsContext gc,
                                              int x,
                                              int y,
                                              int length)

      Draws a vertical line between two points.

      The line is drawn from the point with the `(x,y)` coordinates to the point with the `(x,y+length-1)` coordinates. The drawn line is composed of `length` pixels. If `length` is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the two points of the line.
        `y` - the y coordinate of the first point of the line.
        `length` - the length of the line.

    - #### drawLine

          public static void drawLine​(GraphicsContext gc,
                                      int startX,
                                      int startY,
                                      int endX,
                                      int endY)

      Draws a line between two points.

      The line is drawn from the point with the `(startX,startY)` coordinates to the point with the `(endX,endY)` coordinates.

      Parameters:
        `gc` - the graphics context to use.
        `startX` - the x coordinate of the first point of the line.
        `startY` - the y coordinate of the first point of the line.
        `endX` - the x coordinate of the second point of the line.
        `endY` - the y coordinate of the second point of the line.

    - #### drawRectangle

          public static void drawRectangle​(GraphicsContext gc,
                                           int x,
                                           int y,
                                           int width,
                                           int height)

      Draws an orthogonal rectangle.

      The four points of the rectangle have the following coordinates: `(x,y)`, `(x+width-1,y)`, `(x,y+height-1)` and `(x+width-1,y+height-1)`.

      If either `width` or `height` is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the rectangle.
        `y` - the y coordinate of the rectangle.
        `width` - the width of the rectangle.
        `height` - the height of the rectangle.

    - #### fillRectangle

          public static void fillRectangle​(GraphicsContext gc,
                                           int x,
                                           int y,
                                           int width,
                                           int height)

      Fills an orthogonal rectangle.

      The four points of the rectangle have the following coordinates: `(x,y)`, `x+width-1,y`, `(x,y+height-1)` and `(x+width-1,y+height-1)`.

      If either `width` or `height` is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the rectangle.
        `y` - the y coordinate of the rectangle.
        `width` - the width of the rectangle.
        `height` - the height of the rectangle.

    - #### drawRoundedRectangle

          public static void drawRoundedRectangle​(GraphicsContext gc,
                                                  int x,
                                                  int y,
                                                  int width,
                                                  int height,
                                                  int cornerEllipseWidth,
                                                  int cornerEllipseHeight)

      Draws an orthogonal rectangle with rounded corners.

      The four points of the rectangle have the following coordinates: `(x,y)`, `x+width-1,y`, `(x,y+height-1)` and `(x+width-1,y+height-1)`.

      If either `width` or `height` is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the rectangle.
        `y` - the y coordinate of the rectangle.
        `width` - the width of the rectangle.
        `height` - the height of the rectangle.
        `cornerEllipseWidth` - the horizontal diameter of the corner arcs.
        `cornerEllipseHeight` - the vertical diameter of the corner arcs.

    - #### fillRoundedRectangle

          public static void fillRoundedRectangle​(GraphicsContext gc,
                                                  int x,
                                                  int y,
                                                  int width,
                                                  int height,
                                                  int cornerEllipseWidth,
                                                  int cornerEllipseHeight)

      Fills an orthogonal rectangle with rounded corners.

      The four points of the rectangle have the following coordinates: `(x,y)`, `x+width-1,y`, `(x,y+height-1)` and `(x+width-1,y+height-1)`.

      If either `width` or `height` is negative or zero, nothing is drawn. If either `cornerEllipseWidth` or `arcHeight` is negative or zero, a regular rectangle is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the rectangle.
        `y` - the y coordinate of the rectangle.
        `width` - the width of the rectangle.
        `height` - the height of the rectangle.
        `cornerEllipseWidth` - the horizontal diameter of the corner arcs.
        `cornerEllipseHeight` - the vertical diameter of the corner arcs.

    - #### drawCircleArc

          public static void drawCircleArc​(GraphicsContext gc,
                                           int x,
                                           int y,
                                           int diameter,
                                           float startAngle,
                                           float arcAngle)

      Draws a circle arc.

      The center of the circle is defined as the center of the square whose origin is at `(x,y)` (upper-left corner) and whose dimension is `(diameter,diameter)`.

      The circle arc is drawn from `startAngle` to `startAngle+arcAngle` degrees. The value of `startAngle` is interpreted such that 0 degrees is along the positive x axis.

      A positive angle indicates a counter-clockwise rotation while a negative angle indicates a clockwise rotation.

      If the `diameter` is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the bounding rectangle of the circle.
        `y` - the y coordinate of the bounding rectangle of the circle.
        `diameter` - the diameter of the circle.
        `startAngle` - the start angle of the arc.
        `arcAngle` - the angular distance of the arc.

    - #### drawEllipseArc

          public static void drawEllipseArc​(GraphicsContext gc,
                                            int x,
                                            int y,
                                            int width,
                                            int height,
                                            float startAngle,
                                            float arcAngle)

      Draws an ellipse arc. Ellipses which focal points are not on the same axis are not supported. The center of the ellipse is defined as the center of the rectangle whose origin is at `(x,y)` (upper-left corner) and whose dimension is `(width,height)`.

      The ellipse arc is drawn from `startAngle` to `startAngle+arcAngle` degrees. The value of `startAngle` is interpreted such that 0 degrees is along the positive x axis.

      A positive angle indicates a counter-clockwise rotation while a negative angle indicates a clockwise rotation.

      The angles are given relative to the rectangle. For instance an angle of 45 degrees is always defined by the line from the center of the rectangle to the upper right corner of the rectangle. Thus for a non squared rectangle angles are skewed along either height or width.

      If either `width` or `height` is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the bounding rectangle of the ellipse.
        `y` - the y coordinate of the bounding rectangle of the ellipse.
        `width` - the width of the ellipse.
        `height` - the height of the ellipse.
        `startAngle` - the start angle of the arc.
        `arcAngle` - the angular distance of the arc.

    - #### fillCircleArc

          public static void fillCircleArc​(GraphicsContext gc,
                                           int x,
                                           int y,
                                           int diameter,
                                           float startAngle,
                                           float arcAngle)

      Fills a circle arc.

      The center of the circle is defined as the center of the square whose origin is at `(x,y)` (upper-left corner) and whose dimension is `(diameter,diameter)`.

      The circle arc is drawn from `startAngle` to `startAngle+arcAngle` degrees. The value of `startAngle` is interpreted such that 0 degrees is along the positive x axis.

      A positive angle indicates a counter-clockwise rotation while a negative angle indicates a clockwise rotation.

      If the given diameter is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the bounding rectangle of the circle.
        `y` - the y coordinate of the bounding rectangle of the circle.
        `diameter` - the diameter of the circle.
        `startAngle` - the start angle of the arc.
        `arcAngle` - the angular distance of the arc.

    - #### fillEllipseArc

          public static void fillEllipseArc​(GraphicsContext gc,
                                            int x,
                                            int y,
                                            int width,
                                            int height,
                                            float startAngle,
                                            float arcAngle)

      Fills an ellipse arc. Ellipses which focal points are not on the same axis are not supported. The center of the ellipse is defined as the center of the rectangle whose origin is at `(x,y)` (upper-left corner) and whose dimension is `(width,height)`.

      The ellipse arc is drawn from `startAngle` to `startAngle+arcAngle` degrees. The value of `startAngle` is interpreted such that 0 degrees is along the positive x axis.

      A positive angle indicates a counter-clockwise rotation while a negative angle indicates a clockwise rotation.

      The angles are given relative to the rectangle. For instance an angle of 45 degrees is always defined by the line from the center of the rectangle to the upper right corner of the rectangle. Thus for a non squared rectangle angles are skewed along either height or width.

      If either `width` or `height` is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the bounding rectangle of the ellipse.
        `y` - the y coordinate of the bounding rectangle of the ellipse.
        `width` - the width of the ellipse.
        `height` - the height of the ellipse.
        `startAngle` - the start angle of the arc.
        `arcAngle` - the angular distance of the arc.

    - #### drawCircle

          public static void drawCircle​(GraphicsContext gc,
                                        int x,
                                        int y,
                                        int diameter)

      Draws a circle.

      The center of the circle is defined as the center of the square whose origin is at `(x,y)` (upper-left corner) and whose dimension is `(diameter,diameter)`.

      If the given diameter is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the bounding rectangle of the circle.
        `y` - the y coordinate of the bounding rectangle of the circle.
        `diameter` - the diameter of the circle.

    - #### fillCircle

          public static void fillCircle​(GraphicsContext gc,
                                        int x,
                                        int y,
                                        int diameter)

      Fills a circle.

      The center of the circle is defined as the center of the square whose origin is at `(x,y)` (upper-left corner) and whose dimension is `(diameter,diameter)`.

      If the given diameter is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the bounding rectangle of the circle.
        `y` - the y coordinate of the bounding rectangle of the circle.
        `diameter` - the diameter of the circle.

    - #### drawEllipse

          public static void drawEllipse​(GraphicsContext gc,
                                         int x,
                                         int y,
                                         int width,
                                         int height)

      Draws an ellipse. Ellipses which focal points are not on the same axis are not supported. The center of the ellipse is defined as the center of the rectangle whose origin is at `(x,y)` (upper-left corner) and whose dimension is `(width,height)`.

      If either `width` or `height` is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the bounding rectangle of the ellipse.
        `y` - the y coordinate of the bounding rectangle of the ellipse.
        `width` - the width of the ellipse.
        `height` - the height of the ellipse.

    - #### fillEllipse

          public static void fillEllipse​(GraphicsContext gc,
                                         int x,
                                         int y,
                                         int width,
                                         int height)

      Fills an ellipse. Ellipses which focal points are not on the same axis are not supported. The center of the ellipse is defined as the center of the rectangle whose origin is at `(x,y)` (upper-left corner) and whose dimension is `(width,height)`.

      If either `width` or `height` is negative or zero, nothing is drawn.

      Parameters:
        `gc` - the graphics context to use.
        `x` - the x coordinate of the bounding rectangle of the ellipse.
        `y` - the y coordinate of the bounding rectangle of the ellipse.
        `width` - the width of the ellipse.
        `height` - the height of the ellipse.

    - #### drawDisplayRegion

          public static void drawDisplayRegion​(GraphicsContext gc,
                                               int xSource,
                                               int ySource,
                                               int width,
                                               int height,
                                               int xDestination,
                                               int yDestination)

      Draws a region of the display.

      Equivalent to calling `drawDisplayRegion(GraphicsContext, int, int, int, int, int, int, int)` with `GraphicsContext.OPAQUE` as alpha.

      Parameters:
        `gc` - the graphics context to use.
        `xSource` - the x coordinate of the region to copy.
        `ySource` - the y coordinate of the region to copy.
        `width` - the width of the region to copy.
        `height` - the height of the region to copy.
        `xDestination` - the x coordinate to draw at.
        `yDestination` - the y coordinate to draw at.

    - #### drawDisplayRegion

          public static void drawDisplayRegion​(GraphicsContext gc,
                                               int xSource,
                                               int ySource,
                                               int width,
                                               int height,
                                               int xDestination,
                                               int yDestination,
                                               int alpha)

      Draws a region of the display. This methods supports transparent drawings.

      The four points of the source rectangle have the following coordinates: `(xSource,ySource)`, `(xSource+width-1,ySource)`, `(xSource,ySource+height-1)` and `(xSource+width-1,ySource+height-1)`. However, this rectangle is limited to the boundaries of the display.

      In addition with `drawDisplayRegion(GraphicsContext, int, int, int, int, int, int)`, this method allows to specify the global opacity value to apply during the image rendering. This value is clamped between `GraphicsContext.TRANSPARENT` and `GraphicsContext.OPAQUE`.

      Parameters:
        `gc` - the graphics context to use.
        `xSource` - the x coordinate of the region to copy.
        `ySource` - the y coordinate of the region to copy.
        `width` - the width of the region to copy.
        `height` - the height of the region to copy.
        `xDestination` - the x coordinate to draw at.
        `yDestination` - the y coordinate to draw at.
        `alpha` - the alpha to apply to the region.
      Since:
        2.0

    - #### drawString

          public static void drawString​(GraphicsContext gc,
                                        String string,
                                        Font font,
                                        int x,
                                        int y)

      Draws a string.

      This method uses the background color and the ellipsis width which are set in the given `GraphicsContext`.

      The top-left anchor point of the string is defined by the `(x,y)` coordinates. The `font baseline` may be used to set the anchor at the position of the string baseline.

      Parameters:
        `gc` - the graphics context to use.
        `string` - the string.
        `font` - the font to use.
        `x` - the x coordinate of the string.
        `y` - the y coordinate of the string.

    - #### drawSubstring

          public static void drawSubstring​(GraphicsContext gc,
                                           String string,
                                           int offset,
                                           int length,
                                           Font font,
                                           int x,
                                           int y)

      Draws a subset of a string.

      This method uses the background color and the ellipsis width which are set in the given `GraphicsContext`.

      The top-left anchor point of the string is defined by the `(x,y)` coordinates. The `font baseline` may be used to set the anchor at the position of the string baseline.

      Parameters:
        `gc` - the graphics context to use.
        `string` - the string.
        `offset` - the index of the first character of the string.
        `length` - the number of characters of the string.
        `font` - the font to use.
        `x` - the x coordinate of the string.
        `y` - the y coordinate of the string.
      Throws:
        `StringIndexOutOfBoundsException` - if the given offset and length do not specify a valid range within the given string.

    - #### drawChar

          public static void drawChar​(GraphicsContext gc,
                                      char character,
                                      Font font,
                                      int x,
                                      int y)

      Draws a character.

      This method uses the background color and the ellipsis width which are set in the given `GraphicsContext`.

      The top-left anchor point of the character is defined by the `(x,y)` coordinates. The `font baseline` may be used to set the anchor at the position of the character baseline.

      This method only supports characters in the range U+0000 to U+FFFF. It does not handle characters with code points greater than U+FFFF, which are represented as a pair of char values (referred to as "surrogate pair").

      Parameters:
        `gc` - the graphics context to use.
        `character` - the character.
        `font` - the font to use.
        `x` - the x coordinate of the string.
        `y` - the y coordinate of the string.

    - #### drawRenderableString

          public static void drawRenderableString​(GraphicsContext gc,
                                                  RenderableString string,
                                                  int x,
                                                  int y)

      Draws the string using the font and given graphics context color. Same specification than `drawString(GraphicsContext, String, Font, int, int)`
      Parameters:
        `gc` - the graphics context to use.
        `string` - the renderable string to render.
        `x` - the x coordinate of the anchor point.
        `y` - the y coordinate of the anchor point.
      See Also:
        `drawString(GraphicsContext, String, Font, int, int)`

    - #### drawImage

          public static void drawImage​(GraphicsContext gc,
                                       Image image,
                                       int x,
                                       int y)

      Draws the image at the given anchor top-left point.

      Equivalent to calling `drawImage(GraphicsContext, Image, int, int, int)` with `GraphicsContext.OPAQUE` as alpha.

      Parameters:
        `gc` - the graphics context to use.
        `image` - the image to render.
        `x` - the x coordinate of the anchor top-left point.
        `y` - the y coordinate of the anchor top-left point.

    - #### drawImage

          public static void drawImage​(GraphicsContext gc,
                                       Image image,
                                       int x,
                                       int y,
                                       int alpha)

      Draws the image at the given anchor top-left point.

      In addition with `drawImage(GraphicsContext, Image, int, int)`, this method allows to specify the global opacity value to apply during the image rendering. This value is clamped between `GraphicsContext.TRANSPARENT` and `GraphicsContext.OPAQUE`.

      Parameters:
        `gc` - the graphics context to use.
        `image` - the image to render.
        `x` - the x coordinate of the anchor top-left point.
        `y` - the y coordinate of the anchor top-left point.
        `alpha` - the global opacity rendering value, between 0 (transparent) and 255 (opaque).
      Since:
        2.0

    - #### drawImageRegion

          public static void drawImageRegion​(GraphicsContext gc,
                                             Image image,
                                             int xSource,
                                             int ySource,
                                             int width,
                                             int height,
                                             int xDestination,
                                             int yDestination)

      Draws a region of the image.

      Equivalent to calling `drawImageRegion(GraphicsContext, Image, int, int, int, int, int, int, int)` with `GraphicsContext.OPAQUE` as alpha.

      Parameters:
        `gc` - the graphics context to use.
        `image` - the image to render.
        `xSource` - the x coordinate of the upper-left corner of the region to copy.
        `ySource` - the y coordinate of the upper-left corner of the region to copy.
        `width` - the width of the region to copy.
        `height` - the height of the region to copy.
        `xDestination` - the x coordinate of the anchor top-left point in the destination.
        `yDestination` - the y coordinate of the anchor top-left point in the destination.

    - #### drawImageRegion

          public static void drawImageRegion​(GraphicsContext gc,
                                             Image image,
                                             int xSource,
                                             int ySource,
                                             int width,
                                             int height,
                                             int xDestination,
                                             int yDestination,
                                             int alpha)

      Draws a region of an image.

      The region of the image to draw is given relative to the image (origin at the upper-left corner) as a rectangle.

      If the specified source region exceeds the image bounds, the copied region is limited to the image boundary. If the copied region goes out of the bounds of the graphics context area, pixels out of the range will not be drawn.

      In addition with `drawImageRegion(GraphicsContext, Image, int, int, int, int, int, int)`, this method allows to specify the global opacity value to apply during the image rendering. This value is clamped between `GraphicsContext.TRANSPARENT` and `GraphicsContext.OPAQUE`.

      Parameters:
        `gc` - the graphics context to use.
        `image` - the image to render.
        `xSource` - the x coordinate of the upper-left corner of the region to copy.
        `ySource` - the y coordinate of the upper-left corner of the region to copy.
        `width` - the width of the region to copy.
        `height` - the height of the region to copy.
        `xDestination` - the x coordinate of the anchor top-left point in the destination.
        `yDestination` - the y coordinate of the anchor top-left point in the destination.
        `alpha` - the alpha to apply to the region.
      Since:
        2.0