1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
<html>
<head>
<title>JSXGraph example</title>
<link rel="stylesheet" type="text/css" href="../distrib/jsxgraph.css" />
<script type="text/javascript" src="../distrib/jsxgraphcore.js"></script>
</head>
<body>
<h2>Multitouch Test Area.</h2>
<div style="width:800px">
<div id="jxgbox" class="jxgbox" style="width:800px; height:800px; float:left"></div>
</div>
<div id="debug" style="display:block;"></div>
<script type="text/javascript">
/* <![CDATA[ */
var multitouch = (function () {
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-1, 5, 5, -1], axis: true, showcopyright: false, shownavigation: false}),
points = [],
touches = [],
colors = ['red', 'green', 'navy', 'gray', 'black'],
curves = 0,
touchStart = function (e) {
console.log('this is touch start speaking');
var i, j, eps = 9000, found = false,
tmpTouches = [];
for (i = 0; i < touches.length; i++) {
tmpTouches[i] = touches[i];
}
touches.length = 0;
for (i = 0; i < e.targetTouches.length; i++) {
console.log('no: ' + e.targetTouches.length);
for (j = 0; j < tmpTouches.length; j++) {
console.log('comparing ' + i + ' with ' + j);
console.log('le diff: ' + Math.abs(Math.pow(e.targetTouches[i].screenX, 2) + Math.pow(e.targetTouches[i].screenY, 2) - Math.pow(tmpTouches[j].X, 2) - Math.pow(tmpTouches[j].Y, 2)));
if (Math.abs(Math.pow(e.targetTouches[i].screenX, 2) + Math.pow(e.targetTouches[i].screenY, 2) - Math.pow(tmpTouches[j].X, 2) - Math.pow(tmpTouches[j].Y, 2)) < eps) {
touches[i] = {
X: e.targetTouches[i].screenX,
Y: e.targetTouches[i].screenY,
obj: tmpTouches[j].obj
};
found = true;
break;
}
}
if (!found) {
touches[i] = {
X: e.targetTouches[i].screenX,
Y: e.targetTouches[i].screenY,
obj: board.create('curve', [[], []], {strokeColor: colors[curves%colors.length]})
};
curves++;
}
found = false;
}
},
touchMove = function (e) {
console.log('touch move calling');
var i, c;
console.log('number of touches: ' + touches.length);
for (i = 0; i < e.targetTouches.length; i++) {
touches[i].X = e.targetTouches[i].screenX;
touches[i].Y = e.targetTouches[i].screenY;
c = new JXG.Coords(JXG.COORDS_BY_SCREEN, board.getMousePosition(e, i), board);
touches[i].obj.dataX.push(c.usrCoords[1]);
touches[i].obj.dataY.push(c.usrCoords[2]);
}
board.update();
},
touchEnd = function (e) {
console.log('eeeeh \'sup, touchend');
var i, j, eps = 9000, found = false,
tmpTouches = [];
for (i = 0; i < touches.length; i++) {
tmpTouches[i] = touches[i];
}
touches.length = 0;
for (i = 0; i < e.targetTouches.length; i++) {
for (j = 0; j < tmpTouches.length; j++) {
if (Math.abs(Math.pow(e.targetTouches[i].screenX, 2) + Math.pow(e.targetTouches[i].screenY, 2) - Math.pow(tmpTouches[j].X, 2) - Math.pow(tmpTouches[j].Y, 2)) < eps) {
touches[i] = {
X: e.targetTouches[i].screenX,
Y: e.targetTouches[i].screenY,
obj: tmpTouches[j].obj
};
found = true;
break;
}
}
if (!found) {
touches[i] = {
X: e.targetTouches[i].screenX,
Y: e.targetTouches[i].screenY,
obj: board.create('curve', [[], []], {strokeColor: colors[curves%colors.length]})
};
curves++;
}
found = false;
}
};
points.push(board.create('point', [1, 1]));
points.push(board.create('point', [2, 3]));
points.push(board.create('point', [4, 1]));
points.push(board.create('point', [3, 3]));
JXG.addEvent(document.getElementById('jxgbox'), 'touchstart', touchStart, this);
JXG.addEvent(document.getElementById('jxgbox'), 'touchmove', touchMove, this);
JXG.addEvent(document.getElementById('jxgbox'), 'touchend', touchEnd, this);
})();
/* ]]> */
</script>
</body>
</html>
|