From 6a16ad9c408fb84dd27c618312f3111563ca2ad5 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 9 Dec 2014 01:40:49 -0500 Subject: blitting functions --- js/blit.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 js/blit.js (limited to 'js/blit.js') diff --git a/js/blit.js b/js/blit.js new file mode 100644 index 0000000..09f39b2 --- /dev/null +++ b/js/blit.js @@ -0,0 +1,41 @@ +var blit = (function(){ + var blit = {} + blit.and = blit.atop = function(A, B, x, y){ + x = x || 0 ; y = y || 0 + B.forEach(function(lex, u, v){ + var cell = A.getCell(u+x, v+y) + if (cell && lex.opacity > 0) { + cell.clone(lex) + } + }) + } + blit.or = blit.under = function(A, B, x, y){ + x = x || 0 ; y = y || 0 + B.forEach(function(lex, u, v){ + var cell = A.getCell(u+x, v+y) + if (cell && cell.opacity == 0) { + cell.clone(lex) + } + }) + } + blit.set = blit.replace = function(A, B, x, y){ + x = x || 0 ; y = y || 0 + B.forEach(function(lex, u, v){ + var cell = A.getCell(u+x, v+y) + if (cell) { + cell.clone(lex) + } + }) + } + blit.invert = function(A, B, x, y){ + x = x || 0 ; y = y || 0 + B.forEach(function(lex, u, v){ + var cell = A.getCell(u+x, v+y) + if (cell && lex.opacity > 0) { + cell.fg = get_inverse(cell.fg) + cell.bg = get_inverse(cell.bg) + } + }) + } + return blit +})() -- cgit v1.2.3-70-g09d2 From 353f109d60ca9d29af333fe91bc09edd8a69472f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 11 Dec 2014 22:26:08 -0500 Subject: drag a selection around clones/copies it --- js/blit.js | 12 +++++++++++- js/ui/selection.js | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'js/blit.js') diff --git a/js/blit.js b/js/blit.js index 09f39b2..8683f22 100644 --- a/js/blit.js +++ b/js/blit.js @@ -18,7 +18,17 @@ var blit = (function(){ } }) } - blit.set = blit.replace = function(A, B, x, y){ + // copy the region of A beginning at x,y into B + blit.copy_from = function(A, B, x, y){ + x = x || 0 ; y = y || 0 + B.forEach(function(lex, u, v){ + var cell = A.getCell(u+x, v+y) + if (cell) { + lex.clone(cell) + } + }) + } + blit.copy_to = function(A, B, x, y){ x = x || 0 ; y = y || 0 B.forEach(function(lex, u, v){ var cell = A.getCell(u+x, v+y) diff --git a/js/ui/selection.js b/js/ui/selection.js index 43b1a75..6f8f7db 100644 --- a/js/ui/selection.js +++ b/js/ui/selection.js @@ -22,11 +22,14 @@ var selection = (function(){ // - drag the selection to move it -- this "cuts" it and leaves a blank space on the canvas. // - shift-drag the selection to copy it - var a = [-1, -1] + var a = [0, 0] var b = [0, 0] var c = [0, 0] var d = [0, 0] + function reset () { + a[0] = a[1] = b[0] = b[1] = 0 + } function left (a,b) { return min(a[0],b[0]) } function top (a,b) { return min(a[1],b[1]) } function right (a,b) { return max(a[0],b[0]) } @@ -101,7 +104,8 @@ var selection = (function(){ if (creating) { orient(a,b) selection_canvas.resize(width(a,b), height(a,b)) - // copy canvas here.. + blit.copy_from( canvas, selection_canvas, a[0], a[1] ) + selection_canvas.build() selector_el.classList.remove("creating") } if (moving) { @@ -111,6 +115,7 @@ var selection = (function(){ a[1] += dy b[0] += dx b[1] += dy + blit.copy_to( canvas, selection_canvas, a[0], a[1] ) } if (copying) { } @@ -122,6 +127,11 @@ var selection = (function(){ selecting = true } function hide () { + reset() + selector_el.style.top = "-9999px" + selector_el.style.left = "-9999px" + selector_el.style.width = "0px" + selector_el.style.height = "0px" selecting = false } -- cgit v1.2.3-70-g09d2