summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine/map/tools/line.js
blob: 8f409a8176ea82af0c01be33c1259c28f7b34a03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var LineTool = MapTool.extend(function(base){
	var exports = {}
	
	var selected_point = null
	
	var line = exports.line = []
	
	var can_drag, dragging
	
	exports.down = function(e, cursor){
	  this.cursor = cursor
	  switch (line.length) {
	    case 0:
        line[0] = cursor.x_component()
        can_drag = true
        break
      case 1:
        line[1] = cursor.x_component()
        can_drag = false
        break
      case 2:
        line[0] = cursor.x_component()
        line.pop()
        can_drag = true
        break
    }
	}
	
	exports.move = function(e, cursor){
    this.cursor = cursor
	}
	
	exports.drag = function(e, cursor){
	  if (dragging) {
	    line[1].a = cursor.x.b
	    line[1].b = cursor.y.b
	  }
	  else if (can_drag && cursor.magnitude() > 10/map.zoom) {
	    line[1] = cursor.y_component()
	    dragging = true
	  }
	}
	
	exports.up = function(e, cursor){
	  can_drag = dragging = false
	}
	
	return exports
})