diff options
author | Devine Lu Linvega <[email protected]> | 2018-10-16 11:45:21 +1200 |
---|---|---|
committer | Devine Lu Linvega <[email protected]> | 2018-10-16 11:45:21 +1200 |
commit | bb883fec9ee7d20a3c06a6d02cc27e4b10852ea6 (patch) | |
tree | c5a095177449445c51a5159eed6fc115c58ac217 | |
parent | 08793bac8265aa9f4465f07ac198e7fc69aa2426 (diff) | |
download | Orca-bb883fec9ee7d20a3c06a6d02cc27e4b10852ea6.tar.gz Orca-bb883fec9ee7d20a3c06a6d02cc27e4b10852ea6.zip |
Block copy/paste
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | desktop/core/pico.js | 34 | ||||
-rw-r--r-- | desktop/sources/scripts/cursor.js | 24 | ||||
-rw-r--r-- | desktop/sources/scripts/keyboard.js | 2 |
4 files changed, 55 insertions, 9 deletions
@@ -88,7 +88,9 @@ The idea is to build a synth/mini sequencer, here's some tasks I need to tackle [ ] custom synth functions, like `:SYN[ADSR](C)` [ ] "I wanna be able to 1000x fastforward my pico programs" [ ] sub programs scope -[ ] block copy-paste +[ ] block cut +[ ] block delete +[ ] block add glyph ## Extras diff --git a/desktop/core/pico.js b/desktop/core/pico.js index 9e334f5..1ca12cb 100644 --- a/desktop/core/pico.js +++ b/desktop/core/pico.js @@ -122,6 +122,40 @@ function Pico (w, h) { return x + (this.w * y) } + // Blocks + + this.getBlock = function(x,y,w,h) + { + let _y = y + const block = [] + while(_y < y+h){ + let _x = x + const line = [] + while(_x < x+w){ + line.push(this.glyphAt(_x,_y)) + _x++ + } + block.push(line) + _y++ + } + return block + } + + this.addBlock = function(x,y,block) + { + if(!block || block.length == 0){ this.terminal.log('Nothing to paste'); return; } + + let _y = y + for(const lineId in block){ + let _x = x + for(const glyphId in block[lineId]){ + this.add(_x,_y,block[lineId][glyphId]) + _x++ + } + _y++ + } + } + // Locks this.isLocked = function (x, y) { diff --git a/desktop/sources/scripts/cursor.js b/desktop/sources/scripts/cursor.js index 68574f0..e9bd78f 100644 --- a/desktop/sources/scripts/cursor.js +++ b/desktop/sources/scripts/cursor.js @@ -1,11 +1,15 @@ 'use strict' -function Cursor() +function Cursor(terminal) { + this.terminal = terminal + this.x = 0 this.y = 0 - this.w =1 - this.h =1 + this.w = 1 + this.h = 1 + + this.block = [] this.move = function (x, y) { this.x = clamp(this.x + x, 0, pico.w - 1) @@ -14,8 +18,8 @@ function Cursor() } this.scale = function(x, y){ - this.w = clamp(this.w + x, 1, 10) - this.h = clamp(this.h - y, 1, 10) + this.w = clamp(this.w + x, 1, 30) + this.h = clamp(this.h - y, 1, 30) terminal.update() } @@ -25,7 +29,13 @@ function Cursor() } this.copy = function(){ - console.log('copy',this.x,this.y,this.w,this.h) + this.terminal.log(`Copy ${this.x},${this.y}[${this.w}x${this.h}]`) + this.block = this.terminal.pico.getBlock(this.x,this.y,this.w,this.h) + } + + this.paste = function(){ + this.terminal.log(`Paste ${this.x},${this.y}[${this.w}x${this.h}]`) + this.terminal.pico.addBlock(this.x,this.y,this.block) } this.insert = function (g) { @@ -40,7 +50,7 @@ function Cursor() const g = pico.glyphAt(this.x, this.y) return pico.docs[g] ? pico.docs[g] : `${this.x},${this.y}[${this.w}x${this.h}]` } - + function clamp (v, min, max) { return v < min ? min : v > max ? max : v } } diff --git a/desktop/sources/scripts/keyboard.js b/desktop/sources/scripts/keyboard.js index 3a9aecd..05258ec 100644 --- a/desktop/sources/scripts/keyboard.js +++ b/desktop/sources/scripts/keyboard.js @@ -19,7 +19,7 @@ function Keyboard () { } if (event.key == 'c' && event.metaKey) { terminal.cursor.copy(); return } - if (event.key == 'v' && event.metaKey) { terminal.cursor.copy(); return } + if (event.key == 'v' && event.metaKey) { terminal.cursor.paste(); return } if (event.keyCode == 38) { keyboard.key_arrow_up(event.shiftKey); return } if (event.keyCode == 40) { keyboard.key_arrow_down(event.shiftKey); return } |