Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
aSydiK committed Jul 9, 2010
1 parent b1aac3b commit 8075508
Showing 1 changed file with 119 additions and 4 deletions.
123 changes: 119 additions & 4 deletions psapi.js
Expand Up @@ -24,7 +24,7 @@ function PointStream(){
var VBOs;

// browser detection to handle differences such as mouse scrolling
var browser = -1 ;
var browser = -1;
const MINEFIELD = 0;
const CHROME = 1;
const CHROMIUM = 2;
Expand Down Expand Up @@ -339,6 +339,91 @@ function PointStream(){
return programObject;
};

/**
*/
function keyCodeMap(code, shift) {
// Letters
if (code >= 65 && code <= 90) { // A-Z
// Keys return ASCII for upcased letters.
// Convert to downcase if shiftKey is not pressed.
if (shift) {
return code;
}
else {
return code + 32;
}
}
// Numbers and their shift-symbols
else if (code >= 48 && code <= 57) { // 0-9
if (shift) {
switch (code) {
case 49:
return 33; // !
case 50:
return 64; // @
case 51:
return 35; // #
case 52:
return 36; // $
case 53:
return 37; // %
case 54:
return 94; // ^
case 55:
return 38; // &
case 56:
return 42; // *
case 57:
return 40; // (
case 48:
return 41; // )
}
}
}
// Coded keys
else if (codedKeys.indexOf(code) >= 0) { // SHIFT, CONTROL, ALT, LEFT, RIGHT, UP, DOWN
p.keyCode = code;
return p.CODED;
}
// Symbols and their shift-symbols
else {
if (shift) {
switch (code) {
case 107:
return 43; // +
case 219:
return 123; // {
case 221:
return 125; // }
case 222:
return 34; // "
}
} else {
switch (code) {
case 188:
return 44; // ,
case 109:
return 45; // -
case 190:
return 46; // .
case 191:
return 47; // /
case 192:
return 96; // ~
case 219:
return 91; // [
case 220:
return 92; // \
case 221:
return 93; // ]
case 222:
return 39; // '
}
}
}
return code;
};

/**
*/
var xb = {
Expand All @@ -347,6 +432,9 @@ function PointStream(){
*/
mouseX: 0,
mouseY: 0,
keyDownCode: null,
keyUpCode: null,
keyPressCode: null,

// Number of frames per seconds rendered in the last second.
frameRate: 0,
Expand Down Expand Up @@ -535,23 +623,47 @@ function PointStream(){
delta = -evt.wheelDelta / 360;
}

if(xb.onMouseScroll){
if(typeof xb.onMouseScroll === "function"){
xb.onMouseScroll(delta);
}
},

_mousePressed: function(evt){
if(xb.onMousePressed){
if(typeof xb.onMousePressed === "function"){
xb.onMousePressed();
}
},

_mouseReleased: function(){
if(xb.onMouseReleased){
if(typeof xb.onMouseReleased === "function"){
xb.onMouseReleased();
}
},

_keyDown: function(evt){
keyDownCode = keyCodeMap(evt.keyCode, evt.shiftKey);
if(typeof xb.keyDown === "function"){
xb.keyDown();
}
},

_keyPressed: function(evt){
if (evt.charCode){
keyPressCode = keyCodeMap(evt.charCode, evt.shiftKey);
} else {
keyPressCode = keyCodeMap(evt.keyCode, evt.shiftKey);
}
if(typeof xb.keyPressed === "function"){
xb.keyPressed();
}
},

_keyUp: function(evt){
if(typeof xb.keyUp === "function"){
xb.keyUp();
}
},

/**
cvs
renderCB
Expand All @@ -573,6 +685,9 @@ function PointStream(){
xb.attach(cvs, "mousemove", xb.mouseMove);
xb.attach(cvs, "DOMMouseScroll", xb._mouseScroll);
xb.attach(cvs, "mousewheel", xb._mouseScroll);
xb.attach(cvs, "keydown", xb._keyDown);
xb.attach(cvs, "keypress", xb._keyPressed);
xb.attach(cvs, "keyup", xb._keyUp);
},

/**
Expand Down

0 comments on commit 8075508

Please sign in to comment.