2012-06-21 10:13:21 +02:00
|
|
|
ig.module(
|
|
|
|
'weltmeister.evented-input'
|
|
|
|
)
|
|
|
|
.requires(
|
|
|
|
'impact.input'
|
|
|
|
)
|
2012-06-22 17:26:53 +02:00
|
|
|
.defines(function(){ "use strict";
|
2012-06-21 10:13:21 +02:00
|
|
|
|
|
|
|
wm.EventedInput = ig.Input.extend({
|
|
|
|
mousemoveCallback: null,
|
|
|
|
keyupCallback: null,
|
|
|
|
keydownCallback: null,
|
|
|
|
|
|
|
|
delayedKeyup: {push:function(){},length: 0},
|
|
|
|
|
|
|
|
|
|
|
|
keydown: function( event ) {
|
|
|
|
if( event.target.type == 'text' ) { return; }
|
|
|
|
|
|
|
|
var code = event.type == 'keydown'
|
|
|
|
? event.keyCode
|
|
|
|
: (event.button == 2 ? ig.KEY.MOUSE2 : ig.KEY.MOUSE1);
|
|
|
|
var action = this.bindings[code];
|
|
|
|
if( action ) {
|
|
|
|
if( !this.actions[action] ) {
|
|
|
|
this.actions[action] = true;
|
|
|
|
if( this.keydownCallback ) {
|
|
|
|
this.keydownCallback( action );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
keyup: function( event ) {
|
|
|
|
if( event.target.type == 'text' ) { return; }
|
|
|
|
var code = event.type == 'keyup'
|
|
|
|
? event.keyCode
|
|
|
|
: (event.button == 2 ? ig.KEY.MOUSE2 : ig.KEY.MOUSE1);
|
|
|
|
var action = this.bindings[code];
|
|
|
|
if( action ) {
|
|
|
|
this.actions[action] = false;
|
|
|
|
if( this.keyupCallback ) {
|
|
|
|
this.keyupCallback( action );
|
|
|
|
}
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-06-22 17:26:53 +02:00
|
|
|
mousewheel: function( event ) {
|
|
|
|
var delta = event.wheelDelta ? event.wheelDelta : (event.detail * -1);
|
|
|
|
var code = delta > 0 ? ig.KEY.MWHEEL_UP : ig.KEY.MWHEEL_DOWN;
|
|
|
|
var action = this.bindings[code];
|
|
|
|
if( action ) {
|
|
|
|
if( this.keyupCallback ) {
|
|
|
|
this.keyupCallback( action );
|
|
|
|
}
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-06-21 10:13:21 +02:00
|
|
|
mousemove: function( event ) {
|
|
|
|
this.parent( event );
|
|
|
|
if( this.mousemoveCallback ) {
|
|
|
|
this.mousemoveCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|