Skip to content

Commit c4626e1

Browse files
committed
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-js into ImproveBindings
Conflicts: frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp
2 parents 927f979 + e584dbb commit c4626e1

File tree

22 files changed

+123
-95
lines changed

22 files changed

+123
-95
lines changed

frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_auto_classes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,8 +2556,8 @@ bool JSB_cpSpace_constructor(JSContext *cx, uint32_t argc, jsval *vp)
25562556
{
25572557
JSB_PRECONDITION2(argc==0, cx, false, "Invalid number of arguments");
25582558
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
2559-
JSObject* jsobj = JS_NewObjectForConstructor(cx, JSB_cpSpace_class, args);
2560-
//JSObject *jsobj = JS_NewObject(cx, JSB_cpSpace_class, JS::RootedObject(cx, JSB_cpSpace_object), JS::NullPtr());
2559+
//JSObject* jsobj = JS_NewObjectForConstructor(cx, JSB_cpSpace_class, args);
2560+
JSObject *jsobj = JS_NewObject(cx, JSB_cpSpace_class, JS::RootedObject(cx, JSB_cpSpace_object), JS::NullPtr());
25612561
void* ret_val = cpSpaceNew( );
25622562

25632563
jsb_set_jsobject_for_proxy(jsobj, ret_val);

frameworks/js-bindings/bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ bool JSB_CCPhysicsDebugNode_constructor(JSContext *cx, uint32_t argc, jsval *vp)
273273
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
274274
typeClass = typeMapIter->second;
275275
CCASSERT(typeClass, "The value is null.");
276-
JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, typeClass->jsclass, args));
276+
//JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, typeClass->jsclass, args));
277+
JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)));
277278
args.rval().set(OBJECT_TO_JSVAL(obj));
278279
// link the native object with the javascript object
279280
js_proxy_t* p = jsb_new_proxy(cobj, obj);
@@ -495,7 +496,8 @@ bool JSPROXY_CCPhysicsSprite_constructor(JSContext *cx, uint32_t argc, jsval *vp
495496
CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
496497
typeClass = typeMapIter->second;
497498
CCASSERT(typeClass, "The value is null.");
498-
JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, typeClass->jsclass, args));
499+
//JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, typeClass->jsclass, args));
500+
JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, JS::RootedObject(cx, typeClass->proto), JS::RootedObject(cx, typeClass->parentProto)));
499501
args.rval().set(OBJECT_TO_JSVAL(obj));
500502
// link the native object with the javascript object
501503
js_proxy_t* p = jsb_new_proxy(cobj, obj);

frameworks/js-bindings/bindings/manual/cocos2d_specifics.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5165,8 +5165,11 @@ void register_cocos2dx_js_core(JSContext* cx, JS::HandleObject global)
51655165
JS::RootedObject proto(cx, jsb_cocos2d_SAXParser_prototype);
51665166
JS_DefineFunction(cx, proto, "parse", js_PlistParser_parse, 1, JSPROP_READONLY | JSPROP_PERMANENT);
51675167

5168+
JS_GetProperty(cx, ccObj, "Label", &tmpVal);
5169+
tmpObj = tmpVal.toObjectOrNull();
5170+
JS_DefineFunction(cx, tmpObj, "createWithTTF", js_cocos2dx_Label_createWithTTF, 4, JSPROP_READONLY | JSPROP_PERMANENT);
5171+
51685172
JS::RootedObject labelProto(cx, jsb_cocos2d_Label_prototype);
5169-
JS_DefineFunction(cx, labelProto, "createWithTTF", js_cocos2dx_Label_createWithTTF, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT);
51705173
JS_DefineFunction(cx, labelProto, "setTTFConfig", js_cocos2dx_Label_setTTFConfig, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);
51715174

51725175
JS::RootedObject nodeGridProto(cx, jsb_cocos2d_NodeGrid_prototype);

frameworks/js-bindings/bindings/manual/js_manual_conversions.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ JSStringWrapper::JSStringWrapper(jsval val, JSContext* cx/* = NULL*/)
5050

5151
JSStringWrapper::~JSStringWrapper()
5252
{
53-
#if(CC_TARGET_PLATFORM != CC_PLATFORM_WP8)
54-
CC_SAFE_DELETE_ARRAY(_buffer); //XXX: why break on wp8?
55-
#endif
53+
JS_free(ScriptingCore::getInstance()->getGlobalContext(), (void*)_buffer);
5654
}
5755

