Skip to content

issue #3251 fix bug for layout #1298

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

Merged
merged 2 commits into from
Dec 5, 2013
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions extensions/CocoStudio/GUI/BaseClasses/UIWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ ccs.UIWidget = ccs.Class.extend(/** @lends ccs.UIWidget# */{
*/
removeAllChildren: function () {
var childrenLength = this._children.length;
if (this._children.length <= 0) {
if (childrenLength <= 0) {
return
}
for (var i = 0; i < childrenLength; ++i) {
Expand All @@ -313,12 +313,12 @@ ccs.UIWidget = ccs.Class.extend(/** @lends ccs.UIWidget# */{
* @param {ccs.UIWidget} child
*/
reorderChild: function (child) {
cc.ArrayRemoveObject(this._children, child);
var childrenCount = this._children.length;
if (childrenCount <= 0) {
this._children.push(child);
return;
}
else {
cc.ArrayRemoveObject(this._children, child);
var seekSucceed = false;
var arrayChildren = this._children;
for (var i = childrenCount - 1; i >= 0; --i) {
Expand Down Expand Up @@ -509,7 +509,7 @@ ccs.UIWidget = ccs.Class.extend(/** @lends ccs.UIWidget# */{
*/
ignoreContentAdaptWithSize: function (ignore) {
this._ignoreSize = ignore;
var locSize = this.getContentSize();
var locSize;
if (this._ignoreSize) {
locSize = this.getContentSize();
}
Expand Down
165 changes: 123 additions & 42 deletions extensions/CocoStudio/GUI/Layouts/UILayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,39 +206,21 @@ ccs.UILayout = ccs.UIWidget.extend(/** @lends ccs.UILayout# */{
}
this._backGroundImageFileName = fileName;
this._bgImageTexType = texType;
if (this._backGroundScale9Enabled) {
switch (this._bgImageTexType) {
case ccs.TextureResType.local:
this._backGroundImage.initWithFile(fileName);
break;
case ccs.TextureResType.plist:
this._backGroundImage.initWithSpriteFrameName(fileName);
break;
default:
break;
}
this._backGroundImage.setPreferredSize(this._size);
}
else {
switch (this._bgImageTexType) {
case ccs.TextureResType.local:
this._backGroundImage.initWithFile(fileName);
break;
case ccs.TextureResType.plist:
this._backGroundImage.initWithSpriteFrameName(fileName);
break;
default:
break;
}
switch (this._bgImageTexType) {
case ccs.TextureResType.local:
this._backGroundImage.initWithFile(fileName);
break;
case ccs.TextureResType.plist:
this._backGroundImage.initWithSpriteFrameName(fileName);
break;
default:
break;
}
if (this._backGroundScale9Enabled) {
this._backGroundImage.setColor(this.getColor());
this._backGroundImage.setOpacity(this.getOpacity());
}
else {
this._backGroundImage.setColor(this.getColor());
this._backGroundImage.setOpacity(this.getOpacity());
this._backGroundImage.setPreferredSize(this._size);
}
this._backGroundImage.setColor(this.getColor());
this._backGroundImage.setOpacity(this.getOpacity());
this._backGroundImageTextureSize = this._backGroundImage.getContentSize();
this._backGroundImage.setPosition(cc.p(this._size.width / 2.0, this._size.height / 2.0));
},
Expand Down Expand Up @@ -285,15 +267,13 @@ ccs.UILayout = ccs.UIWidget.extend(/** @lends ccs.UILayout# */{
addBackGroundImage: function () {
if (this._backGroundScale9Enabled) {
this._backGroundImage = cc.Scale9Sprite.create();
this._backGroundImage.setZOrder(-1);
this._renderer.addChild(this._backGroundImage);
this._backGroundImage.setPreferredSize(this._size);
}
else {
this._backGroundImage = cc.Sprite.create();
this._backGroundImage.setZOrder(-1);
this._renderer.addChild(this._backGroundImage);
}
this._backGroundImage.setZOrder(-1);
this._renderer.addChild(this._backGroundImage);
this._backGroundImage.setPosition(cc.p(this._size.width / 2.0, this._size.height / 2.0));
},

Expand Down Expand Up @@ -772,8 +752,8 @@ ccs.UILayout = ccs.UIWidget.extend(/** @lends ccs.UILayout# */{
}
var locRelativeWidgetMargin;
var locMargin = locLayoutParameter.getMargin();
if (locRelativeWidget) {
locRelativeWidgetMargin = locRelativeWidget.getLayoutParameter(ccs.LayoutParameterType.relative).getMargin();
if (locRelativeWidgetLP) {
locRelativeWidgetMargin = locRelativeWidgetLP.getMargin();
}
//handle margin
switch (locAlign) {
Expand Down Expand Up @@ -810,28 +790,128 @@ ccs.UILayout = ccs.UIWidget.extend(/** @lends ccs.UILayout# */{
break;

case ccs.UIRelativeAlign.locationAboveLeftAlign:
locFinalPosY += locMargin.bottom;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopCenterHorizontal
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopLeft
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignNone
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopRight)
{
locFinalPosY += locRelativeWidgetMargin.top;
}
locFinalPosY += locMargin.left;
break;
case ccs.UIRelativeAlign.locationAboveCenter:
locFinalPosY += locMargin.bottom;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopCenterHorizontal
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopLeft
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignNone
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopRight)
{
locFinalPosY += locRelativeWidgetMargin.top;
}
break;
case ccs.UIRelativeAlign.locationAboveRightAlign:
locFinalPosY += locMargin.bottom;
locFinalPosY += locRelativeWidgetMargin.top;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopCenterHorizontal
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopLeft
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignNone
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopRight)
{
locFinalPosY += locRelativeWidgetMargin.top;
}
locFinalPosX -= locMargin.right;
break;
case ccs.UIRelativeAlign.locationLeftOfTopAlign:
locFinalPosX -= locMargin.right;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopLeft
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignNone
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentLeftBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentLeftCenterVertical)
{
locFinalPosX -= locRelativeWidgetMargin.left;
}
locFinalPosY -= locMargin.top;
break;
case ccs.UIRelativeAlign.locationLeftOfCenter:
locFinalPosX -= locMargin.right;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopLeft
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignNone
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentLeftBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentLeftCenterVertical)
{
locFinalPosX -= locRelativeWidgetMargin.left;
}
break;
case ccs.UIRelativeAlign.locationLeftOfBottomAlign:
locFinalPosX -= locMargin.right;
locFinalPosX -= locRelativeWidgetMargin.left;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopLeft
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignNone
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentLeftBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentLeftCenterVertical)
{
locFinalPosX -= locRelativeWidgetMargin.left;
}
locFinalPosY += locMargin.bottom;
break;
break;
case ccs.UIRelativeAlign.locationRightOfTopAlign:
locFinalPosX += locMargin.left;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopRight
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentRightBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentRightCenterVertical)
{
locFinalPosX += locRelativeWidgetMargin.right;
}
locFinalPosY -= locMargin.top;
break;
case ccs.UIRelativeAlign.locationRightOfCenter:
locFinalPosX += locMargin.left;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopRight
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentRightBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentRightCenterVertical)
{
locFinalPosX += locRelativeWidgetMargin.right;
}
break;
case ccs.UIRelativeAlign.locationRightOfBottomAlign:
locFinalPosX += locMargin.left;
locFinalPosX += locRelativeWidgetMargin.right;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentTopRight
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentRightBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentRightCenterVertical)
{
locFinalPosX += locRelativeWidgetMargin.right;
}
locFinalPosY += locMargin.bottom;
break;
break;
case ccs.UIRelativeAlign.locationBelowLeftAlign:
locFinalPosY -= locMargin.top;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentLeftBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentRightBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentBottomCenterHorizontal)
{
locFinalPosY -= locRelativeWidgetMargin.bottom;
}
locFinalPosX += locMargin.left;
break;
case ccs.UIRelativeAlign.locationBelowCenter:
locFinalPosY -= locMargin.top;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentLeftBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentRightBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentBottomCenterHorizontal)
{
locFinalPosY -= locRelativeWidgetMargin.bottom;
}
break;
case ccs.UIRelativeAlign.locationBelowRightAlign:
locFinalPosY -= locMargin.top;
locFinalPosY -= locRelativeWidgetMargin.bottom;
if (locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentLeftBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentRightBottom
&& locRelativeWidgetLP.getAlign() != ccs.UIRelativeAlign.alignParentBottomCenterHorizontal)
{
locFinalPosY -= locRelativeWidgetMargin.bottom;
}
locFinalPosX -= locMargin.right;
break;
default:
break;
Expand Down Expand Up @@ -930,7 +1010,7 @@ ccs.UIRectClippingNode = cc.ClippingNode.extend({
this._arrRect[3] = cc.p(0, this._clippingSize.height);

var green = cc.c4f(0, 1, 0, 1);
this._innerStencil.drawPoly(this._arrRect, 4, green, 0, green);
//this._innerStencil.drawPoly(this._arrRect,green, 0, green);
if (cc.Browser.supportWebGL) {
if (cc.ClippingNode.prototype.init.call(this, this._innerStencil)) {
return true;
Expand All @@ -954,7 +1034,7 @@ ccs.UIRectClippingNode = cc.ClippingNode.extend({
this._arrRect[3] = cc.p(0, this._clippingSize.height);
var green = cc.c4f(0, 1, 0, 1);
this._innerStencil.clear();
this._innerStencil.drawPoly(this._arrRect, 4, green, 0, green);
//this._innerStencil.drawPoly(this._arrRect, green, 0, green);
},

setClippingEnabled: function (enabled) {
Expand Down Expand Up @@ -1015,6 +1095,7 @@ ccs.UIRectClippingNode = cc.ClippingNode.extend({

this._orderOfArrival = 0;
context.restore();
this._stencil.visit();
},

setEnabled: function (enabled) {
Expand Down