Merge pull request #1743 from jareguo/master

Tweaks
This commit is contained in:
pandamicro
2017-06-21 15:53:58 +08:00
committed by GitHub
30 changed files with 151 additions and 5882 deletions
+8 -4
View File
@@ -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)) {
+4 -6
View File
@@ -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);
}
@@ -23,49 +23,26 @@
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');
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_DEV) {
//Debug Info ID map
require('../DebugInfos');
if (!(CC_EDITOR && Editor.isMainProcess)) {
require('./platform/CCSAXParser');
require('./platform/CCView');
require('./platform/CCScreen');
require('./CCScheduler');
require('./event-manager');
require('./renderer');
}
// 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__;
}
+5
View File
@@ -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');
+62 -17
View File
@@ -107,36 +107,81 @@
* @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
require('./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 = {};
// load Cocos2d engine code
// 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('./cocos2d/kazmath');
require('./cocos2d/core/predefine');
ccui = {};
ccs = {};
cp = {};
// LOAD COCOS2D ENGINE CODE
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
+52 -15
View File
@@ -51,26 +51,63 @@ 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;
}
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-predefine');
require('./jsb-game');
require('./jsb-loader');
require('./jsb-director');
-105
View File
@@ -1,105 +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.
****************************************************************************/
/**
* !#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');
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');
if (CC_JSB) {
// rename cc.Class to cc._Class
cc._Class = cc.Class;
}
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');
}
}
ccui = {};
ccs = {};
cp = {};
@@ -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;
}
});
@@ -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;
}
}
});
@@ -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<count; ++i) {
var w = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
w.setTouchEnabled(true);
w.setTag(i);
w.addTouchEventListener(this.onImageViewClicked, this);
this._horizontalLayout.addChild(w);
}
this._loopText = new ccui.Text("loop enabled", "Arial", 20);
this._loopText.setPosition(winSize.width / 2, winSize.height - 50);
this._loopText.setColor(cc.Color.GREEN);
this.addChild(this._loopText);
var btn = new ccui.Button("ccs-res/cocosui/switch-mask.png");
btn.setTitleText("Toggle Loop");
btn.setPosition(60, winSize.height - 50);
btn.setTitleColor(cc.Color.RED);
btn.addTouchEventListener(this.toggleFocusLoop,this);
this.addChild(btn);
return true;
}
return false;
},
toggleFocusLoop: function( ref, touchType){
if (touchType == ccui.Widget.TOUCH_ENDED) {
this._horizontalLayout.setLoopFocus(!this._horizontalLayout.isLoopFocus());
if (this._horizontalLayout.isLoopFocus()) {
this._loopText.setString("loop enabled");
} else {
this._loopText.setString("loop disabled");
}
}
}
});
var UIFocusTestVertical = UIFocusTestBase.extend({
_verticalLayout: null,
_loopText: null,
init: function(){
if (this._super()) {
var winSize = cc.director.getVisibleSize();
this._verticalLayout = new ccui.VBox();
this._verticalLayout.setPosition(winSize.width/2 - 50, winSize.height - 80);
this.addChild(this._verticalLayout);
this._verticalLayout.setTag(100);
//this._verticalLayout.setScale(0.8);
this._verticalLayout.setFocused(true);
this._verticalLayout.setLoopFocus(true);
this._firstFocusedWidget = this._verticalLayout;
var count = 3;
for (var i=0; i<count; ++i) {
var w = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
w.setTouchEnabled(true);
w.setTag(i);
w.addTouchEventListener(this.onImageViewClicked, this);
this._verticalLayout.addChild(w);
if (i == 2)
w.requestFocus();
}
this._loopText = new ccui.Text("loop enabled", "Arial", 20);
this._loopText.setPosition(winSize.width/2, winSize.height - 50);
this._loopText.setColor(cc.Color.GREEN);
this.addChild(this._loopText);
var btn = new ccui.Button("ccs-res/cocosui/switch-mask.png");
btn.setTitleText("Toggle Loop");
btn.setPosition(60, winSize.height - 50);
btn.setTitleColor(cc.Color.RED);
btn.addTouchEventListener(this.toggleFocusLoop, this);
this.addChild(btn);
return true;
}
return false;
},
toggleFocusLoop: function(ref, touchType){
if (touchType == ccui.Widget.TOUCH_ENDED) {
this._verticalLayout.setLoopFocus(!this._verticalLayout.isLoopFocus());
if (this._verticalLayout.isLoopFocus()) {
this._loopText.setString("loop enabled");
} else {
this._loopText.setString("loop disabled");
}
}
}
});
var UIFocusTestNestedLayout1 = UIFocusTestBase.extend({
_verticalLayout: null,
_loopText: null,
init: function(){
if (this._super()) {
var winSize = cc.director.getVisibleSize();
this._verticalLayout = new ccui.VBox();
this._verticalLayout.setPosition(winSize.width/2 - 100, winSize.height - 100);
this.addChild(this._verticalLayout);
//this._verticalLayout.setScale(0.5);
this._verticalLayout.setFocused(true);
this._verticalLayout.setLoopFocus(true);
this._verticalLayout.setTag(100);
this._firstFocusedWidget = this._verticalLayout;
var count1 = 1, i, w;
for (i = 0; i < count1; ++i) {
w = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
w.setAnchorPoint(0, 0);
w.setTouchEnabled(true);
w.setScaleX(2.5);
w.setTag(i + count1);
w.addTouchEventListener(this.onImageViewClicked, this);
this._verticalLayout.addChild(w);
}
//add HBox into VBox
var hbox = new ccui.HBox();
hbox.setScale(0.8);
hbox.setTag(101);
this._verticalLayout.addChild(hbox);
var count2 = 2;
for (i=0; i < count2; ++i) {
w = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
w.setAnchorPoint(0,1);
w.setScaleY(2.0);
w.setTouchEnabled(true);
w.setTag(i+count1+count2);
w.addTouchEventListener(this.onImageViewClicked, this);
hbox.addChild(w);
}
var innerVBox = new ccui.VBox();
hbox.addChild(innerVBox);
innerVBox.setTag(102);
// innerVBox.setPassFocusToChild(false);
// innerVBox.setFocusEnabled(false);
var count3 = 2;
for (i=0; i<count3; ++i) {
w = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
w.setTouchEnabled(true);
w.setTag(i+count1+count2+count3);
w.addTouchEventListener(this.onImageViewClicked, this);
innerVBox.addChild(w);
}
this._loopText = new ccui.Text("loop enabled", "Arial", 20);
this._loopText.setPosition(winSize.width/2, winSize.height - 50);
this._loopText.setColor(cc.Color.GREEN);
this.addChild(this._loopText);
var btn = new ccui.Button("ccs-res/cocosui/switch-mask.png");
btn.setTitleText("Toggle Loop");
btn.setPosition(60, winSize.height - 50);
btn.setTitleColor(cc.Color.RED);
btn.addTouchEventListener(this.toggleFocusLoop, this);
this.addChild(btn);
return true;
}
return false;
},
toggleFocusLoop: function(ref, touchType){
if (touchType == ccui.Widget.TOUCH_ENDED) {
this._verticalLayout.setLoopFocus(!this._verticalLayout.isLoopFocus());
if (this._verticalLayout.isLoopFocus()) {
this._loopText.setString("loop enabled");
}else{
this._loopText.setString("loop disabled");
}
}
}
});
var UIFocusTestNestedLayout2 = 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.width/2 - 160, winSize.height - 120);
this.addChild(this._horizontalLayout);
//this._horizontalLayout.setScale(0.6);
this._horizontalLayout.setFocused(true);
this._horizontalLayout.setLoopFocus(true);
this._horizontalLayout.setTag(100);
this._firstFocusedWidget = this._horizontalLayout;
var count1 = 2, i, w;
for (i=0; i<count1; ++i) {
w = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
w.setAnchorPoint(0,1);
w.setTouchEnabled(true);
w.setTag(i+count1);
w.setScaleY(2.4);
w.addTouchEventListener(this.onImageViewClicked, this);
this._horizontalLayout.addChild(w);
}
//add HBox into VBox
var vbox = new ccui.VBox();
vbox.setScale(0.8);
vbox.setTag(101);
this._horizontalLayout.addChild(vbox);
var count2 = 2;
for (i=0; i < count2; ++i) {
w = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
w.setAnchorPoint(0,1);
w.setScaleX(2.0);
w.setTouchEnabled(true);
w.setTag(i+count1+count2);
w.addTouchEventListener(this.onImageViewClicked, this);
vbox.addChild(w);
}
var innerHBox = new ccui.HBox();
vbox.addChild(innerHBox);
innerHBox.setTag(102);
//innerVBox.setPassFocusToChild(false);
//innerVBox.setFocusEnabled(false);
var count3 = 2;
for (i = 0; i < count3; ++i) {
w = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
w.setTouchEnabled(true);
w.setTag(i + count1 + count2 + count3);
w.addTouchEventListener(this.onImageViewClicked, this);
innerHBox.addChild(w);
}
this._loopText = new ccui.Text("loop enabled", "Arial", 20);
this._loopText.setPosition(winSize.width/2, winSize.height - 50);
this._loopText.setColor(cc.Color.GREEN);
this.addChild(this._loopText);
var btn = new ccui.Button("ccs-res/cocosui/switch-mask.png");
btn.setTitleText("Toggle Loop");
btn.setPosition(60, winSize.height - 50);
btn.setTitleColor(cc.Color.RED);
btn.addTouchEventListener(this.toggleFocusLoop, this);
this.addChild(btn);
return true;
}
return false;
},
toggleFocusLoop: function (ref, touchType) {
if (touchType == ccui.Widget.TOUCH_ENDED) {
this._horizontalLayout.setLoopFocus(!this._horizontalLayout.isLoopFocus());
if (this._horizontalLayout.isLoopFocus()) {
this._loopText.setString("loop enabled");
} else {
this._loopText.setString("loop disabled");
}
}
}
});
var UIFocusTestNestedLayout3 = UIFocusTestBase.extend({
_horizontalLayout: null,
_loopText: null,
init: function(){
if (this._super()) {
var winSize = cc.director.getVisibleSize();
this._verticalLayout = new ccui.VBox();
this._verticalLayout.setPosition(winSize.height / 2 + 80, winSize.height - 150);
this.addChild(this._verticalLayout);
//this._verticalLayout.setScale(0.8);
this._verticalLayout.setFocused(true);
this._verticalLayout.setLoopFocus(true);
this._verticalLayout.setTag(-1000);
this._firstFocusedWidget = this._verticalLayout;
var upperHBox = new ccui.HBox();
upperHBox.setTag(-200);
this._verticalLayout.addChild(upperHBox);
var params = new ccui.LinearLayoutParameter();
params.setMargin(new ccui.Margin(0,0,50,0));
var vparams = new ccui.LinearLayoutParameter();
vparams.setMargin(new ccui.Margin(10, 0, 0, 140));
upperHBox.setLayoutParameter(vparams);
var count = 3, i, w;
for (i = 0; i < count; ++i) {
var firstVbox = new ccui.VBox();
firstVbox.setScale(0.5);
firstVbox.setLayoutParameter(params);
firstVbox.setTag((i+1) * 100);
var count1 = 3;
for (var j = 0; j < count1; ++j) {
w = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
w.setTouchEnabled(true);
w.setTag(j + firstVbox.getTag() + 1);
w.addTouchEventListener(this.onImageViewClicked, this);
firstVbox.addChild(w);
}
upperHBox.addChild(firstVbox);
}
var bottomHBox = new ccui.HBox();
bottomHBox.setScale(0.5);
bottomHBox.setTag(600);
bottomHBox.setLayoutParameter(vparams);
count = 3;
var bottomParams = new ccui.LinearLayoutParameter();
bottomParams.setMargin(new ccui.Margin(0, 0, 8, 0));
for (i = 0; i < count; ++i) {
w = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
w.setLayoutParameter(bottomParams);
w.setTouchEnabled(true);
w.setTag(i + 601);
w.addTouchEventListener(this.onImageViewClicked, this);
bottomHBox.addChild(w);
}
this._verticalLayout.addChild(bottomHBox);
this._loopText = new ccui.Text("loop enabled", "Arial", 20);
this._loopText.setPosition(winSize.width/2, winSize.height - 50);
this._loopText.setColor(cc.Color.GREEN);
this.addChild(this._loopText);
var btn = new ccui.Button("ccs-res/cocosui/switch-mask.png");
btn.setTitleText("Toggle Loop");
btn.setPosition(60, winSize.height - 50);
btn.setTitleColor(cc.Color.RED);
btn.addTouchEventListener(this.toggleFocusLoop, this);
this.addChild(btn);
return true;
}
return false;
},
toggleFocusLoop: function(ref, touchType){
if (touchType == ccui.Widget.TOUCH_ENDED) {
this._verticalLayout.setLoopFocus(!this._verticalLayout.isLoopFocus());
if (this._verticalLayout.isLoopFocus()) {
this._loopText.setString("loop enabled");
}else{
this._loopText.setString("loop disabled");
}
}
}
});
var UIFocusTestListView = UIFocusTestBase.extend({
_listView: null,
_loopText: null,
init: function(){
if (this._super()) {
var winSize = cc.director.getVisibleSize();
this._listView = new ccui.ListView();
this._listView.setDirection(ccui.ScrollView.Dir.VERTICAL);
this._listView.setBounceEnabled(true);
this._listView.setBackGroundImage("ccs-res/cocosui/green_edit.png");
this._listView.setBackGroundImageScale9Enabled(true);
this._listView.setContentSize(240, 130);
this._listView.setPosition(40, 70);
this.addChild(this._listView);
this._listView.setScale(0.8);
this._listView.setFocused(true);
this._listView.setLoopFocus(true);
this._listView.setTag(-1000);
this._firstFocusedWidget = this._listView;
// create model
var default_button = new ccui.Button("ccs-res/cocosui/backtotoppressed.png", "ccs-res/cocosui/backtotopnormal.png");
default_button.setName("Title Button");
// set model
this._listView.setItemModel(default_button);
// add default item
var count = 20, i;
for (i = 0; i < count / 4; ++i) {
this._listView.pushBackDefaultItem();
}
// insert default item
for (i = 0; i < count / 4; ++i) {
this._listView.insertDefaultItem(0);
}
this._loopText = new ccui.Text("loop enabled", "Arial", 20);
this._loopText.setPosition(winSize.width/2, winSize.height - 50);
this._loopText.setColor(cc.Color.GREEN);
this.addChild(this._loopText);
var btn = new ccui.Button("ccs-res/cocosui/switch-mask.png");
btn.setTitleText("Toggle Loop");
btn.setPosition(60, winSize.height - 50);
btn.setTitleColor(cc.Color.RED);
btn.addTouchEventListener(this.toggleFocusLoop, this);
this.addChild(btn);
return true;
}
return false;
},
toggleFocusLoop: function(ref, touchType){
if (touchType == ccui.Widget.TOUCH_ENDED) {
this._listView.setLoopFocus(!this._listView.isLoopFocus());
if (this._listView.isLoopFocus()) {
this._loopText.setString("loop enabled");
}else{
this._loopText.setString("loop disabled");
}
}
}
});
@@ -1,171 +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 UIImageViewTest = UIMainLayer.extend({
init: function () {
if (this._super()) {
//init text
this._topDisplayLabel.setString("");
this._bottomDisplayLabel.setString("ImageView");
var widgetSize = this._widget.getContentSize();
// Create the imageview
var imageView = new ccui.ImageView("ccs-res/cocosui/ccicon.png");
imageView.x = widgetSize.width / 2;
imageView.y = widgetSize.height / 2 + imageView.height / 4;
this._mainNode.addChild(imageView);
return true;
}
return false;
}
});
var UIImageViewTest_Scale9 = UIMainLayer.extend({
init: function () {
if (this._super()) {
var widgetSize = this._widget.getContentSize();
//init text
this._topDisplayLabel.setString("");
this._bottomDisplayLabel.setString("ImageView scale9 render");
// Create the imageview
var imageView = new ccui.ImageView();
imageView.setScale9Enabled(true);
imageView.loadTexture("ccs-res/cocosui/buttonHighlighted.png");
imageView.setContentSize(cc.size(200, 85));
imageView.x = widgetSize.width / 2;
imageView.y = widgetSize.height / 2 + imageView.getContentSize().height / 4;
this._mainNode.addChild(imageView);
return true;
}
return false;
}
});
//2015-01-14
var UIImageViewTest_ContentSize = UIMainLayer.extend({
init: function(){
if (this._super()) {
var widgetSize = this._widget.getContentSize();
this._bottomDisplayLabel.setString("");
var alert = new ccui.Text("ImageView ContentSize Change", "Marker Felt", 26);
alert.setColor(cc.color(159, 168, 176));
alert.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 - alert.getContentSize().height * 2.125));
this._mainNode.addChild(alert);
var status = new ccui.Text("child ImageView position percent", "Marker Felt", 16);
status.setColor(cc.Color.RED);
status.setPosition(cc.p(widgetSize.width/2, widgetSize.height/2 + 80));
this._mainNode.addChild(status,20);
// Create the imageview
var imageView = new ccui.ImageView("ccs-res/cocosui/buttonHighlighted.png");
imageView.setScale9Enabled(true);
imageView.setContentSize(cc.size(200, 80));
imageView.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2));
var imageViewChild = new ccui.ImageView("ccs-res/cocosui/buttonHighlighted.png");
imageViewChild.setScale9Enabled(true);
imageViewChild.setSizeType(ccui.Widget.SIZE_PERCENT);
imageViewChild.setPositionType(ccui.Widget.POSITION_PERCENT);
imageViewChild.setSizePercent(cc.p(0.5, 0.5));
imageViewChild.setPositionPercent(cc.p(0.5, 0.5));
//imageViewChild.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2));
var imageViewChild2 = new ccui.ImageView("ccs-res/cocosui/buttonHighlighted.png");
imageViewChild2.setScale9Enabled(true);
imageViewChild2.setSizeType(ccui.Widget.SIZE_PERCENT);
imageViewChild2.setPositionType(ccui.Widget.POSITION_PERCENT);
imageViewChild2.setSizePercent(cc.p(0.5, 0.5));
imageViewChild2.setPositionPercent(cc.p(0.5, 0.5));
imageViewChild.addChild(imageViewChild2);
imageView.addChild(imageViewChild);
window.aa = imageView;
imageView.setTouchEnabled(true);
imageView.addTouchEventListener(function(sender, type){
if (type == ccui.Widget.TOUCH_ENDED) {
var width = (Math.random() * 200 | 0) + 50;
var height = (Math.random() * 80 | 0) + 30;
imageView.setContentSize(cc.size(width, height));
imageViewChild.setPositionPercent(cc.p(Math.random().toFixed(2), Math.random().toFixed(2)));
status.setString("child ImageView position percent: "+imageViewChild.getPositionPercent().x+", "+imageViewChild.getPositionPercent().y);
}
});
this._mainNode.addChild(imageView);
return true;
}
}
});
//2015-01-14
var UIImageViewFlipTest = UIMainLayer.extend({
init: function(){
if (this._super()) {
cc.spriteFrameCache.addSpriteFrames("Images/blocks9ss.plist");
var widgetSize = this._widget.getContentSize();
this._bottomDisplayLabel.setString("ImageView flip test");
// Create the imageview
var imageView = new ccui.ImageView("blocks9r.png", ccui.Widget.PLIST_TEXTURE);
imageView.setScale9Enabled(true);
imageView.setContentSize(cc.size(250, 115));
imageView.setFlippedX(true);
imageView.setScale(0.5);
imageView.ignoreContentAdaptWithSize(false);
imageView.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2));
this._mainNode.addChild(imageView);
var toggleButton = new ccui.Button();
toggleButton.setTitleText("Toggle FlipX");
var ip = imageView.getPosition();
toggleButton.setPosition(ip.x - 50, ip.y - imageView.getContentSize().height/2 - 20);
this.addChild(toggleButton);
toggleButton.addClickEventListener(function(){
imageView.setFlippedX(!imageView.isFlippedX());
});
var toggleScale9 = new ccui.Button();
toggleScale9.setTitleText("Toggle Scale9");
var ip9 = imageView.getPosition();
toggleScale9.setPosition(ip9.x + 50, ip9.y - imageView.getContentSize().height/2- 20);
this.addChild(toggleScale9);
toggleScale9.addClickEventListener(function(){
imageView.setScale9Enabled(!imageView.isScale9Enabled());
//after switching scale9, you must call setContentSize to keep the size not change
imageView.setContentSize(cc.size(250, 115));
});
return true;
}
}
});
@@ -1,45 +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 UILabelAtlasTest = UIMainLayer.extend({
init: function () {
if (this._super()) {
//init text
this._topDisplayLabel.setString("");
this._bottomDisplayLabel.setString("LabelAtlas");
// Create the label atlas
var textAtlas = new ccui.TextAtlas();
textAtlas.setProperty("1234567890", "ccs-res/cocosui/labelatlas.png", 17, 22, "0");
textAtlas.x = this._widget.width / 2;
textAtlas.y = this._widget.height / 2;
this._mainNode.addChild(textAtlas);
return true;
}
return false;
}
});
@@ -1,46 +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 UILabelBMFontTest = UIMainLayer.extend({
init: function () {
if (this._super()) {
//init text
this._topDisplayLabel.setString("");
this._bottomDisplayLabel.setString("LabelBMFont");
// Create the LabelBMFont
var labelBMFont = new ccui.TextBMFont();
labelBMFont.setFntFile("ccs-res/cocosui/bitmapFontTest2.fnt");
labelBMFont.setString("BMFont");
labelBMFont.x = this._widget.width / 2;
labelBMFont.y = this._widget.height / 2.0 + labelBMFont.height / 8.0;
this._mainNode.addChild(labelBMFont);
return true;
}
return false;
}
});
@@ -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 UILabelTest = UIMainLayer.extend({
init: function () {
if (this._super()) {
//init text
this._topDisplayLabel.setString("");
this._bottomDisplayLabel.setString("Label");
// Create the label
var text = new ccui.Text();
text.attr({
string: "Label",
font: "30px AmericanTypewriter",
x: this._widget.width / 2,
y: this._widget.height / 2 + text.height / 4
});
this._mainNode.addChild(text);
return true;
}
return false;
}
});
var UILabelTest_LineWrap = UIMainLayer.extend({
init: function () {
if (this._super()) {
var widgetSize = this._widget.getContentSize();
//init text
this._topDisplayLabel.string = "";
this._bottomDisplayLabel.string = "Label line wrap";
// Create the text area
var text = new ccui.Text();
text.boundingWidth = 280;
text.boundingHeight = 150;
text.attr({
textAlign: cc.TextAlignment.CENTER,
string: "Label can line wrap",
font: "32px AmericanTypewriter",
x: this._widget.width / 2
});
text.y = this._widget.height / 2 - text.height / 8;
this._mainNode.addChild(text);
return true;
}
return false;
}
});
var UILabelTest_TTF = UIMainLayer.extend({
init: function () {
if (this._super()) {
//init text
this._topDisplayLabel.setString("");
this._bottomDisplayLabel.setString("Label set TTF font");
// Create the text area
var text = new ccui.Text();
text.boundingWidth = 280;
text.boundingHeight = 150;
text.attr({
textAlign: cc.TextAlignment.CENTER,
string: "Label TTF",
font: "32px mericanTypewriter",
x: this._widget.width / 2,
y: this._widget.height / 2 - text.height / 8
});
this._mainNode.addChild(text);
return true;
}
return false;
}
});
@@ -1,536 +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 UILayoutTestBase = UIMainLayer.extend({
layout: null,
button: null,
textButton: null,
button_scale9: null,
init: function () {
if (this._super()) {
var widgetSize = this._widget.getContentSize();
//init text
this._topDisplayLabel.setString("");
this._bottomDisplayLabel.setString(this.getText());
this._bottomDisplayLabel.x = widgetSize.width / 2;
this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3;
// Create the layout
this.layout = this.createLayout();
var layoutRect = this.layout.getContentSize();
var backgroundRect = this._backgroundSize;
this.layout.x = (widgetSize.width - backgroundRect.width) / 2 + (backgroundRect.width - layoutRect.width) / 2;
this.layout.y = (widgetSize.height - backgroundRect.height) / 2 + (backgroundRect.height - layoutRect.height) / 2;
this._mainNode.addChild(this.layout);
this.button = new ccui.Button();
this.button.setTouchEnabled(true);
this.button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
this.button.x = this.button.width / 2;
this.button.y = layoutRect.height - this.button.height / 2;
this.layout.addChild(this.button);
this.textButton = new ccui.Button();
this.textButton.setTouchEnabled(true);
this.textButton.loadTextures("ccs-res/cocosui/backtotopnormal.png", "ccs-res/cocosui/backtotoppressed.png", "");
this.textButton.setTitleText("Text Button");
this.textButton.x = layoutRect.width / 2;
this.textButton.y = layoutRect.height / 2;
this.layout.addChild(this.textButton);
this.button_scale9 = new ccui.Button();
this.button_scale9.setTouchEnabled(true);
this.button_scale9.setScale9Enabled(true);
this.button_scale9.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", "");
this.button_scale9.width = 100;
this.button_scale9.height = 32;
this.button_scale9.x = layoutRect.width - this.button_scale9.width / 2;
this.button_scale9.y = this.button_scale9.height / 2;
this.layout.addChild(this.button_scale9);
this.setLayoutParameter();
return true;
}
return false;
},
getText: function () {
return "";
},
createLayout: function () {
var layout = new ccui.Layout();
layout.setContentSize(cc.size(280, 150));
return layout;
},
setLayoutParameter: function () {
}
});
var UILayoutTest = UILayoutTestBase.extend({
createLayout: function () {
var layout = new ccui.Layout();
layout.setContentSize(cc.size(280, 150));
return layout;
},
getText: function () {
return "Layout";
}
});
var UILayoutTest_Color = UILayoutTestBase.extend({
createLayout: function () {
var layout = new ccui.Layout();
layout.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
layout.setBackGroundColor(cc.color(128, 128, 128));
layout.setContentSize(cc.size(280, 150));
return layout;
},
getText: function () {
return "Layout color render";
}
});
var UILayoutTest_Gradient = UILayoutTestBase.extend({
createLayout: function () {
var layout = new ccui.Layout();
layout.setBackGroundColorType(ccui.Layout.BG_COLOR_GRADIENT);
layout.setBackGroundColor(cc.color(64, 64, 64), cc.color(192, 192, 192));
layout.setContentSize(cc.size(280, 150));
return layout;
},
getText: function () {
return "Layout gradient render";
}
});
var UILayoutTest_BackGroundImage = UILayoutTestBase.extend({
createLayout: function () {
var layout = new ccui.Layout();
layout.setClippingEnabled(true);
layout.setBackGroundImage("ccs-res/cocosui/Hello.png");
layout.setContentSize(cc.size(280, 150));
return layout;
},
getText: function () {
return "Layout background image";
}
});
var UILayoutTest_BackGroundImage_Scale9 = UILayoutTestBase.extend({
createLayout: function () {
var layout = new ccui.Layout();
layout.setBackGroundImageScale9Enabled(true);
layout.setBackGroundImage("ccs-res/cocosui/green_edit.png");
layout.setContentSize(cc.size(280, 150));
return layout;
},
getText: function () {
return "Layout background image scale9";
}
});
var UILayoutTest_Layout_Linear_Vertical = UILayoutTestBase.extend({
createLayout: function () {
var layout = new ccui.Layout();
layout.setLayoutType(ccui.Layout.Type.LINEAR_VERTICAL);
layout.setContentSize(cc.size(280, 150));
return layout;
},
getText: function () {
return "Layout Layout Linear Vertical";
},
setLayoutParameter: function () {
var lp1 = new ccui.LinearLayoutParameter();
this.button.setLayoutParameter(lp1);
lp1.setGravity(ccui.LinearLayoutParameter.CENTER_HORIZONTAL);
lp1.setMargin(new ccui.Margin(0, 5, 0, 10));
var lp2 = new ccui.LinearLayoutParameter();
this.textButton.setLayoutParameter(lp2);
lp2.setGravity(ccui.LinearLayoutParameter.CENTER_HORIZONTAL);
lp2.setMargin(new ccui.Margin(0, 10, 0, 10));
var lp3 = new ccui.LinearLayoutParameter();
this.button_scale9.setLayoutParameter(lp3);
lp3.setGravity(ccui.LinearLayoutParameter.CENTER_HORIZONTAL);
lp3.setMargin(new ccui.Margin(0, 10, 0, 10));
}
});
var UILayoutTest_Layout_Linear_Horizontal = UILayoutTestBase.extend({
createLayout: function () {
var layout = new ccui.Layout();
layout.setLayoutType(ccui.Layout.Type.LINEAR_HORIZONTAL);
layout.setClippingEnabled(true);
layout.setContentSize(cc.size(280, 150));
return layout;
},
getText: function () {
return "Layout Layout Linear Horizontal";
},
setLayoutParameter: function () {
var lp1 = new ccui.LinearLayoutParameter();
this.button.setLayoutParameter(lp1);
lp1.setGravity(ccui.LinearLayoutParameter.CENTER_VERTICAL);
lp1.setMargin(new ccui.Margin(0, 10, 0, 10));
var lp2 = new ccui.LinearLayoutParameter();
this.textButton.setLayoutParameter(lp2);
lp2.setGravity(ccui.LinearLayoutParameter.CENTER_VERTICAL);
lp2.setMargin(new ccui.Margin(0, 10, 0, 10));
var lp3 = new ccui.LinearLayoutParameter();
this.button_scale9.setLayoutParameter(lp3);
lp3.setGravity(ccui.LinearLayoutParameter.CENTER_VERTICAL);
lp3.setMargin(new ccui.Margin(0, 10, 0, 10));
}
});
var UILayoutTest_Layout_Relative = UILayoutTestBase.extend({
createLayout: function () {
var layout = new ccui.Layout();
layout.ignoreContentAdaptWithSize(false);
layout.setLayoutType(ccui.Layout.Type.RELATIVE);
layout.sizeType = ccui.Widget.SIZE_PERCENT;
layout.setSizePercent(cc.p(0.5, 0.5));
//layout.setContentSize(cc.size(280, 150));
layout.setPositionType(ccui.Widget.POSITION_PERCENT);
layout.setPositionPercent(cc.p(0.25, 0.25));
//layout.setPosition(cc.p(cc.winSize.width/2, cc.winSize.height/2));
layout.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
layout.setBackGroundColor(cc.Color.GREEN);
return layout;
},
getText: function () {
return "Layout Layout Relative";
},
setLayoutParameter: function () {
var lp1 = new ccui.RelativeLayoutParameter();
this.button.setLayoutParameter(lp1);
lp1.setAlign(ccui.RelativeLayoutParameter.Type.PARENT_TOP_LEFT);
var lp2 = new ccui.RelativeLayoutParameter();
this.textButton.setLayoutParameter(lp2);
lp2.setAlign(ccui.RelativeLayoutParameter.Type.CENTER_IN_PARENT);
var lp3 = new ccui.RelativeLayoutParameter();
this.button_scale9.setLayoutParameter(lp3);
lp3.setAlign(ccui.RelativeLayoutParameter.Type.PARENT_RIGHT_BOTTOM);
}
});
var UILayoutTest_Layout_Relative_Align_Parent = UIMainLayer.extend({
init: function(){
if (this._super()) {
var widgetSize = this._widget.getContentSize();
// Add the alert
var alert = new ccui.Text("Layout Relative Align Parent", "Arial", 20);
alert.setColor(cc.color(159, 168, 176));
alert.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert.getContentSize().height * 4.5);
this._mainNode.addChild(alert);
// Create the layout
var layout = new ccui.Layout();
layout.setLayoutType(ccui.Layout.Type.RELATIVE);
layout.setContentSize(280, 150);
layout.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
layout.setBackGroundColor(cc.Color.GREEN);
var backgroundSize = this._backgroundSize;
layout.setPosition((widgetSize.width - backgroundSize.width) / 2.0 + (backgroundSize.width - layout.width) / 2.0,
(widgetSize.height - backgroundSize.height) / 2.0 + (backgroundSize.height - layout.height) / 2.0);
this._mainNode.addChild(layout);
// top left
var button_TopLeft = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png");
layout.addChild(button_TopLeft);
var rp_TopLeft = new ccui.RelativeLayoutParameter();
rp_TopLeft.setAlign(ccui.RelativeLayoutParameter.Type.PARENT_TOP_LEFT);
button_TopLeft.setLayoutParameter(rp_TopLeft);
// top center horizontal
var button_TopCenter = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png");
layout.addChild(button_TopCenter);
var rp_TopCenter = new ccui.RelativeLayoutParameter();
rp_TopCenter.setAlign(ccui.RelativeLayoutParameter.Type.PARENT_TOP_CENTER_HORIZONTAL);
button_TopCenter.setLayoutParameter(rp_TopCenter);
// top right
var button_TopRight = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png");
layout.addChild(button_TopRight);
var rp_TopRight = new ccui.RelativeLayoutParameter();
rp_TopRight.setAlign(ccui.RelativeLayoutParameter.Type.PARENT_TOP_RIGHT);
button_TopRight.setLayoutParameter(rp_TopRight);
// left center
var button_LeftCenter = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png");
layout.addChild(button_LeftCenter);
var rp_LeftCenter = new ccui.RelativeLayoutParameter();
rp_LeftCenter.setAlign(ccui.RelativeLayoutParameter.Type.PARENT_LEFT_CENTER_VERTICAL);
button_LeftCenter.setLayoutParameter(rp_LeftCenter);
// center
var buttonCenter = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png");
layout.addChild(buttonCenter);
var rpCenter = new ccui.RelativeLayoutParameter();
rpCenter.setAlign(ccui.RelativeLayoutParameter.Type.CENTER_IN_PARENT);
buttonCenter.setLayoutParameter(rpCenter);
// right center
var button_RightCenter = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png");
layout.addChild(button_RightCenter);
var rp_RightCenter = new ccui.RelativeLayoutParameter();
rp_RightCenter.setAlign(ccui.RelativeLayoutParameter.Type.PARENT_RIGHT_CENTER_VERTICAL);
button_RightCenter.setLayoutParameter(rp_RightCenter);
// left bottom
var button_LeftBottom = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png");
layout.addChild(button_LeftBottom);
var rp_LeftBottom = new ccui.RelativeLayoutParameter();
rp_LeftBottom.setAlign(ccui.RelativeLayoutParameter.Type.PARENT_LEFT_BOTTOM);
button_LeftBottom.setLayoutParameter(rp_LeftBottom);
// bottom center
var button_BottomCenter = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png");
layout.addChild(button_BottomCenter);
var rp_BottomCenter = new ccui.RelativeLayoutParameter();
rp_BottomCenter.setAlign(ccui.RelativeLayoutParameter.Type.PARENT_BOTTOM_CENTER_HORIZONTAL);
button_BottomCenter.setLayoutParameter(rp_BottomCenter);
// right bottom
var button_RightBottom = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png");
layout.addChild(button_RightBottom);
var rp_RightBottom = new ccui.RelativeLayoutParameter();
rp_RightBottom.setAlign(ccui.RelativeLayoutParameter.Type.PARENT_RIGHT_BOTTOM);
button_RightBottom.setLayoutParameter(rp_RightBottom);
return true;
}
return false;
}
});
var UILayoutTest_Layout_Relative_Location = UIMainLayer.extend({
init: function(){
if (this._super()) {
var widgetSize = this._widget.getContentSize();
// Add the alert
var alert = new ccui.Text("Layout Relative Location", "Marker Felt", 20);
alert.setColor(cc.color(159, 168, 176));
alert.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0 - alert.height * 4.5);
this._mainNode.addChild(alert);
// Create the layout
var layout = new ccui.Layout();
layout.setLayoutType(ccui.Layout.Type.RELATIVE);
layout.setContentSize(280, 150);
var backgroundSize = this._backgroundSize;
layout.setPosition((widgetSize.width - backgroundSize.width) / 2.0 + (backgroundSize.width - layout.width) / 2.0,
(widgetSize.height - backgroundSize.height) / 2.0 + (backgroundSize.height - layout.height) / 2.0 );
this._mainNode.addChild(layout);
// center
var imageView_Center = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png");
layout.addChild(imageView_Center);
var rp_Center = new ccui.RelativeLayoutParameter();
rp_Center.setRelativeName("rp_Center");
rp_Center.setAlign(ccui.RelativeLayoutParameter.Type.CENTER_IN_PARENT);
imageView_Center.setLayoutParameter(rp_Center);
// above center
var imageView_AboveCenter = new ccui.ImageView("ccs-res/cocosui/switch-mask.png");
layout.addChild(imageView_AboveCenter);
var rp_AboveCenter = new ccui.RelativeLayoutParameter();
rp_AboveCenter.setRelativeToWidgetName("rp_Center");
rp_AboveCenter.setAlign(ccui.RelativeLayoutParameter.Type.LOCATION_ABOVE_CENTER);
imageView_AboveCenter.setLayoutParameter(rp_AboveCenter);
// below center
var imageView_BelowCenter = new ccui.ImageView("ccs-res/cocosui/switch-mask.png");
layout.addChild(imageView_BelowCenter);
var rp_BelowCenter = new ccui.RelativeLayoutParameter();
rp_BelowCenter.setRelativeToWidgetName("rp_Center");
rp_BelowCenter.setAlign(ccui.RelativeLayoutParameter.Type.LOCATION_BELOW_CENTER);
imageView_BelowCenter.setLayoutParameter(rp_BelowCenter);
// left center
var imageView_LeftCenter = new ccui.ImageView("ccs-res/cocosui/switch-mask.png");
layout.addChild(imageView_LeftCenter);
var rp_LeftCenter = new ccui.RelativeLayoutParameter();
rp_LeftCenter.setRelativeToWidgetName("rp_Center");
rp_LeftCenter.setAlign(ccui.RelativeLayoutParameter.Type.LOCATION_LEFT_OF_CENTER);
imageView_LeftCenter.setLayoutParameter(rp_LeftCenter);
// right center
var imageView_RightCenter = new ccui.ImageView("ccs-res/cocosui/switch-mask.png");
layout.addChild(imageView_RightCenter);
var rp_RightCenter = new ccui.RelativeLayoutParameter();
rp_RightCenter.setRelativeToWidgetName("rp_Center");
rp_RightCenter.setAlign(ccui.RelativeLayoutParameter.Type.LOCATION_RIGHT_OF_CENTER);
imageView_RightCenter.setLayoutParameter(rp_RightCenter);
return true;
}
return false;
}
});
var UILayoutComponentTest = UIMainLayer.extend({
_baseLayer: null,
init: function(){
if (this._super()) {
var widgetSize = this._widget.getContentSize();
this._baseLayer = new cc.LayerColor();
this._baseLayer.setColor(cc.color(50, 100, 0));
this._baseLayer.setOpacity(100);
this._baseLayer.setContentSize(200, 200);
this._mainNode.addChild(this._baseLayer);
var button = new ccui.Button("ccs-res/cocosui/animationbuttonnormal.png");
cc.log("content size should be greater than 0: width = %f, height = %f", button.width, button.height);
button.setPosition(widgetSize.width / 2.0, widgetSize.height / 2.0);
button.addTouchEventListener(this.touchEvent, this);
button.setZoomScale(0.4);
button.setPressedActionEnabled(true);
this._mainNode.addChild(button);
return true;
}
return false;
},
touchEvent: function(sender, type){
switch (type) {
case ccui.Widget.TOUCH_BEGAN:
break;
case ccui.Widget.TOUCH_MOVED:
break;
case ccui.Widget.TOUCH_ENDED:
var widgetSize = this._widget.getContentSize();
var layerSize = this._baseLayer.getContentSize();
if (layerSize.width == widgetSize.width && layerSize.height == widgetSize.height)
this._baseLayer.setContentSize(200, 200);
else
this._baseLayer.setContentSize(widgetSize);
ccui.helper.doLayout(this._baseLayer);
break;
case ccui.Widget.TOUCH_CANCELED:
break;
default:
break;
}
}
});
var UILayoutComponent_Berth_Test = UILayoutComponentTest.extend({
init: function(){
if (this._super()){
var leftTopSprite = new _ccsg.Sprite("ccs-res/cocosui/CloseSelected.png");
var leftTop = ccui.LayoutComponent.bindLayoutComponent(leftTopSprite);
leftTop.setHorizontalEdge(ccui.LayoutComponent.horizontalEdge.LEFT);
leftTop.setVerticalEdge(ccui.LayoutComponent.verticalEdge.TOP);
this._baseLayer.addChild(leftTopSprite);
var leftBottomSprite = new _ccsg.Sprite("ccs-res/cocosui/CloseSelected.png");
var leftBottom = ccui.LayoutComponent.bindLayoutComponent(leftBottomSprite);
leftBottom.setHorizontalEdge(ccui.LayoutComponent.horizontalEdge.LEFT);
leftBottom.setVerticalEdge(ccui.LayoutComponent.verticalEdge.BOTTOM);
this._baseLayer.addChild(leftBottomSprite);
var rightTopSprite = new _ccsg.Sprite("ccs-res/cocosui/CloseSelected.png");
var rightTop = ccui.LayoutComponent.bindLayoutComponent(rightTopSprite);
rightTop.setHorizontalEdge(ccui.LayoutComponent.horizontalEdge.RIGHT);
rightTop.setVerticalEdge(ccui.LayoutComponent.verticalEdge.TOP);
this._baseLayer.addChild(rightTopSprite);
var rightBottomSprite = new _ccsg.Sprite("ccs-res/cocosui/CloseSelected.png");
var rightBottom = ccui.LayoutComponent.bindLayoutComponent(rightBottomSprite);
rightBottom.setHorizontalEdge(ccui.LayoutComponent.horizontalEdge.RIGHT);
rightBottom.setVerticalEdge(ccui.LayoutComponent.verticalEdge.BOTTOM);
this._baseLayer.addChild(rightBottomSprite);
ccui.helper.doLayout(this._baseLayer);
return true;
}
return false;
}
});
var UILayoutComponent_Berth_Stretch_Test = UILayoutComponentTest.extend({
init: function(){
if (this._super()) {
var leftTopSprite = new ccui.ImageView("ccs-res/cocosui/CloseSelected.png");
leftTopSprite.ignoreContentAdaptWithSize(false);
var leftTop = ccui.LayoutComponent.bindLayoutComponent(leftTopSprite);
leftTop.setHorizontalEdge(ccui.LayoutComponent.horizontalEdge.LEFT);
leftTop.setVerticalEdge(ccui.LayoutComponent.verticalEdge.TOP);
leftTop.setStretchWidthEnabled(true);
leftTop.setStretchHeightEnabled(true);
this._baseLayer.addChild(leftTopSprite);
leftTop.setSize(leftTopSprite.getContentSize());
leftTop.setLeftMargin(0);
leftTop.setTopMargin(0);
var leftBottomSprite = new ccui.ImageView("ccs-res/cocosui/CloseSelected.png");
leftBottomSprite.ignoreContentAdaptWithSize(false);
var leftBottom = ccui.LayoutComponent.bindLayoutComponent(leftBottomSprite);
leftBottom.setHorizontalEdge(ccui.LayoutComponent.horizontalEdge.LEFT);
leftBottom.setVerticalEdge(ccui.LayoutComponent.verticalEdge.BOTTOM);
leftBottom.setStretchWidthEnabled(true);
leftBottom.setStretchHeightEnabled(true);
this._baseLayer.addChild(leftBottomSprite);
leftBottom.setSize(leftBottomSprite.getContentSize());
leftBottom.setLeftMargin(0);
leftBottom.setBottomMargin(0);
var rightTopSprite = new ccui.ImageView("ccs-res/cocosui/CloseSelected.png");
rightTopSprite.ignoreContentAdaptWithSize(false);
var rightTop = ccui.LayoutComponent.bindLayoutComponent(rightTopSprite);
rightTop.setHorizontalEdge(ccui.LayoutComponent.horizontalEdge.RIGHT);
rightTop.setVerticalEdge(ccui.LayoutComponent.verticalEdge.TOP);
rightTop.setStretchWidthEnabled(true);
rightTop.setStretchHeightEnabled(true);
this._baseLayer.addChild(rightTopSprite);
rightTop.setSize(rightTopSprite.getContentSize());
rightTop.setTopMargin(0);
rightTop.setRightMargin(0);
var rightBottomSprite = new ccui.ImageView("ccs-res/cocosui/CloseSelected.png");
rightBottomSprite.ignoreContentAdaptWithSize(false);
var rightBottom = ccui.LayoutComponent.bindLayoutComponent(rightBottomSprite);
rightBottom.setHorizontalEdge(ccui.LayoutComponent.horizontalEdge.RIGHT);
rightBottom.setVerticalEdge(ccui.LayoutComponent.verticalEdge.BOTTOM);
rightBottom.setStretchWidthEnabled(true);
rightBottom.setStretchHeightEnabled(true);
this._baseLayer.addChild(rightBottomSprite);
rightBottom.setSize(rightBottomSprite.getContentSize());
rightBottom.setBottomMargin(0);
rightBottom.setRightMargin(0);
ccui.helper.doLayout(this._baseLayer);
return true;
}
return false;
}
});
@@ -1,334 +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 UIListViewTest_Vertical = UIMainLayer.extend({
init: function () {
if (this._super()) {
var widgetSize = this._widget.getContentSize();
var backgroundSize = this._backgroundSize;
this._topDisplayLabel.setString("Scroll listview is disabled.");
this._topDisplayLabel.x = widgetSize.width / 2.0;
this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5;
this._array = [];
for (var i = 0; i < 20; ++i) {
this._array.push("item_" + i);
}
// Create the list view
var listView = new ccui.ListView();
// set list view ex direction
listView.setDirection(ccui.ScrollView.Dir.NONE);
listView.setTouchEnabled(false);
listView.setBounceEnabled(false);
listView.setBackGroundImage("ccs-res/cocosui/green_edit.png");
listView.setBackGroundImageScale9Enabled(true);
listView.setContentSize(cc.size(240, 130));
listView.x = (widgetSize.width - backgroundSize.width) / 2 + (backgroundSize.width - listView.width) / 2;
listView.y = (widgetSize.height - backgroundSize.height) / 2 + (backgroundSize.height - listView.height) / 2;
listView.addEventListener(this.selectedItemEvent, this);
this._mainNode.addChild(listView);
// create model
var default_button = new ccui.Button();
default_button.setName("TextButton");
default_button.setTouchEnabled(true);
default_button.loadTextures("ccs-res/cocosui/backtotoppressed.png", "ccs-res/cocosui/backtotopnormal.png", "");
var default_item = new ccui.Layout();
default_item.setTouchEnabled(true);
default_item.setContentSize(default_button.getContentSize());
default_item.width = listView.width;
default_button.x = default_item.width / 2;
default_button.y = default_item.height / 2;
default_item.addChild(default_button);
// set model
listView.setItemModel(default_item);
// add default item
var count = this._array.length;
for (var i = 0; i < count / 4; ++i) {
listView.pushBackDefaultItem();
}
// insert default item
for (var i = 0; i < count / 4; ++i) {
listView.insertDefaultItem(0);
}
// add custom item
for (var i = 0; i < count / 4; ++i) {
var custom_button = new ccui.Button();
custom_button.setName("TextButton");
custom_button.setTouchEnabled(true);
custom_button.setScale9Enabled(true);
custom_button.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", "");
custom_button.setContentSize(default_button.getContentSize());
var custom_item = new ccui.Layout();
custom_item.setContentSize(custom_button.getContentSize());
custom_item.width = listView.width;
custom_button.x = custom_item.width / 2;
custom_button.y = custom_item.height / 2;
custom_item.addChild(custom_button);
listView.pushBackCustomItem(custom_item);
}
// insert custom item
var items_count = listView.getItems().length;
for (var i = 0; i < count / 4; ++i) {
var custom_button = new ccui.Button();
custom_button.setName("TextButton");
custom_button.setTouchEnabled(true);
custom_button.setScale9Enabled(true);
custom_button.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", "");
custom_button.setContentSize(default_button.getContentSize());
var custom_item = new ccui.Layout();
custom_item.setContentSize(custom_button.getContentSize());
custom_item.width = listView.width;
custom_button.x = custom_item.width / 2;
custom_button.y = custom_item.height / 2;
custom_item.addChild(custom_button);
listView.insertCustomItem(custom_item, items_count);
}
// set item data
items_count = listView.getItems().length;
for (var i = 0; i < items_count; ++i) {
var item = listView.getItem(i);
var button = item.getChildByName("TextButton");
var index = listView.getIndex(item);
button.setTitleText(this._array[index]);
}
// remove last item
listView.removeLastItem();
// remove item by index
items_count = listView.getItems().length;
listView.removeItem(items_count - 1);
// set all items layout gravity
listView.setGravity(ccui.ListView.GRAVITY_CENTER_VERTICAL);
return true;
}
return false;
},
selectedItemEvent: function (sender, type) {
switch (type) {
case ccui.ListView.EVENT_SELECTED_ITEM:
var listViewEx = sender;
cc.log("select child index = " + listViewEx.getCurSelectedIndex());
break;
default:
break;
}
}
});
var UIListViewTest_Horizontal = UIMainLayer.extend({
_array: null,
init: function () {
if (this._super()) {
var widgetSize = this._widget.getContentSize();
var backgroundSize = this._backgroundSize;
// create list view ex data
this._array = [];
var i;
for (i = 0; i < 20; ++i) {
this._array.push("item_" + i);
}
// Create the list view
var listView = new ccui.ListView();
// set list view ex direction
listView.setDirection(ccui.ScrollView.Dir.HORIZONTAL);
listView.setTouchEnabled(true);
listView.setBounceEnabled(true);
listView.setBackGroundImage("ccs-res/cocosui/green_edit.png");
listView.setBackGroundImageScale9Enabled(true);
listView.setContentSize(cc.size(240, 130));
listView.x = (widgetSize.width - backgroundSize.width) / 2 + (backgroundSize.width - listView.width) / 2;
listView.y = (widgetSize.height - backgroundSize.height) / 2 + (backgroundSize.height - listView.height) / 2;
listView.addEventListener(this.selectedItemEvent, this);
this._mainNode.addChild(listView);
// create model
var default_button = new ccui.Button();
default_button.setName("TextButton");
default_button.setTouchEnabled(true);
default_button.loadTextures("ccs-res/cocosui/backtotoppressed.png", "ccs-res/cocosui/backtotopnormal.png", "");
var default_item = new ccui.Layout();
default_item.setTouchEnabled(true);
default_item.setContentSize(default_button.getContentSize());
default_button.x = default_item.width / 2;
default_button.y = default_item.height / 2;
default_item.addChild(default_button);
// set model
listView.setItemModel(default_item);
// add default item
var count = this._array.length;
for (i = 0; i < count / 4; ++i) {
listView.pushBackDefaultItem();
}
// insert default item
for (i = 0; i < count / 4; ++i) {
listView.insertDefaultItem(0);
}
// add custom item
for (i = 0; i < count / 4; ++i) {
var custom_button = new ccui.Button();
custom_button.setName("TextButton");
custom_button.setTouchEnabled(true);
custom_button.setScale9Enabled(true);
custom_button.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", "");
custom_button.setContentSize(default_button.getContentSize());
var custom_item = new ccui.Layout();
custom_item.setContentSize(custom_button.getContentSize());
custom_button.x = custom_item.width / 2;
custom_button.y = custom_item.height / 2;
custom_item.addChild(custom_button);
listView.pushBackCustomItem(custom_item);
}
// insert custom item
var items_count = listView.getItems().length;
for (i = 0; i < count / 4; ++i) {
var custom_button = new ccui.Button();
custom_button.setName("TextButton");
custom_button.setTouchEnabled(true);
custom_button.setScale9Enabled(true);
custom_button.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", "");
custom_button.setContentSize(default_button.getContentSize());
var custom_item = new ccui.Layout();
custom_item.setContentSize(custom_button.getContentSize());
custom_button.x = custom_item.width / 2;
custom_button.y = custom_item.height / 2;
custom_item.addChild(custom_button);
listView.insertCustomItem(custom_item, items_count);
}
// set item data
items_count = listView.getItems().length;
for (i = 0; i < items_count; ++i) {
var item = listView.getItem(i);
var button = item.getChildByName("TextButton");
var index = listView.getIndex(item);
button.setTitleText(this._array[index]);
}
// remove last item
listView.removeLastItem();
// remove item by index
items_count = listView.getItems().length;
listView.removeItem(items_count - 1);
// set all items layout gravity
listView.setGravity(ccui.ListView.GRAVITY_CENTER_VERTICAL);
// set items margin
listView.setItemsMargin(2);
return true;
}
return false;
},
selectedItemEvent: function (sender, type) {
switch (type) {
case ccui.ListView.EVENT_SELECTED_ITEM:
cc.log("select child index = " + sender.getCurSelectedIndex());
break;
default:
break;
}
}
});
var UIListViewTest_TouchIntercept = UIMainLayer.extend({
init: function () {
if(this._super()) {
var widgetSize = this._widget.getContentSize();
var backgroundSize = this._backgroundSize;
this._topDisplayLabel.setString("TouchIntercept");
this._topDisplayLabel.x = widgetSize.width / 2.0;
this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5;
this._bottomDisplayLabel.setString("ListView Disable Touch");
this._bottomDisplayLabel.x = widgetSize.width / 2;
this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3;
// Create the list view
var listView = new ccui.ListView();
// set list view ex direction
listView.setDirection(ccui.ScrollView.Dir.NONE);
listView.setBounceEnabled(true);
listView.setTouchEnabled(false);
listView.setBackGroundImage("ccs-res/cocosui/green_edit.png");
listView.setBackGroundImageScale9Enabled(true);
listView.setContentSize(cc.size(240, 130));
listView.x = (widgetSize.width - backgroundSize.width) / 2 + (backgroundSize.width - listView.width) / 2;
listView.y = (widgetSize.height - backgroundSize.height) / 2 + (backgroundSize.height - listView.height) / 2;
this._mainNode.addChild(listView);
// create model
var default_button = new ccui.Button();
default_button.setName("Title Button");
default_button.loadTextures("ccs-res/cocosui/backtotoppressed.png", "ccs-res/cocosui/backtotopnormal.png", "");
var default_item = new ccui.Layout();
default_item.setTouchEnabled(true);
default_item.setContentSize(default_button.getContentSize());
default_item.width = listView.width;
default_button.x = default_item.width / 2;
default_button.y = default_item.height / 2;
default_item.addChild(default_button);
// set model
listView.setItemModel(default_item);
listView.pushBackDefaultItem();
listView.pushBackDefaultItem();
listView.pushBackDefaultItem();
return true;
}
return false;
}
});
@@ -1,170 +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 UILoadingBarTest = UIMainLayer.extend({
_count: 0,
_loadingBar:null,
ctor: function () {
this._super();
this._count = 0;
},
init: function () {
if (this._super()) {
var widgetSize = this._widget.getContentSize();
//init text
this._topDisplayLabel.setString("");
this._bottomDisplayLabel.setString("LoadingBar");
this.createLoadingBar();
this.scheduleUpdate();
return true;
}
return false;
},
createLoadingBar: function () {
// override me
},
update: function (dt) {
this._count++;
if (this._count > 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;
}
});
@@ -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;
}
});
@@ -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;
}
});
@@ -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);
}
}
}
});
@@ -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;
}
});
-102
View File
@@ -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());
}
});
@@ -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);
@@ -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);
}
}
});
@@ -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;
}
});
@@ -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());
}
});
@@ -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;
}
}
});
@@ -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);
});
}
});
@@ -1,21 +0,0 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Test1</title>
</head>
<body>
<style>
body{ font-family: 微软雅黑; text-align: center; font-size: 26px; }
.title{ font-size: 40px; }
#test{ font-size: 30px;}
</style>
<div class="title">
Page 1
</div>
<div>
<a href="webview2.html">goto page2</a>
</div>
<div id="test"></div>
</body>
</html>
@@ -1,21 +0,0 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<style>
body{ font-family: 微软雅黑; text-align: center; font-size: 26px; }
.title{ font-size: 40px; }
#test{ font-size: 30px;}
</style>
<div class="title">
Page 2
</div>
<div>
<a href="webview.html">goto page1</a>
</div>
<div id="test"></div>
</body>
</html>