From 8161d2ad348041545b68483eb101aacb497b1ad9 Mon Sep 17 00:00:00 2001 From: andyque Date: Fri, 17 Oct 2014 11:31:00 +0800 Subject: [PATCH] fix scrollView rotate issue --- build/cocos2d_tests.xcodeproj/project.pbxproj | 52 +++++++++++-------- cocos/ui/UIScrollView.cpp | 4 +- .../UIScrollViewTest/UIScrollViewTest.cpp | 5 +- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 1cdb82ea9f..1dc2263953 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -2621,12 +2621,12 @@ 1D6058910D05DD3D006BFB54 /* cpp-tests Mac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "cpp-tests Mac.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 1F33634D18E37E840074764D /* RefPtrTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefPtrTest.cpp; sourceTree = ""; }; 1F33634E18E37E840074764D /* RefPtrTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefPtrTest.h; sourceTree = ""; }; - 29080D1A191B574B0066F8DF /* UITest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UITest.cpp; path = ../UITest.cpp; sourceTree = ""; }; - 29080D1B191B574B0066F8DF /* UITest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UITest.h; path = ../UITest.h; sourceTree = ""; }; + 29080D1A191B574B0066F8DF /* UITest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UITest.cpp; path = UITest/UITest.cpp; sourceTree = ""; }; + 29080D1B191B574B0066F8DF /* UITest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UITest.h; path = UITest/UITest.h; sourceTree = ""; }; 29080D1F191B595E0066F8DF /* CocosGUIScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocosGUIScene.cpp; sourceTree = ""; }; 29080D20191B595E0066F8DF /* CocosGUIScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocosGUIScene.h; sourceTree = ""; }; - 29080D21191B595E0066F8DF /* CocoStudioGUITest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocoStudioGUITest.cpp; sourceTree = ""; }; - 29080D22191B595E0066F8DF /* CocoStudioGUITest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoStudioGUITest.h; sourceTree = ""; }; + 29080D21191B595E0066F8DF /* CocoStudioGUITest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CocoStudioGUITest.cpp; path = UITest/CocoStudioGUITest/CocoStudioGUITest.cpp; sourceTree = ""; }; + 29080D22191B595E0066F8DF /* CocoStudioGUITest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CocoStudioGUITest.h; path = UITest/CocoStudioGUITest/CocoStudioGUITest.h; sourceTree = ""; }; 29080D23191B595E0066F8DF /* CustomGUIScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CustomGUIScene.cpp; path = ../CustomGUIScene.cpp; sourceTree = ""; }; 29080D24191B595E0066F8DF /* CustomGUIScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomGUIScene.h; path = ../CustomGUIScene.h; sourceTree = ""; }; 29080D27191B595E0066F8DF /* CustomImageTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomImageTest.cpp; sourceTree = ""; }; @@ -6481,14 +6481,6 @@ sourceTree = ""; }; 29080D17191B571F0066F8DF /* UITest */ = { - isa = PBXGroup; - children = ( - 29080D1E191B595E0066F8DF /* CocoStudioGUITest */, - ); - name = UITest; - sourceTree = ""; - }; - 29080D1E191B595E0066F8DF /* CocoStudioGUITest */ = { isa = PBXGroup; children = ( 29080D1A191B574B0066F8DF /* UITest.cpp */, @@ -6499,8 +6491,7 @@ 29FBBBFB196A9ECD00E65826 /* CocostudioParserTest */, 29080D25191B595E0066F8DF /* CustomTest */, ); - name = CocoStudioGUITest; - path = UITest/CocoStudioGUITest; + name = UITest; sourceTree = ""; }; 29080D25191B595E0066F8DF /* CustomTest */ = { @@ -6512,7 +6503,8 @@ 29080D26191B595E0066F8DF /* CustomImageTest */, 29080D29191B595E0066F8DF /* CustomParticleWidgetTest */, ); - path = CustomTest; + name = CustomTest; + path = UITest/CocoStudioGUITest/CustomTest; sourceTree = ""; }; 29080D26191B595E0066F8DF /* CustomImageTest */ = { @@ -6732,6 +6724,24 @@ name = UIWebViewTest; sourceTree = ""; }; + 29AAE28519F0BD02004F5A18 /* UIScale9SpriteTest */ = { + isa = PBXGroup; + children = ( + 295824571987415900F9746D /* UIScale9SpriteTest.cpp */, + 295824581987415900F9746D /* UIScale9SpriteTest.h */, + ); + name = UIScale9SpriteTest; + sourceTree = ""; + }; + 29AAE28619F0BD12004F5A18 /* UIEditBoxTest */ = { + isa = PBXGroup; + children = ( + 292CF01219A1965E00E8E6A0 /* UIEditBoxTest.cpp */, + 292CF01319A1965E00E8E6A0 /* UIEditBoxTest.h */, + ); + name = UIEditBoxTest; + sourceTree = ""; + }; 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { isa = PBXGroup; children = ( @@ -6806,17 +6816,13 @@ 29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */, 29FBBBFD196A9ECD00E65826 /* CocostudioParserJsonTest.h */, ); - path = CocostudioParserTest; + name = CocostudioParserTest; + path = UITest/CocoStudioGUITest/CocostudioParserTest; sourceTree = ""; }; 29FBBC00196A9F0D00E65826 /* UIAndEditorTests */ = { isa = PBXGroup; children = ( - 298D7F6C19AC31C000FF096D /* UIWebViewTest */, - 295824571987415900F9746D /* UIScale9SpriteTest.cpp */, - 295824581987415900F9746D /* UIScale9SpriteTest.h */, - 292CF01219A1965E00E8E6A0 /* UIEditBoxTest.cpp */, - 292CF01319A1965E00E8E6A0 /* UIEditBoxTest.h */, 29080D1F191B595E0066F8DF /* CocosGUIScene.cpp */, 29080D20191B595E0066F8DF /* CocosGUIScene.h */, 29080D37191B595E0066F8DF /* GUIEditorTest.cpp */, @@ -6829,6 +6835,9 @@ 29080D67191B595E0066F8DF /* UISceneManager.h */, 29080D68191B595E0066F8DF /* UISceneManager_Editor.cpp */, 29080D69191B595E0066F8DF /* UISceneManager_Editor.h */, + 29AAE28619F0BD12004F5A18 /* UIEditBoxTest */, + 29AAE28519F0BD02004F5A18 /* UIScale9SpriteTest */, + 298D7F6C19AC31C000FF096D /* UIWebViewTest */, 29080D6A191B595E0066F8DF /* UIScrollViewTest */, 29080D6F191B595E0066F8DF /* UISliderTest */, 29080D74191B595E0066F8DF /* UITextAtlasTest */, @@ -6848,6 +6857,7 @@ 3EA0FB6F191C844400B170C8 /* UIVideoPlayerTest */, ); name = UIAndEditorTests; + path = UITest/CocoStudioGUITest; sourceTree = ""; }; 38FA2E70194AEBE100FF2BE4 /* CocoStudioActionTimelineTest */ = { diff --git a/cocos/ui/UIScrollView.cpp b/cocos/ui/UIScrollView.cpp index f36f76d706..1e8772b91f 100644 --- a/cocos/ui/UIScrollView.cpp +++ b/cocos/ui/UIScrollView.cpp @@ -1470,7 +1470,9 @@ void ScrollView::handlePressLogic(Touch *touch) void ScrollView::handleMoveLogic(Touch *touch) { - Vec2 delta = touch->getLocation() - touch->getPreviousLocation(); + Vec2 touchPositionInNodeSpace = this->convertToNodeSpace(touch->getLocation()); + Vec2 previousTouchPositionInNodeSpace = this->convertToNodeSpace(touch->getPreviousLocation()); + Vec2 delta = touchPositionInNodeSpace - previousTouchPositionInNodeSpace; switch (_direction) { case Direction::VERTICAL: // vertical diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index e73cb4d4e5..89461e1c21 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -39,7 +39,7 @@ bool UIScrollViewTest_Vertical::init() // Create the scrollview by vertical ui::ScrollView* scrollView = ui::ScrollView::create(); - scrollView->setContentSize(Size(280.0f, 150.0f)); + scrollView->setContentSize(Size(280.0f, 100.0f)); Size backgroundSize = background->getContentSize(); scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + (backgroundSize.width - scrollView->getContentSize().width) / 2.0f, @@ -71,7 +71,8 @@ bool UIScrollViewTest_Vertical::init() imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f)); scrollView->addChild(imageView); - + + return true; }