Skip to content

Commit 564becc

Browse files
committed
scaling now has a different behavior
1 parent 4f084fa commit 564becc

File tree

2 files changed

+31
-62
lines changed

2 files changed

+31
-62
lines changed

extensions/GUI/CCControlExtension/CCScale9Sprite.js

Lines changed: 30 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -93,67 +93,36 @@ cc.Scale9Sprite = cc.Node.extend({
9393
this._bottom.setAnchorPoint(cc.p(0, 0));
9494
this._centre.setAnchorPoint(cc.p(0, 0));
9595

96-
if(!this._capInsets)
97-
{
98-
var equalWidth = size.width / 3;
99-
var equalHeight = size.height / 3;
100-
101-
var equalWidthScale = equalWidth / this._centre.getContentSize().width;
102-
var equalHeightScale = equalHeight / this._centre.getContentSize().height;
103-
104-
this._topLeft.setScale(equalWidthScale, equalHeightScale);
105-
this._top.setScale(equalWidthScale, equalHeightScale);
106-
this._topRight.setScale(equalWidthScale, equalHeightScale);
107-
this._left.setScale(equalWidthScale, equalHeightScale);
108-
this._centre.setScale(equalWidthScale, equalHeightScale);
109-
this._right.setScale(equalWidthScale, equalHeightScale);
110-
this._bottomLeft.setScale(equalWidthScale, equalHeightScale);
111-
this._bottom.setScale(equalWidthScale, equalHeightScale);
112-
this._bottomRight.setScale(equalWidthScale, equalHeightScale);
113-
114-
this._topLeft.setPosition(cc.p(0, 2 * equalHeight));
115-
this._top.setPosition(cc.p(equalWidth, 2 * equalHeight));
116-
this._topRight.setPosition(cc.p(2 * equalWidth, 2 * equalHeight));
117-
this._left.setPosition(cc.p(0, equalHeight));
118-
this._centre.setPosition(cc.p(equalWidth, equalHeight));
119-
this._right.setPosition(cc.p(2 * equalWidth, equalHeight));
120-
this._bottomLeft.setPosition(cc.p(0, 0));
121-
this._bottom.setPosition(cc.p(equalWidth, 0));
122-
this._bottomRight.setPosition(cc.p(2 * equalWidth, 0));
123-
}
124-
else
125-
{
126-
var sizableWidth = size.width - this._topLeft.getContentSize().width - this._topRight.getContentSize().width;
127-
var sizableHeight = size.height - this._topLeft.getContentSize().height - this._bottomRight.getContentSize().height;
128-
var horizontalScale = sizableWidth / this._centre.getContentSize().width;
129-
var verticalScale = sizableHeight / this._centre.getContentSize().height;
130-
this._centre.setScaleX(horizontalScale);
131-
this._centre.setScaleY(verticalScale);
132-
var rescaledWidth = this._centre.getContentSize().width * horizontalScale;
133-
var rescaledHeight = this._centre.getContentSize().height * verticalScale;
134-
135-
var leftWidth = this._bottomLeft.getContentSize().width;
136-
var bottomHeight = this._bottomLeft.getContentSize().height;
137-
138-
// Position corners
139-
this._bottomLeft.setPosition(cc.p(0, 0));
140-
this._bottomRight.setPosition(cc.p(leftWidth + rescaledWidth, 0));
141-
this._topLeft.setPosition(cc.p(0, bottomHeight + rescaledHeight));
142-
this._topRight.setPosition(cc.p(leftWidth + rescaledWidth, bottomHeight + rescaledHeight));
143-
144-
// Scale and position borders
145-
this._left.setPosition(cc.p(0, bottomHeight));
146-
this._left.setScaleY(verticalScale);
147-
this._right.setPosition(cc.p(leftWidth + rescaledWidth, bottomHeight));
148-
this._right.setScaleY(verticalScale);
149-
this._bottom.setPosition(cc.p(leftWidth, 0));
150-
this._bottom.setScaleX(horizontalScale);
151-
this._top.setPosition(cc.p(leftWidth, bottomHeight + rescaledHeight));
152-
this._top.setScaleX(horizontalScale);
153-
154-
// Position centre
155-
this._centre.setPosition(cc.p(leftWidth, bottomHeight));
156-
}
96+
var sizableWidth = size.width - this._topLeft.getContentSize().width - this._topRight.getContentSize().width;
97+
var sizableHeight = size.height - this._topLeft.getContentSize().height - this._bottomRight.getContentSize().height;
98+
var horizontalScale = sizableWidth / this._centre.getContentSize().width;
99+
var verticalScale = sizableHeight / this._centre.getContentSize().height;
100+
this._centre.setScaleX(horizontalScale);
101+
this._centre.setScaleY(verticalScale);
102+
var rescaledWidth = this._centre.getContentSize().width * horizontalScale;
103+
var rescaledHeight = this._centre.getContentSize().height * verticalScale;
104+
105+
var leftWidth = this._bottomLeft.getContentSize().width;
106+
var bottomHeight = this._bottomLeft.getContentSize().height;
107+
108+
// Position corners
109+
this._bottomLeft.setPosition(cc.p(0, 0));
110+
this._bottomRight.setPosition(cc.p(leftWidth + rescaledWidth, 0));
111+
this._topLeft.setPosition(cc.p(0, bottomHeight + rescaledHeight));
112+
this._topRight.setPosition(cc.p(leftWidth + rescaledWidth, bottomHeight + rescaledHeight));
113+
114+
// Scale and position borders
115+
this._left.setPosition(cc.p(0, bottomHeight));
116+
this._left.setScaleY(verticalScale);
117+
this._right.setPosition(cc.p(leftWidth + rescaledWidth, bottomHeight));
118+
this._right.setScaleY(verticalScale);
119+
this._bottom.setPosition(cc.p(leftWidth, 0));
120+
this._bottom.setScaleX(horizontalScale);
121+
this._top.setPosition(cc.p(leftWidth, bottomHeight + rescaledHeight));
122+
this._top.setScaleX(horizontalScale);
123+
124+
// Position centre
125+
this._centre.setPosition(cc.p(leftWidth, bottomHeight));
157126
},
158127

159128
ctor:function () {

samples

0 commit comments

Comments
 (0)