Browse Source

Input now handles 'mousewheel' and 'wheel' events.

dev-tmpl
Bryan Miller 6 years ago
parent
commit
76ed24239f
1 changed files with 32 additions and 7 deletions
  1. +32
    -7
      app/js/ui/Input.js

+ 32
- 7
app/js/ui/Input.js View File

case 8000: case 8000:
ename += ((ename !== "") ? "+" : "") + "mousemove"; ename += ((ename !== "") ? "+" : "") + "mousemove";
break; break;
case 8001:
ename += ((ename !== "") ? "+" : "") + "wheel";
default: default:
ename += ((ename !== "") ? "+" : "") + "mousebtn" + codes[i].toString(); ename += ((ename !== "") ? "+" : "") + "mousebtn" + codes[i].toString();
} }
} }
} else if (key === "mousemove"){ } else if (key === "mousemove"){
mcodes.push(8000); mcodes.push(8000);
} else if (key === "wheel"){
mcodes.push(8001);
} }


// Now handle keyboard event names. // Now handle keyboard event names.
x: pos.x, x: pos.x,
y: pos.y, y: pos.y,
button: this.__mouseLastButton, button: this.__mouseLastButton,
delta: 0,
action: "mousemove" action: "mousemove"
}; };
if (ename !== "" && ename !== "mousemove") if (ename !== "" && ename !== "mousemove")
x: pos.x, x: pos.x,
y: pos.y, y: pos.y,
button: button, button: button,
delta: 0,
action: "mousedown" action: "mousedown"
}; };
this.__mousePosition = pos; this.__mousePosition = pos;
x: pos.x, x: pos.x,
y: pos.y, y: pos.y,
button: button, button: button,
delta: 0,
action: "mouseup" action: "mouseup"
} }
this.__emitter.emit("mouseup", data); this.__emitter.emit("mouseup", data);
}).bind(this); }).bind(this);


var handle_mousewheel = (function(e){ var handle_mousewheel = (function(e){
if (this.__preventDefaults)
e.preventDefault();
// TODO: Finish me!
var pos = mousePosition(e);
if (pos.inbounds === true){
if (this.__preventDefaults)
e.preventDefault();
var ename = MouseEventName("wheel");
var data = {
source: this,
lastX: pos.lastX,
lastY: pos.lastY,
x: pos.x,
y: pos.y,
button: this.__mouseLastButton,
delta: Math.sign(e.deltaY),
action: "wheel"
};
if (ename !== "wheel")
this.__emitter.emit(ename, data);
this.__emitter.emit("wheel", data);
}
}).bind(this); }).bind(this);


// This event is purely for preventing Default behaviors on mouse events we're not using. // This event is purely for preventing Default behaviors on mouse events we're not using.
window.addEventListener("mousemove", handle_mousemove); window.addEventListener("mousemove", handle_mousemove);
window.addEventListener("mousedown", handle_mousedown); window.addEventListener("mousedown", handle_mousedown);
window.addEventListener("mouseup", handle_mouseup); window.addEventListener("mouseup", handle_mouseup);
window.addEventListener("mousewheel", handle_mousewheel);
window.addEventListener("mousewheel", handle_mousewheel); // For older browsers?
window.addEventListener("wheel", handle_mousewheel);
window.addEventListener("click", handle_mouseprevdef); window.addEventListener("click", handle_mouseprevdef);
window.addEventListener("dblclick", handle_mouseprevdef); window.addEventListener("dblclick", handle_mouseprevdef);
window.addEventListener("contextmenu", handle_mouseprevdef); window.addEventListener("contextmenu", handle_mouseprevdef);
window.removeEventListener("mousemove", handle_mousemove); window.removeEventListener("mousemove", handle_mousemove);
window.removeEventListener("mousedown", handle_mousedown); window.removeEventListener("mousedown", handle_mousedown);
window.removeEventListener("mouseup", handle_mouseup); window.removeEventListener("mouseup", handle_mouseup);
window.removeEventListener("mousewheel", handle_mousewheel);
window.removeEventListener("mousewheel", handle_mousewheel); // For older browsers?
window.removeEventListener("wheel", handle_mousewheel);
window.removeEventListener("click", handle_mouseprevdef); window.removeEventListener("click", handle_mouseprevdef);
window.removeEventListener("dblclick", handle_mouseprevdef); window.removeEventListener("dblclick", handle_mouseprevdef);
window.removeEventListener("contextmenu", handle_mouseprevdef); window.removeEventListener("contextmenu", handle_mouseprevdef);
} }


listen(ename, func, owner=null, once=false){ listen(ename, func, owner=null, once=false){
if ((["keyup", "keydown", "keypress", "mousemove", "mousedown", "mouseup", "mouseclick"]).indexOf(ename) >= 0){
if ((["keyup", "keydown", "keypress", "mousemove", "mousedown", "mouseup", "mouseclick", "wheel"]).indexOf(ename) >= 0){
this.__emitter.listen(ename, func, owner, once); this.__emitter.listen(ename, func, owner, once);
} else { } else {
ename = ReorderEventName(ename); ename = ReorderEventName(ename);
} }


unlisten(ename, func, owner=null){ unlisten(ename, func, owner=null){
if ((["keyup", "keydown", "keypress", "mousemove", "mousedown", "mouseup", "mouseclick"]).indexOf(ename) >= 0){
if ((["keyup", "keydown", "keypress", "mousemove", "mousedown", "mouseup", "mouseclick", "wheel"]).indexOf(ename) >= 0){
this.__emitter.unlisten(ename, func, owner); this.__emitter.unlisten(ename, func, owner);
} else { } else {
ename = ReorderEventName(ename); ename = ReorderEventName(ename);

Loading…
Cancel
Save