5856
void JSStringWrapper::set(jsval val, JSContext* cx)
@@ -83,7 +81,11 @@ void JSStringWrapper::set(JSString* str, JSContext* cx)
8381

8482
// _buffer = cc_utf16_to_utf8(pStrUTF16, -1, NULL, NULL);
8583

84+
#if(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
8685
_buffer = JS_EncodeString(cx, str);
86+
#else
87+
_buffer = JS_EncodeStringToUTF8(cx, JS::RootedString(cx, str));
88+
#endif
8789
}
8890

8991
const char* JSStringWrapper::get()
@@ -1799,7 +1801,8 @@ jsval c_string_to_jsval(JSContext* cx, const char* v, size_t length /* = -1 */)
17991801
jsval ret = JSVAL_NULL;
18001802

18011803
//XXX: JS_NewUCStringCopyN can't be resolved on Win32
1802-
/* int utf16_size = 0;
1804+
#if(CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
1805+
int utf16_size = 0;
18031806
jschar* strUTF16 = (jschar*)cc_utf8_to_utf16(v, (int)length, &utf16_size);
18041807

18051808
if (strUTF16 && utf16_size > 0) {
@@ -1809,12 +1812,13 @@ jsval c_string_to_jsval(JSContext* cx, const char* v, size_t length /* = -1 */)
18091812
}
18101813
delete[] strUTF16;
18111814
}
1812-
*/
1815+
#else
18131816
JSString* str = JS_NewStringCopyN(cx, v, length);
18141817
if(str)
18151818
{
18161819
ret = STRING_TO_JSVAL(str);
18171820
}
1821+
#endif
18181822
return ret;
18191823
}
18201824

frameworks/js-bindings/bindings/manual/network/jsb_websocket.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, j
252252
JSB_PRECONDITION2( ok, cx, false, "Error processing arguments");
253253
} while (0);
254254

255-
//JS::RootedObject obj(cx, JS_NewObject(cx, js_cocos2dx_websocket_class, JS::RootedObject(cx, js_cocos2dx_websocket_prototype), JS::NullPtr()));
256-
JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, js_cocos2dx_websocket_class, args));
255+
JS::RootedObject obj(cx, JS_NewObject(cx, js_cocos2dx_websocket_class, JS::RootedObject(cx, js_cocos2dx_websocket_prototype), JS::NullPtr()));
256+
//JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, js_cocos2dx_websocket_class, args));
257257

258258
WebSocket* cobj = new WebSocket();
259259
JSB_WebSocketDelegate* delegate = new JSB_WebSocketDelegate();

frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-2.x.js

Lines changed: 75 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
// WIDGET //
210210
////////////
211211

