From d82d3a59fbd48d378fcbc71f4358f029bfd946ed Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 30 Jul 2019 20:23:51 +0900 Subject: [PATCH] various optimizations --- WORKSHOP.md | 2 +- desktop/sources/scripts/commander.js | 6 ++++-- desktop/sources/scripts/library.js | 3 ++- desktop/sources/scripts/surface.js | 7 +++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/WORKSHOP.md b/WORKSHOP.md index 35aa200..9f6b961 100644 --- a/WORKSHOP.md +++ b/WORKSHOP.md @@ -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). diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index 627cba6..da36906 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -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)`) diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 456c6a0..ce64b61 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -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') diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index 0445146..9e5e11c 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -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 () {