Skip to content

Commit af2321e

Browse files
committed
Merge pull request cocos2d#1855 from joshuastray/develop
Feature #5033: Make ccui classes extendable in H5 and JSB
2 parents dcd07ad + cff9d75 commit af2321e

File tree

15 files changed

+177
-242
lines changed

15 files changed

+177
-242
lines changed

extensions/ccui/base-classes/UIWidget.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ccui.Widget = ccui.Node.extend(/** @lends ccui.Widget# */{
6464
_name: "default",
6565
_widgetType: null,
6666
_actionTag: 0,
67-
_size: null,
67+
_size: cc.size(0, 0),
6868
_customSize: null,
6969
_layoutParameterDictionary: null,
7070
_ignoreSize: false,
@@ -85,38 +85,22 @@ ccui.Widget = ccui.Node.extend(/** @lends ccui.Widget# */{
8585
_flippedY: false,
8686
ctor: function () {
8787
cc.Node.prototype.ctor.call(this);
88-
this._enabled = true;
89-
this._bright = true;
90-
this._touchEnabled = false;
91-
this._touchPassedEnabled = false;
92-
this._focus = false;
9388
this._brightStyle = ccui.Widget.BRIGHT_STYLE_NONE;
94-
this._updateEnabled = false;
9589
this._touchStartPos = cc.p(0, 0);
9690
this._touchMovePos = cc.p(0, 0);
9791
this._touchEndPos = cc.p(0, 0);
98-
this._touchEventListener = null;
99-
this._touchEventSelector = null;
100-
this._name = "default";
10192
this._widgetType = ccui.Widget.TYPE_WIDGET;
102-
this._actionTag = 0;
10393
this._size = cc.size(0, 0);
10494
this._customSize = cc.size(0, 0);
10595
this._layoutParameterDictionary = {};
106-
this._ignoreSize = false;
10796
this._widgetChildren = [];
108-
this._affectByClipping = false;
10997
this._sizeType = ccui.Widget.SIZE_ABSOLUTE;
11098
this._sizePercent = cc.p(0, 0);
11199
this.positionType = ccui.Widget.POSITION_ABSOLUTE;
112100
this._positionPercent = cc.p(0, 0);
113-
this._reorderWidgetChildDirty = false;
114-
this._hitted = false;
115101
this._nodes = [];
116102
this._color = cc.color(255, 255, 255, 255);
117-
this._touchListener = null;
118-
this._flippedX = false;
119-
this._flippedY = false;
103+
this.init();
120104
},
121105

122106
/**
@@ -1491,11 +1475,7 @@ _p = null;
14911475
* var uiWidget = ccui.Widget.create();
14921476
*/
14931477
ccui.Widget.create = function () {
1494-
var widget = new ccui.Widget();
1495-
if (widget && widget.init()) {
1496-
return widget;
1497-
}
1498-
return null;
1478+
return new ccui.Widget();
14991479
};
15001480

15011481

extensions/ccui/layouts/UILayout.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
4040
_backGroundImageFileName: null,
4141
_backGroundImageCapInsets: null,
4242
_colorType: null,
43-
_bgImageTexType: null,
43+
_bgImageTexType: ccui.Widget.LOCAL_TEXTURE,
4444
_colorRender: null,
4545
_gradientRender: null,
4646
_color: null,
4747
_startColor: null,
4848
_endColor: null,
4949
_alongVector: null,
50-
_opacity: null,
50+
_opacity: 255,
5151
_backGroundImageTextureSize: null,
5252
_layoutType: null,
53-
_doLayoutDirty: false,
54-
_clippingRectDirty: false,
53+
_doLayoutDirty: true,
54+
_clippingRectDirty: true,
5555
_clippingType: null,
5656
_clippingStencil: null,
5757
_handleScissor: false,
@@ -60,33 +60,27 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
6060
_clippingParent: null,
6161
_className: "Layout",
6262
_backGroundImageColor: null,
63+
64+
/**
65+
* allocates and initializes a UILayout.
66+
* @constructor
67+
* @example
68+
* // example
69+
* var uiLayout = new ccui.Layout();
70+
*/
6371
ctor: function () {
6472
ccui.Widget.prototype.ctor.call(this);
65-
this._clippingEnabled = false;
66-
this._backGroundScale9Enabled = false;
67-
this._backGroundImage = null;
68-
this._backGroundImageFileName = "";
6973
this._backGroundImageCapInsets = cc.rect(0, 0, 0, 0);
7074
this._colorType = ccui.Layout.BG_COLOR_NONE;
71-
this._bgImageTexType = ccui.Widget.LOCAL_TEXTURE;
72-
this._colorRender = null;
73-
this._gradientRender = null;
7475
this._color = cc.color(255, 255, 255, 255);
7576
this._startColor = cc.color(255, 255, 255, 255);
7677
this._endColor = cc.color(255, 255, 255, 255);
7778
this._alongVector = cc.p(0, -1);
78-
this._opacity = 255;
7979
this._backGroundImageTextureSize = cc.size(0, 0);
8080
this._layoutType = ccui.Layout.ABSOLUTE;
8181
this._widgetType = ccui.Widget.TYPE_CONTAINER;
82-
this._doLayoutDirty = true;
83-
this._clippingRectDirty = true;
8482
this._clippingType = ccui.Layout.CLIPPING_STENCIL;
85-
this._clippingStencil = null;
86-
this._handleScissor = false;
87-
this._scissorRectDirty = false;
8883
this._clippingRect = cc.rect(0, 0, 0, 0);
89-
this._clippingParent = null;
9084
this._backGroundImageColor = cc.color(255, 255, 255, 255);
9185
},
9286
init: function () {
@@ -1532,11 +1526,7 @@ _p = null;
15321526
* var uiLayout = ccui.Layout.create();
15331527
*/
15341528
ccui.Layout.create = function () {
1535-
var layout = new ccui.Layout();
1536-
if (layout && layout.init()) {
1537-
return layout;
1538-
}
1539-
return null;
1529+
return new ccui.Layout();
15401530
};
15411531

15421532
// Constants

extensions/ccui/uiwidgets/UIButton.js

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ ccui.Button = ccui.Widget.extend(/** @lends ccui.Button# */{
4949
_capInsetsNormal: null,
5050
_capInsetsPressed: null,
5151
_capInsetsDisabled: null,
52-
_normalTexType: null,
53-
_pressedTexType: null,
54-
_disabledTexType: null,
52+
_normalTexType: ccui.Widget.LOCAL_TEXTURE,
53+
_pressedTexType: ccui.Widget.LOCAL_TEXTURE,
54+
_disabledTexType: ccui.Widget.LOCAL_TEXTURE,
5555
_normalTextureSize: null,
5656
_pressedTextureSize: null,
5757
_disabledTextureSize: null,
5858
pressedActionEnabled: false,
59-
_titleColor: null,
59+
_titleColor: cc.color.WHITE,
6060
_normalTextureScaleXInSize: 1,
6161
_normalTextureScaleYInSize: 1,
6262
_pressedTextureScaleXInSize: 1,
@@ -65,36 +65,24 @@ ccui.Button = ccui.Widget.extend(/** @lends ccui.Button# */{
6565
_pressedTextureLoaded: false,
6666
_disabledTextureLoaded: false,
6767
_className: "Button",
68+
69+
/**
70+
* allocates and initializes a UIButton.
71+
* @constructor
72+
* @example
73+
* // example
74+
* var uiButton = new ccui.Button();
75+
*/
6876
ctor: function () {
69-
ccui.Widget.prototype.ctor.call(this);
70-
this._buttonNormalRenderer = null;
71-
this._buttonClickedRenderer = null;
72-
this._buttonDisableRenderer = null;
73-
this._titleRenderer = null;
74-
this._normalFileName = "";
75-
this._clickedFileName = "";
76-
this._disabledFileName = "";
77-
this._prevIgnoreSize = true;
78-
this._scale9Enabled = false;
7977
this._capInsetsNormal = cc.rect(0, 0, 0, 0);
8078
this._capInsetsPressed = cc.rect(0, 0, 0, 0);
8179
this._capInsetsDisabled = cc.rect(0, 0, 0, 0);
82-
this._normalTexType = ccui.Widget.LOCAL_TEXTURE;
83-
this._pressedTexType = ccui.Widget.LOCAL_TEXTURE;
84-
this._disabledTexType = ccui.Widget.LOCAL_TEXTURE;
8580
var locSize = this._size;
8681
this._normalTextureSize = cc.size(locSize.width, locSize.height);
8782
this._pressedTextureSize = cc.size(locSize.width, locSize.height);
8883
this._disabledTextureSize = cc.size(locSize.width, locSize.height);
89-
this.pressedActionEnabled = false;
90-
this._titleColor = cc.color.WHITE;
91-
this._normalTextureScaleXInSize = 1;
92-
this._normalTextureScaleYInSize = 1;
93-
this._pressedTextureScaleXInSize = 1;
94-
this._pressedTextureScaleYInSize = 1;
95-
this._normalTextureLoaded = false;
96-
this._pressedTextureLoaded = false;
97-
this._disabledTextureLoaded = false;
84+
85+
ccui.Widget.prototype.ctor.call(this);
9886
},
9987

10088
init: function () {
@@ -821,11 +809,7 @@ _p = null;
821809
* var uiButton = ccui.Button.create();
822810
*/
823811
ccui.Button.create = function () {
824-
var uiButton = new ccui.Button();
825-
if (uiButton && uiButton.init()) {
826-
return uiButton;
827-
}
828-
return null;
812+
return new ccui.Button;
829813
};
830814

831815
// Constants

extensions/ccui/uiwidgets/UICheckBox.js

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,27 @@ ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{
3939
_isSelected: true,
4040
_checkBoxEventListener: null,
4141
_checkBoxEventSelector: null,
42-
_backGroundTexType: null,
43-
_backGroundSelectedTexType: null,
44-
_frontCrossTexType: null,
45-
_backGroundDisabledTexType: null,
46-
_frontCrossDisabledTexType: null,
42+
_backGroundTexType: ccui.Widget.LOCAL_TEXTURE,
43+
_backGroundSelectedTexType: ccui.Widget.LOCAL_TEXTURE,
44+
_frontCrossTexType: ccui.Widget.LOCAL_TEXTURE,
45+
_backGroundDisabledTexType: ccui.Widget.LOCAL_TEXTURE,
46+
_frontCrossDisabledTexType: ccui.Widget.LOCAL_TEXTURE,
4747
_backGroundFileName: "",
4848
_backGroundSelectedFileName: "",
4949
_frontCrossFileName: "",
5050
_backGroundDisabledFileName: "",
5151
_frontCrossDisabledFileName: "",
5252
_className: "CheckBox",
53+
54+
/**
55+
* allocates and initializes a UICheckBox.
56+
* @constructor
57+
* @example
58+
* // example
59+
* var uiCheckBox = new ccui.CheckBox();
60+
*/
5361
ctor: function () {
5462
ccui.Widget.prototype.ctor.call(this);
55-
this._backGroundBoxRenderer = null;
56-
this._backGroundSelectedBoxRenderer = null;
57-
this._frontCrossRenderer = null;
58-
this._backGroundBoxDisabledRenderer = null;
59-
this._frontCrossDisabledRenderer = null;
60-
this._isSelected = true;
61-
this._checkBoxEventListener = null;
62-
this._checkBoxEventSelector = null;
63-
this._backGroundTexType = ccui.Widget.LOCAL_TEXTURE;
64-
this._backGroundSelectedTexType = ccui.Widget.LOCAL_TEXTURE;
65-
this._frontCrossTexType = ccui.Widget.LOCAL_TEXTURE;
66-
this._backGroundDisabledTexType = ccui.Widget.LOCAL_TEXTURE;
67-
this._frontCrossDisabledTexType = ccui.Widget.LOCAL_TEXTURE;
68-
this._backGroundFileName = "";
69-
this._backGroundSelectedFileName = "";
70-
this._frontCrossFileName = "";
71-
this._backGroundDisabledFileName = "";
72-
this._frontCrossDisabledFileName = "";
7363
},
7464
init: function () {
7565
if (ccui.Widget.prototype.init.call(this)) {
@@ -572,11 +562,7 @@ _p = null;
572562
* var uiCheckBox = ccui.CheckBox.create();
573563
*/
574564
ccui.CheckBox.create = function () {
575-
var uiCheckBox = new ccui.CheckBox();
576-
if (uiCheckBox && uiCheckBox.init()) {
577-
return uiCheckBox;
578-
}
579-
return null;
565+
return new ccui.CheckBox();
580566
};
581567

582568
// Constants

extensions/ccui/uiwidgets/UIImageView.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@ ccui.ImageView = ccui.Widget.extend(/** @lends ccui.ImageView# */{
3434
_capInsets: null,
3535
_imageRenderer: null,
3636
_textureFile: "",
37-
_imageTexType: null,
37+
_imageTexType: ccui.Widget.LOCAL_TEXTURE,
3838
_imageTextureSize: null,
3939
_className:"ImageView",
40+
41+
/**
42+
* allocates and initializes a UIImageView.
43+
* @constructor
44+
* @example
45+
* // example
46+
* var uiImageView = new ccui.ImageView;
47+
*/
4048
ctor: function () {
41-
ccui.Widget.prototype.ctor.call(this);
42-
this._scale9Enabled = false;
43-
this._prevIgnoreSize = true;
4449
this._capInsets = cc.rect(0,0,0,0);
45-
this._imageRenderer = null;
46-
this._textureFile = "";
47-
this._imageTexType = ccui.Widget.LOCAL_TEXTURE;
4850
this._imageTextureSize = cc.size(this._size.width, this._size.height);
51+
ccui.Widget.prototype.ctor.call(this);
4952
},
5053

5154
initRenderer: function () {
@@ -320,11 +323,7 @@ ccui.ImageView = ccui.Widget.extend(/** @lends ccui.ImageView# */{
320323
* var uiImageView = ccui.ImageView.create();
321324
*/
322325
ccui.ImageView.create = function () {
323-
var uiImageView = new ccui.ImageView();
324-
if (uiImageView && uiImageView.init()) {
325-
return uiImageView;
326-
}
327-
return null;
326+
return new ccui.ImageView();
328327
};
329328

330329
// Constants

extensions/ccui/uiwidgets/UILoadingBar.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,27 @@ ccui.LoadingBar = ccui.Widget.extend(/** @lends ccui.LoadingBar# */{
3636
_percent: 100,
3737
_totalLength: 0,
3838
_barRenderer: null,
39-
_renderBarTexType: null,
39+
_renderBarTexType: ccui.Widget.LOCAL_TEXTURE,
4040
_barRendererTextureSize: null,
4141
_scale9Enabled: false,
4242
_prevIgnoreSize: true,
4343
_capInsets: null,
4444
_textureFile: "",
4545
_isTextureLoaded: false,
4646
_className: "LoadingBar",
47+
48+
/**
49+
* allocates and initializes a UILoadingBar.
50+
* @constructor
51+
* @example
52+
* // example
53+
* var uiLoadingBar = new ccui.LoadingBar;
54+
*/
4755
ctor: function () {
48-
ccui.Widget.prototype.ctor.call(this);
4956
this._barType = ccui.LoadingBar.TYPE_LEFT;
50-
this._percent = 100;
51-
this._totalLength = 0;
52-
this._barRenderer = null;
53-
this._renderBarTexType = ccui.Widget.LOCAL_TEXTURE;
5457
this._barRendererTextureSize = cc.size(0, 0);
55-
this._scale9Enabled = false;
56-
this._prevIgnoreSize = true;
5758
this._capInsets = cc.rect(0, 0, 0, 0);
58-
this._textureFile = "";
59+
ccui.Widget.prototype.ctor.call(this);
5960
},
6061

6162
initRenderer: function () {
@@ -404,11 +405,7 @@ _p = null;
404405
* var uiLoadingBar = ccui.LoadingBar.create();
405406
*/
406407
ccui.LoadingBar.create = function () {
407-
var uiLoadingBar = new ccui.LoadingBar();
408-
if (uiLoadingBar && uiLoadingBar.init()) {
409-
return uiLoadingBar;
410-
}
411-
return null;
408+
return new ccui.LoadingBar();
412409
};
413410

414411
// Constants

0 commit comments

Comments
 (0)