Added callback to open, fixes #49

This commit is contained in:
Devine Lu Linvega 2019-07-15 14:13:42 +09:00
parent b8d076234d
commit 467834115a
6 changed files with 26 additions and 18 deletions

View File

@ -1,6 +1,6 @@
function Library (ronin) {
this.open = (path, w = 1, h = 1) => {
ronin.surface.open(path, { w, h })
this.open = (path, callback) => {
ronin.surface.open(path, callback)
return path
}
@ -288,9 +288,9 @@ function Library (ronin) {
b = b.toString()
}
if (a !== b) {
console.warn('failed ' + name, a)
console.warn('failed ' + name, a, b)
} else {
console.log('passed ' + name, a, b)
console.log('passed ' + name, a)
}
return a === b
}

View File

@ -112,13 +112,17 @@ function Surface (ronin) {
// IO
this.open = function (path, scale) {
this.open = function (path, callback = () => {}) {
const img = new Image()
img.src = path
img.onload = () => {
ronin.log(`Image(${img.width}x${img.height}), scale:${scale.w}:${scale.h}`)
this.resize({ w: img.width * scale.w, h: img.height * scale.h })
this.context.drawImage(img, 0, 0, img.width * scale.w, img.height * scale.h)
const rect = { w: img.width, h: img.height }
this.fitWindow(rect)
this.resize(rect)
this.context.drawImage(img, 0, 0, img.width, img.height)
if (typeof callback === 'function') {
callback()
}
}
}

View File

@ -1,4 +0,0 @@
(
(def value 12)
(def addOne (lambda (a) (add a 1)))
)

13
examples/open.lisp Normal file
View File

@ -0,0 +1,13 @@
; scale file
(
; Filter
(def filter-action
(lambda () (pixels
(frame)
saturation
0.5)
))
(open (path "/Users/VillaMoirai/Desktop/clip.jpg") filter-action)
)

View File

@ -1,7 +1,5 @@
(
(run "./include.lisp")
(run "../examples/recursive.lisp")
(echo value)
(echo (addOne value))
)

View File

@ -1,3 +0,0 @@
; scale file
(open ($path) 0.25 0.25)