Draw stretch with (draw $line)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
function Library (ronin) {
|
||||
this.import = async (path, rect) => { // Imports a graphic file with format.
|
||||
this.import = async (path, shape) => { // Imports a graphic file with format.
|
||||
const img = new Image()
|
||||
img.src = path
|
||||
return ronin.surface.draw(img, rect)
|
||||
return ronin.surface.draw(img, shape)
|
||||
}
|
||||
|
||||
this.export = (path, format = 'image/png', quality = 1.0) => { // Exports a graphic file with format.
|
||||
|
||||
@@ -133,11 +133,17 @@ function Surface (ronin) {
|
||||
})
|
||||
}
|
||||
|
||||
this.draw = function (img, rect = this.getFrame()) {
|
||||
this.draw = function (img, shape = this.getFrame()) {
|
||||
return new Promise(resolve => {
|
||||
img.onload = () => {
|
||||
ronin.log(`Draw ${img.width}x${img.height}`)
|
||||
this.context.drawImage(img, rect.x, rect.y, rect.w, rect.h) // no strect: img.height * (rect.w / img.width)
|
||||
if (isLine(shape)) {
|
||||
this.context.drawImage(img, shape.a.x, shape.a.y, shape.b.x - shape.a.x, shape.b.y - shape.a.y)
|
||||
} else if (isRect(shape)) {
|
||||
this.context.drawImage(img, shape.x, shape.y, shape.w, img.height * (shape.w / img.width))
|
||||
} else {
|
||||
this.context.drawImage(img, shape.x, shape.y, img.width, img.height)
|
||||
}
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user