From c78388a400c8a7b113d722fb812a158cb699a82d Mon Sep 17 00:00:00 2001 From: Mike Cooper Date: Sun, 6 May 2012 02:09:12 -0700 Subject: [PATCH] Working multitouch for wires and resistors. Except it kind of sucks, because its really hard to get them to actually hittest the nodes. Progress on #24 --- web/js/board.js | 3 +++ web/js/tools.js | 33 +++++++++++++++++---------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/web/js/board.js b/web/js/board.js index ae583ee..23310df 100644 --- a/web/js/board.js +++ b/web/js/board.js @@ -735,6 +735,9 @@ var ProtoWire = ScreenObject.extend({ type: "protowire", init: function(self, board, n1, n2) { + if (n1 === n2) { + throw "Cannot create wire where start and end node are the same"; + } self._super(board); self.n1 = n1; self.n2 = n2; diff --git a/web/js/tools.js b/web/js/tools.js index 456e198..5d9a423 100644 --- a/web/js/tools.js +++ b/web/js/tools.js @@ -161,6 +161,8 @@ var WireTool = Tool.extend({ self.make_elem(); self.line_proto = ProtoWire; self.line_type = Wire; + + self.state = {}; }, make_elem: function(self) { @@ -176,47 +178,46 @@ var WireTool = Tool.extend({ console.log('WireTool.dragstart'); self._super(x, y, id, target); var p = self.board.snap_to(x, y); - if (self.temp_line) { - // Why do we still have one of these? - self.temp_line.remove(); - self.temp_line = null; - } if (target && target.type == "node") { - self.temp_end_node = {'x': x, 'y': y}; - self.temp_line = new self.line_proto(self.board, target, self.temp_end_node, 1); + if (self.state[id] === undefined) { + self.state[id] = {}; + } + self.state[id].temp_end_node = {'x': x, 'y': y}; + self.state[id].temp_line = new self.line_proto(self.board, target, + self.state[id].temp_end_node, 1); } }, drag: function(self, x, y, id, target) { self._super(x, y, id, target); - if (self.temp_end_node) { - self.temp_end_node.x = x; - self.temp_end_node.y = y; + if (self.state[id]) { + self.state[id].temp_end_node.x = x; + self.state[id].temp_end_node.y = y; } }, dragend: function(self, x, y, id, target) { console.log('WireTool.dragend'); self._super(x, y, id, target); + var hit = false; for (var i=0; i