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

issue #4221 add richText #1648

Merged
merged 7 commits into from Mar 7, 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
45 changes: 43 additions & 2 deletions extensions/ccui/base-classes/UIWidget.js
Expand Up @@ -107,6 +107,8 @@ ccui.Widget = ccui.Node.extend(/** @lends ccui.Widget# */{
_touchListener : null,
_color:null,
_className:"Widget",
_flippedX: false,
_flippedY: false,
ctor: function () {
cc.Node.prototype.ctor.call(this);
this._enabled = true;
Expand Down Expand Up @@ -139,6 +141,8 @@ ccui.Widget = ccui.Node.extend(/** @lends ccui.Widget# */{
this._nodes = [];
this._color = cc.color(255,255,255,255);
this._touchListener = null;
this._flippedX = false;
this._flippedY = false;
},

/**
Expand Down Expand Up @@ -647,6 +651,14 @@ ccui.Widget = ccui.Node.extend(/** @lends ccui.Widget# */{
return this._size;
},

/**
* Get custom size
* @returns {cc.Size}
*/
getCustomSize:function(){
return this._customSize
},

/**
* Returns size percent of widget
* @returns {cc.Point}
Expand Down Expand Up @@ -1152,17 +1164,46 @@ ccui.Widget = ccui.Node.extend(/** @lends ccui.Widget# */{
return this.positionType;
},

/**
* Set flipped x
* @param {Boolean} flipX
*/
setFlippedX: function (flipX) {
this._flippedX = flipX;
this.updateFlippedX();
},

/**
* Get flipped x
* @returns {Boolean}
*/
isFlippedX: function () {
return false;
return this._flippedX;
},

/**
* Set flipped y
* @param {Boolean} flipY
*/
setFlippedY: function (flipY) {
this._flippedY = flipY;
this.updateFlippedY();
},

/**
* Get flipped y
* @returns {Boolean}
*/
isFlippedY: function () {
return false;
return this._flippedY;
},

updateFlippedX:function(){

},

updateFlippedY:function(){

},

/**
Expand Down
52 changes: 49 additions & 3 deletions extensions/ccui/layouts/UILayout.js
Expand Up @@ -74,7 +74,8 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
_scissorRectDirty: false,
_clippingRect: null,
_clippingParent: null,
_className:"Layout",
_className:"Layout",
_backGroundImageColor:null,
ctor: function () {
ccui.Widget.prototype.ctor.call(this);
this._clippingEnabled = false;
Expand Down Expand Up @@ -102,6 +103,7 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
this._scissorRectDirty = false;
this._clippingRect = cc.rect(0, 0, 0, 0);
this._clippingParent = null;
this._backGroundImageColor = cc.color(255, 255, 255, 255);
},
init: function () {
if (cc.Node.prototype.init.call(this)){
Expand Down Expand Up @@ -679,10 +681,9 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
if (this._backGroundScale9Enabled) {
this._backGroundImage.setPreferredSize(this._size);
}
this._backGroundImage.setColor(this.getColor());
this._backGroundImage.setOpacity(this.getOpacity());
this._backGroundImageTextureSize = this._backGroundImage.getContentSize();
this._backGroundImage.setPosition(this._size.width / 2.0, this._size.height / 2.0);
this.updateBackGroundImageColor();
},

/**
Expand Down Expand Up @@ -924,6 +925,51 @@ ccui.Layout = ccui.Widget.extend(/** @lends ccui.Layout# */{
return this._alongVector;
},

/**
* Set backGround image color
* @param {cc.Color} color
*/
setBackGroundImageColor: function (color) {
this._backGroundImageColor.r = color.r;
this._backGroundImageColor.g = color.g;
this._backGroundImageColor.b = color.b;

this.updateBackGroundImageColor();
if (color.a !== undefined && !color.a_undefined) {
this.setBackGroundImageOpacity(color.a);
}
},

/**
* Get backGround image color
* @param {Number} opacity
*/
setBackGroundImageOpacity: function (opacity) {
this._backGroundImageColor.a = color.a;
this.getBackGroundImageColor();
},

/**
* Get backGround image color
* @returns {cc.Color}
*/
getBackGroundImageColor: function () {
var color = this._backGroundImageColor;
return cc.color(color.r, color.g, color.b, color.a);
},

/**
* Get backGround image opacity
* @returns {Number}
*/
getBackGroundImageOpacity: function () {
return this._backGroundImageColor.a;
},

updateBackGroundImageColor: function () {
this._backGroundImage.setColor(this._backGroundImageColor);
},

/**
* Gets background image texture size.
* @returns {cc.Size}
Expand Down
63 changes: 41 additions & 22 deletions extensions/ccui/uiwidgets/UIButton.js
Expand Up @@ -102,8 +102,10 @@ ccui.Button = ccui.Widget.extend(/** @lends ccui.Button# */{
},

init: function () {
if (ccui.Widget.prototype.init.call(this))
if (ccui.Widget.prototype.init.call(this)){
this.setTouchEnabled(true);
return true;
}
return false;
},

Expand Down Expand Up @@ -241,7 +243,8 @@ ccui.Button = ccui.Widget.extend(/** @lends ccui.Button# */{

this.updateColorToRenderer(buttonNormalRenderer);
this.updateAnchorPoint();

this.updateFlippedX();
this.updateFlippedY();
this.normalTextureScaleChangedWithSize();
this._normalTextureLoaded = true;
},
Expand Down Expand Up @@ -289,6 +292,8 @@ ccui.Button = ccui.Widget.extend(/** @lends ccui.Button# */{
}
this.updateColorToRenderer(clickedRenderer);
this.updateAnchorPoint();
this.updateFlippedX();
this.updateFlippedY();
this.pressedTextureScaleChangedWithSize();
this._pressedTextureLoaded = true;
},
Expand Down Expand Up @@ -336,6 +341,8 @@ ccui.Button = ccui.Widget.extend(/** @lends ccui.Button# */{
}
this.updateColorToRenderer(disableRenderer);
this.updateAnchorPoint();
this.updateFlippedX();
this.updateFlippedY();
this.disabledTextureScaleChangedWithSize();
this._disabledTextureLoaded = true;
},
Expand Down Expand Up @@ -465,32 +472,44 @@ ccui.Button = ccui.Widget.extend(/** @lends ccui.Button# */{
this._buttonClickedRenderer.setScale(this._pressedTextureScaleXInSize, this._pressedTextureScaleYInSize);
},

/**
* override "setFlippedX" of widget.
* @param {Boolean} flipX
*/
setFlippedX: function (flipX) {
this._titleRenderer.setFlippedX(flipX);
updateFlippedX: function () {
this._titleRenderer.setFlippedX(this._flippedX);
if (this._scale9Enabled) {
return;
if (this._flippedX) {
this._buttonNormalRenderer.setScaleX(-1);
this._buttonClickedRenderer.setScaleX(-1);
this._buttonDisableRenderer.setScaleX(-1);
}
else {
this._buttonNormalRenderer.setScaleX(1);
this._buttonClickedRenderer.setScaleX(1);
this._buttonDisableRenderer.setScaleX(1);
}
} else {
this._buttonNormalRenderer.setFlippedX(this._flippedX);
this._buttonClickedRenderer.setFlippedX(this._flippedX);
this._buttonDisableRenderer.setFlippedX(this._flippedX);
}
this._buttonNormalRenderer.setFlippedX(flipX);
this._buttonClickedRenderer.setFlippedX(flipX);
this._buttonDisableRenderer.setFlippedX(flipX);
},

/**
* override "setFlippedY" of widget.
* @param {Boolean} flipY
*/
setFlippedY: function (flipY) {
this._titleRenderer.setFlippedY(flipY);
updateFlippedY: function () {
this._titleRenderer.setFlippedY(this._flippedY);
if (this._scale9Enabled) {
return;
if (this._flippedX) {
this._buttonNormalRenderer.setScaleY(-1);
this._buttonClickedRenderer.setScaleX(-1);
this._buttonDisableRenderer.setScaleX(-1);
}
else {
this._buttonNormalRenderer.setScaleY(1);
this._buttonClickedRenderer.setScaleY(1);
this._buttonDisableRenderer.setScaleY(1);
}
}else{
this._buttonNormalRenderer.setFlippedY(this._flippedY);
this._buttonClickedRenderer.setFlippedY(this._flippedY);
this._buttonDisableRenderer.setFlippedY(this._flippedY);
}
this._buttonNormalRenderer.setFlippedY(flipY);
this._buttonClickedRenderer.setFlippedY(flipY);
this._buttonDisableRenderer.setFlippedY(flipY);
},

/**
Expand Down
45 changes: 23 additions & 22 deletions extensions/ccui/uiwidgets/UICheckBox.js
Expand Up @@ -82,6 +82,7 @@ ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{
},
init: function () {
if (ccui.Widget.prototype.init.call(this)) {
this.setTouchEnabled(true);
this.setSelectedState(false);
return true;
}
Expand Down Expand Up @@ -144,7 +145,8 @@ ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{

this.updateColorToRenderer(bgBoxRenderer);
this.updateAnchorPoint();

this.updateFlippedX();
this.updateFlippedY();
if(!bgBoxRenderer.textureLoaded()){
this._backGroundBoxRenderer.setContentSize(this._customSize);
bgBoxRenderer.addLoadedEventListener(function(){
Expand Down Expand Up @@ -177,7 +179,8 @@ ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{
}
this.updateColorToRenderer(this._backGroundSelectedBoxRenderer);
this.updateAnchorPoint();

this.updateFlippedX();
this.updateFlippedY();
this.backGroundSelectedTextureScaleChangedWithSize();
},

Expand Down Expand Up @@ -205,6 +208,8 @@ ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{
}
this.updateColorToRenderer(this._frontCrossRenderer);
this.updateAnchorPoint();
this.updateFlippedX();
this.updateFlippedY();
this.frontCrossTextureScaleChangedWithSize();
},

Expand Down Expand Up @@ -232,6 +237,8 @@ ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{
}
this.updateColorToRenderer(this._backGroundBoxDisabledRenderer);
this.updateAnchorPoint();
this.updateFlippedX();
this.updateFlippedY();
this.backGroundDisabledTextureScaleChangedWithSize();
},

Expand Down Expand Up @@ -259,6 +266,8 @@ ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{
}
this.updateColorToRenderer(this._frontCrossDisabledRenderer);
this.updateAnchorPoint();
this.updateFlippedX();
this.updateFlippedY();
this.frontCrossDisabledTextureScaleChangedWithSize();
},

Expand Down Expand Up @@ -342,28 +351,20 @@ ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{
this._checkBoxEventListener = target;
},

/**
* Sets whether the widget should be flipped horizontally or not.
* @param {Boolean} flipX
*/
setFlippedX: function (flipX) {
this._backGroundBoxRenderer.setFlippedX(flipX);
this._backGroundSelectedBoxRenderer.setFlippedX(flipX);
this._frontCrossRenderer.setFlippedX(flipX);
this._backGroundBoxDisabledRenderer.setFlippedX(flipX);
this._frontCrossDisabledRenderer.setFlippedX(flipX);
updateFlippedX: function () {
this._backGroundBoxRenderer.setFlippedX(this._flippedX);
this._backGroundSelectedBoxRenderer.setFlippedX(this._flippedX);
this._frontCrossRenderer.setFlippedX(this._flippedX);
this._backGroundBoxDisabledRenderer.setFlippedX(this._flippedX);
this._frontCrossDisabledRenderer.setFlippedX(this._flippedX);
},

/**
* override "setFlippedY" of widget.
* @param {Boolean} flipY
*/
setFlippedY: function (flipY) {
this._backGroundBoxRenderer.setFlippedY(flipY);
this._backGroundSelectedBoxRenderer.setFlippedY(flipY);
this._frontCrossRenderer.setFlippedY(flipY);
this._backGroundBoxDisabledRenderer.setFlippedY(flipY);
this._frontCrossDisabledRenderer.setFlippedY(flipY);
updateFlippedY: function () {
this._backGroundBoxRenderer.setFlippedY(this._flippedY);
this._backGroundSelectedBoxRenderer.setFlippedY(this._flippedY);
this._frontCrossRenderer.setFlippedY(this._flippedY);
this._backGroundBoxDisabledRenderer.setFlippedY(this._flippedY);
this._frontCrossDisabledRenderer.setFlippedY(this._flippedY);
},

/**
Expand Down