Class Canvas

java.lang.Object
org.openpatch.scratch.extension.Canvas

public final class Canvas extends Object
What a layer drawer draws with: it records into the draw list, nothing is drawn at once and no OpenGL is exposed. Coordinates are those of the layer: world coordinates (Scratch's, y up) for the world layers, stage coordinates for the UI layer and the overlay. Game thread only, and only during the drawer's call.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    clip(double x, double y, double width, double height)
    Draws only inside a rectangle (axis-aligned on the screen) until noClip().
    void
    drawImage(String path, double x, double y, double width, double height)
    An image (a file or a built-in sprite name), centred on a point.
    void
    drawImageQuad(String path, int sx, int sy, int sw, int sh, double[] corners)
    A region of an image on any quad: turned, mirrored, sheared.
    void
    drawImageRegion(String path, int sx, int sy, int sw, int sh, double x, double y, double width, double height)
    A region of an image, centred on a point: one tile of a tileset, one glyph of a bitmap font.
    void
    drawOutline(double[] xs, double[] ys, Color stroke, double weight)
    The outline of a polygon.
    void
    drawPolygon(double[] xs, double[] ys, Color fill)
    A filled polygon, concave ones included.
    void
    drawRectangle(double x, double y, double width, double height, Color fill)
    A filled rectangle centred on a point.
    void
    drawText(String text, double x, double y, double size, Color color)
    A line of text whose first baseline starts at a point, in the default font.
    int
     
    int
     
    void
    Draws everywhere again.
    void
    setOpacity(double opacity)
     

    Methods inherited from class Object

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

    • setOpacity

      public void setOpacity(double opacity)
      Parameters:
      opacity - how opaque what follows is drawn, 0 to 1
    • drawImage

      public void drawImage(String path, double x, double y, double width, double height)
      An image (a file or a built-in sprite name), centred on a point.
      Parameters:
      path - the image
      x - x of its centre
      y - y of its centre
      width - its width
      height - its height
    • drawImageRegion

      public void drawImageRegion(String path, int sx, int sy, int sw, int sh, double x, double y, double width, double height)
      A region of an image, centred on a point: one tile of a tileset, one glyph of a bitmap font.
      Parameters:
      path - the image
      sx - the region's left edge in image pixels
      sy - its top edge
      sw - its width
      sh - its height
      x - x of the centre
      y - y of the centre
      width - the width to draw it at
      height - the height to draw it at
    • drawImageQuad

      public void drawImageQuad(String path, int sx, int sy, int sw, int sh, double[] corners)
      A region of an image on any quad: turned, mirrored, sheared.
      Parameters:
      path - the image
      sx - the region's left edge in image pixels
      sy - its top edge
      sw - its width
      sh - its height
      corners - where the region's top-left, top-right, bottom-right and bottom-left corners go: x0, y0, …, x3, y3
    • drawPolygon

      public void drawPolygon(double[] xs, double[] ys, Color fill)
      A filled polygon, concave ones included.
      Parameters:
      xs - x of every corner
      ys - y of every corner, in the same order
      fill - its colour
    • drawOutline

      public void drawOutline(double[] xs, double[] ys, Color stroke, double weight)
      The outline of a polygon.
      Parameters:
      xs - x of every corner
      ys - y of every corner
      stroke - the outline's colour
      weight - the outline's width
    • drawRectangle

      public void drawRectangle(double x, double y, double width, double height, Color fill)
      A filled rectangle centred on a point.
      Parameters:
      x - x of its centre
      y - y of its centre
      width - its width
      height - its height
      fill - its colour
    • drawText

      public void drawText(String text, double x, double y, double size, Color color)
      A line of text whose first baseline starts at a point, in the default font.
      Parameters:
      text - the text
      x - where it starts
      y - its baseline
      size - the font size
      color - the colour of the letters
    • clip

      public void clip(double x, double y, double width, double height)
      Draws only inside a rectangle (axis-aligned on the screen) until noClip().
      Parameters:
      x - x of its centre
      y - y of its centre
      width - its width
      height - its height
    • noClip

      public void noClip()
      Draws everywhere again.
    • imageWidth

      public int imageWidth(String path)
      Parameters:
      path - an image or a built-in sprite name
      Returns:
      its width in pixels
    • imageHeight

      public int imageHeight(String path)
      Parameters:
      path - an image or a built-in sprite name
      Returns:
      its height in pixels