From beadb53b1349d49dffe28d8ded9d513a50173374 Mon Sep 17 00:00:00 2001 From: Quentin Leonetti Date: Sun, 14 Jul 2019 04:43:47 +0200 Subject: [PATCH] add callback to draw --- desktop/sources/scripts/surface.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index 98f24cf..2cdb61f 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -94,13 +94,16 @@ function Surface (ronin) { } } - this.draw = function (path, rect = this.getFrame()) { + this.draw = function (path, rect = this.getFrame(), callback = () => {}) { const img = new Image() img.src = path img.onload = () => { const ratio = img.width / img.height const scale = rect.w / img.width this.context.drawImage(img, rect.x, rect.y, rect.w, img.height * scale) + if (typeof callback === 'function') { + callback() + } } }