More tests and docs.
This commit is contained in:
parent
1ee2532087
commit
7a1a2850c2
3 changed files with 21 additions and 5 deletions
|
@ -591,7 +591,7 @@ proc strokePolygon*(ctx: Context, pos: Vec2, size: float32, sides: int) =
|
|||
ctx.stroke(path)
|
||||
|
||||
proc drawImage*(ctx: Context, image: Image, dx, dy, dWidth, dHeight: float32) =
|
||||
## Draws an image onto the canvas.
|
||||
## Draws a source image onto the destination image.
|
||||
var path: Path
|
||||
var imageMat = ctx.mat * translate(vec2(dx, dy)) * scale(vec2(
|
||||
dWidth / image.width.float32,
|
||||
|
@ -602,15 +602,15 @@ proc drawImage*(ctx: Context, image: Image, dx, dy, dWidth, dHeight: float32) =
|
|||
ctx.fill(path)
|
||||
|
||||
proc drawImage*(ctx: Context, image: Image, dx, dy: float32) =
|
||||
## Draws an image onto the canvas.
|
||||
## Draws a source image onto the destination image.
|
||||
ctx.drawImage(image, dx, dx, image.width.float32, image.height.float32)
|
||||
|
||||
proc drawImage*(ctx: Context, image: Image, pos: Vec2) =
|
||||
## Draws an image onto the canvas.
|
||||
## Draws a source image onto the destination image.
|
||||
ctx.drawImage(image, pos.x, pos.y)
|
||||
|
||||
proc drawImage*(ctx: Context, image: Image, rect: Rect) =
|
||||
## Draws an image onto the canvas.
|
||||
## Draws a source image onto the destination image.
|
||||
ctx.drawImage(image, rect.x, rect.y, rect.w, rect.h)
|
||||
|
||||
proc drawImage*(
|
||||
|
@ -619,6 +619,14 @@ proc drawImage*(
|
|||
sx, sy, sWidth, sHeight,
|
||||
dx, dy, dWidth, dHeight: float32
|
||||
) =
|
||||
## Draws an image onto the canvas.
|
||||
## Draws a source image onto the destination image.
|
||||
var image = image.subImage(sx.int, sy.int, sWidth.int, sHeight.int)
|
||||
ctx.drawImage(image, dx, dx, image.width.float32, image.height.float32)
|
||||
|
||||
proc drawImage*(ctx: Context, image: Image, src, dest: Rect) =
|
||||
## Draws a source image onto the destination image.
|
||||
ctx.drawImage(
|
||||
image,
|
||||
src.x, src.y, src.w, src.h,
|
||||
dest.x, dest.y, dest.w, dest.h
|
||||
)
|
||||
|
|
BIN
tests/images/context/draw_image_rhino2.png
Normal file
BIN
tests/images/context/draw_image_rhino2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
|
@ -594,3 +594,11 @@ block:
|
|||
rhino = readImage("tests/images/rhino.png")
|
||||
ctx.drawImage(rhino, 33, 71, 104, 124, 21, 20, 87, 104);
|
||||
image.writeFile("tests/images/context/draw_image_rhino.png")
|
||||
|
||||
block:
|
||||
let
|
||||
image = newImage(300, 227)
|
||||
ctx = newContext(image)
|
||||
rhino = readImage("tests/images/rhino.png")
|
||||
ctx.drawImage(rhino, rect(33, 71, 104, 124), rect(21, 20, 87, 104));
|
||||
image.writeFile("tests/images/context/draw_image_rhino2.png")
|
||||
|
|
Loading…
Reference in a new issue