/* The mouse component allows an entity to listen to mouse triggers. @usage re.e('mouse') .on('mousedown:middle', function(m){ //m.x - x position //m.y - y position //m.screenX - screen x position //m.screenY - screen y position }) FUTURE: rename triggers to the standard format mousemove -> mouse:move */ re.c('mouse') .statics({ l:[], press:function(e){ var b, c; //find which key if(e.which == null){ //IE if(e.button < 2){ b = 'left'; } else if(e.button == 4){ b = 'middle'; } else { b = 'right'; } } else { if(e.which < 2){ b = 'left'; } else if(e.which == 2){ b = 'middle'; } else { b = 'right'; } } c = 'mouse:'+b; //register mouse action if(re.pressed.d){ re.pressed.d[c] = (e.type == 'mousedown'); } re.c('mouse').event(e, c); }, event:function(e, extra){ var canvas = re.sys.canvas; //calculate mouse coordinate var x = canvas.width / canvas.offsetWidth; var y = canvas.height / canvas.offsetHeight; //calculate offset if(e.offsetX != null){ //chrome, opera x *= e.offsetX; y *= e.offsetY; } else { //firefox x *= e.layerX - canvas.offsetLeft; y *= e.layerY - canvas.offsetTop; } var listeners = re.c('mouse').l; /* if(re.preventDefault && re.preventDefault.d[key]){ e.preventDefault(); } */ var c, t, obj; for(var i=0; i