summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/blit.js12
-rw-r--r--js/ui/selection.js14
2 files changed, 23 insertions, 3 deletions
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
}