From 12bba32b5dddb0129e44e45b57b1b3cdbc8e7dd5 Mon Sep 17 00:00:00 2001 From: neauoire Date: Wed, 25 Mar 2020 19:30:33 +0900 Subject: [PATCH] Improved controls --- examples/projects/elementary-theme.lisp | 82 +++++++++++++++++++++++++ index.html | 18 ++---- scripts/client.js | 2 +- scripts/library.js | 32 ++-------- 4 files changed, 93 insertions(+), 41 deletions(-) create mode 100644 examples/projects/elementary-theme.lisp diff --git a/examples/projects/elementary-theme.lisp b/examples/projects/elementary-theme.lisp new file mode 100644 index 0000000..79252b3 --- /dev/null +++ b/examples/projects/elementary-theme.lisp @@ -0,0 +1,82 @@ +(clear) +; +(open $path) + +; picker to elementary + +(def unit 40) +(def f + (get-frame)) +(def pos-row-1 + (sub f:h + (mul unit 4))) +(def pos-row-2 + (sub f:h + (mul unit 2))) + +; color picker + +(def color-1 + (pick + (guide + (rect $xy unit unit)))) +(def color-2 + (pick + (guide + (rect $xy unit unit)))) +(def color-3 + (pick + (guide + (rect $xy unit unit)))) +(def color-4 + (pick + (guide + (rect $xy unit unit)))) +(def color-5 + (pick + (guide + (rect $xy unit unit)))) +(def color-6 + (pick + (guide + (rect $xy unit unit)))) +(def color-7 + (pick + (guide + (rect $xy unit unit)))) +(def color-8 + (pick + (guide + (rect $xy unit unit)))) + +; display + +(fill + (circle + (mul unit 2) pos-row-1 unit) color-1) +(fill + (circle + (mul unit 4) pos-row-1 unit) color-2) +(fill + (circle + (mul unit 6) pos-row-1 unit) color-3) +(fill + (circle + (mul unit 8) pos-row-1 unit) color-4) +(fill + (circle + (mul unit 3) pos-row-2 unit) color-5) +(fill + (circle + (mul unit 5) pos-row-2 unit) color-6) +(fill + (circle + (mul unit 7) pos-row-2 unit) color-7) +(fill + (circle + (mul unit 9) pos-row-2 unit) color-8) +; +(def res + (add color-1:hex ":" color-2:hex ":" color-3:hex ":" color-4:hex ":" color-5:hex ":" color-6:hex ":" color-7:hex ":" color-8:hex)) +(echo + (add res res)) \ No newline at end of file diff --git a/index.html b/index.html index 7b8d709..cedf814 100644 --- a/index.html +++ b/index.html @@ -539,7 +539,7 @@ function Client () { this.acels.set('File', 'New', 'CmdOrCtrl+N', () => { this.source.new(); this.surface.clear(); this.commander.clear() }) this.acels.set('File', 'Save', 'CmdOrCtrl+S', () => { this.source.write('ronin', 'lisp', this.commander._input.value, 'text/plain') }) this.acels.set('File', 'Export Image', 'CmdOrCtrl+E', () => { this.source.write('ronin', 'png', this.surface.el.toDataURL('image/png', 1.0), 'image/png') }) - this.acels.set('File', 'Open', 'CmdOrCtrl+O', () => { this.source.open('lisp', this.whenOpen) }) + this.acels.set('File', 'Open', 'CmdOrCtrl+U', () => { this.source.open('lisp', this.whenOpen) }) this.acels.add('Edit', 'undo') this.acels.add('Edit', 'redo') this.acels.add('Edit', 'cut') @@ -1353,18 +1353,6 @@ function Library (client) { [-1, 9, -1], [-1, -1, -1]] } - this.dir = (path = this.dirpath()) => { // Returns the content of a directory. - } - this.file = (path = this.filepath()) => { // Returns the content of a file. - } - this.dirpath = (path = this.filepath()) => { // Returns the path of a directory. - } - this.filepath = (path = client.source.path) => { // Returns the path of a file. - } - this.dirname = (path = this.filepath()) => { // Returns the name of a folder. - } - this.filename = (path = this.filepath()) => { // Returns the name of a file. - } this.offset = (a, b) => { // Offsets pos a with pos b, returns a. a.x += b.x a.y += b.y @@ -1373,6 +1361,10 @@ function Library (client) { this.distance = (a, b) => { // Get distance between positions. return Math.sqrt(((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y))) } + this.print = (value) => { + client.source.write('ronin-print', 'txt', value, 'text/plain') + return value + } this.echo = (...args) => { // Print arguments to interface. client.log(args) return args diff --git a/scripts/client.js b/scripts/client.js index d9673d3..5ad1bf9 100644 --- a/scripts/client.js +++ b/scripts/client.js @@ -47,7 +47,7 @@ function Client () { this.acels.set('File', 'New', 'CmdOrCtrl+N', () => { this.source.new(); this.surface.clear(); this.commander.clear() }) this.acels.set('File', 'Save', 'CmdOrCtrl+S', () => { this.source.write('ronin', 'lisp', this.commander._input.value, 'text/plain') }) this.acels.set('File', 'Export Image', 'CmdOrCtrl+E', () => { this.source.write('ronin', 'png', this.surface.el.toDataURL('image/png', 1.0), 'image/png') }) - this.acels.set('File', 'Open', 'CmdOrCtrl+O', () => { this.source.open('lisp', this.whenOpen) }) + this.acels.set('File', 'Open', 'CmdOrCtrl+U', () => { this.source.open('lisp', this.whenOpen) }) this.acels.add('Edit', 'undo') this.acels.add('Edit', 'redo') diff --git a/scripts/library.js b/scripts/library.js index 9c4ff76..61a7908 100644 --- a/scripts/library.js +++ b/scripts/library.js @@ -5,7 +5,6 @@ function Library (client) { // IO - this.open = async (name, scale = 1) => { // Import a graphic and scale canvas to fit. const img = client.cache.get(name) if (!img) { client.log('No data for ' + name); return } @@ -544,32 +543,6 @@ function Library (client) { [-1, -1, -1]] } - // File System - - this.dir = (path = this.dirpath()) => { // Returns the content of a directory. - // return fs.existsSync(path) ? fs.readdirSync(path) : [] - } - - this.file = (path = this.filepath()) => { // Returns the content of a file. - // return fs.existsSync(path) ? fs.readFileSync(path, 'utf8') : '' - } - - this.dirpath = (path = this.filepath()) => { // Returns the path of a directory. - // return require('path').dirname(path) - } - - this.filepath = (path = client.source.path) => { // Returns the path of a file. - // return path - } - - this.dirname = (path = this.filepath()) => { // Returns the name of a folder. - // return require('path').basename(require('path').dirname(path)) - } - - this.filename = (path = this.filepath()) => { // Returns the name of a file. - // return require('path').parse(path).name - } - this.offset = (a, b) => { // Offsets pos a with pos b, returns a. a.x += b.x a.y += b.y @@ -580,6 +553,11 @@ function Library (client) { return Math.sqrt(((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y))) } + this.print = (value) => { + client.source.write('ronin-print', 'txt', value, 'text/plain') + return value + } + this.echo = (...args) => { // Print arguments to interface. client.log(args) return args