summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine/map/tools/arrow.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles/engine/map/tools/arrow.js')
-rw-r--r--public/assets/javascripts/rectangles/engine/map/tools/arrow.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/public/assets/javascripts/rectangles/engine/map/tools/arrow.js b/public/assets/javascripts/rectangles/engine/map/tools/arrow.js
new file mode 100644
index 0000000..2a73954
--- /dev/null
+++ b/public/assets/javascripts/rectangles/engine/map/tools/arrow.js
@@ -0,0 +1,46 @@
+var ArrowTool = MapTool.extend(function(base){
+ var exports = {}
+
+ var selected_point = null, original_point = null, selected_shape = null
+
+ exports.down = function(e, cursor){
+ last_point.a = cursor.x.a
+ last_point.b = cursor.y.a
+ var p = shapes.findClosestPoint(last_point)
+ if (p) {
+ selected_shape = p.shape
+ selected_point = p.point
+ original_point = selected_point.clone()
+ }
+ else {
+ map.ui.set_drag_tool("position")
+ }
+ }
+
+ exports.move = function(e, cursor){
+ last_point.a = cursor.x.a
+ last_point.b = cursor.y.a
+ var p = shapes.findClosestPoint(last_point)
+ if (p) {
+ document.body.style.cursor = "pointer"
+ last_point.assign(p.point)
+ cursor.x.a = cursor.x.b = last_point.a
+ cursor.y.a = cursor.y.b = last_point.b
+ }
+ else {
+ document.body.style.cursor = "crosshair"
+ }
+ }
+
+ exports.drag = function(e, cursor){
+ selected_point.a = original_point.a + cursor.x.magnitude()
+ selected_point.b = original_point.b + cursor.y.magnitude()
+ selected_shape.rebuild()
+ }
+
+ exports.up = function(e, cursor){
+ selected_point = selected_shape = original_point = null
+ }
+
+ return exports
+}) \ No newline at end of file