master
sigonasr2, Sig, Sigo 4 years ago
parent bc9b273481
commit 3dad07d3fa
  1. 16
      objects.js
  2. 26
      test.js

@ -37,10 +37,10 @@ class Object {
keyReleaseEvent(e) { keyReleaseEvent(e) {
} }
mousePressEvent(e) { mousePressEvent(e,pressed) {
} }
mouseReleaseEvent(e) { mouseReleaseEvent(e,pressed) {
} }
mouseEvent(e) { mouseEvent(e) {
@ -99,15 +99,15 @@ class DebugObj extends Object{
this.storedMouseY=e.offsetY; this.storedMouseY=e.offsetY;
//this.messages.push(this.lastMessage); //this.messages.push(this.lastMessage);
} }
mousePressEvent(e) { mousePressEvent(e,pressed) {
this.eventCount++; this.eventCount++;
super.mousePressEvent(e); super.mousePressEvent(e,pressed);
this.lastMessage="Mouse Press Event"; this.lastMessage="Mouse Press Event: "+JSON.stringify(pressed);
} }
mouseReleaseEvent(e) { mouseReleaseEvent(e,pressed) {
this.eventCount++; this.eventCount++;
super.mouseReleaseEvent(e); super.mouseReleaseEvent(e,pressed);
this.lastMessage="Mouse Release Event"; this.lastMessage="Mouse Release Event: "+JSON.stringify(pressed);
} }
keyPressEvent(e) { keyPressEvent(e) {
this.eventCount++; this.eventCount++;

@ -78,28 +78,30 @@ function mousePressEvent(e) {
"MOUSE4" "MOUSE4"
"MOUSE5" "MOUSE5"
*/ */
var pressedDown = {left:false,right:false,middle:false,mouse4:false,mouse5:false}
mouseDown.splice(0,mouseDown.length); mouseDown.splice(0,mouseDown.length);
var buttonamt = e.buttons; var buttonamt = e.buttons;
if (buttonamt>=16) {buttonamt-=16;mouseDown.push("MOUSE5");} if (buttonamt>=16) {buttonamt-=16;pressedDown.mouse5=true;mouseDown.push("MOUSE5");}
if (buttonamt>=8) {buttonamt-=8;mouseDown.push("MOUSE4");} if (buttonamt>=8) {buttonamt-=8;pressedDown.mouse4=true;mouseDown.push("MOUSE4");}
if (buttonamt>=4) {buttonamt-=4;mouseDown.push("MIDDLE");} if (buttonamt>=4) {buttonamt-=4;pressedDown.middle=true;mouseDown.push("MIDDLE");}
if (buttonamt>=2) {buttonamt-=2;mouseDown.push("RIGHT");} if (buttonamt>=2) {buttonamt-=2;pressedDown.right=true;mouseDown.push("RIGHT");}
if (buttonamt>=1) {buttonamt-=1;mouseDown.push("LEFT");} if (buttonamt>=1) {buttonamt-=1;pressedDown.left=true;mouseDown.push("LEFT");}
for (i=0;i<gameObjs.length;i++) { for (i=0;i<gameObjs.length;i++) {
gameObjs[i].mousePressEvent(e); gameObjs[i].mousePressEvent(e,pressedDown);
} }
} }
function mouseReleaseEvent(e) { function mouseReleaseEvent(e) {
var pressedDown = {left:false,right:false,middle:false,mouse4:false,mouse5:false}
mouseDown.splice(0,mouseDown.length); mouseDown.splice(0,mouseDown.length);
var buttonamt = e.buttons; var buttonamt = e.buttons;
if (buttonamt>=16) {buttonamt-=16;mouseDown.push("MOUSE5");} if (buttonamt>=16) {buttonamt-=16;pressedDown.mouse5=true;mouseDown.push("MOUSE5");}
if (buttonamt>=8) {buttonamt-=8;mouseDown.push("MOUSE4");} if (buttonamt>=8) {buttonamt-=8;pressedDown.mouse4=true;mouseDown.push("MOUSE4");}
if (buttonamt>=4) {buttonamt-=4;mouseDown.push("MIDDLE");} if (buttonamt>=4) {buttonamt-=4;pressedDown.middle=true;mouseDown.push("MIDDLE");}
if (buttonamt>=2) {buttonamt-=2;mouseDown.push("RIGHT");} if (buttonamt>=2) {buttonamt-=2;pressedDown.right=true;mouseDown.push("RIGHT");}
if (buttonamt>=1) {buttonamt-=1;mouseDown.push("LEFT");} if (buttonamt>=1) {buttonamt-=1;pressedDown.left=true;mouseDown.push("LEFT");}
for (i=0;i<gameObjs.length;i++) { for (i=0;i<gameObjs.length;i++) {
gameObjs[i].mouseReleaseEvent(e); gameObjs[i].mouseReleaseEvent(e,pressedDown);
} }
} }

Loading…
Cancel
Save