From 538bc7e825b56a461e9900fc79589001b2d25819 Mon Sep 17 00:00:00 2001 From: joshuastray Date: Wed, 14 May 2014 18:23:49 +0800 Subject: [PATCH 1/3] Feature #5033: add _ctor for ccui classes and modify init funcitons --- frameworks/js-bindings/bindings/script/jsb.js | 1 + .../bindings/script/jsb_ext_create_apis.js | 85 +++++++++++++++++++ tools/tojs/cocos2dx_ui.ini | 6 +- 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 frameworks/js-bindings/bindings/script/jsb_ext_create_apis.js diff --git a/frameworks/js-bindings/bindings/script/jsb.js b/frameworks/js-bindings/bindings/script/jsb.js index 4264e3988c..3f3cdc45e1 100644 --- a/frameworks/js-bindings/bindings/script/jsb.js +++ b/frameworks/js-bindings/bindings/script/jsb.js @@ -33,6 +33,7 @@ require('jsb_cocos2d_ui.js'); require('jsb_property_impls.js'); require('jsb_property_apis.js'); require('jsb_create_apis.js'); +require('jsb_ext_create_apis.js'); require('jsb_chipmunk_constants.js'); require('jsb_chipmunk.js'); require('jsb_opengl_constants.js'); diff --git a/frameworks/js-bindings/bindings/script/jsb_ext_create_apis.js b/frameworks/js-bindings/bindings/script/jsb_ext_create_apis.js new file mode 100644 index 0000000000..6066a86eac --- /dev/null +++ b/frameworks/js-bindings/bindings/script/jsb_ext_create_apis.js @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2014 Chukong Technologies Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/************************************************************ + * + * Constructors with built in init function + * + ************************************************************/ +ccui.Widget.prototype.init = ccui.Widget.prototype._init; +ccui.Button.prototype.init = function(){ + ccui.Widget.prototype.init.call(this); + this.setTouchEnabled(true); +}; +ccui.CheckBox.prototype.init = function(){ + ccui.Widget.prototype.init.call(this); + this.setSelectedState(false); + this.setTouchEnabled(true); +}; +ccui.ImageView.prototype.init = ccui.ImageView.prototype._init; +ccui.LoadingBar.prototype.init = function(){ + ccui.Widget.prototype.init.call(this); +}; +ccui.RichText.prototype.init = function(){ + ccui.Widget.prototype.init.call(this); +}; +ccui.Slider.prototype.init = function(){ + ccui.Widget.prototype.init.call(this); + this.setTouchEnabled(true); +}; +ccui.Text.prototype.init = function(){ + ccui.Widget.prototype.init.call(this); +}; +ccui.TextAtlas.prototype.init = function(){ + ccui.Widget.prototype.init.call(this); +}; +ccui.TextBMFont.prototype.init = function(){ + ccui.Widget.prototype.init.call(this); +}; +ccui.TextField.prototype.init = function(){ + ccui.Widget.prototype.init.call(this); + this.setTouchEnabled(true); +}; +ccui.Layout.prototype.init = ccui.Layout.prototype._init; +ccui.ListView.prototype.init = ccui.ListView.prototype._init; +ccui.PageView.prototype.init = ccui.PageView.prototype._init; +ccui.ScrollView.prototype.init = ccui.ScrollView.prototype._init; + +var _p = {}; +_p._ctor = function(){ + this.init(); +} +ccui.Widget.prototype._ctor = ccui.Button.prototype._ctor + = ccui.CheckBox.prototype._ctor + = ccui.ImageView.prototype._ctor + = ccui.LoadingBar.prototype._ctor + = ccui.RichText.prototype._ctor + = ccui.Slider.prototype._ctor + = ccui.Text.prototype._ctor + = ccui.TextAtlas.prototype._ctor + = ccui.TextBMFont.prototype._ctor + = ccui.TextField.prototype._ctor + = ccui.Layout.prototype._ctor + = ccui.ListView.prototype._ctor + = ccui.PageView.prototype._ctor + = ccui.ScrollView.prototype._ctor + = _p._ctor; diff --git a/tools/tojs/cocos2dx_ui.ini b/tools/tojs/cocos2dx_ui.ini index 2c12d05517..458222d634 100644 --- a/tools/tojs/cocos2dx_ui.ini +++ b/tools/tojs/cocos2dx_ui.ini @@ -30,9 +30,9 @@ headers = %(cocosdir)s/cocos/ui/CocosGUI.h # 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 = Helper Layout Widget Layer Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider Switch TextField ScrollView PageView ListView LayoutParameter LinearLayoutParameter RelativeLayoutParameter +classes = Helper Layout Widget Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider Switch TextField ScrollView PageView ListView LayoutParameter LinearLayoutParameter RelativeLayoutParameter -classes_need_extend = Layout Widget Layer Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider Switch TextField ScrollView PageView ListView +classes_need_extend = Layout Widget Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider Switch TextField ScrollView PageView ListView # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -48,7 +48,7 @@ skip = *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*H ImageView::[doubleClickEvent checkDoubleClick], RichText::[getVirtualRendererSize] -rename_functions = +rename_functions = Widget::[init=_init],ImageView::[init=_init],Layout::[init::_init],ListView::[init::_init],PageView::[init::_init],ScrollView::[init=_init] rename_classes = From 6ab5fb64640d7a31fe72bcf9ef3fadb0e935fb04 Mon Sep 17 00:00:00 2001 From: joshuastray Date: Wed, 14 May 2014 18:28:59 +0800 Subject: [PATCH 2/3] Feature #5033:modify format --- tools/tojs/cocos2dx_ui.ini | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/tojs/cocos2dx_ui.ini b/tools/tojs/cocos2dx_ui.ini index 458222d634..ceb03f68b7 100644 --- a/tools/tojs/cocos2dx_ui.ini +++ b/tools/tojs/cocos2dx_ui.ini @@ -48,7 +48,12 @@ skip = *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*H ImageView::[doubleClickEvent checkDoubleClick], RichText::[getVirtualRendererSize] -rename_functions = Widget::[init=_init],ImageView::[init=_init],Layout::[init::_init],ListView::[init::_init],PageView::[init::_init],ScrollView::[init=_init] +rename_functions = Widget::[init=_init], + ImageView::[init=_init], + Layout::[init=_init], + ListView::[init=_init], + PageView::[init=_init], + ScrollView::[init=_init] rename_classes = From 7930246ae38246234b343c8e937f695d4c63812b Mon Sep 17 00:00:00 2001 From: joshuastray Date: Thu, 15 May 2014 10:37:12 +0800 Subject: [PATCH 3/3] Feature #5033: add extend function for ccui classes --- .../js-bindings/bindings/script/jsb_cocos2d.js | 15 +++++++++++++++ .../bindings/script/jsb_ext_create_apis.js | 5 ----- tools/tojs/cocos2dx_ui.ini | 10 +++------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js index 29b872481f..0b278d2587 100644 --- a/frameworks/js-bindings/bindings/script/jsb_cocos2d.js +++ b/frameworks/js-bindings/bindings/script/jsb_cocos2d.js @@ -1492,6 +1492,21 @@ cc.TMXTiledMap.extend = cc.Class.extend; cc.TMXMapInfo.extend = cc.Class.extend; cc.TransitionScene.extend = cc.Class.extend; ccs.Armature.extend = cc.Class.extend; +ccui.Widget.extend = cc.Class.extend; +ccui.Button.extend = cc.Class.extend; +ccui.CheckBox.extend = cc.Class.extend; +ccui.ImageView.extend = cc.Class.extend; +ccui.LoadingBar.extend = cc.Class.extend; +ccui.RichText.extend = cc.Class.extend; +ccui.Slider.extend = cc.Class.extend; +ccui.Text.extend = cc.Class.extend; +ccui.TextAtlas.extend = cc.Class.extend; +ccui.TextBMFont.extend = cc.Class.extend; +ccui.TextField.extend = cc.Class.extend; +ccui.Layout.extend = cc.Class.extend; +ccui.ListView.extend = cc.Class.extend; +ccui.PageView.extend = cc.Class.extend; +ccui.ScrollView.extend = cc.Class.extend; // Cocos2d-html5 supports multi scene resources preloading. // This is a compatible function for JSB. diff --git a/frameworks/js-bindings/bindings/script/jsb_ext_create_apis.js b/frameworks/js-bindings/bindings/script/jsb_ext_create_apis.js index 6066a86eac..4b80492b35 100644 --- a/frameworks/js-bindings/bindings/script/jsb_ext_create_apis.js +++ b/frameworks/js-bindings/bindings/script/jsb_ext_create_apis.js @@ -35,7 +35,6 @@ ccui.CheckBox.prototype.init = function(){ this.setSelectedState(false); this.setTouchEnabled(true); }; -ccui.ImageView.prototype.init = ccui.ImageView.prototype._init; ccui.LoadingBar.prototype.init = function(){ ccui.Widget.prototype.init.call(this); }; @@ -59,10 +58,6 @@ ccui.TextField.prototype.init = function(){ ccui.Widget.prototype.init.call(this); this.setTouchEnabled(true); }; -ccui.Layout.prototype.init = ccui.Layout.prototype._init; -ccui.ListView.prototype.init = ccui.ListView.prototype._init; -ccui.PageView.prototype.init = ccui.PageView.prototype._init; -ccui.ScrollView.prototype.init = ccui.ScrollView.prototype._init; var _p = {}; _p._ctor = function(){ diff --git a/tools/tojs/cocos2dx_ui.ini b/tools/tojs/cocos2dx_ui.ini index ceb03f68b7..ff36326bf7 100644 --- a/tools/tojs/cocos2dx_ui.ini +++ b/tools/tojs/cocos2dx_ui.ini @@ -30,9 +30,9 @@ headers = %(cocosdir)s/cocos/ui/CocosGUI.h # 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 = Helper Layout Widget Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider Switch TextField ScrollView PageView ListView LayoutParameter LinearLayoutParameter RelativeLayoutParameter +classes = Helper Layout Widget Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider TextField ScrollView PageView ListView LayoutParameter LinearLayoutParameter RelativeLayoutParameter -classes_need_extend = Layout Widget Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider Switch TextField ScrollView PageView ListView +classes_need_extend = Layout Widget Button CheckBox ImageView Text TextAtlas TextBMFont RichText RichElement RichElementText RichElementImage RichElementCustomNode LoadingBar Slider TextField ScrollView PageView ListView # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -49,11 +49,7 @@ skip = *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*H RichText::[getVirtualRendererSize] rename_functions = Widget::[init=_init], - ImageView::[init=_init], - Layout::[init=_init], - ListView::[init=_init], - PageView::[init=_init], - ScrollView::[init=_init] + ImageView::[init=_init] rename_classes =