draw
Draws vertexCount vertices starting at firstVertex with the bound pipeline. Pass the Int parameters by name.
Draws image, or the rectangle of it sourceWidth pixels wide and sourceHeight pixels tall whose top-left corner is at column sourceX and row sourceY, over this image with that corner at column x and row y, blending each of its pixels by its alpha.
A fully opaque pixel of image replaces the pixel under it and a fully transparent one leaves it as it is. Any other is blended over it with the "over" rule for colors whose alpha is not premultiplied, as the rim of fillCircle is: the result's alpha counts both pixels, and a pixel drawn over a transparent one keeps its own color and alpha. The parts that fall outside this image are left out, so a rectangle that lands wholly outside, or has a sourceWidth or sourceHeight of 0, draws nothing. image is never changed, and may be this image, which is then read as it was before the call.
Without a source rectangle the whole of image is drawn; sourceWidth and sourceHeight default to the rest of image right of and below the corner, so passing only sourceX and sourceY cuts off its top and left. The rectangle must lie inside image. Pass sourceX, sourceY, sourceWidth and sourceHeight by name; x and y are a conventional pair.
Throws
if sourceX, sourceY, sourceWidth or sourceHeight is negative, if the corner at sourceX and sourceY lies past the right or bottom edge of image, or if the rectangle runs past the right or bottom edge of image.
Samples
val stamp = Image(2, 2)
stamp.fill(Color.RED)
stamp[0, 1] = Color.RED.withAlpha(0.5f)
stamp[1, 1] = Color.TRANSPARENT
val sheet = Image(4, 4)
sheet.fill(Color.WHITE)
sheet.draw(stamp, x = 1, y = 1)
// An opaque pixel replaces the one under it, a half transparent one blends with it, and a transparent one leaves it.
assertPrints(sheet[1, 1], "Color(#ff0000ff)")
assertPrints(sheet[1, 2], "Color(#ff7f7fff)")
assertPrints(sheet[2, 2], "Color(#ffffffff)")
// The part of the stamp outside the sheet is left out.
sheet.draw(stamp, x = 3, y = 3)
assertPrints(sheet[3, 3], "Color(#ff0000ff)")
// A source rectangle draws only part of an image, such as one picture cut out of a sheet.
val icon = Image(2, 2)
icon.draw(sheet, x = 0, y = 0, sourceX = 1, sourceY = 1, sourceWidth = 2, sourceHeight = 2)
assertPrints(icon[0, 0], "Color(#ff0000ff)")
assertPrints(icon[1, 1], "Color(#ffffffff)")