From b58a854dde42058a2e0c032a876b59000afe3dc7 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Thu, 15 Jun 2017 11:29:55 +0800 Subject: [PATCH 1/6] reduce a bit memory footprint --- cocos2d/core/platform/CCAssetLibrary.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/platform/CCAssetLibrary.js b/cocos2d/core/platform/CCAssetLibrary.js index e4869d64f3..df21512950 100644 --- a/cocos2d/core/platform/CCAssetLibrary.js +++ b/cocos2d/core/platform/CCAssetLibrary.js @@ -46,6 +46,13 @@ function isScene (asset) { return asset && (asset.constructor === cc.SceneAsset || asset instanceof cc.Scene); } +// types + +function RawAssetEntry (url, type) { + this.url = url; + this.type = type; +} + // publics var AssetLibrary = { @@ -290,10 +297,7 @@ var AssetLibrary = { cc.error('Cannot get', typeId); continue; } - _uuidToRawAsset[uuid] = { - url: mountPoint + '/' + url, - type: type, - }; + _uuidToRawAsset[uuid] = new RawAssetEntry(mountPoint + '/' + url, type); // init resources if (mountPoint === 'assets' && url.startsWith(RES_DIR)) { if (cc.isChildClassOf(type, Asset)) { From dbb7519f50045aca3c12ccc2c040b58743c4837b Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 20 Jun 2017 10:39:31 +0800 Subject: [PATCH 2/6] tweaks --- cocos2d/core/platform/deserialize.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/platform/deserialize.js b/cocos2d/core/platform/deserialize.js index b5794067b4..9b85492993 100644 --- a/cocos2d/core/platform/deserialize.js +++ b/cocos2d/core/platform/deserialize.js @@ -421,8 +421,7 @@ var _Deserializer = (function () { // var propName = props[p]; // var rawType = attrs[propName + RAW_TYPE]; // if (!rawType) { - // if (((CC_EDITOR && self._ignoreEditorOnly) || (!CC_EDITOR && CC_DEV && !CC_TEST)) - // && attrs[propName + EDITOR_ONLY]) { + // if (((CC_EDITOR && self._ignoreEditorOnly) || CC_PREVIEW) && attrs[propName + EDITOR_ONLY]) { // var mayUsedInPersistRoot = (cc.Node.isNode(obj) && propName === '_id'); // if ( !mayUsedInPersistRoot ) { // continue; // skip editor only if in preview @@ -486,8 +485,7 @@ var _Deserializer = (function () { var propNameLiteral; var rawType = attrs[propName + RAW_TYPE]; if (!rawType) { - if (((CC_EDITOR && self._ignoreEditorOnly) || (!CC_EDITOR && CC_DEV && !CC_TEST)) - && attrs[propName + EDITOR_ONLY]) { + if ((CC_PREVIEW || (CC_EDITOR && self._ignoreEditorOnly)) && attrs[propName + EDITOR_ONLY]) { var mayUsedInPersistRoot = (propName === '_id' && cc.isChildClassOf(klass, cc.Node)); if (!mayUsedInPersistRoot) { continue; // skip editor only if in preview @@ -593,8 +591,8 @@ var _Deserializer = (function () { JS.value(klass, '__deserialize__', deserialize, true); } deserialize(self, obj, serialized, klass, target); - // if preview or build - if (CC_DEV && (!CC_EDITOR || self._ignoreEditorOnly)) { + // if preview or build worker + if (CC_PREVIEW || (CC_EDITOR && self._ignoreEditorOnly)) { if (klass === cc._PrefabInfo && !obj.sync) { unlinkUnusedPrefab(self, serialized, obj); } From d70eea4e006239196210d7c2fcf6a6462a40156c Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 21 Jun 2017 10:55:00 +0800 Subject: [PATCH 3/6] remove ccui visual test --- .../src/GUITest/UIButtonTest/UIButtonTest.js | 581 -------------- .../GUITest/UICheckBoxTest/UICheckBoxTest.js | 120 --- .../src/GUITest/UIFocusTest/UIFocusTest.js | 550 -------------- .../UIImageViewTest/UIImageViewTest.js | 171 ----- .../UILabelAtlasTest/UILabelAtlasTest.js | 45 -- .../UILabelBMFontTest/UILabelBMFontTest.js | 46 -- .../src/GUITest/UILabelTest/UILabelTest.js | 102 --- .../src/GUITest/UILayoutTest/UILayoutTest.js | 536 ------------- .../GUITest/UIListViewTest/UIListViewTest.js | 334 --------- .../UILoadingBarTest/UILoadingBarTest.js | 170 ----- .../UINodeContainerTest.js | 49 -- .../GUITest/UIPageViewTest/UIPageViewTest.js | 570 -------------- .../GUITest/UIRichTextTest/UIRichTextTest.js | 91 --- .../UIS9NinePatchTest/UIS9NinePatchTest.js | 73 -- test/visual-tests/src/GUITest/UIScene.js | 102 --- .../src/GUITest/UISceneManager.js | 709 ------------------ .../UIScrollViewTest/UIScrollViewTest.js | 598 --------------- .../src/GUITest/UISliderTest/UISliderTest.js | 175 ----- .../UITextFieldTest/UITextFieldTest.js | 339 --------- .../src/GUITest/UITextTest/UITextTest.js | 182 ----- .../GUITest/UIWebViewTest/UIWebViewTest.js | 107 --- .../src/GUITest/UIWebViewTest/webview.html | 21 - .../src/GUITest/UIWebViewTest/webview2.html | 21 - 23 files changed, 5692 deletions(-) delete mode 100644 test/visual-tests/src/GUITest/UIButtonTest/UIButtonTest.js delete mode 100644 test/visual-tests/src/GUITest/UICheckBoxTest/UICheckBoxTest.js delete mode 100644 test/visual-tests/src/GUITest/UIFocusTest/UIFocusTest.js delete mode 100644 test/visual-tests/src/GUITest/UIImageViewTest/UIImageViewTest.js delete mode 100644 test/visual-tests/src/GUITest/UILabelAtlasTest/UILabelAtlasTest.js delete mode 100644 test/visual-tests/src/GUITest/UILabelBMFontTest/UILabelBMFontTest.js delete mode 100644 test/visual-tests/src/GUITest/UILabelTest/UILabelTest.js delete mode 100644 test/visual-tests/src/GUITest/UILayoutTest/UILayoutTest.js delete mode 100644 test/visual-tests/src/GUITest/UIListViewTest/UIListViewTest.js delete mode 100644 test/visual-tests/src/GUITest/UILoadingBarTest/UILoadingBarTest.js delete mode 100644 test/visual-tests/src/GUITest/UINodeContainerTest/UINodeContainerTest.js delete mode 100644 test/visual-tests/src/GUITest/UIPageViewTest/UIPageViewTest.js delete mode 100644 test/visual-tests/src/GUITest/UIRichTextTest/UIRichTextTest.js delete mode 100644 test/visual-tests/src/GUITest/UIS9NinePatchTest/UIS9NinePatchTest.js delete mode 100644 test/visual-tests/src/GUITest/UIScene.js delete mode 100644 test/visual-tests/src/GUITest/UISceneManager.js delete mode 100644 test/visual-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js delete mode 100644 test/visual-tests/src/GUITest/UISliderTest/UISliderTest.js delete mode 100644 test/visual-tests/src/GUITest/UITextFieldTest/UITextFieldTest.js delete mode 100644 test/visual-tests/src/GUITest/UITextTest/UITextTest.js delete mode 100644 test/visual-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js delete mode 100644 test/visual-tests/src/GUITest/UIWebViewTest/webview.html delete mode 100644 test/visual-tests/src/GUITest/UIWebViewTest/webview2.html diff --git a/test/visual-tests/src/GUITest/UIButtonTest/UIButtonTest.js b/test/visual-tests/src/GUITest/UIButtonTest/UIButtonTest.js deleted file mode 100644 index 140499718f..0000000000 --- a/test/visual-tests/src/GUITest/UIButtonTest/UIButtonTest.js +++ /dev/null @@ -1,581 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var UIButtonTest = UIMainLayer.extend({ - _button:null, - init: function () { - if (this._super()) { - //init text - this._topDisplayLabel.setString("No Event"); - this._bottomDisplayLabel.setString("Button"); - - var widgetSize = this._widget.getContentSize(); - // Create the button - var button = this._button = new ccui.Button(); - button.setTouchEnabled(true); - button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", ""); - button.x = widgetSize.width / 2.0; - button.y = widgetSize.height / 2.0; - button.addTouchEventListener(this.touchEvent, this); - this._mainNode.addChild(button); - - var label = new cc.LabelTTF("setOpacity", "Arial", 25); - var menuItem = new cc.MenuItemLabel(label,this.setOpacityTest,this); - var menu = new cc.Menu(menuItem); - menu.x = 0; - menu.y = 0; - menuItem.x = widgetSize.width-100; - menuItem.y = 270; - this._mainNode.addChild(menu); - return true; - } - return false; - }, - setOpacityTest:function(){ - var button = this._button; - var opacity = (button._realOpacity===255? 100:255); - button.setOpacity(opacity); - }, - touchEvent: function (sender, type) { - switch (type) { - case ccui.Widget.TOUCH_BEGAN: - this._topDisplayLabel.setString("Touch Down"); - break; - - case ccui.Widget.TOUCH_MOVED: - this._topDisplayLabel.setString("Touch Move"); - break; - - case ccui.Widget.TOUCH_ENDED: - this._topDisplayLabel.setString("Touch Up"); - break; - - case ccui.Widget.TOUCH_CANCELED: - this._topDisplayLabel.setString("Touch Cancelled"); - break; - - default: - break; - } - } -}); -var UIButtonTest_Scale9 = UIMainLayer.extend({ - init: function () { - if (this._super()) { - //init text - this._topDisplayLabel.setString("No Event"); - this._bottomDisplayLabel.setString("Button scale9 render"); - - // Create the button - var button = new ccui.Button(); - button.setTouchEnabled(true); - button.setScale9Enabled(true); - button.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", ""); - button.x = this._widget.width / 2.0; - button.y = this._widget.height / 2.0; - button.setContentSize(cc.size(150, 48)); - button.addTouchEventListener(this.touchEvent ,this); - this._mainNode.addChild(button); - - return true; - } - return false; - }, - - touchEvent: function (sender, type) { - switch (type) { - case ccui.Widget.TOUCH_BEGAN: - this._topDisplayLabel.setString("Touch Down"); - break; - case ccui.Widget.TOUCH_MOVED: - this._topDisplayLabel.setString("Touch Move"); - break; - case ccui.Widget.TOUCH_ENDED: - this._topDisplayLabel.setString("Touch Up"); - break; - case ccui.Widget.TOUCH_CANCELED: - this._topDisplayLabel.setString("Touch Cancelled"); - break; - - default: - break; - } - } -}); - -var UIButtonTest_PressedAction = UIMainLayer.extend({ - init: function () { - if (this._super()) { - //init text - this._topDisplayLabel.setString("No Event"); - this._bottomDisplayLabel.setString("Button Pressed Action"); - - var widgetSize = this._widget.getContentSize(); - // Create the button - var button = new ccui.Button(); - button.setTouchEnabled(true); - button.setPressedActionEnabled(true); - button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", ""); - button.x = widgetSize.width / 2; - button.y = widgetSize.height / 2; - button.addTouchEventListener(this.touchEvent ,this); - this._mainNode.addChild(button); - return true; - } - return false; - }, - - touchEvent: function (sender, type) { - switch (type) { - case ccui.Widget.TOUCH_BEGAN: - this._topDisplayLabel.setString("Touch Down"); - break; - case ccui.Widget.TOUCH_MOVED: - this._topDisplayLabel.setString("Touch Move"); - break; - case ccui.Widget.TOUCH_ENDED: - this._topDisplayLabel.setString("Touch Up"); - break; - case ccui.Widget.TOUCH_CANCELED: - this._topDisplayLabel.setString("Touch Cancelled"); - break; - default: - break; - } - } -}); - -var UIButtonTest_Title = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("No Event"); - this._bottomDisplayLabel.setString("Button with title"); - - // Create the text button - var textButton = new ccui.Button(); - textButton.setTouchEnabled(true); - textButton.loadTextures("ccs-res/cocosui/backtotopnormal.png", "ccs-res/cocosui/backtotoppressed.png", ""); - textButton.setTitleText("Title Button"); - textButton.x = widgetSize.width / 2.0; - textButton.y = widgetSize.height / 2.0; - textButton.addTouchEventListener(this.touchEvent ,this); - this._mainNode.addChild(textButton); - - return true; - } - return false; - }, - - touchEvent: function (sender, type) { - switch (type) { - case ccui.Widget.TOUCH_BEGAN: - this._topDisplayLabel.setString("Touch Down"); - break; - case ccui.Widget.TOUCH_MOVED: - this._topDisplayLabel.setString("Touch Move"); - break; - case ccui.Widget.TOUCH_ENDED: - this._topDisplayLabel.setString("Touch Up"); - break; - case ccui.Widget.TOUCH_CANCELED: - this._topDisplayLabel.setString("Touch Cancelled"); - break; - default: - break; - } - } -}); - -var UIButtonTestRemoveSelf = UIMainLayer.extend({ - init: function () { - if (this._super()) { - //init text - this._topDisplayLabel.setString("No Event"); - this._bottomDisplayLabel.setString("Remove Self in the Button's Callback shouldn't cause crash!"); - this._bottomDisplayLabel.setFontSize(15); - - var widgetSize = this._widget.getContentSize(); - - var layout = new ccui.Layout(); - layout.setContentSize(widgetSize.width * 0.6, widgetSize.height * 0.6); - layout.setBackGroundColor(cc.Color.GREEN); - layout.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID); - layout.setBackGroundColorOpacity(100); - layout.setPosition(widgetSize.width/2, widgetSize.height/2); - layout.setAnchorPoint(0.5, 0.5); - layout.setTag(12); - this._mainNode.addChild(layout); - - // Create the button - var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", - "ccs-res/cocosui/animationbuttonpressed.png"); - button.setPosition(layout.width / 2.0, layout.height / 2.0); - button.addTouchEventListener(this.touchEvent, this); - layout.addChild(button); - return true; - } - return false; - }, - - touchEvent: function(sender, type){ - switch (type) { - case ccui.Widget.TOUCH_BEGAN: - this._topDisplayLabel.setString("Touch Down"); - break; - - case ccui.Widget.TOUCH_MOVED: - this._topDisplayLabel.setString("Touch Move"); - break; - - case ccui.Widget.TOUCH_ENDED: - this._topDisplayLabel.setString("Touch Up"); - var layout = this._mainNode.getChildByTag(12); - layout.removeFromParent(true); - break; - - case ccui.Widget.TOUCH_CANCELED: - this._topDisplayLabel.setString("Touch Cancelled"); - break; - - default: - break; - } - } -}); - -var UIButtonTestSwitchScale9 = UIMainLayer.extend({ - init: function(){ - if (this._super()){ - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the button events will be displayed - this._topDisplayLabel.setString("No Event"); - this._bottomDisplayLabel.setString(""); - - // Create the button - var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", - "ccs-res/cocosui/animationbuttonpressed.png"); - button.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0); - button.addTouchEventListener(this.touchEvent, this); - button.setTitleText("Button Title"); - button.ignoreContentAdaptWithSize(false); - - this._mainNode.addChild(button); - return true; - } - return false; - }, - - touchEvent: function(sender, type){ - switch (type) { - case ccui.Widget.TOUCH_BEGAN: - this._topDisplayLabel.setString("Touch Down"); - break; - - case ccui.Widget.TOUCH_MOVED: - this._topDisplayLabel.setString("Touch Move"); - break; - - case ccui.Widget.TOUCH_ENDED: - this._topDisplayLabel.setString("Touch Up"); - sender.setScale9Enabled(!sender.isScale9Enabled()); - sender.setContentSize(200,100); - break; - - case ccui.Widget.TOUCH_CANCELED: - this._topDisplayLabel.setString("Touch Cancelled"); - break; - - default: - break; - } - } -}); - -var UIButtonTestZoomScale = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the button events will be displayed - this._topDisplayLabel.setString("Zoom Scale: -0.5"); - this._bottomDisplayLabel.setString(""); - - // Create the button - var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - button.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 ); - button.setPressedActionEnabled(true); - button.addClickEventListener(function () { - cc.log("Button clicked, position = (" + button.x + ", " + button.y + ")"); - }); - button.setName("button"); - this._mainNode.addChild(button); - button.setZoomScale(-0.5); - - var slider = new ccui.Slider(); - slider.loadBarTexture("ccs-res/cocosui/sliderTrack.png"); - slider.loadSlidBallTextures("ccs-res/cocosui/sliderThumb.png", "ccs-res/cocosui/sliderThumb.png", ""); - slider.loadProgressBarTexture("ccs-res/cocosui/sliderProgress.png"); - slider.setPosition(widgetSize.width / 2.0 , widgetSize.height / 2.0 - 50); - slider.addEventListener(this.sliderEvent, this); - slider.setPercent(button.getZoomScale() * 100); - this._mainNode.addChild(slider); - return true; - } - return false; - }, - - sliderEvent: function(slider, type){ - if (type == ccui.Slider.EVENT_PERCENT_CHANGED){ - var percent = slider.getPercent(); - var btn = this._mainNode.getChildByName("button"); - var zoomScale = percent * 0.01; - btn.setZoomScale(zoomScale); - this._topDisplayLabel.setString("Zoom Scale: "+ zoomScale.toFixed(2)); - } - } -}); - -var UIButtonTextOnly = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - // Add a label in which the button events will be displayed - this._topDisplayLabel.setString("Text Only Button"); - this._bottomDisplayLabel.setString(""); - - // Create the button - var button = new ccui.Button(); - button.setPosition(0.5 * this.width, 0.5 * this.height); - - button.setTitleText("PLAY GAME"); - cc.log("content size should be greater than 0: width = %f, height = %f", button.width, button.height); - button.setZoomScale(0.3); - button.setPressedActionEnabled(true); - button.addClickEventListener(function () { - cc.log("clicked!"); - }); - this.addChild(button); - return true; - } - return false; - } -}); - -var UIButtonIgnoreContentSizeTest = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the button events will be displayed - this._topDisplayLabel.setString("Button IgnoreContent Size Test"); - this._bottomDisplayLabel.setString(""); - - // Create the button - var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - button.ignoreContentAdaptWithSize(false); - button.setContentSize(200,100); - button.setPosition(0.3 * this.width, 0.5 * this.height); - button.setTitleText("PLAY GAME"); - button.setZoomScale(0.3); - button.setPressedActionEnabled(true); - button.addClickEventListener(function () { - cc.log("clicked!"); - button.setScale(1.2); - }); - this.addChild(button); - - // Create the button - var button2 = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - button2.ignoreContentAdaptWithSize(false); - button2.setContentSize(200,100); - button2.setPosition(0.8 * this.width, 0.5 * this.height); - button2.setTitleText("PLAY GAME"); - button2.setZoomScale(0.3); - button2.setPressedActionEnabled(true); - button2.addClickEventListener(function () { - button2.runAction(cc.scaleTo(1.0, 1.2)); - cc.log("clicked!"); - }); - this.addChild(button2); - - return true; - } - return false; - } -}); - -var UIButtonTitleEffectTest = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the button events will be displayed - this._topDisplayLabel.setString("Button Title Effect"); - this._bottomDisplayLabel.setString(""); - - // Create the button - var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - button.setPosition(0.3 * this.width, 0.5 * this.height); - button.setTitleText("PLAY GAME"); - //button.setTitleFontName("Marker Felt"); - button.setZoomScale(0.3); - button.setScale(2.0); - button.setPressedActionEnabled(true); - var title = button.getTitleRenderer(); - button.setTitleColor(cc.Color.RED); - title.enableShadow(cc.Color.BLACK, cc.size(2,-2)); - this.addChild(button); - - // Create the button - var button2 = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - button2.setPosition(0.8 * this.width, 0.5 * this.height); - button2.setTitleText("PLAY GAME"); - var title2 = button2.getTitleRenderer(); - title2.enableStroke(cc.Color.GREEN, 3); - this.addChild(button2); - return true; - } - return false; - } -}); - -var UIButtonFlipTest = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - - // Add a label in which the button events will be displayed - this._topDisplayLabel.setString(""); - this._bottomDisplayLabel.setString(""); - - // Create the button - var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - button.setPosition(0.3 * this.width, 0.5 * this.height); - button.setTitleText("PLAY GAME"); - //button.setTitleFontName("Marker Felt"); - button.setZoomScale(0.3); - button.setScale(2.0); - button.setFlippedX(true); - button.setPressedActionEnabled(true); - this.addChild(button); - - var titleLabel = new ccui.Text("Button X flipped", "Arial", 20); - titleLabel.setPosition(0.3 * this.width, 0.7 * this.height); - this.addChild(titleLabel); - - // Create the button - var button2 = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - button2.setPosition(0.8 * this.width, 0.5 * this.height); - button2.setTitleText("PLAY GAME"); - button2.setFlippedY(true); - this.addChild(button2); - - titleLabel = new ccui.Text("Button Y flipped", "Arial", 20); - titleLabel.setPosition(0.8 * this.width, 0.7 * this.height); - this.addChild(titleLabel); - return true; - } - return false; - } -}); - -var UIButtonNormalDefaultTest = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the button events will be displayed - this._topDisplayLabel.setString(""); - this._bottomDisplayLabel.setString(""); - - // Add the alert - var alert = new ccui.Text("Button should scale when clicked","Arial",20); - alert.setColor(cc.color(159, 168, 176)); - alert.setPosition(widgetSize.width / 2.0, - widgetSize.height / 2.0 - alert.height * 1.75); - this._mainNode.addChild(alert); - - // Create the button - var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png"); - button.setPosition(widgetSize.width / 2.0 - 80, widgetSize.height / 2.0 + 40); - button.setZoomScale(0.4); - button.setPressedActionEnabled(true); - this._mainNode.addChild(button); - - // Create the button - var buttonScale9 = new ccui.Button("ccs-res/cocosui/button.png"); - // open scale9 render - buttonScale9.setScale9Enabled(true); - buttonScale9.setPosition(widgetSize.width / 2.0 + 50, widgetSize.height / 2.0 + 40); - buttonScale9.setContentSize(150, 70); - buttonScale9.setPressedActionEnabled(true); - this._mainNode.addChild(buttonScale9); - return true; - } - return false; - } -}); - -var UIButtonDisableDefaultTest = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - this._topDisplayLabel.setString(""); - this._bottomDisplayLabel.setString(""); - - // Add the alert - var alert = new ccui.Text("Left button will turn normal when clicked","Arial",20); - alert.setColor(cc.color(159, 168, 176)); - alert.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert.height * 1.75); - this._mainNode.addChild(alert); - - // Create the button - var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png"); - button.setPosition(widgetSize.width / 2.0 - 80, widgetSize.height / 2.0 + 40); - button.setZoomScale(0.4); - button.setPressedActionEnabled(true); - button.setBright(false); - button.addClickEventListener(function () { - button.setBright(true); - }); - this._mainNode.addChild(button); - - // Create the button - var buttonScale9 = new ccui.Button("ccs-res/cocosui/button.png"); - // open scale9 render - buttonScale9.setScale9Enabled(true); - buttonScale9.setPosition(widgetSize.width / 2.0 + 50, widgetSize.height / 2.0 + 40); - buttonScale9.setContentSize(150, 70); - buttonScale9.setPressedActionEnabled(true); - buttonScale9.setEnabled(false); - buttonScale9.setBright(false); - this._mainNode.addChild(buttonScale9); - return true; - } - return false; - } -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UICheckBoxTest/UICheckBoxTest.js b/test/visual-tests/src/GUITest/UICheckBoxTest/UICheckBoxTest.js deleted file mode 100644 index bce5ed912b..0000000000 --- a/test/visual-tests/src/GUITest/UICheckBoxTest/UICheckBoxTest.js +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var UICheckBoxTest = UIMainLayer.extend({ - init: function () { - if (this._super()) { - //init text - this._topDisplayLabel.setString("No Event"); - this._bottomDisplayLabel.setString("CheckBox"); - - var widgetSize = this._widget.getContentSize(); - // Create the checkbox - var checkBox = new ccui.CheckBox(); - checkBox.setTouchEnabled(true); - checkBox.loadTextures("ccs-res/cocosui/check_box_normal.png", - "ccs-res/cocosui/check_box_normal_press.png", - "ccs-res/cocosui/check_box_active.png", - "ccs-res/cocosui/check_box_normal_disable.png", - "ccs-res/cocosui/check_box_active_disable.png"); - checkBox.x = widgetSize.width / 2.0; - checkBox.y = widgetSize.height / 2.0; - checkBox.addEventListener(this.selectedStateEvent, this); - this._mainNode.addChild(checkBox); - - return true; - } - return false; - }, - - selectedStateEvent: function (sender, type) { - switch (type) { - case ccui.CheckBox.EVENT_UNSELECTED: - this._topDisplayLabel.setString("Unselected"); - break; - case ccui.CheckBox.EVENT_SELECTED: - this._topDisplayLabel.setString("Selected"); - break; - - default: - break; - } - } -}); - -//2015-01-14 -var UICheckBoxDefaultBehaviorTest = UIMainLayer.extend({ - - init: function(){ - if(this._super()){ - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the checkbox events will be displayed - this._displayValueLabel = new ccui.Text("No Event", "Marker Felt", 32); - this._displayValueLabel.setAnchorPoint(cc.p(0.5, -1)); - this._displayValueLabel.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2)); - this._mainNode.addChild(this._displayValueLabel); - this._bottomDisplayLabel.setString(""); - - // Add the alert - var alert = new ccui.Text("Only left two and the last checkbox can be cliked!","Marker Felt",20 ); - alert.setColor(cc.color(159, 168, 176)); - alert.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - alert.getContentSize().height * 1.75)); - this._mainNode.addChild(alert); - - // Create the checkbox - var checkBox = new ccui.CheckBox("ccs-res/cocosui/check_box_normal.png", "ccs-res/cocosui/check_box_active.png"); - checkBox.setPosition(cc.p(widgetSize.width / 2 - 50, widgetSize.height / 2)); - - this._mainNode.addChild(checkBox); - - - // Create the checkbox - var checkBox2 = new ccui.CheckBox("ccs-res/cocosui/check_box_normal.png", "ccs-res/cocosui/check_box_active.png"); - checkBox2.setPosition(cc.p(widgetSize.width / 2 - 150, widgetSize.height / 2)); - checkBox2.ignoreContentAdaptWithSize(false); - checkBox2.setZoomScale(0.5); - checkBox2.setContentSize(cc.size(80,80)); - checkBox2.setName("bigCheckBox"); - this._mainNode.addChild(checkBox2); - - - // Create the checkbox - var checkBoxDisabled = new ccui.CheckBox("ccs-res/cocosui/check_box_normal.png", "ccs-res/cocosui/check_box_active.png"); - checkBoxDisabled.setPosition(cc.p(widgetSize.width / 2 + 20, widgetSize.height / 2)); - checkBoxDisabled.setEnabled(false); - checkBoxDisabled.setBright(false); - this._mainNode.addChild(checkBoxDisabled); - - var checkBoxDisabled2 = new ccui.CheckBox("ccs-res/cocosui/check_box_normal.png", "ccs-res/cocosui/check_box_active.png"); - checkBoxDisabled2.setPosition(cc.p(widgetSize.width / 2 + 70, widgetSize.height / 2)); - checkBoxDisabled2.setBright(false); - checkBoxDisabled2.setSelected(true); - this._mainNode.addChild(checkBoxDisabled2); - return true; - } - } - -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UIFocusTest/UIFocusTest.js b/test/visual-tests/src/GUITest/UIFocusTest/UIFocusTest.js deleted file mode 100644 index 616582d7a1..0000000000 --- a/test/visual-tests/src/GUITest/UIFocusTest/UIFocusTest.js +++ /dev/null @@ -1,550 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var UIFocusTestBase = UIMainLayer.extend({ - _dpadMenu: null, - _firstFocusedWidget: null, - _eventListener:null, - - init: function(){ - if (this._super()) { - this._dpadMenu = new cc.Menu(); - - cc.MenuItemFont.setFontSize(20); - var winSize = cc.director.getVisibleSize(); - var leftItem = new cc.MenuItemFont("Left", this.onLeftKeyPressed, this); - leftItem.setPosition(winSize.width - 100, winSize.height/2); - this._dpadMenu.addChild(leftItem); - - var rightItem = new cc.MenuItemFont("Right", this.onRightKeyPressed, this); - rightItem.setPosition(winSize.width - 30, winSize.height/2); - this._dpadMenu.addChild(rightItem); - - var upItem = new cc.MenuItemFont("Up", this.onUpKeyPressed, this); - upItem.setPosition(winSize.width - 60, winSize.height/2 + 50); - this._dpadMenu.addChild(upItem); - - var downItem = new cc.MenuItemFont("Down", this.onDownKeyPressed, this); - downItem.setPosition(winSize.width - 60, winSize.height/2 - 50); - this._dpadMenu.addChild(downItem); - - this._dpadMenu.setPosition(0, 0); - this.addChild(this._dpadMenu); - - //call this method to enable Dpad focus navigation - ccui.Widget.enableDpadNavigation(true); - - this._eventListener = cc.EventListener.create({ - event: cc.EventListener.FOCUS, //TODO Need add focus event in JSB - onFocusChanged: this.onFocusChanged.bind(this) - }); - cc.eventManager.addListener(this._eventListener, 1); - return true; - } - return false; - }, - - onLeftKeyPressed: function(){ - var event = new cc.Event.EventKeyboard(cc.KEY.dpadLeft, false); - cc.eventManager.dispatchEvent(event); - }, - onRightKeyPressed: function(){ - var event = new cc.Event.EventKeyboard(cc.KEY.dpadRight, false); - cc.eventManager.dispatchEvent(event); - }, - onUpKeyPressed: function(){ - var event = new cc.Event.EventKeyboard(cc.KEY.dpadUp, false); - cc.eventManager.dispatchEvent(event); - }, - onDownKeyPressed: function(){ - var event = new cc.Event.EventKeyboard(cc.KEY.dpadDown, false); - cc.eventManager.dispatchEvent(event); - }, - onFocusChanged: function(widgetLostFocus, widgetGetFocus){ - if (widgetGetFocus && widgetGetFocus.isFocusEnabled()) - widgetGetFocus.setColor(cc.Color.RED); - - if (widgetLostFocus && widgetLostFocus.isFocusEnabled()) - widgetLostFocus.setColor(cc.Color.WHITE); - - if (widgetLostFocus && widgetGetFocus) - cc.log("on focus change, %d widget get focus, %d widget lose focus", widgetGetFocus.getTag(), widgetLostFocus.getTag()); - }, - - onImageViewClicked: function(widget, touchType){ - if (touchType == ccui.Widget.TOUCH_ENDED) { - if (widget.isFocusEnabled()) { - widget.setFocusEnabled(false); - widget.setColor(cc.Color.YELLOW); - }else{ - widget.setFocusEnabled(true); - widget.setColor(cc.Color.WHITE); - } - } - } -}); - -var UIFocusTestHorizontal = UIFocusTestBase.extend({ - _horizontalLayout: null, - _loopText: null, - - init: function(){ - if (this._super()) { - var winSize = cc.director.getVisibleSize(); - - this._horizontalLayout = new ccui.HBox(); - this._horizontalLayout.setPosition(winSize.height/2 - 20, winSize.height/2 + 40); - this.addChild(this._horizontalLayout); - - this._horizontalLayout.setFocused(true); - this._horizontalLayout.setLoopFocus(true); - this._horizontalLayout.setTag(100); - this._firstFocusedWidget = this._horizontalLayout; - - var count = 3; - for (var i=0; i 100) { - this._count = 0; - } - - this._loadingBar && this._loadingBar.setPercent(this._count); - }, - - previousCallback: function (sender, type) { - this.unscheduleUpdate(); - this._super(sender, type) - }, - - restartCallback: function (sender, type) { - this.unscheduleUpdate(); - this._super(sender, type) - }, - - nextCallback: function (sender, type) { - this.unscheduleUpdate(); - this._super(sender, type) - } -}); - -var UILoadingBarTest_Left = UILoadingBarTest.extend({ - createLoadingBar: function () { - var widgetSize = this._widget.getContentSize(); - var loadingBar = new ccui.LoadingBar(); - loadingBar.setName("LoadingBar"); - loadingBar.loadTexture("ccs-res/cocosui/sliderProgress.png"); - loadingBar.setPercent(0); - loadingBar.x = widgetSize.width / 2; - loadingBar.y = widgetSize.height / 2 + loadingBar.height / 4; - this._mainNode.addChild(loadingBar); - this._loadingBar = loadingBar; - } -}); - -var UILoadingBarTest_Right = UILoadingBarTest.extend({ - createLoadingBar: function () { - var widgetSize = this._widget.getContentSize(); - var loadingBar = new ccui.LoadingBar(); - loadingBar.setName("LoadingBar"); - loadingBar.loadTexture("ccs-res/cocosui/sliderProgress.png"); - loadingBar.setDirection(ccui.LoadingBar.Type.RIGHT); - loadingBar.setPercent(0); - loadingBar.x = widgetSize.width / 2; - loadingBar.y = widgetSize.height / 2 + loadingBar.height / 4; - this._mainNode.addChild(loadingBar); - this._loadingBar = loadingBar; - } -}); - -var UILoadingBarTest_Fix = UILoadingBarTest.extend({ - createLoadingBar: function () { - var widgetSize = this._widget.getContentSize(); - var loadingBar = new ccui.LoadingBar(); - loadingBar.setName("LoadingBar"); - loadingBar.loadTexture("ccs-res/cocosui/sliderProgress.png"); - loadingBar.setDirection(ccui.LoadingBar.Type.RIGHT); - loadingBar.setPercent(40); - loadingBar.x = widgetSize.width / 2; - loadingBar.y = widgetSize.height / 2 + loadingBar.height / 4; - this._mainNode.addChild(loadingBar); - this._loadingBar = null; - } -}); - -var UILoadingBarTest_Left_Scale9 = UILoadingBarTest.extend({ - createLoadingBar: function () { - var widgetSize = this._widget.getContentSize(); - var loadingBar = new ccui.LoadingBar(); - loadingBar.setName("LoadingBar"); - loadingBar.setScale9Enabled(true); - loadingBar.loadTexture("ccs-res/cocosui/slider_bar_active_9patch.png"); - loadingBar.setCapInsets(cc.rect(0, 0, 0, 0)); - loadingBar.setContentSize(cc.size(300, 30)); - loadingBar.setPercent(0); - loadingBar.x = widgetSize.width / 2; - loadingBar.y = widgetSize.height / 2 + loadingBar.height / 4; - this._mainNode.addChild(loadingBar); - this._loadingBar = loadingBar; - } -}); - -var UILoadingBarTest_Right_Scale9 = UILoadingBarTest.extend({ - createLoadingBar: function () { - var widgetSize = this._widget.getContentSize(); - var loadingBar = new ccui.LoadingBar(); - loadingBar.setName("LoadingBar"); - loadingBar.setScale9Enabled(true); - loadingBar.loadTexture("ccs-res/cocosui/slider_bar_active_9patch.png"); - loadingBar.setCapInsets(cc.rect(0, 0, 0, 0)); - loadingBar.setContentSize(cc.size(300, 30)); - loadingBar.setDirection(ccui.LoadingBar.Type.RIGHT); - loadingBar.setPercent(0); - loadingBar.x = widgetSize.width / 2; - loadingBar.y = widgetSize.height / 2 + loadingBar.height / 4; - this._mainNode.addChild(loadingBar); - this._loadingBar = loadingBar; - } -}); - -var UILoadingBarTest_Fix_Scale9 = UILoadingBarTest.extend({ - createLoadingBar: function () { - var widgetSize = this._widget.getContentSize(); - var loadingBar = new ccui.LoadingBar(); - loadingBar.setName("LoadingBar"); - loadingBar.setScale9Enabled(true); - loadingBar.loadTexture("ccs-res/cocosui/slider_bar_active_9patch.png"); - loadingBar.setPercent(40); - loadingBar.setCapInsets(cc.rect(0, 0, 0, 0)); - loadingBar.setContentSize(cc.size(300, 30)); - loadingBar.setDirection(ccui.LoadingBar.Type.RIGHT); - loadingBar.x = widgetSize.width / 2; - loadingBar.y = widgetSize.height / 2 + loadingBar.height / 4; - this._mainNode.addChild(loadingBar); - this._loadingBar = null; - } -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UINodeContainerTest/UINodeContainerTest.js b/test/visual-tests/src/GUITest/UINodeContainerTest/UINodeContainerTest.js deleted file mode 100644 index 768bf37a17..0000000000 --- a/test/visual-tests/src/GUITest/UINodeContainerTest/UINodeContainerTest.js +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var UIWidgetAddNodeTest = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString(""); - this._bottomDisplayLabel.setString("NodeContainer"); - - // Create the ui node container - var nodeContainer = new ccui.Widget(); - nodeContainer.x = widgetSize.width / 2; - nodeContainer.y = widgetSize.height / 2; - this._mainNode.addChild(nodeContainer); - - var sprite = new _ccsg.Sprite("ccs-res/cocosui/ccicon.png"); - sprite.x = 0; - sprite.y = sprite.getBoundingBox().height / 4; - nodeContainer.addNode(sprite); - - return true; - } - return false; - } -}); diff --git a/test/visual-tests/src/GUITest/UIPageViewTest/UIPageViewTest.js b/test/visual-tests/src/GUITest/UIPageViewTest/UIPageViewTest.js deleted file mode 100644 index a7154f5cb5..0000000000 --- a/test/visual-tests/src/GUITest/UIPageViewTest/UIPageViewTest.js +++ /dev/null @@ -1,570 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var UIPageViewTest = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("Move by horizontal direction"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - this._bottomDisplayLabel.setString("PageView"); - this._bottomDisplayLabel.x = widgetSize.width / 2; - this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; - - var background = this._backgroundSize; - - // Create the page view - var pageView = new ccui.PageView(); - pageView.setTouchEnabled(true); - pageView.setContentSize(cc.size(240, 130)); - pageView.x = (widgetSize.width - background.width) / 2 + (background.width - pageView.width) / 2; - pageView.y = (widgetSize.height - background.height) / 2 + (background.height - pageView.height) / 2; - - for (var i = 0; i < 3; ++i) { - var layout = new ccui.Layout(); - layout.setContentSize(cc.size(240, 130)); - var layoutRect = layout.getContentSize(); - - var imageView = new ccui.ImageView(); - imageView.setTouchEnabled(true); - imageView.setScale9Enabled(true); - imageView.loadTexture("ccs-res/cocosui/scrollviewbg.png"); - imageView.setContentSize(cc.size(240, 130)); - imageView.x = layoutRect.width / 2; - imageView.y = layoutRect.height / 2; - layout.addChild(imageView); - - var text = new ccui.Text(); - text.string = "page" + (i + 1); - text.font = "30px 'Marker Felt'"; - text.color = cc.color(192, 192, 192); - text.x = layoutRect.width / 2; - text.y = layoutRect.height / 2; - layout.addChild(text); - - pageView.addPage(layout); - } - pageView.addEventListener(this.pageViewEvent, this); - this._mainNode.addChild(pageView); - - return true; - } - return false; - }, - - pageViewEvent: function (sender, type) { - switch (type) { - case ccui.PageView.EVENT_TURNING: - var pageView = sender; - this._topDisplayLabel.setString("page = " + (pageView.getCurPageIndex().valueOf()-0 + 1)); - break; - default: - break; - } - } -}); - -//2015-01-14 -var UIPageViewButtonTest = UIMainLayer.extend({ - init: function(){ - if (this._super()){ - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the dragpanel events will be displayed - this._topDisplayLabel.setString("Move by horizontal direction"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - - // Add the black background - this._bottomDisplayLabel.setString("PageView with Buttons"); - this._bottomDisplayLabel.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - this._bottomDisplayLabel.height * 3.075); - - // Create the page view - var pageView = new ccui.PageView(); - pageView.setContentSize(cc.size(240.0, 130.0)); - var backgroundSize = this._backgroundSize; - pageView.setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2.0 + - (backgroundSize.width - pageView.getContentSize().width) / 2.0, - (widgetSize.height - backgroundSize.height) / 2.0 + - (backgroundSize.height - pageView.getContentSize().height) / 2.0)); - - pageView.removeAllPages(); - - var pageCount = 4; - for (var i = 0; i < pageCount; ++i){ - var outerBox = new ccui.HBox(); - outerBox.setContentSize(cc.size(240.0, 130.0)); - - for (var k = 0; k < 2; ++k) { - var innerBox = new ccui.VBox(); - - for (var j = 0; j < 3; j++) { - var btn = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - btn.setName("button " + j); - btn.addTouchEventListener( this.onButtonClicked, this); - innerBox.addChild(btn); - } - - var parameter = new ccui.LinearLayoutParameter(); - parameter.setMargin({left: 0, top: 0, right: 100, bottom: 0}); - innerBox.setLayoutParameter(parameter); - - outerBox.addChild(innerBox); - } - pageView.insertPage(outerBox,i); - } - - pageView.removePageAtIndex(0); - pageView.addEventListener(this.pageViewEvent, this); - this._mainNode.addChild(pageView); - - return true; - } - }, - - onButtonClicked: function(sender, type){ - cc.log("button %s clicked", sender.getName()); - }, - - pageViewEvent: function(pageView, type){ - switch (type){ - case ccui.PageView.EVENT_TURNING: - this._topDisplayLabel.setString("page = " + pageView.getCurPageIndex() + 1); - break; - default: - break; - } - } -}); - -//2015-01-14 -var UIPageViewCustomScrollThreshold = UIMainLayer.extend({ - init: function(){ - if (this._super()){ - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the dragpanel events will be displayed - this._topDisplayLabel.setString("Scroll Threshold"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - - // Add the black background - this._bottomDisplayLabel.setString("PageView"); - this._bottomDisplayLabel.setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - this._bottomDisplayLabel.height * 3.075)); - - // Create the page view - var pageView = new ccui.PageView(); - pageView.setContentSize(cc.size(240.0, 100.0)); - var backgroundSize = this._backgroundSize; - pageView.setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2.0 + - (backgroundSize.width - pageView.getContentSize().width) / 2.0, - (widgetSize.height - backgroundSize.height) / 2.0 + - (backgroundSize.height - pageView.getContentSize().height) / 2.0 + 20)); - - var pageCount = 4; - for (var i = 0; i < pageCount; ++i) { - var layout = new ccui.Layout(); - layout.setContentSize(cc.size(240.0, 130.0)); - - var imageView = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png"); - imageView.setScale9Enabled(true); - imageView.setContentSize(cc.size(240, 130)); - imageView.setPosition(cc.p(layout.getContentSize().width / 2.0, layout.getContentSize().height / 2.0)); - layout.addChild(imageView); - - var label = new ccui.Text("page " + (i+1) , "Marker Felt", 30); - label.setColor(cc.color(192, 192, 192)); - label.setPosition(cc.p(layout.getContentSize().width / 2.0, layout.getContentSize().height / 2.0)); - layout.addChild(label); - - pageView.insertPage(layout,i); - } - - this._mainNode.addChild(pageView); - pageView.setName("pageView"); - - var slider = new ccui.Slider(); - slider.loadBarTexture("ccs-res/cocosui/sliderTrack.png"); - slider.loadSlidBallTextures("ccs-res/cocosui/sliderThumb.png", "ccs-res/cocosui/sliderThumb.png", ""); - slider.loadProgressBarTexture("ccs-res/cocosui/sliderProgress.png"); - slider.setPosition(cc.p(widgetSize.width / 2.0 , widgetSize.height / 2.0 - 40)); - slider.addEventListener(this.sliderEvent, this); - slider.setPercent(50); - this._mainNode.addChild(slider); - - return true; - } - }, - - sliderEvent: function(slider, type){ - if (type == ccui.Slider.EVENT_PERCENT_CHANGED){ - var percent = slider.getPercent(); - var pageView = this._mainNode.getChildByName("pageView"); - if (percent == 0) - percent = 1; - pageView.setCustomScrollThreshold(percent * 0.01 * pageView.width); - - this._topDisplayLabel.setString("Scroll Threshold: " + pageView.getCustomScrollThreshold().toFixed(2)); - } - } -}); - -//2015-01-14 -var UIPageViewTouchPropagationTest = UIMainLayer.extend({ - init: function(){ - if (this._super()){ - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the dragpanel events will be displayed - this._topDisplayLabel.setString("Move by horizontal direction"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - - // Add the black background - this._bottomDisplayLabel.setString("PageView Touch Propagation"); - this._bottomDisplayLabel.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - this._bottomDisplayLabel.height * 3.075); - - // Create the page view - var pageView = new ccui.PageView(); - pageView.setContentSize(cc.size(240.0, 130.0)); - pageView.setAnchorPoint(cc.p(0.5,0.5)); - var backgroundSize = this._backgroundSize; - pageView.setPosition(cc.p(widgetSize.width / 2.0 ,widgetSize.height / 2.0)); - pageView.setBackGroundColor(cc.Color.GREEN); - pageView.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID); - - var pageCount = 4; - for (var i = 0; i < pageCount; ++i) { - var outerBox = new ccui.HBox(); - outerBox.setContentSize(cc.size(240.0, 130.0)); - - for (var k = 0; k < 2; ++k) { - var innerBox = new ccui.VBox(); - - for (var j = 0; j < 3; j++) { - var btn = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - btn.setName("button " + j); - btn.addTouchEventListener(this.onButtonClicked, this); - innerBox.addChild(btn); - } - - var parameter = new ccui.LinearLayoutParameter(); - parameter.setMargin({left: 0, top: 0, right: 100, bottom: 0}); - innerBox.setLayoutParameter(parameter); - - outerBox.addChild(innerBox); - } - pageView.insertPage(outerBox, i); - } - - pageView.addEventListener(this.pageViewEvent, this); - pageView.setName("pageView"); - pageView.addTouchEventListener(function(sender, type){ - if (type == ccui.Widget.TOUCH_BEGAN){ - cc.log("page view touch began"); - }else if(type == ccui.Widget.TOUCH_MOVED){ - cc.log("page view touch moved"); - }else if(type == ccui.Widget.TOUCH_ENDED){ - cc.log("page view touch ended"); - }else{ - cc.log("page view touch cancelled"); - } - }); - this._mainNode.addChild(pageView); - - var propagationText = new ccui.Text("Allow Propagation", "Arial", 10); - propagationText.setAnchorPoint(cc.p(0,0.5)); - propagationText.setTextColor(cc.Color.RED); - propagationText.setPosition(cc.p(20, pageView.getPosition().y + 50)); - this._mainNode.addChild(propagationText); - - var swallowTouchText = new ccui.Text("Swallow Touches", "Arial", 10); - swallowTouchText.setAnchorPoint(cc.p(0,0.5)); - swallowTouchText.setTextColor(cc.Color.RED); - swallowTouchText.setPosition(cc.p(20, pageView.getPosition().y)); - this._mainNode.addChild(swallowTouchText); - - // Create the checkbox - var checkBox1 = new ccui.CheckBox("ccs-res/cocosui/check_box_normal.png", - "ccs-res/cocosui/check_box_normal_press.png", - "ccs-res/cocosui/check_box_active.png", - "ccs-res/cocosui/check_box_normal_disable.png", - "ccs-res/cocosui/check_box_active_disable.png"); - var propagationPosition = propagationText.getPosition(); - checkBox1.setPosition( - propagationPosition.x + propagationText.getContentSize().width/2, - propagationPosition.y - 20 - ); - - checkBox1.setName("propagation"); - this._mainNode.addChild(checkBox1); - - // Create the checkbox - var checkBox2 = new ccui.CheckBox("ccs-res/cocosui/check_box_normal.png", - "ccs-res/cocosui/check_box_normal_press.png", - "ccs-res/cocosui/check_box_active.png", - "ccs-res/cocosui/check_box_normal_disable.png", - "ccs-res/cocosui/check_box_active_disable.png"); - var swallowPosition = swallowTouchText.getPosition(); - checkBox2.setPosition( - swallowPosition.x + swallowTouchText.getContentSize().width/2, - swallowPosition.y - 20 - ); - - checkBox2.setName("swallow"); - this._mainNode.addChild(checkBox2); - -// var eventListener = new cc.EventListenerTouchOneByOne(); -// eventListener.onTouchBegan = function(touch, event){ -// cc.log("layout recieves touches"); -// return true; -// }; -// this._eventDispatcher.addEventListenerWithSceneGraphPriority(eventListener, this); - - return true; - } - }, - - onButtonClicked: function(btn, type){ - var ck1 = this._mainNode.getChildByName("propagation"); - var ck2 = this._mainNode.getChildByName("swallow"); - var pageView = this._mainNode.getChildByName("pageView"); - - if (type == ccui.Widget.TOUCH_BEGAN){ - if (ck1.isSelected()){ - btn.setPropagateTouchEvents(true); - pageView.setPropagateTouchEvents(true); - }else{ - btn.setPropagateTouchEvents(false); - pageView.setPropagateTouchEvents(false); - } - - if (ck2.isSelected()){ - btn.setSwallowTouches(true); - pageView.setSwallowTouches(true); - }else{ - btn.setSwallowTouches(false); - pageView.setSwallowTouches(false); - } - } - if (type == ccui.Widget.TOUCH_ENDED) - cc.log("button clicked"); - }, - - pageViewEvent: function(pageView, type){ - switch (type){ - case ccui.PageView.EVENT_TURNING: - this._topDisplayLabel.setString("page = " + (pageView.getCurPageIndex()-0 + 1)); - break; - default: - break; - } - } -}); - -//2015-01-14 -var UIPageViewDynamicAddAndRemoveTest = UIMainLayer.extend({ - init: function(){ - var self = this; - if (this._super()){ - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the dragpanel events will be displayed - this._topDisplayLabel.setString("Click Buttons on the Left"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - - // Add the black background - this._bottomDisplayLabel.setString("PageView Dynamic Modification"); - this._bottomDisplayLabel.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - this._bottomDisplayLabel.height * 3.075); - - // Create the page view - var pageView = new ccui.PageView(); - pageView.setContentSize(cc.size(240.0, 130.0)); - pageView.setAnchorPoint(cc.p(0.5,0.5)); - var backgroundSize = this._backgroundSize; - pageView.setPosition(cc.p(widgetSize.width / 2.0 ,widgetSize.height / 2.0)); - pageView.setBackGroundColor(cc.Color.GREEN); - pageView.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID); - - var pageCount = 4; - for (var i = 0; i < pageCount; ++i){ - var outerBox = new ccui.HBox(); - outerBox.setContentSize(cc.size(240.0, 130.0)); - - for (var k = 0; k < 2; ++k){ - var innerBox = new ccui.VBox(); - for (var j = 0; j < 3; j++){ - var btn = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", - "ccs-res/cocosui/animationbuttonpressed.png"); - btn.setName("button " + j); - innerBox.addChild(btn); - } - - var parameter = new ccui.LinearLayoutParameter(); - parameter.setMargin({left: 0, top: 0, right: 100, bottom:0}); - innerBox.setLayoutParameter(parameter); - - outerBox.addChild(innerBox); - } - pageView.insertPage(outerBox,i); - } - - pageView.addEventListener(this.pageViewEvent, this); - pageView.setName("pageView"); - this._mainNode.addChild(pageView); - - //add buttons - var button = new ccui.Button(); - button.setAnchorPoint(0, 0.5); - button.setTitleFontSize(12); - button.setPosition(20, 220); - button.setTitleText("Add A Page"); - button.setZoomScale(0.3); - button.setPressedActionEnabled(true); - button.setTitleColor(cc.Color.RED); - button.addClickEventListener(function(sender){ - var outerBox = new ccui.HBox(); - outerBox.setContentSize(cc.size(240.0, 130.0)); - - for (var k = 0; k < 2; ++k){ - var innerBox = new ccui.VBox(); - for (var j = 0; j < 3; j++){ - var btn = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", - "ccs-res/cocosui/animationbuttonpressed.png"); - btn.setName("button " + j); - innerBox.addChild(btn); - } - - var parameter = new ccui.LinearLayoutParameter(); - parameter.setMargin({left: 0, top: 0, right: 100, bottom: 0}); - innerBox.setLayoutParameter(parameter); - - outerBox.addChild(innerBox); - } - - pageView.addPage(outerBox); - self._topDisplayLabel.setString("page count = " + pageView.getPages().length); - }); - this._mainNode.addChild(button); - - var button2 = new ccui.Button(); - button2.setAnchorPoint(0, 0.5); - button2.setTitleFontSize(12); - button2.setPosition(20, 180); - button2.setTitleText("Remove A Page"); - button2.setZoomScale(0.3); - button2.setPressedActionEnabled(true); - button2.setTitleColor(cc.Color.RED); - button2.addClickEventListener(function(sender){ - if (pageView.getPages().length > 0){ - pageView.removePageAtIndex(pageView.getPages().length-1); - }else{ - cc.log("There is no page to remove!"); - } - self._topDisplayLabel.setString("page count = " + pageView.getPages().length); - - }); - this._mainNode.addChild(button2); - - var button3 = new ccui.Button(); - button3.setAnchorPoint(0, 0.5); - button3.setTitleFontSize(12); - button3.setPosition(cc.p(20, 140)); - button3.setTitleText("Remove All Pages"); - button3.setZoomScale(0.3); - button3.setPressedActionEnabled(true); - button3.setTitleColor(cc.Color.RED); - button3.addClickEventListener(function(sender){ - pageView.removeAllPages(); - self._topDisplayLabel.setString("page count = " + pageView.getPages().length); - }); - this._mainNode.addChild(button3); - - return true; - } - }, - - pageViewEvent: function(pageView, type){ - switch (type){ - case ccui.PageView.EVENT_TURNING: - this._topDisplayLabel.setString("page = " + (pageView.getCurPageIndex() + 1)); - break; - default: - break; - } - } -}); - -var UIPageViewDisableTouchTest = UIMainLayer.extend({ - init: function () { - if(this._super()){ - var widgetSize = this._widget.getContentSize(); - - this._topDisplayLabel.setString("PageView disable touch"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - - this._bottomDisplayLabel.setString("PageView"); - this._bottomDisplayLabel.x = widgetSize.width / 2; - this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; - - var backgroundSize = this._backgroundSize; - - var pageView = new ccui.PageView(); - pageView.setContentSize(cc.size(240, 130)); - pageView.x = (widgetSize.width - backgroundSize.width) / 2 + (backgroundSize.width - pageView.width) / 2; - pageView.y = (widgetSize.height - backgroundSize.height) / 2 + (backgroundSize.height - pageView.height) / 2; - pageView.setTouchEnabled(false); - pageView.removeAllPages(); - - var pageCount = 4; - for(var i = 0; i < pageCount; i++){ - var layout = new ccui.Layout(); - layout.setContentSize(cc.size(240, 130)); - - var imageView = new ccui.ImageView(); - imageView.setScale9Enabled(true); - imageView.loadTexture("ccs-res/cocosui/scrollviewbg.png"); - imageView.setContentSize(cc.size(240, 130)); - imageView.x = layout.getContentSize().width / 2; - imageView.y = layout.getContentSize().height / 2; - layout.addChild(imageView); - var pageNumber = i+1; - var label = new ccui.Text("page" + pageNumber, "Marker Felt",30); - label.setColor(cc.color(192, 192, 192)); - label.setPosition(cc.p(layout.getContentSize().width / 2, layout.getContentSize().height / 2)); - layout.addChild(label); - - pageView.insertPage(layout, i); - } - this._mainNode.addChild(pageView); - return true; - } - return false; - } -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UIRichTextTest/UIRichTextTest.js b/test/visual-tests/src/GUITest/UIRichTextTest/UIRichTextTest.js deleted file mode 100644 index 6dfc397607..0000000000 --- a/test/visual-tests/src/GUITest/UIRichTextTest/UIRichTextTest.js +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var UIRichTextTest = UIMainLayer.extend({ - _richText:null, - init: function () { - if (this._super()) { - //init text - this._topDisplayLabel.setString(""); - this._bottomDisplayLabel.setString("RichText"); - - var widgetSize = this._widget.getContentSize(); - var button = new ccui.Button(); - button.setTouchEnabled(true); - button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", ""); - button.setTitleText("switch"); - button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5)); - button.addTouchEventListener(this.touchEvent,this); - this._mainNode.addChild(button); - - // RichText - var richText = new ccui.RichText(); - richText.ignoreContentAdaptWithSize(false); - richText.width = 120; - richText.height = 100; - - var re1 = new ccui.RichElementText(1, cc.Color.WHITE, 255, "This color is white. ", "Helvetica", 10); - var re2 = new ccui.RichElementText(2, cc.Color.YELLOW, 255, "And this is yellow. ", "Helvetica", 10); - var re3 = new ccui.RichElementText(3, cc.Color.BLUE, 255, "This one is blue. ", "Helvetica", 10); - var re4 = new ccui.RichElementText(4, cc.Color.GREEN, 255, "And green. ", "Helvetica", 10); - var re5 = new ccui.RichElementText(5, cc.Color.RED, 255, "Last one is red ", "Helvetica", 10); - - var reimg = new ccui.RichElementImage(6, cc.Color.WHITE, 255, "ccs-res/cocosui/sliderballnormal.png"); - - ccs.armatureDataManager.addArmatureFileInfo("ccs-res/cocosui/100/100.ExportJson"); - var pAr = new ccs.Armature("100"); - pAr.getAnimation().play("Animation1"); - - var recustom = new ccui.RichElementCustomNode(1, cc.Color.WHITE, 255, pAr); - var re6 = new ccui.RichElementText(7, cc.Color.ORANGE, 255, "Have fun!! ", "Helvetica", 10); - richText.pushBackElement(re1); - richText.insertElement(re2, 1); - richText.pushBackElement(re3); - richText.pushBackElement(re4); - richText.pushBackElement(re5); - richText.insertElement(reimg, 2); - richText.pushBackElement(recustom); - richText.pushBackElement(re6); - - richText.x = widgetSize.width / 2; - richText.y = widgetSize.height / 2; - - this._mainNode.addChild(richText); - this._richText = richText; - return true; - } - return false; - }, - touchEvent: function (sender, type) { - if (type == ccui.Widget.TOUCH_ENDED) { - if (this._richText.isIgnoreContentAdaptWithSize()) { - this._richText.ignoreContentAdaptWithSize(false); - this._richText.setContentSize(cc.size(120, 100)); - } else { - this._richText.ignoreContentAdaptWithSize(true); - } - } - } -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UIS9NinePatchTest/UIS9NinePatchTest.js b/test/visual-tests/src/GUITest/UIS9NinePatchTest/UIS9NinePatchTest.js deleted file mode 100644 index 50730dd902..0000000000 --- a/test/visual-tests/src/GUITest/UIS9NinePatchTest/UIS9NinePatchTest.js +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var UIS9NinePatchTest = UIMainLayer.extend({ - init: function () { - if (this._super()) { - //init text - this._topDisplayLabel.setString(""); - this._bottomDisplayLabel.setString(""); - - cc.spriteFrameCache.addSpriteFrames("ccs-res/cocosui/android9patch.plist"); - - var winSize = director.getWinSize(); - var x = winSize.width / 2; - var y = 0 + (winSize.height / 2 + 50); - - var preferedSize = cc.size(99,99); - - //9-patch sprite with filename - var playerSprite = new cc.Scale9Sprite("ccs-res/cocosui/player.9.png"); - playerSprite.setPosition(x, y); - playerSprite.setContentSize(preferedSize); - var capInsets = playerSprite.getCapInsets(); - cc.log("player sprite capInset = " + capInsets.x + ", " + capInsets.y + " " + capInsets.width + ", " + capInsets.height); - this.addChild(playerSprite); - - var animationBtnSprite = new cc.Scale9Sprite("animationbuttonpressed.png"); - animationBtnSprite.setPosition(x-100, y-100); - capInsets = animationBtnSprite.getCapInsets(); - cc.log("animationBtnSprite capInset = " + capInsets.x + ", " + capInsets.y + " " + capInsets.width + ", " + capInsets.height); - this.addChild(animationBtnSprite); - - - var monsterSprite = new cc.Scale9Sprite("monster.9.png"); - monsterSprite.setPosition(x+100, y-100); - capInsets = monsterSprite.getCapInsets(); - monsterSprite.setContentSize(preferedSize); - cc.log("monsterSprite capInset = ", + capInsets.x + ", " + capInsets.y + " " + capInsets.width + ", " + capInsets.height); - this.addChild(monsterSprite); - - var spriteFrame = cc.spriteFrameCache.getSpriteFrame("buttonnormal.9.png"); - var buttonScale9Sprite = new cc.Scale9Sprite(spriteFrame); - buttonScale9Sprite.setContentSize(cc.size(150,80)); - buttonScale9Sprite.setPosition(cc.p(100,200)); - this.addChild(buttonScale9Sprite); - - return true; - } - return false; - } -}); diff --git a/test/visual-tests/src/GUITest/UIScene.js b/test/visual-tests/src/GUITest/UIScene.js deleted file mode 100644 index f97165791d..0000000000 --- a/test/visual-tests/src/GUITest/UIScene.js +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -var UIScene = TestScene.extend({ - runThisTest: function(){ - var layer = new UIMainLayer(); - this.addChild(layer); - cc.director.runScene(this); - } -}); -var UIMainLayer = BaseTestLayer.extend({ - _topDisplayLabel:null, - _bottomDisplayLabel:null, - _mainNode:null, - _widget: { - width: 480, - height: 320, - getContentSize: function () { - return cc.size(480, 320); - } - }, - _backgroundSize: cc.size(300, 170), - - init: function() { - this._super(); - - var winSize = cc.winSize; - var mainNode = new _ccsg.Node(); - var scale = winSize.height/320; - mainNode.attr({anchorX: 0, anchorY: 0, scale: scale, x: (winSize.width - 480 * scale) / 2, y: (winSize.height - 320 * scale) / 2}); - this.addChild(mainNode); - this._mainNode = mainNode; - - //add topDisplayLabel - var widgetSize = cc.size(480, 320); - var topDisplayText = new ccui.Text(); - topDisplayText.attr({ - string: "", - fontName: "Marker Felt", - fontSize: 32, - anchorX: 0.5, - anchorY: -1, - x: widgetSize.width / 2.0, - y: widgetSize.height / 2.0 - }); - mainNode.addChild(topDisplayText); - - //add bottomDisplayLabel - var bottomDisplayText = new ccui.Text(); - bottomDisplayText.attr({ - string: "INIT", - fontName: "Marker Felt", - fontSize: 30, - color: cc.color(159, 168, 176), - x: widgetSize.width / 2.0 - }); - bottomDisplayText.y = widgetSize.height / 2.0 - bottomDisplayText.height * 1.75; - mainNode.addChild(bottomDisplayText); - - this._topDisplayLabel = topDisplayText; - this._bottomDisplayLabel = bottomDisplayText; - this._mainNode = mainNode; - return true; - }, - setSceneTitle: function (title) { - this._title = title; - }, - - onBackCallback: function (sender) { - cc.director.runScene(UISceneManager.getInstance().previousUIScene()); - }, - - onRestartCallback: function (sender) { - UISceneManager.purge(); - GUITestScene.prototype.runThisTest(); - }, - - onNextCallback: function (sender) { - cc.director.runScene(UISceneManager.getInstance().nextUIScene()); - } -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UISceneManager.js b/test/visual-tests/src/GUITest/UISceneManager.js deleted file mode 100644 index 9731ecbacf..0000000000 --- a/test/visual-tests/src/GUITest/UISceneManager.js +++ /dev/null @@ -1,709 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS()", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -(function(global){ - - var currentTestingArray = null; - - var testingItems = { - "UIButton": [ - { - title: "UIButtonTest", - func: function () { - return new UIButtonTest(); - } - }, - { - title: "UIButtonTest_Scale9", - func: function () { - return new UIButtonTest_Scale9(); - } - }, - { - title: "UIButtonTest_PressedAction", - func: function () { - return new UIButtonTest_PressedAction(); - } - }, - { - title: "UIButtonTest_Title", - func: function () { - return new UIButtonTest_Title(); - } - }, - { - title: "UIButtonTestRemoveSelf", - func: function () { - return new UIButtonTestRemoveSelf(); - } - }, - { - title: "UIButtonTestSwitchScale9", - func: function () { - return new UIButtonTestSwitchScale9(); - } - }, - { - title: "UIButtonTestZoomScale", - func: function () { - return new UIButtonTestZoomScale(); - } - }, - { - title: "UIButtonTextOnly", - func: function () { - return new UIButtonTextOnly(); - } - }, - { - title: "UIButtonIgnoreContentSizeTest", - func: function () { - return new UIButtonIgnoreContentSizeTest(); - } - }, - { - title: "UIButtonTitleEffectTest", - func: function () { - return new UIButtonTitleEffectTest(); - } - }, - { - title: "UIButtonFlipTest", - func: function () { - return new UIButtonFlipTest(); - } - }, - { - title: "UIButtonNormalDefaultTest", - func: function () { - return new UIButtonNormalDefaultTest(); - } - }, - { - title: "UIButtonDisableDefaultTest", - func: function () { - return new UIButtonDisableDefaultTest(); - } - } - ], - "UIFocus": [ - { - title: "UIFocusTestHorizontal", - func: function () { - return new UIFocusTestHorizontal(); - } - }, - { - title: "UIFocusTestVertical", - func: function () { - return new UIFocusTestVertical(); - } - }, - { - title: "UIFocusTestNestedLayout1", - func: function () { - return new UIFocusTestNestedLayout1(); - } - }, - { - title: "UIFocusTestNestedLayout2", - func: function () { - return new UIFocusTestNestedLayout2(); - } - }, - { - title: "UIFocusTestNestedLayout3", - func: function () { - return new UIFocusTestNestedLayout3(); - } - } - /*{ //need test - title: "UIFocusTestListView", - func: function () { - return new UIFocusTestListView(); - } - }*/ - ], - "UICheckBox": [ - { - title: "UICheckBoxTest", - func: function () { - return new UICheckBoxTest(); - } - }, - { - title: "UICheckBoxDefaultBehaviorTest", - func: function(){ - return new UICheckBoxDefaultBehaviorTest(); - } - } - ], - "UISlider": [ - { - title: "UISliderTest", - func: function () { - return new UISliderTest(); - } - }, - { - title: "UISliderTest_Scale9", - func: function () { - return new UISliderTest_Scale9(); - } - }, - { - title: "UISliderNormalDefaultTest", - func: function () { - return new UISliderNormalDefaultTest(); - } - }, - { - title: "UISliderDisabledDefaultTest", - func: function () { - return new UISliderDisabledDefaultTest(); - } - } - ], - "UIImageView": [ - { - title: "UIImageViewTest", - func: function () { - return new UIImageViewTest(); - } - }, - { - title: "UIImageViewTest_Scale9", - func: function () { - return new UIImageViewTest_Scale9(); - } - }, - { - title: "UIImageViewTest_ContentSize", - func: function () { - return new UIImageViewTest_ContentSize(); - } - }, - { - title: "UIImageViewFlipTest", - func: function () { - return new UIImageViewFlipTest(); - } - } - ], - "UILoadingBar": [ - { - title: "UILoadingBarTest_Left", - func: function () { - return new UILoadingBarTest_Left(); - } - }, - { - title: "UILoadingBarTest_Right", - func: function () { - return new UILoadingBarTest_Right(); - } - }, - { - title: "UILoadingBarTest_Fix", - func: function(){ - return new UILoadingBarTest_Fix(); - } - }, - { - title: "UILoadingBarTest_Left_Scale9", - func: function () { - return new UILoadingBarTest_Left_Scale9(); - } - }, - { - title: "UILoadingBarTest_Right_Scale9", - func: function () { - return new UILoadingBarTest_Right_Scale9(); - } - }, - { - title: "UILoadingBarTest_Fix_Scale9", - func: function(){ - return new UILoadingBarTest_Fix_Scale9(); - } - } - ], - "UIText": [ - { - title: "UITextTest", - func: function(){ - return new UITextTest(); - } - }, - { - title: "UITextTest_LineWrap", - func: function(){ - return new UITextTest_LineWrap(); - } - }, - { - title: "UILabelTest_Effect", - func: function(){ - return new UILabelTest_Effect(); - } - }, - { - title: "UITextTest_TTF", - func: function(){ - return new UITextTest_TTF(); - } - }, - { - title: "UITextTest_IgnoreConentSize", - func: function(){ - return new UITextTest_IgnoreConentSize(); - } - }, - { - title: "UILabelAtlasTest", - func: function () { - return new UILabelAtlasTest(); - } - }, - { - title: "UILabelTest", - func: function () { - return new UILabelTest(); - } - }, - { - title: "UILabelTest_LineWrap", - func: function () { - return new UILabelTest_LineWrap(); - } - }, - { - title: "UILabelBMFontTest", - func: function () { - return new UILabelBMFontTest(); - } - }, - { - title: "UILabelTest_TTF", - func: function () { - return new UILabelTest_TTF(); - } - } - ], - "UITextFiled": [ - { - title: "UITextFieldTest", - func: function () { - return new UITextFieldTest(); - } - }, - { - title: "UITextFieldTest_MaxLength", - func: function () { - return new UITextFieldTest_MaxLength(); - } - }, - { - title: "UITextFieldTest_Password", - func: function () { - return new UITextFieldTest_Password(); - } - }, - { - title: "UITextFieldTest_LineWrap", - func: function () { - return new UITextFieldTest_LineWrap(); - } - }, - { - title: "UITextFieldTest_TrueTypeFont", - func: function () { - return new UITextFieldTest_TrueTypeFont(); - } - }, - { - title: "UITextFieldTest_PlaceHolderColor", - func: function () { - return new UITextFieldTest_PlaceHolderColor(); - } - } - ], - "UILayout": [ - { - title: "UILayoutTest", - func: function () { - return new UILayoutTest(); - } - }, - { - title: "UILayoutTest_Color", - func: function () { - return new UILayoutTest_Color(); - } - }, - { - title: "UILayoutTest_Gradient", func: function () { - return new UILayoutTest_Gradient(); - } - }, - { - title: "UILayoutTest_BackGroundImage", - func: function () { - return new UILayoutTest_BackGroundImage(); - } - }, - { - title: "UILayoutTest_BackGroundImage_Scale9", - func: function () { - return new UILayoutTest_BackGroundImage_Scale9(); - } - }, - { - title: "UILayoutTest_Layout_Linear_Vertical", - func: function () { - return new UILayoutTest_Layout_Linear_Vertical(); - } - }, - { - title: "UILayoutTest_Layout_Linear_Horizontal", - func: function () { - return new UILayoutTest_Layout_Linear_Horizontal(); - } - }, - { - title: "UILayoutTest_Layout_Relative", - func: function () { - return new UILayoutTest_Layout_Relative(); - } - }, - { - title: "UILayoutTest_Layout_Relative_Align_Parent", - func: function () { - return new UILayoutTest_Layout_Relative_Align_Parent(); - } - }, - { - title: "UILayoutTest_Layout_Relative_Location", - func: function () { - return new UILayoutTest_Layout_Relative_Location(); - } - }, - { - title: "UILayoutComponent_Berth_Test", - func: function () { - return new UILayoutComponent_Berth_Test(); - } - }, - { - title: "UILayoutComponent_Berth_Stretch_Test", - func: function () { - return new UILayoutComponent_Berth_Stretch_Test(); - } - } - ], - "UIScrollView": [ - { - title: "UIScrollViewTest_Vertical", - func: function () { - return new UIScrollViewTest_Vertical(); - } - }, - { - title: "UIScrollViewTest_Horizontal", - func: function () { - return new UIScrollViewTest_Horizontal(); - } - }, - { - title: "UIScrollViewTest_Both", - func: function () { - return new UIScrollViewTest_Both(); - } - }, - { - title: "UIScrollViewTest_ScrollToPercentBothDirection", - func: function () { - return new UIScrollViewTest_ScrollToPercentBothDirection(); - } - }, - { - title: "UIScrollViewTest_ScrollToPercentBothDirection_Bounce", - func: function () { - return new UIScrollViewTest_ScrollToPercentBothDirection_Bounce(); - } - }, - { - title: "UIScrollViewNestTest", - func: function () { - return new UIScrollViewNestTest(); - } - }, - { - title: "UIScrollViewRotated", - func: function () { - return new UIScrollViewRotated(); - } - }, - { - title: "UIScrollViewDisableTest", - func: function () { - return new UIScrollViewDisableTest(); - } - }, - { - title:"UIScrollView Multiple Items Test", - func: function () { - return new UIScrollViewTest_Vertical_Multiple(); - } - } - ], - "UIPageView": [ - { - title: "UIPageViewTest", - func: function () { - return new UIPageViewTest(); - } - }, - { - title: "UIPageViewButtonTest", - func: function () { - return new UIPageViewButtonTest(); - } - }, - { - title: "UIPageViewCustomScrollThreshold", - func: function () { - return new UIPageViewCustomScrollThreshold(); - } - }, - { - title: "UIPageViewTouchPropagationTest", - func: function () { - return new UIPageViewTouchPropagationTest(); - } - }, - { - title: "UIPageViewDynamicAddAndRemoveTest", - func: function () { - return new UIPageViewDynamicAddAndRemoveTest(); - } - }, - { - title: "UIPageViewDisableTouchTest", - func: function () { - return new UIPageViewDisableTouchTest(); - } - } - ], - "UIListView": [ - { - title: "UIListViewTest_Vertical", - func: function () { - return new UIListViewTest_Vertical(); - } - }, - { - title: "UIListViewTest_Horizontal", - func: function () { - return new UIListViewTest_Horizontal(); - } - }, - { - title:"UIListViewTest_TouchIntercept ", - func: function() { - return new UIListViewTest_TouchIntercept(); - } - } - ], - "UIWidget": [ - { - title: "UIWidgetAddNodeTest", - func: function () { - return new UIWidgetAddNodeTest(); - } - } - ], - "UIRichText": [ - { - title: "UIRichTextTest", - func: function () { - return new UIRichTextTest(); - } - } - ] - }; - - if (cc.sys.isNative) { - testingItems["UIS9NinePatchTest"] = [ - { - title: "UIS9NinePatchTest", - func: function () { - return new UIS9NinePatchTest(); - } - } - ]; - } - - if (cc.sys.os == cc.sys.OS_ANDROID || cc.sys.os == cc.sys.OS_IOS || !cc.sys.isNative) - { - testingItems["UIWebViewTest"] = [ - { - title: "UIWebViewTest", - func: function () { - return new UIWebViewTest(); - } - } - ]; - } - - var guiTestScene = null; - global.GUITestScene = cc.Class.extend({ - - runThisTest: function(){ - if(guiTestScene === null || !cc.sys.isObjectValid(guiTestScene)) - guiTestScene = new listScene; - cc.director.runScene(guiTestScene); - } - - }); - - var listScene = TestScene.extend({ - - ctor: function(){ - TestScene.prototype.ctor.call(this); - - var menu = new cc.Menu(); - menu.x = 0; - menu.y = 0; - var index = 0; - for(var p in testingItems){ - (function(name, list){ - var label = new cc.LabelTTF(name, "Arial", 24); - var menuItem = new cc.MenuItemLabel(label, function(){ - currentTestingArray = list; - var manager = global.UISceneManager.getInstance(); - var scene = manager.currentUIScene(); - cc.director.runScene(scene); - }, this); - menuItem.x = winSize.width / 2; - menuItem.y = (winSize.height - (index++ + 1) * 25); - index++; - menu.addChild(menuItem); - })(p, testingItems[p]); - } - - this._menu = menu; - this.addChild(menu); - - this._length = 0; - for(var p in testingItems){ - this._length++; - } - }, - - onEnter: function(){ - TestScene.prototype.onEnter.call(this); - if ('touches' in cc.sys.capabilities) - cc.eventManager.addListener({ - event: cc.EventListener.TOUCH_ALL_AT_ONCE, - onTouchesMoved: function (touches, event) { - var target = event.getCurrentTarget(); - var delta = touches[0].getDelta(); - target.moveMenu(delta); - return true; - } - }, this); - else if ('mouse' in cc.sys.capabilities) { - cc.eventManager.addListener({ - event: cc.EventListener.MOUSE, - onMouseMove: function (event) { - if (event.getButton() == cc.Event.EventMouse.BUTTON_LEFT) - event.getCurrentTarget().moveMenu(event.getDelta()); - }, - onMouseScroll: function (event) { - var delta = cc.sys.isNative ? event.getScrollY() * 6 : -event.getScrollY(); - event.getCurrentTarget().moveMenu({y: delta}); - return true; - } - }, this); - } - }, - - moveMenu: function(delta){ - var newY = this._menu.y + delta.y; - if (newY < 0 ) - newY = 0; - - if( newY > ((this._length + 1) * 49 - winSize.height)) - newY = ((this._length + 1) * 49 - winSize.height); - - this._menu.y = newY; - } - }); - - global.UISceneManager = { - - _currentUISceneId: 0, - - ctor: function () { - this._currentUISceneId = 0; - }, - - nextUIScene: function () { - this._currentUISceneId++; - if (this._currentUISceneId > currentTestingArray.length - 1) { - this._currentUISceneId = 0; - } - return this.currentUIScene(); - }, - - previousUIScene: function () { - this._currentUISceneId--; - if (this._currentUISceneId < 0) { - this._currentUISceneId = currentTestingArray.length - 1; - } - return this.currentUIScene(); - }, - - currentUIScene: function () { - var test = currentTestingArray[this._currentUISceneId]; - var layer = test.func(); - layer.init(); - layer.setSceneTitle(test.title); - var scene = new UIScene(); - scene.addChild(layer); - return scene; - } - }; - - global.UISceneManager.getInstance = function () { - return this; - }; - - global.UISceneManager.purge = function (){ - this._currentUISceneId = 0; - }; - -})(window); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js b/test/visual-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js deleted file mode 100644 index e7f9528626..0000000000 --- a/test/visual-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js +++ /dev/null @@ -1,598 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var UIScrollViewTest_Vertical = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("Move by vertical direction"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - this._bottomDisplayLabel.setString("ScrollView"); - this._bottomDisplayLabel.x = widgetSize.width / 2; - this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; - - var background = this._backgroundSize; - - // Create the scrollview - var scrollView = new ccui.ScrollView(); - scrollView.setDirection(ccui.ScrollView.Dir.VERTICAL); - scrollView.setTouchEnabled(true); - scrollView.setContentSize(cc.size(280, 150)); - - scrollView.x = (widgetSize.width - background.width) / 2 + (background.width - scrollView.width) / 2; - scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollView.height) / 2; - this._mainNode.addChild(scrollView); - - var imageView = new ccui.ImageView(); - imageView.loadTexture("ccs-res/cocosui/ccicon.png"); - - var innerWidth = scrollView.width; - var innerHeight = scrollView.height + imageView.height; - - scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight)); - - var button = new ccui.Button(); - button.setTouchEnabled(true); - button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", ""); - button.x = innerWidth / 2; - button.y = scrollView.getInnerContainerSize().height - button.height / 2; - scrollView.addChild(button); - - var textButton = new ccui.Button(); - textButton.setTouchEnabled(true); - textButton.loadTextures("ccs-res/cocosui/backtotopnormal.png", "ccs-res/cocosui/backtotoppressed.png", ""); - textButton.setTitleText("Text Button"); - textButton.x = innerWidth / 2; - textButton.y = button.getBottomBoundary() - button.height; - scrollView.addChild(textButton); - - var button_scale9 = new ccui.Button(); - button_scale9.setTouchEnabled(true); - button_scale9.setScale9Enabled(true); - button_scale9.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", ""); - button_scale9.width = 100; - button_scale9.height = 32; - button_scale9.x = innerWidth / 2; - button_scale9.y = textButton.getBottomBoundary() - textButton.height; - scrollView.addChild(button_scale9); - - imageView.x = innerWidth / 2; - imageView.y = imageView.height / 2; - scrollView.addChild(imageView); - - return true; - } - return false; - } -}); - -var UIScrollViewTest_Horizontal = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("Move by horizontal direction"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - this._bottomDisplayLabel.setString("ScrollView"); - this._bottomDisplayLabel.x = widgetSize.width / 2; - this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; - - var background = this._backgroundSize; - - // Create the scrollview - var scrollView = new ccui.ScrollView(); - scrollView.setDirection(ccui.ScrollView.Dir.HORIZONTAL); - scrollView.setTouchEnabled(true); - scrollView.setContentSize(cc.size(280, 150)); - var scrollViewRect = scrollView.getContentSize(); - scrollView.setInnerContainerSize(cc.size(scrollViewRect.width,scrollViewRect.height)); - - scrollView.x = (widgetSize.width - background.width) / 2 + (background.width - scrollViewRect.width) / 2; - scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollViewRect.height) / 2; - this._mainNode.addChild(scrollView); - - var imageView = new ccui.ImageView(); - imageView.loadTexture("ccs-res/cocosui/ccicon.png"); - - var innerWidth = scrollViewRect.width + imageView.getContentSize().width; - var innerHeight = scrollViewRect.height; - - scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight)); - - var button = new ccui.Button(); - button.setTouchEnabled(true); - button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", ""); - button.x = button.width / 2; - button.y = scrollView.getInnerContainerSize().height - button.height / 2; - scrollView.addChild(button); - - var textButton = new ccui.Button(); - textButton.setTouchEnabled(true); - textButton.loadTextures("ccs-res/cocosui/backtotopnormal.png", "ccs-res/cocosui/backtotoppressed.png", ""); - textButton.setTitleText("Text Button"); - textButton.x = button.getRightBoundary() + button.width / 2; - textButton.y = button.getBottomBoundary() - button.height; - scrollView.addChild(textButton); - - var button_scale9 = new ccui.Button(); - button_scale9.setTouchEnabled(true); - button_scale9.setScale9Enabled(true); - button_scale9.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", ""); - button_scale9.width = 100; - button_scale9.height = 32; - button_scale9.x = textButton.getRightBoundary() + textButton.width / 2; - button_scale9.y = textButton.getBottomBoundary() - textButton.height; - scrollView.addChild(button_scale9); - - imageView.x = innerWidth - imageView.width / 2; - imageView.y = button_scale9.getBottomBoundary() - button_scale9.height / 2; - scrollView.addChild(imageView); - - return true; - } - return false; - } -}); - -var UIScrollViewTest_Both = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("Move by any direction"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - this._bottomDisplayLabel.setString("ScrollView both"); - this._bottomDisplayLabel.x = widgetSize.width / 2; - this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; - - var background = this._backgroundSize; - - // Create the scrollview - var scrollView = new ccui.ScrollView(); - scrollView.setDirection(ccui.ScrollView.Dir.BOTH); - scrollView.setTouchEnabled(true); - scrollView.setBounceEnabled(true); - scrollView.setBackGroundImageScale9Enabled(true); - scrollView.setBackGroundImage("ccs-res/cocosui/green_edit.png"); - scrollView.setContentSize(cc.size(210, 122)); - var scrollViewSize = scrollView.getContentSize(); - - scrollView.x = (widgetSize.width - background.width) / 2 + (background.width - scrollViewSize.width) / 2; - scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollViewSize.height) / 2; - this._mainNode.addChild(scrollView); - - var imageView = new ccui.ImageView(); - imageView.loadTexture("ccs-res/cocosui/b11.png"); - scrollView.addChild(imageView); - - scrollView.setInnerContainerSize(cc.size(imageView.width, imageView.height)); - imageView.x = imageView.width/2; - imageView.y = imageView.height/2; - - return true; - } - return false; - } -}); - -var UIScrollViewTest_ScrollToPercentBothDirection = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString(""); - this._bottomDisplayLabel.setString("ScrollView scroll to percent both directrion"); - this._bottomDisplayLabel.x = widgetSize.width / 2; - this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; - - var background = this._backgroundSize; - - // Create the scrollview - var scrollView = new ccui.ScrollView(); - scrollView.setTouchEnabled(true); - scrollView.setBackGroundColor(cc.Color.GREEN); - scrollView.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID); - scrollView.setDirection(ccui.ScrollView.Dir.BOTH); - scrollView.setInnerContainerSize(cc.size(480, 320)); - scrollView.setContentSize(cc.size(100, 100)); - var scrollViewSize = scrollView.getContentSize(); - - scrollView.x = (widgetSize.width - background.width) / 2 + (background.width - scrollViewSize.width) / 2; - scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollViewSize.height) / 2; - scrollView.scrollToPercentBothDirection(cc.p(50, 50), 1, true); - - this._mainNode.addChild(scrollView); - - var imageView = new ccui.ImageView(); - imageView.loadTexture("ccs-res/cocosui/Hello.png"); - imageView.x = 240; - imageView.y = 160; - scrollView.addChild(imageView); - - return true; - } - return false; - } -}); - -var UIScrollViewTest_ScrollToPercentBothDirection_Bounce = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString(""); - this._bottomDisplayLabel.setString("ScrollView scroll to percent both directrion bounce"); - this._bottomDisplayLabel.x = widgetSize.width / 2; - this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; - - var background = this._backgroundSize; - - // Create the scrollview - var scrollView = new ccui.ScrollView(); - scrollView.setTouchEnabled(true); - scrollView.setBounceEnabled(true); - scrollView.setBackGroundColor(cc.Color.GREEN); - scrollView.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID); - scrollView.setDirection(ccui.ScrollView.Dir.BOTH); - scrollView.setInnerContainerSize(cc.size(480, 320)); - scrollView.setContentSize(cc.size(100, 100)); - var scrollViewSize = scrollView.getContentSize(); - - scrollView.x = (widgetSize.width - background.width) / 2 + (background.width - scrollViewSize.width) / 2; - scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollViewSize.height) / 2; - scrollView.scrollToPercentBothDirection(cc.p(50, 50), 1, true); - - this._mainNode.addChild(scrollView); - - var imageView = new ccui.ImageView(); - imageView.loadTexture("ccs-res/cocosui/Hello.png"); - imageView.x = 240; - imageView.y = 160; - scrollView.addChild(imageView); - - return true; - } - return false; - } -}); - -//2015-01-14 -var UIScrollViewNestTest = UIMainLayer.extend({ - init: function(){ - if(this._super()){ - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the scrollview alert will be displayed - this._topDisplayLabel.setString("Move by vertical direction"); - - // Add the alert - this._bottomDisplayLabel.setString("ScrollView vertical"); - this._bottomDisplayLabel.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - this._bottomDisplayLabel.height * 3.075); - - // Create the scrollview by vertical - var scrollView = new ccui.ScrollView(); - scrollView.setContentSize(cc.size(280.0, 150.0)); - scrollView.setDirection(ccui.ScrollView.Dir.BOTH); - var backgroundSize = this._backgroundSize; - scrollView.setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2.0 + - (backgroundSize.width - scrollView.getContentSize().width) / 2.0, - (widgetSize.height - backgroundSize.height) / 2.0 + - (backgroundSize.height - scrollView.getContentSize().height) / 2.0)); - this._mainNode.addChild(scrollView); - - var imageView = new ccui.ImageView("ccs-res/cocosui/ccicon.png"); - - var innerWidth = scrollView.getContentSize().width; - var innerHeight = scrollView.getContentSize().height + imageView.getContentSize().height; - - scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight)); - - var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - button.setPosition(cc.p(innerWidth / 2.0, scrollView.getInnerContainerSize().height - button.getContentSize().height / 2.0)); - scrollView.addChild(button); - - var titleButton = new ccui.Button("ccs-res/cocosui/backtotopnormal.png", "ccs-res/cocosui/backtotoppressed.png"); - titleButton.setTitleText("Title Button"); - titleButton.setPosition(cc.p(innerWidth / 2.0, button.getBottomBoundary() - button.getContentSize().height)); - scrollView.addChild(titleButton); - - var button_scale9 = new ccui.Button("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png"); - button_scale9.setScale9Enabled(true); - button_scale9.setContentSize(cc.size(100.0, button_scale9.getVirtualRendererSize().height)); - button_scale9.setPosition(cc.p(innerWidth / 2.0, titleButton.getBottomBoundary() - titleButton.getContentSize().height)); - scrollView.addChild(button_scale9); - - imageView.setPosition(cc.p(innerWidth / 2.0, imageView.getContentSize().height / 2.0)); - scrollView.addChild(imageView); - - // Create the scrollview by horizontal - var sc = new ccui.ScrollView(); - sc.setBackGroundColor(cc.Color.GREEN); - sc.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID); - sc.setBounceEnabled(true); - sc.setDirection(ccui.ScrollView.Dir.BOTH); - sc.setInnerContainerSize(cc.size(480, 320)); - sc.setContentSize(cc.size(100,100)); - sc.setPropagateTouchEvents(false); - sc.setPosition(cc.p(180,100)); - sc.scrollToPercentBothDirection(cc.p(50, 50), 1, true); - var iv = new ccui.ImageView("ccs-res/cocosui/Hello.png"); - iv.setPosition(cc.p(240, 160)); - sc.addChild(iv); - scrollView.addChild(sc); - - return true; - } - } - -}); - -//2015-01-14 -var UIScrollViewRotated = UIMainLayer.extend({ - init: function(){ - if(this._super()){ - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the scrollview alert will be displayed - this._topDisplayLabel.setString("Move by vertical direction"); - - // Add the alert - this._bottomDisplayLabel.setString("ScrollView vertical"); - this._bottomDisplayLabel.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - this._bottomDisplayLabel.height * 3.075); - - // Create the scrollview by vertical - var scrollView = new ccui.ScrollView(); - scrollView.setContentSize(cc.size(280.0, 150.0)); - scrollView.setDirection(ccui.ScrollView.Dir.BOTH); - var backgroundSize = this._backgroundSize; - scrollView.setPosition(cc.p((widgetSize.width - backgroundSize.width) / 2.0 + - (backgroundSize.width - scrollView.getContentSize().width) / 2.0, - (widgetSize.height - backgroundSize.height) / 2.0 + - (backgroundSize.height - scrollView.getContentSize().height) / 2.0 + 100) ); - scrollView.setRotation(45); - this._mainNode.addChild(scrollView); - - var imageView = new ccui.ImageView("ccs-res/cocosui/ccicon.png"); - - var innerWidth = scrollView.getContentSize().width; - var innerHeight = scrollView.getContentSize().height + imageView.getContentSize().height; - scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight)); - - var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png"); - button.setPosition(cc.p(innerWidth / 2.0, scrollView.getInnerContainerSize().height - button.getContentSize().height / 2.0)); - scrollView.addChild(button); - - var titleButton = new ccui.Button("ccs-res/cocosui/backtotopnormal.png", "ccs-res/cocosui/backtotoppressed.png"); - titleButton.setTitleText("Title Button"); - titleButton.setPosition(cc.p(innerWidth / 2.0, button.getBottomBoundary() - button.getContentSize().height)); - scrollView.addChild(titleButton); - - var button_scale9 = new ccui.Button("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png"); - button_scale9.setScale9Enabled(true); - button_scale9.setContentSize(cc.size(100.0, button_scale9.getVirtualRendererSize().height)); - button_scale9.setPosition(cc.p(innerWidth / 2.0, titleButton.getBottomBoundary() - titleButton.getContentSize().height)); - scrollView.addChild(button_scale9); - - imageView.setPosition(cc.p(innerWidth / 2.0, imageView.getContentSize().height / 2.0)); - scrollView.addChild(imageView); - - return true; - } - } -}); - -var UIScrollViewDisableTest = UIMainLayer.extend({ - init: function () { - if (this._super()){ - var widgetSize = this._widget.getContentSize(); - - this._topDisplayLabel.setString("ScrollView Disable Test"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - - this._bottomDisplayLabel.setString("ScrollView vertical"); - this._bottomDisplayLabel.x = widgetSize.width / 2; - this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; - - var backgroundSize = this._backgroundSize; - - var scrollView = new ccui.ScrollView(); - scrollView.setContentSize(cc.size(280, 150)); - scrollView.x = (widgetSize.width - backgroundSize.width) / 2 + (backgroundSize.width - scrollView.width) / 2; - scrollView.y = (widgetSize.height - backgroundSize.height) / 2 + (backgroundSize.height - scrollView.height) / 2; - scrollView.setTouchEnabled(false); - - this._mainNode.addChild(scrollView); - - var imageView = new ccui.ImageView(); - imageView.loadTexture("ccs-res/cocosui/ccicon.png"); - - var innerWidth = scrollView.width; - var innerHeight = scrollView.height + imageView.height; - - scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight)); - - var button = new ccui.Button(); - button.setTouchEnabled(true); - button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", ""); - button.x = innerWidth / 2; - button.y = scrollView.getInnerContainerSize().height - button.height / 2; - scrollView.addChild(button); - - var textButton = new ccui.Button(); - textButton.setTouchEnabled(true); - textButton.loadTextures("ccs-res/cocosui/backtotopnormal.png", "ccs-res/cocosui/backtotoppressed.png", ""); - textButton.setTitleText("Text Button"); - textButton.x = innerWidth / 2; - textButton.y = button.getBottomBoundary() - button.height; - scrollView.addChild(textButton); - - var button_scale9 = new ccui.Button(); - button_scale9.setTouchEnabled(true); - button_scale9.setScale9Enabled(true); - button_scale9.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", ""); - button_scale9.width = 100; - button_scale9.height = 32; - button_scale9.x = innerWidth / 2; - button_scale9.y = textButton.getBottomBoundary() - textButton.height; - scrollView.addChild(button_scale9); - - imageView.setPosition(cc.p(innerWidth/2, imageView.getContentSize().height/2)); - scrollView.addChild(imageView); - - return true; - } - return false; - } -}); - -var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({ - _scrollView:null, - _itemNumber:1000, - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("Move by vertical direction"); - this._topDisplayLabel.x = widgetSize.width / 2.0; - this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; - this._bottomDisplayLabel.setString("Compare drawCalls and FPS with Previous Version"); - this._bottomDisplayLabel.setFontSize(25); - this._bottomDisplayLabel.x = widgetSize.width / 2; - this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 4; - - var background = this._backgroundSize; - - // Create the scrollview - var scrollView = this._scrollView = new ccui.ScrollView(); - scrollView.setDirection(ccui.ScrollView.Dir.VERTICAL); - scrollView.setTouchEnabled(true); - scrollView.setContentSize(cc.size(280, 150)); - - scrollView.x = (widgetSize.width - background.width) / 2 + (background.width - scrollView.width) / 2; - scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollView.height) / 2; - this._mainNode.addChild(scrollView); - - var labelText = new cc.LabelTTF("Texts", "Arial", 25); - var labelButton = new cc.LabelTTF("Buttons", "Arial", 25); - var labelS9sprite = new cc.LabelTTF("s9Sprites", "Arial", 25); - - var menuItem1 = new cc.MenuItemLabel(labelText, this.drawTexts, this); - var menuItem2 = new cc.MenuItemLabel(labelButton, this.drawButtons, this, false); - var menuItem3 = new cc.MenuItemLabel(labelS9sprite, this.drawS9Buttons, this); - var menu = new cc.Menu(menuItem1, menuItem2, menuItem3); - menu.x = 0; - menu.y = 0; - menuItem1.x = menuItem2.x = menuItem3.x = 120; - menuItem1.y = 150; - menuItem2.y = 200; - menuItem3.y = 250; - this.addChild(menu, 1); - this.drawTexts(); - return true; - } - return false; - }, - drawTexts:function() { - var scrollView = this._scrollView; - var n = this._itemNumber/2; - if(scrollView.getChildren()) - scrollView.removeAllChildren(true); - var Texts = []; - var start = new ccui.Text("---start---", "Thonburi", 10); - var innerWidth = scrollView.width; - var innerHeight = n * start.height; - scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight)); - - start.x = innerWidth / 2; - start.y = scrollView.getInnerContainerSize().height - start.height / 2; - Texts[0] = start; - scrollView.addChild(start); - - for (var i = 1; i < n; i++) { - var text = new ccui.Text("This is a test label: " + i, "Thonburi", 10); - text.x = innerWidth / 2; - text.y = Texts[i - 1].getBottomBoundary() - text.height / 2; - Texts[i] = text; - scrollView.addChild(Texts[i]); - } - }, - drawButtons:function() { - var scrollView = this._scrollView; - var n = this._itemNumber/2; - if(scrollView.getChildren()) - scrollView.removeAllChildren(true); - var Buttons = []; - var innerWidth = scrollView.width; - - for (var j = 0; j < n; j++) { - var button = new ccui.Button(); - button.setTouchEnabled(true); - button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", ""); - button.x = innerWidth / 2; - if(j===0) { - var innerHeight = n * button.height; - scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight)); - button.y =scrollView.getInnerContainerSize().height - button.height / 2; - } - else - button.y =Buttons[j - 1].getBottomBoundary() - button.height / 2; - Buttons.push(button); - scrollView.addChild(button); - } - - }, - drawS9Buttons: function() { - var scrollView = this._scrollView; - var n = this._itemNumber; - if(scrollView.getChildren()) - scrollView.removeAllChildren(true); - var Buttons = []; - var innerWidth = scrollView.width; - - for (var j = 0; j < n; j++) { - var button_scale9 = new ccui.Button(); - button_scale9.setTouchEnabled(true); - button_scale9.setScale9Enabled(true); - button_scale9.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", ""); - button_scale9.width = 100; - button_scale9.height = 32; - button_scale9.x = innerWidth / 2; - if(j === 0) { - var innerHeight = n * 32; - scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight)); - button_scale9.y = scrollView.getInnerContainerSize().height - button_scale9.height / 2; - } - else - button_scale9.y = Buttons[j-1].getBottomBoundary() - button_scale9.height / 2; - Buttons.push(button_scale9); - scrollView.addChild(button_scale9); - } - } -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UISliderTest/UISliderTest.js b/test/visual-tests/src/GUITest/UISliderTest/UISliderTest.js deleted file mode 100644 index 128e240862..0000000000 --- a/test/visual-tests/src/GUITest/UISliderTest/UISliderTest.js +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var UISliderTest = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("Move the slider thumb"); - this._bottomDisplayLabel.setString("Slider"); - - // Create the slider - var slider = new ccui.Slider(); - slider.setTouchEnabled(true); - slider.loadBarTexture("ccs-res/cocosui/sliderTrack.png"); - slider.loadSlidBallTextures("ccs-res/cocosui/sliderThumb.png", "ccs-res/cocosui/sliderThumb.png", ""); - slider.loadProgressBarTexture("ccs-res/cocosui/sliderProgress.png"); - slider.x = widgetSize.width / 2.0; - slider.y = widgetSize.height / 2.0; - slider.addEventListener(this.sliderEvent, this); - this._mainNode.addChild(slider); - - return true; - } - return false; - }, - - sliderEvent: function (sender, type) { - switch (type) { - case ccui.Slider.EVENT_PERCENT_CHANGED: - var slider = sender; - var percent = slider.getPercent(); - this._topDisplayLabel.setString("Percent " + percent.toFixed(0)); - break; - default: - break; - } - } -}); - -var UISliderTest_Scale9 = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("Move the slider thumb"); - this._bottomDisplayLabel.setString("Slider scale9 render"); - - // Create the slider - var slider = new ccui.Slider(); - slider.setTouchEnabled(true); - slider.setScale9Enabled(true); - slider.loadBarTexture("ccs-res/cocosui/sliderTrack2.png"); - slider.loadSlidBallTextures("ccs-res/cocosui/sliderThumb.png", "ccs-res/cocosui/sliderThumb.png", ""); - slider.loadProgressBarTexture("ccs-res/cocosui/slider_bar_active_9patch.png"); - slider.setCapInsets(cc.rect(0, 0, 0, 0)); - slider.setContentSize(cc.size(250, 10)); - slider.x = widgetSize.width / 2.0; - slider.y = widgetSize.height / 2.0; - slider.addEventListener(this.sliderEvent, this); - this._mainNode.addChild(slider); - - return true; - } - return false; - }, - - sliderEvent: function (sender, type) { - switch (type) { - case ccui.Slider.EVENT_PERCENT_CHANGED: - var slider = sender; - var percent = slider.getPercent(); - this._topDisplayLabel.setString("Percent " + percent.toFixed(0)); - break; - default: - break; - } - } -}); - -//2015-01-14 -var UISliderNormalDefaultTest = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - this._bottomDisplayLabel.setString(""); - - // Add the alert - var alert = new ccui.Text("when pressed, the slider ball should scale","Marker Felt",20); - alert.setColor(cc.color(159, 168, 176)); - alert.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - alert.height * 3.75)); - this._mainNode.addChild(alert); - - // Create the slider - var slider = new ccui.Slider(); - slider.loadBarTexture("ccs-res/cocosui/sliderTrack.png"); - slider.loadSlidBallTextures("ccs-res/cocosui/sliderThumb.png"); - slider.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + 50)); - this._mainNode.addChild(slider); - - var sliderScale9 = new ccui.Slider("ccs-res/cocosui/sliderTrack2.png", "ccs-res/cocosui/sliderThumb.png"); - sliderScale9.setScale9Enabled(true); - sliderScale9.setCapInsets(cc.rect(0, 0, 0, 0)); - sliderScale9.setZoomScale(1); - sliderScale9.setContentSize(cc.size(250, 19)); - sliderScale9.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - 20)); - this._mainNode.addChild(sliderScale9); - - - return true; - } - return false; - } -}); - -//2015-01-14 -var UISliderDisabledDefaultTest = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - this._bottomDisplayLabel.setString(""); - - // Add the alert - var alert = new ccui.Text("slider ball should be gray.","Marker Felt",20); - alert.setColor(cc.color(159, 168, 176)); - alert.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - alert.height * 3.75)); - this._mainNode.addChild(alert); - - // Create the slider - var slider = new ccui.Slider(); - slider.loadBarTexture("ccs-res/cocosui/slidbar.png"); - slider.loadSlidBallTextureNormal("ccs-res/cocosui/sliderballnormal.png"); - slider.setEnabled(false); - slider.setBright(false); - slider.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + 50)); - this._mainNode.addChild(slider); - - var sliderScale9 = new ccui.Slider("ccs-res/cocosui/slidbar.png", "ccs-res/cocosui/sliderballnormal.png"); - sliderScale9.setScale9Enabled(true); - sliderScale9.setEnabled(false); - sliderScale9.setBright(false); - sliderScale9.setCapInsets(cc.rect(0, 0, 0, 0)); - sliderScale9.setContentSize(cc.size(250, 10)); - sliderScale9.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - 20)); - this._mainNode.addChild(sliderScale9); - - return true; - } - return false; - } -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UITextFieldTest/UITextFieldTest.js b/test/visual-tests/src/GUITest/UITextFieldTest/UITextFieldTest.js deleted file mode 100644 index 4f344a6abe..0000000000 --- a/test/visual-tests/src/GUITest/UITextFieldTest/UITextFieldTest.js +++ /dev/null @@ -1,339 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -var UITextFieldTest = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("No Event"); - this._topDisplayLabel.setAnchorPoint(cc.p(0.5, -1)); - this._topDisplayLabel.setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 + this._topDisplayLabel.getContentSize().height * 1.5)); - - this._bottomDisplayLabel.setString("TextField"); - this._bottomDisplayLabel.setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - this._bottomDisplayLabel.getContentSize().height * 3.4)); - this._bottomDisplayLabel.setColor(cc.color(255, 255, 255, 255)); - - // Create the textfield - var textField = new ccui.TextField("PlaceHolder", "Marker Felt", 30); - textField.x = widgetSize.width / 2.0; - textField.y = widgetSize.height / 2.0; - textField.addEventListener(this.textFieldEvent, this); - this._mainNode.addChild(textField); - - return true; - } - return false; - }, - - textFieldEvent: function (textField, type) { - switch (type) { - case ccui.TextField.EVENT_ATTACH_WITH_IME: - var widgetSize = this._widget.getContentSize(); - textField.runAction(cc.moveTo(0.225, - cc.p(widgetSize.width / 2, widgetSize.height / 2 + 30))); - this._topDisplayLabel.setString("attach with IME"); - break; - case ccui.TextField.EVENT_DETACH_WITH_IME: - var widgetSize = this._widget.getContentSize(); - textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0))); - this._topDisplayLabel.setString("detach with IME"); - break; - case ccui.TextField.EVENT_INSERT_TEXT: - this._topDisplayLabel.setString("insert words"); - break; - case ccui.TextField.EVENT_DELETE_BACKWARD: - this._topDisplayLabel.setString("delete word"); - break; - default: - break; - } - } -}); - -var UITextFieldTest_MaxLength = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("No Event"); - this._bottomDisplayLabel.setString("TextField max length"); - - // Create the textfield - var textField = new ccui.TextField(); - textField.setMaxLengthEnabled(true); - textField.setMaxLength(3); - textField.setTouchEnabled(true); - textField.fontName = "Marker Felt"; - textField.fontSize = 30; - textField.placeHolder = "input words here"; - textField.x = widgetSize.width / 2.0; - textField.y = widgetSize.height / 2.0; - textField.addEventListener(this.textFieldEvent, this); - this._mainNode.addChild(textField); - - return true; - } - return false; - }, - - textFieldEvent: function (sender, type) { - var textField = sender; - var widgetSize = this._widget.getContentSize(); - switch (type) { - case ccui.TextField.EVENT_ATTACH_WITH_IME: - textField.runAction(cc.moveTo(0.225, - cc.p(widgetSize.width / 2, widgetSize.height / 2 + textField.height / 2))); - this._topDisplayLabel.setString("attach with IME max length:" + textField.getMaxLength()); - break; - case ccui.TextField.EVENT_DETACH_WITH_IME: - textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0))); - this._topDisplayLabel.setString("detach with IME max length:" + textField.getMaxLength()); - break; - case ccui.TextField.EVENT_INSERT_TEXT: - this._topDisplayLabel.setString("insert with IME max length:" + textField.getMaxLength()); - break; - case ccui.TextField.EVENT_DELETE_BACKWARD: - this._topDisplayLabel.setString("delete with IME max length:" + textField.getMaxLength()); - break; - default: - break; - } - this._bottomDisplayLabel.setString(textField.getString()); - } -}); - -var UITextFieldTest_Password = UIMainLayer.extend({ - init: function () { - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - //init text - this._topDisplayLabel.setString("No Event"); - this._bottomDisplayLabel.setString("TextField max length"); - - // Create the textfield - var textField = new ccui.TextField(); - textField.setPasswordEnabled(true); - textField.setPasswordStyleText("*"); - textField.setTouchEnabled(true); - textField.fontName = "Marker Felt"; - textField.fontSize = 30; - textField.placeHolder = "input password here"; - textField.x = widgetSize.width / 2.0; - textField.y = widgetSize.height / 2.0; - textField.addEventListener(this.textFieldEvent, this); - this._mainNode.addChild(textField); - - return true; - } - return false; - }, - - textFieldEvent: function (textField, type) { - var widgetSize = this._widget.getContentSize(); - switch (type) { - case ccui.TextField.EVENT_ATTACH_WITH_IME: - textField.runAction(cc.moveTo(0.225, - cc.p(widgetSize.width / 2, widgetSize.height / 2 + textField.height / 2))); - this._topDisplayLabel.setString("attach with IME IME password"); - break; - case ccui.TextField.EVENT_DETACH_WITH_IME: - textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0))); - this._topDisplayLabel.setString("detach with IME password"); - break; - case ccui.TextField.EVENT_INSERT_TEXT: - this._topDisplayLabel.setString("insert with IME password"); - break; - case ccui.TextField.EVENT_DELETE_BACKWARD: - this._topDisplayLabel.setString("delete with IME password"); - break; - default: - break; - } - this._bottomDisplayLabel.setString(textField.getString()); - } -}); - -//2015-01-14 -var UITextFieldTest_LineWrap = UIMainLayer.extend({ - - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the textfield events will be displayed - this._topDisplayLabel.setString("No Event"); - this._topDisplayLabel.setPosition(widgetSize.width / 2, widgetSize.height / 2 + this._topDisplayLabel.height * 1.5); - this._bottomDisplayLabel.setString(""); - - // Add the alert - var alert = new ccui.Text("TextField line wrap","Marker Felt",30); - alert.setColor(cc.color(159, 168, 176)); - alert.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - alert.height * 3.075)); - this._mainNode.addChild(alert); - - // Create the textfield - var textField = new ccui.TextField("input words here", "Marker Felt",30); - textField.ignoreContentAdaptWithSize(false); - //textField.getVirtualRenderer().setLineBreakWithoutSpace(true); - textField.setContentSize(240, 120); - textField.setString("input words here"); - textField.setTextHorizontalAlignment(cc.TextAlignment.CENTER); - textField.setTextVerticalAlignment(cc.TextAlignment.CENTER); - textField.setPosition(widgetSize.width / 2, widgetSize.height / 2); - textField.addEventListener(this.textFieldEvent, this); - this._mainNode.addChild(textField); - return true; - } - }, - - textFieldEvent: function(textField, type){ - var widgetSize = this._widget.getContentSize(); - switch (type){ - case ccui.TextField.EVENT_ATTACH_WITH_IME: - textField.runAction(cc.moveTo(0.225, cc.p(widgetSize.width / 2, widgetSize.height / 2 + 30))); - textField.setTextHorizontalAlignment(cc.TextAlignment.LEFT); - textField.setTextVerticalAlignment(cc.VerticalTextAlignment.TOP); - this._topDisplayLabel.setString("attach with IME"); - break; - case ccui.TextField.EVENT_DETACH_WITH_IME: - textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2, widgetSize.height / 2))); - textField.setTextHorizontalAlignment(cc.TextAlignment.CENTER); - textField.setTextVerticalAlignment(cc.TextAlignment.CENTER); - this._topDisplayLabel.setString("detach with IME"); - break; - case ccui.TextField.EVENT_INSERT_TEXT: - this._topDisplayLabel.setString("insert words"); - break; - case ccui.TextField.EVENT_DELETE_BACKWARD: - this._topDisplayLabel.setString("delete word"); - break; - default: - break; - } - this._bottomDisplayLabel.setString(textField.getString()); - } -}); - -//2015-01-14 -var UITextFieldTest_TrueTypeFont = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the textfield events will be displayed - this._topDisplayLabel.setString("True Type Font Test - No Event"); - this._topDisplayLabel.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + this._topDisplayLabel.height * 1.5)); - - // Add the alert - this._bottomDisplayLabel.setString("TextField"); - this._bottomDisplayLabel.setPosition(widgetSize.width / 2, widgetSize.height / 2 - this._bottomDisplayLabel.height * 3.075); - - // Create the textfield - var textField = new ccui.TextField("input words here","Marker Felt",30); - textField.setPosition(widgetSize.width / 2, widgetSize.height / 2); - textField.addEventListener(this.textFieldEvent, this); - this._mainNode.addChild(textField); - return true; - } - }, - - textFieldEvent: function(textField, type){ - var widgetSize = this._widget.getContentSize(); - switch (type){ - case ccui.TextField.EVENT_ATTACH_WITH_IME: - textField.runAction(cc.moveTo(0.225, cc.p(widgetSize.width / 2, widgetSize.height / 2 + textField.height / 2))); - this._topDisplayLabel.setString("attach with IME"); - break; - - case ccui.TextField.EVENT_DETACH_WITH_IME: - textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2, widgetSize.height / 2))); - this._topDisplayLabel.setString("detach with IME"); - break; - - case ccui.TextField.EVENT_INSERT_TEXT: - this._topDisplayLabel.setString("insert words"); - break; - - case ccui.TextField.EVENT_DELETE_BACKWARD: - this._topDisplayLabel.setString("delete word"); - break; - - default: - break; - } - this._bottomDisplayLabel.setString(textField.getString()); - } -}); - -//2015-01-14 -var UITextFieldTest_PlaceHolderColor = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - // Add a label in which the textfield events will be displayed - this._topDisplayLabel.setString("Set place hold color"); - this._topDisplayLabel.setPosition(widgetSize.width / 2, widgetSize.height / 2 + this._topDisplayLabel.height * 1.5); - - // Add the alert - this._bottomDisplayLabel.setString("TextField"); - this._bottomDisplayLabel.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - this._bottomDisplayLabel.height * 3.075)); - - // Create the textfield - var textField = new ccui.TextField("input words here","Arial",30); - textField.setPlaceHolder("input text here"); - textField.setPlaceHolderColor(cc.Color.GREEN); - textField.setTextColor(cc.Color.RED); - textField.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2)); - textField.addEventListener(this.textFieldEvent, this); - this._mainNode.addChild(textField); - return true; - } - }, - - textFieldEvent: function(textField, type){ - var widgetSize = this._widget.getContentSize(); - switch (type){ - case ccui.TextField.EVENT_ATTACH_WITH_IME: - textField.runAction(cc.moveTo(0.225, cc.p(widgetSize.width / 2, widgetSize.height / 2 + textField.height / 2))); - this._topDisplayLabel.setString("attach with IME"); - break; - case ccui.TextField.EVENT_DETACH_WITH_IME: - textField.runAction(cc.moveTo(0.175, cc.p(widgetSize.width / 2, widgetSize.height / 2))); - this._topDisplayLabel.setString("detach with IME"); - break; - case ccui.TextField.EVENT_INSERT_TEXT: - this._topDisplayLabel.setString("insert words"); - break; - case ccui.TextField.EVENT_DELETE_BACKWARD: - this._topDisplayLabel.setString("delete word"); - break; - default: - break; - } - this._bottomDisplayLabel.setString(textField.getString()); - } -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UITextTest/UITextTest.js b/test/visual-tests/src/GUITest/UITextTest/UITextTest.js deleted file mode 100644 index 7249631607..0000000000 --- a/test/visual-tests/src/GUITest/UITextTest/UITextTest.js +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -//2015-01-14 -var UITextTest = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - this._bottomDisplayLabel.setString("Text"); - - // Create the text - var text = new ccui.Text("Text", "AmericanTypewriter", 30); - text.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + text.height / 4)); - this._mainNode.addChild(text); - - return true; - } - } -}); - -//2015-01-14 -var UITextTest_LineWrap = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - this._bottomDisplayLabel.setString("Text line wrap"); - - // Create the line wrap - var text = new ccui.Text("TextArea Widget can line wrap","AmericanTypewriter",32); - text.ignoreContentAdaptWithSize(false); - text.setContentSize(cc.size(280, 150)); - text.setTextHorizontalAlignment(cc.TextAlignment.CENTER); - text.setTouchScaleChangeEnabled(true); - text.setTouchEnabled(true); - text.addTouchEventListener(function(sender, type){ - if (type == ccui.Widget.TOUCH_ENDED){ - if (text.width == 280){ - text.setContentSize(cc.size(380,100)); - }else { - text.setContentSize(cc.size(280, 150)); - } - } - }); - text.setPosition(widgetSize.width / 2, widgetSize.height / 2 - text.height / 8); - this._mainNode.addChild(text); - - return true; - } - } -}); - -//2015-01-14 -var UILabelTest_Effect = UIMainLayer.extend({ - init: function(){ - if (this._super()) { - var widgetSize = this._widget.getContentSize(); - - this._bottomDisplayLabel.setString(""); - - var alert = new ccui.Text(); - alert.setString("Label Effect"); - alert.setFontName("Marker Felt"); - alert.setFontSize(30); - alert.setColor(cc.color(159, 168, 176)); - alert.setPosition(widgetSize.width / 2, widgetSize.height / 2 - alert.height * 3.05); - this._mainNode.addChild(alert); - - // create the shadow only label - var shadow_label = new ccui.Text(); - - shadow_label.enableShadow(cc.Color.GRAY, cc.p(10, -10)); - shadow_label.setString("Shadow"); - shadow_label.setPosition(widgetSize.width / 2, widgetSize.height / 2 + shadow_label.height); - - this._mainNode.addChild(shadow_label); - - // create the stroke only label - var glow_label = new ccui.Text(); - glow_label.setFontName("Marker Felt"); - glow_label.setString("Glow"); - glow_label.enableGlow(cc.Color.RED); - glow_label.setPosition(widgetSize.width / 2, widgetSize.height / 2); - this._mainNode.addChild(glow_label); - - // create the label stroke and shadow - var outline_label = new ccui.Text(); - outline_label.enableOutline(cc.Color.BLUE, 2); - outline_label.setString("Outline"); - outline_label.setPosition(widgetSize.width / 2, widgetSize.height / 2 - shadow_label.height); - - this._mainNode.addChild(outline_label); - - return true; - } - } -}); - -//2015-01-14 -var UITextTest_TTF = UIMainLayer.extend({ - init: function(){ - if(this._super()){ - var widgetSize = this._widget.getContentSize(); - - this._bottomDisplayLabel.setString("Text set TTF font"); - - // Create the text, and set font with .ttf - var text = new ccui.Text("Text","A Damn Mess",30); - text.setPosition(widgetSize.width / 2, widgetSize.height / 2 + text.height / 4); - this._mainNode.addChild(text); - - return true; - } - } -}); - -//2015-01-14 -var UITextTest_IgnoreConentSize = UIMainLayer.extend({ - - init: function(){ - if(this._super()){ - var widgetSize = this._widget.getContentSize(); - - this._bottomDisplayLabel.setString(""); - - var leftText = new ccui.Text("ignore conent", "Marker Felt",10); - leftText.setPosition(cc.p(widgetSize.width / 2 - 50, - widgetSize.height / 2)); - leftText.ignoreContentAdaptWithSize(false); - leftText.setTextAreaSize(cc.size(60,60)); - leftText.setString("Text line with break\nText line with break\nText line with break\nText line with break\n"); - leftText.setTouchScaleChangeEnabled(true); - leftText.setTouchEnabled(true); - this._mainNode.addChild(leftText); - - var rightText = new ccui.Text("ignore conent", "Marker Felt",10); - rightText.setPosition(cc.p(widgetSize.width / 2 + 50, - widgetSize.height / 2)); - rightText.setString("Text line with break\nText line with break\nText line with break\nText line with break\n"); - //note: setTextAreaSize must be used with ignoreContentAdaptWithSize(false) - rightText.setTextAreaSize(cc.size(100,30)); - rightText.ignoreContentAdaptWithSize(false); - this._mainNode.addChild(rightText); - - var halighButton = new ccui.Button(); - halighButton.setTitleText("Alignment Right"); - halighButton.addClickEventListener(function(){ - leftText.setTextHorizontalAlignment(cc.TextAlignment.RIGHT); - rightText.setTextHorizontalAlignment(cc.TextAlignment.RIGHT); - }); - halighButton.setPosition(cc.p(widgetSize.width/2 - 50, - widgetSize.height/2 - 50)); - this._mainNode.addChild(halighButton); - - return true; - } - } - -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js b/test/visual-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js deleted file mode 100644 index 09f6117a66..0000000000 --- a/test/visual-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - - -var UIWebViewTest = UIMainLayer.extend({ - - onEnter: function(){ - UIMainLayer.prototype.onEnter.call(this); - - var webView = new ccui.WebView("http://www.baidu.com"); - webView.setContentSize(320, 240); - webView.setPosition(800/2, 450/2); - webView.setScale(0.5); - webView.setScalesPageToFit(true); - window.webView = webView; - this.addChild(webView); - - var widgetSize = this._widget.getContentSize(); - var playState = this._topDisplayLabel; - playState.setString("Press buttons to start"); - playState.y = widgetSize.height / 2.0 + playState.height * 1.5; - this._bottomDisplayLabel.setString(""); - - var list = [ - { name: "loadURL", func: function(){ - playState.setString("loadURL!"); - webView.loadURL("src/GUITest/UIWebViewTest/webview2.html"); - }}, - { name: "Reload", func: function(){ - playState.setString("reload!"); - webView.reload(); - }}, - { name: "goBack", func: function(){ - if (webView.canGoBack()) - { - playState.setString("goBack!"); - webView.goBack(); - } - else - { - playState.setString("can not goBack!"); - } - }}, - { name: "goForward", func: function(){ - if (webView.canGoForward()) { - playState.setString("goForward!"); - webView.goForward(); - } - else { - playState.setString("can not goForward!"); - } - }}, - { name: "EvaluateJS", func: function(){ - playState.setString("evaluateJS!"); - var code = "alert('evaluateJS!')"; - webView.evaluateJS(code); - }}, - { name: "Scale", func: function(){ - var scale = ((Math.random() * 0.5 + 0.2) * 100 | 0) / 100; - playState.setString("setScale(%f)!", scale); - webView.setScale(scale); - }}, - { name: "setAnchorPoint", func: function(){ - var anpX = video.getAnchorPoint().x === 1 ? 0: video.getAnchorPoint().x+ 0.5; - var anpY = video.getAnchorPoint().y === 1 ? 0: video.getAnchorPoint().y+ 0.5; - webView.setAnchorPoint(anpX, anpY); - }} - ]; - - var layer = this; - list.forEach(function(item, i){ - var button = new ccui.Button(); - i+1 !== list.length ? button.setScale(1.3) : button.setScale(1); - button.setPosition( 140 + (i / 4 | 0) * 530, 320 - (i % 4) * 50); - button.setTitleText(item.name); - button.setTitleColor(cc.Color.YELLOW); - button.setZoomScale(0.3); - button.setPressedActionEnabled(true); - button.addClickEventListener(item.func); - layer.addChild(button); - }); - - } - -}); \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UIWebViewTest/webview.html b/test/visual-tests/src/GUITest/UIWebViewTest/webview.html deleted file mode 100644 index 42154f74fb..0000000000 --- a/test/visual-tests/src/GUITest/UIWebViewTest/webview.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - Test1 - - - -
- Page 1 -
-
- goto page2 -
-
- - \ No newline at end of file diff --git a/test/visual-tests/src/GUITest/UIWebViewTest/webview2.html b/test/visual-tests/src/GUITest/UIWebViewTest/webview2.html deleted file mode 100644 index 24fcc44684..0000000000 --- a/test/visual-tests/src/GUITest/UIWebViewTest/webview2.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - -
- Page 2 -
-
- goto page1 -
-
- - \ No newline at end of file From 9c1de1ac5f5244d88a8fc51ace6dee589f68f1c1 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 21 Jun 2017 11:00:02 +0800 Subject: [PATCH 4/6] update predefine --- index.js | 71 ++++++++++++++++++++++++++++++++++---------- jsb/index.js | 48 +++++++++++++++++++++++++++++- jsb/jsb-predefine.js | 71 -------------------------------------------- predefine.js | 43 +-------------------------- 4 files changed, 104 insertions(+), 129 deletions(-) delete mode 100644 jsb/jsb-predefine.js diff --git a/index.js b/index.js index 36ade995f3..173a62974e 100644 --- a/index.js +++ b/index.js @@ -107,30 +107,71 @@ * @property {Boolean} CC_TEST - Running in the engine's unit test. */ function defineMacro (name, defaultValue) { - Function( - // if "global_defs" not preprocessed by uglify, just declare them globally, - // this may happened in release version's preview page. - // (use evaled code to prevent mangle by uglify) - 'if(typeof ' + name + '=="undefined")' + - name + '=' + defaultValue - )(); + // if "global_defs" not preprocessed by uglify, just declare them globally, + // this may happened in release version's preview page. + // (use evaled code to prevent mangle by uglify) + return 'if(typeof ' + name + '=="undefined")' + + name + '=' + defaultValue + ';'; } function defined (name) { return 'typeof ' + name + '=="object"'; } -defineMacro('CC_TEST', defined('tap') + '||' + defined('QUnit')); -defineMacro('CC_EDITOR', defined('Editor') + '&&' + defined('process') + '&&"electron" in process.versions'); -defineMacro('CC_PREVIEW', '!CC_EDITOR'); -defineMacro('CC_DEV', true); // CC_EDITOR || CC_PREVIEW || CC_TEST -defineMacro('CC_DEBUG', true); // CC_DEV || Debug Build -defineMacro('CC_JSB', defined('jsb')); -defineMacro('CC_BUILD', false); +Function( + defineMacro('CC_TEST', defined('tap') + '||' + defined('QUnit')) + + defineMacro('CC_EDITOR', defined('Editor') + '&&' + defined('process') + '&&"electron" in process.versions') + + defineMacro('CC_PREVIEW', '!CC_EDITOR') + + defineMacro('CC_DEV', true) + // CC_EDITOR || CC_PREVIEW || CC_TEST + defineMacro('CC_DEBUG', true) + // CC_DEV || Debug Build + defineMacro('CC_JSB', defined('jsb')) + + defineMacro('CC_BUILD', false) +)(); // PREDEFINE +/** + * !#en + * The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace. + * !#zh + * Cocos 引擎的主要命名空间,引擎代码中所有的类,函数,属性和常量都在这个命名空间中定义。 + * @module cc + * @main cc + */ +cc = {}; + +// The namespace for original nodes rendering in scene graph. +_ccsg = {}; + +if (CC_DEV) { + /** + * contains internal apis for unit tests + * @expose + */ + cc._Test = {}; +} + +// output all info before initialized +require('./CCDebugger'); +cc._initDebugSetting(cc.DebugMode.INFO); +if (CC_DEBUG) { + require('./DebugInfos'); +} + +// polyfills +/* require('./polyfill/bind'); */ +require('./polyfill/string'); +require('./polyfill/misc'); +require('./polyfill/array'); +if (!(CC_EDITOR && Editor.isMainProcess)) { + require('./polyfill/typescript'); +} + require('./predefine'); -// load Cocos2d engine code +ccui = {}; +ccs = {}; +cp = {}; + +// LOAD COCOS2D ENGINE CODE if (CC_EDITOR && Editor.isMainProcess) { cc._initDebugSetting(1); // DEBUG_MODE_INFO diff --git a/jsb/index.js b/jsb/index.js index 29a056043a..6c95b46a30 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -70,7 +70,53 @@ defineMacro('CC_DEBUG', true); // CC_DEV || Debug Build defineMacro('CC_JSB', defined('jsb')); defineMacro('CC_BUILD', false); -require('./jsb-predefine'); +if (!cc.ClassManager) { + cc.ClassManager = window.ClassManager || { + id : (0|(Math.random()*998)), + instanceId : (0|(Math.random()*998)), + getNewID : function(){ + return this.id++; + }, + getNewInstanceId : function(){ + return this.instanceId++; + } + }; +} + +if (CC_DEV) { + /** + * contains internal apis for unit tests + * @expose + */ + cc._Test = {}; +} + +// polyfills +if (!(CC_EDITOR && Editor.isMainProcess)) { + require('../polyfill/typescript'); +} + +// predefine some modules for cocos +require('../cocos2d/core/platform/js'); +require('../cocos2d/core/value-types'); +require('../cocos2d/core/utils/find'); +require('../cocos2d/core/utils/mutable-forward-iterator'); +require('../cocos2d/core/event'); +require('../cocos2d/core/event-manager/CCSystemEvent'); +require('../CCDebugger'); + +if (CC_DEV) { + //Debug Info ID map + require('../DebugInfos'); +} + +// Mark memory model +var macro = require('../cocos2d/core/platform/CCMacro'); + +if (window.__ENABLE_GC_FOR_NATIVE_OBJECTS__ !== undefined) { + macro.ENABLE_GC_FOR_NATIVE_OBJECTS = window.__ENABLE_GC_FOR_NATIVE_OBJECTS__; +} + require('./jsb-game'); require('./jsb-loader'); require('./jsb-director'); diff --git a/jsb/jsb-predefine.js b/jsb/jsb-predefine.js deleted file mode 100644 index 6502e1e7fc..0000000000 --- a/jsb/jsb-predefine.js +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2016 Chukong Technologies Inc. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Chukong Aipu reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -if (!cc.ClassManager) { - cc.ClassManager = window.ClassManager || { - id : (0|(Math.random()*998)), - instanceId : (0|(Math.random()*998)), - getNewID : function(){ - return this.id++; - }, - getNewInstanceId : function(){ - return this.instanceId++; - } - }; -} - -if (CC_DEV) { - /** - * contains internal apis for unit tests - * @expose - */ - cc._Test = {}; -} - -// polyfills -if (!(CC_EDITOR && Editor.isMainProcess)) { - require('../polyfill/typescript'); -} - -// predefine some modules for cocos -require('../cocos2d/core/platform/js'); -require('../cocos2d/core/value-types'); -require('../cocos2d/core/utils/find'); -require('../cocos2d/core/utils/mutable-forward-iterator'); -require('../cocos2d/core/event'); -require('../cocos2d/core/event-manager/CCSystemEvent'); -require('../CCDebugger'); - -if (CC_DEV) { - //Debug Info ID map - require('../DebugInfos'); -} - -// Mark memory model -var macro = require('../cocos2d/core/platform/CCMacro'); - -if (window.__ENABLE_GC_FOR_NATIVE_OBJECTS__ !== undefined) { - macro.ENABLE_GC_FOR_NATIVE_OBJECTS = window.__ENABLE_GC_FOR_NATIVE_OBJECTS__; -} \ No newline at end of file diff --git a/predefine.js b/predefine.js index 2dfd6d8ade..dc92294b5b 100644 --- a/predefine.js +++ b/predefine.js @@ -23,43 +23,6 @@ THE SOFTWARE. ****************************************************************************/ -/** - * !#en - * The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace. - * !#zh - * Cocos 引擎的主要命名空间,引擎代码中所有的类,函数,属性和常量都在这个命名空间中定义。 - * @module cc - * @main cc - */ -cc = {}; - -// The namespace for original nodes rendering in scene graph. -_ccsg = {}; - -if (CC_DEV) { - /** - * contains internal apis for unit tests - * @expose - */ - cc._Test = {}; -} - -// output all info before initialized -require('./CCDebugger'); -cc._initDebugSetting(cc.DebugMode.INFO); -if (CC_DEBUG) { - require('./DebugInfos'); -} - -// polyfills -/* require('./polyfill/bind'); */ -require('./polyfill/string'); -require('./polyfill/misc'); -require('./polyfill/array'); -if (!(CC_EDITOR && Editor.isMainProcess)) { - require('./polyfill/typescript'); -} - // predefine some modules for cocos require('./cocos2d/core/platform/js'); require('./cocos2d/core/value-types'); @@ -98,8 +61,4 @@ else { // Require in predefine to ensure modular-cocos2d can determine whether action module is included require('./cocos2d/actions'); } -} - -ccui = {}; -ccs = {}; -cp = {}; +} \ No newline at end of file From 5c45b6a7af8979fc778d735bd73845d9f8dd203c Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 21 Jun 2017 11:18:27 +0800 Subject: [PATCH 5/6] move predefine.js to cocos2d/core/ --- predefine.js => cocos2d/core/predefine.js | 56 ++++++++--------------- cocos2d/index.js | 5 ++ index.js | 8 +++- 3 files changed, 31 insertions(+), 38 deletions(-) rename predefine.js => cocos2d/core/predefine.js (51%) diff --git a/predefine.js b/cocos2d/core/predefine.js similarity index 51% rename from predefine.js rename to cocos2d/core/predefine.js index dc92294b5b..06adc9bb9f 100644 --- a/predefine.js +++ b/cocos2d/core/predefine.js @@ -24,41 +24,25 @@ ****************************************************************************/ // predefine some modules for cocos -require('./cocos2d/core/platform/js'); -require('./cocos2d/core/value-types'); -require('./cocos2d/core/utils'); -require('./cocos2d/core/platform/CCInputManager'); -require('./cocos2d/core/platform/CCInputExtension'); -require('./cocos2d/core/event'); -require('./cocos2d/core/platform/CCSys'); -require('./cocos2d/core/platform/CCMacro'); -require('./cocos2d/core/load-pipeline'); -require('./cocos2d/core/textures'); +require('./platform/js'); +require('./value-types'); +require('./utils'); +require('./platform/CCInputManager'); +require('./platform/CCInputExtension'); +require('./event'); +require('./platform/CCSys'); +require('./platform/CCMacro'); +require('./load-pipeline'); +require('./textures'); +require('./CCDirector'); +require('./CCDirectorWebGL'); +require('./CCDirectorCanvas'); -if (CC_JSB) { - // rename cc.Class to cc._Class - cc._Class = cc.Class; +if (!(CC_EDITOR && Editor.isMainProcess)) { + require('./platform/CCSAXParser'); + require('./platform/CCView'); + require('./platform/CCScreen'); + require('./CCScheduler'); + require('./event-manager'); + require('./renderer'); } -else { - require('./cocos2d/kazmath'); - require('./cocos2d/core/CCDirector'); - require('./cocos2d/core/CCDirectorWebGL'); - require('./cocos2d/core/CCDirectorCanvas'); - - if (!(CC_EDITOR && Editor.isMainProcess)) { - require('./cocos2d/core/platform/CCSAXParser'); - require('./cocos2d/core/platform/CCView'); - require('./cocos2d/core/platform/CCScreen'); - require('./cocos2d/core/CCScheduler'); - require('./cocos2d/core/event-manager'); - require('./cocos2d/core/renderer'); - require('./cocos2d/shaders'); - require('./cocos2d/compression'); - - require('./CCBoot'); - require('./cocos2d/core/CCGame'); - - // Require in predefine to ensure modular-cocos2d can determine whether action module is included - require('./cocos2d/actions'); - } -} \ No newline at end of file diff --git a/cocos2d/index.js b/cocos2d/index.js index eb29c849f8..b2a17e0c0d 100644 --- a/cocos2d/index.js +++ b/cocos2d/index.js @@ -1,3 +1,8 @@ +require('./core/CCGame'); + +// ensure modular-cocos2d can determine whether action module is included +require('./actions'); + require('./core/base-nodes/BaseNodesPropertyDefine.js'); require('./core/base-nodes/CCSGNode.js'); require('./core/base-nodes/CCSGNodeCanvasRenderCmd.js'); diff --git a/index.js b/index.js index 173a62974e..d5e78e71be 100644 --- a/index.js +++ b/index.js @@ -165,7 +165,8 @@ if (!(CC_EDITOR && Editor.isMainProcess)) { require('./polyfill/typescript'); } -require('./predefine'); +require('./cocos2d/kazmath'); +require('./cocos2d/core/predefine'); ccui = {}; ccs = {}; @@ -177,7 +178,10 @@ if (CC_EDITOR && Editor.isMainProcess) { cc._initDebugSetting(1); // DEBUG_MODE_INFO } else { - require('./cocos2d/index.js'); + require('./cocos2d/shaders'); + require('./cocos2d/compression'); + require('./CCBoot'); + require('./cocos2d'); } // LOAD EXTENDS FOR CREATOR From 0ce0a71d294bad1185c60db6efe25b13c155cea8 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 21 Jun 2017 11:56:30 +0800 Subject: [PATCH 6/6] tweaks --- jsb/index.js | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/jsb/index.js b/jsb/index.js index 6c95b46a30..f7312ed508 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -51,36 +51,27 @@ catch (e) { } function defineMacro (name, defaultValue) { - Function( - // if "global_defs" not preprocessed by uglify, just declare them globally, - // this may happened in release version's preview page. - // (use evaled code to prevent mangle by uglify) - 'if(typeof ' + name + '=="undefined")' + - name + '=' + defaultValue - )(); + // if "global_defs" not preprocessed by uglify, just declare them globally, + // this may happened in release version's preview page. + // (use evaled code to prevent mangle by uglify) + return 'if(typeof ' + name + '=="undefined")' + + name + '=' + defaultValue + ';'; } function defined (name) { return 'typeof ' + name + '=="object"'; } -defineMacro('CC_TEST', defined('tap') + '||' + defined('QUnit')); -defineMacro('CC_EDITOR', defined('Editor') + '&&' + defined('process') + '&&"electron" in process.versions'); -defineMacro('CC_PREVIEW', '!CC_EDITOR'); -defineMacro('CC_DEV', true); // CC_EDITOR || CC_PREVIEW || CC_TEST -defineMacro('CC_DEBUG', true); // CC_DEV || Debug Build -defineMacro('CC_JSB', defined('jsb')); -defineMacro('CC_BUILD', false); +Function( + defineMacro('CC_TEST', defined('tap') + '||' + defined('QUnit')) + + defineMacro('CC_EDITOR', defined('Editor') + '&&' + defined('process') + '&&"electron" in process.versions') + + defineMacro('CC_PREVIEW', '!CC_EDITOR') + + defineMacro('CC_DEV', true) + // CC_EDITOR || CC_PREVIEW || CC_TEST + defineMacro('CC_DEBUG', true) + // CC_DEV || Debug Build + defineMacro('CC_JSB', defined('jsb')) + + defineMacro('CC_BUILD', false) +)(); if (!cc.ClassManager) { - cc.ClassManager = window.ClassManager || { - id : (0|(Math.random()*998)), - instanceId : (0|(Math.random()*998)), - getNewID : function(){ - return this.id++; - }, - getNewInstanceId : function(){ - return this.instanceId++; - } - }; + cc.ClassManager = window.ClassManager; } if (CC_DEV) {