Merge pull request #8783 from andyque/adjustUITestProject

fix scrollView rotate issue
This commit is contained in:
minggo 2014-10-17 14:54:32 +08:00
commit 31664d979a
7 changed files with 139 additions and 28 deletions

View File

@ -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 = "<group>"; };
1F33634E18E37E840074764D /* RefPtrTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefPtrTest.h; sourceTree = "<group>"; };
29080D1A191B574B0066F8DF /* UITest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UITest.cpp; path = ../UITest.cpp; sourceTree = "<group>"; };
29080D1B191B574B0066F8DF /* UITest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UITest.h; path = ../UITest.h; sourceTree = "<group>"; };
29080D1A191B574B0066F8DF /* UITest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UITest.cpp; path = UITest/UITest.cpp; sourceTree = "<group>"; };
29080D1B191B574B0066F8DF /* UITest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UITest.h; path = UITest/UITest.h; sourceTree = "<group>"; };
29080D1F191B595E0066F8DF /* CocosGUIScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocosGUIScene.cpp; sourceTree = "<group>"; };
29080D20191B595E0066F8DF /* CocosGUIScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocosGUIScene.h; sourceTree = "<group>"; };
29080D21191B595E0066F8DF /* CocoStudioGUITest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocoStudioGUITest.cpp; sourceTree = "<group>"; };
29080D22191B595E0066F8DF /* CocoStudioGUITest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoStudioGUITest.h; sourceTree = "<group>"; };
29080D21191B595E0066F8DF /* CocoStudioGUITest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CocoStudioGUITest.cpp; path = UITest/CocoStudioGUITest/CocoStudioGUITest.cpp; sourceTree = "<group>"; };
29080D22191B595E0066F8DF /* CocoStudioGUITest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CocoStudioGUITest.h; path = UITest/CocoStudioGUITest/CocoStudioGUITest.h; sourceTree = "<group>"; };
29080D23191B595E0066F8DF /* CustomGUIScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CustomGUIScene.cpp; path = ../CustomGUIScene.cpp; sourceTree = "<group>"; };
29080D24191B595E0066F8DF /* CustomGUIScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomGUIScene.h; path = ../CustomGUIScene.h; sourceTree = "<group>"; };
29080D27191B595E0066F8DF /* CustomImageTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomImageTest.cpp; sourceTree = "<group>"; };
@ -6481,14 +6481,6 @@
sourceTree = "<group>";
};
29080D17191B571F0066F8DF /* UITest */ = {
isa = PBXGroup;
children = (
29080D1E191B595E0066F8DF /* CocoStudioGUITest */,
);
name = UITest;
sourceTree = "<group>";
};
29080D1E191B595E0066F8DF /* CocoStudioGUITest */ = {
isa = PBXGroup;
children = (
29080D1A191B574B0066F8DF /* UITest.cpp */,
@ -6499,8 +6491,7 @@
29FBBBFB196A9ECD00E65826 /* CocostudioParserTest */,
29080D25191B595E0066F8DF /* CustomTest */,
);
name = CocoStudioGUITest;
path = UITest/CocoStudioGUITest;
name = UITest;
sourceTree = "<group>";
};
29080D25191B595E0066F8DF /* CustomTest */ = {
@ -6512,7 +6503,8 @@
29080D26191B595E0066F8DF /* CustomImageTest */,
29080D29191B595E0066F8DF /* CustomParticleWidgetTest */,
);
path = CustomTest;
name = CustomTest;
path = UITest/CocoStudioGUITest/CustomTest;
sourceTree = "<group>";
};
29080D26191B595E0066F8DF /* CustomImageTest */ = {
@ -6732,6 +6724,24 @@
name = UIWebViewTest;
sourceTree = "<group>";
};
29AAE28519F0BD02004F5A18 /* UIScale9SpriteTest */ = {
isa = PBXGroup;
children = (
295824571987415900F9746D /* UIScale9SpriteTest.cpp */,
295824581987415900F9746D /* UIScale9SpriteTest.h */,
);
name = UIScale9SpriteTest;
sourceTree = "<group>";
};
29AAE28619F0BD12004F5A18 /* UIEditBoxTest */ = {
isa = PBXGroup;
children = (
292CF01219A1965E00E8E6A0 /* UIEditBoxTest.cpp */,
292CF01319A1965E00E8E6A0 /* UIEditBoxTest.h */,
);
name = UIEditBoxTest;
sourceTree = "<group>";
};
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
@ -6806,17 +6816,13 @@
29FBBBFC196A9ECD00E65826 /* CocostudioParserJsonTest.cpp */,
29FBBBFD196A9ECD00E65826 /* CocostudioParserJsonTest.h */,
);
path = CocostudioParserTest;
name = CocostudioParserTest;
path = UITest/CocoStudioGUITest/CocostudioParserTest;
sourceTree = "<group>";
};
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 = "<group>";
};
38FA2E70194AEBE100FF2BE4 /* CocoStudioActionTimelineTest */ = {

View File

@ -1422,10 +1422,12 @@ void ScrollView::endRecordSlidAction()
}
float totalDis = 0.0f;
Vec2 dir;
Vec2 touchEndPositionInNodeSpace = this->convertToNodeSpace(_touchEndPosition);
Vec2 touchBeganPositionInNodeSpace = this->convertToNodeSpace(_touchBeganPosition);
switch (_direction)
{
case Direction::VERTICAL:
totalDis = _touchEndPosition.y - _touchBeganPosition.y;
totalDis = touchEndPositionInNodeSpace.y - touchBeganPositionInNodeSpace.y;
if (totalDis < 0.0f)
{
dir = SCROLLDIR_DOWN;
@ -1436,7 +1438,7 @@ void ScrollView::endRecordSlidAction()
}
break;
case Direction::HORIZONTAL:
totalDis = _touchEndPosition.x - _touchBeganPosition.x;
totalDis = touchEndPositionInNodeSpace.x - touchBeganPositionInNodeSpace.x;
if (totalDis < 0.0f)
{
dir = SCROLLDIR_LEFT;
@ -1448,7 +1450,7 @@ void ScrollView::endRecordSlidAction()
break;
case Direction::BOTH:
{
Vec2 subVector = _touchEndPosition - _touchBeganPosition;
Vec2 subVector = touchEndPositionInNodeSpace - touchBeganPositionInNodeSpace;
totalDis = subVector.getLength();
dir = subVector.getNormalized();
break;
@ -1470,7 +1472,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

View File

@ -211,7 +211,7 @@ g_guisTests[] =
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
sceneManager->setCurrentUISceneId(kUIScrollViewTest_Vertical);
sceneManager->setMinUISceneId(kUIScrollViewTest_Vertical);
sceneManager->setMaxUISceneId(kUIScrollViewNestTest);
sceneManager->setMaxUISceneId(kUIScrollViewRotated);
Scene* scene = sceneManager->currentUIScene();
Director::getInstance()->replaceScene(scene);
}

View File

@ -91,6 +91,7 @@ static const char* s_testArray[] =
"UIScrollViewTest_ScrollToPercentBothDirection",
"UIScrollViewTest_ScrollToPercentBothDirection_Bounce",
"UIScrollViewNestTest",
"UIScrollViewRotated",
"UIPageViewTest",
"UIPageViewButtonTest",
@ -323,6 +324,9 @@ Scene *UISceneManager::currentUIScene()
return UIScrollViewTest_ScrollToPercentBothDirection_Bounce::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIScrollViewNestTest:
return UIScrollViewNestTest::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIScrollViewRotated:
return UIScrollViewRotated::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIPageViewTest:
return UIPageViewTest::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIPageViewButtonTest:

View File

@ -82,6 +82,8 @@ enum
kUIScrollViewTest_ScrollToPercentBothDirection,
kUIScrollViewTest_ScrollToPercentBothDirection_Bounce,
kUIScrollViewNestTest,
kUIScrollViewRotated,
kUIPageViewTest,
kUIPageViewButtonTest,
kUIPageViewCustomScrollThreshold,

View File

@ -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,
@ -72,6 +72,7 @@ bool UIScrollViewTest_Vertical::init()
imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
scrollView->addChild(imageView);
return true;
}
@ -425,3 +426,81 @@ bool UIScrollViewNestTest::init()
return false;
}
// UIScrollViewRotated
UIScrollViewRotated::UIScrollViewRotated()
: _displayValueLabel(nullptr)
{
}
UIScrollViewRotated::~UIScrollViewRotated()
{
}
bool UIScrollViewRotated::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add a label in which the scrollview alert will be displayed
_displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create("ScrollView vertical", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
// Create the scrollview by vertical
ui::ScrollView* scrollView = ui::ScrollView::create();
scrollView->setContentSize(Size(280.0f, 150.0f));
scrollView->setDirection(ui::ScrollView::Direction::BOTH);
Size backgroundSize = background->getContentSize();
scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
(backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - scrollView->getContentSize().height) / 2.0f + 100) );
scrollView->setRotation(45);
_uiLayer->addChild(scrollView);
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
float innerWidth = scrollView->getContentSize().width;
float innerHeight = scrollView->getContentSize().height + imageView->getContentSize().height;
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPosition(Vec2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getContentSize().height / 2.0f));
scrollView->addChild(button);
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button");
titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getContentSize().height));
scrollView->addChild(titleButton);
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true);
button_scale9->setContentSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getContentSize().height));
scrollView->addChild(button_scale9);
imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getContentSize().height / 2.0f));
scrollView->addChild(imageView);
return true;
}
return false;
}

View File

@ -99,4 +99,16 @@ protected:
Text* _displayValueLabel;
};
class UIScrollViewRotated : public UIScene
{
public:
UIScrollViewRotated();
~UIScrollViewRotated();
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIScrollViewRotated)
Text* _displayValueLabel;
};
#endif /* defined(__TestCpp__UIScrollViewTest__) */