Here is what I have as a first draft of the code (mainly I have just
php files left to write):
<head>
<title>First Rough</title>
<style>
body {
text-align: center
}
</style>
<!--[if IE]><script type="text/javascript" src="../excanvas.js"></
script><![endif]-->
<script type="text/javascript" src="../jquery-1.3.2.min.js"></script>
<script type="text/javascript">
var pmousex = 0;
var pmousey = 0;
var nmousex = 0;
var nmousey = 0;
// need textbox for your name and other's name
// isAvail is textbox that reads who is the user from the server
(starts with 'available')
function doBinds(periodic) {
if(isAvail.value != othername) {
$("#mycanvas").bind(onmousedown, function(e) {
ctx.beginPath();
pmousex = e.pageX; // adjust for position of canvas
pmousey = e.pageY; // adjust for position of canvas
ctx.moveTo(pmousex, pmousey);
if(periodic == false) myhidden.value = "[" + "[" + pmousex + "," +
pmousey + "]";
if(periodic == true) myhidden.value = ",[" + pmousex + "," +
pmousey + "]";
});
$("#mycanvas").bind(onmousemove, function(e) {
nmousex = e.pageX; // adjust for position of canvas
nmousey = e.pageY; // adjust for position of canvas
ctx.lineTo(nmousex, nmousey);
ctx.closePath();
ctx.stroke();
myhidden.value += ",[" + nmousex + "," + nmousey + "]";
ctx.moveTo(nmousex,nmousey);
});
// sendtxtX.php appends the txt in your userfile on the server
$("#mycanvas").onmouseup(function() {
$("#mycanvas").unbind(mousemove);
$("#mycanvas").unbind(mousedown);
if(yourname =="user1") {
thesent = sendtxt1.php
}
else {
thesent = sendtxt2.php
}
var tosend = myhidden.value;
myhidden.value = "";
$.post(thesent,tosend,doBinds(true));
});
}
}
function startNew() {
ctx.moveTo(pmousex,pmousey);
doBinds(false);
}
window.onload = function() {
var ctx = document.getElementById('mycanvas').getContext('2d');
var myhidden = document.getElementById('myhidden');
var mycanvas = document.getElementById('mycanvas');
var isAvail = document.getElementById('available');
ctx.strokeStyle = 'black';
ctx.lineWidth = 1;
// timer runs for both at first, then only for non-active person
// timer reads shWBavail.txt and loads that value into textbox
id=isAvail via checkAvail.php
timer = setTimeout(function() {
$("#available").load(checkAvail.php)
},5000);
};
$("#buttonDONE").click(function() {
if(yourname="user1") {
thesent = sendtxt1.php
}
else {
thesent = sendtxt2.php
}
$("#mycanvas").unbind(mouseup);
timer = setTimeout(function() {
$("#available").load(checkAvail.php)
},5000);
myhidden.value += "]";
var tosend = myhidden.value;
myhidden.value = "";
$.post(thesent,tosend,function() {
// usertxt.php sets the username of the person using OR sets that
textbox to 'available
$.post(usertxt.php,"available");
});
});
// othertxtX.php reads all from the OTHER'S JSON store file on the
server
// othertxtXNA.php overwrites the txt in OTHER'S JSON store file to
"" (blank) on the server
$("#buttonMYTURN").click(function() {
othername = document.getElementById("otherusername").value;
yourname = document.getElementById("yourusername").value;
if(isAvail.value != othername) {
timer=null;
if(yourname="user1") {
thefile = "othertxt2.php";
thefileNA = "othertxt2NA.php";
}
else {
thefile = "othertxt1.php"
thefileNA = "othertxt1NA.php";
}
var otherarray = [];
$.getJSON(thefile,function(entryIndex,entry){
otherarray[entryIndex] = [entry[0],entry[1]]
});
for (var i = 0; i < otherarray.length - 2; i++) {
ctx.beginPath();
ctx.moveTo(otherarray[i][0],otherarray[i][1]);
ctx.lineTo(otherarray[i + 1][0],otherarray[i + 1][1]);
ctx.closePath();
ctx.stroke();
if(i = otherarray.length - 2)
{
pmousex = otherarray[i + 1][0];
pmousey = otherarray[i + 1][1];
}
}
$.post(thefileNA,"",startNew());
};
});
</script>
</head>
<body>
<center><input type="text" id="isAvail" value="available"></center>
Fill this in before clicking on the canvas: <input type="text"
id="yourusername" value="YOUR username" />
Fill this in before clicking on the canvas: <input type="text"
id="otherusername" value="OTHER'S username" /><br />
(Main user (or one of the users) must be "user1" (no quotes).)
<br />
<input type="button" value="My Turn" id="buttonMYTURN"><input
type="button" value="DONE" id="buttonDONE">
<input type="hidden" id="myhidden">
<br /><br />
<hr color="#008000" size="6"><br /><br />
<div style="position: absolute; width: 710px; height: 650px; z-index:
1; left: 50px; top: 150px;border: 3px double #FF0000" width="710">
<canvas id="mycanvas" width=700 height=600></canvas>
<p>This tests that lines work in the same way in different browsers
when you are
using sub pixel coordinates.</p>
</div>
</body>