Browse Source

Added initial code for handling mouse. Nothing functional.

dev-tmpl
Bryan Miller 6 years ago
parent
commit
da3b49763a
1 changed files with 40 additions and 0 deletions
  1. +40
    -0
      app/js/ui/Input.js

+ 40
- 0
app/js/ui/Input.js View File

@@ -235,6 +235,8 @@ function ReorderEventName(ename){
export default class Input{
constructor(){
this.__emitter = new EventCaller();
this.__preventDefaults = false;

this.enableKeyboardInput = (function(){
var handle_keydown = (function(e){
if (AddToKeymap(e.keyCode, "keydown")){
@@ -286,6 +288,39 @@ export default class Input{
}).bind(this);
}).apply(this);

this.enableMouseInput = (function(){
var handle_mousemove = (function(e){
// TODO: Finish me!
}).bind(this);

var handle_mousedown = (function(e){
// TODO: Finish me!
}).bind(this);

var handle_mouseup = (function(e){
// TODO: Finish me!
}).bind(this);

var handle_mousewheel = (function(e){
// TODO: Finish me!
}).bind(this);

return (function(enable){
enable = (enable !== false);
if (enable){
window.addEventListener("mousemove", handle_mousemove);
window.addEventListener("mousedown", handle_mousedown);
window.addEventListener("mouseup", handle_mouseup);
window.addEventListener("mousewheel", handle_mousewheel);
} else {
window.removeEventListener("mousemove", handle_mousemove);
window.removeEventListener("mousedown", handle_mousedown);
window.removeEventListener("mouseup", handle_mouseup);
window.removeEventListener("mousewheel", handle_mousewheel);
}
}).bind(this);
}).apply(this);

this.enableKeyboardInput();
}

@@ -311,6 +346,11 @@ export default class Input{
return KEYMAP["currentcodes"].map(e=>e[0]);
}

get preventDefaults(){return this.__preventDefaults;}
set preventDefaults(p){
this.__preventDefaults = (p === true);
}

isKeyDown(key){
if (typeof(key) === 'string'){
key = KeyNameToCode(key);

Loading…
Cancel
Save