various optimizations

This commit is contained in:
Devine Lu Linvega 2019-07-30 20:23:51 +09:00
parent 83f3063bba
commit d82d3a59fb
4 changed files with 12 additions and 6 deletions

View File

@ -209,7 +209,7 @@ We can define a function that triggers when the `mouse-down` event is detected,
(e)
(fill e:circle "red"))
; use the function
(on "mouse-up" draw-rect)
(on "mouse-move" draw-rect)
```
For more examples of functions, see the [examples](https://github.com/hundredrabbits/Ronin/tree/master/examples).

View File

@ -38,7 +38,9 @@ function Commander (ronin) {
this.run = (txt = this._input.value) => {
if (this._input.value.indexOf('$') > -1) { console.warn('$ is present.'); return }
ronin.bindings = {}
ronin.surface.maximize()
if (this._input.value.trim() === '') {
ronin.surface.maximize()
}
ronin.interpreter.run(txt)
}
@ -149,7 +151,7 @@ function Commander (ronin) {
this._input.value = this.cache.replace('$line', `(line ${line.a.x} ${line.a.y} ${line.b.x} ${line.b.y})`)
} else if (word.substr(0, 6) === 'circle' && shape.circle) {
const circle = shape.circle
this._input.value = this.cache.replace('$circle', `(circle ${circle.cx} ${circle.cy} ${circle.r})`)
this._input.value = this.cache.replace('$circle', `(circle ${circle.cx} ${circle.cy} ${circle.r.toFixed(2)})`)
} else if (word.substr(0, 4) === 'drag' && shape.line) {
const rect = shape.rect
this._input.value = this.cache.replace('$drag', `(drag (rect ${rect.x} ${rect.y} ${rect.w} ${rect.h}) $line)`)

View File

@ -145,7 +145,8 @@ function Library (ronin) {
return this.pos(rect.w / 2, rect.h / 2)
}
this.resize = async (w, h, fit = true) => { // Resizes the canvas to target w and h, returns the rect.
this.resize = async (w = ronin.surface.bounds().w, h = ronin.surface.bounds().h, fit = true) => { // Resizes the canvas to target w and h, returns the rect.
if (w === this.frame().w && h === this.frame().h) { return }
const rect = { x: 0, y: 0, w, h }
const a = document.createElement('img')
const b = document.createElement('img')

View File

@ -58,7 +58,6 @@ function Surface (ronin) {
this.trace(shape, context)
if (isText(shape)) {
context.textAlign = shape.a
console.log(shape)
context.font = `${shape.p}px ${shape.f}`
context.fillText(shape.t, shape.x, shape.y)
} else if (isSvg(shape)) {
@ -241,7 +240,11 @@ function Surface (ronin) {
}
this.maximize = function () {
this.resize({ x: 0, y: 0, w: ((window.innerWidth - 60) * this.ratio), h: ((window.innerHeight - 60) * this.ratio), t: 'rect' })
this.resize(this.bounds())
}
this.bounds = function () {
return { x: 0, y: 0, w: ((window.innerWidth - 60) * this.ratio), h: ((window.innerHeight - 60) * this.ratio), t: 'rect' }
}
this.onResize = function () {