summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine/map/tools/arrow.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-07-21 13:23:22 -0400
committerJules Laplace <jules@okfoc.us>2015-07-21 13:23:22 -0400
commit44642b48203b3ee2fa9e281f31ed9fed3f60ee79 (patch)
tree2a08c83ab4aad41274cd1c9ace91753a250a6e6d /public/assets/javascripts/rectangles/engine/map/tools/arrow.js
parentc6a22d43e82d989e73d1be9894c1c9ae9446033d (diff)
find closest segment
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