Skip to content

Commit

Permalink
Improvments for iPad
Browse files Browse the repository at this point in the history
I don't have an iPad so this may not even work
  • Loading branch information
Anthony F committed Jun 25, 2011
1 parent 6693c9c commit e684647
Showing 1 changed file with 99 additions and 7 deletions.
106 changes: 99 additions & 7 deletions ui.js
Expand Up @@ -337,6 +337,77 @@ app.ui=(function(){
lmx = mx;
lmy = my;
}
var gestureBegin_scalex=1;
var gestureBegin_scaley=1;
function gesturestart(e){
gestureBegin_scalex=scalex;
gestureBegin_scaley=scaley;

e.preventDefault();
return false;
}
function gestureend(e){
e.preventDefault();
return false;
}
function gesturechange(e){
var ex=e.scale;
scalex=gestureBegin_scalex*ex;
scaley=gestureBegin_scaley*ex;
/*
var mx = ?;
var my = ?;
var dx=mx+cx;
var dy=my-cy;
if((dx*dx+dy*dy)>1000){
//Move camera towards the point if
//the squared distance to the origin is more than 1000.
cx=ex*(mx+cx)-mx;
cy+=my+ex*(cy-my)-cy;
}
*/

updatePTD(mx,my);
draw();

e.preventDefault();
return false;
}
function touchmove(e){
if(e.touches.length!=1){
return;
}
var s=e.touches[0];
mousemove({x:s.screenX,y:s.screenY,button:0});
e.preventDefault();
return false;
}
function touchstart(e){
if(e.touches.length!=1){
return;
}
drag=true;
if (!drawwhiledrag_c) {
setTimeout(drawwhiledrag, 1000);
drawwhiledrag_c++;
}

var s=e.touches[0];
lmx=s.screenX;
lmy=s.screenY;
}
function touchend(e){
if(e.touches.length!=1){
return;
}
drag=false;
perform_translation();
draw();
e.preventDefault();
return false;
}
var scaleconst = 0.001;
if (/AppleWebKit/.test(navigator.userAgent)) {
scaleconst = 0.0001;
Expand Down Expand Up @@ -948,14 +1019,35 @@ app.ui=(function(){
proto = _proto.cloneNode(true);
proto.removeAttribute("id");

canvas.onmousedown=mousedown;
$(canvas).bind("mousedown",mousedown);
// Touches

//Bind events:
$(document.body).bind("mouseup",function(){if(!allowdrag){return;}drag=false;perform_translation();canvas.style.cursor = "default";draw()})
.bind("mousemove",mousemove)
// .bind("gesturestart", gesturestart)
// .bind("gesturechange",gesturechange)
// .bind("gestureend", gestureend);

document.body.addEventListener("mouseup",function(){if(!allowdrag){return;}drag=false;perform_translation();canvas.style.cursor = "default";draw()},false);
document.body.addEventListener("mousemove",mousemove,false);
window.addEventListener("mousewheel",mousewheel,false);
window.addEventListener("DOMMouseScroll",mousewheel,false);
window.addEventListener("resize",resize,false);
con.addEventListener("mousewheel",function(e){e.stopPropagation();},false);
// .bind("resize",resize);
if(window.addEventListener){
document.body.addEventListener("gesturechange",gesturechange);
document.body.addEventListener("gesturestart",gesturestart);
document.body.addEventListener("gestureend",gestureend);

document.body.addEventListener("touchmove",touchmove);
document.body.addEventListener("touchstart",touchstart);
document.body.addEventListener("touchend",touchend);

window.addEventListener("mousewheel",mousewheel);
window.addEventListener("DOMMouseScroll",mousewheel);

con.addEventListener("mousewheel",function(e){e.stopPropagation();},false);
con.addEventListener("DOMMouseScroll",function(e){e.stopPropagation();},false);
}else{
window.onmousewheel=window.DOMMouseScroll=mousewheel;
con.onmousewheel=window.onDOMMouseScroll=function(e){e.stopPropagation();};
}
document.body.removeChild(document.body.firstChild);
//we may have to implement scaling if browsers don't work properly
if(webkit){
Expand Down

0 comments on commit e684647

Please sign in to comment.