Added callback to open, fixes #49
This commit is contained in:
parent
b8d076234d
commit
467834115a
@ -1,6 +1,6 @@
|
|||||||
function Library (ronin) {
|
function Library (ronin) {
|
||||||
this.open = (path, w = 1, h = 1) => {
|
this.open = (path, callback) => {
|
||||||
ronin.surface.open(path, { w, h })
|
ronin.surface.open(path, callback)
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,9 +288,9 @@ function Library (ronin) {
|
|||||||
b = b.toString()
|
b = b.toString()
|
||||||
}
|
}
|
||||||
if (a !== b) {
|
if (a !== b) {
|
||||||
console.warn('failed ' + name, a)
|
console.warn('failed ' + name, a, b)
|
||||||
} else {
|
} else {
|
||||||
console.log('passed ' + name, a, b)
|
console.log('passed ' + name, a)
|
||||||
}
|
}
|
||||||
return a === b
|
return a === b
|
||||||
}
|
}
|
||||||
|
@ -112,13 +112,17 @@ function Surface (ronin) {
|
|||||||
|
|
||||||
// IO
|
// IO
|
||||||
|
|
||||||
this.open = function (path, scale) {
|
this.open = function (path, callback = () => {}) {
|
||||||
const img = new Image()
|
const img = new Image()
|
||||||
img.src = path
|
img.src = path
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
ronin.log(`Image(${img.width}x${img.height}), scale:${scale.w}:${scale.h}`)
|
const rect = { w: img.width, h: img.height }
|
||||||
this.resize({ w: img.width * scale.w, h: img.height * scale.h })
|
this.fitWindow(rect)
|
||||||
this.context.drawImage(img, 0, 0, img.width * scale.w, img.height * scale.h)
|
this.resize(rect)
|
||||||
|
this.context.drawImage(img, 0, 0, img.width, img.height)
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
(
|
|
||||||
(def value 12)
|
|
||||||
(def addOne (lambda (a) (add a 1)))
|
|
||||||
)
|
|
13
examples/open.lisp
Normal file
13
examples/open.lisp
Normal 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)
|
||||||
|
)
|
@ -1,7 +1,5 @@
|
|||||||
(
|
(
|
||||||
(run "./include.lisp")
|
(run "../examples/recursive.lisp")
|
||||||
|
|
||||||
(echo value)
|
(echo value)
|
||||||
|
|
||||||
(echo (addOne value))
|
(echo (addOne value))
|
||||||
)
|
)
|
@ -1,3 +0,0 @@
|
|||||||
; scale file
|
|
||||||
|
|
||||||
(open ($path) 0.25 0.25)
|
|
Loading…
x
Reference in New Issue
Block a user