Skip to content
Browse files

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
  • Loading branch information...
1 parent da2598b commit c78388a400c8a7b113d722fb812a158cb699a82d @mythmon mythmon committed
Showing with 20 additions and 16 deletions.
  1. +3 −0 web/js/board.js
  2. +17 −16 web/js/tools.js
View
3 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;
View
33 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<self.board.nodes.length; i++) {
var it = self.board.nodes[i];
if (it.type == 'node' && it.hit_test(x, y)) {
- if (it != self.temp_line.n1) {
- new self.line_type(self.board, self.temp_line.n1, it, 1);
- self.temp_line.remove();
+ if (it != self.state[id].temp_line.n1) {
+ new self.line_type(self.board, self.state[id].temp_line.n1, it, 1);
+ self.state[id].temp_line.remove();
hit = true;
}
break;
}
}
if (!hit) {
- self.temp_line.remove();
+ self.state[id].temp_line.remove();
} else {
self.board.undoAdd();
}
- self.temp_line = null;
- self.temp_end_node = null;
+ self.state[id] = undefined;
},
});

0 comments on commit c78388a

Please sign in to comment.
Something went wrong with that request. Please try again.