Skip to content

Commit

Permalink
Working multitouch for wires and resistors.
Browse files Browse the repository at this point in the history
Except it kind of sucks, because its really hard to get them to actually
hittest the nodes.

Progress on #24
  • Loading branch information
mythmon committed May 6, 2012
1 parent da2598b commit c78388a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
3 changes: 3 additions & 0 deletions web/js/board.js
Expand Up @@ -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;
Expand Down
33 changes: 17 additions & 16 deletions web/js/tools.js
Expand Up @@ -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) {
Expand All @@ -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;
},
});

Expand Down

0 comments on commit c78388a

Please sign in to comment.