Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #5033: Make ccui classes extendable in H5 and JSB #372

Merged
merged 4 commits into from May 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions frameworks/js-bindings/bindings/script/jsb.js
Expand Up @@ -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');
Expand Down
15 changes: 15 additions & 0 deletions frameworks/js-bindings/bindings/script/jsb_cocos2d.js
Expand Up @@ -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.
Expand Down
80 changes: 80 additions & 0 deletions frameworks/js-bindings/bindings/script/jsb_ext_create_apis.js
@@ -0,0 +1,80 @@
/*
* 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.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);
};

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;
7 changes: 4 additions & 3 deletions tools/tojs/cocos2dx_ui.ini
Expand Up @@ -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 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 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
Expand All @@ -48,7 +48,8 @@ skip = *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*H
ImageView::[doubleClickEvent checkDoubleClick],
RichText::[getVirtualRendererSize]

rename_functions =
rename_functions = Widget::[init=_init],
ImageView::[init=_init]

rename_classes =

Expand Down