diff --git a/CHANGELOG b/CHANGELOG index ea950c9a4b..d4a8c697dd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,11 +2,13 @@ cocos2d-x-3.6 ?? [NEW] 3rd: update chipmunk to v 6.2.2 on Windows 8.1 Universal App [NEW] 3rd: update freetype to v 2.5.5 on Windows 8.1 Universal App [NEW] Label: added LabelEffect::ALL which can be used in disableEffect(LabelEffect) to disable all effects + [NEW] Lua-binding: binded ui:WebView and added corresponidng test case [NEW] MathUtil: added `MathUtil::lerp()` [NEW] UserDefault: added `UserDefault::setDelegate()` [NEW] Vec2: added `Vec2::setZero()` [NEW] Vec3: added `Vec3::lerp()` [NEW] WP8: remove WP8 support because Angle don't support WP8 any more + [NEW] WP8.1: added back button support [FIX] JNI: JNI illegal start byte error which causes crashing error on Android 5.0 [FIX] UI:VideoPlayer: crashed when playing streamed MP4 file on iOS diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index fb4a899606..657bc74d48 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -1191,10 +1191,6 @@ 29394CF519B01DBA00D2DE1A /* UIWebViewImpl-ios.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEE19B01DBA00D2DE1A /* UIWebViewImpl-ios.h */; }; 29394CF619B01DBA00D2DE1A /* UIWebViewImpl-ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CEF19B01DBA00D2DE1A /* UIWebViewImpl-ios.mm */; }; 29394CF719B01DBA00D2DE1A /* UIWebViewImpl-ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CEF19B01DBA00D2DE1A /* UIWebViewImpl-ios.mm */; }; - 296BF6151A44059B0038EC44 /* UIShaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 296BF6141A44059B0038EC44 /* UIShaders.h */; }; - 296BF6161A44059B0038EC44 /* UIShaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 296BF6141A44059B0038EC44 /* UIShaders.h */; }; - 296BF6181A4405CB0038EC44 /* UIShaders.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 296BF6171A4405CB0038EC44 /* UIShaders.cpp */; }; - 296BF6191A4405CB0038EC44 /* UIShaders.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 296BF6171A4405CB0038EC44 /* UIShaders.cpp */; }; 2986667F18B1B246000E39CA /* CCTweenFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2986667818B1B079000E39CA /* CCTweenFunction.cpp */; }; 299754F4193EC95400A54AC3 /* ObjectFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */; }; 299754F5193EC95400A54AC3 /* ObjectFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */; }; @@ -3045,9 +3041,6 @@ 29394CEF19B01DBA00D2DE1A /* UIWebViewImpl-ios.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "UIWebViewImpl-ios.mm"; sourceTree = ""; }; 2958244919873D8E00F9746D /* UIScale9Sprite.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIScale9Sprite.cpp; sourceTree = ""; }; 2958244A19873D8E00F9746D /* UIScale9Sprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScale9Sprite.h; sourceTree = ""; }; - 296BF6131A4403380038EC44 /* ccShader_grayscale.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_grayscale.frag; sourceTree = ""; }; - 296BF6141A44059B0038EC44 /* UIShaders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIShaders.h; sourceTree = ""; }; - 296BF6171A4405CB0038EC44 /* UIShaders.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIShaders.cpp; sourceTree = ""; }; 2986667818B1B079000E39CA /* CCTweenFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTweenFunction.cpp; sourceTree = ""; }; 2986667918B1B079000E39CA /* CCTweenFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTweenFunction.h; sourceTree = ""; }; 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ObjectFactory.cpp; path = ../base/ObjectFactory.cpp; sourceTree = ""; }; @@ -5194,7 +5187,6 @@ 2905F9E618CF08D000240AA3 /* ui */ = { isa = PBXGroup; children = ( - 296BF6121A4403380038EC44 /* shaders */, 29CB8F531929D67D00C841D6 /* widgets */, 29CB8F521929D65500C841D6 /* experimental */, 29CB8F511929D64500C841D6 /* base */, @@ -5235,16 +5227,6 @@ name = mac; sourceTree = ""; }; - 296BF6121A4403380038EC44 /* shaders */ = { - isa = PBXGroup; - children = ( - 296BF6131A4403380038EC44 /* ccShader_grayscale.frag */, - 296BF6141A44059B0038EC44 /* UIShaders.h */, - 296BF6171A4405CB0038EC44 /* UIShaders.cpp */, - ); - path = shaders; - sourceTree = ""; - }; 29CB8F501929D63600C841D6 /* layout */ = { isa = PBXGroup; children = ( @@ -6903,7 +6885,6 @@ 15AE1C1219AAE2C600C27E9E /* CCPhysicsDebugNode.h in Headers */, B665E3381AA80A6500DDB1C5 /* CCPUOnEmissionObserverTranslator.h in Headers */, 50ABBE951925AB6F00A911A9 /* CCProfiling.h in Headers */, - 296BF6151A44059B0038EC44 /* UIShaders.h in Headers */, B665E2301AA80A6500DDB1C5 /* CCPUBoxColliderTranslator.h in Headers */, 5034CA4B191D591100CE6051 /* ccShader_Label_df_glow.frag in Headers */, 50ABBE4F1925AB6F00A911A9 /* CCEventCustom.h in Headers */, @@ -7448,7 +7429,6 @@ B665E2711AA80A6500DDB1C5 /* CCPUDoFreezeEventHandlerTranslator.h in Headers */, 1A570115180BC8EE0088DEC7 /* CCDrawNode.h in Headers */, 1A57011E180BC90D0088DEC7 /* CCGrabber.h in Headers */, - 296BF6161A44059B0038EC44 /* UIShaders.h in Headers */, 1A570122180BC90D0088DEC7 /* CCGrid.h in Headers */, 15AE1AB319AAD40300C27E9E /* b2CircleContact.h in Headers */, 5034CA2E191D591100CE6051 /* ccShader_PositionTextureA8Color.frag in Headers */, @@ -8598,7 +8578,6 @@ B665E3E61AA80A6600DDB1C5 /* CCPUSineForceAffectorTranslator.cpp in Sources */, 15AE1B5119AADA9900C27E9E /* UIPageView.cpp in Sources */, 15AE18EC19AAD35000C27E9E /* CCActionObject.cpp in Sources */, - 296BF6181A4405CB0038EC44 /* UIShaders.cpp in Sources */, B665E2821AA80A6500DDB1C5 /* CCPUDoStopSystemEventHandler.cpp in Sources */, 1A01C68E18F57BE800EFE3A6 /* CCDictionary.cpp in Sources */, 50ABBD381925AB0000A911A9 /* CCAffineTransform.cpp in Sources */, @@ -9075,7 +9054,6 @@ 182C5CD71A98F30500C30D34 /* Sprite3DReader.cpp in Sources */, 50ABC0061926664800A911A9 /* CCThread-apple.mm in Sources */, 50ABBEB61925AB6F00A911A9 /* CCUserDefault-android.cpp in Sources */, - 296BF6191A4405CB0038EC44 /* UIShaders.cpp in Sources */, 1A57034C180BD09B0088DEC7 /* tinyxml2.cpp in Sources */, 50ABBDB61925AB4100A911A9 /* CCTexture2D.cpp in Sources */, B665E2871AA80A6500DDB1C5 /* CCPUDoStopSystemEventHandlerTranslator.cpp in Sources */, diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 476b8f2e3c..76639c72ce 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -42,6 +42,8 @@ 1502702E1AD3BDC90089CD03 /* TerrainTest in Resources */ = {isa = PBXBuildFile; fileRef = B603F1B31AC8FBFB00A9579C /* TerrainTest */; }; 150F918819DA409E00B89F57 /* lua_test_bindings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150F918619DA409E00B89F57 /* lua_test_bindings.cpp */; }; 150F918919DA409F00B89F57 /* lua_test_bindings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 150F918619DA409E00B89F57 /* lua_test_bindings.cpp */; }; + 1531B2501AE013DE0075DB94 /* Test.html in Resources */ = {isa = PBXBuildFile; fileRef = 29AFEF6619ACCAA000F6B10A /* Test.html */; }; + 1531B2511AE013F00075DB94 /* Test.html in Resources */ = {isa = PBXBuildFile; fileRef = 29AFEF6619ACCAA000F6B10A /* Test.html */; }; 15427B79198B879900DC375D /* libluacocos2d iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 15EFA665198B33EE000C57D3 /* libluacocos2d iOS.a */; }; 15427B7A198B87AA00DC375D /* libcocos2d iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 46A15FBE1807A4F9005B8026 /* libcocos2d iOS.a */; }; 15427B7D198B880100DC375D /* lua_cocos2dx_controller_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15427B7B198B880100DC375D /* lua_cocos2dx_controller_manual.cpp */; }; @@ -4378,6 +4380,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1531B2501AE013DE0075DB94 /* Test.html in Resources */, 1502702E1AD3BDC90089CD03 /* TerrainTest in Resources */, 157B08EC1A90864100B7BEA4 /* Particle3D in Resources */, 15B13E5219F0FD4D008A1ADC /* Manifests in Resources */, @@ -4424,6 +4427,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1531B2511AE013F00075DB94 /* Test.html in Resources */, 1502702D1AD3BDBC0089CD03 /* TerrainTest in Resources */, 157B08ED1A90865600B7BEA4 /* Particle3D in Resources */, 15B3709A19EE5EED00ABE682 /* Manifests in Resources */, diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj index 7d74f8cb6f..0ed3692090 100755 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -601,7 +601,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* - @@ -1176,7 +1175,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* - @@ -1285,7 +1283,6 @@ 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 c80e36f980..f3ded72143 100755 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -259,9 +259,6 @@ {e1848cce-b225-42c4-bb6e-6430b6da123b} - - {e6eaa24a-a21e-4c1d-b6b2-19326d129af2} - @@ -1324,9 +1321,6 @@ cocostudio\reader\WidgetReader\ArmatureNodeReader - - ui\shaders - @@ -3042,9 +3036,6 @@ cocostudio\reader\WidgetReader\ArmatureNodeReader - - ui\shaders - @@ -3548,8 +3539,5 @@ 3d - - ui\shaders - \ 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 b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems index 9c5ba13194..00adbe78f3 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 @@ -472,7 +472,7 @@ - + @@ -498,7 +498,6 @@ - @@ -1028,7 +1027,7 @@ - + @@ -1052,7 +1051,6 @@ - @@ -1190,7 +1188,6 @@ - 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 147ee82956..e3f9665cc0 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 @@ -1225,9 +1225,6 @@ cocostudio\reader\WidgetReader\ArmatureNodeReader - - ui\shaders - cocostudio\TimelineAction @@ -1743,7 +1740,7 @@ 3d - + platform\winrt @@ -2818,9 +2815,6 @@ cocostudio\reader\WidgetReader\ArmatureNodeReader - - ui\shaders - cocostudio\TimelineAction @@ -3318,7 +3312,7 @@ cocostudio\json - + platform\winrt @@ -3557,9 +3551,6 @@ {1151b6b3-739f-4cff-add0-6b772fa7d226} - - {10d3def7-52ba-4939-8de7-d9960a752f1e} - {673ca2c5-2183-424e-a2aa-728cd5231b62} @@ -3683,9 +3674,6 @@ 2d - - ui\shaders - 3d diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Windows/libcocos2d_8_1.Windows.vcxproj b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Windows/libcocos2d_8_1.Windows.vcxproj index 5a68bf0d02..38773c3e01 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Windows/libcocos2d_8_1.Windows.vcxproj +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Windows/libcocos2d_8_1.Windows.vcxproj @@ -114,31 +114,41 @@ false false libcocos2d_v3.6_Windows_8.1 + + false false libcocos2d_v3.6_Windows_8.1 + + false false libcocos2d_v3.6_Windows_8.1 + false false false libcocos2d_v3.6_Windows_8.1 + false false false libcocos2d_v3.6_Windows_8.1 + + false false libcocos2d_v3.6_Windows_8.1 + + diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.WindowsPhone/libcocos2d_8_1.WindowsPhone.vcxproj b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.WindowsPhone/libcocos2d_8_1.WindowsPhone.vcxproj index b7013f6cea..d426914099 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.WindowsPhone/libcocos2d_8_1.WindowsPhone.vcxproj +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.WindowsPhone/libcocos2d_8_1.WindowsPhone.vcxproj @@ -96,11 +96,13 @@ false false libcocos2d_v3.6_WindowsPhone_8.1 + false false false libcocos2d_v3.6_WindowsPhone_8.1 + false diff --git a/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props b/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props index 55a7c3a2a4..c77582b639 100644 --- a/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props +++ b/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props @@ -7,7 +7,7 @@ - $(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\angle\include;$(EngineRoot)external\freetype2\include\$(COCOS2D_PLATFORM)\freetype;$(EngineRoot)external\curl\include\$(COCOS2D_PLATFORM);$(EngineRoot)external\websockets\include\$(COCOS2D_PLATFORM);$(EngineRoot)cocos\platform\winrt;$(EngineRoot)cocos\platform;$(EngineRoot)cocos\editor-support;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\sqlite3\include;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos;$(EngineRoot)extensions;$(EngineRoot)external;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot);$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\xxhash;%(AdditionalIncludeDirectories) + $(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\angle\include;$(EngineRoot)external\freetype2\include\$(COCOS2D_PLATFORM)\freetype2;$(EngineRoot)external\curl\include\$(COCOS2D_PLATFORM);$(EngineRoot)external\websockets\include\$(COCOS2D_PLATFORM);$(EngineRoot)cocos\platform\winrt;$(EngineRoot)cocos\platform;$(EngineRoot)cocos\editor-support;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\sqlite3\include;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos;$(EngineRoot)extensions;$(EngineRoot)external;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot);$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\xxhash;%(AdditionalIncludeDirectories) WINRT;_VARIADIC_MAX=10;NOMINMAX;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions) diff --git a/cocos/3d/CCAnimate3D.cpp b/cocos/3d/CCAnimate3D.cpp index a862cd3c6b..1a429c40c9 100644 --- a/cocos/3d/CCAnimate3D.cpp +++ b/cocos/3d/CCAnimate3D.cpp @@ -142,85 +142,89 @@ Node* findChildByNameRecursively(Node* node, const std::string &childName) //! called before the action start. It will also set the target. void Animate3D::startWithTarget(Node *target) { + bool needReMap = (_target != target); ActionInterval::startWithTarget(target); - _boneCurves.clear(); - _nodeCurves.clear(); - - bool hasCurve = false; - Sprite3D* sprite = dynamic_cast(target); - - if(sprite) + if (needReMap) { - if (_animation) + _boneCurves.clear(); + _nodeCurves.clear(); + + bool hasCurve = false; + Sprite3D* sprite = dynamic_cast(target); + + if(sprite) { - const std::unordered_map& boneCurves = _animation->getBoneCurves(); - for (const auto& iter: boneCurves) + if (_animation) { - const std::string& boneName = iter.first; - auto skin = sprite->getSkeleton(); - if(skin) + const std::unordered_map& boneCurves = _animation->getBoneCurves(); + for (const auto& iter: boneCurves) { - auto bone = skin->getBoneByName(boneName); - if (bone) + const std::string& boneName = iter.first; + auto skin = sprite->getSkeleton(); + if(skin) { - auto curve = _animation->getBoneCurveByName(boneName); - _boneCurves[bone] = curve; - hasCurve = true; - } - else - { - Node* node = nullptr; - if (target->getName() == boneName) - node = target; - else - node = findChildByNameRecursively(target, boneName); - - if (node) + auto bone = skin->getBoneByName(boneName); + if (bone) { auto curve = _animation->getBoneCurveByName(boneName); - if (curve) + _boneCurves[bone] = curve; + hasCurve = true; + } + else + { + Node* node = nullptr; + if (target->getName() == boneName) + node = target; + else + node = findChildByNameRecursively(target, boneName); + + if (node) { - _nodeCurves[node] = curve; - hasCurve = true; + auto curve = _animation->getBoneCurveByName(boneName); + if (curve) + { + _nodeCurves[node] = curve; + hasCurve = true; + } } } } } } } - } - else - { - const std::unordered_map& boneCurves = _animation->getBoneCurves(); - for (const auto& iter: boneCurves) + else { - const std::string& boneName = iter.first; - Node* node = nullptr; - if (target->getName() == boneName) - node = target; - else - node = findChildByNameRecursively(target, boneName); - - if (node) + const std::unordered_map& boneCurves = _animation->getBoneCurves(); + for (const auto& iter: boneCurves) { - auto curve = _animation->getBoneCurveByName(boneName); - if (curve) + const std::string& boneName = iter.first; + Node* node = nullptr; + if (target->getName() == boneName) + node = target; + else + node = findChildByNameRecursively(target, boneName); + + if (node) { - _nodeCurves[node] = curve; - hasCurve = true; + auto curve = _animation->getBoneCurveByName(boneName); + if (curve) + { + _nodeCurves[node] = curve; + hasCurve = true; + } } + } - + } + + if (!hasCurve) + { + CCLOG("warning: no animation finde for the skeleton"); } } - if (!hasCurve) - { - CCLOG("warning: no animation finde for the skeleton"); - } - - auto runningAction = s_runningAnimates.find(sprite); + auto runningAction = s_runningAnimates.find(target); if (runningAction != s_runningAnimates.end()) { //make the running action fade out @@ -229,19 +233,19 @@ void Animate3D::startWithTarget(Node *target) { if (_transTime < 0.001f) { - s_runningAnimates[sprite] = this; + s_runningAnimates[target] = this; _state = Animate3D::Animate3DState::Running; _weight = 1.0f; } else { - s_fadeOutAnimates[sprite] = action; + s_fadeOutAnimates[target] = action; action->_state = Animate3D::Animate3DState::FadeOut; action->_accTransTime = 0.0f; action->_weight = 1.0f; action->_lastTime = 0.f; - s_fadeInAnimates[sprite] = this; + s_fadeInAnimates[target] = this; _accTransTime = 0.0f; _state = Animate3D::Animate3DState::FadeIn; _weight = 0.f; @@ -251,7 +255,12 @@ void Animate3D::startWithTarget(Node *target) } else { - s_runningAnimates[sprite] = this; + auto it = s_fadeInAnimates.find(target); + if (it != s_fadeInAnimates.end()) + { + s_fadeInAnimates.erase(it); + } + s_runningAnimates[target] = this; _state = Animate3D::Animate3DState::Running; _weight = 1.0f; } @@ -284,9 +293,8 @@ void Animate3D::update(float t) _accTransTime = _transTime; _weight = 1.0f; _state = Animate3D::Animate3DState::Running; - Sprite3D* sprite = static_cast(_target); - s_fadeInAnimates.erase(sprite); - s_runningAnimates[sprite] = this; + s_fadeInAnimates.erase(_target); + s_runningAnimates[_target] = this; } } else if (_state == Animate3D::Animate3DState::FadeOut && _lastTime > 0.f) @@ -299,8 +307,7 @@ void Animate3D::update(float t) _accTransTime = _transTime; _weight = 0.0f; - Sprite3D* sprite = static_cast(_target); - s_fadeOutAnimates.erase(sprite); + s_fadeOutAnimates.erase(_target); } } _lastTime = t; diff --git a/cocos/3d/CCBundle3DData.h b/cocos/3d/CCBundle3DData.h index d19568ebd8..8eac018aec 100644 --- a/cocos/3d/CCBundle3DData.h +++ b/cocos/3d/CCBundle3DData.h @@ -367,7 +367,6 @@ public: { Vec3Key() : _time(0) - , _key(Vec3::ZERO) { } diff --git a/cocos/3d/CCSkeleton3D.cpp b/cocos/3d/CCSkeleton3D.cpp index 05e0b9fcd8..b8f1103fbf 100644 --- a/cocos/3d/CCSkeleton3D.cpp +++ b/cocos/3d/CCSkeleton3D.cpp @@ -197,7 +197,7 @@ void Bone3D::updateLocalMat() { if (_blendStates.size()) { - Vec3 translate(Vec3::ZERO), scale(Vec3::ZERO); + Vec3 translate, scale; Quaternion quat(Quaternion::ZERO); float total = 0.f; diff --git a/cocos/3d/CCSkeleton3D.h b/cocos/3d/CCSkeleton3D.h index 89a9ba15f5..c7aab26e44 100644 --- a/cocos/3d/CCSkeleton3D.h +++ b/cocos/3d/CCSkeleton3D.h @@ -136,8 +136,7 @@ protected: float weight; void* tag; // BoneBlendState() - : localTranslate(Vec3::ZERO) - , localRot(Quaternion::identity()) + : localRot(Quaternion::identity()) , localScale(Vec3::ONE) , weight(1.f) , tag(nullptr) diff --git a/cocos/3d/CCTextureCube.cpp b/cocos/3d/CCTextureCube.cpp index 779a1c64f5..aadd0d7cda 100644 --- a/cocos/3d/CCTextureCube.cpp +++ b/cocos/3d/CCTextureCube.cpp @@ -200,7 +200,7 @@ bool TextureCube::init(const std::string& positive_x, const std::string& negativ Texture2D::PixelFormat ePixelFmt; unsigned char* pData = getImageData(img, ePixelFmt); - if (ePixelFmt == Texture2D::PixelFormat::RGBA8888) + if (ePixelFmt == Texture2D::PixelFormat::RGBA8888 || ePixelFmt == Texture2D::PixelFormat::DEFAULT) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, // level diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index 2a19da3e4d..7bdbd83813 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -1644,6 +1644,7 @@ FrameData *DataReaderHelper::decodeFrame(const rapidjson::Value& json, DataInfo if (length != 0) { frameData->easingParams = new float[length]; + frameData->easingParamNumber = length; for (int i = 0; i < length; i++) { diff --git a/cocos/editor-support/cocostudio/CSParseBinary_generated.h b/cocos/editor-support/cocostudio/CSParseBinary_generated.h index a37718f560..7a553be9bb 100644 --- a/cocos/editor-support/cocostudio/CSParseBinary_generated.h +++ b/cocos/editor-support/cocostudio/CSParseBinary_generated.h @@ -727,6 +727,14 @@ struct ButtonOptions : private flatbuffers::Table { const FlatSize *scale9Size() const { return GetStruct(24); } uint8_t scale9Enabled() const { return GetField(26, 0); } uint8_t displaystate() const { return GetField(28, 1); } + uint8_t outlineEnabled() const { return GetField(30, 0); } + const Color *outlineColor() const { return GetStruct(32); } + int32_t outlineSize() const { return GetField(34, 1); } + uint8_t shadowEnabled() const { return GetField(36, 0); } + const Color *shadowColor() const { return GetStruct(38); } + float shadowOffsetX() const { return GetField(40, 2); } + float shadowOffsetY() const { return GetField(42, -2); } + int32_t shadowBlurRadius() const { return GetField(44, 0); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* widgetOptions */) && @@ -749,6 +757,14 @@ struct ButtonOptions : private flatbuffers::Table { VerifyField(verifier, 24 /* scale9Size */) && VerifyField(verifier, 26 /* scale9Enabled */) && VerifyField(verifier, 28 /* displaystate */) && + VerifyField(verifier, 30 /* outlineEnabled */) && + VerifyField(verifier, 32 /* outlineColor */) && + VerifyField(verifier, 34 /* outlineSize */) && + VerifyField(verifier, 36 /* shadowEnabled */) && + VerifyField(verifier, 38 /* shadowColor */) && + VerifyField(verifier, 40 /* shadowOffsetX */) && + VerifyField(verifier, 42 /* shadowOffsetY */) && + VerifyField(verifier, 44 /* shadowBlurRadius */) && verifier.EndTable(); } }; @@ -769,10 +785,18 @@ struct ButtonOptionsBuilder { void add_scale9Size(const FlatSize *scale9Size) { fbb_.AddStruct(24, scale9Size); } void add_scale9Enabled(uint8_t scale9Enabled) { fbb_.AddElement(26, scale9Enabled, 0); } void add_displaystate(uint8_t displaystate) { fbb_.AddElement(28, displaystate, 1); } + void add_outlineEnabled(uint8_t outlineEnabled) { fbb_.AddElement(30, outlineEnabled, 0); } + void add_outlineColor(const Color *outlineColor) { fbb_.AddStruct(32, outlineColor); } + void add_outlineSize(int32_t outlineSize) { fbb_.AddElement(34, outlineSize, 1); } + void add_shadowEnabled(uint8_t shadowEnabled) { fbb_.AddElement(36, shadowEnabled, 0); } + void add_shadowColor(const Color *shadowColor) { fbb_.AddStruct(38, shadowColor); } + void add_shadowOffsetX(float shadowOffsetX) { fbb_.AddElement(40, shadowOffsetX, 2); } + void add_shadowOffsetY(float shadowOffsetY) { fbb_.AddElement(42, shadowOffsetY, -2); } + void add_shadowBlurRadius(int32_t shadowBlurRadius) { fbb_.AddElement(44, shadowBlurRadius, 0); } ButtonOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } ButtonOptionsBuilder &operator=(const ButtonOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 13)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 21)); return o; } }; @@ -790,8 +814,22 @@ inline flatbuffers::Offset CreateButtonOptions(flatbuffers::FlatB const CapInsets *capInsets = 0, const FlatSize *scale9Size = 0, uint8_t scale9Enabled = 0, - uint8_t displaystate = 1) { + uint8_t displaystate = 1, + uint8_t outlineEnabled = 0, + const Color *outlineColor = 0, + int32_t outlineSize = 1, + uint8_t shadowEnabled = 0, + const Color *shadowColor = 0, + float shadowOffsetX = 2, + float shadowOffsetY = -2, + int32_t shadowBlurRadius = 0) { ButtonOptionsBuilder builder_(_fbb); + builder_.add_shadowBlurRadius(shadowBlurRadius); + builder_.add_shadowOffsetY(shadowOffsetY); + builder_.add_shadowOffsetX(shadowOffsetX); + builder_.add_shadowColor(shadowColor); + builder_.add_outlineSize(outlineSize); + builder_.add_outlineColor(outlineColor); builder_.add_scale9Size(scale9Size); builder_.add_capInsets(capInsets); builder_.add_textColor(textColor); @@ -803,6 +841,8 @@ inline flatbuffers::Offset CreateButtonOptions(flatbuffers::FlatB builder_.add_pressedData(pressedData); builder_.add_normalData(normalData); builder_.add_widgetOptions(widgetOptions); + builder_.add_shadowEnabled(shadowEnabled); + builder_.add_outlineEnabled(outlineEnabled); builder_.add_displaystate(displaystate); builder_.add_scale9Enabled(scale9Enabled); return builder_.Finish(); diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index fae7bf852b..69ac8528ef 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -274,6 +274,14 @@ namespace cocostudio std::string fontResourcePlistFile = ""; int fontResourceResourceType = 0; + bool outlineEnabled = false; + Color4B outlineColor = Color4B::BLACK; + int outlineSize = 1; + bool shadowEnabled = false; + Color4B shadowColor = Color4B::BLACK; + Size shadowOffset = Size(2, -2); + int shadowBlurRadius = 0; + // attributes const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); while (attribute) @@ -320,6 +328,30 @@ namespace cocostudio { displaystate = (value == "True") ? true : false; } + else if (name == "OutlineEnabled") + { + outlineEnabled = (value == "True") ? true : false; + } + else if (name == "OutlineSize") + { + outlineSize = atoi(value.c_str()); + } + else if (name == "ShadowEnabled") + { + shadowEnabled = (value == "True") ? true : false; + } + else if (name == "ShadowOffsetX") + { + shadowOffset.width = atof(value.c_str()); + } + else if (name == "ShadowOffsetY") + { + shadowOffset.height = atof(value.c_str()); + } + else if (name == "ShadowBlurRadius") + { + shadowBlurRadius = atoi(value.c_str()); + } attribute = attribute->Next(); } @@ -505,6 +537,64 @@ namespace cocostudio attribute = attribute->Next(); } } + else if (name == "OutlineColor") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + name = attribute->Name(); + std::string value = attribute->Value(); + + if (name == "A") + { + outlineColor.a = atoi(value.c_str()); + } + else if (name == "R") + { + outlineColor.r = atoi(value.c_str()); + } + else if (name == "G") + { + outlineColor.g = atoi(value.c_str()); + } + else if (name == "B") + { + outlineColor.b = atoi(value.c_str()); + } + + attribute = attribute->Next(); + } + } + else if (name == "ShadowColor") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + name = attribute->Name(); + std::string value = attribute->Value(); + + if (name == "A") + { + shadowColor.a = atoi(value.c_str()); + } + else if (name == "R") + { + shadowColor.r = atoi(value.c_str()); + } + else if (name == "G") + { + shadowColor.g = atoi(value.c_str()); + } + else if (name == "B") + { + shadowColor.b = atoi(value.c_str()); + } + + attribute = attribute->Next(); + } + } child = child->NextSiblingElement(); } @@ -512,6 +602,8 @@ namespace cocostudio Color f_textColor(255, textColor.r, textColor.g, textColor.b); CapInsets f_capInsets(capInsets.origin.x, capInsets.origin.y, capInsets.size.width, capInsets.size.height); FlatSize f_scale9Size(scale9Size.width, scale9Size.height); + flatbuffers::Color f_outlineColor(outlineColor.a, outlineColor.r, outlineColor.g, outlineColor.b); + flatbuffers::Color f_shadowColor(shadowColor.a, shadowColor.r, shadowColor.g, shadowColor.b); auto options = CreateButtonOptions(*builder, widgetOptions, @@ -538,8 +630,15 @@ namespace cocostudio &f_capInsets, &f_scale9Size, scale9Enabled, - displaystate - ); + displaystate, + outlineEnabled, + &f_outlineColor, + outlineSize, + shadowEnabled, + &f_shadowColor, + shadowOffset.width, + shadowOffset.height, + shadowBlurRadius); return *(Offset*)(&options); } @@ -786,6 +885,30 @@ namespace cocostudio button->setBright(displaystate); button->setEnabled(displaystate); + bool outlineEnabled = options->outlineEnabled(); + if (outlineEnabled) + { + auto f_outlineColor = options->outlineColor(); + if (f_outlineColor) + { + Color4B outlineColor(f_outlineColor->r(), f_outlineColor->g(), f_outlineColor->b(), f_outlineColor->a()); + auto label = button->getTitleRenderer(); + label->enableOutline(outlineColor, options->outlineSize()); + } + } + + bool shadowEnabled = options->shadowEnabled(); + if (shadowEnabled) + { + auto f_shadowColor = options->shadowColor(); + if (f_shadowColor) + { + Color4B shadowColor(f_shadowColor->r(), f_shadowColor->g(), f_shadowColor->b(), f_shadowColor->a()); + auto label = button->getTitleRenderer(); + label->enableShadow(shadowColor, Size(options->shadowOffsetX(), options->shadowOffsetY()), options->shadowBlurRadius()); + } + } + auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); diff --git a/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.cpp index ae39d9f497..9047de4d88 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.cpp @@ -77,7 +77,7 @@ namespace cocostudio if(!attribute) return Vec3::ZERO; - Vec3 ret(Vec3::ZERO); + Vec3 ret; std::string attriname; while (attribute) @@ -104,15 +104,222 @@ namespace cocostudio return ret; } + Offset
Node3DReader::createOptionsWithFlatBuffersForNode(const tinyxml2::XMLElement *objectData, + flatbuffers::FlatBufferBuilder *builder) + { + std::string name = ""; + long actionTag = 0; + Vec2 rotationSkew = Vec2::ZERO; + int zOrder = 0; + bool visible = true; + GLubyte alpha = 255; + int tag = 0; + Vec2 position = Vec2::ZERO; + Vec2 scale = Vec2(1.0f, 1.0f); + Vec2 anchorPoint = Vec2::ZERO; + Color4B color(255, 255, 255, 255); + + Vec2 size = Vec2::ZERO; + bool flipX = false; + bool flipY = false; + bool ignoreSize = false; + bool touchEnabled = false; + std::string frameEvent = ""; + std::string customProperty = ""; + + bool positionXPercentEnabled = false; + bool positionYPercentEnabled = false; + float positionXPercent = 0; + float positionYPercent = 0; + bool sizeXPercentEnable = false; + bool sizeYPercentEnable = false; + float sizeXPercent = 0; + float sizeYPercent = 0; + bool stretchHorizontalEnabled = false; + bool stretchVerticalEnabled = false; + std::string horizontalEdge; + std::string verticalEdge; + float leftMargin = 0; + float rightMargin = 0; + float topMargin = 0; + float bottomMargin = 0; + + // attributes + const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); + while (attribute) + { + std::string attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "Name") + { + name = value; + } + else if (attriname == "ActionTag") + { + actionTag = atol(value.c_str()); + } + else if (attriname == "VisibleForFrame") + { + visible = (value == "True") ? true : false; + } + else if (attriname == "Alpha") + { + alpha = atoi(value.c_str()); + } + else if (attriname == "Tag") + { + tag = atoi(value.c_str()); + } + else if (attriname == "UserData") + { + customProperty = value; + } + else if (attriname == "FrameEvent") + { + frameEvent = value; + } + + attribute = attribute->Next(); + } + + const tinyxml2::XMLElement* child = objectData->FirstChildElement(); + while (child) + { + std::string attriname = child->Name(); + if (attriname == "Position3D") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "ValueX") + { + position.x = atof(value.c_str()); + } + else if (attriname == "ValueY") + { + position.y = atof(value.c_str()); + } + + attribute = attribute->Next(); + } + } + else if (attriname == "Scale3D") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "ValueX") + { + scale.x = atof(value.c_str()); + } + else if (attriname == "ValueY") + { + scale.y = atof(value.c_str()); + } + + attribute = attribute->Next(); + } + } + else if (attriname == "CColor") + { + attribute = child->FirstAttribute(); + + while (attribute) + { + attriname = attribute->Name(); + std::string value = attribute->Value(); + + if (attriname == "A") + { + color.a = atoi(value.c_str()); + } + else if (attriname == "R") + { + color.r = atoi(value.c_str()); + } + else if (attriname == "G") + { + color.g = atoi(value.c_str()); + } + else if (attriname == "B") + { + color.b = atoi(value.c_str()); + } + + attribute = attribute->Next(); + } + } + child = child->NextSiblingElement(); + } + + RotationSkew f_rotationskew(rotationSkew.x, rotationSkew.y); + Position f_position(position.x, position.y); + Scale f_scale(scale.x, scale.y); + AnchorPoint f_anchortpoint(anchorPoint.x, anchorPoint.y); + Color f_color(color.a, color.r, color.g, color.b); + FlatSize f_size(size.x, size.y); + auto f_layoutComponent = CreateLayoutComponentTable(*builder, + positionXPercentEnabled, + positionYPercentEnabled, + positionXPercent, + positionYPercent, + sizeXPercentEnable, + sizeYPercentEnable, + sizeXPercent, + sizeYPercent, + stretchHorizontalEnabled, + stretchVerticalEnabled, + builder->CreateString(horizontalEdge), + builder->CreateString(verticalEdge), + leftMargin, + rightMargin, + topMargin, + bottomMargin); + + auto options = CreateWidgetOptions(*builder, + builder->CreateString(name), + (int)actionTag, + &f_rotationskew, + zOrder, + visible, + alpha, + tag, + &f_position, + &f_scale, + &f_anchortpoint, + &f_color, + &f_size, + flipX, + flipY, + ignoreSize, + touchEnabled, + builder->CreateString(frameEvent), + builder->CreateString(customProperty), + 0, + 0, + f_layoutComponent); + + return *(Offset
*)(&options); + } + Offset
Node3DReader::createOptionsWithFlatBuffers(const tinyxml2::XMLElement *objectData, flatbuffers::FlatBufferBuilder *builder) { - auto temp = NodeReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder); + auto temp = createOptionsWithFlatBuffersForNode(objectData, builder); auto nodeOptions = *(Offset*)(&temp); - Vec3 position(Vec3::ZERO); - Vec3 rotation(Vec3::ZERO); - Vec3 scale(Vec3::ZERO); + Vec3 position; + Vec3 rotation; + Vec3 scale; int cameraMask = 0; std::string attriname; diff --git a/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.h b/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.h index 6a83b038cd..b13d3307dd 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.h @@ -56,7 +56,8 @@ namespace cocostudio cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* node3DOptions); protected: - + flatbuffers::Offset createOptionsWithFlatBuffersForNode(const tinyxml2::XMLElement* objectData, + flatbuffers::FlatBufferBuilder* builder); cocos2d::Vec3 getVec3Attribute(const tinyxml2::XMLAttribute* attribute) const; }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index 88055deca7..6105ec1092 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -454,7 +454,7 @@ namespace cocostudio auto f_outlineColor = options->outlineColor(); if (f_outlineColor) { - Color4B outlineColor(f_outlineColor->a(), f_outlineColor->r(), f_outlineColor->g(), f_outlineColor->b()); + Color4B outlineColor(f_outlineColor->r(), f_outlineColor->g(), f_outlineColor->b(), f_outlineColor->a()); label->enableOutline(outlineColor, options->outlineSize()); } } @@ -465,7 +465,7 @@ namespace cocostudio auto f_shadowColor = options->shadowColor(); if (f_shadowColor) { - Color4B shadowColor(f_shadowColor->a(), f_shadowColor->r(), f_shadowColor->g(), f_shadowColor->b()); + Color4B shadowColor(f_shadowColor->r(), f_shadowColor->g(), f_shadowColor->b(), f_shadowColor->a()); label->enableShadow(shadowColor, Size(options->shadowOffsetX(), options->shadowOffsetY()), options->shadowBlurRadius()); } } diff --git a/cocos/platform/CCImage.h b/cocos/platform/CCImage.h index b03f4a7db9..12f371d227 100644 --- a/cocos/platform/CCImage.h +++ b/cocos/platform/CCImage.h @@ -31,7 +31,7 @@ THE SOFTWARE. #include "renderer/CCTexture2D.h" #if defined(CC_USE_WIC) -#include "WICImageLoader-win.h" +#include "WICImageLoader-winrt.h" #endif // premultiply alpha, or the effect will wrong when want to use other pixel format in Texture2D, diff --git a/cocos/platform/win32/CCApplication-win32.cpp b/cocos/platform/win32/CCApplication-win32.cpp index 6e2579b0b6..52e30c90c8 100644 --- a/cocos/platform/win32/CCApplication-win32.cpp +++ b/cocos/platform/win32/CCApplication-win32.cpp @@ -73,7 +73,7 @@ int Application::run() // Initialize instance and cocos2d. if (!applicationDidFinishLaunching()) { - return 0; + return 1; } auto director = Director::getInstance(); @@ -106,7 +106,7 @@ int Application::run() director = nullptr; } glview->release(); - return true; + return 0; } void Application::setAnimationInterval(double interval) diff --git a/cocos/platform/win8.1-universal/Cocos2dRenderer.cpp b/cocos/platform/win8.1-universal/Cocos2dRenderer.cpp index fb288b4e95..81e78540c1 100644 --- a/cocos/platform/win8.1-universal/Cocos2dRenderer.cpp +++ b/cocos/platform/win8.1-universal/Cocos2dRenderer.cpp @@ -84,6 +84,11 @@ void Cocos2dRenderer::Pause() } } +bool Cocos2dRenderer::AppShouldExit() +{ + return GLViewImpl::sharedOpenGLView()->AppShouldExit(); +} + void Cocos2dRenderer::DeviceLost() { Pause(); @@ -137,4 +142,9 @@ void Cocos2dRenderer::QueuePointerEvent(cocos2d::PointerEventType type, Windows: GLViewImpl::sharedOpenGLView()->QueuePointerEvent(type, args); } +void Cocos2dRenderer::QueueBackButtonEvent() +{ + GLViewImpl::sharedOpenGLView()->QueueBackKeyPress(); +} + diff --git a/cocos/platform/win8.1-universal/Cocos2dRenderer.h b/cocos/platform/win8.1-universal/Cocos2dRenderer.h index a6f7a9c2a3..cb513eaaae 100644 --- a/cocos/platform/win8.1-universal/Cocos2dRenderer.h +++ b/cocos/platform/win8.1-universal/Cocos2dRenderer.h @@ -35,10 +35,12 @@ namespace cocos2d ~Cocos2dRenderer(); void Draw(GLsizei width, GLsizei height, float dpi, Windows::Graphics::Display::DisplayOrientations orientation); void QueuePointerEvent(PointerEventType type, Windows::UI::Core::PointerEventArgs^ args); + void QueueBackButtonEvent(); void Pause(); void Resume(); void DeviceLost(); - + bool AppShouldExit(); + private: int m_width; diff --git a/cocos/platform/win8.1-universal/OpenGLESPage.xaml.cpp b/cocos/platform/win8.1-universal/OpenGLESPage.xaml.cpp index 13781d649d..6a6a5fd00c 100644 --- a/cocos/platform/win8.1-universal/OpenGLESPage.xaml.cpp +++ b/cocos/platform/win8.1-universal/OpenGLESPage.xaml.cpp @@ -169,16 +169,23 @@ void OpenGLESPage::OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Wi } #if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) +/* + We set args->Handled = true to prevent the app from quitting when the back button is pressed. + This is because this back button event happens on the XAML UI thread and not the cocos2d-x UI thread. + We need to give the game developer a chance to decide to exit the app depending on where they + are in their game. They can receive the back button event by listening for the + EventKeyboard::KeyCode::KEY_ESCAPE event. + + The default behavior is to exit the app if the EventKeyboard::KeyCode::KEY_ESCAPE event + is not handled by the game. +*/ void OpenGLESPage::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args) { - bool myAppCanNavigate = false; - if (myAppCanNavigate) + if (m_renderer) { + m_renderer->QueueBackButtonEvent(); args->Handled = true; } - else { - // Do nothing. Leave args->Handled set to the current value, false. - } } #endif @@ -250,6 +257,15 @@ void OpenGLESPage::RecoverFromLostDevice() StartRenderLoop(); } +void OpenGLESPage::TerminateApp() +{ + { + critical_section::scoped_lock lock(mRenderSurfaceCriticalSection); + DestroyRenderSurface(); + } + Windows::UI::Xaml::Application::Current->Exit(); +} + void OpenGLESPage::StartRenderLoop() { // If the render loop is already running then do not start another thread. @@ -273,8 +289,6 @@ void OpenGLESPage::StartRenderLoop() GLsizei panelWidth = 0; GLsizei panelHeight = 0; GetSwapChainPanelSize(&panelWidth, &panelHeight); - - if (m_renderer.get() == nullptr) { @@ -316,6 +330,17 @@ void OpenGLESPage::StartRenderLoop() return; } + + // run on main UI thread + if (m_renderer->AppShouldExit()) + { + swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() + { + TerminateApp(); + })); + + return; + } } if (m_renderer) diff --git a/cocos/platform/win8.1-universal/OpenGLESPage.xaml.h b/cocos/platform/win8.1-universal/OpenGLESPage.xaml.h index d95b310e0a..3f6eecc3b2 100644 --- a/cocos/platform/win8.1-universal/OpenGLESPage.xaml.h +++ b/cocos/platform/win8.1-universal/OpenGLESPage.xaml.h @@ -46,6 +46,7 @@ namespace cocos2d void CreateRenderSurface(); void DestroyRenderSurface(); void RecoverFromLostDevice(); + void TerminateApp(); void StartRenderLoop(); void StopRenderLoop(); diff --git a/cocos/platform/winrt/CCGLViewImpl-winrt.cpp b/cocos/platform/winrt/CCGLViewImpl-winrt.cpp index 0a3a89d9ea..bb7ae1e7ff 100644 --- a/cocos/platform/winrt/CCGLViewImpl-winrt.cpp +++ b/cocos/platform/winrt/CCGLViewImpl-winrt.cpp @@ -81,9 +81,14 @@ GLViewImpl::GLViewImpl() , m_width(0) , m_height(0) , m_orientation(DisplayOrientations::Landscape) + , m_appShouldExit(false) { s_pEglView = this; _viewName = "cocos2dx"; + + m_backButtonListener = EventListenerKeyboard::create(); + m_backButtonListener->onKeyReleased = CC_CALLBACK_2(GLViewImpl::BackButtonListener, this); + Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(m_backButtonListener, INT_MAX); } GLViewImpl::~GLViewImpl() @@ -188,6 +193,7 @@ bool GLViewImpl::isOpenGLReady() void GLViewImpl::end() { m_windowClosed = true; + m_appShouldExit = true; } @@ -202,13 +208,51 @@ void GLViewImpl::OnResuming(Platform::Object^ sender, Platform::Object^ args) // user pressed the Back Key on the phone void GLViewImpl::OnBackKeyPress() { - std::string str; - if(m_delegate) + cocos2d::EventKeyboard::KeyCode cocos2dKey = EventKeyboard::KeyCode::KEY_ESCAPE; + cocos2d::EventKeyboard event(cocos2dKey, false); + cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); +} + +void GLViewImpl::BackButtonListener(EventKeyboard::KeyCode keyCode, Event* event) +{ + CCLOG("*********************************************************************"); + CCLOG("GLViewImpl::BackButtonListener: Exiting application!"); + CCLOG(""); + CCLOG("If you want to listen for Windows Phone back button events,"); + CCLOG("add a listener for EventKeyboard::KeyCode::KEY_ESCAPE"); + CCLOG("Make sure you call stopPropagation() on the Event if you don't"); + CCLOG("want your app to exit when the back button is pressed."); + CCLOG(""); + CCLOG("For example, add the following to your scene..."); + CCLOG("auto listener = EventListenerKeyboard::create();"); + CCLOG("listener->onKeyReleased = CC_CALLBACK_2(HelloWorld::onKeyReleased, this);"); + CCLOG("getEventDispatcher()->addEventListenerWithFixedPriority(listener, 1);"); + CCLOG(""); + CCLOG("void HelloWorld::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)"); + CCLOG("{"); + CCLOG(" if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)"); + CCLOG(" {"); + CCLOG(" if (myAppShouldNotQuit) // or whatever logic you want..."); + CCLOG(" {"); + CCLOG(" event->stopPropagation();"); + CCLOG(" }"); + CCLOG(" }"); + CCLOG("}"); + CCLOG(""); + CCLOG("You MUST call event->stopPropagation() if you don't want your app to quit!"); + CCLOG("*********************************************************************"); + + if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE) { - //m_delegate->Invoke(Cocos2dEvent::TerminateApp, stringToPlatformString(str)); + Director::getInstance()->end(); } } +bool GLViewImpl::AppShouldExit() +{ + return m_appShouldExit; +} + void GLViewImpl::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args) { OnPointerPressed(args); @@ -221,7 +265,6 @@ void GLViewImpl::OnPointerPressed(PointerEventArgs^ args) handleTouchesBegin(1, &id, &pt.x, &pt.y); } - void GLViewImpl::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args) { float direction = (float)args->CurrentPoint->Properties->MouseWheelDelta; diff --git a/cocos/platform/winrt/CCGLViewImpl-winrt.h b/cocos/platform/winrt/CCGLViewImpl-winrt.h index 942a67552d..6a82918f46 100644 --- a/cocos/platform/winrt/CCGLViewImpl-winrt.h +++ b/cocos/platform/winrt/CCGLViewImpl-winrt.h @@ -81,6 +81,8 @@ public: void OnResuming(Platform::Object^ sender, Platform::Object^ args); void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args); void OnBackKeyPress(); + bool AppShouldExit(); + void BackButtonListener(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event); void QueueBackKeyPress(); void QueuePointerEvent(PointerEventType type, Windows::UI::Core::PointerEventArgs^ args); @@ -155,6 +157,7 @@ private: bool m_running; bool m_initialized; + bool m_appShouldExit; Cocos2dEventDelegate^ m_delegate; Cocos2dMessageBoxDelegate^ m_messageBoxDelegate; @@ -165,6 +168,9 @@ private: Platform::Agile m_dispatcher; Platform::Agile m_panel; KeyBoardWinRT^ m_keyboard; + + cocos2d::EventListenerKeyboard* m_backButtonListener; + }; NS_CC_END diff --git a/cocos/platform/winrt/WICImageLoader-win.cpp b/cocos/platform/winrt/WICImageLoader-winrt.cpp similarity index 97% rename from cocos/platform/winrt/WICImageLoader-win.cpp rename to cocos/platform/winrt/WICImageLoader-winrt.cpp index ac7c42c4a8..c640daf139 100644 --- a/cocos/platform/winrt/WICImageLoader-win.cpp +++ b/cocos/platform/winrt/WICImageLoader-winrt.cpp @@ -24,7 +24,7 @@ THE SOFTWARE. Based upon code from the DirectX Tool Kit by Microsoft Corporation, obtained from https://directxtk.codeplex.com ****************************************************************************/ -#include "WICImageLoader-win.h" +#include "WICImageLoader-winrt.h" NS_CC_BEGIN @@ -53,8 +53,8 @@ static WICConvert g_WICConvert[] = { GUID_WICPixelFormat32bppBGR101010, GUID_WICPixelFormat32bppRGBA1010102 }, // DXGI_FORMAT_R10G10B10A2_UNORM - { GUID_WICPixelFormat24bppBGR, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM - { GUID_WICPixelFormat24bppRGB, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM + { GUID_WICPixelFormat24bppBGR, GUID_WICPixelFormat24bppRGB }, // DXGI_FORMAT_R8G8B8A8_UNORM + { GUID_WICPixelFormat24bppRGB, GUID_WICPixelFormat24bppRGB }, // DXGI_FORMAT_R8G8B8A8_UNORM { GUID_WICPixelFormat32bppPBGRA, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM { GUID_WICPixelFormat32bppPRGBA, GUID_WICPixelFormat32bppRGBA }, // DXGI_FORMAT_R8G8B8A8_UNORM diff --git a/cocos/platform/winrt/WICImageLoader-win.h b/cocos/platform/winrt/WICImageLoader-winrt.h similarity index 100% rename from cocos/platform/winrt/WICImageLoader-win.h rename to cocos/platform/winrt/WICImageLoader-winrt.h diff --git a/cocos/renderer/CCGLProgram.cpp b/cocos/renderer/CCGLProgram.cpp index f7d3666391..69ec843d8d 100644 --- a/cocos/renderer/CCGLProgram.cpp +++ b/cocos/renderer/CCGLProgram.cpp @@ -6,7 +6,7 @@ Copyright 2012 cocos2d-x.org Copyright 2013-2014 Chukong Technologies Inc. http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -58,7 +58,7 @@ const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_U_COLOR = "ShaderPositionTex const char* GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR = "ShaderPositionTextureA8Color"; const char* GLProgram::SHADER_NAME_POSITION_U_COLOR = "ShaderPosition_uColor"; const char* GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR = "ShaderPositionLengthTextureColor"; - +const char* GLProgram::SHADER_NAME_POSITION_GRAYSCALE = "ShaderUIGrayScale"; const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL = "ShaderLabelDFNormal"; const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW = "ShaderLabelDFGlow"; const char* GLProgram::SHADER_NAME_LABEL_NORMAL = "ShaderLabelNormal"; @@ -150,15 +150,15 @@ GLProgram::~GLProgram() { glDeleteShader(_vertShader); } - + if (_fragShader) { glDeleteShader(_fragShader); } - + _vertShader = _fragShader = 0; - if (_program) + if (_program) { GL::deleteProgram(_program); } @@ -218,9 +218,9 @@ bool GLProgram::initWithByteArrays(const GLchar* vShaderByteArray, const GLchar* { glAttachShader(_program, _fragShader); } - + _hashForUniforms.clear(); - + CHECK_GL_ERROR_DEBUG(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || defined(WP8_SHADER_COMPILER) @@ -259,7 +259,7 @@ bool GLProgram::initWithPrecompiledProgramByteArray(const GLchar* vShaderByteArr CHECK_GL_ERROR_DEBUG(); _hashForUniforms.clear(); - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR_DEBUG(); return haveProgram; } @@ -373,13 +373,13 @@ void GLProgram::parseUniforms() } uniform.name = std::string(uniformName); uniform.location = glGetUniformLocation(_program, uniformName); - GLenum __gl_error_code = glGetError(); - if (__gl_error_code != GL_NO_ERROR) - { + GLenum __gl_error_code = glGetError(); + if (__gl_error_code != GL_NO_ERROR) + { CCLOG("error: 0x%x", (int)__gl_error_code); - } + } assert(__gl_error_code == GL_NO_ERROR); - + _userUniforms[uniform.name] = uniform; } } @@ -422,12 +422,12 @@ std::string GLProgram::getDescription() const bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source) { GLint status; - + if (!source) { return false; } - + const GLchar *sources[] = { #if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT (type == GL_VERTEX_SHADER ? "precision mediump float;\n precision mediump int;\n" : "precision mediump float;\n precision mediump int;\n"), @@ -461,10 +461,10 @@ bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source GLsizei length; glGetShaderiv(*shader, GL_SHADER_SOURCE_LENGTH, &length); GLchar* src = (GLchar *)malloc(sizeof(GLchar) * length); - + glGetShaderSource(*shader, length, nullptr, src); CCLOG("cocos2d: ERROR: Failed to compile shader:\n%s", src); - + if (type == GL_VERTEX_SHADER) { CCLOG("cocos2d: %s", getVertexShaderLog().c_str()); @@ -502,7 +502,7 @@ void GLProgram::updateUniforms() _builtInUniforms[UNIFORM_MV_MATRIX] = glGetUniformLocation(_program, UNIFORM_NAME_MV_MATRIX); _builtInUniforms[UNIFORM_MVP_MATRIX] = glGetUniformLocation(_program, UNIFORM_NAME_MVP_MATRIX); _builtInUniforms[UNIFORM_NORMAL_MATRIX] = glGetUniformLocation(_program, UNIFORM_NAME_NORMAL_MATRIX); - + _builtInUniforms[UNIFORM_TIME] = glGetUniformLocation(_program, UNIFORM_NAME_TIME); _builtInUniforms[UNIFORM_SIN_TIME] = glGetUniformLocation(_program, UNIFORM_NAME_SIN_TIME); _builtInUniforms[UNIFORM_COS_TIME] = glGetUniformLocation(_program, UNIFORM_NAME_COS_TIME); @@ -526,7 +526,7 @@ void GLProgram::updateUniforms() _flags.usesRandom = _builtInUniforms[UNIFORM_RANDOM01] != -1; this->use(); - + // Since sample most probably won't change, set it to 0,1,2,3 now. if(_builtInUniforms[UNIFORM_SAMPLER0] != -1) setUniformLocationWith1i(_builtInUniforms[UNIFORM_SAMPLER0], 0); @@ -567,17 +567,17 @@ bool GLProgram::link() { glDeleteShader(_vertShader); } - + if (_fragShader) { glDeleteShader(_fragShader); } - + _vertShader = _fragShader = 0; - + #if DEBUG || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) glGetProgramiv(_program, GL_LINK_STATUS, &status); - + if (status == GL_FALSE) { CCLOG("cocos2d: ERROR: Failed to link program: %i", _program); @@ -662,7 +662,7 @@ bool GLProgram::updateUniformLocation(GLint location, const GLvoid* data, unsign } bool updated = true; - + auto element = _hashForUniforms.find(location); if (element == _hashForUniforms.end()) { @@ -696,14 +696,14 @@ GLint GLProgram::getUniformLocationForName(const char* name) const { CCASSERT(name != nullptr, "Invalid uniform name" ); CCASSERT(_program != 0, "Invalid operation. Cannot get uniform location when program is not initialized"); - + return glGetUniformLocation(_program, name); } void GLProgram::setUniformLocationWith1i(GLint location, GLint i1) { bool updated = updateUniformLocation(location, &i1, sizeof(i1)*1); - + if( updated ) { glUniform1i( (GLint)location, i1); @@ -714,7 +714,7 @@ void GLProgram::setUniformLocationWith2i(GLint location, GLint i1, GLint i2) { GLint ints[2] = {i1,i2}; bool updated = updateUniformLocation(location, ints, sizeof(ints)); - + if( updated ) { glUniform2i( (GLint)location, i1, i2); @@ -725,7 +725,7 @@ void GLProgram::setUniformLocationWith3i(GLint location, GLint i1, GLint i2, GLi { GLint ints[3] = {i1,i2,i3}; bool updated = updateUniformLocation(location, ints, sizeof(ints)); - + if( updated ) { glUniform3i( (GLint)location, i1, i2, i3); @@ -736,7 +736,7 @@ void GLProgram::setUniformLocationWith4i(GLint location, GLint i1, GLint i2, GLi { GLint ints[4] = {i1,i2,i3,i4}; bool updated = updateUniformLocation(location, ints, sizeof(ints)); - + if( updated ) { glUniform4i( (GLint)location, i1, i2, i3, i4); @@ -746,7 +746,7 @@ void GLProgram::setUniformLocationWith4i(GLint location, GLint i1, GLint i2, GLi void GLProgram::setUniformLocationWith2iv(GLint location, GLint* ints, unsigned int numberOfArrays) { bool updated = updateUniformLocation(location, ints, sizeof(int)*2*numberOfArrays); - + if( updated ) { glUniform2iv( (GLint)location, (GLsizei)numberOfArrays, ints ); @@ -756,7 +756,7 @@ void GLProgram::setUniformLocationWith2iv(GLint location, GLint* ints, unsigned void GLProgram::setUniformLocationWith3iv(GLint location, GLint* ints, unsigned int numberOfArrays) { bool updated = updateUniformLocation(location, ints, sizeof(int)*3*numberOfArrays); - + if( updated ) { glUniform3iv( (GLint)location, (GLsizei)numberOfArrays, ints ); @@ -766,7 +766,7 @@ void GLProgram::setUniformLocationWith3iv(GLint location, GLint* ints, unsigned void GLProgram::setUniformLocationWith4iv(GLint location, GLint* ints, unsigned int numberOfArrays) { bool updated = updateUniformLocation(location, ints, sizeof(int)*4*numberOfArrays); - + if( updated ) { glUniform4iv( (GLint)location, (GLsizei)numberOfArrays, ints ); @@ -859,7 +859,7 @@ void GLProgram::setUniformLocationWith4fv(GLint location, const GLfloat* floats, void GLProgram::setUniformLocationWithMatrix2fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices) { bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*4*numberOfMatrices); - + if( updated ) { glUniformMatrix2fv( (GLint)location, (GLsizei)numberOfMatrices, GL_FALSE, matrixArray); @@ -868,7 +868,7 @@ void GLProgram::setUniformLocationWithMatrix2fv(GLint location, const GLfloat* m void GLProgram::setUniformLocationWithMatrix3fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices) { bool updated = updateUniformLocation(location, matrixArray, sizeof(float)*9*numberOfMatrices); - + if( updated ) { glUniformMatrix3fv( (GLint)location, (GLsizei)numberOfMatrices, GL_FALSE, matrixArray); @@ -924,12 +924,12 @@ void GLProgram::setUniformsForBuiltins(const Mat4 &matrixMV) // Cocos2D doesn't store a high precision time value, so this will have to do. // Getting Mach time per frame per shader using time could be extremely expensive. float time = _director->getTotalFrames() * _director->getAnimationInterval(); - + setUniformLocationWith4f(_builtInUniforms[GLProgram::UNIFORM_TIME], time/10.0, time, time*2, time*4); setUniformLocationWith4f(_builtInUniforms[GLProgram::UNIFORM_SIN_TIME], time/8.0, time/4.0, time/2.0, sinf(time)); setUniformLocationWith4f(_builtInUniforms[GLProgram::UNIFORM_COS_TIME], time/8.0, time/4.0, time/2.0, cosf(time)); } - + if(_flags.usesRandom) setUniformLocationWith4f(_builtInUniforms[GLProgram::UNIFORM_RANDOM01], CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1()); } @@ -938,7 +938,7 @@ void GLProgram::reset() { _vertShader = _fragShader = 0; memset(_builtInUniforms, 0, sizeof(_builtInUniforms)); - + // it is already deallocated by android //GL::deleteProgram(_program); @@ -948,7 +948,7 @@ void GLProgram::reset() { free(e.second.first); } - + _hashForUniforms.clear(); } diff --git a/cocos/renderer/CCGLProgram.h b/cocos/renderer/CCGLProgram.h index 58917b7f4c..3d2d4c467d 100644 --- a/cocos/renderer/CCGLProgram.h +++ b/cocos/renderer/CCGLProgram.h @@ -4,10 +4,10 @@ Copyright 2012 Goffredo Marocchi Copyright 2012 Ricardo Quesada Copyright 2012 cocos2d-x.org Copyright 2013-2014 Chukong Technologies Inc. - - + + http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -78,8 +78,8 @@ struct Uniform /** GLProgram Class that implements a glProgram - - + + @since v2.0.0 */ class CC_DLL GLProgram : public Ref @@ -113,7 +113,7 @@ public: // backward compatibility VERTEX_ATTRIB_TEX_COORDS = VERTEX_ATTRIB_TEX_COORD, }; - + /**Preallocated uniform handle.*/ enum { @@ -179,6 +179,9 @@ public: static const char* SHADER_NAME_POSITION_U_COLOR; /**Built in shader for draw a sector with 90 degrees with center at bottom left point.*/ static const char* SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR; + + /**Built in shader for ui effects */ + static const char* SHADER_NAME_POSITION_GRAYSCALE; /** @{ Built in shader for label and label with effects. */ @@ -192,7 +195,7 @@ public: /**Built in shader used for 3D, support Position and Texture vertex attribute, with color specified by a uniform.*/ static const char* SHADER_3D_POSITION_TEXTURE; /** - Built in shader used for 3D, support Position (Skeletal animation by hardware skin) and Texture vertex attribute, + Built in shader used for 3D, support Position (Skeletal animation by hardware skin) and Texture vertex attribute, with color specified by a uniform. */ static const char* SHADER_3D_SKINPOSITION_TEXTURE; @@ -205,7 +208,7 @@ public: */ static const char* SHADER_3D_POSITION_NORMAL_TEXTURE; /** - Built in shader used for 3D, support Position(skeletal animation by hardware skin), Normal, Texture vertex attribute, + Built in shader used for 3D, support Position(skeletal animation by hardware skin), Normal, Texture vertex attribute, used in lighting. with color specified by a uniform. */ static const char* SHADER_3D_SKINPOSITION_NORMAL_TEXTURE; @@ -217,22 +220,22 @@ public: Built in shader for particles, support Position, with a color specified by a uniform. */ static const char* SHADER_3D_PARTICLE_COLOR; - + /** Built in shader for skybox */ static const char* SHADER_3D_SKYBOX; - + /** Built in shader for terrain */ static const char* SHADER_3D_TERRAIN; - + /** end of built shader types. @} */ - + /** @name Built uniform names @{ @@ -329,7 +332,7 @@ public: /** @} */ - + /**@{ Get the uniform or vertex attribute by string name in shader, return null if it does not exist.*/ Uniform* getUniform(const std::string& name); VertexAttrib* getVertexAttrib(const std::string& name); @@ -358,54 +361,54 @@ public: */ void updateUniforms(); - + /** calls retrieves the named uniform location for this shader program. */ GLint getUniformLocationForName(const char* name) const; - - /** calls glUniform1i only if the values are different than the previous call for this same shader program. + + /** calls glUniform1i only if the values are different than the previous call for this same shader program. * @js setUniformLocationI32 * @lua setUniformLocationI32 */ void setUniformLocationWith1i(GLint location, GLint i1); - + /** calls glUniform2i only if the values are different than the previous call for this same shader program. */ void setUniformLocationWith2i(GLint location, GLint i1, GLint i2); - + /** calls glUniform3i only if the values are different than the previous call for this same shader program. */ void setUniformLocationWith3i(GLint location, GLint i1, GLint i2, GLint i3); - + /** calls glUniform4i only if the values are different than the previous call for this same shader program. */ void setUniformLocationWith4i(GLint location, GLint i1, GLint i2, GLint i3, GLint i4); - + /** calls glUniform2iv only if the values are different than the previous call for this same shader program. */ void setUniformLocationWith2iv(GLint location, GLint* ints, unsigned int numberOfArrays); - + /** calls glUniform3iv only if the values are different than the previous call for this same shader program. */ void setUniformLocationWith3iv(GLint location, GLint* ints, unsigned int numberOfArrays); - + /** calls glUniform4iv only if the values are different than the previous call for this same shader program. */ - + void setUniformLocationWith4iv(GLint location, GLint* ints, unsigned int numberOfArrays); - /** calls glUniform1f only if the values are different than the previous call for this same shader program. + /** calls glUniform1f only if the values are different than the previous call for this same shader program. * In js or lua,please use setUniformLocationF32 * @js NA */ void setUniformLocationWith1f(GLint location, GLfloat f1); - /** calls glUniform2f only if the values are different than the previous call for this same shader program. + /** calls glUniform2f only if the values are different than the previous call for this same shader program. * In js or lua,please use setUniformLocationF32 * @js NA */ void setUniformLocationWith2f(GLint location, GLfloat f1, GLfloat f2); - /** calls glUniform3f only if the values are different than the previous call for this same shader program. + /** calls glUniform3f only if the values are different than the previous call for this same shader program. * In js or lua,please use setUniformLocationF32 * @js NA */ void setUniformLocationWith3f(GLint location, GLfloat f1, GLfloat f2, GLfloat f3); - /** calls glUniform4f only if the values are different than the previous call for this same shader program. + /** calls glUniform4f only if the values are different than the previous call for this same shader program. * In js or lua,please use setUniformLocationF32 * @js NA */ @@ -425,13 +428,13 @@ public: /** calls glUniformMatrix2fv only if the values are different than the previous call for this same shader program. */ void setUniformLocationWithMatrix2fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices); - + /** calls glUniformMatrix3fv only if the values are different than the previous call for this same shader program. */ void setUniformLocationWithMatrix3fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices); - + /** calls glUniformMatrix4fv only if the values are different than the previous call for this same shader program. */ void setUniformLocationWithMatrix4fv(GLint location, const GLfloat* matrixArray, unsigned int numberOfMatrices); - + /** Update the builtin uniforms if they are different than the previous call for this same shader program. */ @@ -450,7 +453,7 @@ public: /** returns the program error log */ std::string getProgramLog() const; - + /** Reload all shaders, this function is designed for android when opengl context lost, so don't call it. */ @@ -485,7 +488,7 @@ protected: void parseUniforms(); /**Compile the shader sources.*/ bool compileShader(GLuint * shader, GLenum type, const GLchar* source); - + /**OpenGL handle for program.*/ GLuint _program; /**OpenGL handle for vertex shader.*/ @@ -496,7 +499,7 @@ protected: GLint _builtInUniforms[UNIFORM_MAX]; /**Indicate whether it has a offline shader compiler or not.*/ bool _hasShaderCompiler; - + #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || defined(WP8_SHADER_COMPILER) /**Shader ID in precompiled shaders on Windows phone.*/ std::string _shaderId; diff --git a/cocos/renderer/CCGLProgramCache.cpp b/cocos/renderer/CCGLProgramCache.cpp index 08e7b336d0..53bfe055d6 100644 --- a/cocos/renderer/CCGLProgramCache.cpp +++ b/cocos/renderer/CCGLProgramCache.cpp @@ -53,6 +53,7 @@ enum { kShaderType_PositionLengthTexureColor, kShaderType_LabelDistanceFieldNormal, kShaderType_LabelDistanceFieldGlow, + kShaderType_UIGrayScale, kShaderType_LabelNormal, kShaderType_LabelOutline, kShaderType_3DPosition, @@ -118,7 +119,7 @@ GLProgramCache::~GLProgramCache() } bool GLProgramCache::init() -{ +{ loadDefaultGLPrograms(); return true; } @@ -150,12 +151,12 @@ void GLProgramCache::loadDefaultGLPrograms() p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_PositionColor); _programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_COLOR, p) ); - + // Position, Color, PointSize shader p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_PositionColorTextureAsPointsize); _programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE, p) ); - + // // Position, Color shader no MVP // @@ -190,7 +191,7 @@ void GLProgramCache::loadDefaultGLPrograms() p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_Position_uColor); _programs.insert( std::make_pair(GLProgram::SHADER_NAME_POSITION_U_COLOR, p) ); - + // // Position, Legth(TexCoords, Color (used by Draw Node basically ) // @@ -208,6 +209,10 @@ void GLProgramCache::loadDefaultGLPrograms() _programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW, p) ); #endif + p = new (std::nothrow) GLProgram(); + loadDefaultGLProgram(p, kShaderType_UIGrayScale); + _programs.insert(std::make_pair(GLProgram::SHADER_NAME_POSITION_GRAYSCALE, p)); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_LabelNormal); _programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_NORMAL, p) ); @@ -215,7 +220,7 @@ void GLProgramCache::loadDefaultGLPrograms() p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_LabelOutline); _programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_OUTLINE, p) ); - + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DPosition); _programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION, p) ); @@ -223,7 +228,7 @@ void GLProgramCache::loadDefaultGLPrograms() p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DPositionTex); _programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_TEXTURE, p) ); - + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DSkinPositionTex); _programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE, p)); @@ -239,19 +244,19 @@ void GLProgramCache::loadDefaultGLPrograms() p = new GLProgram(); loadDefaultGLProgram(p, kShaderType_3DSkinPositionNormalTex); _programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE, p)); - + p = new GLProgram(); loadDefaultGLProgram(p, kShaderType_3DParticleColor); _programs.insert(std::make_pair(GLProgram::SHADER_3D_PARTICLE_COLOR, p)); - + p = new GLProgram(); loadDefaultGLProgram(p, kShaderType_3DParticleTex); _programs.insert(std::make_pair(GLProgram::SHADER_3D_PARTICLE_TEXTURE, p)); - + p = new GLProgram(); loadDefaultGLProgram(p, kShaderType_3DSkyBox); _programs.insert(std::make_pair(GLProgram::SHADER_3D_SKYBOX, p)); - + p = new GLProgram(); loadDefaultGLProgram(p, kShaderType_3DTerrain); _programs.insert(std::make_pair(GLProgram::SHADER_3D_TERRAIN, p)); @@ -260,25 +265,25 @@ void GLProgramCache::loadDefaultGLPrograms() void GLProgramCache::reloadDefaultGLPrograms() { // reset all programs and reload them - + // Position Texture Color shader - GLProgram *p = getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR); + GLProgram *p = getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR); p->reset(); loadDefaultGLProgram(p, kShaderType_PositionTextureColor); // Position Texture Color without MVP shader p = getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP); - p->reset(); + p->reset(); loadDefaultGLProgram(p, kShaderType_PositionTextureColor_noMVP); // Position Texture Color alpha test p = getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST); - p->reset(); + p->reset(); loadDefaultGLProgram(p, kShaderType_PositionTextureColorAlphaTest); - + // Position Texture Color alpha test p = getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV); - p->reset(); + p->reset(); loadDefaultGLProgram(p, kShaderType_PositionTextureColorAlphaTestNoMV); // // Position, Color shader @@ -286,7 +291,7 @@ void GLProgramCache::reloadDefaultGLPrograms() p = getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR); p->reset(); loadDefaultGLProgram(p, kShaderType_PositionColor); - + // Position, Color, PointSize shader p = getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE); p->reset(); @@ -304,28 +309,28 @@ void GLProgramCache::reloadDefaultGLPrograms() p = getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE); p->reset(); loadDefaultGLProgram(p, kShaderType_PositionTexture); - + // // Position, Texture attribs, 1 Color as uniform shader // p = getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_U_COLOR); p->reset(); loadDefaultGLProgram(p, kShaderType_PositionTexture_uColor); - + // // Position Texture A8 Color shader // p = getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR); p->reset(); loadDefaultGLProgram(p, kShaderType_PositionTextureA8Color); - + // // Position and 1 color passed as a uniform (to simulate glColor4ub ) // p = getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR); p->reset(); loadDefaultGLProgram(p, kShaderType_Position_uColor); - + // // Position, Legth(TexCoords, Color (used by Draw Node basically ) // @@ -350,19 +355,19 @@ void GLProgramCache::reloadDefaultGLPrograms() p = getGLProgram(GLProgram::SHADER_NAME_LABEL_OUTLINE); p->reset(); loadDefaultGLProgram(p, kShaderType_LabelOutline); - + p = getGLProgram(GLProgram::SHADER_3D_POSITION); p->reset(); loadDefaultGLProgram(p, kShaderType_3DPosition); - + p = getGLProgram(GLProgram::SHADER_3D_POSITION_TEXTURE); p->reset(); loadDefaultGLProgram(p, kShaderType_3DPositionTex); - + p = getGLProgram(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE); p->reset(); loadDefaultGLProgram(p, kShaderType_3DSkinPositionTex); - + p = getGLProgram(GLProgram::SHADER_3D_POSITION_NORMAL); p->reset(); loadDefaultGLProgram(p, kShaderType_3DPositionNormal); @@ -374,19 +379,19 @@ void GLProgramCache::reloadDefaultGLPrograms() p = getGLProgram(GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE); p->reset(); loadDefaultGLProgram(p, kShaderType_3DSkinPositionNormalTex); - + p = getGLProgram(GLProgram::SHADER_3D_PARTICLE_TEXTURE); p->reset(); loadDefaultGLProgram(p, kShaderType_3DParticleTex); - + p = getGLProgram(GLProgram::SHADER_3D_PARTICLE_COLOR); p->reset(); loadDefaultGLProgram(p, kShaderType_3DParticleColor); - + p = getGLProgram(GLProgram::SHADER_3D_SKYBOX); p->reset(); loadDefaultGLProgram(p, kShaderType_3DSkyBox); - + p = getGLProgram(GLProgram::SHADER_3D_TERRAIN); p->reset(); loadDefaultGLProgram(p, kShaderType_3DTerrain); @@ -407,7 +412,7 @@ void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type) case kShaderType_PositionTextureColorAlphaTestNoMV: p->initWithByteArrays(ccPositionTextureColor_noMVP_vert, ccPositionTextureColorAlphaTest_frag); break; - case kShaderType_PositionColor: + case kShaderType_PositionColor: p->initWithByteArrays(ccPositionColor_vert ,ccPositionColor_frag); break; case kShaderType_PositionColorTextureAsPointsize: @@ -440,6 +445,10 @@ void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type) p->initWithByteArrays(ccLabel_vert, ccLabelDistanceFieldGlow_frag); break; #endif + case kShaderType_UIGrayScale: + p->initWithByteArrays(ccPositionTextureColor_noMVP_vert, + ccPositionTexture_GrayScale_frag); + break; case kShaderType_LabelNormal: p->initWithByteArrays(ccLabel_vert, ccLabelNormal_frag); break; @@ -496,10 +505,10 @@ void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type) CCLOG("cocos2d: %s:%d, error shader type", __FUNCTION__, __LINE__); return; } - + p->link(); p->updateUniforms(); - + CHECK_GL_ERROR_DEBUG(); } diff --git a/cocos/renderer/CCTexture2D.cpp b/cocos/renderer/CCTexture2D.cpp index 1073302d9b..240b947890 100644 --- a/cocos/renderer/CCTexture2D.cpp +++ b/cocos/renderer/CCTexture2D.cpp @@ -637,7 +637,12 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat } #endif - CHECK_GL_ERROR_DEBUG(); // clean possible GL error + // clean possible GL error + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + { + cocos2d::log("OpenGL error 0x%04X in %s %s %d\n", err, __FILE__, __FUNCTION__, __LINE__); + } // Specify OpenGL texture image int width = pixelsWide; diff --git a/cocos/ui/shaders/ccShader_grayscale.frag b/cocos/renderer/ccShader_UI_Gray.frag similarity index 84% rename from cocos/ui/shaders/ccShader_grayscale.frag rename to cocos/renderer/ccShader_UI_Gray.frag index 32092e3f83..b20508f80d 100644 --- a/cocos/ui/shaders/ccShader_grayscale.frag +++ b/cocos/renderer/ccShader_UI_Gray.frag @@ -1,4 +1,4 @@ -const char* ccUIGrayScale_frag = STRINGIFY( +const char* ccPositionTexture_GrayScale_frag = STRINGIFY( \n#ifdef GL_ES\n \nprecision mediump float;\n diff --git a/cocos/renderer/ccShaders.cpp b/cocos/renderer/ccShaders.cpp index 93a775286b..5f89ef7265 100644 --- a/cocos/renderer/ccShaders.cpp +++ b/cocos/renderer/ccShaders.cpp @@ -66,6 +66,7 @@ NS_CC_BEGIN #include "ccShader_PositionColorLengthTexture.frag" #include "ccShader_PositionColorLengthTexture.vert" +#include "ccShader_UI_Gray.frag" // #include "ccShader_Label.vert" #include "ccShader_Label_df.frag" diff --git a/cocos/renderer/ccShaders.h b/cocos/renderer/ccShaders.h index 5b00b180fd..41ff659f1d 100644 --- a/cocos/renderer/ccShaders.h +++ b/cocos/renderer/ccShaders.h @@ -66,6 +66,8 @@ extern CC_DLL const GLchar * ccPositionTexture_uColor_vert; extern CC_DLL const GLchar * ccPositionColorLengthTexture_frag; extern CC_DLL const GLchar * ccPositionColorLengthTexture_vert; +extern CC_DLL const GLchar * ccPositionTexture_GrayScale_frag; + extern CC_DLL const GLchar * ccLabelDistanceFieldNormal_frag; extern CC_DLL const GLchar * ccLabelDistanceFieldGlow_frag; extern CC_DLL const GLchar * ccLabelNormal_frag; diff --git a/cocos/scripting/lua-bindings/auto/api/GLProgram.lua b/cocos/scripting/lua-bindings/auto/api/GLProgram.lua index 0ff98ec3bc..15e8afdf0b 100644 --- a/cocos/scripting/lua-bindings/auto/api/GLProgram.lua +++ b/cocos/scripting/lua-bindings/auto/api/GLProgram.lua @@ -58,7 +58,7 @@ -- @return GLProgram#GLProgram self (return value: cc.GLProgram) -------------------------------- --- calls glUniform1i only if the values are different than the previous call for this same shader program.
+-- calls glUniform1i only if the values are different than the previous call for this same shader program.
-- js setUniformLocationI32
-- lua setUniformLocationI32 -- @function [parent=#GLProgram] setUniformLocationWith1i diff --git a/cocos/scripting/lua-bindings/auto/api/WebView.lua b/cocos/scripting/lua-bindings/auto/api/WebView.lua new file mode 100644 index 0000000000..751e0ef854 --- /dev/null +++ b/cocos/scripting/lua-bindings/auto/api/WebView.lua @@ -0,0 +1,112 @@ + +-------------------------------- +-- @module WebView +-- @extend Widget +-- @parent_module ccexp + +-------------------------------- +-- Loads the given URL.
+-- param url Content URL. +-- @function [parent=#WebView] loadURL +-- @param self +-- @param #string url +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Gets whether this WebView has a back history item.
+-- return WebView has a back history item. +-- @function [parent=#WebView] canGoBack +-- @param self +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- Sets the main page content and base URL.
+-- param string The content for the main page.
+-- param baseURL The base URL for the content. +-- @function [parent=#WebView] loadHTMLString +-- @param self +-- @param #string string +-- @param #string baseURL +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Goes forward in the history. +-- @function [parent=#WebView] goForward +-- @param self +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Goes back in the history. +-- @function [parent=#WebView] goBack +-- @param self +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Set javascript interface scheme.
+-- see WebView::setOnJSCallback() +-- @function [parent=#WebView] setJavascriptInterfaceScheme +-- @param self +-- @param #string scheme +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Evaluates JavaScript in the context of the currently displayed page. +-- @function [parent=#WebView] evaluateJS +-- @param self +-- @param #string js +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Get the Javascript callback. +-- @function [parent=#WebView] getOnJSCallback +-- @param self +-- @return function#function ret (return value: function) + +-------------------------------- +-- Reloads the current URL. +-- @function [parent=#WebView] reload +-- @param self +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Set WebView should support zooming. The default value is false. +-- @function [parent=#WebView] setScalesPageToFit +-- @param self +-- @param #bool scalesPageToFit +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Gets whether this WebView has a forward history item.
+-- return WebView has a forward history item. +-- @function [parent=#WebView] canGoForward +-- @param self +-- @return bool#bool ret (return value: bool) + +-------------------------------- +-- Loads the given fileName.
+-- param fileName Content fileName. +-- @function [parent=#WebView] loadFile +-- @param self +-- @param #string fileName +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Stops the current load. +-- @function [parent=#WebView] stopLoading +-- @param self +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Allocates and initializes a WebView. +-- @function [parent=#WebView] create +-- @param self +-- @return experimental::ui::WebView#experimental::ui::WebView ret (return value: cc.experimental::ui::WebView) + +-------------------------------- +-- Toggle visibility of WebView. +-- @function [parent=#WebView] setVisible +-- @param self +-- @param #bool visible +-- @return experimental::ui::WebView#experimental::ui::WebView self (return value: cc.experimental::ui::WebView) + +return nil diff --git a/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_experimental_webview_auto_api.lua b/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_experimental_webview_auto_api.lua new file mode 100644 index 0000000000..5846bfefd9 --- /dev/null +++ b/cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_experimental_webview_auto_api.lua @@ -0,0 +1,9 @@ +-------------------------------- +-- @module ccexp + +-------------------------------------------------------- +-- the ccexp WebView +-- @field [parent=#ccexp] WebView#WebView WebView preloaded module + + +return nil diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.cpp new file mode 100644 index 0000000000..3a030c2b47 --- /dev/null +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.cpp @@ -0,0 +1,734 @@ +#include "lua_cocos2dx_experimental_webview_auto.hpp" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) +#include "UIWebView.h" +#include "tolua_fix.h" +#include "LuaBasicConversions.h" + + + +int lua_cocos2dx_experimental_webview_WebView_loadURL(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_loadURL'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:loadURL"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_loadURL'", nullptr); + return 0; + } + cobj->loadURL(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:loadURL",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_loadURL'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_canGoBack(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_canGoBack'", 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_experimental_webview_WebView_canGoBack'", nullptr); + return 0; + } + bool ret = cobj->canGoBack(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:canGoBack",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_canGoBack'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_loadHTMLString(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_loadHTMLString'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:loadHTMLString"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_loadHTMLString'", nullptr); + return 0; + } + cobj->loadHTMLString(arg0); + lua_settop(tolua_S, 1); + return 1; + } + if (argc == 2) + { + std::string arg0; + std::string arg1; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:loadHTMLString"); + + ok &= luaval_to_std_string(tolua_S, 3,&arg1, "ccexp.WebView:loadHTMLString"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_loadHTMLString'", nullptr); + return 0; + } + cobj->loadHTMLString(arg0, arg1); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:loadHTMLString",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_loadHTMLString'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_goForward(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_goForward'", 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_experimental_webview_WebView_goForward'", nullptr); + return 0; + } + cobj->goForward(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:goForward",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_goForward'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_goBack(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_goBack'", 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_experimental_webview_WebView_goBack'", nullptr); + return 0; + } + cobj->goBack(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:goBack",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_goBack'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_setJavascriptInterfaceScheme(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_setJavascriptInterfaceScheme'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:setJavascriptInterfaceScheme"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_setJavascriptInterfaceScheme'", nullptr); + return 0; + } + cobj->setJavascriptInterfaceScheme(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:setJavascriptInterfaceScheme",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_setJavascriptInterfaceScheme'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_evaluateJS(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_evaluateJS'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:evaluateJS"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_evaluateJS'", nullptr); + return 0; + } + cobj->evaluateJS(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:evaluateJS",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_evaluateJS'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_getOnJSCallback(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_getOnJSCallback'", 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_experimental_webview_WebView_getOnJSCallback'", nullptr); + return 0; + } + cocos2d::experimental::ui::WebView::ccWebViewCallback ret = cobj->getOnJSCallback(); + #pragma warning NO CONVERSION FROM NATIVE FOR std::function; + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:getOnJSCallback",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_getOnJSCallback'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_reload(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_reload'", 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_experimental_webview_WebView_reload'", nullptr); + return 0; + } + cobj->reload(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:reload",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_reload'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_setScalesPageToFit(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_setScalesPageToFit'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + bool arg0; + + ok &= luaval_to_boolean(tolua_S, 2,&arg0, "ccexp.WebView:setScalesPageToFit"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_setScalesPageToFit'", nullptr); + return 0; + } + cobj->setScalesPageToFit(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:setScalesPageToFit",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_setScalesPageToFit'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_canGoForward(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_canGoForward'", 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_experimental_webview_WebView_canGoForward'", nullptr); + return 0; + } + bool ret = cobj->canGoForward(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:canGoForward",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_canGoForward'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_loadFile(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_loadFile'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + std::string arg0; + + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.WebView:loadFile"); + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_loadFile'", nullptr); + return 0; + } + cobj->loadFile(arg0); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:loadFile",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_loadFile'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_stopLoading(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::experimental::ui::WebView* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::experimental::ui::WebView*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_experimental_webview_WebView_stopLoading'", 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_experimental_webview_WebView_stopLoading'", nullptr); + return 0; + } + cobj->stopLoading(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccexp.WebView:stopLoading",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_stopLoading'.",&tolua_err); +#endif + + return 0; +} +int lua_cocos2dx_experimental_webview_WebView_create(lua_State* tolua_S) +{ + int argc = 0; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertable(tolua_S,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + argc = lua_gettop(tolua_S) - 1; + + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_experimental_webview_WebView_create'", nullptr); + return 0; + } + cocos2d::experimental::ui::WebView* ret = cocos2d::experimental::ui::WebView::create(); + object_to_luaval(tolua_S, "ccexp.WebView",(cocos2d::experimental::ui::WebView*)ret); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.WebView:create",argc, 0); + return 0; +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_experimental_webview_WebView_create'.",&tolua_err); +#endif + return 0; +} +static int lua_cocos2dx_experimental_webview_WebView_finalize(lua_State* tolua_S) +{ + printf("luabindings: finalizing LUA object (WebView)"); + return 0; +} + +int lua_register_cocos2dx_experimental_webview_WebView(lua_State* tolua_S) +{ + tolua_usertype(tolua_S,"ccexp.WebView"); + tolua_cclass(tolua_S,"WebView","ccexp.WebView","ccui.Widget",nullptr); + + tolua_beginmodule(tolua_S,"WebView"); + tolua_function(tolua_S,"loadURL",lua_cocos2dx_experimental_webview_WebView_loadURL); + tolua_function(tolua_S,"canGoBack",lua_cocos2dx_experimental_webview_WebView_canGoBack); + tolua_function(tolua_S,"loadHTMLString",lua_cocos2dx_experimental_webview_WebView_loadHTMLString); + tolua_function(tolua_S,"goForward",lua_cocos2dx_experimental_webview_WebView_goForward); + tolua_function(tolua_S,"goBack",lua_cocos2dx_experimental_webview_WebView_goBack); + tolua_function(tolua_S,"setJavascriptInterfaceScheme",lua_cocos2dx_experimental_webview_WebView_setJavascriptInterfaceScheme); + tolua_function(tolua_S,"evaluateJS",lua_cocos2dx_experimental_webview_WebView_evaluateJS); + tolua_function(tolua_S,"getOnJSCallback",lua_cocos2dx_experimental_webview_WebView_getOnJSCallback); + tolua_function(tolua_S,"reload",lua_cocos2dx_experimental_webview_WebView_reload); + tolua_function(tolua_S,"setScalesPageToFit",lua_cocos2dx_experimental_webview_WebView_setScalesPageToFit); + tolua_function(tolua_S,"canGoForward",lua_cocos2dx_experimental_webview_WebView_canGoForward); + tolua_function(tolua_S,"loadFile",lua_cocos2dx_experimental_webview_WebView_loadFile); + tolua_function(tolua_S,"stopLoading",lua_cocos2dx_experimental_webview_WebView_stopLoading); + tolua_function(tolua_S,"create", lua_cocos2dx_experimental_webview_WebView_create); + tolua_endmodule(tolua_S); + std::string typeName = typeid(cocos2d::experimental::ui::WebView).name(); + g_luaType[typeName] = "ccexp.WebView"; + g_typeCast["WebView"] = "ccexp.WebView"; + return 1; +} +TOLUA_API int register_all_cocos2dx_experimental_webview(lua_State* tolua_S) +{ + tolua_open(tolua_S); + + tolua_module(tolua_S,"ccexp",0); + tolua_beginmodule(tolua_S,"ccexp"); + + lua_register_cocos2dx_experimental_webview_WebView(tolua_S); + + tolua_endmodule(tolua_S); + return 1; +} + +#endif diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp new file mode 100644 index 0000000000..aa6680edf3 --- /dev/null +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp @@ -0,0 +1,32 @@ +#include "base/ccConfig.h" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) +#ifndef __cocos2dx_experimental_webview_h__ +#define __cocos2dx_experimental_webview_h__ + +#ifdef __cplusplus +extern "C" { +#endif +#include "tolua++.h" +#ifdef __cplusplus +} +#endif + +int register_all_cocos2dx_experimental_webview(lua_State* tolua_S); + + + + + + + + + + + + + + + + +#endif // __cocos2dx_experimental_webview_h__ +#endif //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) diff --git a/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.cpp b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.cpp new file mode 100644 index 0000000000..f9892ae91c --- /dev/null +++ b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.cpp @@ -0,0 +1,190 @@ +#include "lua_cocos2dx_experimental_video_manual.hpp" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + +#include "UIWebView.h" +#include "tolua_fix.h" +#include "LuaBasicConversions.h" +#include "CCLuaValue.h" +#include "CCLuaEngine.h" + + + +static int lua_cocos2dx_experimental_WebView_setOnShouldStartLoading(lua_State* L) +{ + + int argc = 0; + cocos2d::experimental::ui::WebView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_experimental_WebView_setOnShouldStartLoading'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (argc == 1) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + std::function callback = [L,handler](experimental::ui::WebView *sender, const std::string &url)->bool{ + toluafix_pushusertype_ccobject(L, sender->_ID, &(sender->_luaID), (void*)sender,"ccexp.WebView"); + tolua_pushcppstring(L, url); + return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); + }; + + ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler); + self->setOnShouldStartLoading(callback); + + return 0; + } + luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.WebView:setOnShouldStartLoading",argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(L, "#ferror in function 'lua_cocos2dx_experimental_WebView_setOnShouldStartLoading'.", &tolua_err); +#endif + return 0; +} + +static int lua_cocos2dx_experimental_WebView_setOnDidFinishLoading(lua_State* L) +{ + + int argc = 0; + cocos2d::experimental::ui::WebView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_experimental_WebView_setOnDidFinishLoading'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (argc == 1) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + std::function callback = [L,handler](experimental::ui::WebView *sender, const std::string &url){ + toluafix_pushusertype_ccobject(L, sender->_ID, &(sender->_luaID), (void*)sender,"ccexp.WebView"); + tolua_pushcppstring(L, url); + LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); + }; + + ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler); + self->setOnDidFinishLoading(callback); + return 0; + } + luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.WebView:setOnDidFinishLoading",argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L, "#ferror in function 'lua_cocos2dx_experimental_WebView_setOnDidFinishLoading'.", &tolua_err); +#endif + return 0; +} + +static int lua_cocos2dx_experimental_WebView_setOnDidFailLoading(lua_State* L) +{ + + int argc = 0; + cocos2d::experimental::ui::WebView* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"ccexp.WebView",0,&tolua_err)) goto tolua_lerror; +#endif + + self = static_cast(tolua_tousertype(L,1,0)); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_experimental_WebView_setOnDidFailLoading'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (argc == 1) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err)) + { + goto tolua_lerror; + } +#endif + + LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0)); + std::function callback = [L,handler](experimental::ui::WebView *sender, const std::string &url){ + toluafix_pushusertype_ccobject(L, sender->_ID, &(sender->_luaID), (void*)sender,"ccexp.WebView"); + tolua_pushcppstring(L, url); + LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); + }; + + ScriptHandlerMgr::getInstance()->addCustomHandler((void*)self, handler); + self->setOnDidFinishLoading(callback); + return 0; + } + luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.WebView:setOnDidFailLoading",argc, 1); + return 0; +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L, "#ferror in function 'lua_cocos2dx_experimental_WebView_setOnDidFailLoading'.", &tolua_err); +#endif + return 0; +} + +static void extendWebView(lua_State* L) +{ + lua_pushstring(L, "ccexp.WebView"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "setOnShouldStartLoading", lua_cocos2dx_experimental_WebView_setOnShouldStartLoading); + tolua_function(L, "setOnDidFinishLoading", lua_cocos2dx_experimental_WebView_setOnDidFinishLoading); + tolua_function(L, "setOnDidFailLoading", lua_cocos2dx_experimental_WebView_setOnDidFailLoading); + } + lua_pop(L, 1); +} + +int register_all_cocos2dx_experimental_webview_manual(lua_State* L) +{ + if (nullptr == L) + return 0; + + extendWebView(L); + + return 0; +} + +#endif diff --git a/cocos/ui/shaders/UIShaders.cpp b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp similarity index 65% rename from cocos/ui/shaders/UIShaders.cpp rename to cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp index 40d9459dad..909e64530c 100644 --- a/cocos/ui/shaders/UIShaders.cpp +++ b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp @@ -21,14 +21,21 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ +#include "base/ccConfig.h" +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#include "UIShaders.h" +#ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_EXPERIMENTAL_WEBVIEW_MANUAL_H +#define COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_EXPERIMENTAL_WEBVIEW_MANUAL_H -#define STRINGIFY(A) #A +#ifdef __cplusplus +extern "C" { +#endif +#include "tolua++.h" +#ifdef __cplusplus +} +#endif -NS_CC_BEGIN +TOLUA_API int register_all_cocos2dx_experimental_webview_manual(lua_State* L); -//include the gray scale shader -#include "ccShader_grayscale.frag" - -NS_CC_END \ No newline at end of file +#endif //#ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_EXPERIMENTAL_WEBVIEW_MANUAL_H +#endif //#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) diff --git a/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp index 0e0afe8623..68749b939d 100644 --- a/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp @@ -26,6 +26,8 @@ #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #include "lua_cocos2dx_experimental_video_auto.hpp" #include "lua_cocos2dx_experimental_video_manual.hpp" +#include "lua_cocos2dx_experimental_webview_auto.hpp" +#include "lua_cocos2dx_experimental_webview_manual.hpp" #endif #include "cocos2d.h" #include "tolua_fix.h" @@ -1045,6 +1047,8 @@ int register_ui_moudle(lua_State* L) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) register_all_cocos2dx_experimental_video(L); register_all_cocos2dx_experimental_video_manual(L); + register_all_cocos2dx_experimental_webview(L); + register_all_cocos2dx_experimental_webview_manual(L); #endif extendEventListenerFocusEvent(L); } diff --git a/cocos/scripting/lua-bindings/proj.android/Android.mk b/cocos/scripting/lua-bindings/proj.android/Android.mk index 600da574fa..109c7ec579 100644 --- a/cocos/scripting/lua-bindings/proj.android/Android.mk +++ b/cocos/scripting/lua-bindings/proj.android/Android.mk @@ -105,10 +105,12 @@ LOCAL_SRC_FILES += ../manual/spine/lua_cocos2dx_spine_manual.cpp \ ../auto/lua_cocos2dx_spine_auto.cpp #ui -LOCAL_SRC_FILES += ../manual/ui/lua_cocos2dx_experimental_video_manual.cpp \ +LOCAL_SRC_FILES += ../manual/ui/lua_cocos2dx_experimental_webview_manual.cpp \ + ../manual/ui/lua_cocos2dx_experimental_video_manual.cpp \ ../manual/ui/lua_cocos2dx_ui_manual.cpp \ ../auto/lua_cocos2dx_experimental_video_auto.cpp \ - ../auto/lua_cocos2dx_ui_auto.cpp + ../auto/lua_cocos2dx_ui_auto.cpp \ + ../auto/lua_cocos2dx_experimental_webview_auto.cpp #extension LOCAL_SRC_FILES += ../manual/extension/lua_cocos2dx_extension_manual.cpp \ diff --git a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj index 5040b992a8..f3bd4c33e4 100644 --- a/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj +++ b/cocos/scripting/lua-bindings/proj.ios_mac/cocos2d_lua_bindings.xcodeproj/project.pbxproj @@ -201,6 +201,10 @@ 15C1C2EC19874CBE00A46ACC /* LuaBasicConversions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE77F18BC45C200215002 /* LuaBasicConversions.h */; }; 15C1C2ED19874CBE00A46ACC /* CCLuaObjcBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE78E18BC45C200215002 /* CCLuaObjcBridge.h */; }; 15C1C2EE19874CBE00A46ACC /* tolua_fix.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AACE7B418BC45C200215002 /* tolua_fix.h */; }; + 15C9A10E1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15C9A10C1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.cpp */; }; + 15C9A10F1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 15C9A10D1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.hpp */; }; + 15C9A1121AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15C9A1101AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.cpp */; }; + 15C9A1131AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 15C9A1111AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.hpp */; }; 15EFA1F61989E528000C57D3 /* lua_cocos2dx_experimental_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15622967197780DE009C9067 /* lua_cocos2dx_experimental_auto.cpp */; }; 15EFA1F71989E582000C57D3 /* lua_cocos2dx_experimental_auto.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 15622968197780DE009C9067 /* lua_cocos2dx_experimental_auto.hpp */; }; 15EFA5D9198B2DAA000C57D3 /* libluajit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1ABCA1F318CD8F540087CE3A /* libluajit.a */; }; @@ -351,6 +355,10 @@ 15C1C24F198747E400A46ACC /* LuaOpengl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LuaOpengl.cpp; sourceTree = ""; }; 15C1C250198747E400A46ACC /* LuaOpengl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LuaOpengl.h; sourceTree = ""; }; 15C1C2CC198748D200A46ACC /* libluacocos2d Mac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libluacocos2d Mac.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 15C9A10C1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_experimental_webview_auto.cpp; sourceTree = ""; }; + 15C9A10D1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_experimental_webview_auto.hpp; sourceTree = ""; }; + 15C9A1101AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_experimental_webview_manual.cpp; sourceTree = ""; }; + 15C9A1111AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_experimental_webview_manual.hpp; sourceTree = ""; }; 15EFA401198B2AB2000C57D3 /* lua_cocos2dx_coco_studio_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_coco_studio_manual.cpp; sourceTree = ""; }; 15EFA402198B2AB2000C57D3 /* lua_cocos2dx_coco_studio_manual.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_coco_studio_manual.hpp; sourceTree = ""; }; 15EFA616198B2DAA000C57D3 /* libluacocos2d iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libluacocos2d iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -536,6 +544,8 @@ 15C1BD191986526C00A46ACC /* ui */ = { isa = PBXGroup; children = ( + 15C9A1101AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.cpp */, + 15C9A1111AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.hpp */, 15C1C24B1987473200A46ACC /* lua_cocos2dx_experimental_video_manual.cpp */, 15C1C24C1987473200A46ACC /* lua_cocos2dx_experimental_video_manual.hpp */, 15C1BD1A1986526C00A46ACC /* lua_cocos2dx_ui_manual.cpp */, @@ -562,6 +572,8 @@ 1AACE74818BC45C200215002 /* auto */ = { isa = PBXGroup; children = ( + 15C9A10C1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.cpp */, + 15C9A10D1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.hpp */, 159552381A25E1C5001E9FC9 /* lua_cocos2dx_csloader_auto.cpp */, 159552391A25E1C5001E9FC9 /* lua_cocos2dx_csloader_auto.hpp */, 3E2BDB0319C5E5FE0055CDCD /* lua_cocos2dx_audioengine_auto.cpp */, @@ -877,7 +889,9 @@ 15EFA62C198B3220000C57D3 /* lua_cocos2dx_deprecated.h in Headers */, 155C7E2919A71CE800F08B25 /* lua_cocos2dx_ui_manual.hpp in Headers */, 15EFA62D198B3220000C57D3 /* lua_cocos2dx_experimental_manual.hpp in Headers */, + 15C9A1131AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.hpp in Headers */, 15EFA62E198B3220000C57D3 /* lua_cocos2dx_manual.hpp in Headers */, + 15C9A10F1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.hpp in Headers */, 15EFA62F198B3220000C57D3 /* lua_cocos2dx_physics_manual.hpp in Headers */, 155C7E0919A71C8500F08B25 /* lua_cocos2dx_extension_manual.h in Headers */, 155C7E1919A71CB500F08B25 /* lua_xml_http_request.h in Headers */, @@ -1064,6 +1078,7 @@ 15EFA639198B328B000C57D3 /* tolua_fix.cpp in Sources */, 155C7DFF19A71C5C00F08B25 /* CCBProxy.cpp in Sources */, 1595523B1A25E1C5001E9FC9 /* lua_cocos2dx_csloader_auto.cpp in Sources */, + 15C9A1121AE4973400C15443 /* lua_cocos2dx_experimental_webview_manual.cpp in Sources */, 155C7DF019A71C1E00F08B25 /* lua_cocos2dx_spine_auto.cpp in Sources */, 155C7E0719A71C7800F08B25 /* lua_cocos2dx_extension_manual.cpp in Sources */, 15EFA625198B31FB000C57D3 /* LuaOpengl.cpp in Sources */, @@ -1087,6 +1102,7 @@ 3E2BDB0519C5E5FE0055CDCD /* lua_cocos2dx_audioengine_auto.cpp in Sources */, 155C7E0B19A71C8D00F08B25 /* lua_cocos2dx_network_manual.cpp in Sources */, 15415AAE19A71A53004F1E71 /* except.c in Sources */, + 15C9A10E1AE4972500C15443 /* lua_cocos2dx_experimental_webview_auto.cpp in Sources */, 15415AAA19A71A53004F1E71 /* buffer.c in Sources */, 155C7E2319A71CD500F08B25 /* lua_cocos2dx_experimental_video_manual.cpp in Sources */, 155C7DFB19A71C4E00F08B25 /* lua_cocos2dx_coco_studio_manual.cpp in Sources */, diff --git a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj index 1fd751484b..84877003c9 100644 --- a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj +++ b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj @@ -39,6 +39,7 @@ + @@ -74,6 +75,7 @@ + @@ -107,6 +109,7 @@ + @@ -142,6 +145,7 @@ + diff --git a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters index f9bc11febe..f0af1a57a2 100644 --- a/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters +++ b/cocos/scripting/lua-bindings/proj.win32/libluacocos2d.vcxproj.filters @@ -267,6 +267,12 @@ manual\cocostudio + + auto + + + manual\ui + @@ -467,6 +473,12 @@ manual\cocostudio + + auto + + + manual\ui + diff --git a/cocos/ui/Android.mk b/cocos/ui/Android.mk index 68ec53d8d7..316d8a51d1 100644 --- a/cocos/ui/Android.mk +++ b/cocos/ui/Android.mk @@ -36,7 +36,6 @@ UIWebViewImpl-android.cpp \ UIEditBox/UIEditBox.cpp \ UIEditBox/UIEditBoxImpl-android.cpp \ UILayoutComponent.cpp \ -shaders/UIShaders.cpp \ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../editor-support diff --git a/cocos/ui/CMakeLists.txt b/cocos/ui/CMakeLists.txt index f5d43a4198..42f2cde9a8 100644 --- a/cocos/ui/CMakeLists.txt +++ b/cocos/ui/CMakeLists.txt @@ -49,7 +49,6 @@ set(COCOS_UI_SRC ui/UIWidget.cpp ui/UIEditBox/UIEditBox.cpp ui/UILayoutComponent.cpp - ui/shaders/UIShaders.cpp ${COCOS_UI_SPECIFIC_SRC} ) diff --git a/cocos/ui/UIScale9Sprite.cpp b/cocos/ui/UIScale9Sprite.cpp index 91d3caf464..20b5ac8959 100644 --- a/cocos/ui/UIScale9Sprite.cpp +++ b/cocos/ui/UIScale9Sprite.cpp @@ -1,18 +1,18 @@ /**************************************************************************** Copyright (c) 2013-2014 Chukong Technologies Inc. - + http://www.cocos2d-x.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -28,12 +28,11 @@ #include "base/CCVector.h" #include "base/CCDirector.h" #include "renderer/CCGLProgram.h" -#include "ui/shaders/UIShaders.h" #include "renderer/ccShaders.h" NS_CC_BEGIN namespace ui { - + Scale9Sprite::Scale9Sprite() : _spritesGenerated(false) , _spriteFrameRotated(false) @@ -59,13 +58,13 @@ namespace ui { { this->setAnchorPoint(Vec2(0.5,0.5)); } - + Scale9Sprite::~Scale9Sprite() { this->cleanupSlicedSprites(); CC_SAFE_RELEASE(_scale9Image); } - + void Scale9Sprite::cleanupSlicedSprites() { if (_topLeftSprite && _topLeftSprite->isRunning()) @@ -80,37 +79,37 @@ namespace ui { { _topRightSprite->onExit(); } - + if (_leftSprite && _leftSprite->isRunning()) { _leftSprite->onExit(); } - + if (_centerSprite && _centerSprite->isRunning()) { _centerSprite->onExit(); } - + if (_rightSprite && _rightSprite->isRunning()) { _rightSprite->onExit(); } - + if (_bottomLeftSprite && _bottomLeftSprite->isRunning()) { _bottomLeftSprite->onExit(); } - + if (_bottomRightSprite && _bottomRightSprite->isRunning()) { _bottomRightSprite->onExit(); } - + if (_bottomSprite && _bottomSprite->isRunning()) { _bottomSprite->onExit(); } - + CC_SAFE_RELEASE_NULL(_topLeftSprite); CC_SAFE_RELEASE_NULL(_topSprite); CC_SAFE_RELEASE_NULL(_topRightSprite); @@ -121,44 +120,44 @@ namespace ui { CC_SAFE_RELEASE_NULL(_bottomSprite); CC_SAFE_RELEASE_NULL(_bottomRightSprite); } - + bool Scale9Sprite::init() { return this->init(NULL, Rect::ZERO, Rect::ZERO); } - + bool Scale9Sprite::init(Sprite* sprite, const Rect& rect, const Rect& capInsets) { return this->init(sprite, rect, false, capInsets); } - + bool Scale9Sprite::init(Sprite* sprite, const Rect& rect, bool rotated, const Rect& capInsets) { return init(sprite, rect, rotated, Vec2::ZERO, rect.size, capInsets); } - + bool Scale9Sprite::init(Sprite* sprite, const Rect& rect, bool rotated, const Vec2 &offset, const Size &originalSize, const Rect& capInsets) { if(sprite) { this->updateWithSprite(sprite, rect, rotated, offset, originalSize, capInsets); } - + return true; } - + bool Scale9Sprite::initWithBatchNode(cocos2d::SpriteBatchNode *batchnode, const cocos2d::Rect &rect, bool rotated, const cocos2d::Rect &capInsets) { Sprite *sprite = Sprite::createWithTexture(batchnode->getTexture()); return init(sprite, rect, rotated, capInsets); } - + bool Scale9Sprite::initWithBatchNode(cocos2d::SpriteBatchNode *batchnode, const cocos2d::Rect &rect, const cocos2d::Rect &capInsets) { auto sprite = Sprite::createWithTexture(batchnode->getTexture()); return init(sprite, rect, false, capInsets); } - + void Scale9Sprite::setBlendFunc(const BlendFunc &blendFunc) { _blendFunc = blendFunc; @@ -168,10 +167,10 @@ namespace ui { { return _blendFunc; } - + void Scale9Sprite::updateBlendFunc(Texture2D *texture) { - + // it is possible to have an untextured sprite if (! texture || ! texture->hasPremultipliedAlpha()) { @@ -184,7 +183,7 @@ namespace ui { setOpacityModifyRGB(true); } } - + void Scale9Sprite::applyBlendFunc() { if(_scale9Image) @@ -214,35 +213,35 @@ namespace ui { Sprite *sprite = Sprite::createWithTexture(batchnode->getTexture()); return this->updateWithSprite(sprite, originalRect, rotated, Vec2::ZERO, originalRect.size, capInsets); } - + bool Scale9Sprite::updateWithSprite(Sprite* sprite, const Rect& rect, bool rotated, const Rect& capInsets) { return updateWithSprite(sprite, rect, rotated, Vec2::ZERO, rect.size, capInsets); } - + static Rect intersectRect(const Rect &first, const Rect &second) { Rect ret; ret.origin.x = std::max(first.origin.x,second.origin.x); ret.origin.y = std::max(first.origin.y,second.origin.y); - + float rightRealPoint = std::min(first.origin.x + first.size.width, second.origin.x + second.size.width); float bottomRealPoint = std::min(first.origin.y + first.size.height, second.origin.y + second.size.height); - + ret.size.width = std::max(rightRealPoint - ret.origin.x, 0.0f); ret.size.height = std::max(bottomRealPoint - ret.origin.y, 0.0f); return ret; } - + bool Scale9Sprite::updateWithSprite(Sprite* sprite, const Rect& textureRect, bool rotated, const Vec2 &offset, const Size &originalSize, const Rect& capInsets) { GLubyte opacity = getOpacity(); Color3B color = getColor(); - + // Release old sprites this->cleanupSlicedSprites(); _protectedChildren.clear(); - + updateBlendFunc(sprite?sprite->getTexture():nullptr); if(nullptr != sprite) @@ -251,7 +250,7 @@ namespace ui { { return false; } - + if (nullptr == _scale9Image) { _scale9Image = sprite; @@ -262,38 +261,38 @@ namespace ui { _scale9Image->setSpriteFrame(sprite->getSpriteFrame()); } } - + if (!_scale9Image) { return false; } - + SpriteFrame *spriteFrame = _scale9Image->getSpriteFrame(); - + if (!spriteFrame) { return false; } - + Rect rect(textureRect); Size size(originalSize); - + _capInsets = capInsets; - + // If there is no given rect if ( rect.equals(Rect::ZERO) ) { // Get the texture size as original Size textureSize = _scale9Image->getTexture()->getContentSize(); - + rect = Rect(0, 0, textureSize.width, textureSize.height); } - + if( size.equals(Size::ZERO) ) { size = rect.size; } - + // Set the given rect's size as original size _spriteRect = rect; _offset = offset; @@ -301,16 +300,16 @@ namespace ui { _originalSize = size; _preferredSize = size; _capInsetsInternal = capInsets; - + if (_scale9Enabled) { this->createSlicedSprites(); } - + applyBlendFunc(); - + this->setContentSize(size); - + if (_spritesGenerated) { // Restore color and opacity @@ -318,59 +317,59 @@ namespace ui { this->setColor(color); } _spritesGenerated = true; - + return true; } - + void Scale9Sprite::createSlicedSprites() { float width = _originalSize.width; float height = _originalSize.height; - + Vec2 offsetPosition(ceilf(_offset.x + (_originalSize.width - _spriteRect.size.width) / 2), ceilf(_offset.y + (_originalSize.height - _spriteRect.size.height) / 2)); - + // If there is no specified center region if ( _capInsetsInternal.equals(Rect::ZERO) ) { // log("... cap insets not specified : using default cap insets ..."); _capInsetsInternal = Rect(width /3, height /3, width /3, height /3); } - + Rect originalRect; if(_spriteFrameRotated) originalRect = Rect(_spriteRect.origin.x - offsetPosition.y, _spriteRect.origin.y - offsetPosition.x, _originalSize.width, _originalSize.height); else originalRect = Rect(_spriteRect.origin.x - offsetPosition.x, _spriteRect.origin.y - offsetPosition.y, _originalSize.width, _originalSize.height); - + float leftWidth = _capInsetsInternal.origin.x; float centerWidth = _capInsetsInternal.size.width; float rightWidth = originalRect.size.width - (leftWidth + centerWidth); - + float topHeight = _capInsetsInternal.origin.y; float centerHeight = _capInsetsInternal.size.height; float bottomHeight = originalRect.size.height - (topHeight + centerHeight); - + // calculate rects - + // ... top row float x = 0.0; float y = 0.0; - + Rect pixelRect = Rect(offsetPosition.x, offsetPosition.y, _spriteRect.size.width, _spriteRect.size.height); - + // top left Rect leftTopBoundsOriginal = Rect(x, y, leftWidth, topHeight); Rect leftTopBounds = leftTopBoundsOriginal; - + // top center x += leftWidth; Rect centerTopBounds = Rect(x, y, centerWidth, topHeight); - + // top right x += centerWidth; Rect rightTopBounds = Rect(x, y, rightWidth, topHeight); - + // ... center row x = 0.0; y = 0.0; @@ -378,16 +377,16 @@ namespace ui { // center left Rect leftCenterBounds = Rect(x, y, leftWidth, centerHeight); - + // center center x += leftWidth; Rect centerBoundsOriginal = Rect(x, y, centerWidth, centerHeight); Rect centerBounds = centerBoundsOriginal; - + // center right x += centerWidth; Rect rightCenterBounds = Rect(x, y, rightWidth, centerHeight); - + // ... bottom row x = 0.0; y = 0.0; @@ -396,16 +395,16 @@ namespace ui { // bottom left Rect leftBottomBounds = Rect(x, y, leftWidth, bottomHeight); - + // bottom center x += leftWidth; Rect centerBottomBounds = Rect(x, y, centerWidth, bottomHeight); - + // bottom right x += centerWidth; Rect rightBottomBoundsOriginal = Rect(x, y, rightWidth, bottomHeight); Rect rightBottomBounds = rightBottomBoundsOriginal; - + if((_capInsetsInternal.origin.x + _capInsetsInternal.size.width) <= _originalSize.width || (_capInsetsInternal.origin.y + _capInsetsInternal.size.height) <= _originalSize.height) //in general case it is error but for legacy support we will check it @@ -423,11 +422,11 @@ namespace ui { else //it is error but for legacy turn off clip system CCLOG("Scale9Sprite capInsetsInternal > originalSize"); - + Rect rotatedLeftTopBoundsOriginal = leftTopBoundsOriginal; Rect rotatedCenterBoundsOriginal = centerBoundsOriginal; Rect rotatedRightBottomBoundsOriginal = rightBottomBoundsOriginal; - + Rect rotatedCenterBounds = centerBounds; Rect rotatedRightBottomBounds = rightBottomBounds; Rect rotatedLeftBottomBounds = leftBottomBounds; @@ -437,17 +436,17 @@ namespace ui { Rect rotatedLeftCenterBounds = leftCenterBounds; Rect rotatedCenterBottomBounds = centerBottomBounds; Rect rotatedCenterTopBounds = centerTopBounds; - + if (!_spriteFrameRotated) { - + AffineTransform t = AffineTransform::IDENTITY; t = AffineTransformTranslate(t, originalRect.origin.x, originalRect.origin.y); - + rotatedLeftTopBoundsOriginal = RectApplyAffineTransform(rotatedLeftTopBoundsOriginal, t); rotatedCenterBoundsOriginal = RectApplyAffineTransform(rotatedCenterBoundsOriginal, t); rotatedRightBottomBoundsOriginal = RectApplyAffineTransform(rotatedRightBottomBoundsOriginal, t); - + rotatedCenterBounds = RectApplyAffineTransform(rotatedCenterBounds, t); rotatedRightBottomBounds = RectApplyAffineTransform(rotatedRightBottomBounds, t); rotatedLeftBottomBounds = RectApplyAffineTransform(rotatedLeftBottomBounds, t); @@ -457,23 +456,23 @@ namespace ui { rotatedLeftCenterBounds = RectApplyAffineTransform(rotatedLeftCenterBounds, t); rotatedCenterBottomBounds = RectApplyAffineTransform(rotatedCenterBottomBounds, t); rotatedCenterTopBounds = RectApplyAffineTransform(rotatedCenterTopBounds, t); - - + + } else { // set up transformation of coordinates // to handle the case where the sprite is stored rotated // in the spritesheet // log("rotated"); - + AffineTransform t = AffineTransform::IDENTITY; - + t = AffineTransformTranslate(t, originalRect.size.height+originalRect.origin.x, originalRect.origin.y); t = AffineTransformRotate(t, 1.57079633f); - + leftTopBoundsOriginal = RectApplyAffineTransform(leftTopBoundsOriginal, t); centerBoundsOriginal = RectApplyAffineTransform(centerBoundsOriginal, t); rightBottomBoundsOriginal = RectApplyAffineTransform(rightBottomBoundsOriginal, t); - + centerBounds = RectApplyAffineTransform(centerBounds, t); rightBottomBounds = RectApplyAffineTransform(rightBottomBounds, t); leftBottomBounds = RectApplyAffineTransform(leftBottomBounds, t); @@ -483,11 +482,11 @@ namespace ui { leftCenterBounds = RectApplyAffineTransform(leftCenterBounds, t); centerBottomBounds = RectApplyAffineTransform(centerBottomBounds, t); centerTopBounds = RectApplyAffineTransform(centerTopBounds, t); - + rotatedLeftTopBoundsOriginal.origin = leftTopBoundsOriginal.origin; rotatedCenterBoundsOriginal.origin = centerBoundsOriginal.origin; rotatedRightBottomBoundsOriginal.origin = rightBottomBoundsOriginal.origin; - + rotatedCenterBounds.origin = centerBounds.origin; rotatedRightBottomBounds.origin = rightBottomBounds.origin; rotatedLeftBottomBounds.origin = leftBottomBounds.origin; @@ -497,14 +496,14 @@ namespace ui { rotatedLeftCenterBounds.origin = leftCenterBounds.origin; rotatedCenterBottomBounds.origin = centerBottomBounds.origin; rotatedCenterTopBounds.origin = centerTopBounds.origin; - - + + } - + _topLeftSize = rotatedLeftTopBoundsOriginal.size; _centerSize = rotatedCenterBoundsOriginal.size; _bottomRightSize = rotatedRightBottomBoundsOriginal.size; - + if(_spriteFrameRotated) { float offsetX = (rotatedCenterBounds.origin.x + rotatedCenterBounds.size.height/2) - (rotatedCenterBoundsOriginal.origin.x + rotatedCenterBoundsOriginal.size.height/2); @@ -519,7 +518,7 @@ namespace ui { _centerOffset.x = offsetX; _centerOffset.y = offsetY; } - + // Centre if(rotatedCenterBounds.size.width > 0 && rotatedCenterBounds.size.height > 0 ) { @@ -527,7 +526,7 @@ namespace ui { _centerSprite->retain(); this->addProtectedChild(_centerSprite); } - + // Top if(rotatedCenterTopBounds.size.width > 0 && rotatedCenterTopBounds.size.height > 0 ) { @@ -535,7 +534,7 @@ namespace ui { _topSprite->retain(); this->addProtectedChild(_topSprite); } - + // Bottom if(rotatedCenterBottomBounds.size.width > 0 && rotatedCenterBottomBounds.size.height > 0 ) { @@ -543,7 +542,7 @@ namespace ui { _bottomSprite->retain(); this->addProtectedChild(_bottomSprite); } - + // Left if(rotatedLeftCenterBounds.size.width > 0 && rotatedLeftCenterBounds.size.height > 0 ) { @@ -551,7 +550,7 @@ namespace ui { _leftSprite->retain(); this->addProtectedChild(_leftSprite); } - + // Right if(rotatedRightCenterBounds.size.width > 0 && rotatedRightCenterBounds.size.height > 0 ) { @@ -559,7 +558,7 @@ namespace ui { _rightSprite->retain(); this->addProtectedChild(_rightSprite); } - + // Top left if(rotatedLeftTopBounds.size.width > 0 && rotatedLeftTopBounds.size.height > 0 ) { @@ -567,7 +566,7 @@ namespace ui { _topLeftSprite->retain(); this->addProtectedChild(_topLeftSprite); } - + // Top right if(rotatedRightTopBounds.size.width > 0 && rotatedRightTopBounds.size.height > 0 ) { @@ -575,7 +574,7 @@ namespace ui { _topRightSprite->retain(); this->addProtectedChild(_topRightSprite); } - + // Bottom left if(rotatedLeftBottomBounds.size.width > 0 && rotatedLeftBottomBounds.size.height > 0 ) { @@ -583,7 +582,7 @@ namespace ui { _bottomLeftSprite->retain(); this->addProtectedChild(_bottomLeftSprite); } - + // Bottom right if(rotatedRightBottomBounds.size.width > 0 && rotatedRightBottomBounds.size.height > 0 ) { @@ -592,37 +591,37 @@ namespace ui { this->addProtectedChild(_bottomRightSprite); } } - + void Scale9Sprite::setContentSize(const Size &size) { Node::setContentSize(size); this->_positionsAreDirty = true; } - + void Scale9Sprite::updatePositions() { Size size = this->_contentSize; - + float sizableWidth = size.width - _topLeftSize.width - _bottomRightSize.width; float sizableHeight = size.height - _topLeftSize.height - _bottomRightSize.height; - + float horizontalScale = sizableWidth/_centerSize.width; float verticalScale = sizableHeight/_centerSize.height; - + if(_centerSprite) { _centerSprite->setScaleX(horizontalScale); _centerSprite->setScaleY(verticalScale); } - + float rescaledWidth = _centerSize.width * horizontalScale; float rescaledHeight = _centerSize.height * verticalScale; - + float leftWidth = _topLeftSize.width; float bottomHeight = _bottomRightSize.height; - + Vec2 centerOffset(_centerOffset.x * horizontalScale, _centerOffset.y * verticalScale); - + // Position corners if(_bottomLeftSprite) { @@ -644,7 +643,7 @@ namespace ui { _topRightSprite->setAnchorPoint(Vec2(0,0)); _topRightSprite->setPosition(leftWidth+rescaledWidth, bottomHeight+rescaledHeight); } - + // Scale and position borders if(_leftSprite) { @@ -679,14 +678,14 @@ namespace ui { _centerSprite->setScaleY(verticalScale); } } - + bool Scale9Sprite::initWithFile(const std::string& file, const Rect& rect, const Rect& capInsets) { Sprite *sprite = Sprite::create(file); bool pReturn = this->init(sprite, rect, capInsets); return pReturn; } - + Scale9Sprite* Scale9Sprite::create(const std::string& file, const Rect& rect, const Rect& capInsets) { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); @@ -698,13 +697,13 @@ namespace ui { CC_SAFE_DELETE(pReturn); return NULL; } - + bool Scale9Sprite::initWithFile(const std::string& file, const Rect& rect) { bool pReturn = this->initWithFile(file, rect, Rect::ZERO); return pReturn; } - + Scale9Sprite* Scale9Sprite::create(const std::string& file, const Rect& rect) { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); @@ -716,14 +715,14 @@ namespace ui { CC_SAFE_DELETE(pReturn); return NULL; } - - + + bool Scale9Sprite::initWithFile(const Rect& capInsets, const std::string& file) { bool pReturn = this->initWithFile(file, Rect::ZERO, capInsets); return pReturn; } - + Scale9Sprite* Scale9Sprite::create(const Rect& capInsets, const std::string& file) { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); @@ -735,14 +734,14 @@ namespace ui { CC_SAFE_DELETE(pReturn); return NULL; } - + bool Scale9Sprite::initWithFile(const std::string& file) { bool pReturn = this->initWithFile(file, Rect::ZERO); return pReturn; - + } - + Scale9Sprite* Scale9Sprite::create(const std::string& file) { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); @@ -754,19 +753,19 @@ namespace ui { CC_SAFE_DELETE(pReturn); return NULL; } - + bool Scale9Sprite::initWithSpriteFrame(SpriteFrame* spriteFrame, const Rect& capInsets) { Texture2D* texture = spriteFrame->getTexture(); CCASSERT(texture != NULL, "CCTexture must be not nil"); - + Sprite *sprite = Sprite::createWithSpriteFrame(spriteFrame); CCASSERT(sprite != NULL, "sprite must be not nil"); - + bool pReturn = this->init(sprite, spriteFrame->getRect(), spriteFrame->isRotated(), spriteFrame->getOffset(), spriteFrame->getOriginalSize(), capInsets); return pReturn; } - + Scale9Sprite* Scale9Sprite::createWithSpriteFrame(SpriteFrame* spriteFrame, const Rect& capInsets) { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); @@ -784,7 +783,7 @@ namespace ui { bool pReturn = this->initWithSpriteFrame(spriteFrame, Rect::ZERO); return pReturn; } - + Scale9Sprite* Scale9Sprite::createWithSpriteFrame(SpriteFrame* spriteFrame) { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); @@ -796,20 +795,20 @@ namespace ui { CC_SAFE_DELETE(pReturn); return NULL; } - + bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets) { CCASSERT((SpriteFrameCache::getInstance()) != NULL, "SpriteFrameCache::getInstance() must be non-NULL"); - + SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName); CCASSERT(frame != NULL, "CCSpriteFrame must be non-NULL"); - + if (NULL == frame) return false; - + bool pReturn = this->initWithSpriteFrame(frame, capInsets); return pReturn; } - + Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets) { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); @@ -821,13 +820,13 @@ namespace ui { CC_SAFE_DELETE(pReturn); return NULL; } - + bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName) { bool pReturn = this->initWithSpriteFrameName(spriteFrameName, Rect::ZERO); return pReturn; } - + Scale9Sprite* Scale9Sprite::createWithSpriteFrameName(const std::string& spriteFrameName) { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); @@ -837,12 +836,12 @@ namespace ui { return pReturn; } CC_SAFE_DELETE(pReturn); - + log("Could not allocate Scale9Sprite()"); return NULL; - + } - + Scale9Sprite* Scale9Sprite::resizableSpriteWithCapInsets(const Rect& capInsets) const { Scale9Sprite* pReturn = new (std::nothrow) Scale9Sprite(); @@ -854,7 +853,7 @@ namespace ui { CC_SAFE_DELETE(pReturn); return NULL; } - + Scale9Sprite* Scale9Sprite::create() { Scale9Sprite *pReturn = new (std::nothrow) Scale9Sprite(); @@ -866,7 +865,7 @@ namespace ui { CC_SAFE_DELETE(pReturn); return NULL; } - + void Scale9Sprite::setState(cocos2d::ui::Scale9Sprite::State state) { GLProgramState *glState = nullptr; @@ -879,19 +878,17 @@ namespace ui { break; case State::GRAY: { - auto program = GLProgram::createWithByteArrays(ccPositionTextureColor_noMVP_vert, - ccUIGrayScale_frag); - glState = GLProgramState::getOrCreateWithGLProgram(program); + glState = GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_GRAYSCALE); } default: break; } - + if (nullptr != _scale9Image) { _scale9Image->setGLProgramState(glState); } - + if (_scale9Enabled) { for (auto& sp : _protectedChildren) @@ -900,14 +897,14 @@ namespace ui { } } } - + /** sets the opacity. @warning If the the texture has premultiplied alpha then, the R, G and B channels will be modifed. Values goes from 0 to 255, where 255 means fully opaque. */ - - - + + + void Scale9Sprite::updateCapInset() { Rect insets; @@ -924,27 +921,27 @@ namespace ui { } this->setCapInsets(insets); } - - + + void Scale9Sprite::setSpriteFrame(SpriteFrame * spriteFrame, const Rect& capInsets) { Sprite * sprite = Sprite::createWithTexture(spriteFrame->getTexture()); this->updateWithSprite(sprite, spriteFrame->getRect(), spriteFrame->isRotated(), spriteFrame->getOffset(), spriteFrame->getOriginalSize(), capInsets); - + // Reset insets this->_insetLeft = capInsets.origin.x; this->_insetTop = capInsets.origin.y; this->_insetRight = _originalSize.width - _insetLeft - capInsets.size.width; this->_insetBottom = _originalSize.height - _insetTop - capInsets.size.height; } - + void Scale9Sprite::setPreferredSize(const Size& preferedSize) { this->setContentSize(preferedSize); this->_preferredSize = preferedSize; } - - + + void Scale9Sprite::setCapInsets(const Rect& capInsets) { Size contentSize = this->_contentSize; @@ -955,43 +952,43 @@ namespace ui { this->_insetBottom = _originalSize.height - _insetTop - capInsets.size.height; this->setContentSize(contentSize); } - - + + void Scale9Sprite::setInsetLeft(float insetLeft) { this->_insetLeft = insetLeft; this->updateCapInset(); } - + void Scale9Sprite::setInsetTop(float insetTop) { this->_insetTop = insetTop; this->updateCapInset(); } - + void Scale9Sprite::setInsetRight(float insetRight) { this->_insetRight = insetRight; this->updateCapInset(); } - + void Scale9Sprite::setInsetBottom(float insetBottom) { this->_insetBottom = insetBottom; this->updateCapInset(); } - + void Scale9Sprite::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { - + // quick return if not visible. children won't be drawn. if (!_visible) { return; } - + uint32_t flags = processParentFlags(parentTransform, parentFlags); - + // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it @@ -999,32 +996,32 @@ namespace ui { CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); - + int i = 0; // used by _children int j = 0; // used by _protectedChildren - + sortAllChildren(); sortAllProtectedChildren(); - + // // draw children and protectedChildren zOrder < 0 // for( ; i < _children.size(); i++ ) { auto node = _children.at(i); - + if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, flags); else break; } - + if (_scale9Enabled) { for( ; j < _protectedChildren.size(); j++ ) { auto node = _protectedChildren.at(j); - + if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, flags); else @@ -1038,13 +1035,13 @@ namespace ui { _scale9Image->visit(renderer, _modelViewTransform, flags); } } - + // // draw self // if (isVisitableByVisitingCamera()) this->draw(renderer, _modelViewTransform, flags); - + // // draw children and protectedChildren zOrder >= 0 // @@ -1060,56 +1057,56 @@ namespace ui { _scale9Image->visit(renderer, _modelViewTransform, flags); } } - - + + for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, flags); - + // FIX ME: Why need to set _orderOfArrival to 0?? // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920 // setOrderOfArrival(0); - + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - + } - + Size Scale9Sprite::getOriginalSize()const { return _originalSize; } - - + + Size Scale9Sprite::getPreferredSize() const { return _preferredSize; } - + Rect Scale9Sprite::getCapInsets()const { return _capInsets; } - - + + float Scale9Sprite::getInsetLeft()const { return this->_insetLeft; } - + float Scale9Sprite::getInsetTop()const { return this->_insetTop; } - + float Scale9Sprite::getInsetRight()const { return this->_insetRight; } - + float Scale9Sprite::getInsetBottom()const { return this->_insetBottom; } - + void Scale9Sprite::setScale9Enabled(bool enabled) { if (_scale9Enabled == enabled) @@ -1117,13 +1114,13 @@ namespace ui { return; } _scale9Enabled = enabled; - + this->cleanupSlicedSprites(); _protectedChildren.clear(); - + //we must invalide the transform when toggling scale9enabled _transformUpdated = _transformDirty = _inverseDirty = true; - + if (_scale9Enabled) { if (_scale9Image) @@ -1133,18 +1130,18 @@ namespace ui { } _positionsAreDirty = true; } - + bool Scale9Sprite::isScale9Enabled() const { return _scale9Enabled; } - + void Scale9Sprite::addProtectedChild(cocos2d::Node *child) { _reorderProtectedChildDirty = true; _protectedChildren.pushBack(child); } - + void Scale9Sprite::sortAllProtectedChildren() { if(this->_positionsAreDirty) @@ -1159,7 +1156,7 @@ namespace ui { _reorderProtectedChildDirty = false; } } - + void Scale9Sprite::adjustScale9ImagePosition() { if (_scale9Image) @@ -1168,7 +1165,7 @@ namespace ui { _contentSize.height * _scale9Image->getAnchorPoint().y); } } - + void Scale9Sprite::setAnchorPoint(const cocos2d::Vec2 &position) { Node::setAnchorPoint(position); @@ -1181,7 +1178,7 @@ namespace ui { } } } - + void Scale9Sprite::cleanup() { Node::cleanup(); @@ -1189,7 +1186,7 @@ namespace ui { for( const auto &child: _protectedChildren) child->cleanup(); } - + void Scale9Sprite::onEnter() { #if CC_ENABLE_SCRIPT_BINDING @@ -1203,45 +1200,45 @@ namespace ui { for( const auto &child: _protectedChildren) child->onEnter(); } - + void Scale9Sprite::onExit() { Node::onExit(); for( const auto &child: _protectedChildren) child->onExit(); } - + void Scale9Sprite::onEnterTransitionDidFinish() { Node::onEnterTransitionDidFinish(); for( const auto &child: _protectedChildren) child->onEnterTransitionDidFinish(); } - + void Scale9Sprite::onExitTransitionDidStart() { Node::onExitTransitionDidStart(); for( const auto &child: _protectedChildren) child->onExitTransitionDidStart(); } - + void Scale9Sprite::updateDisplayedColor(const cocos2d::Color3B &parentColor) { _displayedColor.r = _realColor.r * parentColor.r/255.0; _displayedColor.g = _realColor.g * parentColor.g/255.0; _displayedColor.b = _realColor.b * parentColor.b/255.0; updateColor(); - + if (_scale9Image) { _scale9Image->updateDisplayedColor(_displayedColor); } - + for(const auto &child : _protectedChildren) { child->updateDisplayedColor(_displayedColor); } - + if (_cascadeColorEnabled) { for(const auto &child : _children) @@ -1250,22 +1247,22 @@ namespace ui { } } } - + void Scale9Sprite::updateDisplayedOpacity(GLubyte parentOpacity) { _displayedOpacity = _realOpacity * parentOpacity/255.0; updateColor(); - + if (_scale9Image) { _scale9Image->updateDisplayedOpacity(_displayedOpacity); } - + for(auto child : _protectedChildren) { child->updateDisplayedOpacity(_displayedOpacity); } - + if (_cascadeOpacityEnabled) { for(auto child : _children) @@ -1274,7 +1271,7 @@ namespace ui { } } } - + void Scale9Sprite::disableCascadeColor() { for(auto child : _children) @@ -1290,50 +1287,50 @@ namespace ui { _scale9Image->updateDisplayedColor(Color3B::WHITE); } } - + void Scale9Sprite::disableCascadeOpacity() { _displayedOpacity = _realOpacity; - + for(auto child : _children){ child->updateDisplayedOpacity(255); } - + for(auto child : _protectedChildren){ child->updateDisplayedOpacity(255); } } - + Sprite* Scale9Sprite::getSprite()const { return _scale9Image; } - + void Scale9Sprite::setFlippedX(bool flippedX) { - + float realScale = this->getScaleX(); _flippedX = flippedX; this->setScaleX(realScale); } - + void Scale9Sprite::setFlippedY(bool flippedY) { float realScale = this->getScaleY(); _flippedY = flippedY; this->setScaleY(realScale); } - + bool Scale9Sprite::isFlippedX()const { return _flippedX; } - + bool Scale9Sprite::isFlippedY()const { return _flippedY; } - + void Scale9Sprite::setScaleX(float scaleX) { if (_flippedX) { @@ -1341,7 +1338,7 @@ namespace ui { } Node::setScaleX(scaleX); } - + void Scale9Sprite::setScaleY(float scaleY) { if (_flippedY) { @@ -1349,20 +1346,20 @@ namespace ui { } Node::setScaleY(scaleY); } - + void Scale9Sprite::setScale(float scale) { this->setScaleX(scale); this->setScaleY(scale); this->setScaleZ(scale); } - + void Scale9Sprite::setScale(float scaleX, float scaleY) { this->setScaleX(scaleX); this->setScaleY(scaleY); } - + float Scale9Sprite::getScaleX()const { float originalScale = Node::getScaleX(); @@ -1372,7 +1369,7 @@ namespace ui { } return originalScale; } - + float Scale9Sprite::getScaleY()const { float originalScale = Node::getScaleY(); @@ -1382,24 +1379,24 @@ namespace ui { } return originalScale; } - + float Scale9Sprite::getScale()const { CCASSERT(this->getScaleX() == this->getScaleY(), "Scale9Sprite#scale. ScaleX != ScaleY. Don't know which one to return"); return this->getScaleX(); } - + void Scale9Sprite::setCameraMask(unsigned short mask, bool applyChildren) { Node::setCameraMask(mask, applyChildren); - + if(_scale9Image) _scale9Image->setCameraMask(mask,applyChildren); - + for(auto& iter: _protectedChildren) { iter->setCameraMask(mask); } } - + }} diff --git a/cocos/ui/UIWebView.h b/cocos/ui/UIWebView.h index c6226bcf28..303dcd366b 100644 --- a/cocos/ui/UIWebView.h +++ b/cocos/ui/UIWebView.h @@ -27,7 +27,7 @@ #include "platform/CCPlatformConfig.h" -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS ) #include "ui/UIWidget.h" diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index d756efd003..e277f0fac9 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -34,16 +34,15 @@ THE SOFTWARE. #include "renderer/CCGLProgram.h" #include "renderer/CCGLProgramState.h" #include "renderer/ccShaders.h" -#include "ui/shaders/UIShaders.h" NS_CC_BEGIN namespace ui { - + class Widget::FocusNavigationController { void enableFocusNavigation(bool flag); - + FocusNavigationController(): _keyboardListener(nullptr), _firstFocusedWidget(nullptr), @@ -55,12 +54,12 @@ class Widget::FocusNavigationController ~FocusNavigationController(); protected: void setFirstFocsuedWidget(Widget* widget); - + void onKeypadKeyPressed(EventKeyboard::KeyCode, Event*); - + void addKeyboardEventListener(); void removeKeyboardEventListener(); - + friend class Widget; private: EventListenerKeyboard* _keyboardListener ; @@ -68,7 +67,7 @@ private: bool _enableFocusNavigation ; const int _keyboardEventPriority; }; - + Widget::FocusNavigationController::~FocusNavigationController() { this->removeKeyboardEventListener(); @@ -101,9 +100,9 @@ void Widget::FocusNavigationController::enableFocusNavigation(bool flag) { if (_enableFocusNavigation == flag) return; - + _enableFocusNavigation = flag; - + if (flag) this->addKeyboardEventListener(); else @@ -138,7 +137,7 @@ void Widget::FocusNavigationController::removeKeyboardEventListener() Widget* Widget::_focusedWidget = nullptr; Widget::FocusNavigationController* Widget::_focusNavigationController = nullptr; - + Widget::Widget(): _usingLayoutComponent(false), _unifySize(false), @@ -167,7 +166,7 @@ _ccEventCallback(nullptr), _callbackType(""), _callbackName("") { - + } Widget::~Widget() @@ -180,7 +179,7 @@ void Widget::cleanupWidget() //clean up _touchListener _eventDispatcher->removeEventListener(_touchListener); CC_SAFE_RELEASE_NULL(_touchListener); - + //cleanup focused widget and focus navigation controller if (_focusedWidget == this) { @@ -214,7 +213,7 @@ bool Widget::init() this->setAnchorPoint(Vec2(0.5f, 0.5f)); ignoreContentAdaptWithSize(true); - + return true; } return false; @@ -251,11 +250,11 @@ void Widget::setEnabled(bool enabled) { _enabled = enabled; } - + void Widget::initRenderer() { } - + LayoutComponent* Widget::getOrCreateLayoutComponent() { auto layoutComponent = this->getComponent(__LAYOUT_COMPONENT_NAME); @@ -265,14 +264,14 @@ LayoutComponent* Widget::getOrCreateLayoutComponent() this->addComponent(component); layoutComponent = component; } - + return (LayoutComponent*)layoutComponent; } - + void Widget::setContentSize(const cocos2d::Size &contentSize) { ProtectedNode::setContentSize(contentSize); - + _customSize = contentSize; if (_unifySize) { @@ -354,10 +353,10 @@ void Widget::setSizePercent(const Vec2 &percent) void Widget::updateSizeAndPosition() { Size pSize = _parent->getContentSize(); - + updateSizeAndPosition(pSize); } - + void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize) { switch (_sizeType) @@ -402,7 +401,7 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize) default: break; } - + //update position & position percent Vec2 absPos = getPosition(); switch (_positionType) @@ -433,7 +432,7 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize) void Widget::setSizeType(SizeType type) { _sizeType = type; - + if (_usingLayoutComponent) { auto component = this->getOrCreateLayoutComponent(); @@ -485,7 +484,7 @@ const Size& Widget::getSize() const { return this->getContentSize(); } - + const Size& Widget::getCustomSize() const { return _customSize; @@ -531,7 +530,7 @@ Size Widget::getVirtualRendererSize() const { return _contentSize; } - + void Widget::updateContentSizeWithTextureSize(const cocos2d::Size &size) { if (_unifySize) @@ -656,21 +655,21 @@ void Widget::onPressStateChangedToDisabled() { } - + void Widget::updateChildrenDisplayedRGBA() { this->setColor(this->getColor()); this->setOpacity(this->getOpacity()); } - + Widget* Widget::getAncensterWidget(Node* node) { if (nullptr == node) { return nullptr; } - + Node* parent = node->getParent(); if (nullptr == parent) { @@ -686,7 +685,7 @@ Widget* Widget::getAncensterWidget(Node* node) return this->getAncensterWidget(parent->getParent()); } } - + bool Widget::isAncestorsVisible(Node* node) { if (nullptr == node) @@ -694,14 +693,14 @@ bool Widget::isAncestorsVisible(Node* node) return true; } Node* parent = node->getParent(); - + if (parent && !parent->isVisible()) { return false; } return this->isAncestorsVisible(parent); } - + bool Widget::isAncestorsEnabled() { Widget* parentWidget = this->getAncensterWidget(this); @@ -713,20 +712,20 @@ bool Widget::isAncestorsEnabled() { return false; } - + return parentWidget->isAncestorsEnabled(); } - + void Widget::setPropagateTouchEvents(bool isPropagate) { _propagateTouchEvents = isPropagate; } - + bool Widget::isPropagateTouchEvents()const { return _propagateTouchEvents; } - + void Widget::setSwallowTouches(bool swallow) { if (_touchListener) @@ -734,7 +733,7 @@ void Widget::setSwallowTouches(bool swallow) _touchListener->setSwallowTouches(swallow); } } - + bool Widget::isSwallowTouches()const { if (_touchListener) @@ -760,7 +759,7 @@ bool Widget::onTouchBegan(Touch *touch, Event *unusedEvent) return false; } setHighlighted(true); - + /* * Propagate touch events to its parents */ @@ -768,11 +767,11 @@ bool Widget::onTouchBegan(Touch *touch, Event *unusedEvent) { this->propagateTouchEvent(TouchEventType::BEGAN, this, touch); } - + pushDownEvent(); return true; } - + void Widget::propagateTouchEvent(cocos2d::ui::Widget::TouchEventType event, cocos2d::ui::Widget *sender, cocos2d::Touch *touch) { Widget* widgetParent = getWidgetParent(); @@ -785,9 +784,9 @@ void Widget::propagateTouchEvent(cocos2d::ui::Widget::TouchEventType event, coco void Widget::onTouchMoved(Touch *touch, Event *unusedEvent) { _touchMovePosition = touch->getLocation(); - + setHighlighted(hitTest(_touchMovePosition)); - + /* * Propagate touch events to its parents */ @@ -795,14 +794,14 @@ void Widget::onTouchMoved(Touch *touch, Event *unusedEvent) { this->propagateTouchEvent(TouchEventType::MOVED, this, touch); } - + moveEvent(); } void Widget::onTouchEnded(Touch *touch, Event *unusedEvent) { _touchEndPosition = touch->getLocation(); - + /* * Propagate touch events to its parents */ @@ -810,10 +809,10 @@ void Widget::onTouchEnded(Touch *touch, Event *unusedEvent) { this->propagateTouchEvent(TouchEventType::ENDED, this, touch); } - + bool highlight = _highlight; setHighlighted(false); - + if (highlight) { releaseUpEvent(); @@ -837,7 +836,7 @@ void Widget::pushDownEvent() { _touchEventCallback(this, TouchEventType::BEGAN); } - + if (_touchEventListener && _touchEventSelector) { (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_BEGAN); @@ -852,7 +851,7 @@ void Widget::moveEvent() { _touchEventCallback(this, TouchEventType::MOVED); } - + if (_touchEventListener && _touchEventSelector) { (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_MOVED); @@ -867,12 +866,12 @@ void Widget::releaseUpEvent() { _touchEventCallback(this, TouchEventType::ENDED); } - + if (_touchEventListener && _touchEventSelector) { (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_ENDED); } - + if (_clickEventListener) { _clickEventListener(this); } @@ -886,7 +885,7 @@ void Widget::cancelUpEvent() { _touchEventCallback(this, TouchEventType::CANCELED); } - + if (_touchEventListener && _touchEventSelector) { (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_CANCELED); @@ -899,17 +898,17 @@ void Widget::addTouchEventListener(Ref *target, SEL_TouchEvent selector) _touchEventListener = target; _touchEventSelector = selector; } - + void Widget::addTouchEventListener(const ccWidgetTouchCallback& callback) { this->_touchEventCallback = callback; } - + void Widget::addClickEventListener(const ccWidgetClickCallback &callback) { this->_clickEventListener = callback; } - + void Widget::addCCSEventListener(const ccWidgetEventCallback &callback) { this->_ccEventCallback = callback; @@ -1122,7 +1121,7 @@ LayoutParameter* Widget::getLayoutParameter()const { return dynamic_cast(_layoutParameterDictionary.at((int)_layoutParameterType)); } - + LayoutParameter* Widget::getLayoutParameter(LayoutParameter::Type type) { return dynamic_cast(_layoutParameterDictionary.at((int)type)); @@ -1159,7 +1158,7 @@ void Widget::copyClonedWidgetChildren(Widget* model) } } } - + GLProgramState* Widget::getNormalGLProgramState()const { GLProgramState *glState = nullptr; @@ -1169,9 +1168,8 @@ GLProgramState* Widget::getNormalGLProgramState()const GLProgramState* Widget::getGrayGLProgramState()const { - auto program = GLProgram::createWithByteArrays(ccPositionTextureColor_noMVP_vert, - ccUIGrayScale_frag); - GLProgramState *glState = GLProgramState::getOrCreateWithGLProgram(program); + GLProgramState *glState = nullptr; + glState = GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_GRAYSCALE); return glState; } @@ -1215,7 +1213,7 @@ void Widget::copyProperties(Widget *widget) _focused = widget->_focused; _focusEnabled = widget->_focusEnabled; _propagateTouchEvents = widget->_propagateTouchEvents; - + copySpecialProperties(widget); Map& layoutParameterDic = widget->_layoutParameterDictionary; @@ -1224,24 +1222,24 @@ void Widget::copyProperties(Widget *widget) setLayoutParameter(iter->second->clone()); } } - + void Widget::setFlippedX(bool flippedX) { - + float realScale = this->getScaleX(); _flippedX = flippedX; this->setScaleX(realScale); } - + void Widget::setFlippedY(bool flippedY) { float realScale = this->getScaleY(); _flippedY = flippedY; this->setScaleY(realScale); } - - - + + + void Widget::setScaleX(float scaleX) { if (_flippedX) { @@ -1249,7 +1247,7 @@ void Widget::copyProperties(Widget *widget) } Node::setScaleX(scaleX); } - + void Widget::setScaleY(float scaleY) { if (_flippedY) { @@ -1257,20 +1255,20 @@ void Widget::copyProperties(Widget *widget) } Node::setScaleY(scaleY); } - + void Widget::setScale(float scale) { this->setScaleX(scale); this->setScaleY(scale); this->setScaleZ(scale); } - + void Widget::setScale(float scaleX, float scaleY) { this->setScaleX(scaleX); this->setScaleY(scaleY); } - + float Widget::getScaleX()const { float originalScale = Node::getScaleX(); @@ -1280,7 +1278,7 @@ void Widget::copyProperties(Widget *widget) } return originalScale; } - + float Widget::getScaleY()const { float originalScale = Node::getScaleY(); @@ -1290,7 +1288,7 @@ void Widget::copyProperties(Widget *widget) } return originalScale; } - + float Widget::getScale()const { CCASSERT(this->getScaleX() == this->getScaleY(), ""); @@ -1308,11 +1306,11 @@ int Widget::getActionTag()const { return _actionTag; } - + void Widget::setFocused(bool focus) { _focused = focus; - + //make sure there is only one focusedWidget if (focus) { _focusedWidget = this; @@ -1320,7 +1318,7 @@ void Widget::setFocused(bool focus) _focusNavigationController->setFirstFocsuedWidget(this); } } - + } bool Widget::isFocused()const @@ -1344,7 +1342,7 @@ Widget* Widget::findNextFocusedWidget(FocusDirection direction, Widget* current if (this->isFocused() || dynamic_cast(current)) { Node* parent = this->getParent(); - + Layout* layout = dynamic_cast(parent); if (nullptr == layout) { @@ -1381,25 +1379,25 @@ void Widget::dispatchFocusEvent(cocos2d::ui::Widget *widgetLoseFocus, cocos2d::u { widgetLoseFocus = _focusedWidget; } - + if (widgetGetFocus != widgetLoseFocus) { - + if (widgetGetFocus) { widgetGetFocus->onFocusChanged(widgetLoseFocus, widgetGetFocus); } - + if (widgetLoseFocus) { widgetLoseFocus->onFocusChanged(widgetLoseFocus, widgetGetFocus); } - + EventFocus event(widgetLoseFocus, widgetGetFocus); auto dispatcher = cocos2d::Director::getInstance()->getEventDispatcher(); dispatcher->dispatchEvent(&event); } - + } void Widget::requestFocus() @@ -1408,10 +1406,10 @@ void Widget::requestFocus() { return; } - + this->dispatchFocusEvent(_focusedWidget, this); } - + void Widget::onFocusChange(Widget* widgetLostFocus, Widget* widgetGetFocus) { //only change focus when there is indeed a get&lose happens @@ -1419,7 +1417,7 @@ void Widget::onFocusChange(Widget* widgetLostFocus, Widget* widgetGetFocus) { widgetLostFocus->setFocused(false); } - + if (widgetGetFocus) { widgetGetFocus->setFocused(true); @@ -1448,7 +1446,7 @@ void Widget::enableDpadNavigation(bool enable) { CC_SAFE_DELETE(_focusNavigationController); } - + if (nullptr != _focusNavigationController) { _focusNavigationController->enableFocusNavigation(enable); diff --git a/cocos/ui/shaders/UIShaders.h b/cocos/ui/shaders/UIShaders.h deleted file mode 100644 index 821e26313d..0000000000 --- a/cocos/ui/shaders/UIShaders.h +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#ifndef __UISHADERS_H__ -#define __UISHADERS_H__ - -#include "platform/CCGL.h" -#include "platform/CCPlatformMacros.h" - -NS_CC_BEGIN - -extern CC_DLL const GLchar * ccUIGrayScale_frag; - -NS_CC_END - -#endif /* __UISHADERS_H__ */ \ No newline at end of file diff --git a/extensions/Particle3D/CCParticleSystem3D.cpp b/extensions/Particle3D/CCParticleSystem3D.cpp index f1023c2899..8ba10c2fd4 100755 --- a/extensions/Particle3D/CCParticleSystem3D.cpp +++ b/extensions/Particle3D/CCParticleSystem3D.cpp @@ -30,8 +30,7 @@ NS_CC_BEGIN Particle3D::Particle3D() -: position(Vec3::ZERO) -, color(Vec4::ONE) +: color(Vec4::ONE) , rt_uv(Vec2::ONE) , width(1.0f) , height(1.0f) diff --git a/extensions/Particle3D/PU/CCPUBaseForceAffector.cpp b/extensions/Particle3D/PU/CCPUBaseForceAffector.cpp index e47defbaee..a75881cc3d 100644 --- a/extensions/Particle3D/PU/CCPUBaseForceAffector.cpp +++ b/extensions/Particle3D/PU/CCPUBaseForceAffector.cpp @@ -36,7 +36,6 @@ const PUBaseForceAffector::ForceApplication PUBaseForceAffector::DEFAULT_FORCE_A PUBaseForceAffector::PUBaseForceAffector() : PUAffector() , _forceVector(DEFAULT_FORCE_VECTOR) - , _scaledVector(Vec3::ZERO) , _forceApplication(DEFAULT_FORCE_APPL) { } diff --git a/extensions/Particle3D/PU/CCPUBoxCollider.cpp b/extensions/Particle3D/PU/CCPUBoxCollider.cpp index 7beca00789..49a8c226c6 100644 --- a/extensions/Particle3D/PU/CCPUBoxCollider.cpp +++ b/extensions/Particle3D/PU/CCPUBoxCollider.cpp @@ -45,7 +45,6 @@ PUBoxCollider::PUBoxCollider() : _ymax(0.0f), _zmin(0.0f), _zmax(0.0f), - _predictedPosition(Vec3::ZERO), _innerCollision(false) { } diff --git a/extensions/Particle3D/PU/CCPUEmitter.cpp b/extensions/Particle3D/PU/CCPUEmitter.cpp index dd5f4edcb0..9e04ed5f5e 100755 --- a/extensions/Particle3D/PU/CCPUEmitter.cpp +++ b/extensions/Particle3D/PU/CCPUEmitter.cpp @@ -72,7 +72,6 @@ _dynParticleAllDimensionsSet(false), _dynParticleWidthSet(false), _dynParticleHeightSet(false), _dynParticleDepthSet(false), -_upVector(Vec3::ZERO), _remainder(0), _durationRemain(0), _dynDurationSet(false), diff --git a/extensions/Particle3D/PU/CCPUFlockCenteringAffector.cpp b/extensions/Particle3D/PU/CCPUFlockCenteringAffector.cpp index d2e00e7086..a6ebc761a1 100644 --- a/extensions/Particle3D/PU/CCPUFlockCenteringAffector.cpp +++ b/extensions/Particle3D/PU/CCPUFlockCenteringAffector.cpp @@ -30,8 +30,6 @@ NS_CC_BEGIN //----------------------------------------------------------------------- PUFlockCenteringAffector::PUFlockCenteringAffector() : PUAffector(), - _sum(Vec3::ZERO), - _average(Vec3::ZERO), _count(0.0f) { } diff --git a/extensions/Particle3D/PU/CCPUForceField.cpp b/extensions/Particle3D/PU/CCPUForceField.cpp index 8bccf2c527..b7bb104132 100644 --- a/extensions/Particle3D/PU/CCPUForceField.cpp +++ b/extensions/Particle3D/PU/CCPUForceField.cpp @@ -159,7 +159,6 @@ PUForceField::PUForceField(void) : _worldSize(PUForceFieldCalculationFactory::DEFAULT_WORLDSIZE), _forceFieldSize(64), _forceFieldCalculationFactory(0), - _forceFieldPositionBase(Vec3::ZERO), _forceFieldType(FF_REALTIME_CALC) { } diff --git a/extensions/Particle3D/PU/CCPUForceField.h b/extensions/Particle3D/PU/CCPUForceField.h index dea066a10e..aec790d772 100644 --- a/extensions/Particle3D/PU/CCPUForceField.h +++ b/extensions/Particle3D/PU/CCPUForceField.h @@ -45,9 +45,7 @@ public: _frequency(1.0f), _amplitude(1.0f), _persistence(1.0f), - _mapScale(Vec3::ZERO), - _worldSize(DEFAULT_WORLDSIZE), - _mappedPosition(Vec3::ZERO) + _worldSize(DEFAULT_WORLDSIZE) { }; virtual ~PUForceFieldCalculationFactory(void){}; diff --git a/extensions/Particle3D/PU/CCPUForceFieldAffector.cpp b/extensions/Particle3D/PU/CCPUForceFieldAffector.cpp index 54ace4661d..8a1e6340a1 100644 --- a/extensions/Particle3D/PU/CCPUForceFieldAffector.cpp +++ b/extensions/Particle3D/PU/CCPUForceFieldAffector.cpp @@ -45,7 +45,6 @@ const float PUForceFieldAffector::DEFAULT_MOVEMENT_FREQUENCY = 5.0f; PUForceFieldAffector::PUForceFieldAffector() : _forceFieldType(PUForceField::FF_REALTIME_CALC), _delta(DEFAULT_DELTA), - _force(Vec3::ZERO), _scaleForce(DEFAULT_FORCE), _octaves(DEFAULT_OCTAVES), _frequency(DEFAULT_FREQUENCY), @@ -61,8 +60,6 @@ PUForceFieldAffector::PUForceFieldAffector() : _movementSet(false), _movementFrequency(DEFAULT_MOVEMENT_FREQUENCY), _movementFrequencyCount(0.0f), - _displacement(Vec3::ZERO), - _basePosition(Vec3::ZERO), _suppressGeneration(false) { }; diff --git a/extensions/Particle3D/PU/CCPULineEmitter.cpp b/extensions/Particle3D/PU/CCPULineEmitter.cpp index acf8e0654a..9f11ea227f 100644 --- a/extensions/Particle3D/PU/CCPULineEmitter.cpp +++ b/extensions/Particle3D/PU/CCPULineEmitter.cpp @@ -38,7 +38,6 @@ const float PULineEmitter::DEFAULT_MAX_DEVIATION = 0.0f; PULineEmitter::PULineEmitter(void) : PUEmitter(), _end(DEFAULT_END), - _perpendicular(Vec3::ZERO), _maxDeviation(DEFAULT_MAX_DEVIATION), _minIncrement(DEFAULT_MIN_INCREMENT), _maxIncrement(DEFAULT_MAX_INCREMENT), @@ -46,7 +45,6 @@ PULineEmitter::PULineEmitter(void) : _length(0.0f), _incrementsLeft(true), _first(true), - _scaledEnd(Vec3::ZERO), _scaledMaxDeviation(0.0f), _scaledMinIncrement(0.0f), _scaledMaxIncrement(0.0f), diff --git a/extensions/Particle3D/PU/CCPUParticleFollower.cpp b/extensions/Particle3D/PU/CCPUParticleFollower.cpp index e4fd5ae2ff..14af974169 100644 --- a/extensions/Particle3D/PU/CCPUParticleFollower.cpp +++ b/extensions/Particle3D/PU/CCPUParticleFollower.cpp @@ -37,7 +37,6 @@ PUParticleFollower::PUParticleFollower(void) : PUAffector(), _minDistance(DEFAULT_MIN_DISTANCE), _maxDistance(DEFAULT_MAX_DISTANCE), - _positionPreviousParticle(Vec3::ZERO), _first(false) { } diff --git a/extensions/Particle3D/PU/CCPUParticleSystem3D.cpp b/extensions/Particle3D/PU/CCPUParticleSystem3D.cpp index 9fe328a239..0c43156eb4 100755 --- a/extensions/Particle3D/PU/CCPUParticleSystem3D.cpp +++ b/extensions/Particle3D/PU/CCPUParticleSystem3D.cpp @@ -109,20 +109,15 @@ void PUParticle3D::process( float timeElapsed ) } PUParticle3D::PUParticle3D(): - //position(Vec3::ZERO), particleEntityPtr(nullptr), visualData(nullptr), particleType(PT_VISUAL), - direction(Vec3::ZERO), timeToLive(DEFAULT_TTL), totalTimeToLive(DEFAULT_TTL), timeFraction(0.0f), mass(DEFAULT_MASS), eventFlags(0), freezed(false), - originalPosition(Vec3::ZERO), - latestPosition(Vec3::ZERO), - originalDirection(Vec3::ZERO), originalDirectionLength(0.0f), originalScaledDirectionLength(0.0f), originalVelocity(0.0f), diff --git a/extensions/Particle3D/PU/CCPUPlaneCollider.cpp b/extensions/Particle3D/PU/CCPUPlaneCollider.cpp index 074a3ee5b5..5651df9435 100644 --- a/extensions/Particle3D/PU/CCPUPlaneCollider.cpp +++ b/extensions/Particle3D/PU/CCPUPlaneCollider.cpp @@ -34,8 +34,7 @@ const Vec3 PUPlaneCollider::DEFAULT_NORMAL(0, 0, 0); //----------------------------------------------------------------------- PUPlaneCollider::PUPlaneCollider(void) : PUBaseCollider(), - _normal(DEFAULT_NORMAL), - _predictedPosition(Vec3::ZERO) + _normal(DEFAULT_NORMAL) { } PUPlaneCollider::~PUPlaneCollider( void ) diff --git a/extensions/Particle3D/PU/CCPUSlaveEmitter.cpp b/extensions/Particle3D/PU/CCPUSlaveEmitter.cpp index 7f1e72929e..17d7acb676 100644 --- a/extensions/Particle3D/PU/CCPUSlaveEmitter.cpp +++ b/extensions/Particle3D/PU/CCPUSlaveEmitter.cpp @@ -35,8 +35,6 @@ PUSlaveEmitter::PUSlaveEmitter(void) : _masterParticle(0), _masterTechniqueName(), _masterEmitterName(), - _masterPosition(Vec3::ZERO), - _masterDirection(Vec3::ZERO), _masterEmitterNameSet(false) { } diff --git a/extensions/Particle3D/PU/CCPUSphere.cpp b/extensions/Particle3D/PU/CCPUSphere.cpp index 6df66a9160..87338b7024 100644 --- a/extensions/Particle3D/PU/CCPUSphere.cpp +++ b/extensions/Particle3D/PU/CCPUSphere.cpp @@ -29,7 +29,6 @@ NS_CC_BEGIN PUSphere::PUSphere() : _radius(1.0) - , _center(Vec3::ZERO) { } diff --git a/extensions/Particle3D/PU/CCPUSphereCollider.cpp b/extensions/Particle3D/PU/CCPUSphereCollider.cpp index 0e06418897..82291b5a8a 100644 --- a/extensions/Particle3D/PU/CCPUSphereCollider.cpp +++ b/extensions/Particle3D/PU/CCPUSphereCollider.cpp @@ -34,7 +34,6 @@ const float PUSphereCollider::DEFAULT_RADIUS = 100.0f; PUSphereCollider::PUSphereCollider(void) : PUBaseCollider(), _radius(DEFAULT_RADIUS), - _predictedPosition(Vec3::ZERO), _innerCollision(false) { } diff --git a/extensions/Particle3D/PU/CCPUSphereSurfaceEmitter.cpp b/extensions/Particle3D/PU/CCPUSphereSurfaceEmitter.cpp index 7c3695e2cf..6d020ddd4a 100644 --- a/extensions/Particle3D/PU/CCPUSphereSurfaceEmitter.cpp +++ b/extensions/Particle3D/PU/CCPUSphereSurfaceEmitter.cpp @@ -34,8 +34,7 @@ const float PUSphereSurfaceEmitter::DEFAULT_RADIUS = 10.0f; //----------------------------------------------------------------------- PUSphereSurfaceEmitter::PUSphereSurfaceEmitter(void) : PUEmitter(), - _radius(DEFAULT_RADIUS), - _randomVector(Vec3::ZERO) + _radius(DEFAULT_RADIUS) { } //----------------------------------------------------------------------- diff --git a/external/config.json b/external/config.json index 8679c8855d..a16307e253 100644 --- a/external/config.json +++ b/external/config.json @@ -1,5 +1,5 @@ { - "version":"v3-deps-42", + "version":"v3-deps-43", "zip_file_size":"74127526", "repo_name":"cocos2d-x-3rd-party-libs-bin", "repo_parent":"https://github.com/cocos2d/", diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index c0b4c8aabf..c1d67a8f73 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -1075,6 +1075,7 @@ "cocos/renderer/ccShader_PositionTexture_uColor.vert", "cocos/renderer/ccShader_Position_uColor.frag", "cocos/renderer/ccShader_Position_uColor.vert", + "cocos/renderer/ccShader_UI_Gray.frag", "cocos/renderer/ccShaders.cpp", "cocos/renderer/ccShaders.h", "cocos/storage/CMakeLists.txt", @@ -1163,9 +1164,6 @@ "cocos/ui/UIWidget.h", "cocos/ui/proj.win32/libui.vcxproj", "cocos/ui/proj.win32/libui.vcxproj.filters", - "cocos/ui/shaders/UIShaders.cpp", - "cocos/ui/shaders/UIShaders.h", - "cocos/ui/shaders/ccShader_grayscale.frag", "docs/CODING_STYLE.md", "docs/CONTRIBUTE.md", "docs/Groups.h", @@ -4855,6 +4853,7 @@ "cocos/scripting/lua-bindings/auto/api/Waves.lua", "cocos/scripting/lua-bindings/auto/api/Waves3D.lua", "cocos/scripting/lua-bindings/auto/api/WavesTiles3D.lua", + "cocos/scripting/lua-bindings/auto/api/WebView.lua", "cocos/scripting/lua-bindings/auto/api/Widget.lua", "cocos/scripting/lua-bindings/auto/api/ZOrderFrame.lua", "cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_3d_auto_api.lua", @@ -4866,6 +4865,7 @@ "cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_csloader_auto_api.lua", "cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_experimental_auto_api.lua", "cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_experimental_video_auto_api.lua", + "cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_experimental_webview_auto_api.lua", "cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_extension_auto_api.lua", "cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_physics_auto_api.lua", "cocos/scripting/lua-bindings/auto/api/lua_cocos2dx_spine_auto_api.lua", @@ -4889,6 +4889,8 @@ "cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_auto.hpp", "cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_video_auto.cpp", "cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_video_auto.hpp", + "cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.cpp", + "cocos/scripting/lua-bindings/auto/lua_cocos2dx_experimental_webview_auto.hpp", "cocos/scripting/lua-bindings/auto/lua_cocos2dx_extension_auto.cpp", "cocos/scripting/lua-bindings/auto/lua_cocos2dx_extension_auto.hpp", "cocos/scripting/lua-bindings/auto/lua_cocos2dx_physics_auto.cpp", @@ -4967,6 +4969,8 @@ "cocos/scripting/lua-bindings/manual/tolua_fix.h", "cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_video_manual.cpp", "cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_video_manual.hpp", + "cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.cpp", + "cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_experimental_webview_manual.hpp", "cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.cpp", "cocos/scripting/lua-bindings/manual/ui/lua_cocos2dx_ui_manual.hpp", "cocos/scripting/lua-bindings/manual/video/lua_cocos2dx_experimental_video_manual.cpp", @@ -5238,6 +5242,7 @@ "tools/tolua/cocos2dx_csloader.ini", "tools/tolua/cocos2dx_experimental.ini", "tools/tolua/cocos2dx_experimental_video.ini", + "tools/tolua/cocos2dx_experimental_webview.ini", "tools/tolua/cocos2dx_extension.ini", "tools/tolua/cocos2dx_physics.ini", "tools/tolua/cocos2dx_spine.ini", diff --git a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp index fb288b4e95..81e78540c1 100644 --- a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp +++ b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.cpp @@ -84,6 +84,11 @@ void Cocos2dRenderer::Pause() } } +bool Cocos2dRenderer::AppShouldExit() +{ + return GLViewImpl::sharedOpenGLView()->AppShouldExit(); +} + void Cocos2dRenderer::DeviceLost() { Pause(); @@ -137,4 +142,9 @@ void Cocos2dRenderer::QueuePointerEvent(cocos2d::PointerEventType type, Windows: GLViewImpl::sharedOpenGLView()->QueuePointerEvent(type, args); } +void Cocos2dRenderer::QueueBackButtonEvent() +{ + GLViewImpl::sharedOpenGLView()->QueueBackKeyPress(); +} + diff --git a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.h b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.h index a6f7a9c2a3..cb513eaaae 100644 --- a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.h +++ b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/Cocos2dRenderer.h @@ -35,10 +35,12 @@ namespace cocos2d ~Cocos2dRenderer(); void Draw(GLsizei width, GLsizei height, float dpi, Windows::Graphics::Display::DisplayOrientations orientation); void QueuePointerEvent(PointerEventType type, Windows::UI::Core::PointerEventArgs^ args); + void QueueBackButtonEvent(); void Pause(); void Resume(); void DeviceLost(); - + bool AppShouldExit(); + private: int m_width; diff --git a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp index 13781d649d..6a6a5fd00c 100644 --- a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp +++ b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.cpp @@ -169,16 +169,23 @@ void OpenGLESPage::OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Wi } #if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) +/* + We set args->Handled = true to prevent the app from quitting when the back button is pressed. + This is because this back button event happens on the XAML UI thread and not the cocos2d-x UI thread. + We need to give the game developer a chance to decide to exit the app depending on where they + are in their game. They can receive the back button event by listening for the + EventKeyboard::KeyCode::KEY_ESCAPE event. + + The default behavior is to exit the app if the EventKeyboard::KeyCode::KEY_ESCAPE event + is not handled by the game. +*/ void OpenGLESPage::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args) { - bool myAppCanNavigate = false; - if (myAppCanNavigate) + if (m_renderer) { + m_renderer->QueueBackButtonEvent(); args->Handled = true; } - else { - // Do nothing. Leave args->Handled set to the current value, false. - } } #endif @@ -250,6 +257,15 @@ void OpenGLESPage::RecoverFromLostDevice() StartRenderLoop(); } +void OpenGLESPage::TerminateApp() +{ + { + critical_section::scoped_lock lock(mRenderSurfaceCriticalSection); + DestroyRenderSurface(); + } + Windows::UI::Xaml::Application::Current->Exit(); +} + void OpenGLESPage::StartRenderLoop() { // If the render loop is already running then do not start another thread. @@ -273,8 +289,6 @@ void OpenGLESPage::StartRenderLoop() GLsizei panelWidth = 0; GLsizei panelHeight = 0; GetSwapChainPanelSize(&panelWidth, &panelHeight); - - if (m_renderer.get() == nullptr) { @@ -316,6 +330,17 @@ void OpenGLESPage::StartRenderLoop() return; } + + // run on main UI thread + if (m_renderer->AppShouldExit()) + { + swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this]() + { + TerminateApp(); + })); + + return; + } } if (m_renderer) diff --git a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.h b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.h index d95b310e0a..3f6eecc3b2 100644 --- a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.h +++ b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLESPage.xaml.h @@ -46,6 +46,7 @@ namespace cocos2d void CreateRenderSurface(); void DestroyRenderSurface(); void RecoverFromLostDevice(); + void TerminateApp(); void StartRenderLoop(); void StopRenderLoop(); diff --git a/tests/cpp-empty-test/Classes/HelloWorldScene.cpp b/tests/cpp-empty-test/Classes/HelloWorldScene.cpp index 8b603e79bf..32a2702e66 100644 --- a/tests/cpp-empty-test/Classes/HelloWorldScene.cpp +++ b/tests/cpp-empty-test/Classes/HelloWorldScene.cpp @@ -78,11 +78,6 @@ bool HelloWorld::init() void HelloWorld::menuCloseCallback(Ref* sender) { -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert"); - return; -#endif - Director::getInstance()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) diff --git a/tests/cpp-tests/Classes/AppDelegate.cpp b/tests/cpp-tests/Classes/AppDelegate.cpp index ef0c4938ea..db9ef8c4a0 100644 --- a/tests/cpp-tests/Classes/AppDelegate.cpp +++ b/tests/cpp-tests/Classes/AppDelegate.cpp @@ -165,12 +165,7 @@ bool AppDelegate::applicationDidFinishLaunching() fileUtils->setSearchPaths(searchPaths); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) - // a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL); -#else - glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL); -#endif // Enable Remote Console auto console = director->getConsole(); diff --git a/tests/cpp-tests/Classes/BaseTest.cpp b/tests/cpp-tests/Classes/BaseTest.cpp index 260556feb0..115d1d51e4 100644 --- a/tests/cpp-tests/Classes/BaseTest.cpp +++ b/tests/cpp-tests/Classes/BaseTest.cpp @@ -180,10 +180,6 @@ void TestList::runThisTest() { //Add close and "Start AutoTest" button. auto closeItem = MenuItemImage::create(s_pathClose, s_pathClose, [](Ref* sender){ -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) - MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.", "Alert"); - return; -#endif TestController::getInstance()->stopAutoTest(); TestController::destroyInstance(); Director::getInstance()->end(); diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Windows/cpp-tests.Windows.vcxproj b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Windows/cpp-tests.Windows.vcxproj index c38e3ec6a1..a4b34f4c3c 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Windows/cpp-tests.Windows.vcxproj +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.Windows/cpp-tests.Windows.vcxproj @@ -91,6 +91,12 @@ cpp-tests.Windows_TemporaryKey.pfx 35C2132BDB64C0DFA54722663D9148FF118E341B + + false + + + false + diff --git a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.WindowsPhone/cpp-tests.WindowsPhone.vcxproj b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.WindowsPhone/cpp-tests.WindowsPhone.vcxproj index 5bec2809ea..b843635441 100644 --- a/tests/cpp-tests/proj.win8.1-universal/cpp-tests.WindowsPhone/cpp-tests.WindowsPhone.vcxproj +++ b/tests/cpp-tests/proj.win8.1-universal/cpp-tests.WindowsPhone/cpp-tests.WindowsPhone.vcxproj @@ -117,6 +117,12 @@ True x86 + + false + + + false + diff --git a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua index 640846a4fd..44626fee77 100644 --- a/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua +++ b/tests/lua-tests/src/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua @@ -29,9 +29,6 @@ function UIScene:init() self._sceneTitle = root:getChildByName("UItest") - local back_label = root:getChildByName("back")--getWidgetByName - back_label:setVisible(false) - local function previousCallback(sender, eventType) if eventType == ccui.TouchEventType.ended then cc.Director:getInstance():replaceScene(guiSceneManager.previousUIScene()) @@ -711,9 +708,6 @@ function UILoadingBarLeftTest:initExtend() local root = self._uiLayer:getChildByTag(81) self._sceneTitle = root:getChildByName("UItest") - local back_label = root:getChildByName("back") - back_label:setVisible(false) - local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() @@ -837,9 +831,6 @@ function UILoadingBarRightTest:initExtend() local root = self._uiLayer:getChildByTag(81) self._sceneTitle = root:getChildByName("UItest") - local back_label = root:getChildByName("back") - back_label:setVisible(false) - local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() @@ -964,9 +955,6 @@ function UILoadingBarLeftScale9Test:initExtend() local root = self._uiLayer:getChildByTag(81) self._sceneTitle = root:getChildByName("UItest") - local back_label = root:getChildByName("back") - back_label:setVisible(false) - local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() @@ -1093,9 +1081,6 @@ function UILoadingBarRightScale9Test:initExtend() local root = self._uiLayer:getChildByTag(81) self._sceneTitle = root:getChildByName("UItest") - local back_label = root:getChildByName("back") - back_label:setVisible(false) - local widgetSize = self._widget:getContentSize() local alert = ccui.Text:create() diff --git a/tests/lua-tests/src/WebViewTest/WebViewTest.lua b/tests/lua-tests/src/WebViewTest/WebViewTest.lua new file mode 100644 index 0000000000..36c432a786 --- /dev/null +++ b/tests/lua-tests/src/WebViewTest/WebViewTest.lua @@ -0,0 +1,129 @@ + +---------------------------------------- +----WebViewTest +---------------------------------------- +local WebViewTest = class("WebViewTest", function () + local layer = cc.Layer:create() + + return layer +end) + +function WebViewTest:ctor() + self:init() +end + +function WebViewTest:init() + Helper.initWithLayer(self) + Helper.titleLabel:setString(self:title()) + Helper.subtitleLabel:setString(self:subtitle()) + + local winSize = cc.Director:getInstance():getVisibleSize() + self._webView = ccexp.WebView:create() + self._webView:setPosition(winSize.width / 2, winSize.height / 2 - 40) + self._webView:setContentSize(winSize.width / 2, winSize.height / 2) + self._webView:loadURL("http://www.baidu.com") + self._webView:setScalesPageToFit(true) + + self._webView:setOnShouldStartLoading(function(sender, url) + print("onWebViewShouldStartLoading, url is ", url) + return true + end) + self._webView:setOnDidFinishLoading(function(sender, url) + print("onWebViewDidFinishLoading, url is ", url) + end) + self._webView:setOnDidFailLoading(function(sender, url) + print("onWebViewDidFinishLoading, url is ", url) + end) + + self:addChild(self._webView) + + local urlTextField = ccui.TextField:create("Input a URL here", "Arial", 20) + urlTextField:setPlaceHolderColor(cc.c4b(255, 0, 0, 255)) + urlTextField:setPosition(winSize.width/2 - 80, winSize.height/2 + self._webView:getContentSize().height/2 + urlTextField:getContentSize().height/2 + 10) + self:addChild(urlTextField) + + local httpLabel = ccui.Text:create("http:// ", "Arial", 20) + httpLabel:setTextColor(cc.c4b(0, 255, 0, 255)) + httpLabel:setAnchorPoint(cc.p(1.0,0.5)) + local x,y = urlTextField:getPosition() + httpLabel:setPosition( x - urlTextField:getContentSize().width / 2, y) + self:addChild(httpLabel) + + local resetBtn = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") + resetBtn:setTitleText("Visit URL") + resetBtn:setPosition(winSize.width / 2 + 80 , winSize.height / 2 + self._webView:getContentSize().height / 2 + resetBtn:getContentSize().height / 2 + 10) + resetBtn:addClickEventListener(function(sender) + if urlTextField:getString() ~= nil then + self._webView:loadURL("http://" .. urlTextField:getString()) + end + end) + self:addChild(resetBtn) + + local reloadBtn = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") + reloadBtn:setTitleText("Reload") + reloadBtn:setPosition(winSize.width / 2 + self._webView:getContentSize().width / 2 + reloadBtn:getContentSize().width / 2 + 10, winSize.height / 2 + 50) + reloadBtn:addClickEventListener(function(sender) + self._webView:reload() + end) + self:addChild(reloadBtn) + + local forwardBtn = ccui.Button:create("cocosui/animationbuttonnormal.png","cocosui/animationbuttonpressed.png") + forwardBtn:setTitleText("Forward") + forwardBtn:setPosition(winSize.width / 2 + self._webView:getContentSize().width / 2 + forwardBtn:getContentSize().width / 2 + 10,winSize.height / 2) + forwardBtn:addClickEventListener(function(sender) + self._webView:goForward() + end) + self:addChild(forwardBtn) + + local backBtn = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") + backBtn:setTitleText("Back") + backBtn:setPosition(winSize.width / 2 + self._webView:getContentSize().width/2 + backBtn:getContentSize().width/2 + 10, winSize.height - 50) + backBtn:addClickEventListener(function(sender) + self._webView:goBack() + end) + self:addChild(backBtn) + + local loadFileBtn = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") + loadFileBtn:setTitleText("Load FILE") + loadFileBtn:setPosition(winSize.width / 2 - self._webView:getContentSize().width/2 - loadFileBtn:getContentSize().width/2 - 30, winSize.height / 2 + 50) + loadFileBtn:addClickEventListener(function(sender) + self._webView:loadFile("Test.html") + end) + self:addChild(loadFileBtn) + + local loadHTMLBtn = ccui.Button:create("cocosui/animationbuttonnormal.png","cocosui/animationbuttonpressed.png") + loadHTMLBtn:setTitleText("Load Data") + loadHTMLBtn:setPosition(winSize.width / 2 - self._webView:getContentSize().width/2 - loadHTMLBtn:getContentSize().width/2 - 30, winSize.height / 2) + loadHTMLBtn:addClickEventListener(function(sender) + self._webView:loadHTMLString("Hello World ","Images/") + end) + self:addChild(loadHTMLBtn) + + local evalJsBtn = ccui.Button:create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png") + evalJsBtn:setTitleText("Evaluate JS") + evalJsBtn:setPosition(winSize.width / 2 - self._webView:getContentSize().width/2 - evalJsBtn:getContentSize().width/2 - 30, winSize.height / 2 - 50) + evalJsBtn:addClickEventListener(function(sender) + self._webView:evaluateJS("alert(\"hello\")") + end) + self:addChild(evalJsBtn) +end + +function WebViewTest:title() + return "" +end + +function WebViewTest:subtitle() + return "" +end + +function WebViewTestMain() + Helper.createFunctionTable = + { + WebViewTest.create, + } + + local scene = cc.Scene:create() + scene:addChild(WebViewTest.create()) + scene:addChild(CreateBackMenuItem()) + return scene +end \ No newline at end of file diff --git a/tests/lua-tests/src/mainMenu.lua b/tests/lua-tests/src/mainMenu.lua index 3c20ebc779..a8d46ae35c 100644 --- a/tests/lua-tests/src/mainMenu.lua +++ b/tests/lua-tests/src/mainMenu.lua @@ -58,6 +58,7 @@ require "VideoPlayerTest/VideoPlayerTest" require "FastTiledMapTest/FastTiledMapTest" require "NewAudioEngineTest/NewAudioEngineTest" require "CocosStudio3DTest/CocosStudio3DTest" +require "WebViewTest/WebViewTest" local LINE_SPACE = 40 @@ -134,6 +135,7 @@ local _allTests = { { isSupported = true, name = "TransitionsTest" , create_func = TransitionsTest }, { isSupported = true, name = "UserDefaultTest" , create_func= UserDefaultTestMain }, { isSupported = true, name = "VideoPlayerTest" , create_func= VideoPlayerTestMain }, + { isSupported = true, name = "WebViewTest" , create_func= WebViewTestMain }, { isSupported = true, name = "XMLHttpRequestTest" , create_func = XMLHttpRequestTestMain }, { isSupported = true, name = "ZwoptexTest" , create_func = ZwoptexTestMain } } @@ -196,6 +198,12 @@ function CreateTestMenu() end end + if obj.name == "WebViewTest" then + if cc.PLATFORM_OS_IPHONE ~= targetPlatform and cc.PLATFORM_OS_ANDROID ~= targetPlatform then + testMenuItem:setEnabled(false) + end + end + testMenuItem:registerScriptTapHandler(menuCallback) testMenuItem:setPosition(cc.p(s.width / 2, (s.height - (index) * LINE_SPACE))) MainMenu:addChild(testMenuItem, index + 10000, index + 10000) diff --git a/tools/cocos2d-console b/tools/cocos2d-console index fd15b0c3e1..f56ddf5c11 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit fd15b0c3e122e87e7447c4107a7f98ce5cfab7c4 +Subproject commit f56ddf5c118a2652d0d7eb796872420a69f532af diff --git a/tools/tolua/cocos2dx_experimental_webview.ini b/tools/tolua/cocos2dx_experimental_webview.ini new file mode 100644 index 0000000000..4e91348306 --- /dev/null +++ b/tools/tolua/cocos2dx_experimental_webview.ini @@ -0,0 +1,62 @@ +[cocos2dx_experimental_webview] +# the prefix to be added to the generated functions. You might or might not use this in your own +# templates +prefix = cocos2dx_experimental_webview + +# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`) +# all classes will be embedded in that namespace +target_namespace = ccexp + +macro_judgement = #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + +android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.8/include +android_flags = -D_SIZE_T_DEFINED_ + +clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include +clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__ + +cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android + +cocos_flags = -DANDROID + +cxxgenerator_headers = + +# extra arguments for clang +extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s + +# what headers to parse +headers = %(cocosdir)s/cocos/ui/UIWebView.h + +# what classes to produce code for. You can use regular expressions here. When testing the regular +# expression, it will be enclosed in "^$", like this: "^Menu*$". +classes = WebView + +# what should we skip? in the format ClassName::[function function] +# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also +# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just +# add a single "*" as functions. See bellow for several examples. A special class name is "*", which +# will apply to all class names. This is a convenience wildcard to be able to skip similar named +# functions from all classes. + +skip = WebView::[(s|g)etOnShouldStartLoading (s|g)etOnDidFinishLoading (s|g)etOnDidFailLoading setOnJSCallback draw loadData] + +rename_functions = + +rename_classes = + +# for all class names, should we remove something when registering in the target VM? +remove_prefix = + +# classes for which there will be no "parent" lookup +classes_have_no_parents = + +# base classes which will be skipped when their sub-classes found them. +base_classes_to_skip = + +# classes that create no constructor +# Set is special and we will use a hand-written constructor +abstract_classes = + +# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. +script_control_cpp = no + diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index 7a7ea22ab9..abe05e5f08 100755 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -147,6 +147,7 @@ def main(): 'cocos2dx_3d.ini': ('cocos2dx_3d', 'lua_cocos2dx_3d_auto'), \ 'cocos2dx_audioengine.ini': ('cocos2dx_audioengine', 'lua_cocos2dx_audioengine_auto'), \ 'cocos2dx_csloader.ini' : ('cocos2dx_csloader', 'lua_cocos2dx_csloader_auto'), \ + 'cocos2dx_experimental_webview.ini' : ('cocos2dx_experimental_webview', 'lua_cocos2dx_experimental_webview_auto'), \ } target = 'lua' generator_py = '%s/generator.py' % cxx_generator_root