From 6b579ebe5e5823a8c40db13ca8f69ae5a88ee502 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 20 Nov 2013 11:19:51 +0800 Subject: [PATCH 1/5] Don't deprecate callback functions in Layer. Reason: Callback function should not be deprecated, it will generate lots of warnings. Since 'setTouchEnabled' was deprecated, it will make warnings if developer overrides onTouchXXX and invokes setTouchEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX. --- cocos/2d/CCLayer.h | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/cocos/2d/CCLayer.h b/cocos/2d/CCLayer.h index 3c3bad7269..d5f4ddcce2 100644 --- a/cocos/2d/CCLayer.h +++ b/cocos/2d/CCLayer.h @@ -86,21 +86,25 @@ public: CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesEnded(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);} CC_DEPRECATED_ATTRIBUTE virtual void ccTouchesCancelled(Set *pTouches, Event *pEvent) final {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);} - // Deprecated touch callbacks.There not have add CC_DEPRECATED_ATTRIBUTE because of menu still use these api - virtual bool onTouchBegan(Touch *touch, Event *unused_event); + /* Callback function should not be deprecated, it will generate lots of warnings. + Since 'setTouchEnabled' was deprecated, it will make warnings if developer overrides onTouchXXX and invokes setTouchEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX. + */ + virtual bool onTouchBegan(Touch *touch, Event *unused_event); virtual void onTouchMoved(Touch *touch, Event *unused_event); virtual void onTouchEnded(Touch *touch, Event *unused_event); virtual void onTouchCancelled(Touch *touch, Event *unused_event); - // Deprecated touch callbacks. - CC_DEPRECATED_ATTRIBUTE virtual void onTouchesBegan(const std::vector& touches, Event *unused_event); - CC_DEPRECATED_ATTRIBUTE virtual void onTouchesMoved(const std::vector& touches, Event *unused_event); - CC_DEPRECATED_ATTRIBUTE virtual void onTouchesEnded(const std::vector& touches, Event *unused_event); - CC_DEPRECATED_ATTRIBUTE virtual void onTouchesCancelled(const std::vector&touches, Event *unused_event); + virtual void onTouchesBegan(const std::vector& touches, Event *unused_event); + virtual void onTouchesMoved(const std::vector& touches, Event *unused_event); + virtual void onTouchesEnded(const std::vector& touches, Event *unused_event); + virtual void onTouchesCancelled(const std::vector&touches, Event *unused_event); /** @deprecated Please override onAcceleration */ CC_DEPRECATED_ATTRIBUTE virtual void didAccelerate(Acceleration* accelerationValue) final {}; - CC_DEPRECATED_ATTRIBUTE virtual void onAcceleration(Acceleration* acc, Event* unused_event); + /* Callback function should not be deprecated, it will generate lots of warnings. + Since 'setAccelerometerEnabled' was deprecated, it will make warnings if developer overrides onAcceleration and invokes setAccelerometerEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX. + */ + virtual void onAcceleration(Acceleration* acc, Event* unused_event); /** If isTouchEnabled, this method is called onEnter. Override it to change the way Layer receives touch events. @@ -146,13 +150,16 @@ public: CC_DEPRECATED_ATTRIBUTE virtual void setKeyboardEnabled(bool value); /** Please use onKeyPressed instead. */ - virtual void keyPressed(int keyCode) final {}; + CC_DEPRECATED_ATTRIBUTE virtual void keyPressed(int keyCode) final {}; /** Please use onKeyReleased instead. */ - virtual void keyReleased(int keyCode) final {}; + CC_DEPRECATED_ATTRIBUTE virtual void keyReleased(int keyCode) final {}; - CC_DEPRECATED_ATTRIBUTE virtual void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event); - CC_DEPRECATED_ATTRIBUTE virtual void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event); + /* Callback function should not be deprecated, it will generate lots of warnings. + Since 'setKeyboardEnabled' was deprecated, it will make warnings if developer overrides onKeyXXX and invokes setKeyboardEnabled(true) instead of using EventDispatcher::addEventListenerWithXXX. + */ + virtual void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event); + virtual void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event); CC_DEPRECATED_ATTRIBUTE virtual bool isKeypadEnabled() const final { return _keyboardEnabled; } CC_DEPRECATED_ATTRIBUTE virtual void setKeypadEnabled(bool value); @@ -160,9 +167,6 @@ public: /** @deprecated Please override onKeyReleased and check the keycode of KeyboardEvent::KeyCode::Menu(KEY_BACKSPACE) instead. */ CC_DEPRECATED_ATTRIBUTE virtual void keyBackClicked() final {}; CC_DEPRECATED_ATTRIBUTE virtual void keyMenuClicked() final {}; - // - // Overrides - // protected: bool _touchEnabled; From da8c34d994a26f864238600dd45bdece55129e3f Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 20 Nov 2013 11:20:35 +0800 Subject: [PATCH 2/5] Fix of unsigned / signed mismatch in UIPageView.cpp. --- cocos/gui/UIPageView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/gui/UIPageView.cpp b/cocos/gui/UIPageView.cpp index e23be185e1..c6c51ae381 100644 --- a/cocos/gui/UIPageView.cpp +++ b/cocos/gui/UIPageView.cpp @@ -272,7 +272,7 @@ void UIPageView::updateChildrenSize() } cocos2d::Size selfSize = getSize(); - for (unsigned int i=0; i<_pages->count(); i++) + for (long i=0; i<_pages->count(); i++) { UILayout* page = dynamic_cast(_pages->getObjectAtIndex(i)); page->setSize(selfSize); From 8129e49b842441dec4e3815dfb7d66e7ed0575e8 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 20 Nov 2013 11:21:30 +0800 Subject: [PATCH 3/5] Removing unused 'virtual' keyword in testcpp since we're using EventDispatcher::addEventListenerXXX to register event listener. --- .../Cpp/TestCpp/Classes/AccelerometerTest/AccelerometerTest.h | 2 +- samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.h | 4 ++-- samples/Cpp/TestCpp/Classes/KeypadTest/KeypadTest.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/AccelerometerTest/AccelerometerTest.h b/samples/Cpp/TestCpp/Classes/AccelerometerTest/AccelerometerTest.h index 7e4cc7edf1..7c2734e0de 100644 --- a/samples/Cpp/TestCpp/Classes/AccelerometerTest/AccelerometerTest.h +++ b/samples/Cpp/TestCpp/Classes/AccelerometerTest/AccelerometerTest.h @@ -15,7 +15,7 @@ public: AccelerometerTest(void); ~AccelerometerTest(void); - virtual void onAcceleration(Acceleration* acc, Event* event); + void onAcceleration(Acceleration* acc, Event* event); virtual std::string title(); virtual void onEnter(); diff --git a/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.h b/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.h index e4e0f303e9..6a8a65186e 100644 --- a/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.h +++ b/samples/Cpp/TestCpp/Classes/KeyboardTest/KeyboardTest.h @@ -10,8 +10,8 @@ public: KeyboardTest(); ~KeyboardTest(); - virtual void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event); - virtual void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event); + void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event); + void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event); private: LabelTTF* _label; diff --git a/samples/Cpp/TestCpp/Classes/KeypadTest/KeypadTest.h b/samples/Cpp/TestCpp/Classes/KeypadTest/KeypadTest.h index e525511e4a..c327e1420c 100644 --- a/samples/Cpp/TestCpp/Classes/KeypadTest/KeypadTest.h +++ b/samples/Cpp/TestCpp/Classes/KeypadTest/KeypadTest.h @@ -10,7 +10,7 @@ public: KeypadTest(); ~KeypadTest(); - virtual void onKeyReleased(EventKeyboard::KeyCode keycode, Event* event); + void onKeyReleased(EventKeyboard::KeyCode keycode, Event* event); private: LabelTTF* _label; From 59c2647bd6ad240385d98887999af98a980bf668 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 20 Nov 2013 11:35:04 +0800 Subject: [PATCH 4/5] Prevents warning of invoking ScrollView::setTouchEnabled. Layer::setTouchEnabled should not be a virtual function. --- cocos/2d/CCLayer.h | 4 ++-- extensions/GUI/CCControlExtension/CCControl.cpp | 2 -- extensions/GUI/CCScrollView/CCScrollView.cpp | 8 +++++++- extensions/GUI/CCScrollView/CCScrollView.h | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cocos/2d/CCLayer.h b/cocos/2d/CCLayer.h index d5f4ddcce2..617b27f3d9 100644 --- a/cocos/2d/CCLayer.h +++ b/cocos/2d/CCLayer.h @@ -123,8 +123,8 @@ public: Only the touches of this node will be affected. This "method" is not propagated to it's children. @since v0.8.1 */ - CC_DEPRECATED_ATTRIBUTE virtual bool isTouchEnabled() const; - CC_DEPRECATED_ATTRIBUTE virtual void setTouchEnabled(bool value); + CC_DEPRECATED_ATTRIBUTE bool isTouchEnabled() const; + CC_DEPRECATED_ATTRIBUTE void setTouchEnabled(bool value); CC_DEPRECATED_ATTRIBUTE virtual void setTouchMode(Touch::DispatchMode mode); CC_DEPRECATED_ATTRIBUTE virtual Touch::DispatchMode getTouchMode() const; diff --git a/extensions/GUI/CCControlExtension/CCControl.cpp b/extensions/GUI/CCControlExtension/CCControl.cpp index 15fe7b1a8d..3557c9bb5c 100644 --- a/extensions/GUI/CCControlExtension/CCControl.cpp +++ b/extensions/GUI/CCControlExtension/CCControl.cpp @@ -68,8 +68,6 @@ bool Control::init() { if (Layer::init()) { - //this->setTouchEnabled(true); - //_isTouchEnabled=true; // Initialise instance variables _state=Control::State::NORMAL; setEnabled(true); diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index 8db57d6377..664b868e2e 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -177,10 +177,16 @@ void ScrollView::resume(Object* sender) _container->resume(); } +bool ScrollView::isTouchEnabled() const +{ + return _touchListener != nullptr; +} + void ScrollView::setTouchEnabled(bool enabled) { _eventDispatcher->removeEventListener(_touchListener); - + _touchListener = nullptr; + if (enabled) { _touchListener = EventListenerTouchOneByOne::create(); diff --git a/extensions/GUI/CCScrollView/CCScrollView.h b/extensions/GUI/CCScrollView/CCScrollView.h index bd24efc8fb..fb448c314c 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.h +++ b/extensions/GUI/CCScrollView/CCScrollView.h @@ -167,6 +167,7 @@ public: void resume(Object* sender); void setTouchEnabled(bool enabled); + bool isTouchEnabled() const; bool isDragging() const {return _dragging;} bool isTouchMoved() const { return _touchMoved; } bool isBounceable() const { return _bounceable; } From 43e8a4912de919936e4dd2d8745287964eb9eff1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 20 Nov 2013 12:09:27 +0800 Subject: [PATCH 5/5] Update tools/tolua/cocos2dx.ini, ignore onTouchXXX, onKeyXXX, onAccXXX callback functions to be bound to LUA. --- tools/tolua/cocos2dx.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 3a1d67655c..5cdd7c2781 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -98,7 +98,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS Scheduler::[pause resume unschedule schedule update isTargetPaused], TextureCache::[addPVRTCImage], Timer::[getSelector createWithScriptHandler], - *::[copyWith.* onEnter.* onExit.* ^description$ getObjectType (g|s)etDelegate], + *::[copyWith.* onEnter.* onExit.* ^description$ getObjectType (g|s)etDelegate onTouch.* onAcc.* onKey.* onRegisterTouchListener], FileUtils::[(g|s)etSearchResolutionsOrder$ (g|s)etSearchPaths$], Application::[^application.* ^run$], Camera::[getEyeXYZ getCenterXYZ getUpXYZ],