212-
parser.widgetAttributes = function(widget, json){
212+
parser.widgetAttributes = function(widget, json) {
213213
widget.setCascadeColorEnabled(true);
214214
widget.setCascadeOpacityEnabled(true);
215215

@@ -219,33 +219,33 @@
219219
setContentSize(widget, json["Size"]);
220220

221221
var name = json["Name"];
222-
if(name)
222+
if (name)
223223
widget.setName(name);
224224

225225
var actionTag = json["ActionTag"] || 0;
226226
widget.setActionTag(actionTag);
227227
widget.setUserObject(new ccs.ActionTimelineData(actionTag));
228228

229229
var rotationSkewX = json["RotationSkewX"];
230-
if(rotationSkewX)
230+
if (rotationSkewX)
231231
widget.setRotationX(rotationSkewX);
232232

233233
var rotationSkewY = json["RotationSkewY"];
234-
if(rotationSkewY)
234+
if (rotationSkewY)
235235
widget.setRotationY(rotationSkewY);
236236

237237
//var rotation = json["Rotation"];
238238

239239
var flipX = json["FlipX"];
240-
if(flipX)
240+
if (flipX)
241241
widget.setFlippedX(true);
242242

243243
var flipY = json["FlipY"];
244-
if(flipY)
244+
if (flipY)
245245
widget.setFlippedY(true);
246246

247247
var zOrder = json["zOrder"];
248-
if(zOrder != null)
248+
if (zOrder != null)
249249
widget.setLocalZOrder(zOrder);
250250

251251
//var visible = json["Visible"];
@@ -254,7 +254,7 @@
254254
widget.setVisible(visible);
255255

256256
var alpha = json["Alpha"];
257-
if(alpha != null)
257+
if (alpha != null)
258258
widget.setOpacity(alpha);
259259

260260
widget.setTag(json["Tag"] || 0);
@@ -265,100 +265,97 @@
265265
// -- var frameEvent = json["FrameEvent"];
266266

267267
var callBackType = json["CallBackType"];
268-
if(callBackType != null)
268+
if (callBackType != null)
269269
widget.setCallbackType(callBackType);
270270

271271
var callBackName = json["CallBackName"];
272-
if(callBackName)
272+
if (callBackName)
273273
widget.setCallbackName(callBackName);
274274

275275
var position = json["Position"];
276-
if(position != null)
276+
if (position != null)
277277
widget.setPosition(position["X"] || 0, position["Y"] || 0);
278278

279279
var scale = json["Scale"];
280-
if(scale != null){
280+
if (scale != null) {
281281
var scaleX = getParam(scale["ScaleX"], 1);
282282
var scaleY = getParam(scale["ScaleY"], 1);
283283
widget.setScaleX(scaleX);
284284
widget.setScaleY(scaleY);
285285
}
286286

287287
var anchorPoint = json["AnchorPoint"];
288-
if(anchorPoint != null)
288+
if (anchorPoint != null)
289289
widget.setAnchorPoint(anchorPoint["ScaleX"] || 0, anchorPoint["ScaleY"] || 0);
290290

291291
var color = json["CColor"];
292-
if(color != null)
292+
if (color != null)
293293
widget.setColor(getColor(color));
294294

295-
if(widget instanceof ccui.Layout){
296-
var layoutComponent = ccui.LayoutComponent.bindLayoutComponent(widget);
297-
298-
var positionXPercentEnabled = json["PositionPercentXEnable"] || false;
299-
var positionYPercentEnabled = json["PositionPercentYEnable"] || false;
300-
var positionXPercent = 0,
301-
positionYPercent = 0,
302-
PrePosition = json["PrePosition"];
303-
if(PrePosition != null){
304-
positionXPercent = PrePosition["X"] || 0;
305-
positionYPercent = PrePosition["Y"] || 0;
306-
}
307-
var sizeXPercentEnable = json["PercentWidthEnable"] || false;
308-
var sizeYPercentEnable = json["PercentHeightEnable"] || false;
309-
var sizeXPercent = 0,
310-
sizeYPercent = 0,
311-
PreSize = json["PreSize"];
312-
if(PrePosition != null){
313-
sizeXPercent = PreSize["X"] || 0;
314-
sizeYPercent = PreSize["Y"] || 0;
315-
}
316-
var stretchHorizontalEnabled = json["StretchWidthEnable"] || false;
317-
var stretchVerticalEnabled = json["StretchHeightEnable"] || false;
318-
var horizontalEdge = json["HorizontalEdge"];// = ccui.LayoutComponent.horizontalEdge.LEFT;
319-
var verticalEdge = json["VerticalEdge"]; // = ccui.LayoutComponent.verticalEdge.TOP;
320-
var leftMargin = json["LeftMargin"] || 0;
321-
var rightMargin = json["RightMargin"] || 0;
322-
var topMargin = json["TopMargin"] || 0;
323-
var bottomMargin = json["BottomMargin"] || 0;
324-
325-
layoutComponent.setPositionPercentXEnabled(positionXPercentEnabled);
326-
layoutComponent.setPositionPercentYEnabled(positionYPercentEnabled);
327-
layoutComponent.setPositionPercentX(positionXPercent);
328-
layoutComponent.setPositionPercentY(positionYPercent);
329-
layoutComponent.setPercentWidthEnabled(sizeXPercentEnable);
330-
layoutComponent.setPercentHeightEnabled(sizeYPercentEnable);
331-
layoutComponent.setPercentWidth(sizeXPercent);
332-
layoutComponent.setPercentHeight(sizeYPercent);
333-
layoutComponent.setStretchWidthEnabled(stretchHorizontalEnabled);
334-
layoutComponent.setStretchHeightEnabled(stretchVerticalEnabled);
335-
336-
var horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.NONE;
337-
if (horizontalEdge == "LeftEdge"){
338-
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.LEFT;
339-
}else if (horizontalEdge == "RightEdge"){
340-
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.RIGHT;
341-
}else if (horizontalEdge == "BothEdge"){
342-
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.CENTER;
343-
}
344-
layoutComponent.setHorizontalEdge(horizontalEdgeType);
345-
346-
var verticalEdgeType = ccui.LayoutComponent.verticalEdge.NONE;
347-
if (verticalEdge == "TopEdge"){
348-
verticalEdgeType = ccui.LayoutComponent.verticalEdge.TOP;
349-
}else if (verticalEdge == "BottomEdge"){
350-
verticalEdgeType = ccui.LayoutComponent.verticalEdge.BOTTOM;
351-
}else if (verticalEdge == "BothEdge"){
352-
verticalEdgeType = ccui.LayoutComponent.verticalEdge.CENTER;
353-
}
354-
layoutComponent.setVerticalEdge(verticalEdgeType);
295+
var layoutComponent = ccui.LayoutComponent.bindLayoutComponent(widget);
355296

356-
layoutComponent.setTopMargin(topMargin);
357-
layoutComponent.setBottomMargin(bottomMargin);
358-
layoutComponent.setLeftMargin(leftMargin);
359-
layoutComponent.setRightMargin(rightMargin);
297+
var positionXPercentEnabled = json["PositionPercentXEnable"] || false;
298+
var positionYPercentEnabled = json["PositionPercentYEnable"] || false;
299+
var positionXPercent = 0,
300+
positionYPercent = 0,
301+
PrePosition = json["PrePosition"];
302+
if (PrePosition != null) {
303+
positionXPercent = PrePosition["X"] || 0;
304+
positionYPercent = PrePosition["Y"] || 0;
305+
}
306+
var sizeXPercentEnable = json["PercentWidthEnable"] || false;
307+
var sizeYPercentEnable = json["PercentHeightEnable"] || false;
308+
var sizeXPercent = 0,
309+
sizeYPercent = 0,
310+
PreSize = json["PreSize"];
311+
if (PrePosition != null) {
312+
sizeXPercent = PreSize["X"] || 0;
313+
sizeYPercent = PreSize["Y"] || 0;
314+
}
315+
var stretchHorizontalEnabled = json["StretchWidthEnable"] || false;
316+
var stretchVerticalEnabled = json["StretchHeightEnable"] || false;
317+
var horizontalEdge = json["HorizontalEdge"];// = ccui.LayoutComponent.horizontalEdge.LEFT;
318+
var verticalEdge = json["VerticalEdge"]; // = ccui.LayoutComponent.verticalEdge.TOP;
319+
var leftMargin = json["LeftMargin"] || 0;
320+
var rightMargin = json["RightMargin"] || 0;
321+
var topMargin = json["TopMargin"] || 0;
322+
var bottomMargin = json["BottomMargin"] || 0;
323+
324+
layoutComponent.setPositionPercentXEnabled(positionXPercentEnabled);
325+
layoutComponent.setPositionPercentYEnabled(positionYPercentEnabled);
326+
layoutComponent.setPositionPercentX(positionXPercent);
327+
layoutComponent.setPositionPercentY(positionYPercent);
328+
layoutComponent.setPercentWidthEnabled(sizeXPercentEnable);
329+
layoutComponent.setPercentHeightEnabled(sizeYPercentEnable);
330+
layoutComponent.setPercentWidth(sizeXPercent);
331+
layoutComponent.setPercentHeight(sizeYPercent);
332+
layoutComponent.setStretchWidthEnabled(stretchHorizontalEnabled);
333+
layoutComponent.setStretchHeightEnabled(stretchVerticalEnabled);
334+
335+
var horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.NONE;
336+
if (horizontalEdge == "LeftEdge") {
337+
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.LEFT;
338+
} else if (horizontalEdge == "RightEdge") {
339+
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.RIGHT;
340+
} else if (horizontalEdge == "BothEdge") {
341+
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.CENTER;
342+
}
343+
layoutComponent.setHorizontalEdge(horizontalEdgeType);
344+
345+
var verticalEdgeType = ccui.LayoutComponent.verticalEdge.NONE;
346+
if (verticalEdge == "TopEdge") {
347+
verticalEdgeType = ccui.LayoutComponent.verticalEdge.TOP;
348+
} else if (verticalEdge == "BottomEdge") {
349+
verticalEdgeType = ccui.LayoutComponent.verticalEdge.BOTTOM;
350+
} else if (verticalEdge == "BothEdge") {
351+
verticalEdgeType = ccui.LayoutComponent.verticalEdge.CENTER;
360352
}
353+
layoutComponent.setVerticalEdge(verticalEdgeType);
361354

355+
layoutComponent.setTopMargin(topMargin);
356+
layoutComponent.setBottomMargin(bottomMargin);
357+
layoutComponent.setLeftMargin(leftMargin);
358+
layoutComponent.setRightMargin(rightMargin);
362359
};
363360

364361
/**

samples/js-tests/project/proj.wp8-xaml/js-tests/js-tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
</Compile>
109109
</ItemGroup>
110110
<ItemGroup>
111+
<None Include="Assets\Resources\fonts\arialuni.ttf">
112+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
113+
</None>
111114
<None Include="Properties\AppManifest.xml" />
112115
<None Include="Properties\WMAppManifest.xml">
113116
<SubType>Designer</SubType>

samples/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ var UIListViewTest_Vertical = UIScene.extend({
3030
var background = this._widget.getChildByName("background_Panel");
3131
var backgroundSize = background.getContentSize();
3232

33+
this._topDisplayLabel.setString("Scroll listview is disabled.");
34+
this._topDisplayLabel.x = widgetSize.width / 2.0;
35+
this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5;
36+
3337
this._array = [];
3438
for (var i = 0; i < 20; ++i) {
3539
this._array.push("item_" + i);

samples/js-tests/src/LabelTest/LabelTest.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,13 +1331,13 @@ var LabelTTFChinese = AtlasDemo.extend({
13311331
//----start21----ctor
13321332
this._super();
13331333
var size = director.getWinSize();
1334-
var label = new cc.LabelTTF("中国", "Microsoft Yahei", 30);
1334+
var label = new cc.LabelTTF("中国", (cc.sys.os == cc.sys.OS_WP8) ? "fonts/arialuni.ttf" : "Microsoft Yahei", 30);
13351335
label.x = size.width / 2;
13361336
label.y = size.height / 3 * 2;
13371337
this.addChild(label);
13381338

13391339
// Test UTF8 string from native to jsval.
1340-
var label2 = new cc.LabelTTF("string from native:"+label.getString(), "Microsoft Yahei", 30);
1340+
var label2 = new cc.LabelTTF("string from native:"+label.getString(), (cc.sys.os == cc.sys.OS_WP8) ? "fonts/arialuni.ttf" : "Microsoft Yahei", 30);
13411341
label2.x = size.width / 2;
13421342
label2.y = size.height / 3;
13431343
this.addChild(label2);
@@ -1941,6 +1941,8 @@ var WrapAlgorithmTest = AtlasDemo.extend({
19411941
LabelTTF.boundingWidth = 120;
19421942
LabelTTF.boundingHeight = 0;
19431943
LabelTTF.enableStroke(cc.color(0, 0, 0, 1), 3.0);
1944+
if(cc.sys.os == cc.sys.OS_WP8)
1945+
LabelTTF.setFontName("fonts/arialuni.ttf");
19441946
self.addChild(LabelTTF);
19451947
});
19461948

@@ -1963,6 +1965,8 @@ var WrapAlgorithmTest = AtlasDemo.extend({
19631965
LabelTTF.boundingWidth = 3;
19641966
LabelTTF.boundingHeight = 0;
19651967
LabelTTF.enableStroke(cc.color(0, 0, 0, 1), 3.0);
1968+
if(cc.sys.os == cc.sys.OS_WP8)
1969+
LabelTTF.setFontName("fonts/arialuni.ttf");
19661970
self.addChild(LabelTTF);
19671971
});
19681972

@@ -1981,6 +1985,8 @@ var WrapAlgorithmTest = AtlasDemo.extend({
19811985
LabelTTF.boundingWidth = 90;
19821986
LabelTTF.boundingHeight = 0;
19831987
LabelTTF.enableStroke(cc.color(0, 0, 0, 1), 3.0);
1988+
if(cc.sys.os == cc.sys.OS_WP8)
1989+
LabelTTF.setFontName("fonts/arialuni.ttf");
19841990
self.addChild(LabelTTF);
19851991
});
19861992

0 commit comments

Comments
 (0)