diff options
author | Devine Lu Linvega <[email protected]> | 2018-12-02 09:53:24 +1200 |
---|---|---|
committer | Devine Lu Linvega <[email protected]> | 2018-12-02 09:53:24 +1200 |
commit | b3b730859fa7b1d0000b4538d6d0cdca29529fce (patch) | |
tree | 0f4f7d16f31b7b5d1ca360faedfedac00366f91d /desktop/sources | |
parent | d280c7c3fa2bcbd57a375e5994b3ae8da88c2b3a (diff) | |
download | Orca-b3b730859fa7b1d0000b4538d6d0cdca29529fce.tar.gz Orca-b3b730859fa7b1d0000b4538d6d0cdca29529fce.zip |
Added crop
Diffstat (limited to 'desktop/sources')
-rw-r--r-- | desktop/sources/index.html | 3 | ||||
-rw-r--r-- | desktop/sources/scripts/cursor.js | 20 | ||||
-rw-r--r-- | desktop/sources/scripts/terminal.js | 11 |
3 files changed, 25 insertions, 9 deletions
diff --git a/desktop/sources/index.html b/desktop/sources/index.html index 6422e24..1f0192f 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -40,7 +40,6 @@ terminal.controller.add("default","File","Revert",() => { terminal.source.revert(); },"CmdOrCtrl+Shift+R") terminal.controller.add("default","File","Close",() => { terminal.source.close(); },"CmdOrCtrl+W") - // terminal.controller.add("default","Edit","Toggle Mode",() => { terminal.cursor.toggleMode(); },"Enter") terminal.controller.add("default","Edit","Select All",() => { terminal.cursor.selectAll(); },"CmdOrCtrl+A") terminal.controller.add("default","Edit","Erase Selection",() => { terminal.cursor.erase(); },"Backspace") terminal.controller.add("default","Edit","Copy Selection",() => { terminal.cursor.copy(); },"CmdOrCtrl+C") @@ -57,6 +56,8 @@ terminal.controller.add("default","Program","Incr. Row",() => { terminal.modGrid(0,1); },"}") terminal.controller.add("default","Program","Decr. Row",() => { terminal.modGrid(0,-1); },"{") + terminal.controller.add("default","Tools","Crop to Selection",() => { terminal.crop(); },"CmdOrCtrl+K") + terminal.controller.add("default","Theme","Default Theme",() => { terminal.theme.noir(); },"CmdOrCtrl+Shift+1") terminal.controller.add("default","Theme","Light Theme",() => { terminal.theme.pale(); },"CmdOrCtrl+Shift+2") terminal.controller.add("default","Theme","Get More..",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes'); }) diff --git a/desktop/sources/scripts/cursor.js b/desktop/sources/scripts/cursor.js index 8d7e404..cbdca8f 100644 --- a/desktop/sources/scripts/cursor.js +++ b/desktop/sources/scripts/cursor.js @@ -36,7 +36,7 @@ function Cursor (orca, terminal) { } this.copy = function () { - this.block = this.getBlock(this.x, this.y, this.w, this.h) + this.block = this.getBlock() } this.cut = function () { @@ -45,7 +45,7 @@ function Cursor (orca, terminal) { } this.paste = function () { - this.writeBlock(this.x, this.y, this.block) + this.writeBlock(this.toRect(), this.block) } this.write = function (g) { @@ -77,11 +77,11 @@ function Cursor (orca, terminal) { // Block - this.getBlock = function (x, y, w, h) { + this.getBlock = function (rect = this.toRect()) { const block = [] - for (let _y = y; _y < y + h; _y++) { + for (let _y = rect.y; _y < rect.y + rect.h; _y++) { const line = [] - for (let _x = x; _x < x + w; _x++) { + for (let _x = rect.x; _x < rect.x + rect.w; _x++) { line.push(orca.glyphAt(_x, _y)) } block.push(line) @@ -89,11 +89,11 @@ function Cursor (orca, terminal) { return block } - this.writeBlock = function (x, y, block) { + this.writeBlock = function (rect, block) { if (!block || block.length === 0) { return } - let _y = y + let _y = rect.y for (const lineId in block) { - let _x = x + let _x = rect.x for (const glyphId in block[lineId]) { orca.write(_x, _y, block[lineId][glyphId]) _x++ @@ -112,6 +112,10 @@ function Cursor (orca, terminal) { terminal.history.record() } + this.toRect = function () { + return { x: this.x, y: this.y, w: this.w, h: this.h } + } + function clamp (v, min, max) { return v < min ? min : v > max ? max : v } } diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js index e6944b8..51c26dd 100644 --- a/desktop/sources/scripts/terminal.js +++ b/desktop/sources/scripts/terminal.js @@ -57,12 +57,19 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { if (!data) { return } const w = data.split('\n')[0].length const h = data.split('\n').length + if (w < 10 || h < 10) { console.warn('Too small'); return } console.log(`Loading ${w}x${h}`) orca.load(w, h, data, frame) this.resize() this.update() } + this.crop = function () { + const block = this.cursor.getBlock() + const data = block.reduce((acc, val) => { acc.push(val.join('')); return acc }, []).join('\n') + this.load(data) + } + this.update = function () { this.clear() this.ports = this.findPorts() @@ -94,6 +101,10 @@ function Terminal (orca, tile = { w: 20, h: 30 }) { this.update() } + this.modSize = function (w = 0, h = 0) { + + } + // this.isCursor = function (x, y) { |