From 43ea04da3cbf5bdbf540cfb0b78dbdc48b5159df Mon Sep 17 00:00:00 2001 From: zhang <506830650@qq.com> Date: Sun, 28 Jun 2015 13:18:33 +0800 Subject: [PATCH 01/43] fix onTouch begin don't return value fix only receive "begin" envent,can't receive "moved" "ended" --- .../scripting/lua-bindings/script/framework/extends/LayerEx.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/script/framework/extends/LayerEx.lua b/cocos/scripting/lua-bindings/script/framework/extends/LayerEx.lua index 1ab2e76e8a..c52921ad19 100644 --- a/cocos/scripting/lua-bindings/script/framework/extends/LayerEx.lua +++ b/cocos/scripting/lua-bindings/script/framework/extends/LayerEx.lua @@ -43,7 +43,7 @@ function Layer:onTouch(callback, isMultiTouches, swallowTouches) event.x = args[1] event.y = args[2] end - callback(event) + return callback(event) end, isMultiTouches, 0, swallowTouches) self:setTouchEnabled(true) return self From 48c3466774e7c7df76197fd349ba0f25da5fb922 Mon Sep 17 00:00:00 2001 From: zhang <506830650@qq.com> Date: Wed, 1 Jul 2015 20:25:45 +0800 Subject: [PATCH 02/43] Update LayerEx.lua --- .../scripting/lua-bindings/script/framework/extends/LayerEx.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/script/framework/extends/LayerEx.lua b/cocos/scripting/lua-bindings/script/framework/extends/LayerEx.lua index c52921ad19..6bba1b2d81 100644 --- a/cocos/scripting/lua-bindings/script/framework/extends/LayerEx.lua +++ b/cocos/scripting/lua-bindings/script/framework/extends/LayerEx.lua @@ -43,7 +43,7 @@ function Layer:onTouch(callback, isMultiTouches, swallowTouches) event.x = args[1] event.y = args[2] end - return callback(event) + return callback( event ) end, isMultiTouches, 0, swallowTouches) self:setTouchEnabled(true) return self From 155b9b918c5ff8ef7076842d240f526ab528dd8d Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 3 Jul 2015 11:01:43 +0800 Subject: [PATCH 03/43] Add retain/release for XMLHTTPReqest in JSB --- .../manual/network/XMLHTTPRequest.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp index 8d215e1f2d..162ec181ef 100644 --- a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp +++ b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp @@ -943,6 +943,34 @@ void MinXmlHttpRequest::_notify(JSObject * callback) } } +bool js_MinXmlHttpRequest_retain(JSContext *cx, uint32_t argc, jsval *vp) +{ + JSObject *thisObj = JS_THIS_OBJECT(cx, vp); + if (thisObj) { + js_proxy_t *proxy = jsb_get_js_proxy(thisObj); + if (proxy) { + ((cocos2d::Ref *)proxy->ptr)->retain(); + return true; + } + } + JS_ReportError(cx, "Invalid Native Object."); + return false; +} + +bool js_MinXmlHttpRequest_release(JSContext *cx, uint32_t argc, jsval *vp) +{ + JSObject *thisObj = JS_THIS_OBJECT(cx, vp); + if (thisObj) { + js_proxy_t *proxy = jsb_get_js_proxy(thisObj); + if (proxy) { + ((cocos2d::Ref *)proxy->ptr)->release(); + return true; + } + } + JS_ReportError(cx, "Invalid Native Object."); + return false; +} + /** * @brief Register XMLHttpRequest to be usable in JS and add properties and Mehtods. * @param cx Global Spidermonkey JS Context. @@ -986,6 +1014,8 @@ void MinXmlHttpRequest::_js_register(JSContext *cx, JS::HandleObject global) JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, getAllResponseHeaders), JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, getResponseHeader), JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, overrideMimeType), + JS_FN("retain", js_MinXmlHttpRequest_retain, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("release", js_MinXmlHttpRequest_release, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; From f27b370b94d82bfd38873e33cbbd48f97f0aef27 Mon Sep 17 00:00:00 2001 From: Bin Zhang Date: Fri, 3 Jul 2015 11:31:40 +0800 Subject: [PATCH 04/43] Add argument --ios to compile Mac & iOS platforms separately. --- tools/framework-compile/bin/gen_cocos_libs.py | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/tools/framework-compile/bin/gen_cocos_libs.py b/tools/framework-compile/bin/gen_cocos_libs.py index eacb80612e..2546233117 100755 --- a/tools/framework-compile/bin/gen_cocos_libs.py +++ b/tools/framework-compile/bin/gen_cocos_libs.py @@ -45,6 +45,7 @@ class CocosLibsCompiler(object): self.clean = args.clean self.build_win = args.win self.build_mac = args.mac + self.build_ios = args.ios self.build_android = args.android self.disable_strip = args.disable_strip self.repo_x = args.repo_x @@ -53,6 +54,7 @@ class CocosLibsCompiler(object): if args.all: self.build_win = True self.build_mac = True + self.build_ios = True self.build_android = True if args.app_abi is None: @@ -87,7 +89,7 @@ class CocosLibsCompiler(object): self.clean_libs() if self.build_win: self.compile_win() - if self.build_mac: + if self.build_mac or self.build_ios: self.compile_mac_ios() if self.build_android: self.compile_android() @@ -229,36 +231,38 @@ class CocosLibsCompiler(object): xcode_proj_info = self.cfg_info[CocosLibsCompiler.KEY_XCODE_PROJS_INFO] XCODE_CMD_FMT = "xcodebuild -project \"%s\" -configuration Release -target \"%s\" %s CONFIGURATION_BUILD_DIR=%s" + ios_out_dir = os.path.join(self.lib_dir, "ios") + mac_out_dir = os.path.join(self.lib_dir, "mac") + ios_sim_libs_dir = os.path.join(ios_out_dir, "simulator") + ios_dev_libs_dir = os.path.join(ios_out_dir, "device") for key in xcode_proj_info.keys(): proj_path = os.path.join(self.repo_x, key) - ios_out_dir = os.path.join(self.lib_dir, "ios") - mac_out_dir = os.path.join(self.lib_dir, "mac") - ios_sim_libs_dir = os.path.join(ios_out_dir, "simulator") - ios_dev_libs_dir = os.path.join(ios_out_dir, "device") - target = xcode_proj_info[key][CocosLibsCompiler.KEY_XCODE_TARGETS] - # compile ios simulator - build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target, "-sdk iphonesimulator ARCHS=\"i386 x86_64\" VALID_ARCHS=\"i386 x86_64\"", ios_sim_libs_dir) - retVal = utils_cocos.execute_command(build_cmd) - if 0 != retVal: - print("[ERROR] compile ios simulator fail") - return retVal + if self.build_mac: + # compile mac + build_cmd = XCODE_CMD_FMT % (proj_path, "%s Mac" % target, "", mac_out_dir) + retVal = utils_cocos.execute_command(build_cmd) + if 0 != retVal: + print("[ERROR] compile mac fail") + return retVal - # compile ios device - build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target, "-sdk iphoneos", ios_dev_libs_dir) - retVal = utils_cocos.execute_command(build_cmd) - if 0 != retVal: - print("[ERROR] compile ios device fail") - return retVal + if self.build_ios: + # compile ios simulator + build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target, "-sdk iphonesimulator ARCHS=\"i386 x86_64\" VALID_ARCHS=\"i386 x86_64\"", ios_sim_libs_dir) + retVal = utils_cocos.execute_command(build_cmd) + if 0 != retVal: + print("[ERROR] compile ios simulator fail") + return retVal - # compile mac - build_cmd = XCODE_CMD_FMT % (proj_path, "%s Mac" % target, "", mac_out_dir) - retVal = utils_cocos.execute_command(build_cmd) - if 0 != retVal: - print("[ERROR] compile mac fail") - return retVal + # compile ios device + build_cmd = XCODE_CMD_FMT % (proj_path, "%s iOS" % target, "-sdk iphoneos", ios_dev_libs_dir) + retVal = utils_cocos.execute_command(build_cmd) + if 0 != retVal: + print("[ERROR] compile ios device fail") + return retVal + if self.build_ios: # generate fat libs for iOS for lib in os.listdir(ios_sim_libs_dir): sim_lib = os.path.join(ios_sim_libs_dir, lib) @@ -272,10 +276,12 @@ class CocosLibsCompiler(object): utils_cocos.rmdir(ios_sim_libs_dir) utils_cocos.rmdir(ios_dev_libs_dir) - if not self.disable_strip: - # strip the libs + if not self.disable_strip: + # strip the libs + if self.build_ios: ios_strip_cmd = "xcrun -sdk iphoneos strip -S %s/*.a" % ios_out_dir utils_cocos.execute_command(ios_strip_cmd) + if self.build_mac: mac_strip_cmd = "xcrun strip -S %s/*.a" % mac_out_dir utils_cocos.execute_command(mac_strip_cmd) @@ -378,7 +384,8 @@ if __name__ == "__main__": parser.add_argument('-c', dest='clean', action="store_true", help='clean libs folder') parser.add_argument('-all', dest='all', action="store_true", help='compile all platform') parser.add_argument('--win', dest='win', action="store_true", help='compile windows platform') - parser.add_argument('--mac', dest='mac', action="store_true", help='compile mac platform') + parser.add_argument('--mac', dest='mac', action="store_true", help='compile Mac platform') + parser.add_argument('--ios', dest='ios', action="store_true", help='compile iOS platform') parser.add_argument('--android', dest='android', action="store_true",help='complile android platform') parser.add_argument('--dis-strip', "--disable-strip", dest='disable_strip', action="store_true", help='Disable the strip of the generated libs.') parser.add_argument('--vs', dest='vs_version', type=int, help='visual studio version, such as 2013.', default=None) From 1f48beee1e4cce2ef60678a62b1126c751f9f086 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Fri, 3 Jul 2015 12:55:55 +0800 Subject: [PATCH 05/43] Reorganize code --- .../js-bindings/manual/cocos2d_specifics.hpp | 3 ++ .../jsb_cocos2dx_extension_manual.cpp | 37 ++----------------- .../manual/network/XMLHTTPRequest.cpp | 33 ++--------------- 3 files changed, 10 insertions(+), 63 deletions(-) diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp index 2fc54b6583..fa8c6ff9e9 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp @@ -265,6 +265,9 @@ bool js_cocos2dx_Node_onExitTransitionDidStart(JSContext *cx, uint32_t argc, jsv bool js_cocos2dx_Component_onEnter(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Component_onExit(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_retain(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_release(JSContext *cx, uint32_t argc, jsval *vp); + void get_or_create_js_obj(JSContext* cx, JS::HandleObject obj, const std::string &name, JS::MutableHandleObject jsObj); #endif diff --git a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp index 597701d0ba..4f72251f72 100644 --- a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp @@ -879,35 +879,6 @@ bool js_cocos2dx_ext_AssetsManager_getFailedAssets(JSContext *cx, uint32_t argc, } */ -bool js_cocos2dx_ext_retain(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *thisObj = JS_THIS_OBJECT(cx, vp); - if (thisObj) { - js_proxy_t *proxy = jsb_get_js_proxy(thisObj); - if (proxy) { - ((Ref *)proxy->ptr)->retain(); - return true; - } - } - JS_ReportError(cx, "Invalid Native Object."); - return false; -} - -bool js_cocos2dx_ext_release(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *thisObj = JS_THIS_OBJECT(cx, vp); - if (thisObj) { - js_proxy_t *proxy = jsb_get_js_proxy(thisObj); - if (proxy) { - ((Ref *)proxy->ptr)->release(); - return true; - } - } - JS_ReportError(cx, "Invalid Native Object."); - return false; -} - - __JSDownloaderDelegator::__JSDownloaderDelegator(JSContext *cx, JS::HandleObject obj, const std::string &url, JS::HandleObject callback) : _cx(cx) , _url(url) @@ -1077,11 +1048,11 @@ void register_all_cocos2dx_extension_manual(JSContext* cx, JS::HandleObject glob get_or_create_js_obj(cx, global, "cc", &ccObj); JS::RootedObject am(cx, jsb_cocos2d_extension_AssetsManagerEx_prototype); - JS_DefineFunction(cx, am, "retain", js_cocos2dx_ext_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, am, "release", js_cocos2dx_ext_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, am, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, am, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS::RootedObject manifest(cx, jsb_cocos2d_extension_Manifest_prototype); - JS_DefineFunction(cx, manifest, "retain", js_cocos2dx_ext_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); - JS_DefineFunction(cx, manifest, "release", js_cocos2dx_ext_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, manifest, "retain", js_cocos2dx_retain, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); + JS_DefineFunction(cx, manifest, "release", js_cocos2dx_release, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); //JS_DefineFunction(cx, jsb_cocos2d_extension_AssetsManager_prototype, "updateAssets", js_cocos2dx_ext_AssetsManager_updateAssets, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); //JS_DefineFunction(cx, jsb_cocos2d_extension_AssetsManager_prototype, "getFailedAssets", js_cocos2dx_ext_AssetsManager_getFailedAssets, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); diff --git a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp index 162ec181ef..402a318874 100644 --- a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp +++ b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp @@ -29,6 +29,7 @@ #include "XMLHTTPRequest.h" #include #include +#include "cocos2d_specifics.hpp" using namespace std; @@ -943,34 +944,6 @@ void MinXmlHttpRequest::_notify(JSObject * callback) } } -bool js_MinXmlHttpRequest_retain(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *thisObj = JS_THIS_OBJECT(cx, vp); - if (thisObj) { - js_proxy_t *proxy = jsb_get_js_proxy(thisObj); - if (proxy) { - ((cocos2d::Ref *)proxy->ptr)->retain(); - return true; - } - } - JS_ReportError(cx, "Invalid Native Object."); - return false; -} - -bool js_MinXmlHttpRequest_release(JSContext *cx, uint32_t argc, jsval *vp) -{ - JSObject *thisObj = JS_THIS_OBJECT(cx, vp); - if (thisObj) { - js_proxy_t *proxy = jsb_get_js_proxy(thisObj); - if (proxy) { - ((cocos2d::Ref *)proxy->ptr)->release(); - return true; - } - } - JS_ReportError(cx, "Invalid Native Object."); - return false; -} - /** * @brief Register XMLHttpRequest to be usable in JS and add properties and Mehtods. * @param cx Global Spidermonkey JS Context. @@ -1014,8 +987,8 @@ void MinXmlHttpRequest::_js_register(JSContext *cx, JS::HandleObject global) JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, getAllResponseHeaders), JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, getResponseHeader), JS_BINDED_FUNC_FOR_DEF(MinXmlHttpRequest, overrideMimeType), - JS_FN("retain", js_MinXmlHttpRequest_retain, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("release", js_MinXmlHttpRequest_release, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("retain", js_cocos2dx_retain, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("release", js_cocos2dx_release, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; From 6f3fc302e6c6e7eca8661d1a03973e1d05394319 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sat, 4 Jul 2015 08:39:49 +0800 Subject: [PATCH 06/43] Fix web view and video player in simulator --- .../frameworks/runtime-src/Classes/js_module_register.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h b/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h index 866557a0ed..1eb7d05e35 100644 --- a/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h +++ b/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h @@ -28,7 +28,9 @@ #include "navmesh/jsb_cocos2dx_navmesh_manual.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) +#include "experimental/jsb_cocos2dx_experimental_video_auto.hpp" #include "experimental/jsb_cocos2dx_experimental_video_manual.h" +#include "experimental/jsb_cocos2dx_experimental_webView_auto.hpp" #include "experimental/jsb_cocos2dx_experimental_webView_manual.h" #endif @@ -97,7 +99,9 @@ int js_module_register() #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + sc->addRegisterCallback(register_all_cocos2dx_experimental_video); sc->addRegisterCallback(register_all_cocos2dx_experimental_video_manual); + sc->addRegisterCallback(register_all_cocos2dx_experimental_webView); sc->addRegisterCallback(register_all_cocos2dx_experimental_webView_manual); #endif From 2cae17b462435e89e6e7e1bab0c1f233b5eaa1b1 Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Wed, 1 Jul 2015 12:41:47 +0900 Subject: [PATCH 07/43] Add scroll bar feature into ScrollView --- build/cocos2d_libs.xcodeproj/project.pbxproj | 12 + cocos/ui/Android.mk | 1 + cocos/ui/UIScrollView.cpp | 495 ++++++++++-------- cocos/ui/UIScrollView.h | 59 ++- cocos/ui/UIScrollViewBar.cpp | 262 +++++++++ cocos/ui/UIScrollViewBar.h | 92 ++++ .../UIScrollViewTest/UIScrollViewTest.cpp | 11 +- 7 files changed, 693 insertions(+), 239 deletions(-) create mode 100644 cocos/ui/UIScrollViewBar.cpp create mode 100644 cocos/ui/UIScrollViewBar.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 8e5326b405..fa21588217 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -2017,6 +2017,10 @@ B5CE6DC91B3C05BA002B0419 /* UIRadioButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5CE6DC61B3C05BA002B0419 /* UIRadioButton.cpp */; }; B5CE6DCA1B3C05BA002B0419 /* UIRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = B5CE6DC71B3C05BA002B0419 /* UIRadioButton.h */; }; B5CE6DCB1B3C05BA002B0419 /* UIRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = B5CE6DC71B3C05BA002B0419 /* UIRadioButton.h */; }; + B5668D7D1B3838E4003CBD5E /* UIScrollViewBar.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5668D7B1B3838E4003CBD5E /* UIScrollViewBar.cpp */; }; + B5668D7E1B3838E4003CBD5E /* UIScrollViewBar.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B5668D7B1B3838E4003CBD5E /* UIScrollViewBar.cpp */; }; + B5668D7F1B3838E4003CBD5E /* UIScrollViewBar.h in Headers */ = {isa = PBXBuildFile; fileRef = B5668D7C1B3838E4003CBD5E /* UIScrollViewBar.h */; }; + B5668D801B3838E4003CBD5E /* UIScrollViewBar.h in Headers */ = {isa = PBXBuildFile; fileRef = B5668D7C1B3838E4003CBD5E /* UIScrollViewBar.h */; }; B603F1A81AC8EA0900A9579C /* CCTerrain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B603F1A61AC8EA0900A9579C /* CCTerrain.cpp */; }; B603F1A91AC8EA0900A9579C /* CCTerrain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B603F1A61AC8EA0900A9579C /* CCTerrain.cpp */; }; B603F1AA1AC8EA0900A9579C /* CCTerrain.h in Headers */ = {isa = PBXBuildFile; fileRef = B603F1A71AC8EA0900A9579C /* CCTerrain.h */; }; @@ -4704,6 +4708,8 @@ B5CE6DBD1B3BF2B1002B0419 /* UIAbstractCheckButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIAbstractCheckButton.h; sourceTree = ""; }; B5CE6DC61B3C05BA002B0419 /* UIRadioButton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIRadioButton.cpp; sourceTree = ""; }; B5CE6DC71B3C05BA002B0419 /* UIRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIRadioButton.h; sourceTree = ""; }; + B5668D7B1B3838E4003CBD5E /* UIScrollViewBar.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIScrollViewBar.cpp; sourceTree = ""; }; + B5668D7C1B3838E4003CBD5E /* UIScrollViewBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScrollViewBar.h; sourceTree = ""; }; B603F1A61AC8EA0900A9579C /* CCTerrain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTerrain.cpp; sourceTree = ""; }; B603F1A71AC8EA0900A9579C /* CCTerrain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTerrain.h; sourceTree = ""; }; B603F1B11AC8F1FD00A9579C /* ccShader_3D_Terrain.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_Terrain.frag; sourceTree = ""; }; @@ -6841,6 +6847,8 @@ 2905FA0518CF08D000240AA3 /* UIRichText.h */, 2905FA0718CF08D000240AA3 /* UIScrollView.cpp */, 2905FA0818CF08D000240AA3 /* UIScrollView.h */, + B5668D7B1B3838E4003CBD5E /* UIScrollViewBar.cpp */, + B5668D7C1B3838E4003CBD5E /* UIScrollViewBar.h */, 2905FA0918CF08D000240AA3 /* UISlider.cpp */, 2905FA0A18CF08D100240AA3 /* UISlider.h */, 2905FA0B18CF08D100240AA3 /* UIText.cpp */, @@ -9405,6 +9413,7 @@ B6CAB24B1AF9AA1A00B9B856 /* btConvexPlaneCollisionAlgorithm.h in Headers */, B6CAB5391AF9AA1A00B9B856 /* cl.h in Headers */, 15AE1BC219AADFFB00C27E9E /* ExtensionMacros.h in Headers */, + B5668D7F1B3838E4003CBD5E /* UIScrollViewBar.h in Headers */, B665E4001AA80A6600DDB1C5 /* CCPUSphereCollider.h in Headers */, B6CAB42D1AF9AA1A00B9B856 /* btVehicleRaycaster.h in Headers */, 15AE1BDF19AAE01E00C27E9E /* CCInvocation.h in Headers */, @@ -10459,6 +10468,7 @@ B6CAB4B01AF9AA1A00B9B856 /* SpuCollisionTaskProcess.h in Headers */, 15AE185D19AAD31200C27E9E /* CocosDenshion.h in Headers */, B6CAB3661AF9AA1A00B9B856 /* btContinuousConvexCollision.h in Headers */, + B5668D801B3838E4003CBD5E /* UIScrollViewBar.h in Headers */, 15AE194319AAD35100C27E9E /* CCColliderDetector.h in Headers */, 382F7ADF1AB1292A002EBECF /* CCObjectExtensionData.h in Headers */, B6CAB3A81AF9AA1A00B9B856 /* btConstraintSolver.h in Headers */, @@ -11584,6 +11594,7 @@ 50ABC00D1926664800A911A9 /* CCFileUtils.cpp in Sources */, 50ABBE4D1925AB6F00A911A9 /* CCEventCustom.cpp in Sources */, 15AE1A6819AAD40300C27E9E /* b2WorldCallbacks.cpp in Sources */, + B5668D7D1B3838E4003CBD5E /* UIScrollViewBar.cpp in Sources */, B665E2D21AA80A6500DDB1C5 /* CCPUInterParticleColliderTranslator.cpp in Sources */, B6CAB3811AF9AA1A00B9B856 /* btMinkowskiPenetrationDepthSolver.cpp in Sources */, B6CAB4AD1AF9AA1A00B9B856 /* SpuCollisionTaskProcess.cpp in Sources */, @@ -11735,6 +11746,7 @@ 38B8E2E219E671D2002D7CE7 /* UILayoutComponent.cpp in Sources */, B6CAB3D21AF9AA1A00B9B856 /* btSliderConstraint.cpp in Sources */, B2165EEA19921124000BE3E6 /* CCPrimitiveCommand.cpp in Sources */, + B5668D7E1B3838E4003CBD5E /* UIScrollViewBar.cpp in Sources */, B665E32B1AA80A6500DDB1C5 /* CCPUOnCountObserver.cpp in Sources */, 15AE185C19AAD31200C27E9E /* CDOpenALSupport.m in Sources */, B6CAB3B01AF9AA1A00B9B856 /* btFixedConstraint.cpp in Sources */, diff --git a/cocos/ui/Android.mk b/cocos/ui/Android.mk index d68a3e937f..09596acbd8 100644 --- a/cocos/ui/Android.mk +++ b/cocos/ui/Android.mk @@ -19,6 +19,7 @@ UIHelper.cpp \ UIListView.cpp \ UIPageView.cpp \ UIScrollView.cpp \ +UIScrollViewBar.cpp \ UIButton.cpp \ UIAbstractCheckButton.cpp \ UICheckBox.cpp \ diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index c57ee7bd1b..de8a1a8c76 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -26,17 +26,19 @@ THE SOFTWARE. #include "base/CCDirector.h" #include "base/ccUtils.h" #include "platform/CCDevice.h" +#include "ui/UIScrollViewBar.h" #include "2d/CCTweenFunction.h" #include "2d/CCCamera.h" NS_CC_BEGIN namespace ui { -static const float INERTIA_DEACCELERATION = 3000.0f; -static const float BOUNCE_BACK_DURATION = 0.3f; +static const float INERTIA_DEACCELERATION = 700.0f; +static const float INERTIA_VELOCITY_MAX = 2500; +static const float BOUNCE_BACK_DURATION = 1.0f; #define MOVE_INCH 7.0f/160.0f -static float convertDistanceFromPointToInch(Vec2 dis) +static float convertDistanceFromPointToInch(const Vec2& dis) { auto glview = Director::getInstance()->getOpenGLView(); int dpi = Device::getDPI(); @@ -66,6 +68,9 @@ _autoScrollDuration(0), _autoScrollAccumulatedTime(0), _bounceEnabled(false), _bouncingBack(false), +_scrollBarEnabled(true), +_verticalScrollBar(nullptr), +_horizontalScrollBar(nullptr), _scrollViewEventListener(nullptr), _scrollViewEventSelector(nullptr), _eventCallback(nullptr) @@ -75,6 +80,8 @@ _eventCallback(nullptr) ScrollView::~ScrollView() { + _verticalScrollBar = nullptr; + _horizontalScrollBar = nullptr; _scrollViewEventListener = nullptr; _scrollViewEventSelector = nullptr; } @@ -111,6 +118,7 @@ bool ScrollView::init() { setClippingEnabled(true); _innerContainer->setTouchEnabled(false); + initScrollBar(); return true; } return false; @@ -138,7 +146,7 @@ void ScrollView::onSizeChanged() float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width); float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height); _innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight)); - _innerContainer->setPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height)); + moveChildrenToPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height)); } void ScrollView::setInnerContainerSize(const Size &size) @@ -196,7 +204,7 @@ void ScrollView::setInnerContainerSize(const Size &size) { pos.y = _contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getContentSize().height; } - _innerContainer->setPosition(pos); + moveChildrenToPosition(pos); } const Size& ScrollView::getInnerContainerSize() const @@ -266,8 +274,28 @@ Node* ScrollView::getChildByName(const std::string& name)const void ScrollView::moveChildren(float offsetX, float offsetY) { - Vec2 position = _innerContainer->getPosition() + Vec2(offsetX, offsetY); - _innerContainer->setPosition(position); + Vec2 position = _innerContainer->getPosition() + Vec2(offsetX, offsetY); + moveChildrenToPosition(position); +} + +void ScrollView::moveChildrenToPosition(const Vec2& position) +{ + _innerContainer->setPosition(position); + + Vec2 outOfBoundary = getHowMuchOutOfBoundary(Vec2::ZERO); + updateScrollBar(outOfBoundary); +} + +void ScrollView::updateScrollBar(const Vec2& outOfBoundary) +{ + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->onScrolled(outOfBoundary); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->onScrolled(outOfBoundary); + } } bool ScrollView::startBounceBackIfNeeded() @@ -313,44 +341,44 @@ Vec2 ScrollView::getHowMuchOutOfBoundary(const Vec2& addition) const void ScrollView::processAutoScrolling(float deltaTime) { - _autoScrollAccumulatedTime += deltaTime; - float percentage = _autoScrollAccumulatedTime / _autoScrollDuration; - if(percentage >= 1) - { - _innerContainer->setPosition(_autoScrollStartPosition + _autoScrollTargetDelta); - _autoScrolling = false; - _bouncingBack = false; - } - else - { - if(_autoScrollAttenuate) - { - percentage = tweenfunc::expoEaseOut(percentage); - } - Vec2 moveDelta = _autoScrollTargetDelta * percentage; - - // Dispatch related events if bouncing - if(_bouncingBack) - { - if(moveDelta.x > 0) - { - processScrollEvent(MoveDirection::RIGHT, true); - } - else if(moveDelta.x < 0) - { - processScrollEvent(MoveDirection::LEFT, true); - } - if(moveDelta.y > 0) - { - processScrollEvent(MoveDirection::TOP, true); - } - else if(moveDelta.y < 0) - { - processScrollEvent(MoveDirection::BOTTOM, true); - } - } - _innerContainer->setPosition(_autoScrollStartPosition + moveDelta); - } + _autoScrollAccumulatedTime += deltaTime; + float percentage = _autoScrollAccumulatedTime / _autoScrollDuration; + if(percentage >= 1) + { + moveChildrenToPosition(_autoScrollStartPosition + _autoScrollTargetDelta); + _autoScrolling = false; + _bouncingBack = false; + } + else + { + if(_autoScrollAttenuate) + { + percentage = tweenfunc::quintEaseOut(percentage); + } + Vec2 moveDelta = _autoScrollTargetDelta * percentage; + + // Dispatch related events if bouncing + if(_bouncingBack) + { + if(moveDelta.x > 0) + { + processScrollEvent(MoveDirection::RIGHT, true); + } + else if(moveDelta.x < 0) + { + processScrollEvent(MoveDirection::LEFT, true); + } + if(moveDelta.y > 0) + { + processScrollEvent(MoveDirection::TOP, true); + } + else if(moveDelta.y < 0) + { + processScrollEvent(MoveDirection::BOTTOM, true); + } + } + moveChildrenToPosition(_autoScrollStartPosition + moveDelta); + } } bool ScrollView::isOutOfBoundary(MoveDirection dir) const @@ -393,181 +421,156 @@ void ScrollView::jumpToDestination(const Vec2 &des) { float finalOffsetX = des.x; float finalOffsetY = des.y; - if (des.y <= 0 && _direction != Direction::HORIZONTAL) - { - finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getContentSize().height); - } - if (des.x <= 0 && _direction != Direction::VERTICAL) - { - finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getContentSize().width); - } - _innerContainer->setPosition(Vec2(finalOffsetX, finalOffsetY)); + if (des.y <= 0 && _direction != Direction::HORIZONTAL) + { + finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getContentSize().height); + } + if (des.x <= 0 && _direction != Direction::VERTICAL) + { + finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getContentSize().width); + } + moveChildrenToPosition(Vec2(finalOffsetX, finalOffsetY)); } void ScrollView::startInertiaScroll() { - if(_inertiaTouchTimeDeltas.empty()) - { - return; - } - - float totalDuration = 0; - for(auto i = _inertiaTouchTimeDeltas.begin(); i != _inertiaTouchTimeDeltas.end(); ++i) - { - totalDuration += (*i); - } - if(totalDuration >= 0.5f) - { - return; - } - - _inertiaScrolling = true; - - // Calcualte the initial velocity - Vec2 totalMovement; - for(auto i = _inertiaTouchDisplacements.begin(); i != _inertiaTouchDisplacements.end(); ++i) - { - totalMovement += (*i); - } - totalMovement.x = (_direction == Direction::VERTICAL ? 0 : totalMovement.x); - totalMovement.y = (_direction == Direction::HORIZONTAL ? 0 : totalMovement.y); - - _inertiaInitiVelocity = totalMovement / totalDuration; - - // Calculate values for ease out - _inertiaScrollExpectedTime = _inertiaInitiVelocity.length() / INERTIA_DEACCELERATION; - _inertiaScrollElapsedTime = 0; + float totalDuration = 0; + for(auto i = _inertiaTouchTimeDeltas.begin(); i != _inertiaTouchTimeDeltas.end(); ++i) + { + totalDuration += (*i); + } + if(totalDuration == 0 || totalDuration >= 0.5f) + { + return; + } + + _inertiaScrolling = true; + + // Calcualte the initial velocity + Vec2 totalMovement; + for(auto i = _inertiaTouchDisplacements.begin(); i != _inertiaTouchDisplacements.end(); ++i) + { + totalMovement += (*i); + } + totalMovement.x = (_direction == Direction::VERTICAL ? 0 : totalMovement.x); + totalMovement.y = (_direction == Direction::HORIZONTAL ? 0 : totalMovement.y); + + _inertiaInitiVelocity = totalMovement / totalDuration; + _inertiaInitiVelocity.x = MIN(_inertiaInitiVelocity.x, INERTIA_VELOCITY_MAX); + _inertiaInitiVelocity.y = MIN(_inertiaInitiVelocity.y, INERTIA_VELOCITY_MAX); + _inertiaInitiVelocity.x = MAX(_inertiaInitiVelocity.x, -INERTIA_VELOCITY_MAX); + _inertiaInitiVelocity.y = MAX(_inertiaInitiVelocity.y, -INERTIA_VELOCITY_MAX); + + // Calculate values for ease out + _inertiaScrollExpectedTime = _inertiaInitiVelocity.length() / INERTIA_DEACCELERATION; + _inertiaScrollElapsedTime = 0; } void ScrollView::processInertiaScrolling(float dt) { - _inertiaScrollElapsedTime += dt; - if(isOutOfBoundaryLeftOrRight() || isOutOfBoundaryTopOrBottom()) - { - // If the inner container is out of boundary, shorten the inertia time. - _inertiaScrollElapsedTime += dt * 15; - } - float percentage = _inertiaScrollElapsedTime / _inertiaScrollExpectedTime; - if(percentage >= 1) - { - _inertiaScrolling = false; - startBounceBackIfNeeded(); - return; - } - percentage = tweenfunc::expoEaseOut(percentage); - - Vec2 inertiaVelocity = _inertiaInitiVelocity * (1 - percentage); - Vec2 displacement = inertiaVelocity * dt; - if(!_bounceEnabled) - { - Vec2 outOfBoundary = getHowMuchOutOfBoundary(displacement); - if(outOfBoundary != Vec2::ZERO) - { - // Don't allow to go out of boundary - displacement += outOfBoundary; - _inertiaScrolling = false; - } - } - moveChildren(displacement.x, displacement.y); -} - -bool ScrollView::processScrollUp(float* offsetYResult, float touchOffsetY) -{ - float icBottomPos = _innerContainer->getBottomBoundary(); - if (icBottomPos + touchOffsetY < _bottomBoundary) - { - return true; - } - else if(!_bounceEnabled) - { - (*offsetYResult) = _bottomBoundary - icBottomPos; - } - processScrollEvent(MoveDirection::BOTTOM, false); - return false; -} + _inertiaScrollElapsedTime += dt; + if(isOutOfBoundaryLeftOrRight() || isOutOfBoundaryTopOrBottom()) + { + // If the inner container is out of boundary, shorten the inertia time. + _inertiaScrollElapsedTime += dt * (45000 / INERTIA_DEACCELERATION); + } + float percentage = _inertiaScrollElapsedTime / _inertiaScrollExpectedTime; + if(percentage >= 1) + { + _inertiaScrolling = false; + startBounceBackIfNeeded(); + return; + } + percentage = tweenfunc::quartEaseOut(percentage); -bool ScrollView::processScrollDown(float* offsetYResult, float touchOffsetY) -{ - float icTopPos = _innerContainer->getTopBoundary(); - if (icTopPos + touchOffsetY > _topBoundary) - { - return true; - } - else if(!_bounceEnabled) - { - (*offsetYResult) = _topBoundary - icTopPos; - } - processScrollEvent(MoveDirection::TOP, false); - return false; -} - -bool ScrollView::processScrollLeft(float* offsetXResult, float touchOffsetX) -{ - float icRightPos = _innerContainer->getRightBoundary(); - if (icRightPos + touchOffsetX > _rightBoundary) - { - return true; - } - else if(!_bounceEnabled) - { - (*offsetXResult) = _rightBoundary - icRightPos; - } - processScrollEvent(MoveDirection::RIGHT, false); - return false; -} - -bool ScrollView::processScrollRight(float* offsetXResult, float touchOffsetX) -{ - float icLeftPos = _innerContainer->getLeftBoundary(); - if (icLeftPos + touchOffsetX < _leftBoundary) - { - return true; - } - else if(!_bounceEnabled) - { - (*offsetXResult) = _leftBoundary - icLeftPos; - } - processScrollEvent(MoveDirection::LEFT, false); - return false; + Vec2 inertiaVelocity = _inertiaInitiVelocity * (1 - percentage); + Vec2 displacement = inertiaVelocity * dt; + if(!_bounceEnabled) + { + Vec2 outOfBoundary = getHowMuchOutOfBoundary(displacement); + if(outOfBoundary != Vec2::ZERO) + { + // Don't allow to go out of boundary + displacement += outOfBoundary; + _inertiaScrolling = false; + } + } + moveChildren(displacement.x, displacement.y); } bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY) { processScrollingEvent(); - - touchOffsetX = (_direction == Direction::VERTICAL ? 0 : touchOffsetX); - touchOffsetY = (_direction == Direction::HORIZONTAL ? 0 : touchOffsetY); - if(_bounceEnabled) - { - // If the position of the inner container is out of the boundary, the offsets should be divided by two. - touchOffsetX *= (isOutOfBoundaryLeftOrRight() ? 0.5f : 1); - touchOffsetY *= (isOutOfBoundaryTopOrBottom() ? 0.5f : 1); - } - - float realOffsetX = touchOffsetX; - float realOffsetY = touchOffsetY; - - bool scrollEnabledUpDown = true; - bool scrollEnabledLeftRight = true; - if (touchOffsetY > 0.0f) // up - { - scrollEnabledUpDown = processScrollUp(&realOffsetY, touchOffsetY); - } - else if (touchOffsetY < 0.0f) // down - { - scrollEnabledUpDown = processScrollDown(&realOffsetY, touchOffsetY); - } - - if (touchOffsetX < 0.0f) // left - { - scrollEnabledLeftRight = processScrollLeft(&realOffsetX, touchOffsetX); - } - else if (touchOffsetX > 0.0f) // right - { - scrollEnabledLeftRight = processScrollRight(&realOffsetX, touchOffsetX); - } - moveChildren(realOffsetX, realOffsetY); - return scrollEnabledUpDown || scrollEnabledLeftRight; + + touchOffsetX = (_direction == Direction::VERTICAL ? 0 : touchOffsetX); + touchOffsetY = (_direction == Direction::HORIZONTAL ? 0 : touchOffsetY); + if(_bounceEnabled) + { + // If the position of the inner container is out of the boundary, the offsets should be divided by two. + touchOffsetX *= (isOutOfBoundaryLeftOrRight() ? 0.5f : 1); + touchOffsetY *= (isOutOfBoundaryTopOrBottom() ? 0.5f : 1); + } + + float realOffsetX = touchOffsetX; + float realOffsetY = touchOffsetY; + + bool scrollEnabledUpDown = true; + if (touchOffsetY > 0.0f) // up + { + float icBottomPos = _innerContainer->getBottomBoundary(); + if (icBottomPos + touchOffsetY >= _bottomBoundary) + { + if(!_bounceEnabled) + { + realOffsetY = _bottomBoundary - icBottomPos; + } + processScrollEvent(MoveDirection::BOTTOM, false); + scrollEnabledUpDown = false; + } + } + else if (touchOffsetY < 0.0f) // down + { + float icTopPos = _innerContainer->getTopBoundary(); + if (icTopPos + touchOffsetY <= _topBoundary) + { + if(!_bounceEnabled) + { + realOffsetY = _topBoundary - icTopPos; + } + processScrollEvent(MoveDirection::TOP, false); + scrollEnabledUpDown = false; + } + } + + bool scrollEnabledLeftRight = true; + if (touchOffsetX < 0.0f) // left + { + float icRightPos = _innerContainer->getRightBoundary(); + if (icRightPos + touchOffsetX <= _rightBoundary) + { + if(!_bounceEnabled) + { + realOffsetX = _rightBoundary - icRightPos; + } + processScrollEvent(MoveDirection::RIGHT, false); + scrollEnabledLeftRight = false; + } + } + else if (touchOffsetX > 0.0f) // right + { + float icLeftPos = _innerContainer->getLeftBoundary(); + if (icLeftPos + touchOffsetX >= _leftBoundary) + { + if(!_bounceEnabled) + { + realOffsetX = _leftBoundary - icLeftPos; + } + processScrollEvent(MoveDirection::LEFT, false); + scrollEnabledLeftRight = false; + } + } + moveChildren(realOffsetX, realOffsetY); + return scrollEnabledUpDown || scrollEnabledLeftRight; } void ScrollView::scrollToBottom(float second, bool attenuated) @@ -596,7 +599,7 @@ void ScrollView::scrollToTopLeft(float second, bool attenuated) { if (_direction != Direction::BOTH) { - CCLOG("Scroll diretion is not both!"); + CCLOG("Scroll direction is not both!"); return; } startAutoScrollChildrenWithDestination(Vec2(0.0f, _contentSize.height - _innerContainer->getContentSize().height), second, attenuated); @@ -606,7 +609,7 @@ void ScrollView::scrollToTopRight(float second, bool attenuated) { if (_direction != Direction::BOTH) { - CCLOG("Scroll diretion is not both!"); + CCLOG("Scroll direction is not both!"); return; } startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, @@ -617,7 +620,7 @@ void ScrollView::scrollToBottomLeft(float second, bool attenuated) { if (_direction != Direction::BOTH) { - CCLOG("Scroll diretion is not both!"); + CCLOG("Scroll direction is not both!"); return; } startAutoScrollChildrenWithDestination(Vec2::ZERO, second, attenuated); @@ -627,7 +630,7 @@ void ScrollView::scrollToBottomRight(float second, bool attenuated) { if (_direction != Direction::BOTH) { - CCLOG("Scroll diretion is not both!"); + CCLOG("Scroll direction is not both!"); return; } startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, 0.0f), second, attenuated); @@ -683,7 +686,7 @@ void ScrollView::jumpToTopLeft() { if (_direction != Direction::BOTH) { - CCLOG("Scroll diretion is not both!"); + CCLOG("Scroll direction is not both!"); return; } jumpToDestination(Vec2(0.0f, _contentSize.height - _innerContainer->getContentSize().height)); @@ -693,7 +696,7 @@ void ScrollView::jumpToTopRight() { if (_direction != Direction::BOTH) { - CCLOG("Scroll diretion is not both!"); + CCLOG("Scroll direction is not both!"); return; } jumpToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, @@ -704,7 +707,7 @@ void ScrollView::jumpToBottomLeft() { if (_direction != Direction::BOTH) { - CCLOG("Scroll diretion is not both!"); + CCLOG("Scroll direction is not both!"); return; } jumpToDestination(Vec2::ZERO); @@ -714,7 +717,7 @@ void ScrollView::jumpToBottomRight() { if (_direction != Direction::BOTH) { - CCLOG("Scroll diretion is not both!"); + CCLOG("Scroll direction is not both!"); return; } jumpToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, 0.0f)); @@ -776,6 +779,15 @@ void ScrollView::handlePressLogic(Touch *touch) _inertiaPrevTouchTimestamp = utils::getTimeInMilliseconds(); _inertiaTouchDisplacements.clear(); _inertiaTouchTimeDeltas.clear(); + + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->onTouchBegan(); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->onTouchBegan(); + } } void ScrollView::handleMoveLogic(Touch *touch) @@ -807,6 +819,15 @@ void ScrollView::handleReleaseLogic(Touch *touch) { endRecordSlidAction(); _bePressed = false; + + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->onTouchEnded(); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->onTouchEnded(); + } } bool ScrollView::onTouchBegan(Touch *touch, Event *unusedEvent) @@ -986,6 +1007,7 @@ void ScrollView::addEventListener(const ccScrollViewCallback& callback) void ScrollView::setDirection(Direction dir) { _direction = dir; + initScrollBar(); } ScrollView::Direction ScrollView::getDirection()const @@ -1013,6 +1035,17 @@ bool ScrollView::isInertiaScrollEnabled() const return _inertiaScrollEnabled; } +void ScrollView::setScrollBarEnabled(bool enabled) +{ + _scrollBarEnabled = enabled; + initScrollBar(); +} + +bool ScrollView::isScrollBarEnabled() const +{ + return _scrollBarEnabled; +} + Layout* ScrollView::getInnerContainer()const { return _innerContainer; @@ -1090,6 +1123,40 @@ void ScrollView::copySpecialProperties(Widget *widget) } } +void ScrollView::initScrollBar() +{ + removeScrollBar(); + if(!_scrollBarEnabled) + { + return; + } + + if(_direction != Direction::HORIZONTAL && _verticalScrollBar == nullptr) + { + _verticalScrollBar = ScrollViewBar::create(this, Direction::VERTICAL); + addProtectedChild(_verticalScrollBar, 2); + } + if(_direction != Direction::VERTICAL && _horizontalScrollBar == nullptr) + { + _horizontalScrollBar = ScrollViewBar::create(this, Direction::HORIZONTAL); + addProtectedChild(_horizontalScrollBar, 2); + } +} + +void ScrollView::removeScrollBar() +{ + if(_verticalScrollBar != nullptr) + { + removeProtectedChild(_verticalScrollBar); + _verticalScrollBar = nullptr; + } + if(_horizontalScrollBar != nullptr) + { + removeProtectedChild(_horizontalScrollBar); + _horizontalScrollBar = nullptr; + } +} + Widget* ScrollView::findNextFocusedWidget(cocos2d::ui::Widget::FocusDirection direction, cocos2d::ui::Widget *current) { if (this->getLayoutType() == Layout::Type::VERTICAL diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h index 6e075fd9f8..eb301977b3 100644 --- a/cocos/ui/UIScrollView.h +++ b/cocos/ui/UIScrollView.h @@ -39,6 +39,8 @@ class EventFocusListener; namespace ui { +class ScrollViewBar; + /** *Scrollview scroll event type. *@deprecated use @see `ScrollView::EventType` instead. @@ -369,7 +371,21 @@ public: * @return True if inertia is enabled, false otherwise. */ bool isInertiaScrollEnabled() const; - + + /** + * @brief Toggle scroll bar enabled. + * + * @param enabled True if enable scroll bar, false otherwise. + */ + void setScrollBarEnabled(bool enabled); + + /** + * @brief Query scroll bar state. + * + * @return True if scroll bar is enabled, false otherwise. + */ + bool isScrollBarEnabled() const; + /** * Set layout type for scrollview. * @@ -426,11 +442,15 @@ protected: virtual void copySpecialProperties(Widget* model) override; virtual void copyClonedWidgetChildren(Widget* model) override; - bool isOutOfBoundary(MoveDirection dir) const; - bool isOutOfBoundaryTopOrBottom() const; - bool isOutOfBoundaryLeftOrRight() const; + virtual void initScrollBar(); + virtual void removeScrollBar(); - void moveChildren(float offsetX, float offsetY); + bool isOutOfBoundary(MoveDirection dir) const; + bool isOutOfBoundaryTopOrBottom() const; + bool isOutOfBoundaryLeftOrRight() const; + + void moveChildren(float offsetX, float offsetY); + void moveChildrenToPosition(const Vec2& position); void startInertiaScroll(); void processInertiaScrolling(float dt); @@ -443,30 +463,25 @@ protected: void jumpToDestination(const Vec2& des); - virtual bool scrollChildren(float touchOffsetX, float touchOffsetY); - // Without bounce - bool processScrollUp(float* offsetYResult, float touchOffsetY); - bool processScrollDown(float* offsetYResult, float touchOffsetY); - bool processScrollLeft(float* offsetXResult, float touchOffsetX); - bool processScrollRight(float* offsetXResult, float touchOffsetX); - void startRecordSlidAction(); virtual void endRecordSlidAction(); //ScrollViewProtocol - virtual void handlePressLogic(Touch *touch) ; - virtual void handleMoveLogic(Touch *touch) ; - virtual void handleReleaseLogic(Touch *touch) ; + virtual void handlePressLogic(Touch *touch); + virtual void handleMoveLogic(Touch *touch); + virtual void handleReleaseLogic(Touch *touch); virtual void interceptTouchEvent(Widget::TouchEventType event,Widget* sender,Touch *touch) override; - - void processScrollEvent(MoveDirection dir, bool bounce); + + void processScrollEvent(MoveDirection dir, bool bounce); void processScrollingEvent(); - void dispatchEvent(ScrollviewEventType scrollEventType, EventType eventType); - - Vec2 getHowMuchOutOfBoundary(const Vec2& addition) const; + void dispatchEvent(ScrollviewEventType scrollEventType, EventType eventType); + + Vec2 getHowMuchOutOfBoundary(const Vec2& addition) const; + + void updateScrollBar(const Vec2& outOfBoundary); protected: Layout* _innerContainer; @@ -501,6 +516,10 @@ protected: bool _bounceEnabled; bool _bouncingBack; + bool _scrollBarEnabled; + ScrollViewBar* _verticalScrollBar; + ScrollViewBar* _horizontalScrollBar; + Ref* _scrollViewEventListener; #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) #pragma GCC diagnostic ignored "-Wdeprecated-declarations" diff --git a/cocos/ui/UIScrollViewBar.cpp b/cocos/ui/UIScrollViewBar.cpp new file mode 100644 index 0000000000..6664aec1c3 --- /dev/null +++ b/cocos/ui/UIScrollViewBar.cpp @@ -0,0 +1,262 @@ +/**************************************************************************** +Copyright (c) 2015 Neo Kim (neo.kim@neofect.com) + +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. +****************************************************************************/ + +#include "UIScrollViewBar.h" +#include "CCDirector.h" +#include "CCImage.h" +#include "2d/CCSprite.h" +#include "base64.h" + +NS_CC_BEGIN + +namespace ui { + + static const char* HALF_CIRCLE_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAGCAMAAADAMI+zAAAAIVBMVEVGVWtGVWtGVWtGVWtGVWtGVWtGVWtGVWtGVWtGVWtGVWt3DPc3AAAAC3RSTlMAAgMLLFBTYWNkZuZhN4QAAAAvSURBVAjXRchBDgAgCAPBIi0q/3+wxBiZU7cAjJpTNBSPvMLrf7tqgPkR6hB2xzpFkgIfM9q/8QAAAABJRU5ErkJggg=="; + static const char* BODY_IMAGE_1_PIXEL_HEIGHT = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAABCAMAAADdNb8LAAAAA1BMVEVGVWvOwd1pAAAAAXRSTlNm5DccCwAAAApJREFUeAFjQAYAAA0AAWHNnKQAAAAASUVORK5CYII="; + static const float DEFAULT_MARGIN = 30; + static const float AUTO_HIDE_TIME = 0.3f; + + static Sprite* createSpriteFromBase64(const char* base64String) + { + unsigned char* decoded; + int length = base64Decode((const unsigned char*) base64String, (unsigned int) strlen(base64String), &decoded); + + Image *image = new Image(); + bool imageResult = image->initWithImageData(decoded, length); + CCASSERT(imageResult, "Failed to create image from base64!"); + free(decoded); + + Texture2D *pTexture = new Texture2D(); + pTexture->initWithImage(image); + pTexture->setAliasTexParameters(); + image->release(); + + return Sprite::createWithTexture(pTexture); + } + + ScrollViewBar::ScrollViewBar(ScrollView* parent, ScrollView::Direction direction): + _parent(parent), + _direction(direction), + _upperHalfCircle(nullptr), + _lowerHalfCircle(nullptr), + _body(nullptr), + _touching(false), + _autoHideEnabled(true), + _autoHideRemainingTime(0) + { + CCASSERT(direction != ScrollView::Direction::BOTH, "Illegal scroll direction for scroll bar!"); + setCascadeColorEnabled(true); + setCascadeOpacityEnabled(true); + setMargin(DEFAULT_MARGIN); + } + + ScrollViewBar::~ScrollViewBar() + { + } + + ScrollViewBar* ScrollViewBar::create(ScrollView* parent, ScrollView::Direction direction) + { + ScrollViewBar* node = new (std::nothrow) ScrollViewBar(parent, direction); + if (node && node->init()) + { + node->autorelease(); + return node; + } + CC_SAFE_DELETE(node); + return nullptr; + } + + bool ScrollViewBar::init() + { + if (!ProtectedNode::init()) + { + return false; + } + + _upperHalfCircle = createSpriteFromBase64(HALF_CIRCLE_IMAGE); + _upperHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); + addChild(_upperHalfCircle); + + _lowerHalfCircle = Sprite::createWithTexture(_upperHalfCircle->getTexture(), _upperHalfCircle->getTextureRect(), _upperHalfCircle->isTextureRectRotated()); + _lowerHalfCircle->setScaleY(-1); + _lowerHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); + addChild(_lowerHalfCircle); + + _body = createSpriteFromBase64(BODY_IMAGE_1_PIXEL_HEIGHT); + _body->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); + addChild(_body); + + if(_direction == ScrollView::Direction::HORIZONTAL) + { + setRotation(90); + } + + if(_autoHideEnabled) + { + setOpacity(0); + } + return true; + } + + void ScrollViewBar::setMargin(float margin) + { + _margin = margin / Director::getInstance()->getContentScaleFactor(); + } + + float ScrollViewBar::getMargin() const + { + return _margin * Director::getInstance()->getContentScaleFactor(); + } + + void ScrollViewBar::setAutoHideEnabled(bool autoHideEnabled) + { + _autoHideEnabled = autoHideEnabled; + } + + bool ScrollViewBar::isAutoHideEnabled() const + { + return _autoHideEnabled; + } + + void ScrollViewBar::setLength(float length) + { + float ratio = length / _body->getTextureRect().size.height; + _body->setScaleY(ratio); + _upperHalfCircle->setPositionY(_body->getPositionY() + length); + } + + void ScrollViewBar::onEnter() + { + ProtectedNode::onEnter(); + scheduleUpdate(); + } + + void ScrollViewBar::update(float deltaTime) + { + if(!_autoHideEnabled || _touching || _autoHideRemainingTime <= 0) + { + return; + } + + _autoHideRemainingTime -= deltaTime; + if(_autoHideRemainingTime <= AUTO_HIDE_TIME) + { + _autoHideRemainingTime = MAX(0, _autoHideRemainingTime); + this->setOpacity(255 * (_autoHideRemainingTime / AUTO_HIDE_TIME)); + } + } + + void ScrollViewBar::onTouchBegan() + { + _touching = true; + } + + void ScrollViewBar::onTouchEnded() + { + _touching = false; + + if(_autoHideEnabled) + { + _autoHideRemainingTime = AUTO_HIDE_TIME; + } + } + + void ScrollViewBar::onScrolled(const Vec2& outOfBoundary) + { + if(_autoHideEnabled) + { + _autoHideRemainingTime = AUTO_HIDE_TIME; + setOpacity(255); + } + + Layout* innerContainer = _parent->getInnerContainer(); + + float innerContainerMeasure = 0; + float scrollViewMeasure = 0; + float outOfBoundaryValue = 0; + float innerContainerPosition = 0; + if(_direction == ScrollView::Direction::VERTICAL) + { + innerContainerMeasure = innerContainer->getContentSize().height; + scrollViewMeasure = _parent->getContentSize().height; + outOfBoundaryValue = outOfBoundary.y; + innerContainerPosition = -innerContainer->getPositionY(); + } + else if(_direction == ScrollView::Direction::HORIZONTAL) + { + innerContainerMeasure = innerContainer->getContentSize().width; + scrollViewMeasure = _parent->getContentSize().width; + outOfBoundaryValue = outOfBoundary.x; + innerContainerPosition = -innerContainer->getPositionX(); + } + + float length = updateLength(innerContainerMeasure, scrollViewMeasure, outOfBoundaryValue); + updatePosition(innerContainerMeasure, scrollViewMeasure, innerContainerPosition, outOfBoundaryValue, length); + } + + float ScrollViewBar::updateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue) + { + float denominatorValue = innerContainerMeasure; + if(outOfBoundaryValue != 0) + { + // If it is out of boundary, the length of scroll bar gets shorter quickly. + static const float GETTING_SHORTER_FACTOR = 20; + denominatorValue += (outOfBoundaryValue > 0 ? outOfBoundaryValue : -outOfBoundaryValue) * GETTING_SHORTER_FACTOR; + } + + float lengthRatio = scrollViewMeasure / denominatorValue; + float length = (scrollViewMeasure - 2 * _margin) * lengthRatio; + setLength(length); + return length; + } + + void ScrollViewBar::updatePosition(float innerContainerMeasure, float scrollViewMeasure, float innerContainerPosition, float outOfBoundaryValue, float length) + { + float denominatorValue = innerContainerMeasure - scrollViewMeasure; + if(outOfBoundaryValue != 0) + { + denominatorValue += outOfBoundaryValue * (outOfBoundaryValue < 0 ? -1 : 1); + } + + float positionRatio = 0; + if(denominatorValue != 0) + { + positionRatio = innerContainerPosition / denominatorValue; + positionRatio = MAX(positionRatio, 0); + positionRatio = MIN(positionRatio, 1); + } + float position = (scrollViewMeasure - length - 2 * _margin) * positionRatio + _margin; + + if(_direction == ScrollView::Direction::VERTICAL) + { + setPosition(_parent->getContentSize().width - _margin, position); + } + else if(_direction == ScrollView::Direction::HORIZONTAL) + { + setPosition(position, _margin); + } + } +} + +NS_CC_END diff --git a/cocos/ui/UIScrollViewBar.h b/cocos/ui/UIScrollViewBar.h new file mode 100644 index 0000000000..3fecf57370 --- /dev/null +++ b/cocos/ui/UIScrollViewBar.h @@ -0,0 +1,92 @@ +/**************************************************************************** +Copyright (c) 2015 Neo Kim (neo.kim@neofect.com) + +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. +****************************************************************************/ + +#ifndef __UISCROLLVIEWBAR_H__ +#define __UISCROLLVIEWBAR_H__ + +#include "ui/UIScrollView.h" + +NS_CC_BEGIN +/** + * @addtogroup ui + * @{ + */ + +class Sprite; + +namespace ui { + +class CC_GUI_DLL ScrollViewBar : public ProtectedNode +{ + +public: + ScrollViewBar(ScrollView* parent, ScrollView::Direction direction); + + virtual ~ScrollViewBar(); + + static ScrollViewBar* create(ScrollView* parent, ScrollView::Direction direction); + + void setMargin(float margin); + float getMargin() const; + + void setAutoHideEnabled(bool autoHideEnabled); + bool isAutoHideEnabled() const; + + virtual void onScrolled(const Vec2& outOfBoundary); + + virtual void onEnter() override; + virtual void update(float deltaTime) override; + + void onTouchBegan(); + void onTouchEnded(); + +CC_CONSTRUCTOR_ACCESS: + virtual bool init() override; + +private: + float updateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue); + void updatePosition(float innerContainerMeasure, float scrollViewMeasure, float innerContainerPosition, float outOfBoundaryValue, float actualLength); + + void setLength(float length); + + ScrollView* _parent; + ScrollView::Direction _direction; + Sprite* _upperHalfCircle; + Sprite* _lowerHalfCircle; + Sprite* _body; + float _margin; + + bool _touching; + + bool _autoHideEnabled; + float _autoHideRemainingTime; + +}; + +} +// end of ui group +/// @} +NS_CC_END + +#endif /* defined(__UISCROLLVIEWBAR_H__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 78146c3747..0bb7119a5e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -254,7 +254,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection::init() _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create("ScrollView scroll to percent both directrion","fonts/Marker Felt.ttf",20); + Text* alert = Text::create("ScrollView scroll to percent both direction without scroll bar","fonts/Marker Felt.ttf",20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5)); _uiLayer->addChild(alert); @@ -278,6 +278,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection::init() ImageView* iv = ImageView::create("cocosui/Hello.png"); iv->setPosition(Vec2(240, 160)); sc->addChild(iv); + sc->setScrollBarEnabled(false); _uiLayer->addChild(sc); return true; @@ -309,7 +310,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init() _uiLayer->addChild(_displayValueLabel); // Add the alert - Text* alert = Text::create("ScrollView scroll to percent both directrion bounce","fonts/Marker Felt.ttf",20); + Text* alert = Text::create("ScrollView scroll to percent both direction bounce","fonts/Marker Felt.ttf",20); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5)); _uiLayer->addChild(alert); @@ -378,7 +379,7 @@ bool UIScrollViewNestTest::init() // Create the scrollview by vertical ui::ScrollView* scrollView = ui::ScrollView::create(); scrollView->setContentSize(Size(280.0f, 150.0f)); - scrollView->setDirection(ui::ScrollView::Direction::BOTH); + scrollView->setDirection(ui::ScrollView::Direction::VERTICAL); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - scrollView->getContentSize().width) / 2.0f, @@ -413,7 +414,7 @@ bool UIScrollViewNestTest::init() - // Create the scrollview by horizontal + // Create the scrollview by vertical ui::ScrollView* sc = ui::ScrollView::create(); sc->setBackGroundColor(Color3B::GREEN); sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID); @@ -473,7 +474,7 @@ bool UIScrollViewRotated::init() // Create the scrollview by vertical ui::ScrollView* scrollView = ui::ScrollView::create(); scrollView->setContentSize(Size(280.0f, 150.0f)); - scrollView->setDirection(ui::ScrollView::Direction::BOTH); + scrollView->setDirection(ui::ScrollView::Direction::VERTICAL); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - scrollView->getContentSize().width) / 2.0f, From 9a11cfd496f99b0d2e09078cd9e42107510e35b2 Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Fri, 3 Jul 2015 18:26:20 +0900 Subject: [PATCH 08/43] Add a way of changing scroll bar width --- cocos/ui/UIScrollViewBar.cpp | 24 +++++++++++++++++++----- cocos/ui/UIScrollViewBar.h | 9 ++++++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/cocos/ui/UIScrollViewBar.cpp b/cocos/ui/UIScrollViewBar.cpp index 6664aec1c3..ce2d89d0a5 100644 --- a/cocos/ui/UIScrollViewBar.cpp +++ b/cocos/ui/UIScrollViewBar.cpp @@ -23,7 +23,6 @@ THE SOFTWARE. ****************************************************************************/ #include "UIScrollViewBar.h" -#include "CCDirector.h" #include "CCImage.h" #include "2d/CCSprite.h" #include "base64.h" @@ -61,6 +60,7 @@ namespace ui { _upperHalfCircle(nullptr), _lowerHalfCircle(nullptr), _body(nullptr), + _margin(DEFAULT_MARGIN), _touching(false), _autoHideEnabled(true), _autoHideRemainingTime(0) @@ -68,7 +68,6 @@ namespace ui { CCASSERT(direction != ScrollView::Direction::BOTH, "Illegal scroll direction for scroll bar!"); setCascadeColorEnabled(true); setCascadeOpacityEnabled(true); - setMargin(DEFAULT_MARGIN); } ScrollViewBar::~ScrollViewBar() @@ -121,14 +120,29 @@ namespace ui { void ScrollViewBar::setMargin(float margin) { - _margin = margin / Director::getInstance()->getContentScaleFactor(); + _margin = margin; } float ScrollViewBar::getMargin() const { - return _margin * Director::getInstance()->getContentScaleFactor(); + return _margin; } + void ScrollViewBar::setWidth(float width) + { + CCASSERT(_body != nullptr && _upperHalfCircle != nullptr && _lowerHalfCircle != nullptr, "Internal sprites are not set!"); + float scale = width / _body->getContentSize().width; + _body->setScaleX(scale); + _upperHalfCircle->setScale(scale); + _lowerHalfCircle->setScale(-scale); + } + + float ScrollViewBar::getWidth() const + { + CCASSERT(_body != nullptr, "The body sprite is null!"); + return _body->getBoundingBox().size.width; + } + void ScrollViewBar::setAutoHideEnabled(bool autoHideEnabled) { _autoHideEnabled = autoHideEnabled; @@ -181,7 +195,7 @@ namespace ui { _autoHideRemainingTime = AUTO_HIDE_TIME; } } - + void ScrollViewBar::onScrolled(const Vec2& outOfBoundary) { if(_autoHideEnabled) diff --git a/cocos/ui/UIScrollViewBar.h b/cocos/ui/UIScrollViewBar.h index 3fecf57370..d8458c97b4 100644 --- a/cocos/ui/UIScrollViewBar.h +++ b/cocos/ui/UIScrollViewBar.h @@ -47,12 +47,15 @@ public: static ScrollViewBar* create(ScrollView* parent, ScrollView::Direction direction); - void setMargin(float margin); - float getMargin() const; + virtual void setMargin(float margin); + virtual float getMargin() const; + virtual void setWidth(float width); + virtual float getWidth() const; + void setAutoHideEnabled(bool autoHideEnabled); bool isAutoHideEnabled() const; - + virtual void onScrolled(const Vec2& outOfBoundary); virtual void onEnter() override; From c093bb18e28793d468cb7ebb107a599290cce61d Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Fri, 3 Jul 2015 21:32:29 +0900 Subject: [PATCH 09/43] Add scroll bar manipulation methods into ScrollView --- cocos/ui/UIScrollView.cpp | 135 ++++++++++++++++++ cocos/ui/UIScrollView.h | 134 ++++++++++++----- cocos/ui/UIScrollViewBar.cpp | 53 ++++--- cocos/ui/UIScrollViewBar.h | 21 ++- .../UIScrollViewTest/UIScrollViewTest.cpp | 14 +- 5 files changed, 290 insertions(+), 67 deletions(-) diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index de8a1a8c76..9c6afb9a7a 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -1046,6 +1046,141 @@ bool ScrollView::isScrollBarEnabled() const return _scrollBarEnabled; } +void ScrollView::setScrollBarMargin(float margin) +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->setMargin(margin); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->setMargin(margin); + } +} + +float ScrollView::getScrollBarMargin() const +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + return _verticalScrollBar->getMargin(); + } + else if(_horizontalScrollBar != nullptr) + { + return _horizontalScrollBar->getMargin(); + } + return 0; +} + +void ScrollView::setScrollBarWidth(float width) +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->setWidth(width); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->setWidth(width); + } +} + +float ScrollView::getScrollBarWidth() const +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + return _verticalScrollBar->getWidth(); + } + else if(_horizontalScrollBar != nullptr) + { + return _horizontalScrollBar->getWidth(); + } + return 0; +} + +void ScrollView::setScrollBarColor(const Color3B& color) +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->setColor(color); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->setColor(color); + } +} + +const Color3B& ScrollView::getScrollBarColor() const +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + return _verticalScrollBar->getColor(); + } + else if(_horizontalScrollBar != nullptr) + { + return _horizontalScrollBar->getColor(); + } + return Color3B::WHITE; +} + +void ScrollView::setScrollBarAutoHideEnabled(bool autoHideEnabled) +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->setAutoHideEnabled(autoHideEnabled); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->setAutoHideEnabled(autoHideEnabled); + } +} + +bool ScrollView::isScrollBarAutoHideEnabled() const +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + return _verticalScrollBar->isAutoHideEnabled(); + } + else if(_horizontalScrollBar != nullptr) + { + return _horizontalScrollBar->isAutoHideEnabled(); + } + return false; +} + +void ScrollView::setScrollBarAutoHideTime(float autoHideTime) +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->setAutoHideTime(autoHideTime); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->setAutoHideTime(autoHideTime); + } +} + +float ScrollView::getScrollBarAutoHideTime() const +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + return _verticalScrollBar->getAutoHideTime(); + } + else if(_horizontalScrollBar != nullptr) + { + return _horizontalScrollBar->getAutoHideTime(); + } + return 0; +} + Layout* ScrollView::getInnerContainer()const { return _innerContainer; diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h index eb301977b3..2846c9389c 100644 --- a/cocos/ui/UIScrollView.h +++ b/cocos/ui/UIScrollView.h @@ -371,20 +371,90 @@ public: * @return True if inertia is enabled, false otherwise. */ bool isInertiaScrollEnabled() const; + + /** + * @brief Toggle scroll bar enabled. + * + * @param enabled True if enable scroll bar, false otherwise. + */ + void setScrollBarEnabled(bool enabled); + + /** + * @brief Query scroll bar state. + * + * @return True if scroll bar is enabled, false otherwise. + */ + bool isScrollBarEnabled() const; /** - * @brief Toggle scroll bar enabled. + * @brief Set the margin between scroll bar and the container's border * - * @param enabled True if enable scroll bar, false otherwise. + * @param margin The margin between scroll bar and the container's border */ - void setScrollBarEnabled(bool enabled); + void setScrollBarMargin(float margin); /** - * @brief Query scroll bar state. + * @brief Get the margin between scroll bar and the container's border * - * @return True if scroll bar is enabled, false otherwise. + * @return margin */ - bool isScrollBarEnabled() const; + float getScrollBarMargin() const; + + /** + * @brief Set the scroll bar's width + * + * @param width The scroll bar's width + */ + void setScrollBarWidth(float width); + + /** + * @brief Get the scroll bar's width + * + * @return the scroll bar's width + */ + float getScrollBarWidth() const; + + /** + * @brief Set the scroll bar's color + * + * @param the scroll bar's color + */ + void setScrollBarColor(const Color3B& color); + + /** + * @brief Get the scroll bar's color + * + * @return the scroll bar's color + */ + const Color3B& getScrollBarColor() const; + + /** + * @brief Set scroll bar auto hide state + * + * @param scroll bar auto hide state + */ + void setScrollBarAutoHideEnabled(bool autoHideEnabled); + + /** + * @brief Query scroll bar auto hide state + * + * @return True if scroll bar auto hide is enabled, false otherwise. + */ + bool isScrollBarAutoHideEnabled() const; + + /** + * @brief Set scroll bar auto hide time + * + * @param scroll bar auto hide time + */ + void setScrollBarAutoHideTime(float autoHideTime); + + /** + * @brief Get the scroll bar's auto hide time + * + * @return the scroll bar's auto hide time + */ + float getScrollBarAutoHideTime() const; /** * Set layout type for scrollview. @@ -432,7 +502,7 @@ protected: LEFT, RIGHT, }; - + virtual void initRenderer() override; virtual void onSizeChanged() override; @@ -441,20 +511,20 @@ protected: virtual Widget* createCloneInstance() override; virtual void copySpecialProperties(Widget* model) override; virtual void copyClonedWidgetChildren(Widget* model) override; - - virtual void initScrollBar(); - virtual void removeScrollBar(); - - bool isOutOfBoundary(MoveDirection dir) const; - bool isOutOfBoundaryTopOrBottom() const; - bool isOutOfBoundaryLeftOrRight() const; - - void moveChildren(float offsetX, float offsetY); - void moveChildrenToPosition(const Vec2& position); - + + virtual void initScrollBar(); + virtual void removeScrollBar(); + + bool isOutOfBoundary(MoveDirection dir) const; + bool isOutOfBoundaryTopOrBottom() const; + bool isOutOfBoundaryLeftOrRight() const; + + void moveChildren(float offsetX, float offsetY); + void moveChildrenToPosition(const Vec2& position); + void startInertiaScroll(); void processInertiaScrolling(float dt); - + void startAutoScroll(const Vec2& deltaMove, float duration, bool attenuated); void startAutoScrollChildrenWithDestination(const Vec2& des, float second, bool attenuated); void processAutoScrolling(float deltaTime); @@ -474,14 +544,14 @@ protected: virtual void handleReleaseLogic(Touch *touch); virtual void interceptTouchEvent(Widget::TouchEventType event,Widget* sender,Touch *touch) override; - - void processScrollEvent(MoveDirection dir, bool bounce); + + void processScrollEvent(MoveDirection dir, bool bounce); void processScrollingEvent(); - void dispatchEvent(ScrollviewEventType scrollEventType, EventType eventType); - - Vec2 getHowMuchOutOfBoundary(const Vec2& addition) const; - - void updateScrollBar(const Vec2& outOfBoundary); + void dispatchEvent(ScrollviewEventType scrollEventType, EventType eventType); + + Vec2 getHowMuchOutOfBoundary(const Vec2& addition) const; + + void updateScrollBar(const Vec2& outOfBoundary); protected: Layout* _innerContainer; @@ -512,14 +582,14 @@ protected: Vec2 _autoScrollTargetDelta; float _autoScrollDuration; float _autoScrollAccumulatedTime; - + bool _bounceEnabled; bool _bouncingBack; - - bool _scrollBarEnabled; - ScrollViewBar* _verticalScrollBar; - ScrollViewBar* _horizontalScrollBar; - + + bool _scrollBarEnabled; + ScrollViewBar* _verticalScrollBar; + ScrollViewBar* _horizontalScrollBar; + Ref* _scrollViewEventListener; #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) #pragma GCC diagnostic ignored "-Wdeprecated-declarations" diff --git a/cocos/ui/UIScrollViewBar.cpp b/cocos/ui/UIScrollViewBar.cpp index ce2d89d0a5..fc2bc08018 100644 --- a/cocos/ui/UIScrollViewBar.cpp +++ b/cocos/ui/UIScrollViewBar.cpp @@ -31,10 +31,12 @@ NS_CC_BEGIN namespace ui { - static const char* HALF_CIRCLE_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAGCAMAAADAMI+zAAAAIVBMVEVGVWtGVWtGVWtGVWtGVWtGVWtGVWtGVWtGVWtGVWtGVWt3DPc3AAAAC3RSTlMAAgMLLFBTYWNkZuZhN4QAAAAvSURBVAjXRchBDgAgCAPBIi0q/3+wxBiZU7cAjJpTNBSPvMLrf7tqgPkR6hB2xzpFkgIfM9q/8QAAAABJRU5ErkJggg=="; - static const char* BODY_IMAGE_1_PIXEL_HEIGHT = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAABCAMAAADdNb8LAAAAA1BMVEVGVWvOwd1pAAAAAXRSTlNm5DccCwAAAApJREFUeAFjQAYAAA0AAWHNnKQAAAAASUVORK5CYII="; + static const char* HALF_CIRCLE_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAGCAMAAADAMI+zAAAAIVBMVEX///////////////////////////////////////////9/gMdvAAAAC3RSTlMAAgMLLFBTYWNkZuZhN4QAAAAvSURBVAjXRchBDgAgCAPBIi0q/3+wxBiZU7cAjJpTNBSPvMLrf7tqgPkR6hB2xzpFkgIfM9q/8QAAAABJRU5ErkJggg=="; + static const char* BODY_IMAGE_1_PIXEL_HEIGHT = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAABCAMAAADdNb8LAAAAA1BMVEX///+nxBvIAAAAAXRSTlNm5DccCwAAAApJREFUeAFjQAYAAA0AAWHNnKQAAAAASUVORK5CYII="; + + static const Color3B DEFAULT_COLOR(52, 65, 87); static const float DEFAULT_MARGIN = 30; - static const float AUTO_HIDE_TIME = 0.3f; + static const float DEFAULT_AUTO_HIDE_TIME = 0.2f; static Sprite* createSpriteFromBase64(const char* base64String) { @@ -63,6 +65,7 @@ namespace ui { _margin(DEFAULT_MARGIN), _touching(false), _autoHideEnabled(true), + _autoHideTime(DEFAULT_AUTO_HIDE_TIME), _autoHideRemainingTime(0) { CCASSERT(direction != ScrollView::Direction::BOTH, "Illegal scroll direction for scroll bar!"); @@ -106,6 +109,8 @@ namespace ui { _body->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); addChild(_body); + setColor(DEFAULT_COLOR); + if(_direction == ScrollView::Direction::HORIZONTAL) { setRotation(90); @@ -118,16 +123,6 @@ namespace ui { return true; } - void ScrollViewBar::setMargin(float margin) - { - _margin = margin; - } - - float ScrollViewBar::getMargin() const - { - return _margin; - } - void ScrollViewBar::setWidth(float width) { CCASSERT(_body != nullptr && _upperHalfCircle != nullptr && _lowerHalfCircle != nullptr, "Internal sprites are not set!"); @@ -143,16 +138,20 @@ namespace ui { return _body->getBoundingBox().size.width; } - void ScrollViewBar::setAutoHideEnabled(bool autoHideEnabled) - { - _autoHideEnabled = autoHideEnabled; - } - - bool ScrollViewBar::isAutoHideEnabled() const - { - return _autoHideEnabled; - } - + void ScrollViewBar::setColor(const Color3B& color) + { + CCASSERT(_body != nullptr && _upperHalfCircle != nullptr && _lowerHalfCircle != nullptr, "Internal sprites are not set!"); + _body->setColor(color); + _upperHalfCircle->setColor(color); + _lowerHalfCircle->setColor(color); + } + + const Color3B& ScrollViewBar::getColor() const + { + CCASSERT(_body != nullptr, "The body sprite is null!"); + return _body->getColor(); + } + void ScrollViewBar::setLength(float length) { float ratio = length / _body->getTextureRect().size.height; @@ -174,10 +173,10 @@ namespace ui { } _autoHideRemainingTime -= deltaTime; - if(_autoHideRemainingTime <= AUTO_HIDE_TIME) + if(_autoHideRemainingTime <= _autoHideTime) { _autoHideRemainingTime = MAX(0, _autoHideRemainingTime); - this->setOpacity(255 * (_autoHideRemainingTime / AUTO_HIDE_TIME)); + this->setOpacity(255 * (_autoHideRemainingTime / _autoHideTime)); } } @@ -192,7 +191,7 @@ namespace ui { if(_autoHideEnabled) { - _autoHideRemainingTime = AUTO_HIDE_TIME; + _autoHideRemainingTime = _autoHideTime; } } @@ -200,7 +199,7 @@ namespace ui { { if(_autoHideEnabled) { - _autoHideRemainingTime = AUTO_HIDE_TIME; + _autoHideRemainingTime = _autoHideTime; setOpacity(255); } diff --git a/cocos/ui/UIScrollViewBar.h b/cocos/ui/UIScrollViewBar.h index d8458c97b4..cd31e0a8e1 100644 --- a/cocos/ui/UIScrollViewBar.h +++ b/cocos/ui/UIScrollViewBar.h @@ -47,14 +47,20 @@ public: static ScrollViewBar* create(ScrollView* parent, ScrollView::Direction direction); - virtual void setMargin(float margin); - virtual float getMargin() const; - - virtual void setWidth(float width); - virtual float getWidth() const; + void setMargin(float margin) { _margin = margin; } + float getMargin() const { return _margin; } + + void setWidth(float width); + float getWidth() const; - void setAutoHideEnabled(bool autoHideEnabled); - bool isAutoHideEnabled() const; + void setColor(const Color3B& color) override; + const Color3B& getColor() const override; + + void setAutoHideEnabled(bool autoHideEnabled) { _autoHideEnabled = autoHideEnabled; } + bool isAutoHideEnabled() const { return _autoHideEnabled; } + + void setAutoHideTime(float autoHideTime) { _autoHideTime = autoHideTime; } + float getAutoHideTime() const { return _autoHideTime; } virtual void onScrolled(const Vec2& outOfBoundary); @@ -83,6 +89,7 @@ private: bool _touching; bool _autoHideEnabled; + float _autoHideTime; float _autoHideRemainingTime; }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 0bb7119a5e..576d20aaa9 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -55,6 +55,9 @@ bool UIScrollViewTest_Vertical::init() (backgroundSize.width - scrollView->getContentSize().width) / 2.0f, (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - scrollView->getContentSize().height) / 2.0f)); + scrollView->setScrollBarWidth(4); + scrollView->setScrollBarMargin(2); + scrollView->setScrollBarColor(Color3B::WHITE); _uiLayer->addChild(scrollView); ImageView* imageView = ImageView::create("cocosui/ccicon.png"); @@ -127,6 +130,8 @@ bool UIScrollViewTest_Horizontal::init() scrollView->setDirection(ui::ScrollView::Direction::HORIZONTAL); scrollView->setContentSize(Size(280.0f, 150.0f)); scrollView->setInnerContainerSize(scrollView->getContentSize()); + scrollView->setScrollBarMargin(4); + scrollView->setScrollBarColor(Color3B::YELLOW); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - scrollView->getContentSize().width) / 2.0f, @@ -210,6 +215,8 @@ bool UIScrollViewTest_Both::init() scrollView->setBackGroundImageScale9Enabled(true); scrollView->setBackGroundImage("cocosui/green_edit.png"); scrollView->setContentSize(Size(210, 122.5)); + scrollView->setScrollBarWidth(4); + scrollView->setScrollBarMargin(6); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - scrollView->getContentSize().width) / 2.0f, @@ -269,6 +276,7 @@ bool UIScrollViewTest_ScrollToPercentBothDirection::init() sc->setDirection(ui::ScrollView::Direction::BOTH); sc->setInnerContainerSize(Size(480, 320)); sc->setContentSize(Size(100,100)); + sc->setScrollBarEnabled(false); Size backgroundSize = background->getContentSize(); sc->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - sc->getContentSize().width) / 2.0f, @@ -278,7 +286,6 @@ bool UIScrollViewTest_ScrollToPercentBothDirection::init() ImageView* iv = ImageView::create("cocosui/Hello.png"); iv->setPosition(Vec2(240, 160)); sc->addChild(iv); - sc->setScrollBarEnabled(false); _uiLayer->addChild(sc); return true; @@ -326,6 +333,8 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init() sc->setDirection(ui::ScrollView::Direction::BOTH); sc->setInnerContainerSize(Size(480, 320)); sc->setContentSize(Size(100,100)); + sc->setScrollBarMargin(4); + sc->setScrollBarAutoHideEnabled(false); Size backgroundSize = background->getContentSize(); sc->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - sc->getContentSize().width) / 2.0f, @@ -380,6 +389,7 @@ bool UIScrollViewNestTest::init() ui::ScrollView* scrollView = ui::ScrollView::create(); scrollView->setContentSize(Size(280.0f, 150.0f)); scrollView->setDirection(ui::ScrollView::Direction::VERTICAL); + scrollView->setScrollBarMargin(4); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - scrollView->getContentSize().width) / 2.0f, @@ -425,6 +435,7 @@ bool UIScrollViewNestTest::init() sc->setPropagateTouchEvents(false); sc->setPosition(Vec2(180,100)); sc->scrollToPercentBothDirection(Vec2(50, 50), 1, true); + sc->setScrollBarMargin(4); ImageView* iv = ImageView::create("cocosui/Hello.png"); iv->setPosition(Vec2(240, 160)); sc->addChild(iv); @@ -481,6 +492,7 @@ bool UIScrollViewRotated::init() (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - scrollView->getContentSize().height) / 2.0f + 100) ); scrollView->setRotation(45); + scrollView->setScrollBarMargin(4); _uiLayer->addChild(scrollView); ImageView* imageView = ImageView::create("cocosui/ccicon.png"); From ec45be699d528d0ff9b6600107642b8cd90c886f Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Fri, 3 Jul 2015 22:17:15 +0900 Subject: [PATCH 10/43] Add UIScrollViewBar class documentation --- cocos/ui/UIScrollViewBar.h | 85 +++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/cocos/ui/UIScrollViewBar.h b/cocos/ui/UIScrollViewBar.h index cd31e0a8e1..9a0539c26b 100644 --- a/cocos/ui/UIScrollViewBar.h +++ b/cocos/ui/UIScrollViewBar.h @@ -37,37 +37,110 @@ class Sprite; namespace ui { +/** + * Scroll bar being attached to ScrollView layout container. + */ class CC_GUI_DLL ScrollViewBar : public ProtectedNode { public: + /** + * Default constructor + * @js ctor + * @lua new + */ ScrollViewBar(ScrollView* parent, ScrollView::Direction direction); + /** + * Default destructor + * @js NA + * @lua NA + */ virtual ~ScrollViewBar(); + /** + * Create a ScrollView with its parent ScrollView and direction. + * @return A ScrollViewBar instance. + */ static ScrollViewBar* create(ScrollView* parent, ScrollView::Direction direction); - + + /** + * @brief Set the margin between scroll bar and the parent ScrollView's border + * + * @param margin The margin between scroll bar and the parent ScrollView's border + */ void setMargin(float margin) { _margin = margin; } + + /** + * @brief Get the margin between scroll bar and the parent ScrollView's border + * + * @return margin + */ float getMargin() const { return _margin; } - + + /** + * @brief Set the scroll bar's width + * + * @param width The scroll bar's width + */ void setWidth(float width); + + /** + * @brief Get the scroll bar's width + * + * @return the scroll bar's width + */ float getWidth() const; - void setColor(const Color3B& color) override; - const Color3B& getColor() const override; - + /** + * @brief Set scroll bar auto hide state + * + * @param scroll bar auto hide state + */ void setAutoHideEnabled(bool autoHideEnabled) { _autoHideEnabled = autoHideEnabled; } + + /** + * @brief Query scroll bar auto hide state + * + * @return True if scroll bar auto hide is enabled, false otherwise. + */ bool isAutoHideEnabled() const { return _autoHideEnabled; } + /** + * @brief Set scroll bar auto hide time + * + * @param scroll bar auto hide time + */ void setAutoHideTime(float autoHideTime) { _autoHideTime = autoHideTime; } + + /** + * @brief Get the scroll bar's auto hide time + * + * @return the scroll bar's auto hide time + */ float getAutoHideTime() const { return _autoHideTime; } + /** + * @brief This is called by parent ScrollView when the parent is scrolled. Don't call this directly. + * + * @param amount how much the inner container of ScrollView is out of boundary + */ virtual void onScrolled(const Vec2& outOfBoundary); - + + /** + * @lua NA + */ virtual void onEnter() override; virtual void update(float deltaTime) override; + /** + * @brief This is called by parent ScrollView when a touch is began. Don't call this directly. + */ void onTouchBegan(); + + /** + * @brief This is called by parent ScrollView when a touch is ended. Don't call this directly. + */ void onTouchEnded(); CC_CONSTRUCTOR_ACCESS: From 60c32f6fb5572a2aa190aeba293ea63572d0687e Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Fri, 3 Jul 2015 22:17:54 +0900 Subject: [PATCH 11/43] Refactor some codes --- cocos/ui/UIScrollView.cpp | 543 +++++++++--------- cocos/ui/UIScrollViewBar.cpp | 44 +- .../UIScrollViewTest/UIScrollViewTest.cpp | 1 + 3 files changed, 303 insertions(+), 285 deletions(-) diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 9c6afb9a7a..3aa49e1858 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -80,8 +80,8 @@ _eventCallback(nullptr) ScrollView::~ScrollView() { - _verticalScrollBar = nullptr; - _horizontalScrollBar = nullptr; + _verticalScrollBar = nullptr; + _horizontalScrollBar = nullptr; _scrollViewEventListener = nullptr; _scrollViewEventSelector = nullptr; } @@ -118,7 +118,10 @@ bool ScrollView::init() { setClippingEnabled(true); _innerContainer->setTouchEnabled(false); - initScrollBar(); + if(_scrollBarEnabled) + { + initScrollBar(); + } return true; } return false; @@ -146,7 +149,7 @@ void ScrollView::onSizeChanged() float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width); float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height); _innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight)); - moveChildrenToPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height)); + moveChildrenToPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height)); } void ScrollView::setInnerContainerSize(const Size &size) @@ -204,7 +207,7 @@ void ScrollView::setInnerContainerSize(const Size &size) { pos.y = _contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getContentSize().height; } - moveChildrenToPosition(pos); + moveChildrenToPosition(pos); } const Size& ScrollView::getInnerContainerSize() const @@ -274,28 +277,28 @@ Node* ScrollView::getChildByName(const std::string& name)const void ScrollView::moveChildren(float offsetX, float offsetY) { - Vec2 position = _innerContainer->getPosition() + Vec2(offsetX, offsetY); - moveChildrenToPosition(position); + Vec2 position = _innerContainer->getPosition() + Vec2(offsetX, offsetY); + moveChildrenToPosition(position); } - + void ScrollView::moveChildrenToPosition(const Vec2& position) { - _innerContainer->setPosition(position); - - Vec2 outOfBoundary = getHowMuchOutOfBoundary(Vec2::ZERO); - updateScrollBar(outOfBoundary); + _innerContainer->setPosition(position); + + Vec2 outOfBoundary = getHowMuchOutOfBoundary(Vec2::ZERO); + updateScrollBar(outOfBoundary); } void ScrollView::updateScrollBar(const Vec2& outOfBoundary) { - if(_verticalScrollBar != nullptr) - { - _verticalScrollBar->onScrolled(outOfBoundary); - } - if(_horizontalScrollBar != nullptr) - { - _horizontalScrollBar->onScrolled(outOfBoundary); - } + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->onScrolled(outOfBoundary); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->onScrolled(outOfBoundary); + } } bool ScrollView::startBounceBackIfNeeded() @@ -341,54 +344,54 @@ Vec2 ScrollView::getHowMuchOutOfBoundary(const Vec2& addition) const void ScrollView::processAutoScrolling(float deltaTime) { - _autoScrollAccumulatedTime += deltaTime; - float percentage = _autoScrollAccumulatedTime / _autoScrollDuration; - if(percentage >= 1) - { - moveChildrenToPosition(_autoScrollStartPosition + _autoScrollTargetDelta); - _autoScrolling = false; - _bouncingBack = false; - } - else - { - if(_autoScrollAttenuate) - { - percentage = tweenfunc::quintEaseOut(percentage); - } - Vec2 moveDelta = _autoScrollTargetDelta * percentage; - - // Dispatch related events if bouncing - if(_bouncingBack) - { - if(moveDelta.x > 0) - { - processScrollEvent(MoveDirection::RIGHT, true); - } - else if(moveDelta.x < 0) - { - processScrollEvent(MoveDirection::LEFT, true); - } - if(moveDelta.y > 0) - { - processScrollEvent(MoveDirection::TOP, true); - } - else if(moveDelta.y < 0) - { - processScrollEvent(MoveDirection::BOTTOM, true); - } - } - moveChildrenToPosition(_autoScrollStartPosition + moveDelta); - } + _autoScrollAccumulatedTime += deltaTime; + float percentage = _autoScrollAccumulatedTime / _autoScrollDuration; + if(percentage >= 1) + { + moveChildrenToPosition(_autoScrollStartPosition + _autoScrollTargetDelta); + _autoScrolling = false; + _bouncingBack = false; + } + else + { + if(_autoScrollAttenuate) + { + percentage = tweenfunc::quintEaseOut(percentage); + } + Vec2 moveDelta = _autoScrollTargetDelta * percentage; + + // Dispatch related events if bouncing + if(_bouncingBack) + { + if(moveDelta.x > 0) + { + processScrollEvent(MoveDirection::RIGHT, true); + } + else if(moveDelta.x < 0) + { + processScrollEvent(MoveDirection::LEFT, true); + } + if(moveDelta.y > 0) + { + processScrollEvent(MoveDirection::TOP, true); + } + else if(moveDelta.y < 0) + { + processScrollEvent(MoveDirection::BOTTOM, true); + } + } + moveChildrenToPosition(_autoScrollStartPosition + moveDelta); + } } bool ScrollView::isOutOfBoundary(MoveDirection dir) const { switch(dir) { - case MoveDirection::TOP: return _innerContainer->getTopBoundary() < _topBoundary; - case MoveDirection::BOTTOM: return _innerContainer->getBottomBoundary() > _bottomBoundary; - case MoveDirection::LEFT: return _innerContainer->getLeftBoundary() > _leftBoundary; - case MoveDirection::RIGHT: return _innerContainer->getRightBoundary() < _rightBoundary; + case MoveDirection::TOP: return _innerContainer->getTopBoundary() < _topBoundary; + case MoveDirection::BOTTOM: return _innerContainer->getBottomBoundary() > _bottomBoundary; + case MoveDirection::LEFT: return _innerContainer->getLeftBoundary() > _leftBoundary; + case MoveDirection::RIGHT: return _innerContainer->getRightBoundary() < _rightBoundary; } } @@ -421,156 +424,156 @@ void ScrollView::jumpToDestination(const Vec2 &des) { float finalOffsetX = des.x; float finalOffsetY = des.y; - if (des.y <= 0 && _direction != Direction::HORIZONTAL) - { - finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getContentSize().height); - } - if (des.x <= 0 && _direction != Direction::VERTICAL) - { - finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getContentSize().width); - } - moveChildrenToPosition(Vec2(finalOffsetX, finalOffsetY)); + if (des.y <= 0 && _direction != Direction::HORIZONTAL) + { + finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getContentSize().height); + } + if (des.x <= 0 && _direction != Direction::VERTICAL) + { + finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getContentSize().width); + } + moveChildrenToPosition(Vec2(finalOffsetX, finalOffsetY)); } void ScrollView::startInertiaScroll() { - float totalDuration = 0; - for(auto i = _inertiaTouchTimeDeltas.begin(); i != _inertiaTouchTimeDeltas.end(); ++i) - { - totalDuration += (*i); - } - if(totalDuration == 0 || totalDuration >= 0.5f) - { - return; - } - - _inertiaScrolling = true; - - // Calcualte the initial velocity - Vec2 totalMovement; - for(auto i = _inertiaTouchDisplacements.begin(); i != _inertiaTouchDisplacements.end(); ++i) - { - totalMovement += (*i); - } - totalMovement.x = (_direction == Direction::VERTICAL ? 0 : totalMovement.x); - totalMovement.y = (_direction == Direction::HORIZONTAL ? 0 : totalMovement.y); - - _inertiaInitiVelocity = totalMovement / totalDuration; - _inertiaInitiVelocity.x = MIN(_inertiaInitiVelocity.x, INERTIA_VELOCITY_MAX); - _inertiaInitiVelocity.y = MIN(_inertiaInitiVelocity.y, INERTIA_VELOCITY_MAX); - _inertiaInitiVelocity.x = MAX(_inertiaInitiVelocity.x, -INERTIA_VELOCITY_MAX); - _inertiaInitiVelocity.y = MAX(_inertiaInitiVelocity.y, -INERTIA_VELOCITY_MAX); - - // Calculate values for ease out - _inertiaScrollExpectedTime = _inertiaInitiVelocity.length() / INERTIA_DEACCELERATION; - _inertiaScrollElapsedTime = 0; + float totalDuration = 0; + for(auto i = _inertiaTouchTimeDeltas.begin(); i != _inertiaTouchTimeDeltas.end(); ++i) + { + totalDuration += (*i); + } + if(totalDuration == 0 || totalDuration >= 0.5f) + { + return; + } + + _inertiaScrolling = true; + + // Calcualte the initial velocity + Vec2 totalMovement; + for(auto i = _inertiaTouchDisplacements.begin(); i != _inertiaTouchDisplacements.end(); ++i) + { + totalMovement += (*i); + } + totalMovement.x = (_direction == Direction::VERTICAL ? 0 : totalMovement.x); + totalMovement.y = (_direction == Direction::HORIZONTAL ? 0 : totalMovement.y); + + _inertiaInitiVelocity = totalMovement / totalDuration; + _inertiaInitiVelocity.x = MIN(_inertiaInitiVelocity.x, INERTIA_VELOCITY_MAX); + _inertiaInitiVelocity.y = MIN(_inertiaInitiVelocity.y, INERTIA_VELOCITY_MAX); + _inertiaInitiVelocity.x = MAX(_inertiaInitiVelocity.x, -INERTIA_VELOCITY_MAX); + _inertiaInitiVelocity.y = MAX(_inertiaInitiVelocity.y, -INERTIA_VELOCITY_MAX); + + // Calculate values for ease out + _inertiaScrollExpectedTime = _inertiaInitiVelocity.length() / INERTIA_DEACCELERATION; + _inertiaScrollElapsedTime = 0; } void ScrollView::processInertiaScrolling(float dt) { - _inertiaScrollElapsedTime += dt; - if(isOutOfBoundaryLeftOrRight() || isOutOfBoundaryTopOrBottom()) - { - // If the inner container is out of boundary, shorten the inertia time. - _inertiaScrollElapsedTime += dt * (45000 / INERTIA_DEACCELERATION); - } - float percentage = _inertiaScrollElapsedTime / _inertiaScrollExpectedTime; - if(percentage >= 1) - { - _inertiaScrolling = false; - startBounceBackIfNeeded(); - return; - } - percentage = tweenfunc::quartEaseOut(percentage); - - Vec2 inertiaVelocity = _inertiaInitiVelocity * (1 - percentage); - Vec2 displacement = inertiaVelocity * dt; - if(!_bounceEnabled) - { - Vec2 outOfBoundary = getHowMuchOutOfBoundary(displacement); - if(outOfBoundary != Vec2::ZERO) - { - // Don't allow to go out of boundary - displacement += outOfBoundary; - _inertiaScrolling = false; - } - } - moveChildren(displacement.x, displacement.y); + _inertiaScrollElapsedTime += dt; + if(isOutOfBoundaryLeftOrRight() || isOutOfBoundaryTopOrBottom()) + { + // If the inner container is out of boundary, shorten the inertia time. + _inertiaScrollElapsedTime += dt * (45000 / INERTIA_DEACCELERATION); + } + float percentage = _inertiaScrollElapsedTime / _inertiaScrollExpectedTime; + if(percentage >= 1) + { + _inertiaScrolling = false; + startBounceBackIfNeeded(); + return; + } + percentage = tweenfunc::quartEaseOut(percentage); + + Vec2 inertiaVelocity = _inertiaInitiVelocity * (1 - percentage); + Vec2 displacement = inertiaVelocity * dt; + if(!_bounceEnabled) + { + Vec2 outOfBoundary = getHowMuchOutOfBoundary(displacement); + if(outOfBoundary != Vec2::ZERO) + { + // Don't allow to go out of boundary + displacement += outOfBoundary; + _inertiaScrolling = false; + } + } + moveChildren(displacement.x, displacement.y); } bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY) { processScrollingEvent(); - - touchOffsetX = (_direction == Direction::VERTICAL ? 0 : touchOffsetX); - touchOffsetY = (_direction == Direction::HORIZONTAL ? 0 : touchOffsetY); - if(_bounceEnabled) - { - // If the position of the inner container is out of the boundary, the offsets should be divided by two. - touchOffsetX *= (isOutOfBoundaryLeftOrRight() ? 0.5f : 1); - touchOffsetY *= (isOutOfBoundaryTopOrBottom() ? 0.5f : 1); - } - - float realOffsetX = touchOffsetX; - float realOffsetY = touchOffsetY; - - bool scrollEnabledUpDown = true; - if (touchOffsetY > 0.0f) // up - { - float icBottomPos = _innerContainer->getBottomBoundary(); - if (icBottomPos + touchOffsetY >= _bottomBoundary) - { - if(!_bounceEnabled) - { - realOffsetY = _bottomBoundary - icBottomPos; - } - processScrollEvent(MoveDirection::BOTTOM, false); - scrollEnabledUpDown = false; - } - } - else if (touchOffsetY < 0.0f) // down - { - float icTopPos = _innerContainer->getTopBoundary(); - if (icTopPos + touchOffsetY <= _topBoundary) - { - if(!_bounceEnabled) - { - realOffsetY = _topBoundary - icTopPos; - } - processScrollEvent(MoveDirection::TOP, false); - scrollEnabledUpDown = false; - } - } - - bool scrollEnabledLeftRight = true; - if (touchOffsetX < 0.0f) // left - { - float icRightPos = _innerContainer->getRightBoundary(); - if (icRightPos + touchOffsetX <= _rightBoundary) - { - if(!_bounceEnabled) - { - realOffsetX = _rightBoundary - icRightPos; - } - processScrollEvent(MoveDirection::RIGHT, false); - scrollEnabledLeftRight = false; - } - } - else if (touchOffsetX > 0.0f) // right - { - float icLeftPos = _innerContainer->getLeftBoundary(); - if (icLeftPos + touchOffsetX >= _leftBoundary) - { - if(!_bounceEnabled) - { - realOffsetX = _leftBoundary - icLeftPos; - } - processScrollEvent(MoveDirection::LEFT, false); - scrollEnabledLeftRight = false; - } - } - moveChildren(realOffsetX, realOffsetY); - return scrollEnabledUpDown || scrollEnabledLeftRight; + + touchOffsetX = (_direction == Direction::VERTICAL ? 0 : touchOffsetX); + touchOffsetY = (_direction == Direction::HORIZONTAL ? 0 : touchOffsetY); + if(_bounceEnabled) + { + // If the position of the inner container is out of the boundary, the offsets should be divided by two. + touchOffsetX *= (isOutOfBoundaryLeftOrRight() ? 0.5f : 1); + touchOffsetY *= (isOutOfBoundaryTopOrBottom() ? 0.5f : 1); + } + + float realOffsetX = touchOffsetX; + float realOffsetY = touchOffsetY; + + bool scrollEnabledUpDown = true; + if (touchOffsetY > 0.0f) // up + { + float icBottomPos = _innerContainer->getBottomBoundary(); + if (icBottomPos + touchOffsetY >= _bottomBoundary) + { + if(!_bounceEnabled) + { + realOffsetY = _bottomBoundary - icBottomPos; + } + processScrollEvent(MoveDirection::BOTTOM, false); + scrollEnabledUpDown = false; + } + } + else if (touchOffsetY < 0.0f) // down + { + float icTopPos = _innerContainer->getTopBoundary(); + if (icTopPos + touchOffsetY <= _topBoundary) + { + if(!_bounceEnabled) + { + realOffsetY = _topBoundary - icTopPos; + } + processScrollEvent(MoveDirection::TOP, false); + scrollEnabledUpDown = false; + } + } + + bool scrollEnabledLeftRight = true; + if (touchOffsetX < 0.0f) // left + { + float icRightPos = _innerContainer->getRightBoundary(); + if (icRightPos + touchOffsetX <= _rightBoundary) + { + if(!_bounceEnabled) + { + realOffsetX = _rightBoundary - icRightPos; + } + processScrollEvent(MoveDirection::RIGHT, false); + scrollEnabledLeftRight = false; + } + } + else if (touchOffsetX > 0.0f) // right + { + float icLeftPos = _innerContainer->getLeftBoundary(); + if (icLeftPos + touchOffsetX >= _leftBoundary) + { + if(!_bounceEnabled) + { + realOffsetX = _leftBoundary - icLeftPos; + } + processScrollEvent(MoveDirection::LEFT, false); + scrollEnabledLeftRight = false; + } + } + moveChildren(realOffsetX, realOffsetY); + return scrollEnabledUpDown || scrollEnabledLeftRight; } void ScrollView::scrollToBottom(float second, bool attenuated) @@ -752,22 +755,21 @@ void ScrollView::startRecordSlidAction() { if (_inertiaScrolling) { - _inertiaScrolling = false; + _inertiaScrolling = false; + } + if(_autoScrolling) + { + _autoScrolling = false; + _bouncingBack = false; } - if(_autoScrolling) - { - _autoScrolling = false; - _bouncingBack = false; - } } void ScrollView::endRecordSlidAction() { - bool bounceBackStarted = startBounceBackIfNeeded(); - if(!bounceBackStarted && _inertiaScrollEnabled) - { - startInertiaScroll(); - + bool bounceBackStarted = startBounceBackIfNeeded(); + if(!bounceBackStarted && _inertiaScrollEnabled) + { + startInertiaScroll(); } } @@ -779,15 +781,15 @@ void ScrollView::handlePressLogic(Touch *touch) _inertiaPrevTouchTimestamp = utils::getTimeInMilliseconds(); _inertiaTouchDisplacements.clear(); _inertiaTouchTimeDeltas.clear(); - - if(_verticalScrollBar != nullptr) - { - _verticalScrollBar->onTouchBegan(); - } - if(_horizontalScrollBar != nullptr) - { - _horizontalScrollBar->onTouchBegan(); - } + + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->onTouchBegan(); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->onTouchBegan(); + } } void ScrollView::handleMoveLogic(Touch *touch) @@ -819,15 +821,15 @@ void ScrollView::handleReleaseLogic(Touch *touch) { endRecordSlidAction(); _bePressed = false; - - if(_verticalScrollBar != nullptr) - { - _verticalScrollBar->onTouchEnded(); - } - if(_horizontalScrollBar != nullptr) - { - _horizontalScrollBar->onTouchEnded(); - } + + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->onTouchEnded(); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->onTouchEnded(); + } } bool ScrollView::onTouchBegan(Touch *touch, Event *unusedEvent) @@ -878,10 +880,10 @@ void ScrollView::update(float dt) { processInertiaScrolling(dt); } - else if (_autoScrolling) - { - processAutoScrolling(dt); - } + else if (_autoScrolling) + { + processAutoScrolling(dt); + } } void ScrollView::interceptTouchEvent(Widget::TouchEventType event, Widget *sender,Touch* touch) @@ -965,7 +967,7 @@ void ScrollView::processScrollEvent(MoveDirection dir, bool bounce) scrollEventType = (bounce ? SCROLLVIEW_EVENT_BOUNCE_RIGHT : SCROLLVIEW_EVENT_SCROLL_TO_RIGHT); eventType = (bounce ? EventType::BOUNCE_RIGHT : EventType::SCROLL_TO_RIGHT); break; - } + } } dispatchEvent(scrollEventType, eventType); } @@ -1007,7 +1009,11 @@ void ScrollView::addEventListener(const ccScrollViewCallback& callback) void ScrollView::setDirection(Direction dir) { _direction = dir; - initScrollBar(); + if(_scrollBarEnabled) + { + removeScrollBar(); + initScrollBar(); + } } ScrollView::Direction ScrollView::getDirection()const @@ -1037,13 +1043,20 @@ bool ScrollView::isInertiaScrollEnabled() const void ScrollView::setScrollBarEnabled(bool enabled) { - _scrollBarEnabled = enabled; - initScrollBar(); + if(_scrollBarEnabled) + { + removeScrollBar(); + } + _scrollBarEnabled = enabled; + if(_scrollBarEnabled) + { + initScrollBar(); + } } bool ScrollView::isScrollBarEnabled() const { - return _scrollBarEnabled; + return _scrollBarEnabled; } void ScrollView::setScrollBarMargin(float margin) @@ -1255,41 +1268,45 @@ void ScrollView::copySpecialProperties(Widget *widget) _scrollViewEventSelector = scrollView->_scrollViewEventSelector; _eventCallback = scrollView->_eventCallback; _ccEventCallback = scrollView->_ccEventCallback; + + setScrollBarEnabled(scrollView->isScrollBarEnabled()); + if(isScrollBarEnabled()) + { + setScrollBarMargin(scrollView->getScrollBarMargin()); + setScrollBarWidth(scrollView->getScrollBarWidth()); + setScrollBarColor(scrollView->getScrollBarColor()); + setScrollBarAutoHideEnabled(scrollView->isScrollBarAutoHideEnabled()); + setScrollBarAutoHideTime(scrollView->getScrollBarAutoHideTime()); + } } } void ScrollView::initScrollBar() { - removeScrollBar(); - if(!_scrollBarEnabled) - { - return; - } - - if(_direction != Direction::HORIZONTAL && _verticalScrollBar == nullptr) - { - _verticalScrollBar = ScrollViewBar::create(this, Direction::VERTICAL); - addProtectedChild(_verticalScrollBar, 2); - } - if(_direction != Direction::VERTICAL && _horizontalScrollBar == nullptr) - { - _horizontalScrollBar = ScrollViewBar::create(this, Direction::HORIZONTAL); - addProtectedChild(_horizontalScrollBar, 2); - } + if(_direction != Direction::HORIZONTAL && _verticalScrollBar == nullptr) + { + _verticalScrollBar = ScrollViewBar::create(this, Direction::VERTICAL); + addProtectedChild(_verticalScrollBar, 2); + } + if(_direction != Direction::VERTICAL && _horizontalScrollBar == nullptr) + { + _horizontalScrollBar = ScrollViewBar::create(this, Direction::HORIZONTAL); + addProtectedChild(_horizontalScrollBar, 2); + } } void ScrollView::removeScrollBar() { - if(_verticalScrollBar != nullptr) - { - removeProtectedChild(_verticalScrollBar); - _verticalScrollBar = nullptr; - } - if(_horizontalScrollBar != nullptr) - { - removeProtectedChild(_horizontalScrollBar); - _horizontalScrollBar = nullptr; - } + if(_verticalScrollBar != nullptr) + { + removeProtectedChild(_verticalScrollBar); + _verticalScrollBar = nullptr; + } + if(_horizontalScrollBar != nullptr) + { + removeProtectedChild(_horizontalScrollBar); + _horizontalScrollBar = nullptr; + } } Widget* ScrollView::findNextFocusedWidget(cocos2d::ui::Widget::FocusDirection direction, cocos2d::ui::Widget *current) diff --git a/cocos/ui/UIScrollViewBar.cpp b/cocos/ui/UIScrollViewBar.cpp index fc2bc08018..0c9275d0e9 100644 --- a/cocos/ui/UIScrollViewBar.cpp +++ b/cocos/ui/UIScrollViewBar.cpp @@ -68,6 +68,7 @@ namespace ui { _autoHideTime(DEFAULT_AUTO_HIDE_TIME), _autoHideRemainingTime(0) { + CCASSERT(parent != nullptr, "Parent scroll view must not be null!"); CCASSERT(direction != ScrollView::Direction::BOTH, "Illegal scroll direction for scroll bar!"); setCascadeColorEnabled(true); setCascadeOpacityEnabled(true); @@ -125,7 +126,6 @@ namespace ui { void ScrollViewBar::setWidth(float width) { - CCASSERT(_body != nullptr && _upperHalfCircle != nullptr && _lowerHalfCircle != nullptr, "Internal sprites are not set!"); float scale = width / _body->getContentSize().width; _body->setScaleX(scale); _upperHalfCircle->setScale(scale); @@ -134,24 +134,9 @@ namespace ui { float ScrollViewBar::getWidth() const { - CCASSERT(_body != nullptr, "The body sprite is null!"); return _body->getBoundingBox().size.width; } - void ScrollViewBar::setColor(const Color3B& color) - { - CCASSERT(_body != nullptr && _upperHalfCircle != nullptr && _lowerHalfCircle != nullptr, "Internal sprites are not set!"); - _body->setColor(color); - _upperHalfCircle->setColor(color); - _lowerHalfCircle->setColor(color); - } - - const Color3B& ScrollViewBar::getColor() const - { - CCASSERT(_body != nullptr, "The body sprite is null!"); - return _body->getColor(); - } - void ScrollViewBar::setLength(float length) { float ratio = length / _body->getTextureRect().size.height; @@ -167,11 +152,16 @@ namespace ui { void ScrollViewBar::update(float deltaTime) { - if(!_autoHideEnabled || _touching || _autoHideRemainingTime <= 0) + if(!_autoHideEnabled || _autoHideRemainingTime <= 0) { return; } - + else if(_touching) + { + // If it is touching, don't auto hide. + return; + } + _autoHideRemainingTime -= deltaTime; if(_autoHideRemainingTime <= _autoHideTime) { @@ -182,17 +172,27 @@ namespace ui { void ScrollViewBar::onTouchBegan() { + if(!_autoHideEnabled) + { + return; + } _touching = true; } void ScrollViewBar::onTouchEnded() { + if(!_autoHideEnabled) + { + return; + } _touching = false; - if(_autoHideEnabled) - { - _autoHideRemainingTime = _autoHideTime; - } + if(_autoHideRemainingTime <= 0) + { + // If the remaining time is 0, it means that it didn't moved after touch started so scroll bar is not showing. + return; + } + _autoHideRemainingTime = _autoHideTime; } void ScrollViewBar::onScrolled(const Vec2& outOfBoundary) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 576d20aaa9..0fe4acd812 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -493,6 +493,7 @@ bool UIScrollViewRotated::init() (backgroundSize.height - scrollView->getContentSize().height) / 2.0f + 100) ); scrollView->setRotation(45); scrollView->setScrollBarMargin(4); + scrollView->setScrollBarColor(Color3B::WHITE); _uiLayer->addChild(scrollView); ImageView* imageView = ImageView::create("cocosui/ccicon.png"); From 86cbd59bfd69343dd5a8bbc5a6014024912a4a16 Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Wed, 1 Jul 2015 12:42:24 +0900 Subject: [PATCH 12/43] Add UIScrollViewBar.cpp into CMake and Windows project configuration. --- cocos/2d/libcocos2d.vcxproj | 1 + cocos/2d/libcocos2d.vcxproj.filters | 3 +++ .../libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems | 6 +++++- .../libcocos2d_8_1.Shared.vcxitems.filters | 8 +++++++- cocos/2d/libcocos2d_win10/libcocos2d.vcxproj | 1 + cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters | 3 +++ cocos/ui/CMakeLists.txt | 1 + cocos/ui/proj.win32/libui.vcxproj | 1 + cocos/ui/proj.win32/libui.vcxproj.filters | 3 +++ templates/cocos2dx_files.json | 2 ++ 10 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 8a18237822..4678e83df5 100644 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -647,6 +647,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters index 8137a888dc..c1cc7491ec 100644 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -931,6 +931,9 @@ ui\UIWidgets\ScrollWidget + + ui\UIWidgets\ScrollWidget + cocostudio\TimelineAction\trigger diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems index 06518ba58c..46d1d15383 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems @@ -1136,6 +1136,7 @@ + @@ -1259,4 +1260,7 @@ - \ No newline at end of file + + + + diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters index 27516b1a9d..be5ec0663c 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters @@ -2291,6 +2291,9 @@ ui\UIWidgets\ScrollWidget + + ui\UIWidgets\ScrollWidget + ui\UIWidgets @@ -3897,4 +3900,7 @@ 3d - \ No newline at end of file + + + + diff --git a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj index 48e35ec96f..2a6c5ffa59 100644 --- a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj @@ -642,6 +642,7 @@ + diff --git a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters index 179ad04589..cb7dcb98d7 100644 --- a/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d_win10/libcocos2d.vcxproj.filters @@ -1761,6 +1761,9 @@ ui\UIWidgets\ScrollWidget + + ui\UIWidgets\ScrollWidget + ui\UIWidgets diff --git a/cocos/ui/CMakeLists.txt b/cocos/ui/CMakeLists.txt index f5f2653e1f..4ab3940db9 100644 --- a/cocos/ui/CMakeLists.txt +++ b/cocos/ui/CMakeLists.txt @@ -41,6 +41,7 @@ set(COCOS_UI_SRC ui/UIRichText.cpp ui/UIScale9Sprite.cpp ui/UIScrollView.cpp + ui/UIScrollViewBar.cpp ui/UISlider.cpp ui/UIText.cpp ui/UITextAtlas.cpp diff --git a/cocos/ui/proj.win32/libui.vcxproj b/cocos/ui/proj.win32/libui.vcxproj index 2455a54cf6..0cb39b29cf 100644 --- a/cocos/ui/proj.win32/libui.vcxproj +++ b/cocos/ui/proj.win32/libui.vcxproj @@ -66,6 +66,7 @@ + diff --git a/cocos/ui/proj.win32/libui.vcxproj.filters b/cocos/ui/proj.win32/libui.vcxproj.filters index 8f12f2c2c5..000ab33b24 100644 --- a/cocos/ui/proj.win32/libui.vcxproj.filters +++ b/cocos/ui/proj.win32/libui.vcxproj.filters @@ -122,6 +122,9 @@ UIWidgets\ScrollWidget + + UIWidgets\ScrollWidget + UIWidgets\ScrollWidget diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index 96c774c16b..cedb71ff1a 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -1212,6 +1212,8 @@ "cocos/ui/UIScale9Sprite.h", "cocos/ui/UIScrollView.cpp", "cocos/ui/UIScrollView.h", + "cocos/ui/UIScrollViewBar.cpp", + "cocos/ui/UIScrollViewBar.h", "cocos/ui/UISlider.cpp", "cocos/ui/UISlider.h", "cocos/ui/UIText.cpp", From 3b6cd4dffc3d4e7cc7b4295fb3bd3f8b3d7454ae Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Fri, 3 Jul 2015 23:03:02 +0900 Subject: [PATCH 13/43] Modify indentation to comply with the convention --- cocos/ui/UIScrollView.cpp | 246 +++++++++---------- cocos/ui/UIScrollView.h | 142 +++++------ cocos/ui/UIScrollViewBar.cpp | 464 ++++++++++++++++++----------------- cocos/ui/UIScrollViewBar.h | 178 +++++++------- 4 files changed, 518 insertions(+), 512 deletions(-) diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 3aa49e1858..113a3a1da2 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -118,10 +118,10 @@ bool ScrollView::init() { setClippingEnabled(true); _innerContainer->setTouchEnabled(false); - if(_scrollBarEnabled) - { - initScrollBar(); - } + if(_scrollBarEnabled) + { + initScrollBar(); + } return true; } return false; @@ -1009,11 +1009,11 @@ void ScrollView::addEventListener(const ccScrollViewCallback& callback) void ScrollView::setDirection(Direction dir) { _direction = dir; - if(_scrollBarEnabled) - { - removeScrollBar(); - initScrollBar(); - } + if(_scrollBarEnabled) + { + removeScrollBar(); + initScrollBar(); + } } ScrollView::Direction ScrollView::getDirection()const @@ -1043,15 +1043,15 @@ bool ScrollView::isInertiaScrollEnabled() const void ScrollView::setScrollBarEnabled(bool enabled) { - if(_scrollBarEnabled) - { - removeScrollBar(); - } + if(_scrollBarEnabled) + { + removeScrollBar(); + } _scrollBarEnabled = enabled; - if(_scrollBarEnabled) - { - initScrollBar(); - } + if(_scrollBarEnabled) + { + initScrollBar(); + } } bool ScrollView::isScrollBarEnabled() const @@ -1061,137 +1061,137 @@ bool ScrollView::isScrollBarEnabled() const void ScrollView::setScrollBarMargin(float margin) { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - _verticalScrollBar->setMargin(margin); - } - if(_horizontalScrollBar != nullptr) - { - _horizontalScrollBar->setMargin(margin); - } + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->setMargin(margin); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->setMargin(margin); + } } float ScrollView::getScrollBarMargin() const { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - return _verticalScrollBar->getMargin(); - } - else if(_horizontalScrollBar != nullptr) - { - return _horizontalScrollBar->getMargin(); - } - return 0; + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + return _verticalScrollBar->getMargin(); + } + else if(_horizontalScrollBar != nullptr) + { + return _horizontalScrollBar->getMargin(); + } + return 0; } void ScrollView::setScrollBarWidth(float width) { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - _verticalScrollBar->setWidth(width); - } - if(_horizontalScrollBar != nullptr) - { - _horizontalScrollBar->setWidth(width); - } + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->setWidth(width); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->setWidth(width); + } } float ScrollView::getScrollBarWidth() const { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - return _verticalScrollBar->getWidth(); - } - else if(_horizontalScrollBar != nullptr) - { - return _horizontalScrollBar->getWidth(); - } - return 0; + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + return _verticalScrollBar->getWidth(); + } + else if(_horizontalScrollBar != nullptr) + { + return _horizontalScrollBar->getWidth(); + } + return 0; } void ScrollView::setScrollBarColor(const Color3B& color) { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - _verticalScrollBar->setColor(color); - } - if(_horizontalScrollBar != nullptr) - { - _horizontalScrollBar->setColor(color); - } + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->setColor(color); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->setColor(color); + } } const Color3B& ScrollView::getScrollBarColor() const { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - return _verticalScrollBar->getColor(); - } - else if(_horizontalScrollBar != nullptr) - { - return _horizontalScrollBar->getColor(); - } - return Color3B::WHITE; + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + return _verticalScrollBar->getColor(); + } + else if(_horizontalScrollBar != nullptr) + { + return _horizontalScrollBar->getColor(); + } + return Color3B::WHITE; } void ScrollView::setScrollBarAutoHideEnabled(bool autoHideEnabled) { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - _verticalScrollBar->setAutoHideEnabled(autoHideEnabled); - } - if(_horizontalScrollBar != nullptr) - { - _horizontalScrollBar->setAutoHideEnabled(autoHideEnabled); - } + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->setAutoHideEnabled(autoHideEnabled); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->setAutoHideEnabled(autoHideEnabled); + } } bool ScrollView::isScrollBarAutoHideEnabled() const { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - return _verticalScrollBar->isAutoHideEnabled(); - } - else if(_horizontalScrollBar != nullptr) - { - return _horizontalScrollBar->isAutoHideEnabled(); - } - return false; + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + return _verticalScrollBar->isAutoHideEnabled(); + } + else if(_horizontalScrollBar != nullptr) + { + return _horizontalScrollBar->isAutoHideEnabled(); + } + return false; } void ScrollView::setScrollBarAutoHideTime(float autoHideTime) { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - _verticalScrollBar->setAutoHideTime(autoHideTime); - } - if(_horizontalScrollBar != nullptr) - { - _horizontalScrollBar->setAutoHideTime(autoHideTime); - } + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + _verticalScrollBar->setAutoHideTime(autoHideTime); + } + if(_horizontalScrollBar != nullptr) + { + _horizontalScrollBar->setAutoHideTime(autoHideTime); + } } - + float ScrollView::getScrollBarAutoHideTime() const { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - return _verticalScrollBar->getAutoHideTime(); - } - else if(_horizontalScrollBar != nullptr) - { - return _horizontalScrollBar->getAutoHideTime(); - } - return 0; + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + if(_verticalScrollBar != nullptr) + { + return _verticalScrollBar->getAutoHideTime(); + } + else if(_horizontalScrollBar != nullptr) + { + return _horizontalScrollBar->getAutoHideTime(); + } + return 0; } Layout* ScrollView::getInnerContainer()const @@ -1268,16 +1268,16 @@ void ScrollView::copySpecialProperties(Widget *widget) _scrollViewEventSelector = scrollView->_scrollViewEventSelector; _eventCallback = scrollView->_eventCallback; _ccEventCallback = scrollView->_ccEventCallback; - - setScrollBarEnabled(scrollView->isScrollBarEnabled()); - if(isScrollBarEnabled()) - { - setScrollBarMargin(scrollView->getScrollBarMargin()); - setScrollBarWidth(scrollView->getScrollBarWidth()); - setScrollBarColor(scrollView->getScrollBarColor()); - setScrollBarAutoHideEnabled(scrollView->isScrollBarAutoHideEnabled()); - setScrollBarAutoHideTime(scrollView->getScrollBarAutoHideTime()); - } + + setScrollBarEnabled(scrollView->isScrollBarEnabled()); + if(isScrollBarEnabled()) + { + setScrollBarMargin(scrollView->getScrollBarMargin()); + setScrollBarWidth(scrollView->getScrollBarWidth()); + setScrollBarColor(scrollView->getScrollBarColor()); + setScrollBarAutoHideEnabled(scrollView->isScrollBarAutoHideEnabled()); + setScrollBarAutoHideTime(scrollView->getScrollBarAutoHideTime()); + } } } diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h index 2846c9389c..4a37623a4d 100644 --- a/cocos/ui/UIScrollView.h +++ b/cocos/ui/UIScrollView.h @@ -385,77 +385,77 @@ public: * @return True if scroll bar is enabled, false otherwise. */ bool isScrollBarEnabled() const; - - /** - * @brief Set the margin between scroll bar and the container's border - * - * @param margin The margin between scroll bar and the container's border - */ - void setScrollBarMargin(float margin); - - /** - * @brief Get the margin between scroll bar and the container's border - * - * @return margin - */ - float getScrollBarMargin() const; - - /** - * @brief Set the scroll bar's width - * - * @param width The scroll bar's width - */ - void setScrollBarWidth(float width); - - /** - * @brief Get the scroll bar's width - * - * @return the scroll bar's width - */ - float getScrollBarWidth() const; - - /** - * @brief Set the scroll bar's color - * - * @param the scroll bar's color - */ - void setScrollBarColor(const Color3B& color); - - /** - * @brief Get the scroll bar's color - * - * @return the scroll bar's color - */ - const Color3B& getScrollBarColor() const; - - /** - * @brief Set scroll bar auto hide state - * - * @param scroll bar auto hide state - */ - void setScrollBarAutoHideEnabled(bool autoHideEnabled); - - /** - * @brief Query scroll bar auto hide state - * - * @return True if scroll bar auto hide is enabled, false otherwise. - */ - bool isScrollBarAutoHideEnabled() const; - - /** - * @brief Set scroll bar auto hide time - * - * @param scroll bar auto hide time - */ - void setScrollBarAutoHideTime(float autoHideTime); - - /** - * @brief Get the scroll bar's auto hide time - * - * @return the scroll bar's auto hide time - */ - float getScrollBarAutoHideTime() const; - + + /** + * @brief Set the margin between scroll bar and the container's border + * + * @param margin The margin between scroll bar and the container's border + */ + void setScrollBarMargin(float margin); + + /** + * @brief Get the margin between scroll bar and the container's border + * + * @return margin + */ + float getScrollBarMargin() const; + + /** + * @brief Set the scroll bar's width + * + * @param width The scroll bar's width + */ + void setScrollBarWidth(float width); + + /** + * @brief Get the scroll bar's width + * + * @return the scroll bar's width + */ + float getScrollBarWidth() const; + + /** + * @brief Set the scroll bar's color + * + * @param the scroll bar's color + */ + void setScrollBarColor(const Color3B& color); + + /** + * @brief Get the scroll bar's color + * + * @return the scroll bar's color + */ + const Color3B& getScrollBarColor() const; + + /** + * @brief Set scroll bar auto hide state + * + * @param scroll bar auto hide state + */ + void setScrollBarAutoHideEnabled(bool autoHideEnabled); + + /** + * @brief Query scroll bar auto hide state + * + * @return True if scroll bar auto hide is enabled, false otherwise. + */ + bool isScrollBarAutoHideEnabled() const; + + /** + * @brief Set scroll bar auto hide time + * + * @param scroll bar auto hide time + */ + void setScrollBarAutoHideTime(float autoHideTime); + + /** + * @brief Get the scroll bar's auto hide time + * + * @return the scroll bar's auto hide time + */ + float getScrollBarAutoHideTime() const; + /** * Set layout type for scrollview. * diff --git a/cocos/ui/UIScrollViewBar.cpp b/cocos/ui/UIScrollViewBar.cpp index 0c9275d0e9..3d08f59c34 100644 --- a/cocos/ui/UIScrollViewBar.cpp +++ b/cocos/ui/UIScrollViewBar.cpp @@ -31,245 +31,251 @@ NS_CC_BEGIN namespace ui { - static const char* HALF_CIRCLE_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAGCAMAAADAMI+zAAAAIVBMVEX///////////////////////////////////////////9/gMdvAAAAC3RSTlMAAgMLLFBTYWNkZuZhN4QAAAAvSURBVAjXRchBDgAgCAPBIi0q/3+wxBiZU7cAjJpTNBSPvMLrf7tqgPkR6hB2xzpFkgIfM9q/8QAAAABJRU5ErkJggg=="; - static const char* BODY_IMAGE_1_PIXEL_HEIGHT = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAABCAMAAADdNb8LAAAAA1BMVEX///+nxBvIAAAAAXRSTlNm5DccCwAAAApJREFUeAFjQAYAAA0AAWHNnKQAAAAASUVORK5CYII="; +static const char* HALF_CIRCLE_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAGCAMAAADAMI+zAAAAIVBMVEX///////////////////////////////////////////9/gMdvAAAAC3RSTlMAAgMLLFBTYWNkZuZhN4QAAAAvSURBVAjXRchBDgAgCAPBIi0q/3+wxBiZU7cAjJpTNBSPvMLrf7tqgPkR6hB2xzpFkgIfM9q/8QAAAABJRU5ErkJggg=="; +static const char* BODY_IMAGE_1_PIXEL_HEIGHT = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAABCAMAAADdNb8LAAAAA1BMVEX///+nxBvIAAAAAXRSTlNm5DccCwAAAApJREFUeAFjQAYAAA0AAWHNnKQAAAAASUVORK5CYII="; + +static const Color3B DEFAULT_COLOR(52, 65, 87); +static const float DEFAULT_MARGIN = 30; +static const float DEFAULT_AUTO_HIDE_TIME = 0.2f; + +static Sprite* createSpriteFromBase64(const char* base64String) +{ + unsigned char* decoded; + int length = base64Decode((const unsigned char*) base64String, (unsigned int) strlen(base64String), &decoded); - static const Color3B DEFAULT_COLOR(52, 65, 87); - static const float DEFAULT_MARGIN = 30; - static const float DEFAULT_AUTO_HIDE_TIME = 0.2f; + Image *image = new Image(); + bool imageResult = image->initWithImageData(decoded, length); + CCASSERT(imageResult, "Failed to create image from base64!"); + free(decoded); - static Sprite* createSpriteFromBase64(const char* base64String) - { - unsigned char* decoded; - int length = base64Decode((const unsigned char*) base64String, (unsigned int) strlen(base64String), &decoded); - - Image *image = new Image(); - bool imageResult = image->initWithImageData(decoded, length); - CCASSERT(imageResult, "Failed to create image from base64!"); - free(decoded); - - Texture2D *pTexture = new Texture2D(); - pTexture->initWithImage(image); - pTexture->setAliasTexParameters(); - image->release(); - - return Sprite::createWithTexture(pTexture); - } - - ScrollViewBar::ScrollViewBar(ScrollView* parent, ScrollView::Direction direction): - _parent(parent), - _direction(direction), - _upperHalfCircle(nullptr), - _lowerHalfCircle(nullptr), - _body(nullptr), - _margin(DEFAULT_MARGIN), - _touching(false), - _autoHideEnabled(true), - _autoHideTime(DEFAULT_AUTO_HIDE_TIME), - _autoHideRemainingTime(0) - { - CCASSERT(parent != nullptr, "Parent scroll view must not be null!"); - CCASSERT(direction != ScrollView::Direction::BOTH, "Illegal scroll direction for scroll bar!"); - setCascadeColorEnabled(true); - setCascadeOpacityEnabled(true); - } - - ScrollViewBar::~ScrollViewBar() - { - } - - ScrollViewBar* ScrollViewBar::create(ScrollView* parent, ScrollView::Direction direction) - { - ScrollViewBar* node = new (std::nothrow) ScrollViewBar(parent, direction); - if (node && node->init()) - { - node->autorelease(); - return node; - } - CC_SAFE_DELETE(node); - return nullptr; - } - - bool ScrollViewBar::init() - { - if (!ProtectedNode::init()) - { - return false; - } - - _upperHalfCircle = createSpriteFromBase64(HALF_CIRCLE_IMAGE); - _upperHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - addChild(_upperHalfCircle); - - _lowerHalfCircle = Sprite::createWithTexture(_upperHalfCircle->getTexture(), _upperHalfCircle->getTextureRect(), _upperHalfCircle->isTextureRectRotated()); - _lowerHalfCircle->setScaleY(-1); - _lowerHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - addChild(_lowerHalfCircle); - - _body = createSpriteFromBase64(BODY_IMAGE_1_PIXEL_HEIGHT); - _body->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - addChild(_body); - - setColor(DEFAULT_COLOR); - - if(_direction == ScrollView::Direction::HORIZONTAL) - { - setRotation(90); - } - - if(_autoHideEnabled) - { - setOpacity(0); - } - return true; - } - - void ScrollViewBar::setWidth(float width) + Texture2D *pTexture = new Texture2D(); + pTexture->initWithImage(image); + pTexture->setAliasTexParameters(); + image->release(); + + return Sprite::createWithTexture(pTexture); +} + +ScrollViewBar::ScrollViewBar(ScrollView* parent, ScrollView::Direction direction): +_parent(parent), +_direction(direction), +_upperHalfCircle(nullptr), +_lowerHalfCircle(nullptr), +_body(nullptr), +_margin(DEFAULT_MARGIN), +_touching(false), +_autoHideEnabled(true), +_autoHideTime(DEFAULT_AUTO_HIDE_TIME), +_autoHideRemainingTime(0) +{ + CCASSERT(parent != nullptr, "Parent scroll view must not be null!"); + CCASSERT(direction != ScrollView::Direction::BOTH, "Illegal scroll direction for scroll bar!"); + setCascadeColorEnabled(true); + setCascadeOpacityEnabled(true); +} + +ScrollViewBar::~ScrollViewBar() +{ +} + +ScrollViewBar* ScrollViewBar::create(ScrollView* parent, ScrollView::Direction direction) +{ + ScrollViewBar* node = new (std::nothrow) ScrollViewBar(parent, direction); + if (node && node->init()) { - float scale = width / _body->getContentSize().width; - _body->setScaleX(scale); - _upperHalfCircle->setScale(scale); - _lowerHalfCircle->setScale(-scale); + node->autorelease(); + return node; + } + CC_SAFE_DELETE(node); + return nullptr; +} + +bool ScrollViewBar::init() +{ + if (!ProtectedNode::init()) + { + return false; } - float ScrollViewBar::getWidth() const + _upperHalfCircle = createSpriteFromBase64(HALF_CIRCLE_IMAGE); + _upperHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); + addChild(_upperHalfCircle); + + _lowerHalfCircle = Sprite::createWithTexture(_upperHalfCircle->getTexture(), _upperHalfCircle->getTextureRect(), _upperHalfCircle->isTextureRectRotated()); + _lowerHalfCircle->setScaleY(-1); + _lowerHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); + addChild(_lowerHalfCircle); + + _body = createSpriteFromBase64(BODY_IMAGE_1_PIXEL_HEIGHT); + _body->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); + addChild(_body); + + setColor(DEFAULT_COLOR); + + if(_direction == ScrollView::Direction::HORIZONTAL) { - return _body->getBoundingBox().size.width; + setRotation(90); } - void ScrollViewBar::setLength(float length) - { - float ratio = length / _body->getTextureRect().size.height; - _body->setScaleY(ratio); - _upperHalfCircle->setPositionY(_body->getPositionY() + length); - } - - void ScrollViewBar::onEnter() - { - ProtectedNode::onEnter(); - scheduleUpdate(); - } - - void ScrollViewBar::update(float deltaTime) - { - if(!_autoHideEnabled || _autoHideRemainingTime <= 0) - { - return; - } - else if(_touching) - { - // If it is touching, don't auto hide. - return; - } - - _autoHideRemainingTime -= deltaTime; - if(_autoHideRemainingTime <= _autoHideTime) - { - _autoHideRemainingTime = MAX(0, _autoHideRemainingTime); - this->setOpacity(255 * (_autoHideRemainingTime / _autoHideTime)); - } - } - - void ScrollViewBar::onTouchBegan() - { - if(!_autoHideEnabled) - { - return; - } - _touching = true; - } - - void ScrollViewBar::onTouchEnded() - { - if(!_autoHideEnabled) - { - return; - } - _touching = false; - - if(_autoHideRemainingTime <= 0) - { - // If the remaining time is 0, it means that it didn't moved after touch started so scroll bar is not showing. - return; - } + if(_autoHideEnabled) + { + setOpacity(0); + } + return true; +} + +void ScrollViewBar::setWidth(float width) +{ + float scale = width / _body->getContentSize().width; + _body->setScaleX(scale); + _upperHalfCircle->setScale(scale); + _lowerHalfCircle->setScale(-scale); +} + +void ScrollViewBar::setAutoHideEnabled(bool autoHideEnabled) +{ + _autoHideEnabled = autoHideEnabled; + setOpacity(255); +} + +float ScrollViewBar::getWidth() const +{ + return _body->getBoundingBox().size.width; +} + +void ScrollViewBar::setLength(float length) +{ + float ratio = length / _body->getTextureRect().size.height; + _body->setScaleY(ratio); + _upperHalfCircle->setPositionY(_body->getPositionY() + length); +} + +void ScrollViewBar::onEnter() +{ + ProtectedNode::onEnter(); + scheduleUpdate(); +} + +void ScrollViewBar::update(float deltaTime) +{ + if(!_autoHideEnabled || _autoHideRemainingTime <= 0) + { + return; + } + else if(_touching) + { + // If it is touching, don't auto hide. + return; + } + + _autoHideRemainingTime -= deltaTime; + if(_autoHideRemainingTime <= _autoHideTime) + { + _autoHideRemainingTime = MAX(0, _autoHideRemainingTime); + this->setOpacity(255 * (_autoHideRemainingTime / _autoHideTime)); + } +} + +void ScrollViewBar::onTouchBegan() +{ + if(!_autoHideEnabled) + { + return; + } + _touching = true; +} + +void ScrollViewBar::onTouchEnded() +{ + if(!_autoHideEnabled) + { + return; + } + _touching = false; + + if(_autoHideRemainingTime <= 0) + { + // If the remaining time is 0, it means that it didn't moved after touch started so scroll bar is not showing. + return; + } + _autoHideRemainingTime = _autoHideTime; +} + +void ScrollViewBar::onScrolled(const Vec2& outOfBoundary) +{ + if(_autoHideEnabled) + { _autoHideRemainingTime = _autoHideTime; - } + setOpacity(255); + } - void ScrollViewBar::onScrolled(const Vec2& outOfBoundary) - { - if(_autoHideEnabled) - { - _autoHideRemainingTime = _autoHideTime; - setOpacity(255); - } - - Layout* innerContainer = _parent->getInnerContainer(); - - float innerContainerMeasure = 0; - float scrollViewMeasure = 0; - float outOfBoundaryValue = 0; - float innerContainerPosition = 0; - if(_direction == ScrollView::Direction::VERTICAL) - { - innerContainerMeasure = innerContainer->getContentSize().height; - scrollViewMeasure = _parent->getContentSize().height; - outOfBoundaryValue = outOfBoundary.y; - innerContainerPosition = -innerContainer->getPositionY(); - } - else if(_direction == ScrollView::Direction::HORIZONTAL) - { - innerContainerMeasure = innerContainer->getContentSize().width; - scrollViewMeasure = _parent->getContentSize().width; - outOfBoundaryValue = outOfBoundary.x; - innerContainerPosition = -innerContainer->getPositionX(); - } - - float length = updateLength(innerContainerMeasure, scrollViewMeasure, outOfBoundaryValue); - updatePosition(innerContainerMeasure, scrollViewMeasure, innerContainerPosition, outOfBoundaryValue, length); - } - - float ScrollViewBar::updateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue) - { - float denominatorValue = innerContainerMeasure; - if(outOfBoundaryValue != 0) - { - // If it is out of boundary, the length of scroll bar gets shorter quickly. - static const float GETTING_SHORTER_FACTOR = 20; - denominatorValue += (outOfBoundaryValue > 0 ? outOfBoundaryValue : -outOfBoundaryValue) * GETTING_SHORTER_FACTOR; - } - - float lengthRatio = scrollViewMeasure / denominatorValue; - float length = (scrollViewMeasure - 2 * _margin) * lengthRatio; - setLength(length); - return length; - } - - void ScrollViewBar::updatePosition(float innerContainerMeasure, float scrollViewMeasure, float innerContainerPosition, float outOfBoundaryValue, float length) - { - float denominatorValue = innerContainerMeasure - scrollViewMeasure; - if(outOfBoundaryValue != 0) - { - denominatorValue += outOfBoundaryValue * (outOfBoundaryValue < 0 ? -1 : 1); - } - - float positionRatio = 0; - if(denominatorValue != 0) - { - positionRatio = innerContainerPosition / denominatorValue; - positionRatio = MAX(positionRatio, 0); - positionRatio = MIN(positionRatio, 1); - } - float position = (scrollViewMeasure - length - 2 * _margin) * positionRatio + _margin; - - if(_direction == ScrollView::Direction::VERTICAL) - { - setPosition(_parent->getContentSize().width - _margin, position); - } - else if(_direction == ScrollView::Direction::HORIZONTAL) - { - setPosition(position, _margin); - } - } + Layout* innerContainer = _parent->getInnerContainer(); + + float innerContainerMeasure = 0; + float scrollViewMeasure = 0; + float outOfBoundaryValue = 0; + float innerContainerPosition = 0; + if(_direction == ScrollView::Direction::VERTICAL) + { + innerContainerMeasure = innerContainer->getContentSize().height; + scrollViewMeasure = _parent->getContentSize().height; + outOfBoundaryValue = outOfBoundary.y; + innerContainerPosition = -innerContainer->getPositionY(); + } + else if(_direction == ScrollView::Direction::HORIZONTAL) + { + innerContainerMeasure = innerContainer->getContentSize().width; + scrollViewMeasure = _parent->getContentSize().width; + outOfBoundaryValue = outOfBoundary.x; + innerContainerPosition = -innerContainer->getPositionX(); + } + + float length = updateLength(innerContainerMeasure, scrollViewMeasure, outOfBoundaryValue); + updatePosition(innerContainerMeasure, scrollViewMeasure, innerContainerPosition, outOfBoundaryValue, length); +} + +float ScrollViewBar::updateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue) +{ + float denominatorValue = innerContainerMeasure; + if(outOfBoundaryValue != 0) + { + // If it is out of boundary, the length of scroll bar gets shorter quickly. + static const float GETTING_SHORTER_FACTOR = 20; + denominatorValue += (outOfBoundaryValue > 0 ? outOfBoundaryValue : -outOfBoundaryValue) * GETTING_SHORTER_FACTOR; + } + + float lengthRatio = scrollViewMeasure / denominatorValue; + float length = (scrollViewMeasure - 2 * _margin) * lengthRatio; + setLength(length); + return length; +} + +void ScrollViewBar::updatePosition(float innerContainerMeasure, float scrollViewMeasure, float innerContainerPosition, float outOfBoundaryValue, float length) +{ + float denominatorValue = innerContainerMeasure - scrollViewMeasure; + if(outOfBoundaryValue != 0) + { + denominatorValue += outOfBoundaryValue * (outOfBoundaryValue < 0 ? -1 : 1); + } + + float positionRatio = 0; + if(denominatorValue != 0) + { + positionRatio = innerContainerPosition / denominatorValue; + positionRatio = MAX(positionRatio, 0); + positionRatio = MIN(positionRatio, 1); + } + float position = (scrollViewMeasure - length - 2 * _margin) * positionRatio + _margin; + + if(_direction == ScrollView::Direction::VERTICAL) + { + setPosition(_parent->getContentSize().width - _margin, position); + } + else if(_direction == ScrollView::Direction::HORIZONTAL) + { + setPosition(position, _margin); + } +} } NS_CC_END diff --git a/cocos/ui/UIScrollViewBar.h b/cocos/ui/UIScrollViewBar.h index 9a0539c26b..e773354a2f 100644 --- a/cocos/ui/UIScrollViewBar.h +++ b/cocos/ui/UIScrollViewBar.h @@ -44,103 +44,103 @@ class CC_GUI_DLL ScrollViewBar : public ProtectedNode { public: - /** - * Default constructor - * @js ctor - * @lua new - */ + /** + * Default constructor + * @js ctor + * @lua new + */ ScrollViewBar(ScrollView* parent, ScrollView::Direction direction); - /** - * Default destructor - * @js NA - * @lua NA - */ + /** + * Default destructor + * @js NA + * @lua NA + */ virtual ~ScrollViewBar(); - /** - * Create a ScrollView with its parent ScrollView and direction. - * @return A ScrollViewBar instance. - */ + /** + * Create a ScrollView with its parent ScrollView and direction. + * @return A ScrollViewBar instance. + */ static ScrollViewBar* create(ScrollView* parent, ScrollView::Direction direction); - - /** - * @brief Set the margin between scroll bar and the parent ScrollView's border - * - * @param margin The margin between scroll bar and the parent ScrollView's border - */ - void setMargin(float margin) { _margin = margin; } - - /** - * @brief Get the margin between scroll bar and the parent ScrollView's border - * - * @return margin - */ - float getMargin() const { return _margin; } - - /** - * @brief Set the scroll bar's width - * - * @param width The scroll bar's width - */ - void setWidth(float width); - - /** - * @brief Get the scroll bar's width - * - * @return the scroll bar's width - */ - float getWidth() const; - - /** - * @brief Set scroll bar auto hide state - * - * @param scroll bar auto hide state - */ - void setAutoHideEnabled(bool autoHideEnabled) { _autoHideEnabled = autoHideEnabled; } - - /** - * @brief Query scroll bar auto hide state - * - * @return True if scroll bar auto hide is enabled, false otherwise. - */ - bool isAutoHideEnabled() const { return _autoHideEnabled; } - - /** - * @brief Set scroll bar auto hide time - * - * @param scroll bar auto hide time - */ - void setAutoHideTime(float autoHideTime) { _autoHideTime = autoHideTime; } - - /** - * @brief Get the scroll bar's auto hide time - * - * @return the scroll bar's auto hide time - */ - float getAutoHideTime() const { return _autoHideTime; } - - /** - * @brief This is called by parent ScrollView when the parent is scrolled. Don't call this directly. - * - * @param amount how much the inner container of ScrollView is out of boundary - */ + + /** + * @brief Set the margin between scroll bar and the parent ScrollView's border + * + * @param margin The margin between scroll bar and the parent ScrollView's border + */ + void setMargin(float margin) { _margin = margin; } + + /** + * @brief Get the margin between scroll bar and the parent ScrollView's border + * + * @return margin + */ + float getMargin() const { return _margin; } + + /** + * @brief Set the scroll bar's width + * + * @param width The scroll bar's width + */ + void setWidth(float width); + + /** + * @brief Get the scroll bar's width + * + * @return the scroll bar's width + */ + float getWidth() const; + + /** + * @brief Set scroll bar auto hide state + * + * @param scroll bar auto hide state + */ + void setAutoHideEnabled(bool autoHideEnabled); + + /** + * @brief Query scroll bar auto hide state + * + * @return True if scroll bar auto hide is enabled, false otherwise. + */ + bool isAutoHideEnabled() const { return _autoHideEnabled; } + + /** + * @brief Set scroll bar auto hide time + * + * @param scroll bar auto hide time + */ + void setAutoHideTime(float autoHideTime) { _autoHideTime = autoHideTime; } + + /** + * @brief Get the scroll bar's auto hide time + * + * @return the scroll bar's auto hide time + */ + float getAutoHideTime() const { return _autoHideTime; } + + /** + * @brief This is called by parent ScrollView when the parent is scrolled. Don't call this directly. + * + * @param amount how much the inner container of ScrollView is out of boundary + */ virtual void onScrolled(const Vec2& outOfBoundary); - - /** - * @lua NA - */ + + /** + * @lua NA + */ virtual void onEnter() override; virtual void update(float deltaTime) override; - /** - * @brief This is called by parent ScrollView when a touch is began. Don't call this directly. - */ + /** + * @brief This is called by parent ScrollView when a touch is began. Don't call this directly. + */ void onTouchBegan(); - - /** - * @brief This is called by parent ScrollView when a touch is ended. Don't call this directly. - */ + + /** + * @brief This is called by parent ScrollView when a touch is ended. Don't call this directly. + */ void onTouchEnded(); CC_CONSTRUCTOR_ACCESS: @@ -162,9 +162,9 @@ private: bool _touching; bool _autoHideEnabled; - float _autoHideTime; + float _autoHideTime; float _autoHideRemainingTime; - + }; } From f667b085b8b2de7dbfccc7cc9d471df71a483f2e Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Fri, 3 Jul 2015 23:51:17 +0900 Subject: [PATCH 14/43] Change not to show scroll bar when the scroll view is initiated. --- cocos/ui/UIScrollView.cpp | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 113a3a1da2..30908accf5 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -149,7 +149,7 @@ void ScrollView::onSizeChanged() float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width); float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height); _innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight)); - moveChildrenToPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height)); + _innerContainer->setPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height)); } void ScrollView::setInnerContainerSize(const Size &size) @@ -175,20 +175,6 @@ void ScrollView::setInnerContainerSize(const Size &size) } _innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight)); - // Scroll children appropriately - { - float offsetX = originalInnerSize.height - innerSizeHeight; - float offsetY = 0; - if (_innerContainer->getRightBoundary() <= _contentSize.width) - { - offsetX = originalInnerSize.width - innerSizeWidth; - } - if(offsetX != 0 || offsetY != 0) - { - scrollChildren(offsetX, offsetY); - } - } - // Calculate and set the position of the inner container. Vec2 pos = _innerContainer->getPosition(); if (_innerContainer->getLeftBoundary() > 0.0f) @@ -207,7 +193,7 @@ void ScrollView::setInnerContainerSize(const Size &size) { pos.y = _contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getContentSize().height; } - moveChildrenToPosition(pos); + _innerContainer->setPosition(pos); } const Size& ScrollView::getInnerContainerSize() const From 0bcdf898bfb46eb46fbd5a9a2f67b4fb3ea77a56 Mon Sep 17 00:00:00 2001 From: Bin Zhang Date: Sat, 4 Jul 2015 10:17:40 +0800 Subject: [PATCH 15/43] Solve the error in simulator. --- .../runtime-src/Classes/js_module_register.h | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h b/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h index 1eb7d05e35..243552a155 100644 --- a/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h +++ b/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h @@ -27,12 +27,12 @@ #include "jsb_cocos2dx_navmesh_auto.hpp" #include "navmesh/jsb_cocos2dx_navmesh_manual.h" -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#include "experimental/jsb_cocos2dx_experimental_video_auto.hpp" -#include "experimental/jsb_cocos2dx_experimental_video_manual.h" -#include "experimental/jsb_cocos2dx_experimental_webView_auto.hpp" -#include "experimental/jsb_cocos2dx_experimental_webView_manual.h" -#endif +// #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) +// #include "experimental/jsb_cocos2dx_experimental_video_auto.hpp" +// #include "experimental/jsb_cocos2dx_experimental_video_manual.h" +// #include "experimental/jsb_cocos2dx_experimental_webView_auto.hpp" +// #include "experimental/jsb_cocos2dx_experimental_webView_manual.h" +// #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "platform/android/CCJavascriptJavaBridge.h" @@ -98,12 +98,12 @@ int js_module_register() sc->addRegisterCallback(register_all_cocos2dx_navmesh_manual); #endif -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - sc->addRegisterCallback(register_all_cocos2dx_experimental_video); - sc->addRegisterCallback(register_all_cocos2dx_experimental_video_manual); - sc->addRegisterCallback(register_all_cocos2dx_experimental_webView); - sc->addRegisterCallback(register_all_cocos2dx_experimental_webView_manual); -#endif +// #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) +// sc->addRegisterCallback(register_all_cocos2dx_experimental_video); +// sc->addRegisterCallback(register_all_cocos2dx_experimental_video_manual); +// sc->addRegisterCallback(register_all_cocos2dx_experimental_webView); +// sc->addRegisterCallback(register_all_cocos2dx_experimental_webView_manual); +// #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) sc->addRegisterCallback(JavascriptJavaBridge::_js_register); From ceeca575f3e05721b4b5252af64199ab141c597c Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Sat, 4 Jul 2015 00:11:01 +0900 Subject: [PATCH 16/43] Replace 'margin' of scroll bar with 'positionFromCorner' --- cocos/ui/UIScrollView.cpp | 58 ++- cocos/ui/UIScrollView.h | 33 +- cocos/ui/UIScrollViewBar.cpp | 339 +++++++++--------- cocos/ui/UIScrollViewBar.h | 14 +- .../UIScrollViewTest/UIScrollViewTest.cpp | 19 +- 5 files changed, 256 insertions(+), 207 deletions(-) diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 30908accf5..1c55d22ffd 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -149,7 +149,7 @@ void ScrollView::onSizeChanged() float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width); float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height); _innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight)); - _innerContainer->setPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height)); + _innerContainer->setPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height)); } void ScrollView::setInnerContainerSize(const Size &size) @@ -193,7 +193,7 @@ void ScrollView::setInnerContainerSize(const Size &size) { pos.y = _contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getContentSize().height; } - _innerContainer->setPosition(pos); + _innerContainer->setPosition(pos); } const Size& ScrollView::getInnerContainerSize() const @@ -1045,31 +1045,44 @@ bool ScrollView::isScrollBarEnabled() const return _scrollBarEnabled; } -void ScrollView::setScrollBarMargin(float margin) +void ScrollView::setScrollBarPositionFromCorner(const Vec2& positionFromCorner) { - CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) + if(_direction != Direction::HORIZONTAL) { - _verticalScrollBar->setMargin(margin); + setScrollBarPositionFromCornerForVertical(positionFromCorner); } - if(_horizontalScrollBar != nullptr) + if(_direction != Direction::VERTICAL) { - _horizontalScrollBar->setMargin(margin); + setScrollBarPositionFromCornerForHorizontal(positionFromCorner); } } -float ScrollView::getScrollBarMargin() const +void ScrollView::setScrollBarPositionFromCornerForVertical(const Vec2& positionFromCorner) { CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); - if(_verticalScrollBar != nullptr) - { - return _verticalScrollBar->getMargin(); - } - else if(_horizontalScrollBar != nullptr) - { - return _horizontalScrollBar->getMargin(); - } - return 0; + CCASSERT(_direction != Direction::HORIZONTAL, "Scroll view doesn't have a vertical scroll bar!"); + _verticalScrollBar->setPositionFromCorner(positionFromCorner); +} + +const Vec2& ScrollView::getScrollBarPositionFromCornerForVertical() const +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + CCASSERT(_direction != Direction::HORIZONTAL, "Scroll view doesn't have a vertical scroll bar!"); + return _verticalScrollBar->getPositionFromCorner(); +} + +void ScrollView::setScrollBarPositionFromCornerForHorizontal(const Vec2& positionFromCorner) +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + CCASSERT(_direction != Direction::VERTICAL, "Scroll view doesn't have a horizontal scroll bar!"); + _horizontalScrollBar->setPositionFromCorner(positionFromCorner); +} + +const Vec2& ScrollView::getScrollBarPositionFromCornerForHorizontal() const +{ + CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); + CCASSERT(_direction != Direction::VERTICAL, "Scroll view doesn't have a horizontal scroll bar!"); + return _horizontalScrollBar->getPositionFromCorner(); } void ScrollView::setScrollBarWidth(float width) @@ -1258,7 +1271,14 @@ void ScrollView::copySpecialProperties(Widget *widget) setScrollBarEnabled(scrollView->isScrollBarEnabled()); if(isScrollBarEnabled()) { - setScrollBarMargin(scrollView->getScrollBarMargin()); + if(_direction != Direction::HORIZONTAL) + { + setScrollBarPositionFromCornerForVertical(scrollView->getScrollBarPositionFromCornerForVertical()); + } + if(_direction != Direction::VERTICAL) + { + setScrollBarPositionFromCornerForHorizontal(scrollView->getScrollBarPositionFromCornerForHorizontal()); + } setScrollBarWidth(scrollView->getScrollBarWidth()); setScrollBarColor(scrollView->getScrollBarColor()); setScrollBarAutoHideEnabled(scrollView->isScrollBarAutoHideEnabled()); diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h index 4a37623a4d..5f058cc638 100644 --- a/cocos/ui/UIScrollView.h +++ b/cocos/ui/UIScrollView.h @@ -387,18 +387,39 @@ public: bool isScrollBarEnabled() const; /** - * @brief Set the margin between scroll bar and the container's border + * @brief Set the scroll bar positions from the left-bottom corner (horizontal) and right-top corner (vertical). * - * @param margin The margin between scroll bar and the container's border + * @param positionFromCorner The position from the left-bottom corner (horizontal) and right-top corner (vertical). */ - void setScrollBarMargin(float margin); + void setScrollBarPositionFromCorner(const Vec2& positionFromCorner); /** - * @brief Get the margin between scroll bar and the container's border + * @brief Set the vertical scroll bar position from right-top corner. * - * @return margin + * @param positionFromCorner The position from right-top corner */ - float getScrollBarMargin() const; + void setScrollBarPositionFromCornerForVertical(const Vec2& positionFromCorner); + + /** + * @brief Get the vertical scroll bar's position from right-top corner. + * + * @return positionFromCorner + */ + const Vec2& getScrollBarPositionFromCornerForVertical() const; + + /** + * @brief Set the horizontal scroll bar position from left-bottom corner. + * + * @param positionFromCorner The position from left-bottom corner + */ + void setScrollBarPositionFromCornerForHorizontal(const Vec2& positionFromCorner); + + /** + * @brief Get the horizontal scroll bar's position from right-top corner. + * + * @return positionFromCorner + */ + const Vec2& getScrollBarPositionFromCornerForHorizontal() const; /** * @brief Set the scroll bar's width diff --git a/cocos/ui/UIScrollViewBar.cpp b/cocos/ui/UIScrollViewBar.cpp index 3d08f59c34..a22cc4808d 100644 --- a/cocos/ui/UIScrollViewBar.cpp +++ b/cocos/ui/UIScrollViewBar.cpp @@ -35,43 +35,44 @@ static const char* HALF_CIRCLE_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAGCAMAAADA static const char* BODY_IMAGE_1_PIXEL_HEIGHT = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAABCAMAAADdNb8LAAAAA1BMVEX///+nxBvIAAAAAXRSTlNm5DccCwAAAApJREFUeAFjQAYAAA0AAWHNnKQAAAAASUVORK5CYII="; static const Color3B DEFAULT_COLOR(52, 65, 87); -static const float DEFAULT_MARGIN = 30; +static const float DEFAULT_MARGIN = 20; static const float DEFAULT_AUTO_HIDE_TIME = 0.2f; static Sprite* createSpriteFromBase64(const char* base64String) { - unsigned char* decoded; - int length = base64Decode((const unsigned char*) base64String, (unsigned int) strlen(base64String), &decoded); - - Image *image = new Image(); - bool imageResult = image->initWithImageData(decoded, length); - CCASSERT(imageResult, "Failed to create image from base64!"); - free(decoded); - - Texture2D *pTexture = new Texture2D(); - pTexture->initWithImage(image); - pTexture->setAliasTexParameters(); - image->release(); - - return Sprite::createWithTexture(pTexture); + unsigned char* decoded; + int length = base64Decode((const unsigned char*) base64String, (unsigned int) strlen(base64String), &decoded); + + Image *image = new Image(); + bool imageResult = image->initWithImageData(decoded, length); + CCASSERT(imageResult, "Failed to create image from base64!"); + free(decoded); + + Texture2D *pTexture = new Texture2D(); + pTexture->initWithImage(image); + pTexture->setAliasTexParameters(); + image->release(); + + return Sprite::createWithTexture(pTexture); } - + ScrollViewBar::ScrollViewBar(ScrollView* parent, ScrollView::Direction direction): _parent(parent), _direction(direction), _upperHalfCircle(nullptr), _lowerHalfCircle(nullptr), _body(nullptr), -_margin(DEFAULT_MARGIN), _touching(false), _autoHideEnabled(true), _autoHideTime(DEFAULT_AUTO_HIDE_TIME), _autoHideRemainingTime(0) { - CCASSERT(parent != nullptr, "Parent scroll view must not be null!"); - CCASSERT(direction != ScrollView::Direction::BOTH, "Illegal scroll direction for scroll bar!"); - setCascadeColorEnabled(true); - setCascadeOpacityEnabled(true); + CCASSERT(parent != nullptr, "Parent scroll view must not be null!"); + CCASSERT(direction != ScrollView::Direction::BOTH, "Illegal scroll direction for scroll bar!"); + setCascadeColorEnabled(true); + setCascadeOpacityEnabled(true); + + _positionFromCorner = Vec2(DEFAULT_MARGIN, DEFAULT_MARGIN); } ScrollViewBar::~ScrollViewBar() @@ -80,201 +81,203 @@ ScrollViewBar::~ScrollViewBar() ScrollViewBar* ScrollViewBar::create(ScrollView* parent, ScrollView::Direction direction) { - ScrollViewBar* node = new (std::nothrow) ScrollViewBar(parent, direction); - if (node && node->init()) - { - node->autorelease(); - return node; - } - CC_SAFE_DELETE(node); - return nullptr; + ScrollViewBar* node = new (std::nothrow) ScrollViewBar(parent, direction); + if (node && node->init()) + { + node->autorelease(); + return node; + } + CC_SAFE_DELETE(node); + return nullptr; } bool ScrollViewBar::init() { - if (!ProtectedNode::init()) - { - return false; - } - - _upperHalfCircle = createSpriteFromBase64(HALF_CIRCLE_IMAGE); - _upperHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - addChild(_upperHalfCircle); - - _lowerHalfCircle = Sprite::createWithTexture(_upperHalfCircle->getTexture(), _upperHalfCircle->getTextureRect(), _upperHalfCircle->isTextureRectRotated()); - _lowerHalfCircle->setScaleY(-1); - _lowerHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - addChild(_lowerHalfCircle); - - _body = createSpriteFromBase64(BODY_IMAGE_1_PIXEL_HEIGHT); - _body->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); - addChild(_body); - - setColor(DEFAULT_COLOR); - - if(_direction == ScrollView::Direction::HORIZONTAL) - { - setRotation(90); - } - - if(_autoHideEnabled) - { - setOpacity(0); - } - return true; + if (!ProtectedNode::init()) + { + return false; + } + + _upperHalfCircle = createSpriteFromBase64(HALF_CIRCLE_IMAGE); + _upperHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); + addChild(_upperHalfCircle); + + _lowerHalfCircle = Sprite::createWithTexture(_upperHalfCircle->getTexture(), _upperHalfCircle->getTextureRect(), _upperHalfCircle->isTextureRectRotated()); + _lowerHalfCircle->setScaleY(-1); + _lowerHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); + addChild(_lowerHalfCircle); + + _body = createSpriteFromBase64(BODY_IMAGE_1_PIXEL_HEIGHT); + _body->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); + addChild(_body); + + setColor(DEFAULT_COLOR); + + if(_direction == ScrollView::Direction::HORIZONTAL) + { + setRotation(90); + } + + if(_autoHideEnabled) + { + setOpacity(0); + } + return true; } void ScrollViewBar::setWidth(float width) { - float scale = width / _body->getContentSize().width; - _body->setScaleX(scale); - _upperHalfCircle->setScale(scale); - _lowerHalfCircle->setScale(-scale); + float scale = width / _body->getContentSize().width; + _body->setScaleX(scale); + _upperHalfCircle->setScale(scale); + _lowerHalfCircle->setScale(-scale); } void ScrollViewBar::setAutoHideEnabled(bool autoHideEnabled) { - _autoHideEnabled = autoHideEnabled; - setOpacity(255); + _autoHideEnabled = autoHideEnabled; + setOpacity(255); } float ScrollViewBar::getWidth() const { - return _body->getBoundingBox().size.width; + return _body->getBoundingBox().size.width; } void ScrollViewBar::setLength(float length) { - float ratio = length / _body->getTextureRect().size.height; - _body->setScaleY(ratio); - _upperHalfCircle->setPositionY(_body->getPositionY() + length); + float ratio = length / _body->getTextureRect().size.height; + _body->setScaleY(ratio); + _upperHalfCircle->setPositionY(_body->getPositionY() + length); } void ScrollViewBar::onEnter() { - ProtectedNode::onEnter(); - scheduleUpdate(); + ProtectedNode::onEnter(); + scheduleUpdate(); } void ScrollViewBar::update(float deltaTime) { - if(!_autoHideEnabled || _autoHideRemainingTime <= 0) - { - return; - } - else if(_touching) - { - // If it is touching, don't auto hide. - return; - } - - _autoHideRemainingTime -= deltaTime; - if(_autoHideRemainingTime <= _autoHideTime) - { - _autoHideRemainingTime = MAX(0, _autoHideRemainingTime); - this->setOpacity(255 * (_autoHideRemainingTime / _autoHideTime)); - } + if(!_autoHideEnabled || _autoHideRemainingTime <= 0) + { + return; + } + else if(_touching) + { + // If it is touching, don't auto hide. + return; + } + + _autoHideRemainingTime -= deltaTime; + if(_autoHideRemainingTime <= _autoHideTime) + { + _autoHideRemainingTime = MAX(0, _autoHideRemainingTime); + this->setOpacity(255 * (_autoHideRemainingTime / _autoHideTime)); + } } void ScrollViewBar::onTouchBegan() { - if(!_autoHideEnabled) - { - return; - } - _touching = true; + if(!_autoHideEnabled) + { + return; + } + _touching = true; } void ScrollViewBar::onTouchEnded() { - if(!_autoHideEnabled) - { - return; - } - _touching = false; - - if(_autoHideRemainingTime <= 0) - { - // If the remaining time is 0, it means that it didn't moved after touch started so scroll bar is not showing. - return; - } - _autoHideRemainingTime = _autoHideTime; + if(!_autoHideEnabled) + { + return; + } + _touching = false; + + if(_autoHideRemainingTime <= 0) + { + // If the remaining time is 0, it means that it didn't moved after touch started so scroll bar is not showing. + return; + } + _autoHideRemainingTime = _autoHideTime; } void ScrollViewBar::onScrolled(const Vec2& outOfBoundary) { - if(_autoHideEnabled) - { - _autoHideRemainingTime = _autoHideTime; - setOpacity(255); - } - - Layout* innerContainer = _parent->getInnerContainer(); - - float innerContainerMeasure = 0; - float scrollViewMeasure = 0; - float outOfBoundaryValue = 0; - float innerContainerPosition = 0; - if(_direction == ScrollView::Direction::VERTICAL) - { - innerContainerMeasure = innerContainer->getContentSize().height; - scrollViewMeasure = _parent->getContentSize().height; - outOfBoundaryValue = outOfBoundary.y; - innerContainerPosition = -innerContainer->getPositionY(); - } - else if(_direction == ScrollView::Direction::HORIZONTAL) - { - innerContainerMeasure = innerContainer->getContentSize().width; - scrollViewMeasure = _parent->getContentSize().width; - outOfBoundaryValue = outOfBoundary.x; - innerContainerPosition = -innerContainer->getPositionX(); - } - - float length = updateLength(innerContainerMeasure, scrollViewMeasure, outOfBoundaryValue); - updatePosition(innerContainerMeasure, scrollViewMeasure, innerContainerPosition, outOfBoundaryValue, length); + if(_autoHideEnabled) + { + _autoHideRemainingTime = _autoHideTime; + setOpacity(255); + } + + Layout* innerContainer = _parent->getInnerContainer(); + + float innerContainerMeasure = 0; + float scrollViewMeasure = 0; + float outOfBoundaryValue = 0; + float innerContainerPosition = 0; + if(_direction == ScrollView::Direction::VERTICAL) + { + innerContainerMeasure = innerContainer->getContentSize().height; + scrollViewMeasure = _parent->getContentSize().height; + outOfBoundaryValue = outOfBoundary.y; + innerContainerPosition = -innerContainer->getPositionY(); + } + else if(_direction == ScrollView::Direction::HORIZONTAL) + { + innerContainerMeasure = innerContainer->getContentSize().width; + scrollViewMeasure = _parent->getContentSize().width; + outOfBoundaryValue = outOfBoundary.x; + innerContainerPosition = -innerContainer->getPositionX(); + } + + float length = updateLength(innerContainerMeasure, scrollViewMeasure, outOfBoundaryValue); + updatePosition(innerContainerMeasure, scrollViewMeasure, innerContainerPosition, outOfBoundaryValue, length); } float ScrollViewBar::updateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue) { - float denominatorValue = innerContainerMeasure; - if(outOfBoundaryValue != 0) - { - // If it is out of boundary, the length of scroll bar gets shorter quickly. - static const float GETTING_SHORTER_FACTOR = 20; - denominatorValue += (outOfBoundaryValue > 0 ? outOfBoundaryValue : -outOfBoundaryValue) * GETTING_SHORTER_FACTOR; - } - - float lengthRatio = scrollViewMeasure / denominatorValue; - float length = (scrollViewMeasure - 2 * _margin) * lengthRatio; - setLength(length); - return length; + float denominatorValue = innerContainerMeasure; + if(outOfBoundaryValue != 0) + { + // If it is out of boundary, the length of scroll bar gets shorter quickly. + static const float GETTING_SHORTER_FACTOR = 20; + denominatorValue += (outOfBoundaryValue > 0 ? outOfBoundaryValue : -outOfBoundaryValue) * GETTING_SHORTER_FACTOR; + } + + float lengthRatio = scrollViewMeasure / denominatorValue; + float marginForLength = (_direction == ScrollView::Direction::HORIZONTAL ? _positionFromCorner.x : _positionFromCorner.y); + float length = fabsf(scrollViewMeasure - 2 * marginForLength) * lengthRatio; + setLength(length); + return length; } void ScrollViewBar::updatePosition(float innerContainerMeasure, float scrollViewMeasure, float innerContainerPosition, float outOfBoundaryValue, float length) { - float denominatorValue = innerContainerMeasure - scrollViewMeasure; - if(outOfBoundaryValue != 0) - { - denominatorValue += outOfBoundaryValue * (outOfBoundaryValue < 0 ? -1 : 1); - } - - float positionRatio = 0; - if(denominatorValue != 0) - { - positionRatio = innerContainerPosition / denominatorValue; - positionRatio = MAX(positionRatio, 0); - positionRatio = MIN(positionRatio, 1); - } - float position = (scrollViewMeasure - length - 2 * _margin) * positionRatio + _margin; - - if(_direction == ScrollView::Direction::VERTICAL) - { - setPosition(_parent->getContentSize().width - _margin, position); - } - else if(_direction == ScrollView::Direction::HORIZONTAL) - { - setPosition(position, _margin); - } + float denominatorValue = innerContainerMeasure - scrollViewMeasure; + if(outOfBoundaryValue != 0) + { + denominatorValue += fabs(outOfBoundaryValue); + } + + float positionRatio = 0; + if(denominatorValue != 0) + { + positionRatio = innerContainerPosition / denominatorValue; + positionRatio = MAX(positionRatio, 0); + positionRatio = MIN(positionRatio, 1); + } + float marginForLength = (_direction == ScrollView::Direction::HORIZONTAL ? _positionFromCorner.x : _positionFromCorner.y); + float marginFromBoundary = (_direction == ScrollView::Direction::HORIZONTAL ? _positionFromCorner.y : _positionFromCorner.x); + float position = (scrollViewMeasure - length - 2 * marginForLength) * positionRatio + marginForLength; + if(_direction == ScrollView::Direction::VERTICAL) + { + setPosition(_parent->getContentSize().width - marginFromBoundary, position); + } + else if(_direction == ScrollView::Direction::HORIZONTAL) + { + setPosition(position, marginFromBoundary); + } } } diff --git a/cocos/ui/UIScrollViewBar.h b/cocos/ui/UIScrollViewBar.h index e773354a2f..589f9d7a83 100644 --- a/cocos/ui/UIScrollViewBar.h +++ b/cocos/ui/UIScrollViewBar.h @@ -65,18 +65,18 @@ public: static ScrollViewBar* create(ScrollView* parent, ScrollView::Direction direction); /** - * @brief Set the margin between scroll bar and the parent ScrollView's border + * @brief Set the scroll bar position from the left-bottom corner (horizontal) or right-top corner (vertical). * - * @param margin The margin between scroll bar and the parent ScrollView's border + * @param positionFromCorner The position from the left-bottom corner (horizontal) or right-top corner (vertical). */ - void setMargin(float margin) { _margin = margin; } + void setPositionFromCorner(const Vec2& positionFromCorner) { _positionFromCorner = positionFromCorner; } /** - * @brief Get the margin between scroll bar and the parent ScrollView's border + * @brief Get the scroll bar position from the left-bottom corner (horizontal) or right-top corner (vertical). * - * @return margin + * @return positionFromCorner */ - float getMargin() const { return _margin; } + const Vec2& getPositionFromCorner() const { return _positionFromCorner; } /** * @brief Set the scroll bar's width @@ -157,7 +157,7 @@ private: Sprite* _upperHalfCircle; Sprite* _lowerHalfCircle; Sprite* _body; - float _margin; + Vec2 _positionFromCorner; bool _touching; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 0fe4acd812..5cbf101e92 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -56,7 +56,7 @@ bool UIScrollViewTest_Vertical::init() (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - scrollView->getContentSize().height) / 2.0f)); scrollView->setScrollBarWidth(4); - scrollView->setScrollBarMargin(2); + scrollView->setScrollBarPositionFromCorner(Vec2(2, 2)); scrollView->setScrollBarColor(Color3B::WHITE); _uiLayer->addChild(scrollView); @@ -130,7 +130,7 @@ bool UIScrollViewTest_Horizontal::init() scrollView->setDirection(ui::ScrollView::Direction::HORIZONTAL); scrollView->setContentSize(Size(280.0f, 150.0f)); scrollView->setInnerContainerSize(scrollView->getContentSize()); - scrollView->setScrollBarMargin(4); + scrollView->setScrollBarPositionFromCorner(Vec2(4, 4)); scrollView->setScrollBarColor(Color3B::YELLOW); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + @@ -216,7 +216,7 @@ bool UIScrollViewTest_Both::init() scrollView->setBackGroundImage("cocosui/green_edit.png"); scrollView->setContentSize(Size(210, 122.5)); scrollView->setScrollBarWidth(4); - scrollView->setScrollBarMargin(6); + scrollView->setScrollBarPositionFromCorner(Vec2(6, 6)); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - scrollView->getContentSize().width) / 2.0f, @@ -333,7 +333,8 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init() sc->setDirection(ui::ScrollView::Direction::BOTH); sc->setInnerContainerSize(Size(480, 320)); sc->setContentSize(Size(100,100)); - sc->setScrollBarMargin(4); + sc->setScrollBarPositionFromCornerForHorizontal(Vec2(5, sc->getContentSize().height - 5)); + sc->setScrollBarPositionFromCornerForVertical(Vec2(sc->getContentSize().width - 5, 5)); sc->setScrollBarAutoHideEnabled(false); Size backgroundSize = background->getContentSize(); sc->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + @@ -389,7 +390,7 @@ bool UIScrollViewNestTest::init() ui::ScrollView* scrollView = ui::ScrollView::create(); scrollView->setContentSize(Size(280.0f, 150.0f)); scrollView->setDirection(ui::ScrollView::Direction::VERTICAL); - scrollView->setScrollBarMargin(4); + scrollView->setScrollBarPositionFromCorner(Vec2(4, 4)); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - scrollView->getContentSize().width) / 2.0f, @@ -435,7 +436,7 @@ bool UIScrollViewNestTest::init() sc->setPropagateTouchEvents(false); sc->setPosition(Vec2(180,100)); sc->scrollToPercentBothDirection(Vec2(50, 50), 1, true); - sc->setScrollBarMargin(4); + sc->setScrollBarPositionFromCorner(Vec2(4, 4)); ImageView* iv = ImageView::create("cocosui/Hello.png"); iv->setPosition(Vec2(240, 160)); sc->addChild(iv); @@ -448,6 +449,10 @@ bool UIScrollViewNestTest::init() return false; } + + + + // UIScrollViewRotated UIScrollViewRotated::UIScrollViewRotated() @@ -492,7 +497,7 @@ bool UIScrollViewRotated::init() (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - scrollView->getContentSize().height) / 2.0f + 100) ); scrollView->setRotation(45); - scrollView->setScrollBarMargin(4); + scrollView->setScrollBarPositionFromCorner(Vec2(4, 4)); scrollView->setScrollBarColor(Color3B::WHITE); _uiLayer->addChild(scrollView); From 6264f7fefb3aff64cebbc6d5fdc121af1ed72a9b Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Sat, 4 Jul 2015 15:03:05 +0900 Subject: [PATCH 17/43] Correct include-related build errors in some platforms --- cocos/ui/UIScrollViewBar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/ui/UIScrollViewBar.cpp b/cocos/ui/UIScrollViewBar.cpp index a22cc4808d..3e696d11dd 100644 --- a/cocos/ui/UIScrollViewBar.cpp +++ b/cocos/ui/UIScrollViewBar.cpp @@ -25,7 +25,7 @@ THE SOFTWARE. #include "UIScrollViewBar.h" #include "CCImage.h" #include "2d/CCSprite.h" -#include "base64.h" +#include "base/base64.h" NS_CC_BEGIN From 3ab4285960afaf46f591289566bfeb99ee24fbda Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Sat, 4 Jul 2015 15:40:47 +0900 Subject: [PATCH 18/43] Refactor code --- cocos/ui/UIScrollView.cpp | 4 +- cocos/ui/UIScrollView.h | 4 +- cocos/ui/UIScrollViewBar.cpp | 57 +++++++++++++------ cocos/ui/UIScrollViewBar.h | 16 +++--- .../UIListViewTest/UIListViewTest.cpp | 3 +- .../UIScrollViewTest/UIScrollViewTest.cpp | 4 +- 6 files changed, 58 insertions(+), 30 deletions(-) diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 1c55d22ffd..5f6e8dfb64 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -1064,7 +1064,7 @@ void ScrollView::setScrollBarPositionFromCornerForVertical(const Vec2& positionF _verticalScrollBar->setPositionFromCorner(positionFromCorner); } -const Vec2& ScrollView::getScrollBarPositionFromCornerForVertical() const +Vec2 ScrollView::getScrollBarPositionFromCornerForVertical() const { CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); CCASSERT(_direction != Direction::HORIZONTAL, "Scroll view doesn't have a vertical scroll bar!"); @@ -1078,7 +1078,7 @@ void ScrollView::setScrollBarPositionFromCornerForHorizontal(const Vec2& positio _horizontalScrollBar->setPositionFromCorner(positionFromCorner); } -const Vec2& ScrollView::getScrollBarPositionFromCornerForHorizontal() const +Vec2 ScrollView::getScrollBarPositionFromCornerForHorizontal() const { CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!"); CCASSERT(_direction != Direction::VERTICAL, "Scroll view doesn't have a horizontal scroll bar!"); diff --git a/cocos/ui/UIScrollView.h b/cocos/ui/UIScrollView.h index 5f058cc638..18f318e3a9 100644 --- a/cocos/ui/UIScrollView.h +++ b/cocos/ui/UIScrollView.h @@ -405,7 +405,7 @@ public: * * @return positionFromCorner */ - const Vec2& getScrollBarPositionFromCornerForVertical() const; + Vec2 getScrollBarPositionFromCornerForVertical() const; /** * @brief Set the horizontal scroll bar position from left-bottom corner. @@ -419,7 +419,7 @@ public: * * @return positionFromCorner */ - const Vec2& getScrollBarPositionFromCornerForHorizontal() const; + Vec2 getScrollBarPositionFromCornerForHorizontal() const; /** * @brief Set the scroll bar's width diff --git a/cocos/ui/UIScrollViewBar.cpp b/cocos/ui/UIScrollViewBar.cpp index 3e696d11dd..8059e5e150 100644 --- a/cocos/ui/UIScrollViewBar.cpp +++ b/cocos/ui/UIScrollViewBar.cpp @@ -62,6 +62,8 @@ _direction(direction), _upperHalfCircle(nullptr), _lowerHalfCircle(nullptr), _body(nullptr), +_marginFromBoundary(DEFAULT_MARGIN), +_marginForLength(DEFAULT_MARGIN), _touching(false), _autoHideEnabled(true), _autoHideTime(DEFAULT_AUTO_HIDE_TIME), @@ -71,8 +73,6 @@ _autoHideRemainingTime(0) CCASSERT(direction != ScrollView::Direction::BOTH, "Illegal scroll direction for scroll bar!"); setCascadeColorEnabled(true); setCascadeOpacityEnabled(true); - - _positionFromCorner = Vec2(DEFAULT_MARGIN, DEFAULT_MARGIN); } ScrollViewBar::~ScrollViewBar() @@ -124,6 +124,32 @@ bool ScrollViewBar::init() } return true; } + +void ScrollViewBar::setPositionFromCorner(const Vec2& positionFromCorner) +{ + if(_direction == ScrollView::Direction::VERTICAL) + { + _marginForLength = positionFromCorner.y; + _marginFromBoundary = positionFromCorner.x; + } + else + { + _marginForLength = positionFromCorner.x; + _marginFromBoundary = positionFromCorner.y; + } +} + +Vec2 ScrollViewBar::getPositionFromCorner() const +{ + if(_direction == ScrollView::Direction::VERTICAL) + { + return Vec2(_marginFromBoundary, _marginForLength); + } + else + { + return Vec2(_marginForLength, _marginFromBoundary); + } +} void ScrollViewBar::setWidth(float width) { @@ -144,7 +170,7 @@ float ScrollViewBar::getWidth() const return _body->getBoundingBox().size.width; } -void ScrollViewBar::setLength(float length) +void ScrollViewBar::updateLength(float length) { float ratio = length / _body->getTextureRect().size.height; _body->setScaleY(ratio); @@ -231,11 +257,13 @@ void ScrollViewBar::onScrolled(const Vec2& outOfBoundary) innerContainerPosition = -innerContainer->getPositionX(); } - float length = updateLength(innerContainerMeasure, scrollViewMeasure, outOfBoundaryValue); - updatePosition(innerContainerMeasure, scrollViewMeasure, innerContainerPosition, outOfBoundaryValue, length); + float length = calculateLength(innerContainerMeasure, scrollViewMeasure, outOfBoundaryValue); + Vec2 position = calculatePosition(innerContainerMeasure, scrollViewMeasure, innerContainerPosition, outOfBoundaryValue, length); + updateLength(length); + setPosition(position); } -float ScrollViewBar::updateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue) +float ScrollViewBar::calculateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue) { float denominatorValue = innerContainerMeasure; if(outOfBoundaryValue != 0) @@ -246,13 +274,10 @@ float ScrollViewBar::updateLength(float innerContainerMeasure, float scrollViewM } float lengthRatio = scrollViewMeasure / denominatorValue; - float marginForLength = (_direction == ScrollView::Direction::HORIZONTAL ? _positionFromCorner.x : _positionFromCorner.y); - float length = fabsf(scrollViewMeasure - 2 * marginForLength) * lengthRatio; - setLength(length); - return length; + return fabsf(scrollViewMeasure - 2 * _marginForLength) * lengthRatio; } -void ScrollViewBar::updatePosition(float innerContainerMeasure, float scrollViewMeasure, float innerContainerPosition, float outOfBoundaryValue, float length) +Vec2 ScrollViewBar::calculatePosition(float innerContainerMeasure, float scrollViewMeasure, float innerContainerPosition, float outOfBoundaryValue, float length) { float denominatorValue = innerContainerMeasure - scrollViewMeasure; if(outOfBoundaryValue != 0) @@ -267,16 +292,14 @@ void ScrollViewBar::updatePosition(float innerContainerMeasure, float scrollView positionRatio = MAX(positionRatio, 0); positionRatio = MIN(positionRatio, 1); } - float marginForLength = (_direction == ScrollView::Direction::HORIZONTAL ? _positionFromCorner.x : _positionFromCorner.y); - float marginFromBoundary = (_direction == ScrollView::Direction::HORIZONTAL ? _positionFromCorner.y : _positionFromCorner.x); - float position = (scrollViewMeasure - length - 2 * marginForLength) * positionRatio + marginForLength; + float position = (scrollViewMeasure - length - 2 * _marginForLength) * positionRatio + _marginForLength; if(_direction == ScrollView::Direction::VERTICAL) { - setPosition(_parent->getContentSize().width - marginFromBoundary, position); + return Vec2(_parent->getContentSize().width - _marginFromBoundary, position); } - else if(_direction == ScrollView::Direction::HORIZONTAL) + else { - setPosition(position, marginFromBoundary); + return Vec2(position, _marginFromBoundary); } } } diff --git a/cocos/ui/UIScrollViewBar.h b/cocos/ui/UIScrollViewBar.h index 589f9d7a83..d023049606 100644 --- a/cocos/ui/UIScrollViewBar.h +++ b/cocos/ui/UIScrollViewBar.h @@ -69,14 +69,14 @@ public: * * @param positionFromCorner The position from the left-bottom corner (horizontal) or right-top corner (vertical). */ - void setPositionFromCorner(const Vec2& positionFromCorner) { _positionFromCorner = positionFromCorner; } + void setPositionFromCorner(const Vec2& positionFromCorner); /** * @brief Get the scroll bar position from the left-bottom corner (horizontal) or right-top corner (vertical). * * @return positionFromCorner */ - const Vec2& getPositionFromCorner() const { return _positionFromCorner; } + Vec2 getPositionFromCorner() const; /** * @brief Set the scroll bar's width @@ -147,18 +147,20 @@ CC_CONSTRUCTOR_ACCESS: virtual bool init() override; private: - float updateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue); - void updatePosition(float innerContainerMeasure, float scrollViewMeasure, float innerContainerPosition, float outOfBoundaryValue, float actualLength); + float calculateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue); + Vec2 calculatePosition(float innerContainerMeasure, float scrollViewMeasure, float innerContainerPosition, float outOfBoundaryValue, float actualLength); - void setLength(float length); + void updateLength(float length); ScrollView* _parent; ScrollView::Direction _direction; Sprite* _upperHalfCircle; Sprite* _lowerHalfCircle; Sprite* _body; - Vec2 _positionFromCorner; - +// Vec2 _positionFromCorner; + float _marginFromBoundary; + float _marginForLength; + bool _touching; bool _autoHideEnabled; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index b996707b03..534295b456 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -71,7 +71,7 @@ bool UIListViewTest_Vertical::init() (backgroundSize.height - listView->getContentSize().height) / 2.0f)); listView->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(UIListViewTest_Vertical::selectedItemEvent, this)); listView->addEventListener((ui::ListView::ccScrollViewCallback)CC_CALLBACK_2(UIListViewTest_Vertical::selectedItemEventScrollView,this)); - + listView->setScrollBarPositionFromCorner(Vec2(7, 7)); _uiLayer->addChild(listView); @@ -268,6 +268,7 @@ bool UIListViewTest_Horizontal::init() (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - listView->getContentSize().height) / 2.0f)); listView->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(UIListViewTest_Horizontal::selectedItemEvent, this)); + listView->setScrollBarPositionFromCorner(Vec2(7, 7)); _uiLayer->addChild(listView); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 5cbf101e92..ddc07e1c5e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -396,6 +396,8 @@ bool UIScrollViewNestTest::init() (backgroundSize.width - scrollView->getContentSize().width) / 2.0f, (widgetSize.height - backgroundSize.height) / 2.0f + (backgroundSize.height - scrollView->getContentSize().height) / 2.0f)); + scrollView->setScrollBarPositionFromCornerForVertical(Vec2(scrollView->getContentSize().width - 4, 4)); + scrollView->setScrollBarColor(Color3B::BLUE); _uiLayer->addChild(scrollView); ImageView* imageView = ImageView::create("cocosui/ccicon.png"); @@ -425,7 +427,7 @@ bool UIScrollViewNestTest::init() - // Create the scrollview by vertical + // Create the scrollview by both ui::ScrollView* sc = ui::ScrollView::create(); sc->setBackGroundColor(Color3B::GREEN); sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID); From a4803c6713a2570b0f53193731e1b9686caa0aaf Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Sun, 5 Jul 2015 21:30:13 +0900 Subject: [PATCH 19/43] Remove unnecessary commented out code. --- cocos/ui/UIScrollViewBar.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cocos/ui/UIScrollViewBar.h b/cocos/ui/UIScrollViewBar.h index d023049606..8503c6344d 100644 --- a/cocos/ui/UIScrollViewBar.h +++ b/cocos/ui/UIScrollViewBar.h @@ -154,10 +154,11 @@ private: ScrollView* _parent; ScrollView::Direction _direction; + Sprite* _upperHalfCircle; Sprite* _lowerHalfCircle; Sprite* _body; -// Vec2 _positionFromCorner; + float _marginFromBoundary; float _marginForLength; From 43308e258a6f87f76a10afae7649c5820f59af03 Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Mon, 6 Jul 2015 11:29:39 +0900 Subject: [PATCH 20/43] Fix an issue of not releasing Texture instance in ScrollViewBar --- cocos/ui/UIScrollViewBar.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cocos/ui/UIScrollViewBar.cpp b/cocos/ui/UIScrollViewBar.cpp index 8059e5e150..e005d93d6a 100644 --- a/cocos/ui/UIScrollViewBar.cpp +++ b/cocos/ui/UIScrollViewBar.cpp @@ -48,14 +48,17 @@ static Sprite* createSpriteFromBase64(const char* base64String) CCASSERT(imageResult, "Failed to create image from base64!"); free(decoded); - Texture2D *pTexture = new Texture2D(); - pTexture->initWithImage(image); - pTexture->setAliasTexParameters(); + Texture2D *texture = new Texture2D(); + texture->initWithImage(image); + texture->setAliasTexParameters(); image->release(); - return Sprite::createWithTexture(pTexture); -} + Sprite* sprite = Sprite::createWithTexture(texture); + texture->release(); + return sprite; +} + ScrollViewBar::ScrollViewBar(ScrollView* parent, ScrollView::Direction direction): _parent(parent), _direction(direction), From 0ff7aaef95397eb22a51faa8613be49564733038 Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Mon, 6 Jul 2015 11:30:24 +0900 Subject: [PATCH 21/43] Modify loop iteration codes --- cocos/ui/UIScrollView.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 5f6e8dfb64..78a2236117 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -424,10 +424,10 @@ void ScrollView::jumpToDestination(const Vec2 &des) void ScrollView::startInertiaScroll() { float totalDuration = 0; - for(auto i = _inertiaTouchTimeDeltas.begin(); i != _inertiaTouchTimeDeltas.end(); ++i) - { - totalDuration += (*i); - } + for(auto &timeDelta : _inertiaTouchTimeDeltas) + { + totalDuration += timeDelta; + } if(totalDuration == 0 || totalDuration >= 0.5f) { return; @@ -437,6 +437,11 @@ void ScrollView::startInertiaScroll() // Calcualte the initial velocity Vec2 totalMovement; + for(auto &displacement : _inertiaTouchDisplacements) + { + totalMovement += displacement; + } + for(auto i = _inertiaTouchDisplacements.begin(); i != _inertiaTouchDisplacements.end(); ++i) { totalMovement += (*i); From c4dc9b04fdc4d6a5a1a60996d7a069b5477ca796 Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Mon, 6 Jul 2015 12:56:49 +0900 Subject: [PATCH 22/43] Add a guard filtering tries to set same value. --- cocos/ui/UIScrollView.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index 78a2236117..f32cac06be 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -1034,6 +1034,11 @@ bool ScrollView::isInertiaScrollEnabled() const void ScrollView::setScrollBarEnabled(bool enabled) { + if(_scrollBarEnabled == enabled) + { + return; + } + if(_scrollBarEnabled) { removeScrollBar(); From 69a4a438bb695422db7fe22caea09924eab53f9d Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Mon, 6 Jul 2015 13:02:12 +0900 Subject: [PATCH 23/43] Change Xcode project configurations to use spaces instead of tab as indentation. --- build/cocos2d_libs.xcodeproj/project.pbxproj | 1 + build/cocos2d_tests.xcodeproj/project.pbxproj | 1 + 2 files changed, 2 insertions(+) diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index fa21588217..a906d0c3d2 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -5612,6 +5612,7 @@ 2905F9E618CF08D000240AA3 /* ui */, ); sourceTree = ""; + usesTabs = 0; }; 1551A340158F2AB200E66CFE /* Products */ = { isa = PBXGroup; diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index f1a8b18e4b..8b250e7b2f 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -4069,6 +4069,7 @@ ); name = CustomTemplate; sourceTree = ""; + usesTabs = 0; }; 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; From a01f31c75cbefae9ad2bbfea08791af104ead7aa Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Mon, 6 Jul 2015 15:34:32 +0900 Subject: [PATCH 24/43] Change NULL to nullptr --- cocos/base/ccUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/base/ccUtils.cpp b/cocos/base/ccUtils.cpp index 6ddb4451b6..f02c76d6b4 100644 --- a/cocos/base/ccUtils.cpp +++ b/cocos/base/ccUtils.cpp @@ -164,7 +164,7 @@ double gettime() long long getTimeInMilliseconds() { struct timeval tv; - gettimeofday (&tv, NULL); + gettimeofday (&tv, nullptr); return tv.tv_sec * 1000 + tv.tv_usec / 1000; } From a9f98aefea63deaadc6352f0284b0d2f979b6903 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 7 Jul 2015 09:38:38 +0800 Subject: [PATCH 25/43] [Simulator JSB] Fix issue caused by video and web view binding --- .../runtime-src/Classes/js_module_register.h | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h b/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h index 243552a155..6ebf98c53f 100644 --- a/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h +++ b/tools/simulator/frameworks/runtime-src/Classes/js_module_register.h @@ -27,12 +27,12 @@ #include "jsb_cocos2dx_navmesh_auto.hpp" #include "navmesh/jsb_cocos2dx_navmesh_manual.h" -// #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -// #include "experimental/jsb_cocos2dx_experimental_video_auto.hpp" -// #include "experimental/jsb_cocos2dx_experimental_video_manual.h" -// #include "experimental/jsb_cocos2dx_experimental_webView_auto.hpp" -// #include "experimental/jsb_cocos2dx_experimental_webView_manual.h" -// #endif +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) +#include "jsb_cocos2dx_experimental_video_auto.hpp" +#include "experimental/jsb_cocos2dx_experimental_video_manual.h" +#include "jsb_cocos2dx_experimental_webView_auto.hpp" +#include "experimental/jsb_cocos2dx_experimental_webView_manual.h" +#endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "platform/android/CCJavascriptJavaBridge.h" @@ -98,12 +98,12 @@ int js_module_register() sc->addRegisterCallback(register_all_cocos2dx_navmesh_manual); #endif -// #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -// sc->addRegisterCallback(register_all_cocos2dx_experimental_video); -// sc->addRegisterCallback(register_all_cocos2dx_experimental_video_manual); -// sc->addRegisterCallback(register_all_cocos2dx_experimental_webView); -// sc->addRegisterCallback(register_all_cocos2dx_experimental_webView_manual); -// #endif +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + sc->addRegisterCallback(register_all_cocos2dx_experimental_video); + sc->addRegisterCallback(register_all_cocos2dx_experimental_video_manual); + sc->addRegisterCallback(register_all_cocos2dx_experimental_webView); + sc->addRegisterCallback(register_all_cocos2dx_experimental_webView_manual); +#endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) sc->addRegisterCallback(JavascriptJavaBridge::_js_register); From b4559a005bc0cdd078565e98321c441fd2f4364e Mon Sep 17 00:00:00 2001 From: Vincent Yang Date: Tue, 7 Jul 2015 10:42:04 +0800 Subject: [PATCH 26/43] Fix bug taken from pr12602: scroll view can't scroll if pressed the button on it. --- cocos/ui/UIWidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index bbb63cff9f..54c16e0f16 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -783,7 +783,9 @@ void Widget::propagateTouchEvent(cocos2d::ui::Widget::TouchEventType event, coco Widget* widgetParent = getWidgetParent(); if (widgetParent) { + widgetParent->_hittedByCamera = _hittedByCamera; widgetParent->interceptTouchEvent(event, sender, touch); + widgetParent->_hittedByCamera = nullptr; } } @@ -974,7 +976,9 @@ void Widget::interceptTouchEvent(cocos2d::ui::Widget::TouchEventType event, coco Widget* widgetParent = getWidgetParent(); if (widgetParent) { + widgetParent->_hittedByCamera = _hittedByCamera; widgetParent->interceptTouchEvent(event,sender,touch); + widgetParent->_hittedByCamera = nullptr; } } From dd0edac171ba227e7f778e066d55b41944945534 Mon Sep 17 00:00:00 2001 From: VisualSj Date: Tue, 7 Jul 2015 13:36:47 +0800 Subject: [PATCH 27/43] Constant value error (ccui.Layout.BACKGROUND_IMAGE_ZORDER ) --- cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js b/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js index 6bc5ffa5d9..b17dcd24bc 100644 --- a/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js +++ b/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js @@ -48,7 +48,7 @@ ccui.Layout.RELATIVE = 3; ccui.Layout.CLIPPING_STENCIL = 0; ccui.Layout.CLIPPING_SCISSOR = 1; -ccui.Layout.BACKGROUND_IMAGE_ZORDER = -2; +ccui.Layout.BACKGROUND_IMAGE_ZORDER = -1; ccui.Layout.BACKGROUND_RENDERER_ZORDER = -2; /* From 4a486077c0fb9139d9571e109d1b9a85a4d12eca Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Tue, 7 Jul 2015 06:05:39 +0000 Subject: [PATCH 28/43] [ci skip][AUTO]: updating luabinding & jsbinding automatically --- .../auto/api/jsb_cocos2dx_ui_auto_api.js | 150 ++++ .../js-bindings/auto/jsb_cocos2dx_ui_auto.cpp | 301 +++++++ .../js-bindings/auto/jsb_cocos2dx_ui_auto.hpp | 15 + .../lua-bindings/auto/api/ScrollView.lua | 113 +++ .../auto/lua_cocos2dx_ui_auto.cpp | 744 ++++++++++++++++++ .../auto/lua_cocos2dx_ui_auto.hpp | 15 + 6 files changed, 1338 insertions(+) diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_ui_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_ui_auto_api.js index 51a63d203f..fd20a292f2 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_ui_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_ui_auto_api.js @@ -2683,6 +2683,16 @@ bool { }, +/** + * @method setScrollBarEnabled + * @param {bool} arg0 + */ +setScrollBarEnabled : function ( +bool +) +{ +}, + /** * @method isInertiaScrollEnabled * @return {bool} @@ -2717,6 +2727,16 @@ getDirection : function ( return 0; }, +/** + * @method setScrollBarColor + * @param {color3b_object} arg0 + */ +setScrollBarColor : function ( +color3b +) +{ +}, + /** * @method scrollToBottomLeft * @param {float} arg0 @@ -2825,6 +2845,26 @@ float { }, +/** + * @method setScrollBarAutoHideTime + * @param {float} arg0 + */ +setScrollBarAutoHideTime : function ( +float +) +{ +}, + +/** + * @method setScrollBarPositionFromCornerForHorizontal + * @param {vec2_object} arg0 + */ +setScrollBarPositionFromCornerForHorizontal : function ( +vec2 +) +{ +}, + /** * @method setInertiaScrollEnabled * @param {bool} arg0 @@ -2835,6 +2875,16 @@ bool { }, +/** + * @method getScrollBarColor + * @return {color3b_object} + */ +getScrollBarColor : function ( +) +{ + return cc.Color3B; +}, + /** * @method jumpToTopLeft */ @@ -2861,6 +2911,26 @@ jumpToBottomRight : function ( { }, +/** + * @method getScrollBarPositionFromCornerForHorizontal + * @return {vec2_object} + */ +getScrollBarPositionFromCornerForHorizontal : function ( +) +{ + return cc.Vec2; +}, + +/** + * @method setScrollBarWidth + * @param {float} arg0 + */ +setScrollBarWidth : function ( +float +) +{ +}, + /** * @method setBounceEnabled * @param {bool} arg0 @@ -2901,6 +2971,16 @@ vec2 { }, +/** + * @method getScrollBarPositionFromCornerForVertical + * @return {vec2_object} + */ +getScrollBarPositionFromCornerForVertical : function ( +) +{ + return cc.Vec2; +}, + /** * @method scrollToPercentVertical * @param {float} arg0 @@ -2927,6 +3007,16 @@ bool { }, +/** + * @method setScrollBarAutoHideEnabled + * @param {bool} arg0 + */ +setScrollBarAutoHideEnabled : function ( +bool +) +{ +}, + /** * @method scrollToBottomRight * @param {float} arg0 @@ -2939,6 +3029,36 @@ bool { }, +/** + * @method setScrollBarPositionFromCorner + * @param {vec2_object} arg0 + */ +setScrollBarPositionFromCorner : function ( +vec2 +) +{ +}, + +/** + * @method setScrollBarPositionFromCornerForVertical + * @param {vec2_object} arg0 + */ +setScrollBarPositionFromCornerForVertical : function ( +vec2 +) +{ +}, + +/** + * @method getScrollBarAutoHideTime + * @return {float} + */ +getScrollBarAutoHideTime : function ( +) +{ + return 0; +}, + /** * @method jumpToLeft */ @@ -2959,6 +3079,36 @@ bool { }, +/** + * @method isScrollBarEnabled + * @return {bool} + */ +isScrollBarEnabled : function ( +) +{ + return false; +}, + +/** + * @method getScrollBarWidth + * @return {float} + */ +getScrollBarWidth : function ( +) +{ + return 0; +}, + +/** + * @method isScrollBarAutoHideEnabled + * @return {bool} + */ +isScrollBarAutoHideEnabled : function ( +) +{ + return false; +}, + /** * @method jumpToRight */ diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_ui_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_ui_auto.cpp index e3576c3ec8..3440f30625 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_ui_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_ui_auto.cpp @@ -7284,6 +7284,26 @@ bool js_cocos2dx_ui_ScrollView_scrollToPercentHorizontal(JSContext *cx, uint32_t JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_scrollToPercentHorizontal : wrong number of arguments: %d, was expecting %d", argc, 3); return false; } +bool js_cocos2dx_ui_ScrollView_setScrollBarEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarEnabled : Error processing arguments"); + cobj->setScrollBarEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_setScrollBarEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_ui_ScrollView_isInertiaScrollEnabled(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -7344,6 +7364,26 @@ bool js_cocos2dx_ui_ScrollView_getDirection(JSContext *cx, uint32_t argc, jsval JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_getDirection : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_ui_ScrollView_setScrollBarColor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarColor : Invalid Native Object"); + if (argc == 1) { + cocos2d::Color3B arg0; + ok &= jsval_to_cccolor3b(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarColor : Error processing arguments"); + cobj->setScrollBarColor(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_setScrollBarColor : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_ui_ScrollView_scrollToBottomLeft(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -7557,6 +7597,46 @@ bool js_cocos2dx_ui_ScrollView_jumpToPercentVertical(JSContext *cx, uint32_t arg JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_jumpToPercentVertical : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime : Error processing arguments"); + cobj->setScrollBarAutoHideTime(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec2 arg0; + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal : Error processing arguments"); + cobj->setScrollBarPositionFromCornerForHorizontal(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_ui_ScrollView_setInertiaScrollEnabled(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -7577,6 +7657,24 @@ bool js_cocos2dx_ui_ScrollView_setInertiaScrollEnabled(JSContext *cx, uint32_t a JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_setInertiaScrollEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_ui_ScrollView_getScrollBarColor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_getScrollBarColor : Invalid Native Object"); + if (argc == 0) { + const cocos2d::Color3B& ret = cobj->getScrollBarColor(); + jsval jsret = JSVAL_NULL; + jsret = cccolor3b_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_getScrollBarColor : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_ui_ScrollView_jumpToTopLeft(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -7629,6 +7727,44 @@ bool js_cocos2dx_ui_ScrollView_jumpToBottomRight(JSContext *cx, uint32_t argc, j JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_jumpToBottomRight : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForHorizontal(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForHorizontal : Invalid Native Object"); + if (argc == 0) { + cocos2d::Vec2 ret = cobj->getScrollBarPositionFromCornerForHorizontal(); + jsval jsret = JSVAL_NULL; + jsret = vector2_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForHorizontal : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_ScrollView_setScrollBarWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarWidth : Invalid Native Object"); + if (argc == 1) { + double arg0; + ok &= JS::ToNumber( cx, args.get(0), &arg0) && !isnan(arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarWidth : Error processing arguments"); + cobj->setScrollBarWidth(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_setScrollBarWidth : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_ui_ScrollView_setBounceEnabled(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -7707,6 +7843,24 @@ bool js_cocos2dx_ui_ScrollView_jumpToPercentBothDirection(JSContext *cx, uint32_ JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_jumpToPercentBothDirection : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForVertical(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForVertical : Invalid Native Object"); + if (argc == 0) { + cocos2d::Vec2 ret = cobj->getScrollBarPositionFromCornerForVertical(); + jsval jsret = JSVAL_NULL; + jsret = vector2_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForVertical : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_ui_ScrollView_scrollToPercentVertical(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -7753,6 +7907,26 @@ bool js_cocos2dx_ui_ScrollView_scrollToBottom(JSContext *cx, uint32_t argc, jsva JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_scrollToBottom : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } +bool js_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled : Invalid Native Object"); + if (argc == 1) { + bool arg0; + arg0 = JS::ToBoolean(args.get(0)); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled : Error processing arguments"); + cobj->setScrollBarAutoHideEnabled(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_ui_ScrollView_scrollToBottomRight(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -7775,6 +7949,64 @@ bool js_cocos2dx_ui_ScrollView_scrollToBottomRight(JSContext *cx, uint32_t argc, JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_scrollToBottomRight : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } +bool js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec2 arg0; + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner : Error processing arguments"); + cobj->setScrollBarPositionFromCorner(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical : Invalid Native Object"); + if (argc == 1) { + cocos2d::Vec2 arg0; + ok &= jsval_to_vector2(cx, args.get(0), &arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical : Error processing arguments"); + cobj->setScrollBarPositionFromCornerForVertical(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_cocos2dx_ui_ScrollView_getScrollBarAutoHideTime(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_getScrollBarAutoHideTime : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getScrollBarAutoHideTime(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_getScrollBarAutoHideTime : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_ui_ScrollView_jumpToLeft(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -7813,6 +8045,60 @@ bool js_cocos2dx_ui_ScrollView_scrollToRight(JSContext *cx, uint32_t argc, jsval JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_scrollToRight : wrong number of arguments: %d, was expecting %d", argc, 2); return false; } +bool js_cocos2dx_ui_ScrollView_isScrollBarEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_isScrollBarEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isScrollBarEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_isScrollBarEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_ScrollView_getScrollBarWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_getScrollBarWidth : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getScrollBarWidth(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_getScrollBarWidth : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_cocos2dx_ui_ScrollView_isScrollBarAutoHideEnabled(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::ui::ScrollView* cobj = (cocos2d::ui::ScrollView *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ui_ScrollView_isScrollBarAutoHideEnabled : Invalid Native Object"); + if (argc == 0) { + bool ret = cobj->isScrollBarAutoHideEnabled(); + jsval jsret = JSVAL_NULL; + jsret = BOOLEAN_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_ui_ScrollView_isScrollBarAutoHideEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_ui_ScrollView_jumpToRight(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -7966,9 +8252,11 @@ void js_register_cocos2dx_ui_ScrollView(JSContext *cx, JS::HandleObject global) static JSFunctionSpec funcs[] = { JS_FN("scrollToTop", js_cocos2dx_ui_ScrollView_scrollToTop, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("scrollToPercentHorizontal", js_cocos2dx_ui_ScrollView_scrollToPercentHorizontal, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setScrollBarEnabled", js_cocos2dx_ui_ScrollView_setScrollBarEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isInertiaScrollEnabled", js_cocos2dx_ui_ScrollView_isInertiaScrollEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("scrollToPercentBothDirection", js_cocos2dx_ui_ScrollView_scrollToPercentBothDirection, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getDirection", js_cocos2dx_ui_ScrollView_getDirection, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setScrollBarColor", js_cocos2dx_ui_ScrollView_setScrollBarColor, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("scrollToBottomLeft", js_cocos2dx_ui_ScrollView_scrollToBottomLeft, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getInnerContainer", js_cocos2dx_ui_ScrollView_getInnerContainer, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("jumpToBottom", js_cocos2dx_ui_ScrollView_jumpToBottom, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -7980,19 +8268,32 @@ void js_register_cocos2dx_ui_ScrollView(JSContext *cx, JS::HandleObject global) JS_FN("getInnerContainerSize", js_cocos2dx_ui_ScrollView_getInnerContainerSize, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isBounceEnabled", js_cocos2dx_ui_ScrollView_isBounceEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("jumpToPercentVertical", js_cocos2dx_ui_ScrollView_jumpToPercentVertical, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setScrollBarAutoHideTime", js_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setScrollBarPositionFromCornerForHorizontal", js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setInertiaScrollEnabled", js_cocos2dx_ui_ScrollView_setInertiaScrollEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getScrollBarColor", js_cocos2dx_ui_ScrollView_getScrollBarColor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("jumpToTopLeft", js_cocos2dx_ui_ScrollView_jumpToTopLeft, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("jumpToPercentHorizontal", js_cocos2dx_ui_ScrollView_jumpToPercentHorizontal, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("jumpToBottomRight", js_cocos2dx_ui_ScrollView_jumpToBottomRight, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getScrollBarPositionFromCornerForHorizontal", js_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForHorizontal, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setScrollBarWidth", js_cocos2dx_ui_ScrollView_setScrollBarWidth, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setBounceEnabled", js_cocos2dx_ui_ScrollView_setBounceEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("jumpToTop", js_cocos2dx_ui_ScrollView_jumpToTop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("scrollToLeft", js_cocos2dx_ui_ScrollView_scrollToLeft, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("jumpToPercentBothDirection", js_cocos2dx_ui_ScrollView_jumpToPercentBothDirection, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getScrollBarPositionFromCornerForVertical", js_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForVertical, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("scrollToPercentVertical", js_cocos2dx_ui_ScrollView_scrollToPercentVertical, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("scrollToBottom", js_cocos2dx_ui_ScrollView_scrollToBottom, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setScrollBarAutoHideEnabled", js_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("scrollToBottomRight", js_cocos2dx_ui_ScrollView_scrollToBottomRight, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setScrollBarPositionFromCorner", js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setScrollBarPositionFromCornerForVertical", js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getScrollBarAutoHideTime", js_cocos2dx_ui_ScrollView_getScrollBarAutoHideTime, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("jumpToLeft", js_cocos2dx_ui_ScrollView_jumpToLeft, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("scrollToRight", js_cocos2dx_ui_ScrollView_scrollToRight, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isScrollBarEnabled", js_cocos2dx_ui_ScrollView_isScrollBarEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getScrollBarWidth", js_cocos2dx_ui_ScrollView_getScrollBarWidth, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("isScrollBarAutoHideEnabled", js_cocos2dx_ui_ScrollView_isScrollBarAutoHideEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("jumpToRight", js_cocos2dx_ui_ScrollView_jumpToRight, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("scrollToTopRight", js_cocos2dx_ui_ScrollView_scrollToTopRight, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("ctor", js_cocos2d_ui_ScrollView_ctor, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_ui_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_ui_auto.hpp index 7d9789ebc2..60f36ffb88 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_ui_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_ui_auto.hpp @@ -367,9 +367,11 @@ void js_register_cocos2dx_ui_ScrollView(JSContext *cx, JS::HandleObject global); void register_all_cocos2dx_ui(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_ui_ScrollView_scrollToTop(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_scrollToPercentHorizontal(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_setScrollBarEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_isInertiaScrollEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_scrollToPercentBothDirection(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_getDirection(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_setScrollBarColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_scrollToBottomLeft(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_getInnerContainer(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_jumpToBottom(JSContext *cx, uint32_t argc, jsval *vp); @@ -381,19 +383,32 @@ bool js_cocos2dx_ui_ScrollView_setInnerContainerSize(JSContext *cx, uint32_t arg bool js_cocos2dx_ui_ScrollView_getInnerContainerSize(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_isBounceEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_jumpToPercentVertical(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_setInertiaScrollEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_getScrollBarColor(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_jumpToTopLeft(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_jumpToPercentHorizontal(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_jumpToBottomRight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForHorizontal(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_setScrollBarWidth(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_setBounceEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_jumpToTop(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_scrollToLeft(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_jumpToPercentBothDirection(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForVertical(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_scrollToPercentVertical(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_scrollToBottom(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_scrollToBottomRight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_getScrollBarAutoHideTime(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_jumpToLeft(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_scrollToRight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_isScrollBarEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_getScrollBarWidth(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_ui_ScrollView_isScrollBarAutoHideEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_jumpToRight(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_scrollToTopRight(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_ui_ScrollView_create(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/cocos/scripting/lua-bindings/auto/api/ScrollView.lua b/cocos/scripting/lua-bindings/auto/api/ScrollView.lua index db1f9aa766..9dbbcbbbaa 100644 --- a/cocos/scripting/lua-bindings/auto/api/ScrollView.lua +++ b/cocos/scripting/lua-bindings/auto/api/ScrollView.lua @@ -26,6 +26,14 @@ -- @param #bool attenuated -- @return ScrollView#ScrollView self (return value: ccui.ScrollView) +-------------------------------- +-- brief Toggle scroll bar enabled.
+-- param enabled True if enable scroll bar, false otherwise. +-- @function [parent=#ScrollView] setScrollBarEnabled +-- @param self +-- @param #bool enabled +-- @return ScrollView#ScrollView self (return value: ccui.ScrollView) + -------------------------------- -- brief Query inertia scroll state.
-- return True if inertia is enabled, false otherwise. @@ -53,6 +61,14 @@ -- @param self -- @return int#int ret (return value: int) +-------------------------------- +-- brief Set the scroll bar's color
+-- param the scroll bar's color +-- @function [parent=#ScrollView] setScrollBarColor +-- @param self +-- @param #color3b_table color +-- @return ScrollView#ScrollView self (return value: ccui.ScrollView) + -------------------------------- -- Scroll inner container to bottom and left boundary of scrollview.
-- param second Time in seconds.
@@ -148,6 +164,22 @@ -- @param #function callback -- @return ScrollView#ScrollView self (return value: ccui.ScrollView) +-------------------------------- +-- brief Set scroll bar auto hide time
+-- param scroll bar auto hide time +-- @function [parent=#ScrollView] setScrollBarAutoHideTime +-- @param self +-- @param #float autoHideTime +-- @return ScrollView#ScrollView self (return value: ccui.ScrollView) + +-------------------------------- +-- brief Set the horizontal scroll bar position from left-bottom corner.
+-- param positionFromCorner The position from left-bottom corner +-- @function [parent=#ScrollView] setScrollBarPositionFromCornerForHorizontal +-- @param self +-- @param #vec2_table positionFromCorner +-- @return ScrollView#ScrollView self (return value: ccui.ScrollView) + -------------------------------- -- brief Toggle whether enable scroll inertia while scrolling.
-- param enabled True if enable inertia, false otherwise. @@ -156,6 +188,13 @@ -- @param #bool enabled -- @return ScrollView#ScrollView self (return value: ccui.ScrollView) +-------------------------------- +-- brief Get the scroll bar's color
+-- return the scroll bar's color +-- @function [parent=#ScrollView] getScrollBarColor +-- @param self +-- @return color3b_table#color3b_table ret (return value: color3b_table) + -------------------------------- -- Move inner container to top and left boundary of scrollview. -- @function [parent=#ScrollView] jumpToTopLeft @@ -176,6 +215,21 @@ -- @param self -- @return ScrollView#ScrollView self (return value: ccui.ScrollView) +-------------------------------- +-- brief Get the horizontal scroll bar's position from right-top corner.
+-- return positionFromCorner +-- @function [parent=#ScrollView] getScrollBarPositionFromCornerForHorizontal +-- @param self +-- @return vec2_table#vec2_table ret (return value: vec2_table) + +-------------------------------- +-- brief Set the scroll bar's width
+-- param width The scroll bar's width +-- @function [parent=#ScrollView] setScrollBarWidth +-- @param self +-- @param #float width +-- @return ScrollView#ScrollView self (return value: ccui.ScrollView) + -------------------------------- -- brief Toggle bounce enabled when scroll to the edge.
-- param enabled True if enable bounce, false otherwise. @@ -208,6 +262,13 @@ -- @param #vec2_table percent -- @return ScrollView#ScrollView self (return value: ccui.ScrollView) +-------------------------------- +-- brief Get the vertical scroll bar's position from right-top corner.
+-- return positionFromCorner +-- @function [parent=#ScrollView] getScrollBarPositionFromCornerForVertical +-- @param self +-- @return vec2_table#vec2_table ret (return value: vec2_table) + -------------------------------- -- Scroll inner container to vertical percent position of scrollview.
-- param percent A value between 0 and 100.
@@ -230,6 +291,14 @@ -- @param #bool attenuated -- @return ScrollView#ScrollView self (return value: ccui.ScrollView) +-------------------------------- +-- brief Set scroll bar auto hide state
+-- param scroll bar auto hide state +-- @function [parent=#ScrollView] setScrollBarAutoHideEnabled +-- @param self +-- @param #bool autoHideEnabled +-- @return ScrollView#ScrollView self (return value: ccui.ScrollView) + -------------------------------- -- Scroll inner container to bottom and right boundary of scrollview.
-- param second Time in seconds
@@ -240,6 +309,29 @@ -- @param #bool attenuated -- @return ScrollView#ScrollView self (return value: ccui.ScrollView) +-------------------------------- +-- brief Set the scroll bar positions from the left-bottom corner (horizontal) and right-top corner (vertical).
+-- param positionFromCorner The position from the left-bottom corner (horizontal) and right-top corner (vertical). +-- @function [parent=#ScrollView] setScrollBarPositionFromCorner +-- @param self +-- @param #vec2_table positionFromCorner +-- @return ScrollView#ScrollView self (return value: ccui.ScrollView) + +-------------------------------- +-- brief Set the vertical scroll bar position from right-top corner.
+-- param positionFromCorner The position from right-top corner +-- @function [parent=#ScrollView] setScrollBarPositionFromCornerForVertical +-- @param self +-- @param #vec2_table positionFromCorner +-- @return ScrollView#ScrollView self (return value: ccui.ScrollView) + +-------------------------------- +-- brief Get the scroll bar's auto hide time
+-- return the scroll bar's auto hide time +-- @function [parent=#ScrollView] getScrollBarAutoHideTime +-- @param self +-- @return float#float ret (return value: float) + -------------------------------- -- Move inner container to left boundary of scrollview. -- @function [parent=#ScrollView] jumpToLeft @@ -256,6 +348,27 @@ -- @param #bool attenuated -- @return ScrollView#ScrollView self (return value: ccui.ScrollView) +-------------------------------- +-- brief Query scroll bar state.
+-- return True if scroll bar is enabled, false otherwise. +-- @function [parent=#ScrollView] isScrollBarEnabled +-- @param self +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- brief Get the scroll bar's width
+-- return the scroll bar's width +-- @function [parent=#ScrollView] getScrollBarWidth +-- @param self +-- @return float#float ret (return value: float) + +-------------------------------- +-- brief Query scroll bar auto hide state
+-- return True if scroll bar auto hide is enabled, false otherwise. +-- @function [parent=#ScrollView] isScrollBarAutoHideEnabled +-- @param self +-- @return bool#bool ret (return value: bool) + -------------------------------- -- Move inner container to right boundary of scrollview. -- @function [parent=#ScrollView] jumpToRight diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp index f139072d17..c67cf3c661 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.cpp @@ -11205,6 +11205,56 @@ int lua_cocos2dx_ui_ScrollView_scrollToPercentHorizontal(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_ScrollView_setScrollBarEnabled(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_setScrollBarEnabled'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + bool arg0; + + ok &= luaval_to_boolean(tolua_S, 2,&arg0, "ccui.ScrollView:setScrollBarEnabled"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_setScrollBarEnabled'", nullptr); + return 0; + } + cobj->setScrollBarEnabled(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:setScrollBarEnabled",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_setScrollBarEnabled'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_ScrollView_isInertiaScrollEnabled(lua_State* tolua_S) { int argc = 0; @@ -11355,6 +11405,56 @@ int lua_cocos2dx_ui_ScrollView_getDirection(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_ScrollView_setScrollBarColor(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_setScrollBarColor'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocos2d::Color3B arg0; + + ok &= luaval_to_color3b(tolua_S, 2, &arg0, "ccui.ScrollView:setScrollBarColor"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_setScrollBarColor'", nullptr); + return 0; + } + cobj->setScrollBarColor(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:setScrollBarColor",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_setScrollBarColor'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_ScrollView_scrollToBottomLeft(lua_State* tolua_S) { int argc = 0; @@ -11947,6 +12047,106 @@ int lua_cocos2dx_ui_ScrollView_addEventListener(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + double arg0; + + ok &= luaval_to_number(tolua_S, 2,&arg0, "ccui.ScrollView:setScrollBarAutoHideTime"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime'", nullptr); + return 0; + } + cobj->setScrollBarAutoHideTime(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:setScrollBarAutoHideTime",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocos2d::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "ccui.ScrollView:setScrollBarPositionFromCornerForHorizontal"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal'", nullptr); + return 0; + } + cobj->setScrollBarPositionFromCornerForHorizontal(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:setScrollBarPositionFromCornerForHorizontal",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_ScrollView_setInertiaScrollEnabled(lua_State* tolua_S) { int argc = 0; @@ -11997,6 +12197,53 @@ int lua_cocos2dx_ui_ScrollView_setInertiaScrollEnabled(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_ScrollView_getScrollBarColor(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_getScrollBarColor'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_getScrollBarColor'", nullptr); + return 0; + } + const cocos2d::Color3B& ret = cobj->getScrollBarColor(); + color3b_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:getScrollBarColor",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_getScrollBarColor'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_ScrollView_jumpToTopLeft(lua_State* tolua_S) { int argc = 0; @@ -12141,6 +12388,103 @@ int lua_cocos2dx_ui_ScrollView_jumpToBottomRight(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForHorizontal(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForHorizontal'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForHorizontal'", nullptr); + return 0; + } + cocos2d::Vec2 ret = cobj->getScrollBarPositionFromCornerForHorizontal(); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:getScrollBarPositionFromCornerForHorizontal",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForHorizontal'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_ui_ScrollView_setScrollBarWidth(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_setScrollBarWidth'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + double arg0; + + ok &= luaval_to_number(tolua_S, 2,&arg0, "ccui.ScrollView:setScrollBarWidth"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_setScrollBarWidth'", nullptr); + return 0; + } + cobj->setScrollBarWidth(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:setScrollBarWidth",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_setScrollBarWidth'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_ScrollView_setBounceEnabled(lua_State* tolua_S) { int argc = 0; @@ -12341,6 +12685,53 @@ int lua_cocos2dx_ui_ScrollView_jumpToPercentBothDirection(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForVertical(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForVertical'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForVertical'", nullptr); + return 0; + } + cocos2d::Vec2 ret = cobj->getScrollBarPositionFromCornerForVertical(); + vec2_to_luaval(tolua_S, ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:getScrollBarPositionFromCornerForVertical",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForVertical'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_ScrollView_scrollToPercentVertical(lua_State* tolua_S) { int argc = 0; @@ -12450,6 +12841,56 @@ int lua_cocos2dx_ui_ScrollView_scrollToBottom(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + bool arg0; + + ok &= luaval_to_boolean(tolua_S, 2,&arg0, "ccui.ScrollView:setScrollBarAutoHideEnabled"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled'", nullptr); + return 0; + } + cobj->setScrollBarAutoHideEnabled(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:setScrollBarAutoHideEnabled",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_ScrollView_scrollToBottomRight(lua_State* tolua_S) { int argc = 0; @@ -12503,6 +12944,153 @@ int lua_cocos2dx_ui_ScrollView_scrollToBottomRight(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocos2d::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "ccui.ScrollView:setScrollBarPositionFromCorner"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner'", nullptr); + return 0; + } + cobj->setScrollBarPositionFromCorner(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:setScrollBarPositionFromCorner",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocos2d::Vec2 arg0; + + ok &= luaval_to_vec2(tolua_S, 2, &arg0, "ccui.ScrollView:setScrollBarPositionFromCornerForVertical"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical'", nullptr); + return 0; + } + cobj->setScrollBarPositionFromCornerForVertical(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:setScrollBarPositionFromCornerForVertical",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_ui_ScrollView_getScrollBarAutoHideTime(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_getScrollBarAutoHideTime'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_getScrollBarAutoHideTime'", nullptr); + return 0; + } + double ret = cobj->getScrollBarAutoHideTime(); + tolua_pushnumber(tolua_S,(lua_Number)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:getScrollBarAutoHideTime",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_getScrollBarAutoHideTime'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_ScrollView_jumpToLeft(lua_State* tolua_S) { int argc = 0; @@ -12603,6 +13191,147 @@ int lua_cocos2dx_ui_ScrollView_scrollToRight(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ui_ScrollView_isScrollBarEnabled(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_isScrollBarEnabled'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_isScrollBarEnabled'", nullptr); + return 0; + } + bool ret = cobj->isScrollBarEnabled(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:isScrollBarEnabled",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_isScrollBarEnabled'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_ui_ScrollView_getScrollBarWidth(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_getScrollBarWidth'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_getScrollBarWidth'", nullptr); + return 0; + } + double ret = cobj->getScrollBarWidth(); + tolua_pushnumber(tolua_S,(lua_Number)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:getScrollBarWidth",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_getScrollBarWidth'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_ui_ScrollView_isScrollBarAutoHideEnabled(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ui::ScrollView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccui.ScrollView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ui::ScrollView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_ScrollView_isScrollBarAutoHideEnabled'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_ScrollView_isScrollBarAutoHideEnabled'", nullptr); + return 0; + } + bool ret = cobj->isScrollBarAutoHideEnabled(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.ScrollView:isScrollBarAutoHideEnabled",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_ScrollView_isScrollBarAutoHideEnabled'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ui_ScrollView_jumpToRight(lua_State* tolua_S) { int argc = 0; @@ -12823,9 +13552,11 @@ int lua_register_cocos2dx_ui_ScrollView(lua_State* tolua_S) tolua_function(tolua_S,"new",lua_cocos2dx_ui_ScrollView_constructor); tolua_function(tolua_S,"scrollToTop",lua_cocos2dx_ui_ScrollView_scrollToTop); tolua_function(tolua_S,"scrollToPercentHorizontal",lua_cocos2dx_ui_ScrollView_scrollToPercentHorizontal); + tolua_function(tolua_S,"setScrollBarEnabled",lua_cocos2dx_ui_ScrollView_setScrollBarEnabled); tolua_function(tolua_S,"isInertiaScrollEnabled",lua_cocos2dx_ui_ScrollView_isInertiaScrollEnabled); tolua_function(tolua_S,"scrollToPercentBothDirection",lua_cocos2dx_ui_ScrollView_scrollToPercentBothDirection); tolua_function(tolua_S,"getDirection",lua_cocos2dx_ui_ScrollView_getDirection); + tolua_function(tolua_S,"setScrollBarColor",lua_cocos2dx_ui_ScrollView_setScrollBarColor); tolua_function(tolua_S,"scrollToBottomLeft",lua_cocos2dx_ui_ScrollView_scrollToBottomLeft); tolua_function(tolua_S,"getInnerContainer",lua_cocos2dx_ui_ScrollView_getInnerContainer); tolua_function(tolua_S,"jumpToBottom",lua_cocos2dx_ui_ScrollView_jumpToBottom); @@ -12838,19 +13569,32 @@ int lua_register_cocos2dx_ui_ScrollView(lua_State* tolua_S) tolua_function(tolua_S,"isBounceEnabled",lua_cocos2dx_ui_ScrollView_isBounceEnabled); tolua_function(tolua_S,"jumpToPercentVertical",lua_cocos2dx_ui_ScrollView_jumpToPercentVertical); tolua_function(tolua_S,"addEventListener",lua_cocos2dx_ui_ScrollView_addEventListener); + tolua_function(tolua_S,"setScrollBarAutoHideTime",lua_cocos2dx_ui_ScrollView_setScrollBarAutoHideTime); + tolua_function(tolua_S,"setScrollBarPositionFromCornerForHorizontal",lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForHorizontal); tolua_function(tolua_S,"setInertiaScrollEnabled",lua_cocos2dx_ui_ScrollView_setInertiaScrollEnabled); + tolua_function(tolua_S,"getScrollBarColor",lua_cocos2dx_ui_ScrollView_getScrollBarColor); tolua_function(tolua_S,"jumpToTopLeft",lua_cocos2dx_ui_ScrollView_jumpToTopLeft); tolua_function(tolua_S,"jumpToPercentHorizontal",lua_cocos2dx_ui_ScrollView_jumpToPercentHorizontal); tolua_function(tolua_S,"jumpToBottomRight",lua_cocos2dx_ui_ScrollView_jumpToBottomRight); + tolua_function(tolua_S,"getScrollBarPositionFromCornerForHorizontal",lua_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForHorizontal); + tolua_function(tolua_S,"setScrollBarWidth",lua_cocos2dx_ui_ScrollView_setScrollBarWidth); tolua_function(tolua_S,"setBounceEnabled",lua_cocos2dx_ui_ScrollView_setBounceEnabled); tolua_function(tolua_S,"jumpToTop",lua_cocos2dx_ui_ScrollView_jumpToTop); tolua_function(tolua_S,"scrollToLeft",lua_cocos2dx_ui_ScrollView_scrollToLeft); tolua_function(tolua_S,"jumpToPercentBothDirection",lua_cocos2dx_ui_ScrollView_jumpToPercentBothDirection); + tolua_function(tolua_S,"getScrollBarPositionFromCornerForVertical",lua_cocos2dx_ui_ScrollView_getScrollBarPositionFromCornerForVertical); tolua_function(tolua_S,"scrollToPercentVertical",lua_cocos2dx_ui_ScrollView_scrollToPercentVertical); tolua_function(tolua_S,"scrollToBottom",lua_cocos2dx_ui_ScrollView_scrollToBottom); + tolua_function(tolua_S,"setScrollBarAutoHideEnabled",lua_cocos2dx_ui_ScrollView_setScrollBarAutoHideEnabled); tolua_function(tolua_S,"scrollToBottomRight",lua_cocos2dx_ui_ScrollView_scrollToBottomRight); + tolua_function(tolua_S,"setScrollBarPositionFromCorner",lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCorner); + tolua_function(tolua_S,"setScrollBarPositionFromCornerForVertical",lua_cocos2dx_ui_ScrollView_setScrollBarPositionFromCornerForVertical); + tolua_function(tolua_S,"getScrollBarAutoHideTime",lua_cocos2dx_ui_ScrollView_getScrollBarAutoHideTime); tolua_function(tolua_S,"jumpToLeft",lua_cocos2dx_ui_ScrollView_jumpToLeft); tolua_function(tolua_S,"scrollToRight",lua_cocos2dx_ui_ScrollView_scrollToRight); + tolua_function(tolua_S,"isScrollBarEnabled",lua_cocos2dx_ui_ScrollView_isScrollBarEnabled); + tolua_function(tolua_S,"getScrollBarWidth",lua_cocos2dx_ui_ScrollView_getScrollBarWidth); + tolua_function(tolua_S,"isScrollBarAutoHideEnabled",lua_cocos2dx_ui_ScrollView_isScrollBarAutoHideEnabled); tolua_function(tolua_S,"jumpToRight",lua_cocos2dx_ui_ScrollView_jumpToRight); tolua_function(tolua_S,"scrollToTopRight",lua_cocos2dx_ui_ScrollView_scrollToTopRight); tolua_function(tolua_S,"create", lua_cocos2dx_ui_ScrollView_create); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp index 9bb7a15177..a450edd5dc 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_ui_auto.hpp @@ -539,6 +539,21 @@ int register_all_cocos2dx_ui(lua_State* tolua_S); + + + + + + + + + + + + + + + From 302976b6035d795629817d0c1e87b23e160ef022 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 7 Jul 2015 14:24:17 +0800 Subject: [PATCH 29/43] add shared scheme to iOS & Mac project. --- .../xcschemes/js-tests Mac.xcscheme | 88 +++++++++++++++++++ .../xcschemes/js-tests iOS.xcscheme | 88 +++++++++++++++++++ .../xcschemes/HelloCpp-desktop.xcscheme | 88 +++++++++++++++++++ .../xcschemes/HelloCpp-mobile.xcscheme | 88 +++++++++++++++++++ .../HelloJavascript-desktop.xcscheme | 88 +++++++++++++++++++ .../xcschemes/HelloJavascript-mobile.xcscheme | 88 +++++++++++++++++++ .../HelloJavascript-desktop.xcscheme | 88 +++++++++++++++++++ .../xcschemes/HelloJavascript-mobile.xcscheme | 88 +++++++++++++++++++ .../xcschemes/HelloLua-desktop.xcscheme | 88 +++++++++++++++++++ .../xcschemes/HelloLua-mobile.xcscheme | 88 +++++++++++++++++++ 10 files changed, 880 insertions(+) create mode 100644 build/cocos2d_tests.xcodeproj/xcshareddata/xcschemes/js-tests Mac.xcscheme create mode 100644 build/cocos2d_tests.xcodeproj/xcshareddata/xcschemes/js-tests iOS.xcscheme create mode 100644 templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-desktop.xcscheme create mode 100644 templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-mobile.xcscheme create mode 100644 templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme create mode 100644 templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme create mode 100644 templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme create mode 100644 templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme create mode 100644 templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-desktop.xcscheme create mode 100644 templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-mobile.xcscheme diff --git a/build/cocos2d_tests.xcodeproj/xcshareddata/xcschemes/js-tests Mac.xcscheme b/build/cocos2d_tests.xcodeproj/xcshareddata/xcschemes/js-tests Mac.xcscheme new file mode 100644 index 0000000000..0bd1c8b92d --- /dev/null +++ b/build/cocos2d_tests.xcodeproj/xcshareddata/xcschemes/js-tests Mac.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/cocos2d_tests.xcodeproj/xcshareddata/xcschemes/js-tests iOS.xcscheme b/build/cocos2d_tests.xcodeproj/xcshareddata/xcschemes/js-tests iOS.xcscheme new file mode 100644 index 0000000000..bd5a720c84 --- /dev/null +++ b/build/cocos2d_tests.xcodeproj/xcshareddata/xcschemes/js-tests iOS.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-desktop.xcscheme b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-desktop.xcscheme new file mode 100644 index 0000000000..3e1247c3ed --- /dev/null +++ b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-desktop.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-mobile.xcscheme b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-mobile.xcscheme new file mode 100644 index 0000000000..b44f47a122 --- /dev/null +++ b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-mobile.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme new file mode 100644 index 0000000000..73aafb72a7 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme new file mode 100644 index 0000000000..5be56b11f0 --- /dev/null +++ b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme b/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme new file mode 100644 index 0000000000..73aafb72a7 --- /dev/null +++ b/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme b/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme new file mode 100644 index 0000000000..5be56b11f0 --- /dev/null +++ b/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-desktop.xcscheme b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-desktop.xcscheme new file mode 100644 index 0000000000..c0ebb1806d --- /dev/null +++ b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-desktop.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-mobile.xcscheme b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-mobile.xcscheme new file mode 100644 index 0000000000..f811bd7808 --- /dev/null +++ b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-mobile.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From d8bf9c8a2a978d550177e3e161dd7b375f69ae8c Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 7 Jul 2015 11:02:21 +0800 Subject: [PATCH 30/43] improve template daily build scripts --- .../slave-scripts/templates/android-build.sh | 13 ++ .../slave-scripts/templates/ios-build.sh | 7 + .../slave-scripts/templates/linux-build.sh | 13 ++ .../slave-scripts/templates/mac-build.sh | 22 +++ .../slave-scripts/templates/win32-build.bat | 2 + .../templates/windows-universal.bat | 2 + .../jenkins-scripts/templates-daily-build.py | 150 +++++++++--------- 7 files changed, 131 insertions(+), 78 deletions(-) create mode 100755 tools/jenkins-scripts/slave-scripts/templates/android-build.sh create mode 100755 tools/jenkins-scripts/slave-scripts/templates/ios-build.sh create mode 100755 tools/jenkins-scripts/slave-scripts/templates/linux-build.sh create mode 100755 tools/jenkins-scripts/slave-scripts/templates/mac-build.sh create mode 100644 tools/jenkins-scripts/slave-scripts/templates/win32-build.bat create mode 100755 tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat diff --git a/tools/jenkins-scripts/slave-scripts/templates/android-build.sh b/tools/jenkins-scripts/slave-scripts/templates/android-build.sh new file mode 100755 index 0000000000..df44270d91 --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/templates/android-build.sh @@ -0,0 +1,13 @@ +#put xctool.sh into your PATH +tools/cocos2d-console/bin/cocos new -l $1 +# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# COCOS2DX_ROOT="$DIR"/../../.. +# cd ${COCOS2DX_ROOT} +# python build/android-build.py -p 10 cpp-tests lua-tests js-tests +if [ $1 == "cpp" ];then + cocos compile -p android -s MyCppGame --android-studio -j4 --ndk-mode release --compile-script 0 +elif [ $1 == "lua" ];then + cocos compile -p android -s MyLuaGame --android-studio -j4 --ndk-mode release --compile-script 0 +elif [ $1 == "js" ];then + cocos compile -p android -s MyJsGame --android-studio -j4 --ndk-mode release --compile-script 0 +fi diff --git a/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh b/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh new file mode 100755 index 0000000000..1adfdb8e7f --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh @@ -0,0 +1,7 @@ +#put xctool.sh into your PATH +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +COCOS2DX_ROOT="$DIR"/../../.. +xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests iOS" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty +xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests iOS" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty +#the following commands must not be removed +xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests iOS" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build diff --git a/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh b/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh new file mode 100755 index 0000000000..f940139ff4 --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh @@ -0,0 +1,13 @@ +#put xctool.sh into your PATH +tools/cocos2d-console/bin/cocos new -l $1 +# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# COCOS2DX_ROOT="$DIR"/../../.. +# cd ${COCOS2DX_ROOT} +# python build/android-build.py -p 10 cpp-tests lua-tests js-tests +if [ $1 == "cpp" ];then + cocos compile -p linux -s MyCppGame -m release -j4 --compile-script 0 +elif [ $1 == "lua" ];then + cocos compile -p linux -s MyLuaGame -m release -j4 --compile-script 0 +elif [ $1 == "js" ];then + cocos compile -p linux -s MyJsGame -m release -j4 --compile-script 0 +fi diff --git a/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh b/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh new file mode 100755 index 0000000000..47f41c551f --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh @@ -0,0 +1,22 @@ +#put xctool.sh into your PATH + +####### +# Cmake build +####### +# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# COCOS2DX_ROOT="$DIR"/../../.. +# cd ${COCOS2DX_ROOT} +# mkdir mac-build +# cd mac-build +# cmake .. +# make -j4 + +####### +# xcode build +####### +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +COCOS2DX_ROOT="$DIR"/../../.. +xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests Mac" clean | xcpretty +xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests Mac" build | xcpretty +#xcpretty has a bug, some xcodebuid fails return value would be treated as 0. +xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests Mac" build diff --git a/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat b/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat new file mode 100644 index 0000000000..7f29e5337d --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat @@ -0,0 +1,2 @@ +call "%VS120COMNTOOLS%vsvars32.bat" +msbuild build\cocos2d-win32.sln /t:Build /p:Platform="Win32" /p:Configuration="Release" /m diff --git a/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat b/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat new file mode 100755 index 0000000000..7959cc3aed --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat @@ -0,0 +1,2 @@ +call "%VS120COMNTOOLS%vsvars32.bat" +msbuild build\cocos2d-win8.1-universal.sln /t:Build /p:Platform="Win32" /p:Configuration="Release" /m diff --git a/tools/jenkins-scripts/templates-daily-build.py b/tools/jenkins-scripts/templates-daily-build.py index 2f074e438b..efe5a7f5b0 100644 --- a/tools/jenkins-scripts/templates-daily-build.py +++ b/tools/jenkins-scripts/templates-daily-build.py @@ -1,13 +1,9 @@ -#Cocos2D-X templates daily build scripts +#Cocos2D-X template project daily build import os import sys import traceback -# for local debugging purpose, you could change the value to 0 and run -# this scripts in your local machine -remote_build = 1 - if('branch' in os.environ): branch = os.environ['branch'] else: @@ -21,93 +17,83 @@ else: if('NODE_NAME' in os.environ): node_name = os.environ['NODE_NAME'] else: - node_name = 'mac' + node_name = 'linux' +# for local debugging purpose, you could change the value to 0 and run +# this scripts in your local machine +remote_build = 0 -if('build_mode' in os.environ): - build_mode = os.environ['build_mode'] -else: - build_mode = "debug" - -#valide build_type are 'template' and 'runtime' -if('build_type' in os.environ): - build_type = os.environ['build_type'] -else: - build_type = 'template' - -default_templates_types = ["cpp", "lua", "js"] -runtime_templates_types = ["lua", "js"] -default_templates_names = ["test_cpp", "test_lua", "test_js"] -runtime_template_names = ["test_rt_lua", "test_rt_js"] - -def do_clean_up(): - for name in default_templates_names: - commands = 'rm -rf ' + name - os.system(commands) - for name in runtime_template_names: - commands = 'rm -rf ' + name - os.system(commands) +def download_3rd_library(): + #run download-deps.py + print("prepare to downloading ...") + os.system('python download-deps.py -r no') -def build_templates(mode, templates, is_runtime): - ret = 0 +def sync_remote_repo(): + #reset path to workspace root + os.system("cd " + workspace) + + #pull latest code + os.system("git fetch origin " + branch) + os.system("git checkout " + branch) + os.system("git merge origin/" + branch) + #clean workspace + print "Before checkout: git clean -xdf -f" + os.system("git clean -xdf -f") + + #update submodule + git_update_submodule = "git submodule update --init --force" + ret = os.system(git_update_submodule) + if(ret != 0): + sys.exit(ret) + + +def gen_scripting_bindings(): + # Generate binding glue codes if(branch == 'v3' or branch == 'v4-develop'): - do_clean_up() - test_project_prefix = " test_" - if is_runtime: - test_project_prefix = " test_rt_" + ret = os.system("python tools/jenkins-scripts/slave-scripts/gen_jsb.py") + if(ret != 0): + sys.exit(ret) - #build for default templates - for type in templates: - #create project - create_project_commands = "cocos new -l " + type - if is_runtime: - create_project_commands += " -t runtime " + test_project_prefix + type - else: - create_project_commands += test_project_prefix + type - create_ret = os.system(create_project_commands) - #create project failed - if create_ret != 0: - return 1 +def do_build_slaves(): + jenkins_script_path = "tools" + os.sep + "jenkins-scripts" + os.sep + "slave-scripts" + os.sep + "templates" + os.sep - ret += create_ret - #compile - compile_project_commands = "cocos compile -p " + node_name + " -s " + test_project_prefix + type + " --compile-script 0" - build_mode_args = " -m " - if node_name == "android": - build_mode_args = " --ndk-mode " - build_mode_args += mode + if(branch == 'v3' or branch == 'v4-develop'): + slave_build_scripts = "" + if(node_name == 'android') or (node_name == 'android_bak'): + slave_build_scripts = jenkins_script_path + "android-build.sh js" + elif(node_name == 'win32' or node_name == 'win32_win7' or node_name == 'win32_bak'): + slave_build_scripts = jenkins_script_path + "win32-build.bat" + elif(node_name == 'windows-universal' or node_name == 'windows-universal_bak'): + slave_build_scripts = jenkins_script_path + "windows-universal.bat" + elif(node_name == 'ios_mac' or node_name == 'ios' or node_name == 'ios_bak'): + slave_build_scripts = jenkins_script_path + "ios-build.sh" + elif(node_name == 'mac' or node_name == 'mac_bak'): + slave_build_scripts = jenkins_script_path + "mac-build.sh" + elif(node_name == 'linux_centos' or node_name == 'linux' or node_name == 'linux_bak'): + slave_build_scripts = jenkins_script_path + "linux-build.sh cpp" + elif(node_name == 'wp8'): + if(branch != 'v4'): + slave_build_scripts = jenkins_script_path + "wp8-v3.bat" - if node_name == "windows-universal": - #run wp8.1 and windows 8.1 - # lua & js don't have runtime template - if is_runtime: - continue - wp_ret = os.system("cocos compile -p wp8_1 " + build_mode_args + " -s " + test_project_prefix + type + " --compile-script 0") - winrt_ret = os.system("cocos compile -p metro " + build_mode_args + " -s " + test_project_prefix + type + " --compile-script 0") - ret += wp_ret - ret += winrt_ret - else: - if node_name == "android": - compile_project_commands += " --app-abi armeabi:armeabi-v7a:x86 " - if node_name == "linux" and is_runtime: - continue - compile_ret = os.system(compile_project_commands + build_mode_args) - ret += compile_ret + ret = os.system(slave_build_scripts) + #get build result + print "build finished and return " + str(ret) return ret def main(): - #start build jobs on each slave - default_build_type = default_templates_types - default_flag = False - if build_type == "runtime": - default_build_type = runtime_templates_types - default_flag = True - ret = build_templates(build_mode, default_build_type, default_flag) + if remote_build == 1: + #syntronize local git repository with remote and merge the PR + sync_remote_repo() + #copy check_current_3rd_libs + download_3rd_library() + #generate jsb and luabindings + gen_scripting_bindings() - print "build finished and return " + str(ret) + #start build jobs on each slave + ret = do_build_slaves() exit_code = 1 if ret == 0: @@ -115,6 +101,14 @@ def main(): else: exit_code = 1 + #clean workspace, we don't won't clean the repository + if remote_build == 1: + os.system("cd " + workspace) + os.system("git reset --hard") + os.system("git clean -xdf -f") + else: + print "local build, no need to cleanup" + return(exit_code) # -------------- main -------------- From 494036be1ae823fd33a6f87be6ce0d30f0ef09cf Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 7 Jul 2015 11:21:32 +0800 Subject: [PATCH 31/43] fix linux build --- .../slave-scripts/templates/android-build.sh | 20 ++++++++----------- .../slave-scripts/templates/linux-build.sh | 20 ++++++++----------- .../jenkins-scripts/templates-daily-build.py | 2 +- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/tools/jenkins-scripts/slave-scripts/templates/android-build.sh b/tools/jenkins-scripts/slave-scripts/templates/android-build.sh index df44270d91..a0f9a34810 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/android-build.sh +++ b/tools/jenkins-scripts/slave-scripts/templates/android-build.sh @@ -1,13 +1,9 @@ -#put xctool.sh into your PATH -tools/cocos2d-console/bin/cocos new -l $1 -# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# COCOS2DX_ROOT="$DIR"/../../.. -# cd ${COCOS2DX_ROOT} -# python build/android-build.py -p 10 cpp-tests lua-tests js-tests -if [ $1 == "cpp" ];then - cocos compile -p android -s MyCppGame --android-studio -j4 --ndk-mode release --compile-script 0 -elif [ $1 == "lua" ];then - cocos compile -p android -s MyLuaGame --android-studio -j4 --ndk-mode release --compile-script 0 -elif [ $1 == "js" ];then - cocos compile -p android -s MyJsGame --android-studio -j4 --ndk-mode release --compile-script 0 +mycocos=tools/cocos2d-console/bin/cocos +$mycocos new -l $1 +if [ $1 = "cpp" ];then + $mycocos compile -p android -s MyCppGame --android-studio -j4 --ndk-mode release --compile-script 0 +elif [ $1 = "lua" ];then + $mycocos compile -p android -s MyLuaGame --android-studio -j4 --ndk-mode release --compile-script 0 +elif [ $1 = "js" ];then + $mycocos compile -p android -s MyJSGame --android-studio -j4 --ndk-mode release --compile-script 0 fi diff --git a/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh b/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh index f940139ff4..54c41bdd1c 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh +++ b/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh @@ -1,13 +1,9 @@ -#put xctool.sh into your PATH -tools/cocos2d-console/bin/cocos new -l $1 -# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# COCOS2DX_ROOT="$DIR"/../../.. -# cd ${COCOS2DX_ROOT} -# python build/android-build.py -p 10 cpp-tests lua-tests js-tests -if [ $1 == "cpp" ];then - cocos compile -p linux -s MyCppGame -m release -j4 --compile-script 0 -elif [ $1 == "lua" ];then - cocos compile -p linux -s MyLuaGame -m release -j4 --compile-script 0 -elif [ $1 == "js" ];then - cocos compile -p linux -s MyJsGame -m release -j4 --compile-script 0 +mycocos=tools/cocos2d-console/bin/cocos +$mycocos new -l $1 +if [ $1 = "cpp" ];then + $mycocos compile -p linux -s MyCppGame -m release -j4 --compile-script 0 +elif [ $1 = "lua" ];then + $mycocos compile -p linux -s MyLuaGame -m release -j4 --compile-script 0 +elif [ $1 = "js" ];then + $mycocos compile -p linux -s MyJSGame -m release -j4 --compile-script 0 fi diff --git a/tools/jenkins-scripts/templates-daily-build.py b/tools/jenkins-scripts/templates-daily-build.py index efe5a7f5b0..e4675ac3e8 100644 --- a/tools/jenkins-scripts/templates-daily-build.py +++ b/tools/jenkins-scripts/templates-daily-build.py @@ -71,7 +71,7 @@ def do_build_slaves(): elif(node_name == 'mac' or node_name == 'mac_bak'): slave_build_scripts = jenkins_script_path + "mac-build.sh" elif(node_name == 'linux_centos' or node_name == 'linux' or node_name == 'linux_bak'): - slave_build_scripts = jenkins_script_path + "linux-build.sh cpp" + slave_build_scripts = jenkins_script_path + "linux-build.sh lua" elif(node_name == 'wp8'): if(branch != 'v4'): slave_build_scripts = jenkins_script_path + "wp8-v3.bat" From a5115bd7398db7df60e62c8650c4c37010aae717 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 7 Jul 2015 13:42:44 +0800 Subject: [PATCH 32/43] improve --- .../slave-scripts/templates/android-build.sh | 9 +++-- .../slave-scripts/templates/ios-build.sh | 25 ++++++++++--- .../slave-scripts/templates/linux-build.sh | 16 +++++--- .../slave-scripts/templates/mac-build.sh | 37 +++++++++---------- .../jenkins-scripts/templates-daily-build.py | 6 +-- 5 files changed, 55 insertions(+), 38 deletions(-) diff --git a/tools/jenkins-scripts/slave-scripts/templates/android-build.sh b/tools/jenkins-scripts/slave-scripts/templates/android-build.sh index a0f9a34810..ab29d41889 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/android-build.sh +++ b/tools/jenkins-scripts/slave-scripts/templates/android-build.sh @@ -1,9 +1,12 @@ +#!/bin/bash mycocos=tools/cocos2d-console/bin/cocos $mycocos new -l $1 if [ $1 = "cpp" ];then - $mycocos compile -p android -s MyCppGame --android-studio -j4 --ndk-mode release --compile-script 0 + projectname="MyCppGame" elif [ $1 = "lua" ];then - $mycocos compile -p android -s MyLuaGame --android-studio -j4 --ndk-mode release --compile-script 0 + projectname="MyLuaGame" elif [ $1 = "js" ];then - $mycocos compile -p android -s MyJSGame --android-studio -j4 --ndk-mode release --compile-script 0 + projectname="MyJSGame" fi + +$mycocos compile -p android -s $projectname --android-studio -j4 --ndk-mode release --compile-script 0 diff --git a/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh b/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh index 1adfdb8e7f..4b5e33faab 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh +++ b/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh @@ -1,7 +1,20 @@ -#put xctool.sh into your PATH -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -COCOS2DX_ROOT="$DIR"/../../.. -xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests iOS" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty -xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests iOS" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty +#!/bin/bash +mycocos=tools/cocos2d-console/bin/cocos +$mycocos new -l $1 + +if [ $1 = "cpp" ];then + schemename="MyCppGame-mobile" + projectpath="MyCppGame/proj.ios_mac/MyCppGame.xcodeproj" +elif [ $1 = "lua" ];then + schemename="MyLuaGame-mobile" + projectpath="MyLuaGame/frameworks/runtime-src/proj.ios_mac/MyLuaGame.xcodeproj" +elif [ $1 = "js" ];then + schemename="MyJSGame-mobile" + projectpath="MyJSGame/frameworks/runtime-src/proj.ios_mac/MyJSGame.xcodeproj" +fi + +echo "start building..." +xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty +xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty #the following commands must not be removed -xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests iOS" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build +xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build diff --git a/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh b/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh index 54c41bdd1c..7c051bfc22 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh +++ b/tools/jenkins-scripts/slave-scripts/templates/linux-build.sh @@ -1,9 +1,13 @@ +#!/bin/bash mycocos=tools/cocos2d-console/bin/cocos $mycocos new -l $1 -if [ $1 = "cpp" ];then - $mycocos compile -p linux -s MyCppGame -m release -j4 --compile-script 0 -elif [ $1 = "lua" ];then - $mycocos compile -p linux -s MyLuaGame -m release -j4 --compile-script 0 -elif [ $1 = "js" ];then - $mycocos compile -p linux -s MyJSGame -m release -j4 --compile-script 0 + +if [ $1 = "cpp" ]; then + projectname="MyCppGame" +elif [ $1 = "lua" ]; then + projectname="MyLuaGame" +elif [ $1 = "js" ]; then + projectname="MyJSGame" fi + +$mycocos compile -p linux -s $projectname -m release -j4 --compile-script 0 diff --git a/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh b/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh index 47f41c551f..79f0149a5c 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh +++ b/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh @@ -1,22 +1,19 @@ -#put xctool.sh into your PATH +#!/bin/bash +mycocos=tools/cocos2d-console/bin/cocos +# $mycocos new -l $1 -####### -# Cmake build -####### -# DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -# COCOS2DX_ROOT="$DIR"/../../.. -# cd ${COCOS2DX_ROOT} -# mkdir mac-build -# cd mac-build -# cmake .. -# make -j4 +if [ $1 = "cpp" ];then + schemename="MyCppGame-desktop" + projectpath="MyCppGame/proj.ios_mac/MyCppGame.xcodeproj" +elif [ $1 = "lua" ];then + schemename="MyLuaGame-desktop" + projectpath="MyLuaGame/frameworks/runtime-src/proj.ios_mac/MyLuaGame.xcodeproj" +elif [ $1 = "js" ];then + schemename="MyJSGame-desktop" + projectpath="MyJSGame/frameworks/runtime-src/proj.ios_mac/MyJSGame.xcodeproj" +fi -####### -# xcode build -####### -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -COCOS2DX_ROOT="$DIR"/../../.. -xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests Mac" clean | xcpretty -xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests Mac" build | xcpretty -#xcpretty has a bug, some xcodebuid fails return value would be treated as 0. -xcodebuild -project "$COCOS2DX_ROOT"/build/cocos2d_tests.xcodeproj -scheme "build all tests Mac" build +xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty +xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty +#the following commands must not be removed +xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build diff --git a/tools/jenkins-scripts/templates-daily-build.py b/tools/jenkins-scripts/templates-daily-build.py index e4675ac3e8..a6da52b9ca 100644 --- a/tools/jenkins-scripts/templates-daily-build.py +++ b/tools/jenkins-scripts/templates-daily-build.py @@ -17,7 +17,7 @@ else: if('NODE_NAME' in os.environ): node_name = os.environ['NODE_NAME'] else: - node_name = 'linux' + node_name = 'ios' # for local debugging purpose, you could change the value to 0 and run # this scripts in your local machine remote_build = 0 @@ -61,13 +61,13 @@ def do_build_slaves(): if(branch == 'v3' or branch == 'v4-develop'): slave_build_scripts = "" if(node_name == 'android') or (node_name == 'android_bak'): - slave_build_scripts = jenkins_script_path + "android-build.sh js" + slave_build_scripts = jenkins_script_path + "android-build.sh lua" elif(node_name == 'win32' or node_name == 'win32_win7' or node_name == 'win32_bak'): slave_build_scripts = jenkins_script_path + "win32-build.bat" elif(node_name == 'windows-universal' or node_name == 'windows-universal_bak'): slave_build_scripts = jenkins_script_path + "windows-universal.bat" elif(node_name == 'ios_mac' or node_name == 'ios' or node_name == 'ios_bak'): - slave_build_scripts = jenkins_script_path + "ios-build.sh" + slave_build_scripts = jenkins_script_path + "ios-build.sh js" elif(node_name == 'mac' or node_name == 'mac_bak'): slave_build_scripts = jenkins_script_path + "mac-build.sh" elif(node_name == 'linux_centos' or node_name == 'linux' or node_name == 'linux_bak'): From 04ade7c16ec889447f0f26a1f4cb039bb2d8ba6f Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 7 Jul 2015 14:57:25 +0800 Subject: [PATCH 33/43] remove xcode scheme --- .../xcschemes/HelloCpp-desktop.xcscheme | 88 ------------------- .../xcschemes/HelloCpp-mobile.xcscheme | 88 ------------------- .../HelloJavascript-desktop.xcscheme | 88 ------------------- .../xcschemes/HelloJavascript-mobile.xcscheme | 88 ------------------- .../HelloJavascript-desktop.xcscheme | 88 ------------------- .../xcschemes/HelloJavascript-mobile.xcscheme | 88 ------------------- .../xcschemes/HelloLua-desktop.xcscheme | 88 ------------------- .../xcschemes/HelloLua-mobile.xcscheme | 88 ------------------- .../slave-scripts/templates/ios-build.sh | 6 +- 9 files changed, 3 insertions(+), 707 deletions(-) delete mode 100644 templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-desktop.xcscheme delete mode 100644 templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-mobile.xcscheme delete mode 100644 templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme delete mode 100644 templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme delete mode 100644 templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme delete mode 100644 templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme delete mode 100644 templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-desktop.xcscheme delete mode 100644 templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-mobile.xcscheme diff --git a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-desktop.xcscheme b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-desktop.xcscheme deleted file mode 100644 index 3e1247c3ed..0000000000 --- a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-desktop.xcscheme +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-mobile.xcscheme b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-mobile.xcscheme deleted file mode 100644 index b44f47a122..0000000000 --- a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/xcshareddata/xcschemes/HelloCpp-mobile.xcscheme +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme deleted file mode 100644 index 73aafb72a7..0000000000 --- a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme deleted file mode 100644 index 5be56b11f0..0000000000 --- a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme b/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme deleted file mode 100644 index 73aafb72a7..0000000000 --- a/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-desktop.xcscheme +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme b/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme deleted file mode 100644 index 5be56b11f0..0000000000 --- a/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/xcshareddata/xcschemes/HelloJavascript-mobile.xcscheme +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-desktop.xcscheme b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-desktop.xcscheme deleted file mode 100644 index c0ebb1806d..0000000000 --- a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-desktop.xcscheme +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-mobile.xcscheme b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-mobile.xcscheme deleted file mode 100644 index f811bd7808..0000000000 --- a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/xcshareddata/xcschemes/HelloLua-mobile.xcscheme +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh b/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh index 4b5e33faab..3dd3f90e9c 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh +++ b/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh @@ -14,7 +14,7 @@ elif [ $1 = "js" ];then fi echo "start building..." -xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty -xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty #the following commands must not be removed -xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build From 47bae381682f80f823b862ca1d75847dc6e24333 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 7 Jul 2015 16:27:38 +0800 Subject: [PATCH 34/43] finish template daily build --- .../slave-scripts/templates/mac-build.sh | 8 ++++---- .../slave-scripts/templates/win32-build.bat | 14 ++++++++++++- .../templates/windows-universal.bat | 14 ++++++++++++- .../jenkins-scripts/templates-daily-build.py | 20 ++++++++++++------- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh b/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh index 79f0149a5c..bf66dbe939 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh +++ b/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh @@ -1,6 +1,6 @@ #!/bin/bash mycocos=tools/cocos2d-console/bin/cocos -# $mycocos new -l $1 +$mycocos new -l $1 if [ $1 = "cpp" ];then schemename="MyCppGame-desktop" @@ -13,7 +13,7 @@ elif [ $1 = "js" ];then projectpath="MyJSGame/frameworks/runtime-src/proj.ios_mac/MyJSGame.xcodeproj" fi -xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty -xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty #the following commands must not be removed -xcodebuild -project $projectpath -scheme "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build diff --git a/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat b/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat index 7f29e5337d..17a863cf84 100644 --- a/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat +++ b/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat @@ -1,2 +1,14 @@ +@echo on + +set mycocos=tools/cocos2d-console/bin/cocos.bat +set language=%1 +call %mycocos% new -l %language% + +set projectname= +if "%language%"=="cpp" set projectname=MyCppGame/proj.win32/MyCppGame.sln +if "%language%"=="lua" set projectname=MyLuaGame/frameworks/runtime-src/proj.win32/MyLuaGame.sln +if "%language%"=="js" set projectname=MyJSGame/frameworks/runtime-src/proj.win32/MyJSGame.sln + +echo %projectname% call "%VS120COMNTOOLS%vsvars32.bat" -msbuild build\cocos2d-win32.sln /t:Build /p:Platform="Win32" /p:Configuration="Release" /m +msbuild %projectname% /t:Build /p:Platform="Win32" /p:Configuration="Release" /m diff --git a/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat b/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat index 7959cc3aed..4def9c437e 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat +++ b/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat @@ -1,2 +1,14 @@ +@echo on + +set mycocos=tools/cocos2d-console/bin/cocos.bat +set language=%1 +call %mycocos% new -l %language% + +set projectname= +if "%language%"=="cpp" set projectname=MyCppGame/proj.win8.1-universal/MyCppGame.sln +if "%language%"=="lua" set projectname=MyLuaGame/frameworks/runtime-src/proj.win8.1-universal/MyLuaGame.sln +if "%language%"=="js" set projectname=MyJSGame/frameworks/runtime-src/proj.win8.1-universal/MyJSGame.sln + +echo %projectname% call "%VS120COMNTOOLS%vsvars32.bat" -msbuild build\cocos2d-win8.1-universal.sln /t:Build /p:Platform="Win32" /p:Configuration="Release" /m +msbuild %projectname% /t:Build /p:Platform="Win32" /p:Configuration="Release" /m diff --git a/tools/jenkins-scripts/templates-daily-build.py b/tools/jenkins-scripts/templates-daily-build.py index a6da52b9ca..2d56400daf 100644 --- a/tools/jenkins-scripts/templates-daily-build.py +++ b/tools/jenkins-scripts/templates-daily-build.py @@ -17,7 +17,13 @@ else: if('NODE_NAME' in os.environ): node_name = os.environ['NODE_NAME'] else: - node_name = 'ios' + node_name = 'windows-universal' + +if('language' in os.environ): + language = os.environ['language'] +else: + language = 'cpp' + # for local debugging purpose, you could change the value to 0 and run # this scripts in your local machine remote_build = 0 @@ -61,17 +67,17 @@ def do_build_slaves(): if(branch == 'v3' or branch == 'v4-develop'): slave_build_scripts = "" if(node_name == 'android') or (node_name == 'android_bak'): - slave_build_scripts = jenkins_script_path + "android-build.sh lua" + slave_build_scripts = jenkins_script_path + "android-build.sh " + language elif(node_name == 'win32' or node_name == 'win32_win7' or node_name == 'win32_bak'): - slave_build_scripts = jenkins_script_path + "win32-build.bat" + slave_build_scripts = jenkins_script_path + "win32-build.bat " + language elif(node_name == 'windows-universal' or node_name == 'windows-universal_bak'): - slave_build_scripts = jenkins_script_path + "windows-universal.bat" + slave_build_scripts = jenkins_script_path + "windows-universal.bat " + language elif(node_name == 'ios_mac' or node_name == 'ios' or node_name == 'ios_bak'): - slave_build_scripts = jenkins_script_path + "ios-build.sh js" + slave_build_scripts = jenkins_script_path + "ios-build.sh " + language elif(node_name == 'mac' or node_name == 'mac_bak'): - slave_build_scripts = jenkins_script_path + "mac-build.sh" + slave_build_scripts = jenkins_script_path + "mac-build.sh " + language elif(node_name == 'linux_centos' or node_name == 'linux' or node_name == 'linux_bak'): - slave_build_scripts = jenkins_script_path + "linux-build.sh lua" + slave_build_scripts = jenkins_script_path + "linux-build.sh " + language elif(node_name == 'wp8'): if(branch != 'v4'): slave_build_scripts = jenkins_script_path + "wp8-v3.bat" From 0ca645f7444bc0c10331ddecdace163f4130d03c Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 7 Jul 2015 16:54:03 +0800 Subject: [PATCH 35/43] add runtime daily build script --- tools/jenkins-scripts/runtime-daily-build.py | 129 ++++++++++++++++++ .../slave-scripts/runtime/android-build.sh | 12 ++ .../slave-scripts/runtime/ios-build.sh | 20 +++ .../slave-scripts/runtime/linux-build.sh | 13 ++ .../slave-scripts/runtime/mac-build.sh | 19 +++ .../slave-scripts/runtime/win32-build.bat | 14 ++ .../runtime/windows-universal.bat | 14 ++ 7 files changed, 221 insertions(+) create mode 100644 tools/jenkins-scripts/runtime-daily-build.py create mode 100755 tools/jenkins-scripts/slave-scripts/runtime/android-build.sh create mode 100755 tools/jenkins-scripts/slave-scripts/runtime/ios-build.sh create mode 100755 tools/jenkins-scripts/slave-scripts/runtime/linux-build.sh create mode 100755 tools/jenkins-scripts/slave-scripts/runtime/mac-build.sh create mode 100644 tools/jenkins-scripts/slave-scripts/runtime/win32-build.bat create mode 100755 tools/jenkins-scripts/slave-scripts/runtime/windows-universal.bat diff --git a/tools/jenkins-scripts/runtime-daily-build.py b/tools/jenkins-scripts/runtime-daily-build.py new file mode 100644 index 0000000000..40b674711c --- /dev/null +++ b/tools/jenkins-scripts/runtime-daily-build.py @@ -0,0 +1,129 @@ +#Cocos2D-X runtime project daily build + +import os +import sys +import traceback + +if('branch' in os.environ): + branch = os.environ['branch'] +else: + branch = 'v4-develop' + +if('WORKSPACE' in os.environ): + workspace = os.environ['WORKSPACE'] +else: + workspace = "." + +if('NODE_NAME' in os.environ): + node_name = os.environ['NODE_NAME'] +else: + node_name = 'win32' + +if('language' in os.environ): + language = os.environ['language'] +else: + language = 'lua' + +# for local debugging purpose, you could change the value to 0 and run +# this scripts in your local machine +remote_build = 0 + +def download_3rd_library(): + #run download-deps.py + print("prepare to downloading ...") + os.system('python download-deps.py -r no') + + +def sync_remote_repo(): + #reset path to workspace root + os.system("cd " + workspace) + + #pull latest code + os.system("git fetch origin " + branch) + os.system("git checkout " + branch) + os.system("git merge origin/" + branch) + #clean workspace + print "Before checkout: git clean -xdf -f" + os.system("git clean -xdf -f") + + #update submodule + git_update_submodule = "git submodule update --init --force" + ret = os.system(git_update_submodule) + if(ret != 0): + sys.exit(ret) + + +def gen_scripting_bindings(): + # Generate binding glue codes + if(branch == 'v3' or branch == 'v4-develop'): + ret = os.system("python tools/jenkins-scripts/slave-scripts/gen_jsb.py") + if(ret != 0): + sys.exit(ret) + + +def do_build_slaves(): + jenkins_script_path = "tools" + os.sep + "jenkins-scripts" + os.sep + "slave-scripts" + os.sep + "runtime" + os.sep + + if(branch == 'v3' or branch == 'v4-develop'): + slave_build_scripts = "" + if(node_name == 'android') or (node_name == 'android_bak'): + slave_build_scripts = jenkins_script_path + "android-build.sh " + language + elif(node_name == 'win32' or node_name == 'win32_win7' or node_name == 'win32_bak'): + slave_build_scripts = jenkins_script_path + "win32-build.bat " + language + elif(node_name == 'windows-universal' or node_name == 'windows-universal_bak'): + slave_build_scripts = jenkins_script_path + "windows-universal.bat " + language + elif(node_name == 'ios_mac' or node_name == 'ios' or node_name == 'ios_bak'): + slave_build_scripts = jenkins_script_path + "ios-build.sh " + language + elif(node_name == 'mac' or node_name == 'mac_bak'): + slave_build_scripts = jenkins_script_path + "mac-build.sh " + language + elif(node_name == 'linux_centos' or node_name == 'linux' or node_name == 'linux_bak'): + slave_build_scripts = jenkins_script_path + "linux-build.sh " + language + elif(node_name == 'wp8'): + if(branch != 'v4'): + slave_build_scripts = jenkins_script_path + "wp8-v3.bat" + + ret = os.system(slave_build_scripts) + + #get build result + print "build finished and return " + str(ret) + return ret + + +def main(): + if remote_build == 1: + #syntronize local git repository with remote and merge the PR + sync_remote_repo() + #copy check_current_3rd_libs + download_3rd_library() + #generate jsb and luabindings + gen_scripting_bindings() + + #start build jobs on each slave + ret = do_build_slaves() + + exit_code = 1 + if ret == 0: + exit_code = 0 + else: + exit_code = 1 + + #clean workspace, we don't won't clean the repository + if remote_build == 1: + os.system("cd " + workspace) + os.system("git reset --hard") + os.system("git clean -xdf -f") + else: + print "local build, no need to cleanup" + + return(exit_code) + +# -------------- main -------------- +if __name__ == '__main__': + sys_ret = 0 + try: + sys_ret = main() + except: + traceback.print_exc() + sys_ret = 1 + finally: + sys.exit(sys_ret) diff --git a/tools/jenkins-scripts/slave-scripts/runtime/android-build.sh b/tools/jenkins-scripts/slave-scripts/runtime/android-build.sh new file mode 100755 index 0000000000..d9b019a866 --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/runtime/android-build.sh @@ -0,0 +1,12 @@ +#!/bin/bash +mycocos=tools/cocos2d-console/bin/cocos +$mycocos new -l $1 -t runtime +if [ $1 = "cpp" ];then + projectname="MyCppGame" +elif [ $1 = "lua" ];then + projectname="MyLuaGame" +elif [ $1 = "js" ];then + projectname="MyJSGame" +fi + +$mycocos compile -p android -s $projectname --android-studio -j4 --ndk-mode release --compile-script 0 diff --git a/tools/jenkins-scripts/slave-scripts/runtime/ios-build.sh b/tools/jenkins-scripts/slave-scripts/runtime/ios-build.sh new file mode 100755 index 0000000000..98c78458ef --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/runtime/ios-build.sh @@ -0,0 +1,20 @@ +#!/bin/bash +mycocos=tools/cocos2d-console/bin/cocos +$mycocos new -l $1 -t runtime + +if [ $1 = "cpp" ];then + schemename="MyCppGame-mobile" + projectpath="MyCppGame/proj.ios_mac/MyCppGame.xcodeproj" +elif [ $1 = "lua" ];then + schemename="MyLuaGame-mobile" + projectpath="MyLuaGame/frameworks/runtime-src/proj.ios_mac/MyLuaGame.xcodeproj" +elif [ $1 = "js" ];then + schemename="MyJSGame-mobile" + projectpath="MyJSGame/frameworks/runtime-src/proj.ios_mac/MyJSGame.xcodeproj" +fi + +echo "start building..." +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty +#the following commands must not be removed +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build diff --git a/tools/jenkins-scripts/slave-scripts/runtime/linux-build.sh b/tools/jenkins-scripts/slave-scripts/runtime/linux-build.sh new file mode 100755 index 0000000000..7c051bfc22 --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/runtime/linux-build.sh @@ -0,0 +1,13 @@ +#!/bin/bash +mycocos=tools/cocos2d-console/bin/cocos +$mycocos new -l $1 + +if [ $1 = "cpp" ]; then + projectname="MyCppGame" +elif [ $1 = "lua" ]; then + projectname="MyLuaGame" +elif [ $1 = "js" ]; then + projectname="MyJSGame" +fi + +$mycocos compile -p linux -s $projectname -m release -j4 --compile-script 0 diff --git a/tools/jenkins-scripts/slave-scripts/runtime/mac-build.sh b/tools/jenkins-scripts/slave-scripts/runtime/mac-build.sh new file mode 100755 index 0000000000..8d18c0af81 --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/runtime/mac-build.sh @@ -0,0 +1,19 @@ +#!/bin/bash +mycocos=tools/cocos2d-console/bin/cocos +$mycocos new -l $1 -t runtime + +if [ $1 = "cpp" ];then + schemename="MyCppGame-desktop" + projectpath="MyCppGame/proj.ios_mac/MyCppGame.xcodeproj" +elif [ $1 = "lua" ];then + schemename="MyLuaGame-desktop" + projectpath="MyLuaGame/frameworks/runtime-src/proj.ios_mac/MyLuaGame.xcodeproj" +elif [ $1 = "js" ];then + schemename="MyJSGame-desktop" + projectpath="MyJSGame/frameworks/runtime-src/proj.ios_mac/MyJSGame.xcodeproj" +fi + +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty +#the following commands must not be removed +xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build diff --git a/tools/jenkins-scripts/slave-scripts/runtime/win32-build.bat b/tools/jenkins-scripts/slave-scripts/runtime/win32-build.bat new file mode 100644 index 0000000000..43dc1ba890 --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/runtime/win32-build.bat @@ -0,0 +1,14 @@ +@echo on + +set mycocos=tools/cocos2d-console/bin/cocos.bat +set language=%1 +call %mycocos% new -l %language% -t runtime + +set projectname= +if "%language%"=="cpp" set projectname=MyCppGame/proj.win32/MyCppGame.sln +if "%language%"=="lua" set projectname=MyLuaGame/frameworks/runtime-src/proj.win32/MyLuaGame.sln +if "%language%"=="js" set projectname=MyJSGame/frameworks/runtime-src/proj.win32/MyJSGame.sln + +echo %projectname% +call "%VS120COMNTOOLS%vsvars32.bat" +msbuild %projectname% /t:Build /p:Platform="Win32" /p:Configuration="Release" /m diff --git a/tools/jenkins-scripts/slave-scripts/runtime/windows-universal.bat b/tools/jenkins-scripts/slave-scripts/runtime/windows-universal.bat new file mode 100755 index 0000000000..4def9c437e --- /dev/null +++ b/tools/jenkins-scripts/slave-scripts/runtime/windows-universal.bat @@ -0,0 +1,14 @@ +@echo on + +set mycocos=tools/cocos2d-console/bin/cocos.bat +set language=%1 +call %mycocos% new -l %language% + +set projectname= +if "%language%"=="cpp" set projectname=MyCppGame/proj.win8.1-universal/MyCppGame.sln +if "%language%"=="lua" set projectname=MyLuaGame/frameworks/runtime-src/proj.win8.1-universal/MyLuaGame.sln +if "%language%"=="js" set projectname=MyJSGame/frameworks/runtime-src/proj.win8.1-universal/MyJSGame.sln + +echo %projectname% +call "%VS120COMNTOOLS%vsvars32.bat" +msbuild %projectname% /t:Build /p:Platform="Win32" /p:Configuration="Release" /m From a18116aaa462a4420b1755beaac808570b4cd1fb Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 7 Jul 2015 16:56:38 +0800 Subject: [PATCH 36/43] minor improvements --- tools/jenkins-scripts/daily-build.py | 16 ++++++---------- tools/jenkins-scripts/runtime-daily-build.py | 2 +- tools/jenkins-scripts/templates-daily-build.py | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tools/jenkins-scripts/daily-build.py b/tools/jenkins-scripts/daily-build.py index e8a7bc271d..107e1292f5 100644 --- a/tools/jenkins-scripts/daily-build.py +++ b/tools/jenkins-scripts/daily-build.py @@ -102,16 +102,12 @@ def main(): exit_code = 1 # #clean workspace, we don't won't clean the repository - # if remote_build == 1: - # os.system("cd " + workspace) - # os.system("git reset --hard") - # os.system("git clean -xdf -f") - # else: - # print "local build, no need to cleanup" - #remove stats module - os.system("cd " + workspace) - os.system("rm tools/cocos2d-console/bin/cocos_stat.py") - os.system("rm tools/cocos2d-console/bin/cocos_stat.pyc") + if remote_build == 1: + os.system("cd " + workspace) + os.system("git reset --hard") + os.system("git clean -xdf -f") + else: + print "local build, no need to cleanup" return(exit_code) diff --git a/tools/jenkins-scripts/runtime-daily-build.py b/tools/jenkins-scripts/runtime-daily-build.py index 40b674711c..23d52bd7d2 100644 --- a/tools/jenkins-scripts/runtime-daily-build.py +++ b/tools/jenkins-scripts/runtime-daily-build.py @@ -26,7 +26,7 @@ else: # for local debugging purpose, you could change the value to 0 and run # this scripts in your local machine -remote_build = 0 +remote_build = 1 def download_3rd_library(): #run download-deps.py diff --git a/tools/jenkins-scripts/templates-daily-build.py b/tools/jenkins-scripts/templates-daily-build.py index 2d56400daf..ffa29780ab 100644 --- a/tools/jenkins-scripts/templates-daily-build.py +++ b/tools/jenkins-scripts/templates-daily-build.py @@ -26,7 +26,7 @@ else: # for local debugging purpose, you could change the value to 0 and run # this scripts in your local machine -remote_build = 0 +remote_build = 1 def download_3rd_library(): #run download-deps.py From 160bff8e131a59ff723c592d5291b44cdce1b9bd Mon Sep 17 00:00:00 2001 From: Neo Kim Date: Tue, 7 Jul 2015 18:47:20 +0900 Subject: [PATCH 37/43] Add a setter for line width in DrawNode --- cocos/2d/CCDrawNode.cpp | 11 ++++++++++- cocos/2d/CCDrawNode.h | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 2d04abb00f..e959584dab 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -104,6 +104,8 @@ static inline Tex2F __t(const Vec2 &v) // implementation of DrawNode +static const int DEFAULT_LINE_WIDTH = 2; + DrawNode::DrawNode() : _vao(0) , _vbo(0) @@ -123,6 +125,7 @@ DrawNode::DrawNode() , _dirty(false) , _dirtyGLPoint(false) , _dirtyGLLine(false) +, _lineWidth(DEFAULT_LINE_WIDTH) { _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; } @@ -393,7 +396,7 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags) // texcood glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords)); } - glLineWidth(2); + glLineWidth(_lineWidth); glDrawArrays(GL_LINES, 0, _bufferCountGLLine); if (Configuration::getInstance()->supportsShareableVAO()) @@ -921,6 +924,7 @@ void DrawNode::clear() _dirtyGLLine = true; _bufferCountGLPoint = 0; _dirtyGLPoint = true; + _lineWidth = DEFAULT_LINE_WIDTH; } const BlendFunc& DrawNode::getBlendFunc() const @@ -933,4 +937,9 @@ void DrawNode::setBlendFunc(const BlendFunc &blendFunc) _blendFunc = blendFunc; } +void DrawNode::setLineWidth(int lineWidth) +{ + _lineWidth = lineWidth; +} + NS_CC_END diff --git a/cocos/2d/CCDrawNode.h b/cocos/2d/CCDrawNode.h index 712fc8ac3b..ed51254eac 100644 --- a/cocos/2d/CCDrawNode.h +++ b/cocos/2d/CCDrawNode.h @@ -311,6 +311,8 @@ public: // Overrides virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; + void setLineWidth(int lineWidth); + CC_CONSTRUCTOR_ACCESS: DrawNode(); virtual ~DrawNode(); @@ -350,6 +352,8 @@ protected: bool _dirty; bool _dirtyGLPoint; bool _dirtyGLLine; + + int _lineWidth; private: CC_DISALLOW_COPY_AND_ASSIGN(DrawNode); From a567b7b7958acfb5ccaad306f10d80ad5805059e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E9=BE=99=E5=B1=B1=E4=BA=BA?= Date: Tue, 7 Jul 2015 17:52:58 +0800 Subject: [PATCH 38/43] Update Authors --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 48c64d9af2..647deb53fd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -7,6 +7,7 @@ Core Developers: XiaoMing Zhang (Minggo) JianHua Chen (James) Zhe Wang (Walzer) + Hao Wu (Wu-Hao) Qingkui Hu (samuele3hu) Huabing Xu (dabingnn) Wenhai Lin (Dhilan007) From 451bedbaad56fbb4d7dc6a195caffe29dafe258c Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 7 Jul 2015 22:02:35 +0800 Subject: [PATCH 39/43] change sign team to none. --- .../HelloCpp.xcodeproj/project.pbxproj | 5 - .../HelloJavascript.xcodeproj/project.pbxproj | 5 - .../HelloJavascript.xcodeproj/project.pbxproj | 121 ++++++++---------- .../HelloLua.xcodeproj/project.pbxproj | 5 - 4 files changed, 52 insertions(+), 84 deletions(-) diff --git a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj index ccef05cd71..4174d70698 100644 --- a/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj +++ b/templates/cpp-template-default/proj.ios_mac/HelloCpp.xcodeproj/project.pbxproj @@ -391,11 +391,6 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 0500; - TargetAttributes = { - 1D6058900D05DD3D006BFB54 = { - DevelopmentTeam = MDDB52YB8L; - }; - }; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "HelloCpp" */; compatibilityVersion = "Xcode 3.2"; diff --git a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj index 02ca1a94b3..3e813d3421 100644 --- a/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj +++ b/templates/js-template-default/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj @@ -539,11 +539,6 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 0500; - TargetAttributes = { - A922753C1517C094001B78AA = { - DevelopmentTeam = MDDB52YB8L; - }; - }; }; buildConfigurationList = A92275371517C094001B78AA /* Build configuration list for PBXProject "HelloJavascript" */; compatibilityVersion = "Xcode 3.2"; diff --git a/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj b/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj index 3c49e23c65..904959c8cb 100644 --- a/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj +++ b/templates/js-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloJavascript.xcodeproj/project.pbxproj @@ -190,34 +190,6 @@ remoteGlobalIDString = A07A4D641783777C0073F6A7; remoteInfo = "cocos2dx iOS"; }; - 9FFEB9B71A6AB8810095C43A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 9FFEB9B21A6AB8810095C43A /* libsimulator.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9F7214351A5C271F00DAED06; - remoteInfo = "libsimulator Mac"; - }; - 9FFEB9B91A6AB8810095C43A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 9FFEB9B21A6AB8810095C43A /* libsimulator.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9F7214851A5C28BA00DAED06; - remoteInfo = "libsimulator iOS"; - }; - 9FFEB9BB1A6AB8940095C43A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 9FFEB9B21A6AB8810095C43A /* libsimulator.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 9F7214341A5C271F00DAED06; - remoteInfo = "libsimulator Mac"; - }; - 9FFEB9BD1A6AB89B0095C43A /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 9FFEB9B21A6AB8810095C43A /* libsimulator.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 9F7214841A5C28BA00DAED06; - remoteInfo = "libsimulator iOS"; - }; 1AC6FB57180E9ACB004C840B /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 1AC6FB34180E9ACB004C840B /* cocos2d_libs.xcodeproj */; @@ -246,6 +218,34 @@ remoteGlobalIDString = A07A4FB4178387730073F6A7; remoteInfo = "CocosDenshion iOS"; }; + 9FFEB9B71A6AB8810095C43A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 9FFEB9B21A6AB8810095C43A /* libsimulator.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 9F7214351A5C271F00DAED06; + remoteInfo = "libsimulator Mac"; + }; + 9FFEB9B91A6AB8810095C43A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 9FFEB9B21A6AB8810095C43A /* libsimulator.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 9F7214851A5C28BA00DAED06; + remoteInfo = "libsimulator iOS"; + }; + 9FFEB9BB1A6AB8940095C43A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 9FFEB9B21A6AB8810095C43A /* libsimulator.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 9F7214341A5C271F00DAED06; + remoteInfo = "libsimulator Mac"; + }; + 9FFEB9BD1A6AB89B0095C43A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 9FFEB9B21A6AB8810095C43A /* libsimulator.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 9F7214841A5C28BA00DAED06; + remoteInfo = "libsimulator iOS"; + }; C037820618BF76AF00FE4F13 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = C037820118BF76AF00FE4F13 /* cocos2d_js_bindings.xcodeproj */; @@ -563,8 +563,6 @@ A92275401517C094001B78AA /* Frameworks */ = { isa = PBXGroup; children = ( - BA4E718219EB6E4600932425 /* GameController.framework */, - BA4E718019EB6E3E00932425 /* MediaPlayer.framework */, 87D4C4441AB2187000F68C44 /* Security.framework */, 9F20C9E11A5BBE85006FB50B /* Security.framework */, D6B061231803AB9F0077942B /* CoreMotion.framework */, @@ -691,11 +689,6 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 0500; - TargetAttributes = { - A922753C1517C094001B78AA = { - DevelopmentTeam = MDDB52YB8L; - }; - }; }; buildConfigurationList = A92275371517C094001B78AA /* Build configuration list for PBXProject "HelloJavascript" */; compatibilityVersion = "Xcode 3.2"; @@ -780,20 +773,6 @@ path = "libcocos2dx-extensions iOS.a"; remoteRef = 1AC6FB57180E9ACB004C840B /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; - }; - 9FFEB9B81A6AB8810095C43A /* libsimulator Mac.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libsimulator Mac.a"; - remoteRef = 9FFEB9B71A6AB8810095C43A /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 9FFEB9BA1A6AB8810095C43A /* libsimulator iOS.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libsimulator iOS.a"; - remoteRef = 9FFEB9B91A6AB8810095C43A /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; }; 1AC6FB5A180E9ACB004C840B /* libchipmunk iOS.a */ = { isa = PBXReferenceProxy; @@ -816,6 +795,20 @@ remoteRef = 1AC6FB5D180E9ACB004C840B /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + 9FFEB9B81A6AB8810095C43A /* libsimulator Mac.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = "libsimulator Mac.a"; + remoteRef = 9FFEB9B71A6AB8810095C43A /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 9FFEB9BA1A6AB8810095C43A /* libsimulator iOS.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = "libsimulator iOS.a"; + remoteRef = 9FFEB9B91A6AB8810095C43A /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; C037820718BF76AF00FE4F13 /* libjscocos2d Mac.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -903,18 +896,8 @@ buildActionMask = 2147483647; files = ( 9FD1E6B61A51361B0009A6C5 /* PlayerFileDialogServiceMac.mm in Sources */, - 3E12D1E61957FB18002FF0FD /* common.cc in Sources */, 9FD1E6B51A51361B0009A6C5 /* PlayerEditBoxServiceMac.mm in Sources */, - 9FD1E6EE1A5169230009A6C5 /* AppLang.cpp in Sources */, 9FD1E6B21A51361B0009A6C5 /* ConsoleWindowController.m in Sources */, - 3E12D1E81957FB18002FF0FD /* once.cc in Sources */, - 9FD1E6ED1A5169230009A6C5 /* AppEvent.cpp in Sources */, - 3E12D1E01957FB18002FF0FD /* message_lite.cc in Sources */, - 3E12D1D61957FB18002FF0FD /* extension_set.cc in Sources */, - C00FD4B51938628E00C6382D /* PlayDisable_png.cpp in Sources */, - AB9079D519E931D80033128B /* ConsoleCommand.cpp in Sources */, - 3E12D1EA1957FB18002FF0FD /* stringprintf.cc in Sources */, - C06C37891918E81100617BED /* ConfigParser.cpp in Sources */, 9FD1E6B71A51361B0009A6C5 /* PlayerMac.mm in Sources */, 509D4A8117EBB24E00697056 /* AppDelegate.cpp in Sources */, 9FD1E6BA1A51361B0009A6C5 /* PlayerTaskServiceMac.mm in Sources */, @@ -969,16 +952,6 @@ name = "cocos2dx iOS"; targetProxy = 1A67682E180E9C110076BC67 /* PBXContainerItemProxy */; }; - 9FFEB9BC1A6AB8940095C43A /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = "libsimulator Mac"; - targetProxy = 9FFEB9BB1A6AB8940095C43A /* PBXContainerItemProxy */; - }; - 9FFEB9BE1A6AB89B0095C43A /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = "libsimulator iOS"; - targetProxy = 9FFEB9BD1A6AB89B0095C43A /* PBXContainerItemProxy */; - }; 1A676831180E9C110076BC67 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = "cocos2dx-extensions iOS"; @@ -994,6 +967,16 @@ name = "CocosDenshion iOS"; targetProxy = 1A676834180E9C110076BC67 /* PBXContainerItemProxy */; }; + 9FFEB9BC1A6AB8940095C43A /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = "libsimulator Mac"; + targetProxy = 9FFEB9BB1A6AB8940095C43A /* PBXContainerItemProxy */; + }; + 9FFEB9BE1A6AB89B0095C43A /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = "libsimulator iOS"; + targetProxy = 9FFEB9BD1A6AB89B0095C43A /* PBXContainerItemProxy */; + }; C037820B18BF77BC00FE4F13 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = "jsbindings iOS"; diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj index a132ea77cd..4228649c4c 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj +++ b/templates/lua-template-default/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj @@ -518,11 +518,6 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 0500; - TargetAttributes = { - F293B3C715EB7BE500256477 = { - DevelopmentTeam = MDDB52YB8L; - }; - }; }; buildConfigurationList = F293B3C215EB7BE500256477 /* Build configuration list for PBXProject "HelloLua" */; compatibilityVersion = "Xcode 3.2"; From 29dcbe6685b78abb25f809dc880a8e43930ecdcb Mon Sep 17 00:00:00 2001 From: xpol Date: Tue, 7 Jul 2015 23:01:24 +0800 Subject: [PATCH 40/43] Fixes some warnings and a related bug in CCSprite. This story tells us that we should not just ignore warnings. --- cocos/2d/CCClippingNode.cpp | 2 +- cocos/2d/CCSprite.cpp | 4 ++-- cocos/3d/CCObjLoader.cpp | 2 +- cocos/3d/CCTerrain.cpp | 14 +++++++------- .../cocostudio/ActionTimeline/CCTimeLine.cpp | 10 +++++----- .../cocostudio/ActionTimeline/CCTimeLine.h | 16 ++++++++-------- .../WidgetReader/TextReader/TextReader.cpp | 4 ++-- cocos/ui/UILayout.cpp | 2 +- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index a2b3e04e0b..664c695738 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -492,7 +492,7 @@ void ClippingNode::onAfterDrawStencil() // restore the depth test state glDepthMask(_currentDepthWriteMask); - RenderState::StateBlock::_defaultState->setDepthWrite(_currentDepthWriteMask); + RenderState::StateBlock::_defaultState->setDepthWrite(_currentDepthWriteMask != 0); //if (currentDepthTestEnabled) { // glEnable(GL_DEPTH_TEST); diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 5482e8934c..30b153a40c 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -223,7 +223,7 @@ bool Sprite::initWithPolygon(const cocos2d::PolygonInfo &info) { Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(info.filename); bool res = false; - if(initWithTexture(texture)); + if(initWithTexture(texture)) { _polyInfo = info; setContentSize(_polyInfo.rect.size/Director::getInstance()->getContentScaleFactor()); @@ -449,7 +449,7 @@ void Sprite::debugDraw(bool on) auto last = _polyInfo.triangles.indexCount/3; auto _indices = _polyInfo.triangles.indices; auto _verts = _polyInfo.triangles.verts; - for(unsigned int i = 0; i < last; i++) + for(ssize_t i = 0; i < last; i++) { //draw 3 lines Vec3 from =_verts[_indices[i*3]].vertices; diff --git a/cocos/3d/CCObjLoader.cpp b/cocos/3d/CCObjLoader.cpp index 2facde285d..f4e8bb2ae1 100644 --- a/cocos/3d/CCObjLoader.cpp +++ b/cocos/3d/CCObjLoader.cpp @@ -275,7 +275,7 @@ void InitMaterial(ObjLoader::material_t& material) static std::string& replacePathSeperator(std::string& path) { - for (int i = 0; i < path.size(); i++) { + for (size_t i = 0; i < path.size(); i++) { if (path[i] == '\\') path[i] = '/'; } diff --git a/cocos/3d/CCTerrain.cpp b/cocos/3d/CCTerrain.cpp index ce645e0810..2ad2b5ff9d 100644 --- a/cocos/3d/CCTerrain.cpp +++ b/cocos/3d/CCTerrain.cpp @@ -460,12 +460,12 @@ Terrain::~Terrain() } } - for(int i =0;i<_chunkLodIndicesSet.size();i++) + for(size_t i =0;i<_chunkLodIndicesSet.size();i++) { glDeleteBuffers(1,&(_chunkLodIndicesSet[i]._chunkIndices._indices)); } - for(int i =0;i<_chunkLodIndicesSkirtSet.size();i++) + for(size_t i =0;i<_chunkLodIndicesSkirtSet.size();i++) { glDeleteBuffers(1,&(_chunkLodIndicesSkirtSet[i]._chunkIndices._indices)); } @@ -686,7 +686,7 @@ Terrain::ChunkIndices Terrain::lookForIndicesLOD(int neighborLod[4], int selfLod int test[5]; memcpy(test,neighborLod,sizeof(int [4])); test[4] = selfLod; - for(int i =0;i<_chunkLodIndicesSet.size();i++) + for(size_t i =0;i<_chunkLodIndicesSet.size();i++) { if(memcmp(test,_chunkLodIndicesSet[i]._relativeLod,sizeof(test))==0) { @@ -723,7 +723,7 @@ Terrain::ChunkIndices Terrain::lookForIndicesLODSkrit(int selfLod, bool * result return badResult; } - for(int i =0;i<_chunkLodIndicesSkirtSet.size();i++) + for(size_t i =0;i<_chunkLodIndicesSkirtSet.size();i++) { if(_chunkLodIndicesSkirtSet[i]._selfLod == selfLod) { @@ -1234,7 +1234,7 @@ void Terrain::Chunk::updateIndicesLOD() void Terrain::Chunk::calculateAABB() { std::vectorpos; - for(int i =0;i<_originalVertices.size();i++) + for(size_t i =0;i<_originalVertices.size();i++) { pos.push_back(_originalVertices[i]._position); } @@ -1245,7 +1245,7 @@ void Terrain::Chunk::calculateSlope() { //find max slope auto lowest = _originalVertices[0]._position; - for(int i = 0;i<_originalVertices.size();i++) + for(size_t i = 0;i<_originalVertices.size();i++) { if(_originalVertices[i]._position.y< lowest.y) { @@ -1253,7 +1253,7 @@ void Terrain::Chunk::calculateSlope() } } auto highest = _originalVertices[0]._position; - for(int i = 0;i<_originalVertices.size();i++) + for(size_t i = 0;i<_originalVertices.size();i++) { if(_originalVertices[i]._position.y> highest.y) { diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp index 662f368724..1e1c0f489e 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp @@ -120,7 +120,7 @@ Node* Timeline::getNode() const return _node; } -void Timeline::apply(int frameIndex) +void Timeline::apply(unsigned int frameIndex) { if (_currentKeyFrame) { @@ -129,7 +129,7 @@ void Timeline::apply(int frameIndex) } } -void Timeline::binarySearchKeyFrame(int frameIndex) +void Timeline::binarySearchKeyFrame(unsigned int frameIndex) { Frame *from = nullptr; Frame *to = nullptr; @@ -202,7 +202,7 @@ void Timeline::binarySearchKeyFrame(int frameIndex) } } -void Timeline::updateCurrentKeyFrame(int frameIndex) +void Timeline::updateCurrentKeyFrame(unsigned int frameIndex) { //! If play to current frame's front or back, then find current frame again if (frameIndex < _currentKeyFrameIndex || frameIndex >= _currentKeyFrameIndex + _betweenDuration) @@ -223,7 +223,7 @@ void Timeline::updateCurrentKeyFrame(int frameIndex) } else if(frameIndex >= _frames.at(length - 1)->getFrameIndex()) { - int lastFrameIndex = _frames.at(length - 1)->getFrameIndex(); + unsigned int lastFrameIndex = _frames.at(length - 1)->getFrameIndex(); if(_currentKeyFrameIndex >= lastFrameIndex) return; frameIndex = lastFrameIndex; @@ -236,7 +236,7 @@ void Timeline::updateCurrentKeyFrame(int frameIndex) _currentKeyFrameIndex = from->getFrameIndex(); _toIndex = _fromIndex + 1; - if (_toIndex >= length) + if ((ssize_t)_toIndex >= length) { _toIndex = 0; } diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.h b/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.h index 753e60364a..27bf766886 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.h @@ -62,19 +62,19 @@ public: virtual Timeline* clone(); protected: - virtual void apply(int frameIndex); + virtual void apply(unsigned int frameIndex); - virtual void binarySearchKeyFrame (int frameIndex); - virtual void updateCurrentKeyFrame(int frameIndex); + virtual void binarySearchKeyFrame (unsigned int frameIndex); + virtual void updateCurrentKeyFrame(unsigned int frameIndex); cocos2d::Vector _frames; Frame* _currentKeyFrame; - int _currentKeyFrameIndex; + unsigned int _currentKeyFrameIndex; - int _fromIndex; - int _toIndex; - int _betweenDuration; - int _actionTag; + unsigned int _fromIndex; + unsigned int _toIndex; + unsigned int _betweenDuration; + unsigned int _actionTag; ActionTimeline* _ActionTimeline; cocos2d::Node* _node; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index d53bfa4442..173aeac4f9 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -448,7 +448,7 @@ namespace cocostudio //} } - bool outlineEnabled = options->outlineEnabled(); + bool outlineEnabled = options->outlineEnabled() != 0; if (outlineEnabled) { auto f_outlineColor = options->outlineColor(); @@ -459,7 +459,7 @@ namespace cocostudio } } - bool shadowEnabled = options->shadowEnabled(); + bool shadowEnabled = options->shadowEnabled() != 0; if (shadowEnabled) { auto f_shadowColor = options->shadowColor(); diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index 6619d292f6..80b72c3ce1 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -410,7 +410,7 @@ void Layout::drawFullScreenQuadClearStencil() void Layout::onAfterDrawStencil() { glDepthMask(_currentDepthWriteMask); - RenderState::StateBlock::_defaultState->setDepthWrite(_currentDepthWriteMask); + RenderState::StateBlock::_defaultState->setDepthWrite(_currentDepthWriteMask != 0); glStencilFunc(GL_EQUAL, _mask_layer_le, _mask_layer_le); // RenderState::StateBlock::_defaultState->setStencilFunction( From 8179fe04f040756e2f53c4ded86abe163ec01c06 Mon Sep 17 00:00:00 2001 From: xpol Date: Tue, 7 Jul 2015 23:10:04 +0800 Subject: [PATCH 41/43] And more warnings. --- .../cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp | 4 ++-- extensions/Particle3D/CCParticleSystem3D.cpp | 2 +- extensions/Particle3D/PU/CCPUOnQuotaObserver.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index 357169531c..c64b9e1aa0 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -885,7 +885,7 @@ namespace cocostudio button->setBright(displaystate); button->setEnabled(displaystate); - bool outlineEnabled = options->outlineEnabled(); + bool outlineEnabled = options->outlineEnabled() != 0; if (outlineEnabled) { auto f_outlineColor = options->outlineColor(); @@ -897,7 +897,7 @@ namespace cocostudio } } - bool shadowEnabled = options->shadowEnabled(); + bool shadowEnabled = options->shadowEnabled() != 0; if (shadowEnabled) { auto f_shadowColor = options->shadowColor(); diff --git a/extensions/Particle3D/CCParticleSystem3D.cpp b/extensions/Particle3D/CCParticleSystem3D.cpp index 8ba10c2fd4..7c13e58624 100755 --- a/extensions/Particle3D/CCParticleSystem3D.cpp +++ b/extensions/Particle3D/CCParticleSystem3D.cpp @@ -152,7 +152,7 @@ void ParticleSystem3D::removeAllAffector() Particle3DAffector* ParticleSystem3D::getAffector(int index) { - CCASSERT(index < _affectors.size(), "wrong index"); + CCASSERT(index < (int)_affectors.size(), "wrong index"); return _affectors[index]; } diff --git a/extensions/Particle3D/PU/CCPUOnQuotaObserver.cpp b/extensions/Particle3D/PU/CCPUOnQuotaObserver.cpp index 82f2ff3a42..9d5b19ed44 100644 --- a/extensions/Particle3D/PU/CCPUOnQuotaObserver.cpp +++ b/extensions/Particle3D/PU/CCPUOnQuotaObserver.cpp @@ -63,7 +63,7 @@ void PUOnQuotaObserver::postUpdateObserver(float deltaTime) } //_result = particleTechnique->getNumberOfEmittedParticles(_particleTypeToObserve) >= quota; - _result = static_cast(_particleSystem)->getAliveParticleCount() >= quota; + _result = static_cast(_particleSystem)->getAliveParticleCount() >= (int)quota; } else { @@ -77,7 +77,7 @@ void PUOnQuotaObserver::postUpdateObserver(float deltaTime) + static_cast(_particleSystem)->getEmittedEmitterQuota() + static_cast(_particleSystem)->getEmittedSystemQuota(); //_result = particleTechnique->getNumberOfEmittedParticles() >= quota; - _result = static_cast(_particleSystem)->getAliveParticleCount() >= quota; + _result = static_cast(_particleSystem)->getAliveParticleCount() >= (int)quota; } } From dda07bebf55646d012d50f748ee07c4062f6f7b2 Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 8 Jul 2015 07:36:26 +0800 Subject: [PATCH 42/43] fix ios/mac/win32/win8.1 compile error --- .../slave-scripts/templates/ios-build.sh | 13 +++++++++---- .../slave-scripts/templates/mac-build.sh | 14 ++++++++++---- .../slave-scripts/templates/win32-build.bat | 2 +- .../slave-scripts/templates/windows-universal.bat | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh b/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh index 3dd3f90e9c..c55cfb227c 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh +++ b/tools/jenkins-scripts/slave-scripts/templates/ios-build.sh @@ -5,16 +5,21 @@ $mycocos new -l $1 if [ $1 = "cpp" ];then schemename="MyCppGame-mobile" projectpath="MyCppGame/proj.ios_mac/MyCppGame.xcodeproj" + cocos_project_path="MyCppGame" elif [ $1 = "lua" ];then schemename="MyLuaGame-mobile" projectpath="MyLuaGame/frameworks/runtime-src/proj.ios_mac/MyLuaGame.xcodeproj" + cocos_project_path="MyLuaGame" elif [ $1 = "js" ];then schemename="MyJSGame-mobile" projectpath="MyJSGame/frameworks/runtime-src/proj.ios_mac/MyJSGame.xcodeproj" + cocos_project_path="MyJSGame" fi echo "start building..." -xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty -xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty -#the following commands must not be removed -xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build +cocos compile -p ios -s $cocos_project_path | xcpretty +cocos compile -p ios -s $cocos_project_path +# xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty +# xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty +# #the following commands must not be removed +# xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build diff --git a/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh b/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh index bf66dbe939..177d67d5b3 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh +++ b/tools/jenkins-scripts/slave-scripts/templates/mac-build.sh @@ -5,15 +5,21 @@ $mycocos new -l $1 if [ $1 = "cpp" ];then schemename="MyCppGame-desktop" projectpath="MyCppGame/proj.ios_mac/MyCppGame.xcodeproj" + cocos_project_path="MyCppGame" elif [ $1 = "lua" ];then schemename="MyLuaGame-desktop" projectpath="MyLuaGame/frameworks/runtime-src/proj.ios_mac/MyLuaGame.xcodeproj" + cocos_project_path="MyLuaGame" elif [ $1 = "js" ];then schemename="MyJSGame-desktop" projectpath="MyJSGame/frameworks/runtime-src/proj.ios_mac/MyJSGame.xcodeproj" + cocos_project_path="MyJSGame" fi -xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty -xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty -#the following commands must not be removed -xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build +cocos compile -p mac -s $cocos_project_path | xcpretty +cocos compile -p mac -s $cocos_project_path + +# xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" clean | xcpretty +# xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty +# #the following commands must not be removed +# xcodebuild -project $projectpath -target "${schemename}" -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build diff --git a/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat b/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat index 17a863cf84..4184cc54d5 100644 --- a/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat +++ b/tools/jenkins-scripts/slave-scripts/templates/win32-build.bat @@ -11,4 +11,4 @@ if "%language%"=="js" set projectname=MyJSGame/frameworks/runtime-src/proj.win32 echo %projectname% call "%VS120COMNTOOLS%vsvars32.bat" -msbuild %projectname% /t:Build /p:Platform="Win32" /p:Configuration="Release" /m +msbuild %projectname% /t:Build diff --git a/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat b/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat index 4def9c437e..e1f23c44f5 100755 --- a/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat +++ b/tools/jenkins-scripts/slave-scripts/templates/windows-universal.bat @@ -11,4 +11,4 @@ if "%language%"=="js" set projectname=MyJSGame/frameworks/runtime-src/proj.win8. echo %projectname% call "%VS120COMNTOOLS%vsvars32.bat" -msbuild %projectname% /t:Build /p:Platform="Win32" /p:Configuration="Release" /m +msbuild %projectname% /t:Build From 9638ae628a2e1fcd90eb7e57dbb13816751da2e2 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Wed, 8 Jul 2015 05:48:55 +0000 Subject: [PATCH 43/43] [ci skip][AUTO]: updating luabinding & jsbinding automatically --- .../auto/api/jsb_cocos2dx_auto_api.js | 10 ++++ .../js-bindings/auto/jsb_cocos2dx_auto.cpp | 21 ++++++++ .../js-bindings/auto/jsb_cocos2dx_auto.hpp | 1 + .../lua-bindings/auto/api/DrawNode.lua | 7 +++ .../lua-bindings/auto/lua_cocos2dx_auto.cpp | 51 +++++++++++++++++++ .../lua-bindings/auto/lua_cocos2dx_auto.hpp | 1 + 6 files changed, 91 insertions(+) diff --git a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js index dee0f0f4a9..ef0eb44730 100644 --- a/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js +++ b/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_auto_api.js @@ -11148,6 +11148,16 @@ color4f { }, +/** + * @method setLineWidth + * @param {int} arg0 + */ +setLineWidth : function ( +int +) +{ +}, + /** * @method onDrawGLPoint * @param {mat4_object} arg0 diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp index 360f665600..84ce17c14c 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp @@ -34936,6 +34936,26 @@ bool js_cocos2dx_DrawNode_drawSolidCircle(JSContext *cx, uint32_t argc, jsval *v JS_ReportError(cx, "js_cocos2dx_DrawNode_drawSolidCircle : wrong number of arguments"); return false; } +bool js_cocos2dx_DrawNode_setLineWidth(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::DrawNode* cobj = (cocos2d::DrawNode *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_DrawNode_setLineWidth : Invalid Native Object"); + if (argc == 1) { + int arg0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_DrawNode_setLineWidth : Error processing arguments"); + cobj->setLineWidth(arg0); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_DrawNode_setLineWidth : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} bool js_cocos2dx_DrawNode_onDrawGLPoint(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -35536,6 +35556,7 @@ void js_register_cocos2dx_DrawNode(JSContext *cx, JS::HandleObject global) { JS_FN("drawPoints", js_cocos2dx_DrawNode_drawPoints, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("drawRect", js_cocos2dx_DrawNode_drawRect, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("drawSolidCircle", js_cocos2dx_DrawNode_drawSolidCircle, 5, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setLineWidth", js_cocos2dx_DrawNode_setLineWidth, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("onDrawGLPoint", js_cocos2dx_DrawNode_onDrawGLPoint, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("drawDot", js_cocos2dx_DrawNode_drawDot, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("drawCatmullRom", js_cocos2dx_DrawNode_drawCatmullRom, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE), diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp index c9ccd7e09a..80f8a96933 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp @@ -2122,6 +2122,7 @@ bool js_cocos2dx_DrawNode_drawLine(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawPoints(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawRect(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawSolidCircle(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_DrawNode_setLineWidth(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_onDrawGLPoint(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawDot(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_DrawNode_drawCatmullRom(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/cocos/scripting/lua-bindings/auto/api/DrawNode.lua b/cocos/scripting/lua-bindings/auto/api/DrawNode.lua index 402441ce43..4e2d0a5077 100644 --- a/cocos/scripting/lua-bindings/auto/api/DrawNode.lua +++ b/cocos/scripting/lua-bindings/auto/api/DrawNode.lua @@ -43,6 +43,13 @@ -- @param #color4f_table color -- @return DrawNode#DrawNode self (return value: cc.DrawNode) +-------------------------------- +-- +-- @function [parent=#DrawNode] setLineWidth +-- @param self +-- @param #int lineWidth +-- @return DrawNode#DrawNode self (return value: cc.DrawNode) + -------------------------------- -- js NA -- @function [parent=#DrawNode] onDrawGLPoint diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index 3518c1417e..25e6fc5e09 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -47134,6 +47134,56 @@ int lua_cocos2dx_DrawNode_drawSolidCircle(lua_State* tolua_S) return 0; } +int lua_cocos2dx_DrawNode_setLineWidth(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::DrawNode* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.DrawNode",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::DrawNode*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_DrawNode_setLineWidth'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + int arg0; + + ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.DrawNode:setLineWidth"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_DrawNode_setLineWidth'", nullptr); + return 0; + } + cobj->setLineWidth(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.DrawNode:setLineWidth",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_DrawNode_setLineWidth'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_DrawNode_onDrawGLPoint(lua_State* tolua_S) { int argc = 0; @@ -48040,6 +48090,7 @@ int lua_register_cocos2dx_DrawNode(lua_State* tolua_S) tolua_function(tolua_S,"drawLine",lua_cocos2dx_DrawNode_drawLine); tolua_function(tolua_S,"drawRect",lua_cocos2dx_DrawNode_drawRect); tolua_function(tolua_S,"drawSolidCircle",lua_cocos2dx_DrawNode_drawSolidCircle); + tolua_function(tolua_S,"setLineWidth",lua_cocos2dx_DrawNode_setLineWidth); tolua_function(tolua_S,"onDrawGLPoint",lua_cocos2dx_DrawNode_onDrawGLPoint); tolua_function(tolua_S,"drawDot",lua_cocos2dx_DrawNode_drawDot); tolua_function(tolua_S,"drawSegment",lua_cocos2dx_DrawNode_drawSegment); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index e33d58090e..999e6ca5b5 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -2062,6 +2062,7 @@ int register_all_cocos2dx(lua_State* tolua_S); + #endif // __cocos2dx_h__