diff --git a/desktop/sources/index.html b/desktop/sources/index.html index c4d2875..0b6cdc1 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -40,7 +40,6 @@ ronin.controller.addRole('default', 'Edit', 'delete') ronin.controller.addRole('default', 'Edit', 'selectall') - ronin.controller.add("default","Project","Run",() => { ronin.commander.run(); },"CmdOrCtrl+R"); ronin.controller.commit(); diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index a840a45..3aebf00 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -11,17 +11,13 @@ function Commander (ronin) { host.appendChild(this.el) this._input.addEventListener('input', this.onInput) + + window.addEventListener('dragover', this.drag) + window.addEventListener('drop', this.drop) } this.start = function () { - this._input.value = ` -(stroke (rect 15 15 120 80) 2 "red") -(fill (rect 30 30 120 80) 2 "blue") -(clear (rect 45 45 45 45)) -`.trim() - this._status.textContent = 'Idle, RUN(cmd+enter).' - this._input.focus() this.run() } @@ -33,6 +29,11 @@ function Commander (ronin) { inter.toPixels() } + this.load = function (txt) { + this._input.value = txt + this.run() + } + this.update = function () { } @@ -44,4 +45,24 @@ function Commander (ronin) { this.getQuery = function () { } + + // Events + + this.drag = function (e) { + e.stopPropagation() + e.preventDefault() + e.dataTransfer.dropEffect = 'copy' + } + + this.drop = function (e) { + e.preventDefault() + e.stopPropagation() + const file = e.dataTransfer.files[0] + if (!file || !file.name || file.name.indexOf('.lisp') < 0) { console.warn('File', 'Not a .lisp file.'); return } + const reader = new FileReader() + reader.onload = function (e) { + ronin.commander.load(e.target.result) + } + reader.readAsText(file) + } } diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index bb94cea..712f9b8 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -2,16 +2,22 @@ function Library (ronin) { this.clear = (rect = this.select_all()) => { } + // Rects + this.rect = (x, y, w, h) => { return { x, y, w, h } } + this.frame = () => { + return { x: 0, y: 0, w: Math.floor(window.innerWidth / 2) - 15, h: Math.floor(window.innerHeight) - 30 } + } + this.stroke = (rect, thickness, color) => { ronin.surface.stroke(rect, thickness, color) return rect } - this.fill = (rect, thickness, color) => { + this.fill = (rect = this.frame(), thickness, color) => { ronin.surface.fill(rect, thickness, color) return rect } @@ -20,8 +26,4 @@ function Library (ronin) { ronin.surface.clear(rect) return rect } - - this.select_all = () => { - ronin.surface.getRect() - } } diff --git a/examples/test1.lisp b/examples/test1.lisp new file mode 100644 index 0000000..ccaf52a --- /dev/null +++ b/examples/test1.lisp @@ -0,0 +1,5 @@ +; test file + +((stroke (rect 15 15 120 80) 2 "red") +(fill (rect 30 30 120 80) 2 "blue") +(clear (rect 45 45 45 45))) \ No newline at end of file