diff --git a/AUTHORS b/AUTHORS index c3109272d8..41ba3dac1a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -920,6 +920,7 @@ Developers: Fix video scale issue in iOS Fix iOS VideoPlayer memory leak Added c++11 random library support + Added WebView widget which supports iOS and Android billtt Fixed a bug that Node::setScale(float) may not work properly diff --git a/CHANGELOG b/CHANGELOG index 92e29182dc..ae0b7d74bc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ cocos2d-x-3.3?? ?? [NEW] ActionManager: added removeAllActionsByTag() [NEW] Node: added stopAllActionsByTag() + [NEW] UI: added `WebView` on iOS and Android [FIX] Node: create unneeded temple `Vec2` object in `setPosition(int, int)`, `setPositionX()` and `setPositionY()` diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 1dce556650..d171951a40 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -1350,6 +1350,14 @@ 1ABA68B11888D700007D1BB4 /* CCFontCharMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ABA68AD1888D700007D1BB4 /* CCFontCharMap.h */; }; 1AC0269C1914068200FA920D /* ConvertUTF.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AC026991914068200FA920D /* ConvertUTF.h */; }; 1AC0269D1914068200FA920D /* ConvertUTF.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AC026991914068200FA920D /* ConvertUTF.h */; }; + 29394CF019B01DBA00D2DE1A /* UIWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEC19B01DBA00D2DE1A /* UIWebView.h */; }; + 29394CF119B01DBA00D2DE1A /* UIWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEC19B01DBA00D2DE1A /* UIWebView.h */; }; + 29394CF219B01DBA00D2DE1A /* UIWebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CED19B01DBA00D2DE1A /* UIWebView.mm */; }; + 29394CF319B01DBA00D2DE1A /* UIWebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29394CED19B01DBA00D2DE1A /* UIWebView.mm */; }; + 29394CF419B01DBA00D2DE1A /* UIWebViewImpl_iOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 29394CEE19B01DBA00D2DE1A /* UIWebViewImpl_iOS.h */; }; + 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 */; }; 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 */; }; @@ -2296,6 +2304,10 @@ 2905FA1318CF08D100240AA3 /* UIWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIWidget.cpp; sourceTree = ""; }; 2905FA1418CF08D100240AA3 /* UIWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWidget.h; sourceTree = ""; }; 29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = ""; }; + 29394CEC19B01DBA00D2DE1A /* UIWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWebView.h; sourceTree = ""; }; + 29394CED19B01DBA00D2DE1A /* UIWebView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIWebView.mm; sourceTree = ""; }; + 29394CEE19B01DBA00D2DE1A /* UIWebViewImpl_iOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWebViewImpl_iOS.h; sourceTree = ""; }; + 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 = ""; }; 2986667818B1B079000E39CA /* CCTweenFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTweenFunction.cpp; sourceTree = ""; }; @@ -4012,6 +4024,10 @@ 29CB8F521929D65500C841D6 /* experimental */ = { isa = PBXGroup; children = ( + 29394CEC19B01DBA00D2DE1A /* UIWebView.h */, + 29394CED19B01DBA00D2DE1A /* UIWebView.mm */, + 29394CEE19B01DBA00D2DE1A /* UIWebViewImpl_iOS.h */, + 29394CEF19B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm */, 3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */, 3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */, ); @@ -5031,6 +5047,7 @@ 1A570093180BC5A10088DEC7 /* CCActionTween.h in Headers */, 50ABBD4A1925AB0000A911A9 /* Mat4.h in Headers */, 15AE1A6919AAD40300C27E9E /* b2WorldCallbacks.h in Headers */, + 29394CF419B01DBA00D2DE1A /* UIWebViewImpl_iOS.h in Headers */, 1A57009A180BC5C10088DEC7 /* CCAtlasNode.h in Headers */, 15AE190819AAD35000C27E9E /* CCDatas.h in Headers */, 1A5700A0180BC5D20088DEC7 /* CCNode.h in Headers */, @@ -5228,6 +5245,7 @@ 15AE191019AAD35000C27E9E /* CCInputDelegate.h in Headers */, 15AE184C19AAD30800C27E9E /* SimpleAudioEngine.h in Headers */, 50ABBDA11925AB4100A911A9 /* CCGroupCommand.h in Headers */, + 29394CF019B01DBA00D2DE1A /* UIWebView.h in Headers */, 15AE186519AAD31D00C27E9E /* CDOpenALSupport.h in Headers */, 15AE1B5C19AADA9900C27E9E /* UITextAtlas.h in Headers */, 1A5702FC180BCE750088DEC7 /* CCTMXXMLParser.h in Headers */, @@ -5558,6 +5576,7 @@ 15AE1AB319AAD40300C27E9E /* b2CircleContact.h in Headers */, 5034CA2E191D591100CE6051 /* ccShader_PositionTextureA8Color.frag in Headers */, 15AE1A4F19AAD3D500C27E9E /* b2Shape.h in Headers */, + 29394CF519B01DBA00D2DE1A /* UIWebViewImpl_iOS.h in Headers */, 50ABBD5B1925AB0000A911A9 /* Vec2.h in Headers */, 50ABBD411925AB0000A911A9 /* CCMath.h in Headers */, 1A5701A0180BCB590088DEC7 /* CCFont.h in Headers */, @@ -5670,6 +5689,7 @@ 15AE1BAC19AADFDF00C27E9E /* UILayout.h in Headers */, 1A570230180BCC1A0088DEC7 /* CCParticleSystemQuad.h in Headers */, 15AE1AF619AAD42500C27E9E /* chipmunk_ffi.h in Headers */, + 29394CF119B01DBA00D2DE1A /* UIWebView.h in Headers */, 15AE18B419AAD33D00C27E9E /* CCBSelectorResolver.h in Headers */, B24AA988195A675C007B4522 /* CCFastTMXLayer.h in Headers */, 15AE1AB919AAD40300C27E9E /* b2EdgeAndCircleContact.h in Headers */, @@ -6122,6 +6142,7 @@ 15AE187A19AAD33D00C27E9E /* CCBAnimationManager.cpp in Sources */, 15AE1B6D19AADA9900C27E9E /* UIHelper.cpp in Sources */, 15AE1A8A19AAD40300C27E9E /* b2PulleyJoint.cpp in Sources */, + 29394CF219B01DBA00D2DE1A /* UIWebView.mm in Sources */, 15AE1BD419AAE01E00C27E9E /* CCControlSaturationBrightnessPicker.cpp in Sources */, 1A57019D180BCB590088DEC7 /* CCFont.cpp in Sources */, 1A5701A1180BCB590088DEC7 /* CCFontAtlas.cpp in Sources */, @@ -6287,6 +6308,7 @@ 15AE196E19AAD35700C27E9E /* CCActionTimelineCache.cpp in Sources */, 50ABBEB31925AB6F00A911A9 /* CCUserDefault.mm in Sources */, 50ABBEB51925AB6F00A911A9 /* CCUserDefaultAndroid.cpp in Sources */, + 29394CF619B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm in Sources */, 50ABBE831925AB6F00A911A9 /* ccFPSImages.c in Sources */, 15AE1B7019AADA9900C27E9E /* CocosGUI.cpp in Sources */, 15AE19D019AAD3A700C27E9E /* AttachmentLoader.cpp in Sources */, @@ -6630,6 +6652,7 @@ 50ABBD9C1925AB4100A911A9 /* ccGLStateCache.cpp in Sources */, 1A5701E7180BCB8C0088DEC7 /* CCTransition.cpp in Sources */, 15AE1AC019AAD40300C27E9E /* b2MotorJoint.cpp in Sources */, + 29394CF319B01DBA00D2DE1A /* UIWebView.mm in Sources */, 15AE18BD19AAD33D00C27E9E /* CCLabelBMFontLoader.cpp in Sources */, 50ABC01E1926664800A911A9 /* CCThread.cpp in Sources */, 15AE1B3A19AAD43700C27E9E /* cpBB.c in Sources */, @@ -6672,6 +6695,7 @@ 15AE1BFD19AAE01E00C27E9E /* CCInvocation.cpp in Sources */, B24AA98A195A675C007B4522 /* CCFastTMXTiledMap.cpp in Sources */, 15AE18CE19AAD33D00C27E9E /* CCNodeLoader.cpp in Sources */, + 29394CF719B01DBA00D2DE1A /* UIWebViewImpl_iOS.mm in Sources */, 15AE1AC619AAD40300C27E9E /* b2GearJoint.cpp in Sources */, B24AA986195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */, 1A57022E180BCC1A0088DEC7 /* CCParticleSystemQuad.cpp in Sources */, diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 977187abac..2029a5d0ff 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -865,6 +865,8 @@ 290E94B6196FC16900694919 /* CocostudioParserTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 290E94B3196FC16900694919 /* CocostudioParserTest.cpp */; }; 295824591987415900F9746D /* UIScale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 295824571987415900F9746D /* UIScale9SpriteTest.cpp */; }; 2958245A1987415900F9746D /* UIScale9SpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 295824571987415900F9746D /* UIScale9SpriteTest.cpp */; }; + 298D7F6F19AC31F300FF096D /* UIWebViewTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 298D7F6D19AC31F300FF096D /* UIWebViewTest.cpp */; }; + 29AFEF6719ACCAA000F6B10A /* Test.html in Resources */ = {isa = PBXBuildFile; fileRef = 29AFEF6619ACCAA000F6B10A /* Test.html */; }; 29FBBBFE196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */; }; 29FBBBFF196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */; }; 38FA2E73194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 38FA2E71194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp */; }; @@ -2886,6 +2888,9 @@ 290E94B4196FC16900694919 /* CocostudioParserTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CocostudioParserTest.h; path = ../CocostudioParserTest.h; sourceTree = ""; }; 295824571987415900F9746D /* UIScale9SpriteTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIScale9SpriteTest.cpp; sourceTree = ""; }; 295824581987415900F9746D /* UIScale9SpriteTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScale9SpriteTest.h; sourceTree = ""; }; + 298D7F6D19AC31F300FF096D /* UIWebViewTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UIWebViewTest.cpp; path = UIWebViewTest/UIWebViewTest.cpp; sourceTree = ""; }; + 298D7F6E19AC31F300FF096D /* UIWebViewTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIWebViewTest.h; path = UIWebViewTest/UIWebViewTest.h; sourceTree = ""; }; + 29AFEF6619ACCAA000F6B10A /* Test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = Test.html; path = "../tests/cpp-tests/Resources/Test.html"; sourceTree = ""; }; 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocostudioParserJsonTest.cpp; sourceTree = ""; }; 29FBBBFD196A9ECD00E65826 /* CocostudioParserJsonTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocostudioParserJsonTest.h; sourceTree = ""; }; 38FA2E71194AEBE100FF2BE4 /* ActionTimelineTestScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActionTimelineTestScene.cpp; sourceTree = ""; }; @@ -6495,6 +6500,7 @@ 1AC35CB518CED84500F37B72 /* effect1.raw */, 1AC35CB618CED84500F37B72 /* effect1.wav */, 1AC35CC418CED84500F37B72 /* pew-pew-lei.wav */, + 29AFEF6619ACCAA000F6B10A /* Test.html */, ); name = Resources; sourceTree = ""; @@ -6907,6 +6913,15 @@ path = UIWidgetAddNodeTest; sourceTree = ""; }; + 298D7F6C19AC31C000FF096D /* UIWebViewTest */ = { + isa = PBXGroup; + children = ( + 298D7F6D19AC31F300FF096D /* UIWebViewTest.cpp */, + 298D7F6E19AC31F300FF096D /* UIWebViewTest.h */, + ); + name = UIWebViewTest; + sourceTree = ""; + }; 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { isa = PBXGroup; children = ( @@ -6988,6 +7003,7 @@ 29FBBC00196A9F0D00E65826 /* UIAndEditorTests */ = { isa = PBXGroup; children = ( + 298D7F6C19AC31C000FF096D /* UIWebViewTest */, 295824571987415900F9746D /* UIScale9SpriteTest.cpp */, 295824581987415900F9746D /* UIScale9SpriteTest.h */, 29080D1F191B595E0066F8DF /* CocosGUIScene.cpp */, @@ -7816,6 +7832,7 @@ 1AC35D0918CED84500F37B72 /* TileMaps in Resources */, 1AC35CFF18CED84500F37B72 /* Particles in Resources */, 1AC35C8818CECF1400F37B72 /* Default-568h@2x.png in Resources */, + 29AFEF6719ACCAA000F6B10A /* Test.html in Resources */, 1AC35CD518CED84500F37B72 /* ccb in Resources */, 1AC35CE118CED84500F37B72 /* configs in Resources */, 1AC35CE918CED84500F37B72 /* extensions in Resources */, @@ -8316,6 +8333,7 @@ 1AC35B3E18CECF0C00F37B72 /* Bug-422.cpp in Sources */, 29080DAC191B595E0066F8DF /* UIFocusTest.cpp in Sources */, 1AC35BF618CECF0C00F37B72 /* HttpClientTest.cpp in Sources */, + 298D7F6F19AC31F300FF096D /* UIWebViewTest.cpp in Sources */, 29080DA6191B595E0066F8DF /* UIButtonTest_Editor.cpp in Sources */, 1AC35B5018CECF0C00F37B72 /* ClickAndMoveTest.cpp in Sources */, ); diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index f1616fa25e..f220a57cb2 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -71,6 +71,8 @@ bool nodeComparisonLess(Node* n1, Node* n2) // XXX: Yes, nodes might have a sort problem once every 15 days if the game runs at 60 FPS and each frame sprites are reordered. int Node::s_globalOrderOfArrival = 1; +// MARK: Constructor, Destructor, Init + Node::Node(void) : _rotationX(0.0f) , _rotationY(0.0f) @@ -143,6 +145,20 @@ Node::Node(void) _transform = _inverse = _additionalTransform = Mat4::IDENTITY; } +Node * Node::create() +{ + Node * ret = new (std::nothrow) Node(); + if (ret && ret->init()) + { + ret->autorelease(); + } + else + { + CC_SAFE_DELETE(ret); + } + return ret; +} + Node::~Node() { CCLOGINFO( "deallocing Node: %p - tag: %i", this, _tag ); @@ -193,6 +209,34 @@ bool Node::init() return true; } +void Node::cleanup() +{ + // actions + this->stopAllActions(); + this->unscheduleAllSelectors(); + +#if CC_ENABLE_SCRIPT_BINDING + if ( _scriptType != kScriptTypeNone) + { + int action = kNodeOnCleanup; + BasicScriptData data(this,(void*)&action); + ScriptEvent scriptEvent(kNodeEvent,(void*)&data); + ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent); + } +#endif // #if CC_ENABLE_SCRIPT_BINDING + + // timers + for( const auto &child: _children) + child->cleanup(); +} + +std::string Node::getDescription() const +{ + return StringUtils::format("init()) - { - ret->autorelease(); - } - else - { - CC_SAFE_DELETE(ret); - } - return ret; -} - -void Node::cleanup() -{ - // actions - this->stopAllActions(); - this->unscheduleAllSelectors(); - -#if CC_ENABLE_SCRIPT_BINDING - if ( _scriptType != kScriptTypeNone) - { - int action = kNodeOnCleanup; - BasicScriptData data(this,(void*)&action); - ScriptEvent scriptEvent(kNodeEvent,(void*)&data); - ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent); - } -#endif // #if CC_ENABLE_SCRIPT_BINDING - - // timers - for( const auto &child: _children) - child->cleanup(); -} - - -std::string Node::getDescription() const -{ - return StringUtils::format("getRenderer(); @@ -1291,6 +1298,8 @@ Mat4 Node::transform(const Mat4& parentTransform) return ret; } +// MARK: events + void Node::onEnter() { if (_onEnterCallback) @@ -1419,6 +1428,8 @@ void Node::setActionManager(ActionManager* actionManager) } } +// MARK: actions + Action * Node::runAction(Action* action) { CCASSERT( action != nullptr, "Argument must be non-nil"); @@ -1459,7 +1470,7 @@ ssize_t Node::getNumberOfRunningActions() const return _actionManager->getNumberOfRunningActionsInTarget(this); } -// Node - Callbacks +// MARK: Callbacks void Node::setScheduler(Scheduler* scheduler) { @@ -1590,6 +1601,8 @@ void Node::update(float fDelta) } } +// MARK: coordinates + AffineTransform Node::getNodeToParentAffineTransform() const { AffineTransform ret; @@ -1844,6 +1857,8 @@ void Node::updateTransform() child->updateTransform(); } +// MARK: components + Component* Node::getComponent(const std::string& name) { if( _componentContainer ) @@ -1881,6 +1896,9 @@ void Node::removeAllComponents() } #if CC_USE_PHYSICS + +// MARK: Physics + void Node::updatePhysicsBodyTransform(Scene* scene) { updatePhysicsBodyScale(scene); @@ -2034,6 +2052,8 @@ PhysicsBody* Node::getPhysicsBody() const } #endif //CC_USE_PHYSICS +// MARK: Opacity and Color + GLubyte Node::getOpacity(void) const { return _realOpacity; @@ -2183,6 +2203,7 @@ void Node::disableCascadeColor() } } +// MARK: Camera void Node::setCameraMask(unsigned short mask, bool applyChildren) { _cameraMask = mask; @@ -2194,6 +2215,8 @@ void Node::setCameraMask(unsigned short mask, bool applyChildren) } } +// MARK: Deprecated + __NodeRGBA::__NodeRGBA() { CCLOG("NodeRGBA deprecated."); diff --git a/cocos/2d/cocos2d_wp8.vcxproj b/cocos/2d/cocos2d_wp8.vcxproj index 07a0aefc46..bd9eafacf0 100644 --- a/cocos/2d/cocos2d_wp8.vcxproj +++ b/cocos/2d/cocos2d_wp8.vcxproj @@ -236,8 +236,6 @@ - - @@ -280,7 +278,6 @@ NotUsing - @@ -462,8 +459,6 @@ - - @@ -496,7 +491,6 @@ - diff --git a/cocos/2d/cocos2d_wp8.vcxproj.filters b/cocos/2d/cocos2d_wp8.vcxproj.filters index 5a53e1329e..154b65da34 100644 --- a/cocos/2d/cocos2d_wp8.vcxproj.filters +++ b/cocos/2d/cocos2d_wp8.vcxproj.filters @@ -623,12 +623,6 @@ 3d - - 3d - - - 3d - 3d @@ -647,9 +641,6 @@ renderer - - base - base @@ -1313,12 +1304,6 @@ 3d - - 3d - - - 3d - 3d @@ -1337,9 +1322,6 @@ renderer - - base - base diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index f56e2e6351..c454b4f63a 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -85,6 +85,8 @@ list(REMOVE_ITEM cocos2d_source_files "${CMAKE_CURRENT_SOURCE_DIR}/base/CCController-android.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/base/CCUserDefaultAndroid.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/ui/UIVideoPlayerAndroid.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/ui/UIWebView.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/ui/UIWebViewImpl_android.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/storage/local-storage/LocalStorageAndroid.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/base/CCEventController.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/base/CCEventListenerController.cpp" diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java index 1ad24349ab..53ea0418a3 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -33,11 +33,10 @@ import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.os.Message; -import android.view.ViewGroup; -import android.view.WindowManager; -import android.util.Log; -import android.widget.FrameLayout; import android.preference.PreferenceManager.OnActivityResultListener; +import android.util.Log; +import android.view.ViewGroup; +import android.widget.FrameLayout; public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener { // =========================================================== @@ -55,6 +54,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe private Cocos2dxHandler mHandler; private static Cocos2dxActivity sContext = null; private Cocos2dxVideoHelper mVideoHelper = null; + private Cocos2dxWebViewHelper mWebViewHelper = null; public static Context getContext() { return sContext; @@ -102,6 +102,10 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe if (mVideoHelper == null) { mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout); } + + if(mWebViewHelper == null){ + mWebViewHelper = new Cocos2dxWebViewHelper(mFrameLayout); + } } //native method,call GLViewImpl::getGLContextAttrs() to get the OpenGL ES context attributions diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebView.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebView.java new file mode 100755 index 0000000000..15a55841b7 --- /dev/null +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebView.java @@ -0,0 +1,94 @@ +package org.cocos2dx.lib; + +import java.lang.reflect.Method; +import java.net.URI; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.Log; +import android.webkit.WebChromeClient; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.FrameLayout; + +public class Cocos2dxWebView extends WebView { + private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName(); + + private int viewTag; + private String jsScheme; + + public Cocos2dxWebView(Context context) { + this(context, -1); + } + + @SuppressLint("SetJavaScriptEnabled") + public Cocos2dxWebView(Context context, int viewTag) { + super(context); + this.viewTag = viewTag; + this.jsScheme = ""; + + this.setFocusable(true); + this.setFocusableInTouchMode(true); + + this.getSettings().setSupportZoom(false); + + this.getSettings().setJavaScriptEnabled(true); + + // `searchBoxJavaBridge_` has big security risk. http://jvn.jp/en/jp/JVN53768697 + try { + Method method = this.getClass().getMethod("removeJavascriptInterface", new Class[]{String.class}); + method.invoke(this, "searchBoxJavaBridge_"); + } catch (Exception e) { + Log.d(TAG, "This API level do not support `removeJavascriptInterface`"); + } + + this.setWebViewClient(new Cocos2dxWebViewClient()); + this.setWebChromeClient(new WebChromeClient()); + } + + public void setJavascriptInterfaceScheme(String scheme) { + this.jsScheme = scheme != null ? scheme : ""; + } + + public void setScalesPageToFit(boolean scalesPageToFit) { + this.getSettings().setSupportZoom(scalesPageToFit); + } + + class Cocos2dxWebViewClient extends WebViewClient { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String urlString) { + URI uri = URI.create(urlString); + if (uri != null && uri.getScheme().equals(jsScheme)) { + Cocos2dxWebViewHelper._onJsCallback(viewTag, urlString); + return true; + } + return Cocos2dxWebViewHelper._shouldStartLoading(viewTag, urlString); + } + + @Override + public void onPageFinished(WebView view, String url) { + super.onPageFinished(view, url); + Cocos2dxWebViewHelper._didFinishLoading(viewTag, url); + } + + @Override + public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { + super.onReceivedError(view, errorCode, description, failingUrl); + Cocos2dxWebViewHelper._didFailLoading(viewTag, failingUrl); + } + } + + public void setWebViewRect(int left, int top, int maxWidth, int maxHeight) { + fixSize(left, top, maxWidth, maxHeight); + } + + private void fixSize(int left, int top, int width, int height) { + FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, + FrameLayout.LayoutParams.WRAP_CONTENT); + layoutParams.leftMargin = left; + layoutParams.topMargin = top; + layoutParams.width = width; + layoutParams.height = height; + this.setLayoutParams(layoutParams); + } +} diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java new file mode 100755 index 0000000000..e8d45b787e --- /dev/null +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxWebViewHelper.java @@ -0,0 +1,296 @@ +package org.cocos2dx.lib; + +import android.os.Handler; +import android.os.Looper; +import android.util.SparseArray; +import android.view.View; +import android.widget.FrameLayout; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.FutureTask; + + +public class Cocos2dxWebViewHelper { + private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName(); + private static Handler handler; + private static Cocos2dxActivity cocos2dxActivity; + private static FrameLayout layout; + + private static SparseArray webViews; + private static int viewTag = 0; + + public Cocos2dxWebViewHelper(FrameLayout layout) { + Cocos2dxWebViewHelper.layout = layout; + Cocos2dxWebViewHelper.handler = new Handler(Looper.myLooper()); + + Cocos2dxWebViewHelper.cocos2dxActivity = (Cocos2dxActivity) Cocos2dxActivity.getContext(); + Cocos2dxWebViewHelper.webViews = new SparseArray(); + } + + private static native boolean shouldStartLoading(int index, String message); + + public static boolean _shouldStartLoading(int index, String message) { + return !shouldStartLoading(index, message); + } + + private static native void didFinishLoading(int index, String message); + + public static void _didFinishLoading(int index, String message) { + didFinishLoading(index, message); + } + + private static native void didFailLoading(int index, String message); + + public static void _didFailLoading(int index, String message) { + didFailLoading(index, message); + } + + private static native void onJsCallback(int index, String message); + + public static void _onJsCallback(int index, String message) { + onJsCallback(index, message); + } + + @SuppressWarnings("unused") + public static int createWebView() { + final int index = viewTag; + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = new Cocos2dxWebView(cocos2dxActivity, index); + FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.WRAP_CONTENT, + FrameLayout.LayoutParams.WRAP_CONTENT); + layout.addView(webView, lParams); + + webViews.put(index, webView); + } + }); + return viewTag++; + } + + @SuppressWarnings("unused") + public static void removeWebView(final int index) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webViews.remove(index); + layout.removeView(webView); + } + } + }); + } + + @SuppressWarnings("unused") + public static void setVisible(final int index, final boolean visible) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.setVisibility(visible ? View.VISIBLE : View.GONE); + } + } + }); + } + + @SuppressWarnings("unused") + public static void setWebViewRect(final int index, final int left, final int top, final int maxWidth, final int maxHeight) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.setWebViewRect(left, top, maxWidth, maxHeight); + } + } + }); + } + + @SuppressWarnings("unused") + public static void setJavascriptInterfaceScheme(final int index, final String scheme) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.setJavascriptInterfaceScheme(scheme); + } + } + }); + } + + @SuppressWarnings("unused") + public static void loadData(final int index, final String data, final String mimeType, final String encoding, final String baseURL) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.loadDataWithBaseURL(baseURL, data, mimeType, encoding, null); + } + } + }); + } + + @SuppressWarnings("unused") + public static void loadHTMLString(final int index, final String htmlString, final String mimeType, final String encoding) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.loadData(htmlString, mimeType, encoding); + } + } + }); + } + + @SuppressWarnings("unused") + public static void loadUrl(final int index, final String url) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.loadUrl(url); + } + } + }); + } + + @SuppressWarnings("unused") + public static void loadFile(final int index, final String filePath) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.loadUrl(filePath); + } + } + }); + } + + public static void stopLoading(final int index) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.stopLoading(); + } + } + }); + + } + + public static void reload(final int index) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.reload(); + } + } + }); + } + + public static T callInMainThread(Callable call) throws ExecutionException, InterruptedException { + FutureTask task = new FutureTask(call); + handler.post(task); + return task.get(); + } + + @SuppressWarnings("unused") + public static boolean canGoBack(final int index) { + Callable callable = new Callable() { + @Override + public Boolean call() throws Exception { + Cocos2dxWebView webView = webViews.get(index); + return webView != null && webView.canGoBack(); + } + }; + try { + return callInMainThread(callable); + } catch (ExecutionException e) { + return false; + } catch (InterruptedException e) { + return false; + } + } + + @SuppressWarnings("unused") + public static boolean canGoForward(final int index) { + Callable callable = new Callable() { + @Override + public Boolean call() throws Exception { + Cocos2dxWebView webView = webViews.get(index); + return webView != null && webView.canGoForward(); + } + }; + try { + return callInMainThread(callable); + } catch (ExecutionException e) { + return false; + } catch (InterruptedException e) { + return false; + } + } + + @SuppressWarnings("unused") + public static void goBack(final int index) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.goBack(); + } + } + }); + } + + @SuppressWarnings("unused") + public static void goForward(final int index) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.goForward(); + } + } + }); + } + + @SuppressWarnings("unused") + public static void evaluateJS(final int index, final String js) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.loadUrl("javascript:" + js); + } + } + }); + } + + @SuppressWarnings("unused") + public static void setScalesPageToFit(final int index, final boolean scalesPageToFit) { + cocos2dxActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Cocos2dxWebView webView = webViews.get(index); + if (webView != null) { + webView.setScalesPageToFit(scalesPageToFit); + } + } + }); + } +} diff --git a/cocos/scripting/lua-bindings/auto/api/ActionManager.lua b/cocos/scripting/lua-bindings/auto/api/ActionManager.lua index 28013accad..8597ac46f3 100644 --- a/cocos/scripting/lua-bindings/auto/api/ActionManager.lua +++ b/cocos/scripting/lua-bindings/auto/api/ActionManager.lua @@ -38,6 +38,11 @@ -- @param self -- @param #float float +-------------------------------- +-- @function [parent=#ActionManager] pauseTarget +-- @param self +-- @param #cc.Node node + -------------------------------- -- @function [parent=#ActionManager] getNumberOfRunningActionsInTarget -- @param self @@ -60,8 +65,9 @@ -- @param #cc.Action action -------------------------------- --- @function [parent=#ActionManager] pauseTarget +-- @function [parent=#ActionManager] removeAllActionsByTag -- @param self +-- @param #int int -- @param #cc.Node node -------------------------------- diff --git a/cocos/scripting/lua-bindings/auto/api/Node.lua b/cocos/scripting/lua-bindings/auto/api/Node.lua index 78ed3e036e..e97163ead5 100644 --- a/cocos/scripting/lua-bindings/auto/api/Node.lua +++ b/cocos/scripting/lua-bindings/auto/api/Node.lua @@ -614,6 +614,11 @@ -- @param self -- @return size_table#size_table ret (return value: size_table) +-------------------------------- +-- @function [parent=#Node] stopAllActionsByTag +-- @param self +-- @param #int int + -------------------------------- -- @function [parent=#Node] getColor -- @param self diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index 02ae6b060a..88054b0c75 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -7943,6 +7943,52 @@ int lua_cocos2dx_Node_getContentSize(lua_State* tolua_S) return 0; } +int lua_cocos2dx_Node_stopAllActionsByTag(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Node* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_stopAllActionsByTag'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + int arg0; + + ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.Node:stopAllActionsByTag"); + if(!ok) + return 0; + cobj->stopAllActionsByTag(arg0); + return 0; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:stopAllActionsByTag",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_stopAllActionsByTag'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_Node_getColor(lua_State* tolua_S) { int argc = 0; @@ -8968,6 +9014,7 @@ int lua_register_cocos2dx_Node(lua_State* tolua_S) tolua_function(tolua_S,"cleanup",lua_cocos2dx_Node_cleanup); tolua_function(tolua_S,"getComponent",lua_cocos2dx_Node_getComponent); tolua_function(tolua_S,"getContentSize",lua_cocos2dx_Node_getContentSize); + tolua_function(tolua_S,"stopAllActionsByTag",lua_cocos2dx_Node_stopAllActionsByTag); tolua_function(tolua_S,"getColor",lua_cocos2dx_Node_getColor); tolua_function(tolua_S,"getBoundingBox",lua_cocos2dx_Node_getBoundingBox); tolua_function(tolua_S,"setEventDispatcher",lua_cocos2dx_Node_setEventDispatcher); @@ -26338,6 +26385,52 @@ int lua_cocos2dx_ActionManager_update(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ActionManager_pauseTarget(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ActionManager* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.ActionManager",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ActionManager*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ActionManager_pauseTarget'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 1) + { + cocos2d::Node* arg0; + + ok &= luaval_to_object(tolua_S, 2, "cc.Node",&arg0); + if(!ok) + return 0; + cobj->pauseTarget(arg0); + return 0; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.ActionManager:pauseTarget",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ActionManager_pauseTarget'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ActionManager_getNumberOfRunningActionsInTarget(lua_State* tolua_S) { int argc = 0; @@ -26523,7 +26616,7 @@ int lua_cocos2dx_ActionManager_removeAction(lua_State* tolua_S) return 0; } -int lua_cocos2dx_ActionManager_pauseTarget(lua_State* tolua_S) +int lua_cocos2dx_ActionManager_removeAllActionsByTag(lua_State* tolua_S) { int argc = 0; cocos2d::ActionManager* cobj = nullptr; @@ -26543,28 +26636,31 @@ int lua_cocos2dx_ActionManager_pauseTarget(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 if (!cobj) { - tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ActionManager_pauseTarget'", nullptr); + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ActionManager_removeAllActionsByTag'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; - if (argc == 1) + if (argc == 2) { - cocos2d::Node* arg0; + int arg0; + cocos2d::Node* arg1; - ok &= luaval_to_object(tolua_S, 2, "cc.Node",&arg0); + ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.ActionManager:removeAllActionsByTag"); + + ok &= luaval_to_object(tolua_S, 3, "cc.Node",&arg1); if(!ok) return 0; - cobj->pauseTarget(arg0); + cobj->removeAllActionsByTag(arg0, arg1); return 0; } - CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.ActionManager:pauseTarget",argc, 1); + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.ActionManager:removeAllActionsByTag",argc, 2); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ActionManager_pauseTarget'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ActionManager_removeAllActionsByTag'.",&tolua_err); #endif return 0; @@ -26666,11 +26762,12 @@ int lua_register_cocos2dx_ActionManager(lua_State* tolua_S) tolua_function(tolua_S,"addAction",lua_cocos2dx_ActionManager_addAction); tolua_function(tolua_S,"resumeTarget",lua_cocos2dx_ActionManager_resumeTarget); tolua_function(tolua_S,"update",lua_cocos2dx_ActionManager_update); + tolua_function(tolua_S,"pauseTarget",lua_cocos2dx_ActionManager_pauseTarget); tolua_function(tolua_S,"getNumberOfRunningActionsInTarget",lua_cocos2dx_ActionManager_getNumberOfRunningActionsInTarget); tolua_function(tolua_S,"removeAllActionsFromTarget",lua_cocos2dx_ActionManager_removeAllActionsFromTarget); tolua_function(tolua_S,"resumeTargets",lua_cocos2dx_ActionManager_resumeTargets); tolua_function(tolua_S,"removeAction",lua_cocos2dx_ActionManager_removeAction); - tolua_function(tolua_S,"pauseTarget",lua_cocos2dx_ActionManager_pauseTarget); + tolua_function(tolua_S,"removeAllActionsByTag",lua_cocos2dx_ActionManager_removeAllActionsByTag); tolua_function(tolua_S,"pauseAllRunningActions",lua_cocos2dx_ActionManager_pauseAllRunningActions); tolua_endmodule(tolua_S); std::string typeName = typeid(cocos2d::ActionManager).name(); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index e4b2d6b037..4d85878dfc 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -1558,6 +1558,8 @@ int register_all_cocos2dx(lua_State* tolua_S); + + diff --git a/cocos/ui/Android.mk b/cocos/ui/Android.mk index 78bd2c4630..221315e578 100644 --- a/cocos/ui/Android.mk +++ b/cocos/ui/Android.mk @@ -31,6 +31,8 @@ UIRelativeBox.cpp \ UIVideoPlayerAndroid.cpp \ UIDeprecated.cpp \ UIScale9Sprite.cpp \ +UIWebView.cpp \ +UIWebViewImpl_android.cpp \ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \ $(LOCAL_PATH)/../editor-support diff --git a/cocos/ui/CocosGUI.h b/cocos/ui/CocosGUI.h index 5fc08abefc..04ce980bd5 100644 --- a/cocos/ui/CocosGUI.h +++ b/cocos/ui/CocosGUI.h @@ -47,6 +47,7 @@ THE SOFTWARE. #include "ui/UIRelativeBox.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #include "ui/UIVideoPlayer.h" +#include "ui/UIWebView.h" #endif #include "ui/UIDeprecated.h" #include "ui/GUIExport.h" diff --git a/cocos/ui/UIWebView-inl.h b/cocos/ui/UIWebView-inl.h new file mode 100644 index 0000000000..26e8eb369f --- /dev/null +++ b/cocos/ui/UIWebView-inl.h @@ -0,0 +1,141 @@ +/**************************************************************************** + Copyright (c) 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. + ****************************************************************************/ + + +#include "UIWebView.h" +#include "platform/CCGLView.h" +#include "base/CCDirector.h" +#include "platform/CCFileUtils.h" + + + +NS_CC_BEGIN +namespace experimental{ + namespace ui{ + + WebView::WebView() + : _impl(new WebViewImpl(this)) + { + } + + WebView::~WebView() + { + CC_SAFE_DELETE(_impl); + } + + WebView *WebView::create() + { + auto webView = new(std::nothrow) WebView(); + if (webView && webView->init()) + { + webView->autorelease(); + return webView; + } + CC_SAFE_DELETE(webView); + return nullptr; + } + + void WebView::setJavascriptInterfaceScheme(const std::string &scheme) + { + _impl->setJavascriptInterfaceScheme(scheme); + } + + void WebView::loadData(const cocos2d::Data &data, + const std::string &MIMEType, + const std::string &encoding, + const std::string &baseURL) + { + _impl->loadData(data, MIMEType, encoding, baseURL); + } + + void WebView::loadHTMLString(const std::string &string, const std::string &baseURL) + { + _impl->loadHTMLString(string, baseURL); + } + + void WebView::loadUrl(const std::string &url) + { + _impl->loadUrl(url); + } + + void WebView::loadFile(const std::string &fileName) + { + _impl->loadFile(fileName); + } + + void WebView::stopLoading() + { + _impl->stopLoading(); + } + + void WebView::reload() + { + _impl->reload(); + } + + bool WebView::canGoBack() + { + return _impl->canGoBack(); + } + + bool WebView::canGoForward() + { + return _impl->canGoForward(); + } + + void WebView::goBack() + { + _impl->goBack(); + } + + void WebView::goForward() + { + _impl->goForward(); + } + + void WebView::evaluateJS(const std::string &js) + { + _impl->evaluateJS(js); + } + + void WebView::setScalesPageToFit(bool const scalesPageToFit) + { + _impl->setScalesPageToFit(scalesPageToFit); + } + + void WebView::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) + { + cocos2d::ui::Widget::draw(renderer, transform, flags); + _impl->draw(renderer, transform, flags); + } + + void WebView::setVisible(bool visible) + { + Node::setVisible(visible); + _impl->setVisible(visible); + } + } // namespace ui +} // namespace experimental +} //namespace cocos2d + diff --git a/cocos/ui/UIWebView.cpp b/cocos/ui/UIWebView.cpp new file mode 100644 index 0000000000..07bb327b0f --- /dev/null +++ b/cocos/ui/UIWebView.cpp @@ -0,0 +1,30 @@ +/**************************************************************************** + Copyright (c) 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. + ****************************************************************************/ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + +#include "UIWebViewImpl_android.h" +#include "UIWebView-inl.h" + + +#endif diff --git a/cocos/ui/UIWebView.h b/cocos/ui/UIWebView.h new file mode 100644 index 0000000000..37c67e3d91 --- /dev/null +++ b/cocos/ui/UIWebView.h @@ -0,0 +1,176 @@ +/**************************************************************************** + Copyright (c) 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 __Cocos2d_Plugin_WebView_H_ +#define __Cocos2d_Plugin_WebView_H_ + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + + +#include "ui/UIWidget.h" +#include "base/CCData.h" + +NS_CC_BEGIN +namespace experimental{ + namespace ui{ + +class WebViewImpl; + +class WebView : public cocos2d::ui::Widget { +public: + /** + * Allocates and initializes a WebView. + */ + static WebView *create(); + + /** + * Default constructor + */ + WebView(); + + /** + * Default destructor + */ + virtual ~WebView(); + + /** + * Call before a web view begins loading. + * @param sender The web view that is about to load new content. + * @param url content URL. + * @return YES if the web view should begin loading content; otherwise, NO . + */ + std::function shouldStartLoading; + /** + * Call after a web view finishes loading. + * @param sender The web view that has finished loading. + * @param url content URL. + */ + std::function didFinishLoading; + /** + * Call if a web view failed to load content. + * @param sender The web view that has failed loading. + * @param url content URL. + */ + std::function didFailLoading; + + /** + * Set javascript interface scheme. + * @see #onJsCallback + */ + void setJavascriptInterfaceScheme(const std::string &scheme); + + /** + * This callback called when load URL that start with javascript interface scheme. + */ + std::function onJsCallback; + + /** + * Sets the main page contents, MIME type, content encoding, and base URL. + * @param data The content for the main page. + * @param MIMEType The MIME type of the data. + * @param encoding the encoding of the data. + * @param baseURL The base URL for the content. + */ + void loadData(const cocos2d::Data &data, + const std::string &MIMEType, + const std::string &encoding, + const std::string &baseURL); + + + /** + * Sets the main page content and base URL. + * @param string The content for the main page. + * @param baseURL The base URL for the content. + */ + void loadHTMLString(const std::string &string, const std::string &baseURL); + + /** + * Loads the given URL. + * @param url content URL + */ + void loadUrl(const std::string &url); + + /** + * Loads the given fileName. + * @param fileName content fileName + */ + void loadFile(const std::string &fileName); + + /** + * Stops the current load. + */ + void stopLoading(); + + /** + * Reloads the current URL. + */ + void reload(); + + /** + * Gets whether this WebView has a back history item. + * @return web view has a back history item. + */ + bool canGoBack(); + + /** + * Gets whether this WebView has a forward history item. + * @return web view has a forward history item. + */ + bool canGoForward(); + + /** + * Goes back in the history. + */ + void goBack(); + + /** + * Goes forward in the history. + */ + void goForward(); + + /** + * evaluates JavaScript in the context of the currently displayed page + */ + void evaluateJS(const std::string &js); + + /** + * Set WebView should support zooming. The default value is false. + */ + void setScalesPageToFit(const bool scalesPageToFit); + + virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) override; + + virtual void setVisible(bool visible) override; + +private: + WebViewImpl *_impl; +}; + + } // namespace ui + } // namespace experimental +}//namespace cocos2d + +#endif + +#endif //__Cocos2d_Plugin_WebView_H_ diff --git a/cocos/ui/UIWebView.mm b/cocos/ui/UIWebView.mm new file mode 100644 index 0000000000..455fbb43e5 --- /dev/null +++ b/cocos/ui/UIWebView.mm @@ -0,0 +1,30 @@ +/**************************************************************************** + Copyright (c) 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. + ****************************************************************************/ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + +#include "UIWebViewImpl_iOS.h" +#include "UIWebView-inl.h" + + +#endif diff --git a/cocos/ui/UIWebViewImpl_android.cpp b/cocos/ui/UIWebViewImpl_android.cpp new file mode 100644 index 0000000000..53abeb2aaa --- /dev/null +++ b/cocos/ui/UIWebViewImpl_android.cpp @@ -0,0 +1,435 @@ +/**************************************************************************** + Copyright (c) 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. + ****************************************************************************/ + +#include "UIWebViewImpl_android.h" + +#include +#include +#include +#include "jni/JniHelper.h" +#include + +#include "UIWebView.h" +#include "platform/CCGLView.h" +#include "base/CCDirector.h" +#include "platform/CCFileUtils.h" + +#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxWebViewHelper" + +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,"",__VA_ARGS__) + +extern "C" { + /* + * Class: org_cocos2dx_lib_Cocos2dxWebViewHelper + * Method: shouldStartLoading + * Signature: (ILjava/lang/String;)Z + */ + JNIEXPORT jboolean JNICALL Java_org_cocos2dx_lib_Cocos2dxWebViewHelper_shouldStartLoading(JNIEnv *env, jclass, jint index, jstring jurl) { + auto charUrl = env->GetStringUTFChars(jurl, NULL); + std::string url = charUrl; + env->ReleaseStringUTFChars(jurl, charUrl); + return cocos2d::experimental::ui::WebViewImpl::shouldStartLoading(index, url); + } + + /* + * Class: org_cocos2dx_lib_Cocos2dxWebViewHelper + * Method: didFinishLoading + * Signature: (ILjava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxWebViewHelper_didFinishLoading(JNIEnv *env, jclass, jint index, jstring jurl) { + // LOGD("didFinishLoading"); + auto charUrl = env->GetStringUTFChars(jurl, NULL); + std::string url = charUrl; + env->ReleaseStringUTFChars(jurl, charUrl); + cocos2d::experimental::ui::WebViewImpl::didFinishLoading(index, url); + } + + /* + * Class: org_cocos2dx_lib_Cocos2dxWebViewHelper + * Method: didFailLoading + * Signature: (ILjava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxWebViewHelper_didFailLoading(JNIEnv *env, jclass, jint index, jstring jurl) { + // LOGD("didFailLoading"); + auto charUrl = env->GetStringUTFChars(jurl, NULL); + std::string url = charUrl; + env->ReleaseStringUTFChars(jurl, charUrl); + cocos2d::experimental::ui::WebViewImpl::didFailLoading(index, url); + } + + /* + * Class: org_cocos2dx_lib_Cocos2dxWebViewHelper + * Method: onJsCallback + * Signature: (ILjava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxWebViewHelper_onJsCallback(JNIEnv *env, jclass, jint index, jstring jmessage) { + // LOGD("jsCallback"); + auto charMessage = env->GetStringUTFChars(jmessage, NULL); + std::string message = charMessage; + env->ReleaseStringUTFChars(jmessage, charMessage); + cocos2d::experimental::ui::WebViewImpl::onJsCallback(index, message); + } +} + +namespace { + +int createWebViewJNI() { + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "createWebView", "()I")) { + // LOGD("error: %s,%d",__func__,__LINE__); + jint viewTag = t.env->CallStaticIntMethod(t.classID, t.methodID); + t.env->DeleteLocalRef(t.classID); + return viewTag; + } + return -1; +} + +void removeWebViewJNI(const int index) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "removeWebView", "(I)V")) { + t.env->CallStaticVoidMethod(t.classID, t.methodID, index); + t.env->DeleteLocalRef(t.classID); + } +} + +void setWebViewRectJNI(const int index, const int left, const int top, const int width, const int height) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setWebViewRect", "(IIIII)V")) { + t.env->CallStaticVoidMethod(t.classID, t.methodID, index, left, top, width, height); + t.env->DeleteLocalRef(t.classID); + } +} + +void setJavascriptInterfaceSchemeJNI(const int index, const std::string &scheme) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setJavascriptInterfaceScheme", "(ILjava/lang/String;)V")) { + jstring jScheme = t.env->NewStringUTF(scheme.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jScheme); + + t.env->DeleteLocalRef(jScheme); + t.env->DeleteLocalRef(t.classID); + } +} + +void loadDataJNI(const int index, const std::string &data, const std::string &MIMEType, const std::string &encoding, const std::string &baseURL) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "loadData", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) { + jstring jData = t.env->NewStringUTF(data.c_str()); + jstring jMIMEType = t.env->NewStringUTF(MIMEType.c_str()); + jstring jEncoding = t.env->NewStringUTF(encoding.c_str()); + jstring jBaseURL = t.env->NewStringUTF(baseURL.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jData, jMIMEType, jEncoding, jBaseURL); + + t.env->DeleteLocalRef(jData); + t.env->DeleteLocalRef(jMIMEType); + t.env->DeleteLocalRef(jEncoding); + t.env->DeleteLocalRef(jBaseURL); + t.env->DeleteLocalRef(t.classID); + } +} + +void loadHTMLStringJNI(const int index, const std::string &string, const std::string &baseURL) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "loadHTMLString", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) { + jstring jString = t.env->NewStringUTF(string.c_str()); + jstring jBaseURL = t.env->NewStringUTF(baseURL.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jString, jBaseURL,nullptr); + + t.env->DeleteLocalRef(jString); + t.env->DeleteLocalRef(jBaseURL); + t.env->DeleteLocalRef(t.classID); + } +} + +void loadUrlJNI(const int index, const std::string &url) { + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "loadUrl", "(ILjava/lang/String;)V")) { + jstring jUrl = t.env->NewStringUTF(url.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jUrl); + + t.env->DeleteLocalRef(jUrl); + t.env->DeleteLocalRef(t.classID); + } +} + +void loadFileJNI(const int index, const std::string &filePath) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "loadFile", "(ILjava/lang/String;)V")) { + jstring jFilePath = t.env->NewStringUTF(filePath.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jFilePath); + + t.env->DeleteLocalRef(jFilePath); + t.env->DeleteLocalRef(t.classID); + } +} + +void stopLoadingJNI(const int index) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "stopLoading", "(I)V")) { + t.env->CallStaticVoidMethod(t.classID, t.methodID, index); + t.env->DeleteLocalRef(t.classID); + } +} + +void reloadJNI(const int index) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "reload", "(I)V")) { + t.env->CallStaticVoidMethod(t.classID, t.methodID, index); + t.env->DeleteLocalRef(t.classID); + } +} + +bool canGoBackJNI(const int index) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "canGoBack", "(I)Z")) { + jboolean ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, index); + t.env->DeleteLocalRef(t.classID); + return ret; + } + return false; +} + +bool canGoForwardJNI(const int index) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "canGoForward", "(I)Z")) { + jboolean ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, index); + t.env->DeleteLocalRef(t.classID); + return ret; + } + return false; +} + +void goBackJNI(const int index) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "goBack", "(I)V")) { + t.env->CallStaticVoidMethod(t.classID, t.methodID, index); + t.env->DeleteLocalRef(t.classID); + } +} + +void goForwardJNI(const int index) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "goForward", "(I)V")) { + t.env->CallStaticVoidMethod(t.classID, t.methodID, index); + t.env->DeleteLocalRef(t.classID); + } +} + +void evaluateJSJNI(const int index, const std::string &js) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "evaluateJS", "(ILjava/lang/String;)V")) { + jstring jjs = t.env->NewStringUTF(js.c_str()); + t.env->CallStaticVoidMethod(t.classID, t.methodID, index, jjs); + + t.env->DeleteLocalRef(jjs); + t.env->DeleteLocalRef(t.classID); + } +} + +void setScalesPageToFitJNI(const int index, const bool scalesPageToFit) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setScalesPageToFit", "(IZ)V")) { + t.env->CallStaticVoidMethod(t.classID, t.methodID, index, scalesPageToFit); + t.env->DeleteLocalRef(t.classID); + } +} + +void setWebViewVisibleJNI(const int index, const bool visible) { + // LOGD("error: %s,%d",__func__,__LINE__); + cocos2d::JniMethodInfo t; + if (cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setVisible", "(IZ)V")) { + t.env->CallStaticVoidMethod(t.classID, t.methodID, index, visible); + t.env->DeleteLocalRef(t.classID); + } +} + +std::string getUrlStringByFileName(const std::string &fileName) { + // LOGD("error: %s,%d",__func__,__LINE__); + const std::string basePath("file:///android_asset/"); + std::string fullPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fileName); + const std::string assetsPath("assets/"); + + std::string urlString; + if (fullPath.find(assetsPath) != std::string::npos) { + urlString = fullPath.replace(fullPath.find_first_of(assetsPath), assetsPath.length(), basePath); + } else { + urlString = fullPath; + } + + return urlString; +} +} // namespace + +namespace cocos2d { + namespace experimental { + namespace ui{ + + static std::unordered_map s_WebViewImpls; + + WebViewImpl::WebViewImpl(WebView *webView) : _viewTag(-1), _webView(webView) { + _viewTag = createWebViewJNI(); + s_WebViewImpls[_viewTag] = this; + } + + WebViewImpl::~WebViewImpl() { + removeWebViewJNI(_viewTag); + s_WebViewImpls.erase(_viewTag); + } + + void WebViewImpl::loadData(const Data &data, const std::string &MIMEType, const std::string &encoding, const std::string &baseURL) { + std::string dataString(reinterpret_cast(data.getBytes()), static_cast(data.getSize())); + loadDataJNI(_viewTag, dataString, MIMEType, encoding, baseURL); + } + + void WebViewImpl::loadHTMLString(const std::string &string, const std::string &baseURL) { + loadHTMLStringJNI(_viewTag, string, baseURL); + } + + void WebViewImpl::loadUrl(const std::string &url) { + loadUrlJNI(_viewTag, url); + } + + void WebViewImpl::loadFile(const std::string &fileName) { + auto fullPath = getUrlStringByFileName(fileName); + loadFileJNI(_viewTag, fullPath); + } + + void WebViewImpl::stopLoading() { + stopLoadingJNI(_viewTag); + } + + void WebViewImpl::reload() { + reloadJNI(_viewTag); + } + + bool WebViewImpl::canGoBack() { + return canGoBackJNI(_viewTag); + } + + bool WebViewImpl::canGoForward() { + return canGoForwardJNI(_viewTag); + } + + void WebViewImpl::goBack() { + goBackJNI(_viewTag); + } + + void WebViewImpl::goForward() { + goForwardJNI(_viewTag); + } + + void WebViewImpl::setJavascriptInterfaceScheme(const std::string &scheme) { + setJavascriptInterfaceSchemeJNI(_viewTag, scheme); + } + + void WebViewImpl::evaluateJS(const std::string &js) { + evaluateJSJNI(_viewTag, js); + } + + void WebViewImpl::setScalesPageToFit(const bool scalesPageToFit) { + setScalesPageToFitJNI(_viewTag, scalesPageToFit); + } + + bool WebViewImpl::shouldStartLoading(const int viewTag, const std::string &url) { + auto it = s_WebViewImpls.find(viewTag); + if (it != s_WebViewImpls.end()) { + auto webView = s_WebViewImpls[viewTag]->_webView; + if (webView->shouldStartLoading) { + return webView->shouldStartLoading(webView, url); + } + } + return true; + } + + void WebViewImpl::didFinishLoading(const int viewTag, const std::string &url){ + auto it = s_WebViewImpls.find(viewTag); + if (it != s_WebViewImpls.end()) { + auto webView = s_WebViewImpls[viewTag]->_webView; + if (webView->didFinishLoading) { + webView->didFinishLoading(webView, url); + } + } + } + + void WebViewImpl::didFailLoading(const int viewTag, const std::string &url){ + auto it = s_WebViewImpls.find(viewTag); + if (it != s_WebViewImpls.end()) { + auto webView = s_WebViewImpls[viewTag]->_webView; + if (webView->didFailLoading) { + webView->didFailLoading(webView, url); + } + } + } + + void WebViewImpl::onJsCallback(const int viewTag, const std::string &message){ + auto it = s_WebViewImpls.find(viewTag); + if (it != s_WebViewImpls.end()) { + auto webView = s_WebViewImpls[viewTag]->_webView; + if (webView->onJsCallback) { + webView->onJsCallback(webView, message); + } + } + } + + void WebViewImpl::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) { + if (flags & cocos2d::Node::FLAGS_TRANSFORM_DIRTY) { + auto directorInstance = cocos2d::Director::getInstance(); + auto glView = directorInstance->getOpenGLView(); + auto frameSize = glView->getFrameSize(); + + auto winSize = directorInstance->getWinSize(); + + auto leftBottom = this->_webView->convertToWorldSpace(cocos2d::Point::ZERO); + auto rightTop = this->_webView->convertToWorldSpace(cocos2d::Point(this->_webView->getContentSize().width,this->_webView->getContentSize().height)); + + auto uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2 ) * glView->getScaleX(); + auto uiTop = frameSize.height /2 - (rightTop.y - winSize.height / 2) * glView->getScaleY(); + + setWebViewRectJNI(_viewTag,uiLeft,uiTop, + (rightTop.x - leftBottom.x) * glView->getScaleX(), + (rightTop.y - leftBottom.y) * glView->getScaleY()); + } + } + + void WebViewImpl::setVisible(bool visible) { + setWebViewVisibleJNI(_viewTag, visible); + } + } // namespace ui + } // namespace experimental +} //namespace cocos2d + diff --git a/cocos/ui/UIWebViewImpl_android.h b/cocos/ui/UIWebViewImpl_android.h new file mode 100644 index 0000000000..01a3fd86ef --- /dev/null +++ b/cocos/ui/UIWebViewImpl_android.h @@ -0,0 +1,96 @@ +/**************************************************************************** + Copyright (c) 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 __cocos2d_plugin_WebViewImpl_android_H_ +#define __cocos2d_plugin_WebViewImpl_android_H_ + +#include + +namespace cocos2d { + class Data; + class Renderer; + class Mat4; + + namespace experimental { + namespace ui{ + class WebView; + } + } +} + +namespace cocos2d { + namespace experimental { + namespace ui{ + + class WebViewImpl { + public: + WebViewImpl(cocos2d::experimental::ui::WebView *webView); + + virtual ~WebViewImpl(); + + void setJavascriptInterfaceScheme(const std::string &scheme); + + void loadData(const cocos2d::Data &data, const std::string &MIMEType, const std::string &encoding, const std::string &baseURL); + + void loadHTMLString(const std::string &string, const std::string &baseURL); + + void loadUrl(const std::string &url); + + void loadFile(const std::string &fileName); + + void stopLoading(); + + void reload(); + + bool canGoBack(); + + bool canGoForward(); + + void goBack(); + + void goForward(); + + void evaluateJS(const std::string &js); + + void setScalesPageToFit(const bool scalesPageToFit); + + virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags); + + virtual void setVisible(bool visible); + + static bool shouldStartLoading(const int viewTag, const std::string &url); + static void didFinishLoading(const int viewTag, const std::string &url); + static void didFailLoading(const int viewTag, const std::string &url); + static void onJsCallback(const int viewTag, const std::string &message); + + private: + int _viewTag; + WebView *_webView; + }; + + } // namespace ui + } // namespace experimental +} //cocos2d + +#endif //__cocos2d_plugin_WebViewImpl_android_H_ diff --git a/cocos/ui/UIWebViewImpl_iOS.h b/cocos/ui/UIWebViewImpl_iOS.h new file mode 100644 index 0000000000..277ca59a58 --- /dev/null +++ b/cocos/ui/UIWebViewImpl_iOS.h @@ -0,0 +1,91 @@ +/**************************************************************************** + Copyright (c) 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 __cocos2d_plugin_WebViewImpl_IOS_H_ +#define __cocos2d_plugin_WebViewImpl_IOS_H_ + +#include + +@class UIWebViewWrapper; + +namespace cocos2d { + +class Data; +class Renderer; +class Mat4; + +namespace experimental { + namespace ui{ + +class WebView; + +class WebViewImpl { +public: + WebViewImpl(WebView *webView); + + virtual ~WebViewImpl(); + + void setJavascriptInterfaceScheme(const std::string &scheme); + + void loadData(const cocos2d::Data &data, + const std::string &MIMEType, + const std::string &encoding, + const std::string &baseURL); + + void loadHTMLString(const std::string &string, const std::string &baseURL); + + void loadUrl(const std::string &url); + + void loadFile(const std::string &fileName); + + void stopLoading(); + + void reload(); + + bool canGoBack(); + + bool canGoForward(); + + void goBack(); + + void goForward(); + + void evaluateJS(const std::string &js); + + void setScalesPageToFit(const bool scalesPageToFit); + + virtual void draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags); + + virtual void setVisible(bool visible); + +private: + UIWebViewWrapper *_uiWebViewWrapper; + WebView *_webView; +}; + + } // namespace ui + } // namespace experimental +}//namespace cocos2d + +#endif //__cocos2d_plugin_WebViewImpl_IOS_H_ diff --git a/cocos/ui/UIWebViewImpl_iOS.mm b/cocos/ui/UIWebViewImpl_iOS.mm new file mode 100644 index 0000000000..116b116975 --- /dev/null +++ b/cocos/ui/UIWebViewImpl_iOS.mm @@ -0,0 +1,353 @@ +/**************************************************************************** + Copyright (c) 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. + ****************************************************************************/ + +#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS + +#include "UIWebViewImpl_iOS.h" +#include "renderer/CCRenderer.h" +#include "CCDirector.h" +#include "CCGLView.h" +#include "CCEAGLView.h" +#include "platform/CCFileUtils.h" +#include "ui/UIWebView.h" + +@interface UIWebViewWrapper : NSObject +@property (nonatomic) std::function shouldStartLoading; +@property (nonatomic) std::function didFinishLoading; +@property (nonatomic) std::function didFailLoading; +@property (nonatomic) std::function onJsCallback; + +@property(nonatomic, readonly, getter=canGoBack) BOOL canGoBack; +@property(nonatomic, readonly, getter=canGoForward) BOOL canGoForward; + ++ (instancetype)webViewWrapper; + +- (void)setVisible:(bool)visible; + +- (void)setFrameWithX:(float)x y:(float)y width:(float)width height:(float)height; + +- (void)setJavascriptInterfaceScheme:(const std::string &)scheme; + +- (void)loadData:(const std::string &)data MIMEType:(const std::string &)MIMEType textEncodingName:(const std::string &)encodingName baseURL:(const std::string &)baseURL; + +- (void)loadHTMLString:(const std::string &)string baseURL:(const std::string &)baseURL; + +- (void)loadUrl:(const std::string &)urlString; + +- (void)loadFile:(const std::string &)filePath; + +- (void)stopLoading; + +- (void)reload; + +- (void)evaluateJS:(const std::string &)js; + +- (void)goBack; + +- (void)goForward; + +- (void)setScalesPageToFit:(const bool)scalesPageToFit; +@end + + +@interface UIWebViewWrapper () +@property(nonatomic, retain) UIWebView *uiWebView; +@property(nonatomic, copy) NSString *jsScheme; +@end + +@implementation UIWebViewWrapper { + +} + ++ (instancetype)webViewWrapper { + return [[[self alloc] init] autorelease]; +} + +- (instancetype)init { + self = [super init]; + if (self) { + self.uiWebView = nil; + self.shouldStartLoading = nullptr; + self.didFinishLoading = nullptr; + self.didFailLoading = nullptr; + } + return self; +} + +- (void)dealloc { + self.uiWebView.delegate = nil; + [self.uiWebView removeFromSuperview]; + self.jsScheme = nil; + [super dealloc]; +} + +- (void)setupWebView { + if (!self.uiWebView) { + self.uiWebView = [[[UIWebView alloc] init] autorelease]; + self.uiWebView.delegate = self; + } + if (!self.uiWebView.superview) { + auto view = cocos2d::Director::getInstance()->getOpenGLView(); + auto eaglview = (CCEAGLView *) view->getEAGLView(); + [eaglview addSubview:self.uiWebView]; + } +} + +- (void)setVisible:(bool)visible { + self.uiWebView.hidden = !visible; +} + +- (void)setFrameWithX:(float)x y:(float)y width:(float)width height:(float)height { + if (!self.uiWebView) {[self setupWebView];} + CGRect newFrame = CGRectMake(x, y, width, height); + if (!CGRectEqualToRect(self.uiWebView.frame, newFrame)) { + self.uiWebView.frame = CGRectMake(x, y, width, height); + } +} + +- (void)setJavascriptInterfaceScheme:(const std::string &)scheme { + self.jsScheme = @(scheme.c_str()); +} + +- (void)loadData:(const std::string &)data MIMEType:(const std::string &)MIMEType textEncodingName:(const std::string &)encodingName baseURL:(const std::string &)baseURL { + [self.uiWebView loadData:[NSData dataWithBytes:data.c_str() length:data.length()] + MIMEType:@(MIMEType.c_str()) + textEncodingName:@(encodingName.c_str()) + baseURL:[NSURL URLWithString:@(baseURL.c_str())]]; +} + +- (void)loadHTMLString:(const std::string &)string baseURL:(const std::string &)baseURL { + [self.uiWebView loadHTMLString:@(string.c_str()) baseURL:[NSURL URLWithString:@(baseURL.c_str())]]; +} + +- (void)loadUrl:(const std::string &)urlString { + if (!self.uiWebView) {[self setupWebView];} + NSURL *url = [NSURL URLWithString:@(urlString.c_str())]; + NSURLRequest *request = [NSURLRequest requestWithURL:url]; + [self.uiWebView loadRequest:request]; +} + +- (void)loadFile:(const std::string &)filePath { + if (!self.uiWebView) {[self setupWebView];} + NSURL *url = [NSURL fileURLWithPath:@(filePath.c_str())]; + NSURLRequest *request = [NSURLRequest requestWithURL:url]; + [self.uiWebView loadRequest:request]; +} + +- (void)stopLoading { + [self.uiWebView stopLoading]; +} + +- (void)reload { + [self.uiWebView reload]; +} + +- (BOOL)canGoForward { + return self.uiWebView.canGoForward; +} + +- (BOOL)canGoBack { + return self.uiWebView.canGoBack; +} + +- (void)goBack { + [self.uiWebView goBack]; +} + +- (void)goForward { + [self.uiWebView goForward]; +} + +- (void)evaluateJS:(const std::string &)js { + if (!self.uiWebView) {[self setupWebView];} + [self.uiWebView stringByEvaluatingJavaScriptFromString:@(js.c_str())]; +} + +- (void)setScalesPageToFit:(const bool)scalesPageToFit { + self.uiWebView.scalesPageToFit = scalesPageToFit; +} + +#pragma mark - UIWebViewDelegate +- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { + NSString *url = [[request URL] absoluteString]; + if ([[[request URL] scheme] isEqualToString:self.jsScheme]) { + self.onJsCallback([url UTF8String]); + return NO; + } + if (self.shouldStartLoading && url) { + return self.shouldStartLoading([url UTF8String]); + } + return YES; +} + +- (void)webViewDidFinishLoad:(UIWebView *)webView { + if (self.didFinishLoading) { + NSString *url = [[webView.request URL] absoluteString]; + self.didFinishLoading([url UTF8String]); + } +} + +- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { + if (self.didFailLoading) { + NSString *url = error.userInfo[NSURLErrorFailingURLStringErrorKey]; + if (url) { + self.didFailLoading([url UTF8String]); + } + } +} + +@end + + + +namespace cocos2d { +namespace experimental { + namespace ui{ + +WebViewImpl::WebViewImpl(WebView *webView) + : _uiWebViewWrapper([UIWebViewWrapper webViewWrapper]), + _webView(webView) { + [_uiWebViewWrapper retain]; + + _uiWebViewWrapper.shouldStartLoading = [this](std::string url) { + if (this->_webView->shouldStartLoading) { + return this->_webView->shouldStartLoading(this->_webView, url); + } + return true; + }; + _uiWebViewWrapper.didFinishLoading = [this](std::string url) { + if (this->_webView->didFinishLoading) { + this->_webView->didFinishLoading(this->_webView, url); + } + }; + _uiWebViewWrapper.didFailLoading = [this](std::string url) { + if (this->_webView->didFailLoading) { + this->_webView->didFailLoading(this->_webView, url); + } + }; + _uiWebViewWrapper.onJsCallback = [this](std::string url) { + if (this->_webView->onJsCallback) { + this->_webView->onJsCallback(this->_webView, url); + } + }; +} + +WebViewImpl::~WebViewImpl(){ + [_uiWebViewWrapper release]; + _uiWebViewWrapper = nullptr; +} + +void WebViewImpl::setJavascriptInterfaceScheme(const std::string &scheme) { + [_uiWebViewWrapper setJavascriptInterfaceScheme:scheme]; +} + +void WebViewImpl::loadData(const Data &data, + const std::string &MIMEType, + const std::string &encoding, + const std::string &baseURL) { + + std::string dataString(reinterpret_cast(data.getBytes()), static_cast(data.getSize())); + [_uiWebViewWrapper loadData:dataString MIMEType:MIMEType textEncodingName:encoding baseURL:baseURL]; +} + +void WebViewImpl::loadHTMLString(const std::string &string, const std::string &baseURL) { + [_uiWebViewWrapper loadHTMLString:string baseURL:baseURL]; +} + +void WebViewImpl::loadUrl(const std::string &url) { + [_uiWebViewWrapper loadUrl:url]; +} + +void WebViewImpl::loadFile(const std::string &fileName) { + auto fullPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fileName); + [_uiWebViewWrapper loadFile:fullPath]; +} + +void WebViewImpl::stopLoading() { + [_uiWebViewWrapper stopLoading]; +} + +void WebViewImpl::reload() { + [_uiWebViewWrapper reload]; +} + +bool WebViewImpl::canGoBack() { + return _uiWebViewWrapper.canGoBack; +} + +bool WebViewImpl::canGoForward() { + return _uiWebViewWrapper.canGoForward; +} + +void WebViewImpl::goBack() { + [_uiWebViewWrapper goBack]; +} + +void WebViewImpl::goForward() { + [_uiWebViewWrapper goForward]; +} + +void WebViewImpl::evaluateJS(const std::string &js) { + [_uiWebViewWrapper evaluateJS:js]; +} + +void WebViewImpl::setScalesPageToFit(const bool scalesPageToFit) { + [_uiWebViewWrapper setScalesPageToFit:scalesPageToFit]; +} + +void WebViewImpl::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags) { + if (flags & cocos2d::Node::FLAGS_TRANSFORM_DIRTY) { + + auto direcrot = cocos2d::Director::getInstance(); + auto glView = direcrot->getOpenGLView(); + auto frameSize = glView->getFrameSize(); + + auto scaleFactor = [static_cast(glView->getEAGLView()) contentScaleFactor]; + + auto winSize = direcrot->getWinSize(); + + auto leftBottom = this->_webView->convertToWorldSpace(cocos2d::Vec2::ZERO); + auto rightTop = this->_webView->convertToWorldSpace(cocos2d::Vec2(this->_webView->getContentSize().width, this->_webView->getContentSize().height)); + + auto x = (frameSize.width / 2 + (leftBottom.x - winSize.width / 2) * glView->getScaleX()) / scaleFactor; + auto y = (frameSize.height / 2 - (rightTop.y - winSize.height / 2) * glView->getScaleY()) / scaleFactor; + auto width = (rightTop.x - leftBottom.x) * glView->getScaleX() / scaleFactor; + auto height = (rightTop.y - leftBottom.y) * glView->getScaleY() / scaleFactor; + + [_uiWebViewWrapper setFrameWithX:x + y:y + width:width + height:height]; + } +} + +void WebViewImpl::setVisible(bool visible){ + [_uiWebViewWrapper setVisible:visible]; +} + + } // namespace ui +} // namespace experimental +} //namespace cocos2d + +#endif // CC_TARGET_PLATFORM == CC_PLATFORM_IOS diff --git a/templates/cpp-template-default/proj.android/jni/Application.mk b/templates/cpp-template-default/proj.android/jni/Application.mk index 93c859c1b0..59808706eb 100644 --- a/templates/cpp-template-default/proj.android/jni/Application.mk +++ b/templates/cpp-template-default/proj.android/jni/Application.mk @@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch APP_LDFLAGS := -latomic -APP_DEBUG := $(strip $(NDK_DEBUG)) -ifeq ($(APP_DEBUG),1) +ifeq ($(NDK_DEBUG),1) APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 APP_OPTIM := debug else APP_CPPFLAGS += -DNDEBUG APP_OPTIM := release -endif \ No newline at end of file +endif diff --git a/templates/lua-template-default/frameworks/runtime-src/proj.android/jni/Application.mk b/templates/lua-template-default/frameworks/runtime-src/proj.android/jni/Application.mk index 93c859c1b0..59808706eb 100644 --- a/templates/lua-template-default/frameworks/runtime-src/proj.android/jni/Application.mk +++ b/templates/lua-template-default/frameworks/runtime-src/proj.android/jni/Application.mk @@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch APP_LDFLAGS := -latomic -APP_DEBUG := $(strip $(NDK_DEBUG)) -ifeq ($(APP_DEBUG),1) +ifeq ($(NDK_DEBUG),1) APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 APP_OPTIM := debug else APP_CPPFLAGS += -DNDEBUG APP_OPTIM := release -endif \ No newline at end of file +endif diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/Application.mk b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/Application.mk index 93c859c1b0..59808706eb 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/Application.mk +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.android/jni/Application.mk @@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch APP_LDFLAGS := -latomic -APP_DEBUG := $(strip $(NDK_DEBUG)) -ifeq ($(APP_DEBUG),1) +ifeq ($(NDK_DEBUG),1) APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 APP_OPTIM := debug else APP_CPPFLAGS += -DNDEBUG APP_OPTIM := release -endif \ No newline at end of file +endif diff --git a/tests/cpp-empty-test/proj.android/jni/Application.mk b/tests/cpp-empty-test/proj.android/jni/Application.mk index 93c859c1b0..59808706eb 100644 --- a/tests/cpp-empty-test/proj.android/jni/Application.mk +++ b/tests/cpp-empty-test/proj.android/jni/Application.mk @@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch APP_LDFLAGS := -latomic -APP_DEBUG := $(strip $(NDK_DEBUG)) -ifeq ($(APP_DEBUG),1) +ifeq ($(NDK_DEBUG),1) APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 APP_OPTIM := debug else APP_CPPFLAGS += -DNDEBUG APP_OPTIM := release -endif \ No newline at end of file +endif diff --git a/tests/cpp-tests/Android.mk b/tests/cpp-tests/Android.mk index a954ff93e1..71ff77954d 100644 --- a/tests/cpp-tests/Android.mk +++ b/tests/cpp-tests/Android.mk @@ -104,6 +104,7 @@ Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp \ Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp \ Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp \ Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp \ +Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp \ Classes/UITest/CocoStudioGUITest/CustomWidget/CustomImageView.cpp \ Classes/UITest/CocoStudioGUITest/CustomWidget/CustomImageViewReader.cpp \ Classes/UITest/CocoStudioGUITest/CustomWidget/CustomParticleWidget.cpp \ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index 888c3e24c7..615f472d4d 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -29,6 +29,20 @@ g_guisTests[] = Director::getInstance()->replaceScene(scene); } }, +#endif +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + { + "WebViewTest", + [](Ref* sender) + { + UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); + sceneManager->setCurrentUISceneId(KWebViewTest); + sceneManager->setMinUISceneId(KWebViewTest); + sceneManager->setMaxUISceneId(KWebViewTest); + Scene* scene = sceneManager->currentUIScene(); + Director::getInstance()->replaceScene(scene); + } + }, #endif { "focus test", diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index 39ac466605..535b85c4ad 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -20,6 +20,7 @@ #include "UIFocusTest/UIFocusTest.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #include "UIVideoPlayerTest/UIVideoPlayerTest.h" +#include "UIWebViewTest/UIWebViewTest.h" #endif #include "UIScale9SpriteTest.h" @@ -94,6 +95,7 @@ static const char* s_testArray[] = "UIFocusTest-ListView", #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) "UIVideoPlayerTest", + "UIWebViewTest", #endif "UIScale9SpriteTest", "UIScale9SpriteHierarchialTest", @@ -328,6 +330,8 @@ Scene *UISceneManager::currentUIScene() #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) case kUIVideoPlayerTest: return VideoPlayerTest::sceneWithTitle(s_testArray[_currentUISceneId]); + case KWebViewTest: + return WebViewTest::sceneWithTitle(s_testArray[_currentUISceneId]); #endif case kUIScale9SpriteTest: return UIScale9SpriteTest::sceneWithTitle(s_testArray[_currentUISceneId]); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h index 4361de611f..6bf7c2c2c9 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h @@ -92,6 +92,7 @@ enum kUIFocusTest_ListView, #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) kUIVideoPlayerTest, + KWebViewTest, #endif kUIScale9SpriteTest, kUIScale9SpriteHierarchialTest, diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp new file mode 100644 index 0000000000..4b643fbd45 --- /dev/null +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** + 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. + ****************************************************************************/ + +#include "UIWebViewTest.h" + +WebViewTest::WebViewTest() +{ + +} + +WebViewTest::~WebViewTest() +{ + +} + +bool WebViewTest::init() +{ + if (UIScene::init()) { + Size winSize = Director::getInstance()->getVisibleSize(); + + + _webView = cocos2d::experimental::ui::WebView::create(); + _webView->setPosition(winSize/2); + _webView->setContentSize(winSize * 0.5); + _webView->loadUrl("http://www.google.com"); + _webView->setScalesPageToFit(true); + + _webView->shouldStartLoading = CC_CALLBACK_2(WebViewTest::onWebViewShouldStartLoading, this); + _webView->didFinishLoading = CC_CALLBACK_2(WebViewTest::onWebViewDidFinishLoading, this); + _webView->didFailLoading = CC_CALLBACK_2(WebViewTest::onWebViewDidFailLoading, this); + + this->addChild(_webView); + + TextField *urlTextField = TextField::create("Input a URL here", "Arial", 20); + urlTextField->setPlaceHolderColor(Color3B::RED); + urlTextField->setPosition(Vec2(winSize/2) + Vec2(-80, _webView->getContentSize().height/2 + + urlTextField->getContentSize().height/2 + 10)); + this->addChild(urlTextField); + + Text *httpLabel = Text::create("http:// ", "Arial", 20); + httpLabel->setTextColor(Color4B::GREEN); + httpLabel->setAnchorPoint(Vec2(1.0,0.5)); + httpLabel->setPosition(urlTextField->getPosition() - Vec2(urlTextField->getContentSize().width/2,0)); + this->addChild(httpLabel); + + + Button *resetBtn = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + resetBtn->setTitleText("Visit URL"); + resetBtn->setPosition(Vec2(winSize/2) + Vec2(50, _webView->getContentSize().height/2 + + resetBtn->getContentSize().height/2 + 10)); + resetBtn->addClickEventListener([=](Ref*){ + _webView->loadUrl(std::string("http://") + urlTextField->getStringValue()); + }); + this->addChild(resetBtn); + + + Button *reloadBtn = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + reloadBtn->setTitleText("Reload"); + reloadBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 + + reloadBtn->getContentSize().width/2 + 10,50 )); + reloadBtn->addClickEventListener([=](Ref*){ + _webView->reload(); + }); + this->addChild(reloadBtn); + + Button *forwardBtn = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + forwardBtn->setTitleText("Forward"); + forwardBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 + + forwardBtn->getContentSize().width/2 + 10,0 )); + forwardBtn->addClickEventListener([=](Ref*){ + _webView->goForward(); + }); + this->addChild(forwardBtn); + + + + Button *backBtn = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + backBtn->setTitleText("Back"); + backBtn->setPosition(Vec2(winSize/2) + Vec2( _webView->getContentSize().width/2 + + backBtn->getContentSize().width/2 + 10,-50 )); + backBtn->addClickEventListener([=](Ref*){ + _webView->goBack(); + }); + this->addChild(backBtn); + + + Button *loadFileBtn = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + loadFileBtn->setTitleText("Load FILE"); + loadFileBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 + + loadFileBtn->getContentSize().width/2 + 10,50 )); + loadFileBtn->addClickEventListener([=](Ref*){ + _webView->loadFile("Test.html"); + }); + this->addChild(loadFileBtn); + + Button *loadHTMLBtn = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + loadHTMLBtn->setTitleText("Load HTML"); + loadHTMLBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 + + loadHTMLBtn->getContentSize().width/2 + 10,0 )); + loadHTMLBtn->addClickEventListener([=](Ref*){ + _webView->loadHTMLString("Hello World","text/html"); + }); + this->addChild(loadHTMLBtn); + + + + + Button *evalJsBtn = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + evalJsBtn->setTitleText("Evaluate JS"); + evalJsBtn->setPosition(Vec2(winSize/2) - Vec2( _webView->getContentSize().width/2 + + evalJsBtn->getContentSize().width/2 + 10,-50 )); + evalJsBtn->addClickEventListener([=](Ref*){ + _webView->evaluateJS("alert(\"hello\")"); + }); + this->addChild(evalJsBtn); + + return true; + } + return false; +} + +bool WebViewTest::onWebViewShouldStartLoading(experimental::ui::WebView *sender, std::string url) +{ + CCLOG("onWebViewShouldStartLoading, url is %s", url.c_str()); + + return true; +} + +void WebViewTest::onWebViewDidFinishLoading(experimental::ui::WebView *sender, std::string url) +{ + CCLOG("onWebViewDidFinishLoading, url is %s", url.c_str()); + +} + +void WebViewTest::onWebViewDidFailLoading(experimental::ui::WebView *sender, std::string url) +{ + CCLOG("onWebViewDidFailLoading, url is %s", url.c_str()); + +} + diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h new file mode 100644 index 0000000000..a7ae59e075 --- /dev/null +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWebViewTest/UIWebViewTest.h @@ -0,0 +1,50 @@ +/**************************************************************************** + 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 __cocos2d_tests__UIWebViewTest__ +#define __cocos2d_tests__UIWebViewTest__ + +#include "../UIScene.h" + +USING_NS_CC; + +class WebViewTest : public UIScene +{ +public: + WebViewTest(); + virtual ~WebViewTest(); + UI_SCENE_CREATE_FUNC(WebViewTest); + + virtual bool init(); + bool onWebViewShouldStartLoading(experimental::ui::WebView *sender, std::string url); + void onWebViewDidFinishLoading(experimental::ui::WebView *sender, std::string url); + void onWebViewDidFailLoading(experimental::ui::WebView *sender, std::string url); + + +private: + cocos2d::experimental::ui::WebView *_webView; + +}; + +#endif /* defined(__cocos2d_tests__UIWebViewTest__) */ diff --git a/tests/cpp-tests/Resources/Test.html b/tests/cpp-tests/Resources/Test.html new file mode 100644 index 0000000000..1e90fb526f --- /dev/null +++ b/tests/cpp-tests/Resources/Test.html @@ -0,0 +1,5 @@ + + + Hello World + + \ No newline at end of file diff --git a/tests/cpp-tests/proj.android/jni/Application.mk b/tests/cpp-tests/proj.android/jni/Application.mk index 362124d303..59808706eb 100644 --- a/tests/cpp-tests/proj.android/jni/Application.mk +++ b/tests/cpp-tests/proj.android/jni/Application.mk @@ -5,8 +5,7 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch APP_LDFLAGS := -latomic -APP_DEBUG := $(strip $(NDK_DEBUG)) -ifeq ($(APP_DEBUG),1) +ifeq ($(NDK_DEBUG),1) APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 APP_OPTIM := debug else diff --git a/tests/game-controller-test/proj.android/jni/Application.mk b/tests/game-controller-test/proj.android/jni/Application.mk index 93c859c1b0..59808706eb 100644 --- a/tests/game-controller-test/proj.android/jni/Application.mk +++ b/tests/game-controller-test/proj.android/jni/Application.mk @@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch APP_LDFLAGS := -latomic -APP_DEBUG := $(strip $(NDK_DEBUG)) -ifeq ($(APP_DEBUG),1) +ifeq ($(NDK_DEBUG),1) APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 APP_OPTIM := debug else APP_CPPFLAGS += -DNDEBUG APP_OPTIM := release -endif \ No newline at end of file +endif diff --git a/tests/lua-empty-test/project/proj.android/jni/Application.mk b/tests/lua-empty-test/project/proj.android/jni/Application.mk index 93c859c1b0..59808706eb 100644 --- a/tests/lua-empty-test/project/proj.android/jni/Application.mk +++ b/tests/lua-empty-test/project/proj.android/jni/Application.mk @@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch APP_LDFLAGS := -latomic -APP_DEBUG := $(strip $(NDK_DEBUG)) -ifeq ($(APP_DEBUG),1) +ifeq ($(NDK_DEBUG),1) APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 APP_OPTIM := debug else APP_CPPFLAGS += -DNDEBUG APP_OPTIM := release -endif \ No newline at end of file +endif diff --git a/tests/lua-game-controller-test/project/proj.android/jni/Application.mk b/tests/lua-game-controller-test/project/proj.android/jni/Application.mk index 362124d303..59808706eb 100644 --- a/tests/lua-game-controller-test/project/proj.android/jni/Application.mk +++ b/tests/lua-game-controller-test/project/proj.android/jni/Application.mk @@ -5,8 +5,7 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch APP_LDFLAGS := -latomic -APP_DEBUG := $(strip $(NDK_DEBUG)) -ifeq ($(APP_DEBUG),1) +ifeq ($(NDK_DEBUG),1) APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 APP_OPTIM := debug else diff --git a/tests/lua-tests/project/proj.android/jni/Application.mk b/tests/lua-tests/project/proj.android/jni/Application.mk index 93c859c1b0..59808706eb 100644 --- a/tests/lua-tests/project/proj.android/jni/Application.mk +++ b/tests/lua-tests/project/proj.android/jni/Application.mk @@ -5,11 +5,10 @@ APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-ch APP_LDFLAGS := -latomic -APP_DEBUG := $(strip $(NDK_DEBUG)) -ifeq ($(APP_DEBUG),1) +ifeq ($(NDK_DEBUG),1) APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 APP_OPTIM := debug else APP_CPPFLAGS += -DNDEBUG APP_OPTIM := release -endif \ No newline at end of file +endif