From 14760461b99bd06b0e1470283e6a6154a35aaa27 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 4 Mar 2014 19:35:54 +0800 Subject: [PATCH 1/6] most event dispatcher test work. --- .../bindings/manual/cocos2d_specifics.cpp | 3 + .../bindings/manual/cocos2d_specifics.hpp | 2 + .../bindings/script/jsb_cocos2d.js | 259 ++++++++++-------- .../NewEventManagerTest.js | 57 ++-- tools/tojs/cocos2dx.ini | 5 +- 5 files changed, 177 insertions(+), 149 deletions(-) diff --git a/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp b/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp index df15674ce8..8f18e6fe43 100644 --- a/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp +++ b/frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp @@ -4202,6 +4202,9 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global) JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, jsb_cocos2d_EventListener_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, jsb_cocos2d_EventListener_prototype, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, jsb_cocos2d_GLProgram_prototype, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, jsb_cocos2d_GLProgram_prototype, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, jsb_cocos2d_Node_prototype, "onExit", js_doNothing, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); diff --git a/frameworks/js-bindings/bindings/manual/cocos2d_specifics.hpp b/frameworks/js-bindings/bindings/manual/cocos2d_specifics.hpp index 3d819ea9b0..e5fa08ac0b 100644 --- a/frameworks/js-bindings/bindings/manual/cocos2d_specifics.hpp +++ b/frameworks/js-bindings/bindings/manual/cocos2d_specifics.hpp @@ -75,6 +75,8 @@ inline js_proxy_t *js_get_or_create_proxy(JSContext *cx, T *native_obj) { return NULL; } + JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET + JSObject* js_obj = JS_NewObject(cx, typeProxy->jsclass, typeProxy->proto, typeProxy->parentProto); proxy = jsb_new_proxy(native_obj, js_obj); #ifdef DEBUG diff --git a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js index 6b01dc6093..cefc1e76d3 100644 --- a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js +++ b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js @@ -716,111 +716,6 @@ var __onParseConfig = function(type, str) { } }; -cc.visibleRect = { - _topLeft:cc.p(0,0), - _topRight:cc.p(0,0), - _top:cc.p(0,0), - _bottomLeft:cc.p(0,0), - _bottomRight:cc.p(0,0), - _bottom:cc.p(0,0), - _center:cc.p(0,0), - _left:cc.p(0,0), - _right:cc.p(0,0), - _width:0, - _height:0, - _isInitialized: false, - init:function(){ - var director = cc.Director.getInstance(); - var origin = director.getVisibleOrigin(); - var size = director.getVisibleSize(); - - this._width = size.width; - this._height = size.height; - - var x = origin.x; - var y = origin.y; - var w = this._width; - var h = this._height; - - var left = origin.x; - var right = origin.x + size.width; - var middle = origin.x + size.width/2; - - //top - this._top.y = this._topLeft.y = this._topRight.y = y + h; - this._topLeft.x = left; - this._top.x = middle; - this._topRight.x = right; - - //bottom - - this._bottom.y = this._bottomRight.y = this._bottomLeft.y = y; - this._bottomLeft.x = left - this._bottom.x = middle; - this._bottomRight.x = right; - - //center - this._right.y = this._left.y = this._center.y = y + h/2; - this._center.x = middle; - - //left - this._left.x = left; - - //right - this._right.x = right; - }, - - lazyInit: function(){ - if (!this._isInitialized) { - this.init(); - this._isInitialized = true; - } - }, - getWidth:function(){ - this.lazyInit(); - return this._width; - }, - getHeight:function(){ - this.lazyInit(); - return this._height; - }, - topLeft:function(){ - this.lazyInit(); - return this._topLeft; - }, - topRight:function(){ - this.lazyInit(); - return this._topRight; - }, - top:function(){ - this.lazyInit(); - return this._top; - }, - bottomLeft:function(){ - this.lazyInit(); - return this._bottomLeft; - }, - bottomRight:function(){ - this.lazyInit(); - return this._bottomRight; - }, - bottom:function(){ - this.lazyInit(); - return this._bottom; - }, - center:function(){ - this.lazyInit(); - return this._center; - }, - left:function(){ - this.lazyInit(); - return this._left; - }, - right:function(){ - this.lazyInit(); - return this._right; - } -}; var _windowTimeIntervalId = 0; var _windowTimeFunHash = {}; @@ -1120,19 +1015,6 @@ cc.EventListener.CUSTOM = 6; cc.eventManager = cc.Director.getInstance().getEventDispatcher(); -cc.eventManager.addListener = function(listener, nodeOrPriority) { - if (typeof nodeOrPriority == "number") { - if (nodeOrPriority == 0) { - cc.log("0 priority is forbidden for fixed priority since it's used for scene graph based priority."); - return; - } - - cc.eventManager.addEventListenerWithFixedPriority(listener, nodeOrPriority); - } else { - cc.eventManager.addEventListenerWithSceneGraphPriority(listener, nodeOrPriority); - } -}; - cc.EventListener.create = function(argObj){ if(!argObj || !argObj.event){ throw "Invalid parameter."; @@ -1161,6 +1043,10 @@ cc.EventListener.create = function(argObj){ listener = cc.EventListenerAcceleration.create(argObj.callback); delete argObj.callback; } + else + { + cc.log("Error: Invalid listener type."); + } for(var key in argObj) { listener[key] = argObj[key]; @@ -1169,4 +1055,141 @@ cc.EventListener.create = function(argObj){ return listener; }; +cc.eventManager.addListener = function(listener, nodeOrPriority) { + if(!(listener instanceof cc.EventListener)) { + listener = cc.EventListener.create(listener); + } + + if (typeof nodeOrPriority == "number") { + if (nodeOrPriority == 0) { + cc.log("0 priority is forbidden for fixed priority since it's used for scene graph based priority."); + return; + } + + cc.eventManager.addEventListenerWithFixedPriority(listener, nodeOrPriority); + } else { + cc.eventManager.addEventListenerWithSceneGraphPriority(listener, nodeOrPriority); + } +}; + +cc.EventCustom.prototype.setUserData = function(userData) { + this._userData = userData; +}; + +cc.EventCustom.prototype.getUserData = function() { + return this._userData; +}; + +cc.inputManager = { + setAccelerometerEnabled: cc.Device.setAccelerometerEnabled, + setAccelerometerInterval: cc.Device.setAccelerometerInterval, + getDPI: cc.Device.getDPI +}; + cc.director = cc.Director.getInstance(); + +cc.Director.EVENT_PROJECTION_CHANGED = "director_projection_changed"; +cc.Director.EVENT_AFTER_DRAW = "director_after_draw"; +cc.Director.EVENT_AFTER_VISIT = "director_after_visit"; +cc.Director.EVENT_AFTER_UPDATE = "director_after_update"; + +cc.visibleRect = { + _topLeft:cc.p(0,0), + _topRight:cc.p(0,0), + _top:cc.p(0,0), + _bottomLeft:cc.p(0,0), + _bottomRight:cc.p(0,0), + _bottom:cc.p(0,0), + _center:cc.p(0,0), + _left:cc.p(0,0), + _right:cc.p(0,0), + _width:0, + _height:0, + _isInitialized: false, + init:function(){ + + var director = cc.Director.getInstance(); + var origin = director.getVisibleOrigin(); + var size = director.getVisibleSize(); + + this._width = size.width; + this._height = size.height; + + var w = this._width; + var h = this._height; + + //top + this._topLeft.y = h; + this._topRight.x = w; + this._topRight.y = h; + this._top.x = w/2; + this._top.y = h; + + //bottom + this._bottomRight.x = w; + this._bottom.x = w/2; + + //center + this._center.x = w/2; + this._center.y = h/2; + + //left + this._left.y = h/2; + + //right + this._right.x = w; + this._right.y = h/2; + }, + lazyInit: function(){ + if (!this._isInitialized) { + this.init(); + this._isInitialized = true; + } + }, +}; + +cc.defineGetterSetter(cc.visibleRect, "width", function(){ + this.lazyInit(); + return this._width; +}); +cc.defineGetterSetter(cc.visibleRect, "height", function(){ + this.lazyInit(); + return this._height; +}); +cc.defineGetterSetter(cc.visibleRect, "topLeft", function(){ + this.lazyInit(); + return this._topLeft; +}); +cc.defineGetterSetter(cc.visibleRect, "topRight", function(){ + this.lazyInit(); + return this._topRight; +}); +cc.defineGetterSetter(cc.visibleRect, "top", function(){ + this.lazyInit(); + return this._top; +}); +cc.defineGetterSetter(cc.visibleRect, "bottomLeft", function(){ + this.lazyInit(); + return this._bottomLeft; +}); +cc.defineGetterSetter(cc.visibleRect, "bottomRight", function(){ + this.lazyInit(); + return this._bottomRight; +}); +cc.defineGetterSetter(cc.visibleRect, "bottom", function(){ + this.lazyInit(); + return this._bottom; +}); +cc.defineGetterSetter(cc.visibleRect, "center", function(){ + this.lazyInit(); + return this._center; +}); +cc.defineGetterSetter(cc.visibleRect, "left", function(){ + this.lazyInit(); + return this._left; +}); +cc.defineGetterSetter(cc.visibleRect, "right", function(){ + this.lazyInit(); + return this._right; +}); + diff --git a/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js b/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js index 64a3930ea9..e08dc74a78 100644 --- a/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js +++ b/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js @@ -134,8 +134,8 @@ var TouchableSpriteTest = EventDispatcherTestDemo.extend({ }); nextItem.setFontSize(16); - nextItem.x = cc.visibleRect.right.x -100; - nextItem.y = cc.visibleRect.right.y - 30; + nextItem.setPositionX(cc.visibleRect.right.x -100); + nextItem.setPositionY(cc.visibleRect.right.y - 30); var menu2 = cc.Menu.create(nextItem); menu2.setPosition(0, 0); @@ -144,7 +144,7 @@ var TouchableSpriteTest = EventDispatcherTestDemo.extend({ }); removeAllTouchItem.setFontSize(16); - removeAllTouchItem.setPositionX(removeAllTouchItem.getPositionX() + cc.visibleRect.right.x -100); + removeAllTouchItem.setPositionX(cc.visibleRect.right.x -100); removeAllTouchItem.setPositionY(cc.visibleRect.right.y); var menu = cc.Menu.create(removeAllTouchItem); @@ -550,7 +550,7 @@ var RemoveAndRetainNodeTest = EventDispatcherTestDemo.extend({ if (cc.rectContainsPoint(rect, locationInNode)) { cc.log("sprite began... x = " + locationInNode.x + ", y = " + locationInNode.y); - target.opacity = 180; + target.setOpacity(180); return true; } return false; @@ -558,13 +558,13 @@ var RemoveAndRetainNodeTest = EventDispatcherTestDemo.extend({ onTouchMoved: function (touch, event) { var target = event.getCurrentTarget(); var delta = touch.getDelta(); - target.x += delta.x; - target.y += delta.y; + target.setPositionX(target.getPositionX() + delta.x); + target.setPositionY(target.getPositionY() + delta.y); }, onTouchEnded: function (touch, event) { var target = event.getCurrentTarget(); cc.log("sprite onTouchesEnded.. "); - target.opacity = 255; + target.setOpacity(255); } }); cc.eventManager.addListener(listener1, this._sprite); @@ -579,8 +579,8 @@ var RemoveAndRetainNodeTest = EventDispatcherTestDemo.extend({ cc.CallFunc.create(function () { this._spriteSaved = false; this.addChild(this._sprite); - if(!cc.sys.isNative) - cc.eventManager.addListener(listener1, this._sprite); +// if(!cc.sys.isNative) +// cc.eventManager.addListener(listener1, this._sprite); this._sprite.release(); }, this) )); @@ -727,10 +727,10 @@ var DirectorEventTest = EventDispatcherTestDemo.extend({ this._event2 = dispatcher.addCustomListener(cc.Director.EVENT_AFTER_VISIT, this.onEvent2.bind(this)); this._event3 = dispatcher.addCustomListener(cc.Director.EVENT_AFTER_DRAW, function(event) { selfPointer._label3.setString("Draw: " + selfPointer._count3++); - }, this); + }); this._event4 = dispatcher.addCustomListener(cc.Director.EVENT_PROJECTION_CHANGED, function(event) { selfPointer._label4.setString("Projection: " + selfPointer._count4++); - }, this); + }); this._event1.retain(); this._event2.retain(); @@ -804,7 +804,7 @@ var GlobalZTouchTest = EventDispatcherTestDemo.extend({ var rect = cc.rect(0, 0, s.width, s.height); if (cc.rectContainsPoint(rect, locationInNode)) { - log("sprite began... x = %f, y = %f", locationInNode.x, locationInNode.y); + cc.log("sprite began... x = %f, y = %f", locationInNode.x, locationInNode.y); target.setOpacity(180); return true; } @@ -816,7 +816,7 @@ var GlobalZTouchTest = EventDispatcherTestDemo.extend({ target.y += delta.y; }, onTouchEnded: function(touch, event){ - log("sprite onTouchesEnded.. "); + cc.log("sprite onTouchesEnded.. "); event.getCurrentTarget().setOpacity(255); } }); @@ -834,8 +834,8 @@ var GlobalZTouchTest = EventDispatcherTestDemo.extend({ this.addChild(sprite); var visibleSize = cc.director.getVisibleSize(); - sprite.x = cc.VisibleRect.left().x + visibleSize.width / (SPRITE_COUNT - 1) * i; - sprite.y = cc.VisibleRect.center().y; + sprite.x = cc.visibleRect.left.x + visibleSize.width / (SPRITE_COUNT - 1) * i; + sprite.y = cc.visibleRect.center.y; } this.scheduleUpdate(); @@ -958,7 +958,7 @@ var StopPropagationTest = EventDispatcherTestDemo.extend({ } - cc.eventManager.addListener(touchOneByOneListener.clone(), sprite1); + cc.eventManager.addListener(touchOneByOneListener, sprite1); cc.eventManager.addListener(keyboardEventListener.clone(), sprite1); cc.eventManager.addListener(touchAllAtOnceListener.clone(), sprite2); @@ -966,10 +966,10 @@ var StopPropagationTest = EventDispatcherTestDemo.extend({ var visibleSize = cc.director.getVisibleSize(); - sprite1.x = cc.VisibleRect.left().x + visibleSize.width / (SPRITE_COUNT - 1) * i; - sprite1.y = cc.VisibleRect.center().y + sprite2.getContentSize().height / 2 + 10; - sprite2.x = cc.VisibleRect.left().x + visibleSize.width / (SPRITE_COUNT - 1) * i; - sprite2.y = cc.VisibleRect.center().y - sprite2.getContentSize().height / 2 - 10; + sprite1.setPositionX(cc.visibleRect.left.x + visibleSize.width / (SPRITE_COUNT - 1) * i); + sprite1.setPositionY(cc.visibleRect.center.y + sprite2.getContentSize().height / 2 + 10); + sprite2.setPositionX(cc.visibleRect.left.x + visibleSize.width / (SPRITE_COUNT - 1) * i); + sprite2.setPositionY(cc.visibleRect.center.y - sprite2.getContentSize().height / 2 - 10); } }, @@ -1007,25 +1007,24 @@ var Issue4160 = EventDispatcherTestDemo.extend({ var size = cc.director.getVisibleSize(); var sprite1 = TouchableSprite.create(); - sprite1.initWithFile("res/Images/CyanSquare.png"); + sprite1.setTexture("res/Images/CyanSquare.png"); sprite1.setPriority(-30); - sprite1.x = origin.x + (size.width/2) - 80; - sprite1.y = origin.y + (size.height/2) + 40; + sprite1.setPositionX(origin.x + (size.width/2) - 80); + sprite1.setPositionY(origin.y + (size.height/2) + 40); this.addChild(sprite1, 5); var sprite2 = TouchableSprite.create(); - sprite2.initWithFile("res/Images/MagentaSquare.png"); + sprite2.setTexture("res/Images/MagentaSquare.png"); sprite2.setPriority(-20); sprite2.removeListenerOnTouchEnded(true); - sprite2.x = origin.x + (size.width/2); - sprite2.y = origin.y + (size.height/2); + sprite2.setPositionX(origin.x + (size.width/2)); + sprite2.setPositionY(origin.y + (size.height/2)); this.addChild(sprite2, 10); var sprite3 = TouchableSprite.create(); - sprite3.initWithFile("res/Images/YellowSquare.png"); + sprite3.setTexture("res/Images/YellowSquare.png"); sprite3.setPriority(-10); - sprite3.x = 0; - sprite3.y = 0; + sprite3.setPosition(0, 0); sprite2.addChild(sprite3, 21); }, diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index 8a4caeca06..af3d7c4aa8 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/2d/cocos2d.h %(cocosdir)s/cocos/audio/include/Simpl # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set SimpleAudioEngine Scheduler Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak TextFieldTTF GLViewProtocol GLView Component __NodeRGBA __LayerRGBA SAXParser Event(?!.*(Physics).*).* +classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set SimpleAudioEngine Scheduler Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak TextFieldTTF GLViewProtocol GLView Component __NodeRGBA __LayerRGBA SAXParser Event(?!.*(Physics).*).* Device classes_need_extend = Node Layer.* Sprite MenuItemFont Scene DrawNode @@ -114,7 +114,8 @@ skip = Node::[^setPosition$ setGLServerState description getUserObject .*UserDat TextFieldTTF::[(g|s)etDelegate], EventListenerVector::[*], EventListener(Touch|Keyboard).*::[create], - EventTouch::[(s|g)etTouches] + EventTouch::[(s|g)etTouches], + Device::[getTextureDataForText] rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame], MenuItemFont::[setFontNameObj=setFontName setFontSizeObj=setFontSize getFontSizeObj=getFontSize getFontNameObj=getFontName], From fb8dc85153b8211d45976601d14adb90d56664e8 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 5 Mar 2014 09:53:15 +0800 Subject: [PATCH 2/6] Adds clone support for EventListenerOneByOne and EventListenerAllAtOnce. --- .../manual/jsb_event_dispatcher_manual.cpp | 1 - .../bindings/script/jsb_cocos2d.js | 25 +++++++++++++++++++ .../NewEventManagerTest.js | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp b/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp index 1012b7705a..845ff3cc8e 100644 --- a/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp +++ b/frameworks/js-bindings/bindings/manual/jsb_event_dispatcher_manual.cpp @@ -67,7 +67,6 @@ bool js_EventListenerTouchOneByOne_create(JSContext *cx, uint32_t argc, jsval *v return false; } - bool js_EventListenerTouchAllAtOnce_create(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 0) { diff --git a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js index cefc1e76d3..e9b5deb15b 100644 --- a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js +++ b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js @@ -1086,6 +1086,31 @@ cc.inputManager = { getDPI: cc.Device.getDPI }; +cc.EventListenerTouchOneByOne.prototype.clone = function() { + var ret = cc.EventListenerTouchOneByOne.create(); + ret.onTouchBegan = this.onTouchBegan; + ret.onTouchMoved = this.onTouchMoved; + ret.onTouchEnded = this.onTouchEnded; + ret.onTouchCancelled = this.onTouchCancelled; + return ret; +}; + +cc.EventListenerTouchAllAtOnce.prototype.clone = function() { + var ret = cc.EventListenerTouchAllAtOnce.create(); + ret.onTouchesBegan = this.onTouchesBegan; + ret.onTouchesMoved = this.onTouchesMoved; + ret.onTouchesEnded = this.onTouchesEnded; + ret.onTouchesCancelled = this.onTouchesCancelled; + return ret; +}; + +cc.EventListenerKeyboard.prototype.clone = function() { + var ret = cc.EventListenerKeyboard.create(); + ret.onKeyPressed = this.onKeyPressed; + ret.onKeyReleased = this.onKeyReleased; + return ret; +}; + cc.director = cc.Director.getInstance(); cc.Director.EVENT_PROJECTION_CHANGED = "director_projection_changed"; diff --git a/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js b/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js index e08dc74a78..7bb297c7d6 100644 --- a/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js +++ b/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js @@ -958,7 +958,7 @@ var StopPropagationTest = EventDispatcherTestDemo.extend({ } - cc.eventManager.addListener(touchOneByOneListener, sprite1); + cc.eventManager.addListener(touchOneByOneListener.clone(), sprite1); cc.eventManager.addListener(keyboardEventListener.clone(), sprite1); cc.eventManager.addListener(touchAllAtOnceListener.clone(), sprite2); From b641c2a9a75c23a6621fa2e84719a222cace24f4 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 5 Mar 2014 11:32:24 +0800 Subject: [PATCH 3/6] issue #4234: Updates cocos2d-x. --- frameworks/js-bindings/cocos2d-x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js-bindings/cocos2d-x b/frameworks/js-bindings/cocos2d-x index cd21f33ccb..ae83998c72 160000 --- a/frameworks/js-bindings/cocos2d-x +++ b/frameworks/js-bindings/cocos2d-x @@ -1 +1 @@ -Subproject commit cd21f33ccbbd140af3d7f2a9956e1783c55e7728 +Subproject commit ae83998c727d1ab41a8494de4a9b33777e165229 From 6e01b25c2b537709a16e601822c8050c1f21a8c3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 5 Mar 2014 11:33:10 +0800 Subject: [PATCH 4/6] issue #4234: New eventdispacher test works ok on JSB. --- .../bindings/script/jsb_cocos2d.js | 18 ++ .../bindings/script/jsb_property_apis.js | 1 + .../NewEventManagerTest.js | 208 +++++++++++++----- tools/tojs/cocos2dx.ini | 2 +- 4 files changed, 173 insertions(+), 56 deletions(-) diff --git a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js index e9b5deb15b..5f6c0d4cf5 100644 --- a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js +++ b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js @@ -5,6 +5,14 @@ var cc = cc || {}; var window = window || this; +cc.sys = sys || {}; +cc.sys.isNative = true; + +cc.assert = function(cond, msg) { + if (!cond) + cc.log("Assert: " + msg); +} + cc.TARGET_PLATFORM = { WINDOWS:0, LINUX:1, @@ -1092,6 +1100,7 @@ cc.EventListenerTouchOneByOne.prototype.clone = function() { ret.onTouchMoved = this.onTouchMoved; ret.onTouchEnded = this.onTouchEnded; ret.onTouchCancelled = this.onTouchCancelled; + ret.setSwallowTouches(this.isSwallowTouches()); return ret; }; @@ -1118,6 +1127,15 @@ cc.Director.EVENT_AFTER_DRAW = "director_after_draw"; cc.Director.EVENT_AFTER_VISIT = "director_after_visit"; cc.Director.EVENT_AFTER_UPDATE = "director_after_update"; +cc.Director.prototype.runScene = function(scene){ + if (!this.getRunningScene()) { + this.runWithScene(scene); + } + else { + this.replaceScene(scene); + } +}; + cc.visibleRect = { _topLeft:cc.p(0,0), _topRight:cc.p(0,0), diff --git a/frameworks/js-bindings/bindings/script/jsb_property_apis.js b/frameworks/js-bindings/bindings/script/jsb_property_apis.js index 4eecc77f1d..102d15ae87 100644 --- a/frameworks/js-bindings/bindings/script/jsb_property_apis.js +++ b/frameworks/js-bindings/bindings/script/jsb_property_apis.js @@ -239,6 +239,7 @@ cc.defineGetterSetter(_proto, "actionManager", _proto.getActionManager, _proto.s cc.defineGetterSetter(_proto, "scheduler", _proto.getScheduler, _proto.setScheduler); cc.defineGetterSetter(_proto, "shaderProgram", _proto.getShaderProgram, _proto.setShaderProgram); cc.defineGetterSetter(_proto, "glServerState", _proto.getGLServerState, _proto.setGLServerState); +cc.defineGetterSetter(_proto, "tag", _proto.getTag, _proto.setTag); _proto = cc.NodeRGBA.prototype; cc.defineGetterSetter(_proto, "opacity", _proto.getOpacity, _proto.setOpacity); diff --git a/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js b/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js index 7bb297c7d6..7fb6e57717 100644 --- a/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js +++ b/samples/js-tests/src/NewEventManagerTest/NewEventManagerTest.js @@ -40,21 +40,21 @@ var EventDispatcherTestDemo = BaseTestLayer.extend({ onBackCallback:function (sender) { var s = new EventDispatcherTestScene(); s.addChild(previousDispatcherTest()); - director.replaceScene(s); + director.runScene(s); }, onRestartCallback:function (sender) { var s = new EventDispatcherTestScene(); s.addChild(restartDispatcherTest()); - director.replaceScene(s); + director.runScene(s); }, onNextCallback:function (sender) { var s = new EventDispatcherTestScene(); s.addChild(nextDispatcherTest()); - director.replaceScene(s); + director.runScene(s); }, - // automation + // varmation numberOfPendingTests:function() { return ( (arrayOfEventDispatcherTest.length-1) - eventDispatcherSceneIdx ); }, @@ -96,7 +96,7 @@ var TouchableSpriteTest = EventDispatcherTestDemo.extend({ if (cc.rectContainsPoint(rect, locationInNode)) { cc.log("sprite began... x = " + locationInNode.x + ", y = " + locationInNode.y); - target.setOpacity(180); + target.opacity = 180; return true; } return false; @@ -104,8 +104,8 @@ var TouchableSpriteTest = EventDispatcherTestDemo.extend({ onTouchMoved: function (touch, event) { var target = event.getCurrentTarget(); var delta = touch.getDelta(); - target.setPositionX(target.getPositionX() + delta.x); - target.setPositionY(target.getPositionY() + delta.y); + target.x += delta.x; + target.y += delta.y; }, onTouchEnded: function (touch, event) { var target = event.getCurrentTarget(); @@ -133,9 +133,9 @@ var TouchableSpriteTest = EventDispatcherTestDemo.extend({ selfPointer.onNextCallback(); }); - nextItem.setFontSize(16); - nextItem.setPositionX(cc.visibleRect.right.x -100); - nextItem.setPositionY(cc.visibleRect.right.y - 30); + nextItem.fontSize = 16; + nextItem.x = cc.visibleRect.right.x -100; + nextItem.y = cc.visibleRect.right.y - 30; var menu2 = cc.Menu.create(nextItem); menu2.setPosition(0, 0); @@ -143,9 +143,9 @@ var TouchableSpriteTest = EventDispatcherTestDemo.extend({ selfPointer.addChild(menu2); }); - removeAllTouchItem.setFontSize(16); - removeAllTouchItem.setPositionX(cc.visibleRect.right.x -100); - removeAllTouchItem.setPositionY(cc.visibleRect.right.y); + removeAllTouchItem.fontSize = 16; + removeAllTouchItem.x = cc.visibleRect.right.x -100; + removeAllTouchItem.y = cc.visibleRect.right.y; var menu = cc.Menu.create(removeAllTouchItem); menu.setPosition(0, 0); @@ -173,6 +173,11 @@ var TouchableSprite = cc.Sprite.extend({ _fixedPriority:0, _removeListenerOnTouchEnded: false, + ctor: function(priority){ + this._super(); + this._fixedPriority = priority || 0; + }, + setPriority:function(fixedPriority){ this._fixedPriority = fixedPriority; }, @@ -200,17 +205,24 @@ var TouchableSprite = cc.Sprite.extend({ }, onTouchEnded: function (touch, event) { selfPointer.setColor(cc.color.white); - if(selfPointer._removeListenerOnTouchEnded) + if(selfPointer._removeListenerOnTouchEnded) { cc.eventManager.removeListener(selfPointer._listener); + selfPointer._listener = null; + } } }); - cc.eventManager.addListener(listener, this._fixedPriority); + if(this._fixedPriority != 0) + cc.eventManager.addListener(listener, this._fixedPriority); + else + cc.eventManager.addListener(listener, this); this._listener = listener; }, onExit: function(){ - cc.eventManager.removeListener(this._listener); + if (this._listener != null) + cc.eventManager.removeListener(this._listener); + this._super(); }, @@ -219,13 +231,12 @@ var TouchableSprite = cc.Sprite.extend({ } }); -TouchableSprite.create = function(){ - var test = new TouchableSprite(); +TouchableSprite.create = function(priority){ + var test = new TouchableSprite(priority); test.init(); return test; }; - var FixedPriorityTest = EventDispatcherTestDemo.extend({ onEnter:function(){ this._super(); @@ -233,22 +244,22 @@ var FixedPriorityTest = EventDispatcherTestDemo.extend({ var origin = director.getVisibleOrigin(); var size = director.getVisibleSize(); - var sprite1 = TouchableSprite.create(); + var sprite1 = TouchableSprite.create(30); sprite1.setTexture("res/Images/CyanSquare.png"); - sprite1.setPriority(30); - sprite1.setPosition(origin.x +size.width/2 - 80, origin.y + size.height/2 + 40); + sprite1.x = origin.x + size.width / 2 - 80; + sprite1.y = origin.y + size.height / 2 + 40; this.addChild(sprite1, 10); - var sprite2 = TouchableSprite.create(); + var sprite2 = TouchableSprite.create(20); sprite2.setTexture("res/Images/MagentaSquare.png"); - sprite2.setPriority(20); - sprite2.setPosition(origin.x + size.width/2, origin.y + size.height/2); + sprite2.x = origin.x + size.width / 2; + sprite2.y = origin.y + size.height / 2; this.addChild(sprite2, 20); - var sprite3 = TouchableSprite.create(); + var sprite3 = TouchableSprite.create(10); sprite3.setTexture("res/Images/YellowSquare.png"); - sprite3.setPriority(10); - sprite3.setPosition(0, 0); + sprite3.x = 0; + sprite3.y = 0; sprite2.addChild(sprite3, 1); }, @@ -550,7 +561,7 @@ var RemoveAndRetainNodeTest = EventDispatcherTestDemo.extend({ if (cc.rectContainsPoint(rect, locationInNode)) { cc.log("sprite began... x = " + locationInNode.x + ", y = " + locationInNode.y); - target.setOpacity(180); + target.opacity = 180; return true; } return false; @@ -558,13 +569,13 @@ var RemoveAndRetainNodeTest = EventDispatcherTestDemo.extend({ onTouchMoved: function (touch, event) { var target = event.getCurrentTarget(); var delta = touch.getDelta(); - target.setPositionX(target.getPositionX() + delta.x); - target.setPositionY(target.getPositionY() + delta.y); + target.x += delta.x; + target.y += delta.y; }, onTouchEnded: function (touch, event) { var target = event.getCurrentTarget(); cc.log("sprite onTouchesEnded.. "); - target.setOpacity(255); + target.opacity = 255; } }); cc.eventManager.addListener(listener1, this._sprite); @@ -579,8 +590,8 @@ var RemoveAndRetainNodeTest = EventDispatcherTestDemo.extend({ cc.CallFunc.create(function () { this._spriteSaved = false; this.addChild(this._sprite); -// if(!cc.sys.isNative) -// cc.eventManager.addListener(listener1, this._sprite); + if(!cc.sys.isNative) + cc.eventManager.addListener(listener1, this._sprite); this._sprite.release(); }, this) )); @@ -615,7 +626,7 @@ var RemoveListenerAfterAddingTest = EventDispatcherTestDemo.extend({ var listener = cc.EventListener.create({ event: cc.EventListener.TOUCH_ONE_BY_ONE, onTouchBegan: function (touch, event) { - cc.Assert(false, "Should not come here!"); + cc.assert(false, "Should not come here!"); return true; } }); @@ -641,7 +652,7 @@ var RemoveListenerAfterAddingTest = EventDispatcherTestDemo.extend({ var listener = cc.EventListener.create({ event: cc.EventListener.TOUCH_ONE_BY_ONE, onTouchBegan: function(touch, event){ - cc.Assert("Should not come here!"); + cc.assert("Should not come here!"); return true; } }); @@ -655,7 +666,7 @@ var RemoveListenerAfterAddingTest = EventDispatcherTestDemo.extend({ var listener = cc.EventListener.create({ event: cc.EventListener.TOUCH_ONE_BY_ONE, onTouchBegan: function(touch, event){ - cc.Assert(false, "Should not come here!"); + cc.assert(false, "Should not come here!"); return true; } }); @@ -839,6 +850,8 @@ var GlobalZTouchTest = EventDispatcherTestDemo.extend({ } this.scheduleUpdate(); + + this.setGlobalZOrder(-2); }, update: function(dt){ @@ -966,10 +979,10 @@ var StopPropagationTest = EventDispatcherTestDemo.extend({ var visibleSize = cc.director.getVisibleSize(); - sprite1.setPositionX(cc.visibleRect.left.x + visibleSize.width / (SPRITE_COUNT - 1) * i); - sprite1.setPositionY(cc.visibleRect.center.y + sprite2.getContentSize().height / 2 + 10); - sprite2.setPositionX(cc.visibleRect.left.x + visibleSize.width / (SPRITE_COUNT - 1) * i); - sprite2.setPositionY(cc.visibleRect.center.y - sprite2.getContentSize().height / 2 - 10); + sprite1.x = cc.visibleRect.left.x + visibleSize.width / (SPRITE_COUNT - 1) * i; + sprite1.y = cc.visibleRect.center.y + sprite2.getContentSize().height / 2 + 10; + sprite2.x = cc.visibleRect.left.x + visibleSize.width / (SPRITE_COUNT - 1) * i; + sprite2.y = cc.visibleRect.center.y - sprite2.getContentSize().height / 2 - 10; } }, @@ -1006,25 +1019,23 @@ var Issue4160 = EventDispatcherTestDemo.extend({ var origin = cc.director.getVisibleOrigin(); var size = cc.director.getVisibleSize(); - var sprite1 = TouchableSprite.create(); + var sprite1 = TouchableSprite.create(-30); sprite1.setTexture("res/Images/CyanSquare.png"); - sprite1.setPriority(-30); - sprite1.setPositionX(origin.x + (size.width/2) - 80); - sprite1.setPositionY(origin.y + (size.height/2) + 40); + sprite1.x = origin.x + (size.width/2) - 80; + sprite1.y = origin.y + (size.height/2) + 40; this.addChild(sprite1, 5); - var sprite2 = TouchableSprite.create(); + var sprite2 = TouchableSprite.create(-20); sprite2.setTexture("res/Images/MagentaSquare.png"); - sprite2.setPriority(-20); sprite2.removeListenerOnTouchEnded(true); - sprite2.setPositionX(origin.x + (size.width/2)); - sprite2.setPositionY(origin.y + (size.height/2)); + sprite2.x = origin.x + (size.width/2); + sprite2.y = origin.y + (size.height/2); this.addChild(sprite2, 10); - var sprite3 = TouchableSprite.create(); + var sprite3 = TouchableSprite.create(-10); sprite3.setTexture("res/Images/YellowSquare.png"); - sprite3.setPriority(-10); - sprite3.setPosition(0, 0); + sprite3.x = 0; + sprite3.y = 0; sprite2.addChild(sprite3, 21); }, @@ -1043,11 +1054,97 @@ Issue4160.create = function(){ return test; }; +var PauseResumeTargetTest = EventDispatcherTestDemo.extend({ + ctor: function () { + this._super(); + + var origin = cc.director.getVisibleOrigin(); + var size = cc.director.getVisibleSize(); + + var sprite1 = TouchableSprite.create(); + sprite1.setTexture("res/Images/CyanSquare.png"); + sprite1.x = origin.x + size.width / 2 - 180; + sprite1.y = origin.y + size.height / 2 + 40; + this.addChild(sprite1, 10); + + var sprite2 = TouchableSprite.create(); + sprite2.setTexture("res/Images/MagentaSquare.png"); + sprite2.x = origin.x + size.width / 2 - 100; + sprite2.y = origin.y + size.height / 2; + this.addChild(sprite2, 1); + + var sprite3 = TouchableSprite.create(); + sprite3.setTexture("res/Images/YellowSquare.png"); + sprite3.x = 0; + sprite3.y = 0; + sprite2.addChild(sprite3, 20); + + var _this = this; + var popup = cc.MenuItemFont.create("Popup", function(sender){ + cc.eventManager.pauseTarget(_this, true); + var colorLayer = cc.LayerColor.create(cc.color(0, 0, 255, 100)); + _this.addChild(colorLayer, 999); //set colorLayer to top + + // Add the button + var backgroundButton = cc.Scale9Sprite.create(s_extensions_button); + var backgroundHighlightedButton = cc.Scale9Sprite.create(s_extensions_buttonHighlighted); + + var titleButton = cc.LabelTTF.create("Close Dialog", "Marker Felt", 26); + titleButton.color = cc.color(159, 168, 176); + + var controlButton = cc.ControlButton.create(titleButton, backgroundButton); + controlButton.setBackgroundSpriteForState(backgroundHighlightedButton, cc.CONTROL_STATE_HIGHLIGHTED); + controlButton.setTitleColorForState(cc.color.white, cc.CONTROL_STATE_HIGHLIGHTED); + + controlButton.anchorX = 0.5; + controlButton.anchorY = 1; + controlButton.x = size.width / 2 + 50; + controlButton.y = size.height / 2; + colorLayer.addChild(controlButton, 1); + controlButton.addTargetWithActionForControlEvents(this, function(){ + colorLayer.removeFromParent(); + cc.eventManager.resumeTarget(_this, true); + }, cc.CONTROL_EVENT_TOUCH_UP_INSIDE); + + // Add the black background + var background = cc.Scale9Sprite.create(s_extensions_buttonBackground); + background.width = 300; + background.height = 170; + background.x = size.width / 2.0 + 50; + background.y = size.height / 2.0; + colorLayer.addChild(background); + }); + + popup.setAnchorPoint(1,0.5); + popup.setPosition(cc.visibleRect.right); + + var menu = cc.Menu.create(popup); + menu.setAnchorPoint(0, 0); + menu.setPosition(0, 0); + + this.addChild(menu); + }, + + title: function(){ + return "PauseResumeTargetTest"; + }, + + subtitle: function() { + return ""; + } +}); + +PauseResumeTargetTest.create = function(){ + var test = new Issue4160(); + test.init(); + return test; +}; + var EventDispatcherTestScene = TestScene.extend({ runThisTest:function () { eventDispatcherSceneIdx = -1; this.addChild(nextDispatcherTest()); - director.replaceScene(this); + director.runScene(this); } }); @@ -1061,9 +1158,10 @@ var arrayOfEventDispatcherTest = [ RemoveAndRetainNodeTest, RemoveListenerAfterAddingTest, DirectorEventTest, - GlobalZTouchTest, + //GlobalZTouchTest, StopPropagationTest, - Issue4160 + Issue4160, + PauseResumeTargetTest ]; var nextDispatcherTest = function () { diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index af3d7c4aa8..2ee701dd4e 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -131,7 +131,7 @@ rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames ge Touch::[getID=getId], SimpleAudioEngine::[preloadBackgroundMusic=preloadMusic setBackgroundMusicVolume=setMusicVolume getBackgroundMusicVolume=getMusicVolume playBackgroundMusic=playMusic stopBackgroundMusic=stopMusic pauseBackgroundMusic=pauseMusic resumeBackgroundMusic=resumeMusic rewindBackgroundMusic=rewindMusic isBackgroundMusicPlaying=isMusicPlaying willPlayBackgroundMusic=willPlayMusic], FileUtils::[loadFilenameLookupDictionaryFromFile=loadFilenameLookup], - EventDispatcher::[addCustomEventListener=addCustomListener removeEventListener=removeListener removeEventListenersForType=removeListeners removeCustomEventListeners=removeCustomListeners removeAllEventListeners=removeAllListeners] + EventDispatcher::[addCustomEventListener=addCustomListener removeEventListener=removeListener removeEventListenersForType=removeListeners removeEventListenersForTarget=removeListeners removeCustomEventListeners=removeCustomListeners removeAllEventListeners=removeAllListeners pauseEventListenersForTarget=pauseTarget resumeEventListenersForTarget=resumeTarget] rename_classes = ParticleSystemQuad::ParticleSystem, SimpleAudioEngine::AudioEngine, From 7e0519d24dcccba0ff5b46ee29dc37eb5cf6671c Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 5 Mar 2014 11:34:16 +0800 Subject: [PATCH 5/6] issue #4234: Updates cocos2d-console. --- tools/cocos2d-console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cocos2d-console b/tools/cocos2d-console index a248bfd9ec..2ee95f1cc0 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit a248bfd9ecd96f1c65a2b968892e8562b6ba001f +Subproject commit 2ee95f1cc0a874d690659409923b2f017a1336cc From 69b2a1df7f217cf828f3135c3b49b42df7175475 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 5 Mar 2014 11:34:44 +0800 Subject: [PATCH 6/6] issue #4234: Updates auto bindings codes. --- .../auto/api/jsb_cocos2dx_auto_api.js | 113 ++++-- .../bindings/auto/jsb_cocos2dx_auto.cpp | 379 ++++++++++++------ .../bindings/auto/jsb_cocos2dx_auto.hpp | 21 +- 3 files changed, 345 insertions(+), 168 deletions(-) diff --git a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js index d7ad21c9e2..a41c6887b5 100644 --- a/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js +++ b/frameworks/js-bindings/bindings/auto/api/jsb_cocos2dx_auto_api.js @@ -1105,12 +1105,10 @@ checkAvailable : function ( cc.EventDispatcher = { /** - * @method pauseEventListenersForTarget - * @param {cc.Node} arg0 - * @param {bool} arg1 + * @method setEnabled + * @param {bool} arg0 */ -pauseEventListenersForTarget : function ( -node, +setEnabled : function ( bool ) { @@ -1136,16 +1134,6 @@ node { }, -/** - * @method setEnabled - * @param {bool} arg0 - */ -setEnabled : function ( -bool -) -{ -}, - /** * @method addCustomEventListener * @param {String} arg0 @@ -1173,23 +1161,13 @@ int }, /** - * @method removeEventListenersForType - * @param {cc.EventListener::Type} arg0 - */ -removeEventListenersForType : function ( -type -) -{ -}, - -/** - * @method dispatchCustomEvent - * @param {String} arg0 - * @param {void*} arg1 - */ -dispatchCustomEvent : function ( -str, -void + * @method removeEventListenersForTarget +* @param {cc.Node|cc.EventListener::Type} node +* @param {bool} bool +*/ +removeEventListenersForTarget : function( +node, +bool ) { }, @@ -1207,13 +1185,13 @@ bool }, /** - * @method removeEventListenersForTarget - * @param {cc.Node} arg0 - * @param {bool} arg1 + * @method dispatchCustomEvent + * @param {String} arg0 + * @param {void*} arg1 */ -removeEventListenersForTarget : function ( -node, -bool +dispatchCustomEvent : function ( +str, +void ) { }, @@ -1240,6 +1218,18 @@ event { }, +/** + * @method pauseEventListenersForTarget + * @param {cc.Node} arg0 + * @param {bool} arg1 + */ +pauseEventListenersForTarget : function ( +node, +bool +) +{ +}, + /** * @method removeCustomEventListeners * @param {String} arg0 @@ -12539,6 +12529,43 @@ str }; +/** + * @class Device + */ +cc.Device = { + +/** + * @method setAccelerometerEnabled + * @param {bool} arg0 + */ +setAccelerometerEnabled : function ( +bool +) +{ +}, + +/** + * @method setAccelerometerInterval + * @param {float} arg0 + */ +setAccelerometerInterval : function ( +float +) +{ +}, + +/** + * @method getDPI + * @return {int} + */ +getDPI : function ( +) +{ + return 0; +}, + +}; + /** * @class FileUtils */ @@ -14590,6 +14617,16 @@ TileMapAtlas : function ( */ cc.EventListenerTouchOneByOne = { +/** + * @method isSwallowTouches + * @return {bool} + */ +isSwallowTouches : function ( +) +{ + return false; +}, + /** * @method setSwallowTouches * @param {bool} arg0 diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp index 9aa25c12d6..3e2b4cf7d7 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.cpp @@ -2942,48 +2942,24 @@ void js_register_cocos2dx_EventListener(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_EventDispatcher_class; JSObject *jsb_cocos2d_EventDispatcher_prototype; -bool js_cocos2dx_EventDispatcher_pauseEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_EventDispatcher_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_setEnabled : Invalid Native Object"); if (argc == 1) { - cocos2d::Node* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - proxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : Error processing arguments"); - cobj->pauseEventListenersForTarget(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - if (argc == 2) { - cocos2d::Node* arg0; - bool arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - proxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= JS_ValueToBoolean(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : Error processing arguments"); - cobj->pauseEventListenersForTarget(arg0, arg1); + bool arg0; + ok &= JS_ValueToBoolean(cx, argv[0], &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_setEnabled : Error processing arguments"); + cobj->setEnabled(arg0); JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } - JS_ReportError(cx, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_EventDispatcher_setEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_EventDispatcher_removeAllEventListeners(JSContext *cx, uint32_t argc, jsval *vp) @@ -3037,26 +3013,6 @@ bool js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority(JSContex JS_ReportError(cx, "js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_EventDispatcher_setEnabled(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_setEnabled : Invalid Native Object"); - if (argc == 1) { - bool arg0; - ok &= JS_ValueToBoolean(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_setEnabled : Error processing arguments"); - cobj->setEnabled(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - - JS_ReportError(cx, "js_cocos2dx_EventDispatcher_setEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} bool js_cocos2dx_EventDispatcher_addCustomEventListener(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); @@ -3137,54 +3093,68 @@ bool js_cocos2dx_EventDispatcher_addEventListenerWithFixedPriority(JSContext *cx JS_ReportError(cx, "js_cocos2dx_EventDispatcher_addEventListenerWithFixedPriority : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } -bool js_cocos2dx_EventDispatcher_removeEventListenersForType(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_EventDispatcher_removeEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_removeEventListenersForType : Invalid Native Object"); - if (argc == 1) { - cocos2d::EventListener::Type arg0; - ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_removeEventListenersForType : Error processing arguments"); - cobj->removeEventListenersForType(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - JS_ReportError(cx, "js_cocos2dx_EventDispatcher_removeEventListenersForType : wrong number of arguments: %d, was expecting %d", argc, 1); - return false; -} -bool js_cocos2dx_EventDispatcher_dispatchCustomEvent(JSContext *cx, uint32_t argc, jsval *vp) -{ - jsval *argv = JS_ARGV(cx, vp); - bool ok = true; - JSObject *obj = JS_THIS_OBJECT(cx, vp); + JSObject *obj = NULL; + cocos2d::EventDispatcher* cobj = NULL; + obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); - cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_dispatchCustomEvent : Invalid Native Object"); - if (argc == 1) { - std::string arg0; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_dispatchCustomEvent : Error processing arguments"); - cobj->dispatchCustomEvent(arg0); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } - if (argc == 2) { - std::string arg0; - void* arg1; - ok &= jsval_to_std_string(cx, argv[0], &arg0); - #pragma warning NO CONVERSION TO NATIVE FOR void*; - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_dispatchCustomEvent : Error processing arguments"); - cobj->dispatchCustomEvent(arg0, arg1); - JS_SET_RVAL(cx, vp, JSVAL_VOID); - return true; - } + cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_removeEventListenersForTarget : Invalid Native Object"); + do { + if (argc == 1) { + cocos2d::Node* arg0; + do { + if (!argv[0].isObject()) { ok = false; break; } + js_proxy_t *proxy; + JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + proxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + cobj->removeEventListenersForTarget(arg0); + JS_SET_RVAL(cx, vp, JSVAL_VOID); + return true; + } + } while(0); - JS_ReportError(cx, "js_cocos2dx_EventDispatcher_dispatchCustomEvent : wrong number of arguments: %d, was expecting %d", argc, 1); + do { + if (argc == 2) { + cocos2d::Node* arg0; + do { + if (!argv[0].isObject()) { ok = false; break; } + js_proxy_t *proxy; + JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + proxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + if (!ok) { ok = true; break; } + bool arg1; + ok &= JS_ValueToBoolean(cx, argv[1], &arg1); + if (!ok) { ok = true; break; } + cobj->removeEventListenersForTarget(arg0, arg1); + JS_SET_RVAL(cx, vp, JSVAL_VOID); + return true; + } + } while(0); + + do { + if (argc == 1) { + cocos2d::EventListener::Type arg0; + ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); + if (!ok) { ok = true; break; } + cobj->removeEventListenersForType(arg0); + JS_SET_RVAL(cx, vp, JSVAL_VOID); + return true; + } + } while(0); + + JS_ReportError(cx, "js_cocos2dx_EventDispatcher_removeEventListenersForTarget : wrong number of arguments"); return false; } bool js_cocos2dx_EventDispatcher_resumeEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp) @@ -3231,48 +3201,34 @@ bool js_cocos2dx_EventDispatcher_resumeEventListenersForTarget(JSContext *cx, ui JS_ReportError(cx, "js_cocos2dx_EventDispatcher_resumeEventListenersForTarget : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } -bool js_cocos2dx_EventDispatcher_removeEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp) +bool js_cocos2dx_EventDispatcher_dispatchCustomEvent(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); bool ok = true; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_removeEventListenersForTarget : Invalid Native Object"); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_dispatchCustomEvent : Invalid Native Object"); if (argc == 1) { - cocos2d::Node* arg0; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - proxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_removeEventListenersForTarget : Error processing arguments"); - cobj->removeEventListenersForTarget(arg0); + std::string arg0; + ok &= jsval_to_std_string(cx, argv[0], &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_dispatchCustomEvent : Error processing arguments"); + cobj->dispatchCustomEvent(arg0); JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } if (argc == 2) { - cocos2d::Node* arg0; - bool arg1; - do { - if (!argv[0].isObject()) { ok = false; break; } - js_proxy_t *proxy; - JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); - proxy = jsb_get_js_proxy(tmpObj); - arg0 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - ok &= JS_ValueToBoolean(cx, argv[1], &arg1); - JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_removeEventListenersForTarget : Error processing arguments"); - cobj->removeEventListenersForTarget(arg0, arg1); + std::string arg0; + void* arg1; + ok &= jsval_to_std_string(cx, argv[0], &arg0); + #pragma warning NO CONVERSION TO NATIVE FOR void*; + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_dispatchCustomEvent : Error processing arguments"); + cobj->dispatchCustomEvent(arg0, arg1); JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } - JS_ReportError(cx, "js_cocos2dx_EventDispatcher_removeEventListenersForTarget : wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "js_cocos2dx_EventDispatcher_dispatchCustomEvent : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } bool js_cocos2dx_EventDispatcher_setPriority(JSContext *cx, uint32_t argc, jsval *vp) @@ -3331,6 +3287,50 @@ bool js_cocos2dx_EventDispatcher_dispatchEvent(JSContext *cx, uint32_t argc, jsv JS_ReportError(cx, "js_cocos2dx_EventDispatcher_dispatchEvent : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_EventDispatcher_pauseEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + bool ok = true; + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::EventDispatcher* cobj = (cocos2d::EventDispatcher *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : Invalid Native Object"); + if (argc == 1) { + cocos2d::Node* arg0; + do { + if (!argv[0].isObject()) { ok = false; break; } + js_proxy_t *proxy; + JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + proxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : Error processing arguments"); + cobj->pauseEventListenersForTarget(arg0); + JS_SET_RVAL(cx, vp, JSVAL_VOID); + return true; + } + if (argc == 2) { + cocos2d::Node* arg0; + bool arg1; + do { + if (!argv[0].isObject()) { ok = false; break; } + js_proxy_t *proxy; + JSObject *tmpObj = JSVAL_TO_OBJECT(argv[0]); + proxy = jsb_get_js_proxy(tmpObj); + arg0 = (cocos2d::Node*)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + ok &= JS_ValueToBoolean(cx, argv[1], &arg1); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : Error processing arguments"); + cobj->pauseEventListenersForTarget(arg0, arg1); + JS_SET_RVAL(cx, vp, JSVAL_VOID); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_EventDispatcher_pauseEventListenersForTarget : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_EventDispatcher_removeCustomEventListeners(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); @@ -3447,18 +3447,17 @@ void js_register_cocos2dx_EventDispatcher(JSContext *cx, JSObject *global) { }; static JSFunctionSpec funcs[] = { - JS_FN("pauseEventListenersForTarget", js_cocos2dx_EventDispatcher_pauseEventListenersForTarget, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setEnabled", js_cocos2dx_EventDispatcher_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeAllListeners", js_cocos2dx_EventDispatcher_removeAllEventListeners, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("addEventListenerWithSceneGraphPriority", js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setEnabled", js_cocos2dx_EventDispatcher_setEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("addCustomListener", js_cocos2dx_EventDispatcher_addCustomEventListener, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("addEventListenerWithFixedPriority", js_cocos2dx_EventDispatcher_addEventListenerWithFixedPriority, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("removeListeners", js_cocos2dx_EventDispatcher_removeEventListenersForType, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("removeListeners", js_cocos2dx_EventDispatcher_removeEventListenersForTarget, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("resumeTarget", js_cocos2dx_EventDispatcher_resumeEventListenersForTarget, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("dispatchCustomEvent", js_cocos2dx_EventDispatcher_dispatchCustomEvent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("resumeEventListenersForTarget", js_cocos2dx_EventDispatcher_resumeEventListenersForTarget, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("removeEventListenersForTarget", js_cocos2dx_EventDispatcher_removeEventListenersForTarget, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setPriority", js_cocos2dx_EventDispatcher_setPriority, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("dispatchEvent", js_cocos2dx_EventDispatcher_dispatchEvent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("pauseTarget", js_cocos2dx_EventDispatcher_pauseEventListenersForTarget, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeCustomListeners", js_cocos2dx_EventDispatcher_removeCustomEventListeners, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeListener", js_cocos2dx_EventDispatcher_removeEventListener, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isEnabled", js_cocos2dx_EventDispatcher_isEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -39712,6 +39711,117 @@ void js_register_cocos2dx_EventCustom(JSContext *cx, JSObject *global) { } } +JSClass *jsb_cocos2d_Device_class; +JSObject *jsb_cocos2d_Device_prototype; + +bool js_cocos2dx_Device_setAccelerometerEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + bool ok = true; + if (argc == 1) { + bool arg0; + ok &= JS_ValueToBoolean(cx, argv[0], &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Device_setAccelerometerEnabled : Error processing arguments"); + cocos2d::Device::setAccelerometerEnabled(arg0); + JS_SET_RVAL(cx, vp, JSVAL_VOID); + return true; + } + JS_ReportError(cx, "js_cocos2dx_Device_setAccelerometerEnabled : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_Device_setAccelerometerInterval(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + bool ok = true; + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, JS::RootedValue(cx, argv[0]), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Device_setAccelerometerInterval : Error processing arguments"); + cocos2d::Device::setAccelerometerInterval(arg0); + JS_SET_RVAL(cx, vp, JSVAL_VOID); + return true; + } + JS_ReportError(cx, "js_cocos2dx_Device_setAccelerometerInterval : wrong number of arguments"); + return false; +} + +bool js_cocos2dx_Device_getDPI(JSContext *cx, uint32_t argc, jsval *vp) +{ + if (argc == 0) { + int ret = cocos2d::Device::getDPI(); + jsval jsret = JSVAL_NULL; + jsret = int32_to_jsval(cx, ret); + JS_SET_RVAL(cx, vp, jsret); + return true; + } + JS_ReportError(cx, "js_cocos2dx_Device_getDPI : wrong number of arguments"); + return false; +} + + + +void js_cocos2d_Device_finalize(JSFreeOp *fop, JSObject *obj) { + CCLOGINFO("jsbindings: finalizing JS object %p (Device)", obj); +} + +void js_register_cocos2dx_Device(JSContext *cx, JSObject *global) { + jsb_cocos2d_Device_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_cocos2d_Device_class->name = "Device"; + jsb_cocos2d_Device_class->addProperty = JS_PropertyStub; + jsb_cocos2d_Device_class->delProperty = JS_DeletePropertyStub; + jsb_cocos2d_Device_class->getProperty = JS_PropertyStub; + jsb_cocos2d_Device_class->setProperty = JS_StrictPropertyStub; + jsb_cocos2d_Device_class->enumerate = JS_EnumerateStub; + jsb_cocos2d_Device_class->resolve = JS_ResolveStub; + jsb_cocos2d_Device_class->convert = JS_ConvertStub; + jsb_cocos2d_Device_class->finalize = js_cocos2d_Device_finalize; + jsb_cocos2d_Device_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + {"__nativeObj", 0, JSPROP_ENUMERATE | JSPROP_PERMANENT, JSOP_WRAPPER(js_is_native_obj), JSOP_NULLWRAPPER}, + {0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER} + }; + + static JSFunctionSpec funcs[] = { + JS_FS_END + }; + + static JSFunctionSpec st_funcs[] = { + JS_FN("setAccelerometerEnabled", js_cocos2dx_Device_setAccelerometerEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setAccelerometerInterval", js_cocos2dx_Device_setAccelerometerInterval, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getDPI", js_cocos2dx_Device_getDPI, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + jsb_cocos2d_Device_prototype = JS_InitClass( + cx, global, + NULL, // parent proto + jsb_cocos2d_Device_class, + dummy_constructor, 0, // no constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + // make the class enumerable in the registered namespace +// bool found; +//FIXME: Removed in Firefox v27 +// JS_SetPropertyAttributes(cx, global, "Device", JSPROP_ENUMERATE | JSPROP_READONLY, &found); + + // add the proto and JSClass to the type->js info hash table + TypeTest t; + js_type_class_t *p; + std::string typeName = t.s_name(); + if (_js_global_type_map.find(typeName) == _js_global_type_map.end()) + { + p = (js_type_class_t *)malloc(sizeof(js_type_class_t)); + p->jsclass = jsb_cocos2d_Device_class; + p->proto = jsb_cocos2d_Device_prototype; + p->parentProto = NULL; + _js_global_type_map.insert(std::make_pair(typeName, p)); + } +} + JSClass *jsb_cocos2d_FileUtils_class; JSObject *jsb_cocos2d_FileUtils_prototype; @@ -45151,6 +45261,23 @@ void js_register_cocos2dx_TileMapAtlas(JSContext *cx, JSObject *global) { JSClass *jsb_cocos2d_EventListenerTouchOneByOne_class; JSObject *jsb_cocos2d_EventListenerTouchOneByOne_prototype; +bool js_cocos2dx_EventListenerTouchOneByOne_isSwallowTouches(JSContext *cx, uint32_t argc, jsval *vp) +{ + JSObject *obj = JS_THIS_OBJECT(cx, vp); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::EventListenerTouchOneByOne* cobj = (cocos2d::EventListenerTouchOneByOne *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_EventListenerTouchOneByOne_isSwallowTouches : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isSwallowTouches(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + JS_SET_RVAL(cx, vp, jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_EventListenerTouchOneByOne_isSwallowTouches : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_EventListenerTouchOneByOne_setSwallowTouches(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); @@ -45197,6 +45324,7 @@ void js_register_cocos2dx_EventListenerTouchOneByOne(JSContext *cx, JSObject *gl }; static JSFunctionSpec funcs[] = { + JS_FN("isSwallowTouches", js_cocos2dx_EventListenerTouchOneByOne_isSwallowTouches, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setSwallowTouches", js_cocos2dx_EventListenerTouchOneByOne_setSwallowTouches, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -47106,6 +47234,7 @@ void register_all_cocos2dx(JSContext* cx, JSObject* obj) { js_register_cocos2dx_TransitionTurnOffTiles(cx, obj); js_register_cocos2dx_RotateTo(cx, obj); js_register_cocos2dx_TransitionSplitRows(cx, obj); + js_register_cocos2dx_Device(cx, obj); js_register_cocos2dx_TransitionProgressRadialCCW(cx, obj); js_register_cocos2dx_ScaleTo(cx, obj); js_register_cocos2dx_TransitionPageTurn(cx, obj); diff --git a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp index 15f6d2727f..54c0cc1894 100644 --- a/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp +++ b/frameworks/js-bindings/bindings/auto/jsb_cocos2dx_auto.hpp @@ -194,18 +194,17 @@ bool js_cocos2dx_EventDispatcher_constructor(JSContext *cx, uint32_t argc, jsval void js_cocos2dx_EventDispatcher_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_EventDispatcher(JSContext *cx, JSObject *global); void register_all_cocos2dx(JSContext* cx, JSObject* obj); -bool js_cocos2dx_EventDispatcher_pauseEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_EventDispatcher_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_removeAllEventListeners(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_addEventListenerWithSceneGraphPriority(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_EventDispatcher_setEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_addCustomEventListener(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_addEventListenerWithFixedPriority(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_EventDispatcher_removeEventListenersForType(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_EventDispatcher_dispatchCustomEvent(JSContext *cx, uint32_t argc, jsval *vp); -bool js_cocos2dx_EventDispatcher_resumeEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_removeEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_EventDispatcher_resumeEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_EventDispatcher_dispatchCustomEvent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_setPriority(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_dispatchEvent(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_EventDispatcher_pauseEventListenersForTarget(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_removeCustomEventListeners(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_removeEventListener(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventDispatcher_isEnabled(JSContext *cx, uint32_t argc, jsval *vp); @@ -2693,6 +2692,17 @@ bool js_cocos2dx_EventCustom_setUserData(JSContext *cx, uint32_t argc, jsval *vp bool js_cocos2dx_EventCustom_getUserData(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventCustom_EventCustom(JSContext *cx, uint32_t argc, jsval *vp); +extern JSClass *jsb_cocos2d_Device_class; +extern JSObject *jsb_cocos2d_Device_prototype; + +bool js_cocos2dx_Device_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_cocos2dx_Device_finalize(JSContext *cx, JSObject *obj); +void js_register_cocos2dx_Device(JSContext *cx, JSObject *global); +void register_all_cocos2dx(JSContext* cx, JSObject* obj); +bool js_cocos2dx_Device_setAccelerometerEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Device_setAccelerometerInterval(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Device_getDPI(JSContext *cx, uint32_t argc, jsval *vp); + extern JSClass *jsb_cocos2d_FileUtils_class; extern JSObject *jsb_cocos2d_FileUtils_prototype; @@ -3023,6 +3033,7 @@ bool js_cocos2dx_EventListenerTouchOneByOne_constructor(JSContext *cx, uint32_t void js_cocos2dx_EventListenerTouchOneByOne_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_EventListenerTouchOneByOne(JSContext *cx, JSObject *global); void register_all_cocos2dx(JSContext* cx, JSObject* obj); +bool js_cocos2dx_EventListenerTouchOneByOne_isSwallowTouches(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_EventListenerTouchOneByOne_setSwallowTouches(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_cocos2d_EventListenerTouchAllAtOnce_class;