var selection = (function(){ var creating = false, moving = false, copying = false var selection_canvas = new Matrix (1, 1, function(x,y){ var lex = new Lex (x,y) lex.build() return lex }) // in selection mode.. // - we start by clicking the canvas. this positions the selection, and copies // the character // - then we drag down and to the right. this resizes the selection and pushes new // rows and columns. each of these copies the character underneath. // - on mouseup, the selection is locked. then.. // - 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 corner = [-1, -1] var dimensions = [0, 0] function contains (point) { var contains_x = corner[0] < point[0] && point[0] < corner[0] + dimensions[0] var contains_y = corner[1] < point[1] && point[1] < corner[1] + dimensions[1] return (contains_x && contains_y) } function reposition () { var top_left = canvas.aa[corner[1]][corner[0]].span var left = top_left.offsetLeft var top = top_left.offsetTop var width = top_left.offsetWidth var height = top_left.offsetHeight } function down (e, lex, point){ if (contains(point)) { copying = false moving = true creating = false } else { copying = false moving = false creating = true corner[0] = point[0] corner[1] = point[1] dimensions[0] = 1 dimensions[1] = 1 } show() reposition() } function move (e, lex, point){ if (creating) { var x = point[0] - corner[0] var y = point[1] - corner[1] if (x < 0) { corner[0] = point[0] } if (y < 0) { corner[0] = point[0] } dimensions[0] = abs(x) reposition() } else if (moving) { } } function up (e) { } function show () { selecting = true } function hide () { selecting = false } var selection = {} selection.down = down selection.move = move selection.up = up selection.canvas = selection_canvas selection.show = show selection.hide = hide return selection })()