Skip to content
Browse files

Keypad changes:

Keypad -> Keyboard (it dispatche keyboard events, not just keypad
events)
Events:
  keyDown -> onKeyDown (in order to follow the new event convention)
  keyUp   -> onKeyUp
  • Loading branch information...
1 parent f627638 commit 7274831188eeebfe67da20bdf94702d62e811584 @ricardoquesada ricardoquesada committed Aug 9, 2012
View
14 cocos2d/CCDirector.js
@@ -186,7 +186,7 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
_scheduler:null,
_actionManager:null,
_touchDispatcher:null,
- _keypadDispatcher:null,
+ _keyboardDispatcher:null,
_accelerometer:null,
_watcherFun:null,
@@ -248,8 +248,8 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
this._touchDispatcher = new cc.TouchDispatcher();
this._touchDispatcher.init();
- //KeypadDispatcher
- this._keypadDispatcher = cc.KeypadDispatcher.getInstance();
+ //KeyboardDispatcher
+ this._keyboardDispatcher = cc.KeyboardDispatcher.getInstance();
//accelerometer
//this._accelerometer = new cc.Accelerometer();
@@ -1115,11 +1115,11 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{
}
},
- getKeypadDispatcher:function () {
- return this._keypadDispatcher;
+ getKeyboardDispatcher:function () {
+ return this._keyboardDispatcher;
},
- setKeypadDispatcher:function (keypadDispatcher) {
- this._keypadDispatcher = keypadDispatcher;
+ setKeyboardDispatcher:function (keyboardDispatcher) {
+ this._keyboardDispatcher = keyboardDispatcher;
},
getAccelerometer:function () {
View
6 cocos2d/build.xml
@@ -68,8 +68,8 @@
<file name="touch_dispatcher/CCTouchDelegateProtocol.js"/>
<file name="touch_dispatcher/CCTouchHandler.js"/>
<file name="touch_dispatcher/CCTouchDispatcher.js"/>
- <file name="keypad_dispatcher/CCKeypadDelegate.js"/>
- <file name="keypad_dispatcher/CCKeypadDispatcher.js"/>
+ <file name="keyboard_dispatcher/CCKeyboardDelegate.js"/>
+ <file name="keyboard_dispatcher/CCKeyboardDispatcher.js"/>
<file name="text_input_node/CCIMEDispatcher.js"/>
<file name="text_input_node/CCTextFieldTTF.js"/>
<file name="CCDirector.js"/>
@@ -93,4 +93,4 @@
</sources>
</jscomp>
</target>
-</project>
+</project>
View
BIN cocos2d/keyboard_dispatcher/.CCKeypadDelegate.js.swp
Binary file not shown.
View
BIN cocos2d/keyboard_dispatcher/.CCKeypadDispatcher.js.swp
Binary file not shown.
View
32 ...s2d/keypad_dispatcher/CCKeypadDelegate.js → ...keyboard_dispatcher/CCKeyboardDelegate.js
@@ -26,50 +26,50 @@
/**
- * you must extend the keypadDelegate and
+ * you must extend the keyboardDelegate and
* implement your own game logic in
* keydown and keyup functions
* @class
* @extends cc.Class
*/
-cc.KeypadDelegate = cc.Class.extend(/** @lends cc.KeypadDelegate# */{
+cc.KeyboardDelegate = cc.Class.extend(/** @lends cc.KeyboardDelegate# */{
/**
* Call back when a key is pressed down
*/
- keyDown:function () {
+ onKeyDown:function () {
},
/**
* Call back when a key is released
*/
- keyUp:function () {
+ onKeyUp:function () {
}
});
/**
- * KeypadHandler is an object that contains KeypadDelegate
+ * KeyboardHandler is an object that contains KeyboardDelegate
* @class
* @extends cc.Class
*/
-cc.KeypadHandler = cc.Class.extend(/** @lends cc.KeypadHandler# */{
+cc.KeyboardHandler = cc.Class.extend(/** @lends cc.KeyboardHandler# */{
/**
- * returns the keypad delegate
- * @return {cc.KeypadDelegate}
+ * returns the keyboard delegate
+ * @return {cc.KeyboardDelegate}
*/
getDelegate:function () {
return this._delegate;
},
/**
- * set the keypad delegate
- * @param {cc.KeypadDelegate} delegate
+ * set the keyboard delegate
+ * @param {cc.KeyboardDelegate} delegate
*/
setDelegate:function (delegate) {
this._delegate = delegate;
},
/**
- * initializes a cc.KeypadHandler with a delegate
- * @param {cc.KeypadDelegate} delegate
+ * initializes a cc.KeyboardHandler with a delegate
+ * @param {cc.KeyboardDelegate} delegate
* @return {Boolean}
*/
initWithDelegate:function (delegate) {
@@ -82,12 +82,12 @@ cc.KeypadHandler = cc.Class.extend(/** @lends cc.KeypadHandler# */{
_delegate:null
});
/**
- * Create a KeypadHandler with KeypadDelegate
+ * Create a KeyboardHandler with KeyboardDelegate
* @param delegate
- * @return {cc.KeypadHandler}
+ * @return {cc.KeyboardHandler}
*/
-cc.KeypadHandler.create = function (delegate) {
- var handler = new cc.KeypadHandler();
+cc.KeyboardHandler.create = function (delegate) {
+ var handler = new cc.KeyboardHandler();
handler.initWithDelegate(delegate);
return handler;
};
View
52 ...d/keypad_dispatcher/CCKeypadDispatcher.js → ...yboard_dispatcher/CCKeyboardDispatcher.js
@@ -164,14 +164,14 @@ cc.KEY = {
};
/**
- * Dispatch the keypad message
+ * Dispatch the keyboard message
* @class
* @extends cc.Class
*/
-cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
+cc.KeyboardDispatcher = cc.Class.extend(/** @lends cc.KeyboardDispatcher# */{
/**
- * add delegate to concern keypad msg
- * @param {cc.KeypadDelegate} delegate keypad delegate object
+ * add delegate to concern keyboard msg
+ * @param {cc.KeyboardDelegate} delegate keyboard delegate object
*/
addDelegate:function (delegate) {
if (!delegate) {
@@ -187,8 +187,8 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
},
/**
- * remove the delegate from the delegates who concern keypad msg
- * @param {cc.KeypadDelegate} delegate
+ * remove the delegate from the delegates who concern keyboard msg
+ * @param {cc.KeyboardDelegate} delegate
*/
removeDelegate:function (delegate) {
if (!delegate) {
@@ -205,10 +205,10 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
/**
* force add the delegate
- * @param {cc.KeypadDelegate} delegate
+ * @param {cc.KeyboardDelegate} delegate
*/
forceAddDelegate:function (delegate) {
- var handler = cc.KeypadHandler.create(delegate);
+ var handler = cc.KeyboardHandler.create(delegate);
if (handler) {
//if handler already exist
for (var i = 0; i < this._delegates; i++) {
@@ -221,7 +221,7 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
/**
* force remove the delegate
- * @param {cc.KeypadDelegate} delegate
+ * @param {cc.KeyboardDelegate} delegate
*/
forceRemoveDelegate:function (delegate) {
for (var i = 0; i < this._delegates.length; i++) {
@@ -233,12 +233,12 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
},
/**
- * dispatch the keypad message to the delegates
+ * dispatch the keyboard message to the delegates
* @param {event} e
* @param {Boolean} keydown whether this is a keydown or keyup
* @return {Boolean}
*/
- dispatchKeypadMSG:function (e, keydown) {
+ dispatchKeyboardMSG:function (e, keydown) {
this._locked = true;
e.stopPropagation();
e.preventDefault();
@@ -247,13 +247,13 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
{
//execute all deletegate that registered a keyboard event
for (var i = 0; i < this._delegates.length; i++) {
- this._delegates[i].getDelegate().keyDown(e.keyCode);
+ this._delegates[i].getDelegate().onKeyDown(e.keyCode);
}
}
else if (!keydown && e)//if keyup and our keymap have that key in it
{
for (var i = 0; i < this._delegates.length; i++) {
- this._delegates[i].getDelegate().keyUp(e.keyCode);
+ this._delegates[i].getDelegate().onKeyUp(e.keyCode);
}
}
this._locked = false;
@@ -286,33 +286,33 @@ cc.KeypadDispatcher = cc.Class.extend(/** @lends cc.KeypadDispatcher# */{
});
/**
- * Returns the shared cc.KeypadDispatcher object for the system.
- * @return {cc.keypadDispatcher}
+ * Returns the shared cc.KeyboardDispatcher object for the system.
+ * @return {cc.keyboardDispatcher}
*/
-cc.KeypadDispatcher.getInstance = function () {
- if (!cc.keypadDispatcher) {
- cc.keypadDispatcher = new cc.KeypadDispatcher();
+cc.KeyboardDispatcher.getInstance = function () {
+ if (!cc.keyboardDispatcher) {
+ cc.keyboardDispatcher = new cc.KeyboardDispatcher();
//make canvas focusable
cc.canvas.setAttribute('contentEditable', true);
cc.canvas.style.outline = 'none';
cc.canvas.style.cursor = 'default';
cc.canvas.addEventListener("keydown", function (e) {
- cc.keypadDispatcher.dispatchKeypadMSG(e, true);
+ cc.keyboardDispatcher.dispatchKeyboardMSG(e, true);
cc.IMEDispatcher.getInstance().processKeycode(e.keyCode);
});
cc.canvas.addEventListener("keyup", function (e) {
- cc.keypadDispatcher.dispatchKeypadMSG(e, false);
+ cc.keyboardDispatcher.dispatchKeyboardMSG(e, false);
});
}
- return cc.keypadDispatcher;
+ return cc.keyboardDispatcher;
};
/**
- * Release the shared cc.KeypadDispatcher object from the system.
+ * Release the shared cc.KeyboardDispatcher object from the system.
*/
-cc.KeypadDispatcher.purgeSharedDispatcher = function () {
- if (cc.keypadDispatcher) {
- delete cc.keypadDispatcher;
- cc.keypadDispatcher = null;
+cc.KeyboardDispatcher.purgeSharedDispatcher = function () {
+ if (cc.keyboardDispatcher) {
+ delete cc.keyboardDispatcher;
+ cc.keyboardDispatcher = null;
}
};
View
26 cocos2d/layers_scenes_transitions_nodes/CCLayer.js
@@ -34,7 +34,7 @@
cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
_isTouchEnabled:false,
_isAccelerometerEnabled:false,
- _isKeypadEnabled:false,
+ _isKeyboardEnabled:false,
/**
* Constructor
@@ -134,28 +134,28 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
},
/**
- * whether or not it will receive keypad events<br/>
+ * whether or not it will receive keyboard events<br/>
* You can enable / disable accelerometer events with this property.<br/>
* it's new in cocos2d-x
* @return {Boolean}
*/
- isKeypadEnabled:function () {
- return this._isKeypadEnabled;
+ isKeyboardEnabled:function () {
+ return this._isKeyboardEnabled;
},
/**
* Enable Keyboard interaction
* @param {Boolean} enabled
*/
- setKeypadEnabled:function (enabled) {
- if (enabled != this._isKeypadEnabled) {
- this._isKeypadEnabled = enabled;
+ setKeyboardEnabled:function (enabled) {
+ if (enabled != this._isKeyboardEnabled) {
+ this._isKeyboardEnabled = enabled;
if (this._isRunning) {
var director = cc.Director.getInstance();
if (enabled) {
- director.getKeypadDispatcher().addDelegate(this);
+ director.getKeyboardDispatcher().addDelegate(this);
} else {
- director.getKeypadDispatcher().removeDelegate(this);
+ director.getKeyboardDispatcher().removeDelegate(this);
}
}
}
@@ -181,8 +181,8 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
}
// add this layer to concern the kaypad msg
- if (this._isKeypadEnabled) {
- director.getKeypadDispatcher().addDelegate(this);
+ if (this._isKeyboardEnabled) {
+ director.getKeyboardDispatcher().addDelegate(this);
}
},
@@ -201,8 +201,8 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
}
// remove this layer from the delegates who concern the kaypad msg
- if (this._isKeypadEnabled) {
- director.getKeypadDispatcher().removeDelegate(this);
+ if (this._isKeyboardEnabled) {
+ director.getKeyboardDispatcher().removeDelegate(this);
}
this._super();
View
4 cocos2d/platform/jsloader.js
@@ -82,8 +82,8 @@ var cc = cc || cc || {};
'touch_dispatcher/CCTouchDelegateProtocol.js',
'touch_dispatcher/CCTouchHandler.js',
'touch_dispatcher/CCTouchDispatcher.js',
- 'keypad_dispatcher/CCKeypadDelegate.js',
- 'keypad_dispatcher/CCKeypadDispatcher.js',
+ 'keyboard_dispatcher/CCKeyboardDelegate.js',
+ 'keyboard_dispatcher/CCKeyboardDispatcher.js',
'text_input_node/CCIMEDispatcher.js',
'text_input_node/CCTextFieldTTF.js',
'CCDirector.js',
View
2 cocos2d/text_input_node/CCIMEDispatcher.js
@@ -422,7 +422,7 @@ cc.IMEDispatcher.Impl = cc.Class.extend(/** @lends cc.IMEDispatcher.Impl# */{
cc.IMEDispatcher.getInstance = function () {
if (!cc.IMEDispatcher.instance) {
cc.IMEDispatcher.instance = new cc.IMEDispatcher();
- cc.KeypadDispatcher.getInstance();
+ cc.KeyboardDispatcher.getInstance();
}
return cc.IMEDispatcher.instance;
};
View
2 tests/src/testbasic.js
@@ -210,7 +210,7 @@ var testNames = [
return new IntervalTestScene();
}
},
- //"KeypadTest",
+ //"KeyboardTest",
{
title:"LabelTest",
testScene:function () {

0 comments on commit 7274831

Please sign in to comment.
Something went wrong with that request. Please try again.