summaryrefslogtreecommitdiff
path: root/js/ui/selection.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/ui/selection.js')
-rw-r--r--js/ui/selection.js71
1 files changed, 69 insertions, 2 deletions
diff --git a/js/ui/selection.js b/js/ui/selection.js
index cbeb051..f1e7e5e 100644
--- a/js/ui/selection.js
+++ b/js/ui/selection.js
@@ -1,6 +1,8 @@
var selection = (function(){
- var selection = new Matrix (1, 1, function(x,y){
+ 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
@@ -15,7 +17,72 @@ 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 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
})()