diff options
| -rw-r--r-- | public/assets/javascripts/rectangles/engine/map/ui_ortho.js | 68 | ||||
| -rw-r--r-- | public/assets/test/ortho3.html | 18 |
2 files changed, 66 insertions, 20 deletions
diff --git a/public/assets/javascripts/rectangles/engine/map/ui_ortho.js b/public/assets/javascripts/rectangles/engine/map/ui_ortho.js index dab7354..52f7339 100644 --- a/public/assets/javascripts/rectangles/engine/map/ui_ortho.js +++ b/public/assets/javascripts/rectangles/engine/map/ui_ortho.js @@ -10,35 +10,72 @@ Map.UI.Ortho = function(map){ el: map.el, down: function(e, cursor){ last_event = e - cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) - cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) - base.tools[currentTool].down(e, cursor) + cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom) + cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom) + if (tool.recenterCursor) { + cursor.x.add(map.center.a) + cursor.y.sub(map.center.b) + base.tools[currentTool].down(e, cursor) + } + else { + base.tools[currentTool].down(e, cursor) + cursor.x.add(map.center.a) + cursor.y.sub(map.center.b) + } }, move: function(e, cursor){ last_event = e - cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) - cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) - base.tools[currentTool].move(e, cursor) + cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom) + cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom) + if (tool.recenterCursor) { + cursor.x.add(map.center.a) + cursor.y.sub(map.center.b) + base.tools[currentTool].move(e, cursor) + } + else { + base.tools[currentTool].move(e, cursor) + cursor.x.add(map.center.a) + cursor.y.sub(map.center.b) + } }, drag: function(e, cursor){ last_event = e - cursor.x.b = ((cursor.x.b/map.dimensions.a)+0.5) * map.dimensions.a / map.zoom + map.center.a - cursor.y.b = ((cursor.y.b/map.dimensions.b)-0.5) * map.dimensions.b / map.zoom - map.center.b - base.tools[currentTool].drag(e, cursor) + cursor.x.b = ((cursor.x.b/map.dimensions.a)+0.5) * map.dimensions.a / map.zoom + cursor.y.b = ((cursor.y.b/map.dimensions.b)-0.5) * map.dimensions.b / map.zoom + if (tool.recenterCursor) { + cursor.x.b += map.center.a + cursor.y.b -= map.center.b + base.tools[currentTool].drag(e, cursor) + } + else { + base.tools[currentTool].drag(e, cursor) + cursor.x.b += map.center.a + cursor.y.b -= map.center.b + } }, up: function(e, cursor, new_cursor){ last_event = e - new_cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom).add(map.center.a) - new_cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom).sub(map.center.b) - base.tools[currentTool].up(e, cursor, new_cursor) + new_cursor.x.div(map.dimensions.a).add(0.5).mul(map.dimensions.a / map.zoom) + new_cursor.y.div(map.dimensions.b).sub(0.5).mul(map.dimensions.b / map.zoom) + if (tool.recenterCursor) { + new_cursor.x.add(map.center.a) + new_cursor.y.sub(map.center.b) + base.tools[currentTool].up(e, cursor, new_cursor) + } + else { + base.tools[currentTool].up(e, cursor, new_cursor) + new_cursor.x.add(map.center.a) + new_cursor.y.sub(map.center.b) + } if (nextTool) { + console.log('found nextTool') base.set_tool(nextTool) nextTool = null } } }) - var currentTool = "polyline", nextTool + var currentTool = "polyline", nextTool, tool base.add_tool = function(name, tool){ base.tools[name] = tool } @@ -46,11 +83,14 @@ Map.UI.Ortho = function(map){ console.log("set tool to", s) base.tools[currentTool].cancel() currentTool = s + tool = base.tools[currentTool] } base.set_drag_tool = function(s){ + console.log('set drag tool to', s) nextTool = currentTool currentTool = s - base.tools[s].down(last_event, base.mouse.cursor) + tool = base.tools[currentTool] + base.tools[currentTool].down(last_event, base.mouse.cursor) } base.tools = {} diff --git a/public/assets/test/ortho3.html b/public/assets/test/ortho3.html index 319f788..6bf2619 100644 --- a/public/assets/test/ortho3.html +++ b/public/assets/test/ortho3.html @@ -78,6 +78,7 @@ app.off = function(){ app.tube.off.apply(app.tube, arguments) } var MapTool = Fiber.extend(function(base){ var exports = { + recenterCursor: true, down: function(e, cursor){}, move: function(e, cursor){}, drag: function(e, cursor){}, @@ -136,14 +137,18 @@ var ArrowTool = MapTool.extend(function(base){ var PositionTool = MapTool.extend(function(base){ var exports = { - down: function(e, cursor){ + recenterCursor: false, + drag: function(e, cursor){ + map.center.a = -cursor.x.magnitude() + map.center.b = cursor.y.magnitude() + }, + rightclick: function(e, cursor){ cursor.quantize(1/map.zoom) map.center.a = cursor.x.a map.center.b = -cursor.y.a cursor.x.b = cursor.x.a cursor.y.b = cursor.y.a - map.ui.mouse.down = false - }, + } } return exports }) @@ -167,7 +172,7 @@ var PolylineTool = MapTool.extend(function (base) { } return } - map.ui.tools.position.down(e, cursor) + map.ui.tools.position.rightclick(e, cursor) return } @@ -216,7 +221,6 @@ var OrthoPolylineTool = MapTool.extend(function (base) { var exports = {} exports.down = function(e, cursor){ - // rightclick? if (e.ctrlKey || e.which === 3) { e.preventDefault() @@ -232,7 +236,9 @@ var OrthoPolylineTool = MapTool.extend(function (base) { } return } - map.ui.tools.position.down(e, cursor) + else { + map.ui.tools.position.rightclick(e, cursor) + } return } |
