Merge pull request #6894 from andyque/refactor5183

refactor Layout, LayoutParameter and LayoutExecutant
This commit is contained in:
minggo 2014-05-26 00:41:04 -05:00
commit 75cb686573
17 changed files with 1232 additions and 955 deletions

View File

@ -944,8 +944,6 @@
2905FA6F18CF08D100240AA3 /* UIRichText.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FA0418CF08D000240AA3 /* UIRichText.cpp */; }; 2905FA6F18CF08D100240AA3 /* UIRichText.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FA0418CF08D000240AA3 /* UIRichText.cpp */; };
2905FA7018CF08D100240AA3 /* UIRichText.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA0518CF08D000240AA3 /* UIRichText.h */; }; 2905FA7018CF08D100240AA3 /* UIRichText.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA0518CF08D000240AA3 /* UIRichText.h */; };
2905FA7118CF08D100240AA3 /* UIRichText.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA0518CF08D000240AA3 /* UIRichText.h */; }; 2905FA7118CF08D100240AA3 /* UIRichText.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA0518CF08D000240AA3 /* UIRichText.h */; };
2905FA7218CF08D100240AA3 /* UIScrollInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA0618CF08D000240AA3 /* UIScrollInterface.h */; };
2905FA7318CF08D100240AA3 /* UIScrollInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA0618CF08D000240AA3 /* UIScrollInterface.h */; };
2905FA7418CF08D100240AA3 /* UIScrollView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FA0718CF08D000240AA3 /* UIScrollView.cpp */; }; 2905FA7418CF08D100240AA3 /* UIScrollView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FA0718CF08D000240AA3 /* UIScrollView.cpp */; };
2905FA7518CF08D100240AA3 /* UIScrollView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FA0718CF08D000240AA3 /* UIScrollView.cpp */; }; 2905FA7518CF08D100240AA3 /* UIScrollView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FA0718CF08D000240AA3 /* UIScrollView.cpp */; };
2905FA7618CF08D100240AA3 /* UIScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA0818CF08D000240AA3 /* UIScrollView.h */; }; 2905FA7618CF08D100240AA3 /* UIScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA0818CF08D000240AA3 /* UIScrollView.h */; };
@ -975,6 +973,12 @@
2905FA8E18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; }; 2905FA8E18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; };
2905FA8F18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; }; 2905FA8F18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; };
2986667F18B1B246000E39CA /* CCTweenFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2986667818B1B079000E39CA /* CCTweenFunction.cpp */; }; 2986667F18B1B246000E39CA /* CCTweenFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2986667818B1B079000E39CA /* CCTweenFunction.cpp */; };
29CB8F4C1929D1BB00C841D6 /* UILayoutExecutant.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29CB8F4A1929D1BB00C841D6 /* UILayoutExecutant.cpp */; };
29CB8F4D1929D1BB00C841D6 /* UILayoutExecutant.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29CB8F4A1929D1BB00C841D6 /* UILayoutExecutant.cpp */; };
29CB8F4E1929D1BB00C841D6 /* UILayoutExecutant.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutExecutant.h */; };
29CB8F4F1929D1BB00C841D6 /* UILayoutExecutant.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutExecutant.h */; };
29CB8F551929D7A900C841D6 /* UIScrollInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F541929D7A900C841D6 /* UIScrollInterface.h */; };
29CB8F561929D7A900C841D6 /* UIScrollInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F541929D7A900C841D6 /* UIScrollInterface.h */; };
2AC795DB1862870F005EC8E1 /* SkeletonBounds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D918628689005EC8E1 /* SkeletonBounds.cpp */; }; 2AC795DB1862870F005EC8E1 /* SkeletonBounds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D918628689005EC8E1 /* SkeletonBounds.cpp */; };
2AC795DC1862870F005EC8E1 /* Event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D51862867D005EC8E1 /* Event.cpp */; }; 2AC795DC1862870F005EC8E1 /* Event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D51862867D005EC8E1 /* Event.cpp */; };
2AC795DD1862870F005EC8E1 /* EventData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D71862867D005EC8E1 /* EventData.cpp */; }; 2AC795DD1862870F005EC8E1 /* EventData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D71862867D005EC8E1 /* EventData.cpp */; };
@ -2235,7 +2239,6 @@
2905FA0318CF08D000240AA3 /* UIPageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIPageView.h; sourceTree = "<group>"; }; 2905FA0318CF08D000240AA3 /* UIPageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIPageView.h; sourceTree = "<group>"; };
2905FA0418CF08D000240AA3 /* UIRichText.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIRichText.cpp; sourceTree = "<group>"; }; 2905FA0418CF08D000240AA3 /* UIRichText.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIRichText.cpp; sourceTree = "<group>"; };
2905FA0518CF08D000240AA3 /* UIRichText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIRichText.h; sourceTree = "<group>"; }; 2905FA0518CF08D000240AA3 /* UIRichText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIRichText.h; sourceTree = "<group>"; };
2905FA0618CF08D000240AA3 /* UIScrollInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScrollInterface.h; sourceTree = "<group>"; };
2905FA0718CF08D000240AA3 /* UIScrollView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIScrollView.cpp; sourceTree = "<group>"; }; 2905FA0718CF08D000240AA3 /* UIScrollView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIScrollView.cpp; sourceTree = "<group>"; };
2905FA0818CF08D000240AA3 /* UIScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScrollView.h; sourceTree = "<group>"; }; 2905FA0818CF08D000240AA3 /* UIScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScrollView.h; sourceTree = "<group>"; };
2905FA0918CF08D000240AA3 /* UISlider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UISlider.cpp; sourceTree = "<group>"; }; 2905FA0918CF08D000240AA3 /* UISlider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UISlider.cpp; sourceTree = "<group>"; };
@ -2253,6 +2256,9 @@
29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = "<group>"; }; 29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = "<group>"; };
2986667818B1B079000E39CA /* CCTweenFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTweenFunction.cpp; sourceTree = "<group>"; }; 2986667818B1B079000E39CA /* CCTweenFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTweenFunction.cpp; sourceTree = "<group>"; };
2986667918B1B079000E39CA /* CCTweenFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTweenFunction.h; sourceTree = "<group>"; }; 2986667918B1B079000E39CA /* CCTweenFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTweenFunction.h; sourceTree = "<group>"; };
29CB8F4A1929D1BB00C841D6 /* UILayoutExecutant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UILayoutExecutant.cpp; sourceTree = "<group>"; };
29CB8F4B1929D1BB00C841D6 /* UILayoutExecutant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILayoutExecutant.h; sourceTree = "<group>"; };
29CB8F541929D7A900C841D6 /* UIScrollInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScrollInterface.h; sourceTree = "<group>"; };
2AC795D318628672005EC8E1 /* BoundingBoxAttachment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoundingBoxAttachment.cpp; sourceTree = "<group>"; }; 2AC795D318628672005EC8E1 /* BoundingBoxAttachment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoundingBoxAttachment.cpp; sourceTree = "<group>"; };
2AC795D418628672005EC8E1 /* BoundingBoxAttachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoundingBoxAttachment.h; sourceTree = "<group>"; }; 2AC795D418628672005EC8E1 /* BoundingBoxAttachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoundingBoxAttachment.h; sourceTree = "<group>"; };
2AC795D51862867D005EC8E1 /* Event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Event.cpp; sourceTree = "<group>"; }; 2AC795D51862867D005EC8E1 /* Event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Event.cpp; sourceTree = "<group>"; };
@ -3902,23 +3908,63 @@
2905F9E618CF08D000240AA3 /* ui */ = { 2905F9E618CF08D000240AA3 /* ui */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */, 29CB8F531929D67D00C841D6 /* widgets */,
3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */, 29CB8F521929D65500C841D6 /* experimental */,
29CB8F511929D64500C841D6 /* base */,
29CB8F501929D63600C841D6 /* layout */,
2905F9E918CF08D000240AA3 /* CocosGUI.cpp */, 2905F9E918CF08D000240AA3 /* CocosGUI.cpp */,
2905F9EA18CF08D000240AA3 /* CocosGUI.h */, 2905F9EA18CF08D000240AA3 /* CocosGUI.h */,
2905F9EB18CF08D000240AA3 /* GUIDefine.h */, );
2905F9F018CF08D000240AA3 /* UIButton.cpp */, name = ui;
2905F9F118CF08D000240AA3 /* UIButton.h */, path = ../cocos/ui;
2905F9F218CF08D000240AA3 /* UICheckBox.cpp */, sourceTree = "<group>";
2905F9F318CF08D000240AA3 /* UICheckBox.h */, };
2905F9F418CF08D000240AA3 /* UIHelper.cpp */, 29CB8F501929D63600C841D6 /* layout */ = {
2905F9F518CF08D000240AA3 /* UIHelper.h */, isa = PBXGroup;
2905F9F618CF08D000240AA3 /* UIImageView.cpp */, children = (
2905F9F718CF08D000240AA3 /* UIImageView.h */, 50E6D32E18E174130051CA34 /* UIHBox.cpp */,
50E6D32F18E174130051CA34 /* UIHBox.h */,
50E6D33018E174130051CA34 /* UIRelativeBox.cpp */,
50E6D33118E174130051CA34 /* UIRelativeBox.h */,
50E6D33218E174130051CA34 /* UIVBox.cpp */,
50E6D33318E174130051CA34 /* UIVBox.h */,
2905F9F818CF08D000240AA3 /* UILayout.cpp */, 2905F9F818CF08D000240AA3 /* UILayout.cpp */,
2905F9F918CF08D000240AA3 /* UILayout.h */, 2905F9F918CF08D000240AA3 /* UILayout.h */,
2905F9FC18CF08D000240AA3 /* UILayoutParameter.cpp */, 2905F9FC18CF08D000240AA3 /* UILayoutParameter.cpp */,
2905F9FD18CF08D000240AA3 /* UILayoutParameter.h */, 2905F9FD18CF08D000240AA3 /* UILayoutParameter.h */,
29CB8F4A1929D1BB00C841D6 /* UILayoutExecutant.cpp */,
29CB8F4B1929D1BB00C841D6 /* UILayoutExecutant.h */,
);
name = layout;
sourceTree = "<group>";
};
29CB8F511929D64500C841D6 /* base */ = {
isa = PBXGroup;
children = (
29080DEB191B82CE0066F8DF /* UIDeprecated.h */,
2905FA1318CF08D100240AA3 /* UIWidget.cpp */,
2905FA1418CF08D100240AA3 /* UIWidget.h */,
50E6D30C18DADB5D0051CA34 /* CCProtectedNode.cpp */,
50E6D30D18DADB5D0051CA34 /* CCProtectedNode.h */,
2905F9F418CF08D000240AA3 /* UIHelper.cpp */,
2905F9F518CF08D000240AA3 /* UIHelper.h */,
2905F9EB18CF08D000240AA3 /* GUIDefine.h */,
);
name = base;
sourceTree = "<group>";
};
29CB8F521929D65500C841D6 /* experimental */ = {
isa = PBXGroup;
children = (
3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */,
3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */,
);
name = experimental;
sourceTree = "<group>";
};
29CB8F531929D67D00C841D6 /* widgets */ = {
isa = PBXGroup;
children = (
2905F9FE18CF08D000240AA3 /* UIListView.cpp */, 2905F9FE18CF08D000240AA3 /* UIListView.cpp */,
2905F9FF18CF08D000240AA3 /* UIListView.h */, 2905F9FF18CF08D000240AA3 /* UIListView.h */,
2905FA0018CF08D000240AA3 /* UILoadingBar.cpp */, 2905FA0018CF08D000240AA3 /* UILoadingBar.cpp */,
@ -3927,9 +3973,9 @@
2905FA0318CF08D000240AA3 /* UIPageView.h */, 2905FA0318CF08D000240AA3 /* UIPageView.h */,
2905FA0418CF08D000240AA3 /* UIRichText.cpp */, 2905FA0418CF08D000240AA3 /* UIRichText.cpp */,
2905FA0518CF08D000240AA3 /* UIRichText.h */, 2905FA0518CF08D000240AA3 /* UIRichText.h */,
2905FA0618CF08D000240AA3 /* UIScrollInterface.h */,
2905FA0718CF08D000240AA3 /* UIScrollView.cpp */, 2905FA0718CF08D000240AA3 /* UIScrollView.cpp */,
2905FA0818CF08D000240AA3 /* UIScrollView.h */, 2905FA0818CF08D000240AA3 /* UIScrollView.h */,
29CB8F541929D7A900C841D6 /* UIScrollInterface.h */,
2905FA0918CF08D000240AA3 /* UISlider.cpp */, 2905FA0918CF08D000240AA3 /* UISlider.cpp */,
2905FA0A18CF08D100240AA3 /* UISlider.h */, 2905FA0A18CF08D100240AA3 /* UISlider.h */,
2905FA0B18CF08D100240AA3 /* UIText.cpp */, 2905FA0B18CF08D100240AA3 /* UIText.cpp */,
@ -3940,20 +3986,14 @@
2905FA1018CF08D100240AA3 /* UITextBMFont.h */, 2905FA1018CF08D100240AA3 /* UITextBMFont.h */,
2905FA1118CF08D100240AA3 /* UITextField.cpp */, 2905FA1118CF08D100240AA3 /* UITextField.cpp */,
2905FA1218CF08D100240AA3 /* UITextField.h */, 2905FA1218CF08D100240AA3 /* UITextField.h */,
2905FA1318CF08D100240AA3 /* UIWidget.cpp */, 2905F9F018CF08D000240AA3 /* UIButton.cpp */,
2905FA1418CF08D100240AA3 /* UIWidget.h */, 2905F9F118CF08D000240AA3 /* UIButton.h */,
50E6D30C18DADB5D0051CA34 /* CCProtectedNode.cpp */, 2905F9F218CF08D000240AA3 /* UICheckBox.cpp */,
50E6D30D18DADB5D0051CA34 /* CCProtectedNode.h */, 2905F9F318CF08D000240AA3 /* UICheckBox.h */,
50E6D32E18E174130051CA34 /* UIHBox.cpp */, 2905F9F618CF08D000240AA3 /* UIImageView.cpp */,
50E6D32F18E174130051CA34 /* UIHBox.h */, 2905F9F718CF08D000240AA3 /* UIImageView.h */,
50E6D33018E174130051CA34 /* UIRelativeBox.cpp */,
50E6D33118E174130051CA34 /* UIRelativeBox.h */,
50E6D33218E174130051CA34 /* UIVBox.cpp */,
50E6D33318E174130051CA34 /* UIVBox.h */,
29080DEB191B82CE0066F8DF /* UIDeprecated.h */,
); );
name = ui; name = widgets;
path = ../cocos/ui;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
37936A361869B76800E974DD /* internal */ = { 37936A361869B76800E974DD /* internal */ = {
@ -4806,6 +4846,7 @@
5034CA39191D591100CE6051 /* ccShader_PositionColorLengthTexture.frag in Headers */, 5034CA39191D591100CE6051 /* ccShader_PositionColorLengthTexture.frag in Headers */,
2AC795DF18628723005EC8E1 /* SkeletonBounds.h in Headers */, 2AC795DF18628723005EC8E1 /* SkeletonBounds.h in Headers */,
50ABBE891925AB6F00A911A9 /* CCMap.h in Headers */, 50ABBE891925AB6F00A911A9 /* CCMap.h in Headers */,
29CB8F4E1929D1BB00C841D6 /* UILayoutExecutant.h in Headers */,
2AC795E018628723005EC8E1 /* Event.h in Headers */, 2AC795E018628723005EC8E1 /* Event.h in Headers */,
2AC795E118628723005EC8E1 /* EventData.h in Headers */, 2AC795E118628723005EC8E1 /* EventData.h in Headers */,
50E6D33618E174130051CA34 /* UIHBox.h in Headers */, 50E6D33618E174130051CA34 /* UIHBox.h in Headers */,
@ -5010,7 +5051,6 @@
1AD71DED180E26E600808F54 /* CCMenuLoader.h in Headers */, 1AD71DED180E26E600808F54 /* CCMenuLoader.h in Headers */,
50ABBE8F1925AB6F00A911A9 /* CCPlatformConfig.h in Headers */, 50ABBE8F1925AB6F00A911A9 /* CCPlatformConfig.h in Headers */,
1AD71DF1180E26E600808F54 /* CCNode+CCBRelativePositioning.h in Headers */, 1AD71DF1180E26E600808F54 /* CCNode+CCBRelativePositioning.h in Headers */,
2905FA7218CF08D100240AA3 /* UIScrollInterface.h in Headers */,
1AD71DF5180E26E600808F54 /* CCNodeLoader.h in Headers */, 1AD71DF5180E26E600808F54 /* CCNodeLoader.h in Headers */,
1AD71DF9180E26E600808F54 /* CCNodeLoaderLibrary.h in Headers */, 1AD71DF9180E26E600808F54 /* CCNodeLoaderLibrary.h in Headers */,
50ABBE291925AB6F00A911A9 /* CCAutoreleasePool.h in Headers */, 50ABBE291925AB6F00A911A9 /* CCAutoreleasePool.h in Headers */,
@ -5075,6 +5115,7 @@
50ABBD9D1925AB4100A911A9 /* ccGLStateCache.h in Headers */, 50ABBD9D1925AB4100A911A9 /* ccGLStateCache.h in Headers */,
50ABBEB91925AB6F00A911A9 /* ccUTF8.h in Headers */, 50ABBEB91925AB6F00A911A9 /* ccUTF8.h in Headers */,
1AAF536E180E3374000584C8 /* HttpRequest.h in Headers */, 1AAF536E180E3374000584C8 /* HttpRequest.h in Headers */,
29CB8F551929D7A900C841D6 /* UIScrollInterface.h in Headers */,
1AAF5370180E3374000584C8 /* HttpResponse.h in Headers */, 1AAF5370180E3374000584C8 /* HttpResponse.h in Headers */,
50ABBE671925AB6F00A911A9 /* CCEventListenerCustom.h in Headers */, 50ABBE671925AB6F00A911A9 /* CCEventListenerCustom.h in Headers */,
1AAF5374180E3374000584C8 /* SocketIO.h in Headers */, 1AAF5374180E3374000584C8 /* SocketIO.h in Headers */,
@ -5357,7 +5398,6 @@
503DD8E41926736A00CD74DD /* CCDirectorCaller.h in Headers */, 503DD8E41926736A00CD74DD /* CCDirectorCaller.h in Headers */,
50ABBD8A1925AB4100A911A9 /* CCCustomCommand.h in Headers */, 50ABBD8A1925AB4100A911A9 /* CCCustomCommand.h in Headers */,
2905FA6D18CF08D100240AA3 /* UIPageView.h in Headers */, 2905FA6D18CF08D100240AA3 /* UIPageView.h in Headers */,
2905FA7318CF08D100240AA3 /* UIScrollInterface.h in Headers */,
50ABBE881925AB6F00A911A9 /* ccMacros.h in Headers */, 50ABBE881925AB6F00A911A9 /* ccMacros.h in Headers */,
50ABC0101926664800A911A9 /* CCFileUtils.h in Headers */, 50ABC0101926664800A911A9 /* CCFileUtils.h in Headers */,
2905FA4318CF08D100240AA3 /* CocosGUI.h in Headers */, 2905FA4318CF08D100240AA3 /* CocosGUI.h in Headers */,
@ -5528,6 +5568,7 @@
50ABBD921925AB4100A911A9 /* CCGLProgramCache.h in Headers */, 50ABBD921925AB4100A911A9 /* CCGLProgramCache.h in Headers */,
1AD71E0E180E26E600808F54 /* CocosBuilder.h in Headers */, 1AD71E0E180E26E600808F54 /* CocosBuilder.h in Headers */,
B29594C91926D61F003EEF37 /* CCObjLoader.h in Headers */, B29594C91926D61F003EEF37 /* CCObjLoader.h in Headers */,
29CB8F561929D7A900C841D6 /* UIScrollInterface.h in Headers */,
1AD71E98180E26E600808F54 /* Animation.h in Headers */, 1AD71E98180E26E600808F54 /* Animation.h in Headers */,
1AD71E9C180E26E600808F54 /* AnimationState.h in Headers */, 1AD71E9C180E26E600808F54 /* AnimationState.h in Headers */,
50ABBE961925AB6F00A911A9 /* CCProfiling.h in Headers */, 50ABBE961925AB6F00A911A9 /* CCProfiling.h in Headers */,
@ -5620,6 +5661,7 @@
1A8C59E2180E930E00EF57C3 /* CCInputDelegate.h in Headers */, 1A8C59E2180E930E00EF57C3 /* CCInputDelegate.h in Headers */,
503DD8EA1926736A00CD74DD /* CCESRenderer.h in Headers */, 503DD8EA1926736A00CD74DD /* CCESRenderer.h in Headers */,
1A8C59E6180E930E00EF57C3 /* CCProcessBase.h in Headers */, 1A8C59E6180E930E00EF57C3 /* CCProcessBase.h in Headers */,
29CB8F4F1929D1BB00C841D6 /* UILayoutExecutant.h in Headers */,
50ABBE581925AB6F00A911A9 /* CCEventFocus.h in Headers */, 50ABBE581925AB6F00A911A9 /* CCEventFocus.h in Headers */,
50ABC00A1926664800A911A9 /* CCCommon.h in Headers */, 50ABC00A1926664800A911A9 /* CCCommon.h in Headers */,
2905FA5918CF08D100240AA3 /* UILayout.h in Headers */, 2905FA5918CF08D100240AA3 /* UILayout.h in Headers */,
@ -6200,6 +6242,7 @@
2905FA4018CF08D100240AA3 /* CocosGUI.cpp in Sources */, 2905FA4018CF08D100240AA3 /* CocosGUI.cpp in Sources */,
1AD71EC1180E26E600808F54 /* extension.cpp in Sources */, 1AD71EC1180E26E600808F54 /* extension.cpp in Sources */,
50ABBE511925AB6F00A911A9 /* CCEventDispatcher.cpp in Sources */, 50ABBE511925AB6F00A911A9 /* CCEventDispatcher.cpp in Sources */,
29CB8F4C1929D1BB00C841D6 /* UILayoutExecutant.cpp in Sources */,
50ABC0051926664800A911A9 /* CCThread.mm in Sources */, 50ABC0051926664800A911A9 /* CCThread.mm in Sources */,
1AD71EC5180E26E600808F54 /* Json.cpp in Sources */, 1AD71EC5180E26E600808F54 /* Json.cpp in Sources */,
50E6D33C18E174130051CA34 /* UIVBox.cpp in Sources */, 50E6D33C18E174130051CA34 /* UIVBox.cpp in Sources */,
@ -6678,6 +6721,7 @@
50FCEBAC18C72017004AD434 /* PageViewReader.cpp in Sources */, 50FCEBAC18C72017004AD434 /* PageViewReader.cpp in Sources */,
1A8C598C180E930E00EF57C3 /* CCActionFrame.cpp in Sources */, 1A8C598C180E930E00EF57C3 /* CCActionFrame.cpp in Sources */,
1A8C5990180E930E00EF57C3 /* CCActionFrameEasing.cpp in Sources */, 1A8C5990180E930E00EF57C3 /* CCActionFrameEasing.cpp in Sources */,
29CB8F4D1929D1BB00C841D6 /* UILayoutExecutant.cpp in Sources */,
50FCEBA418C72017004AD434 /* ListViewReader.cpp in Sources */, 50FCEBA418C72017004AD434 /* ListViewReader.cpp in Sources */,
1A8C5994180E930E00EF57C3 /* CCActionManagerEx.cpp in Sources */, 1A8C5994180E930E00EF57C3 /* CCActionManagerEx.cpp in Sources */,
50ABBEBC1925AB6F00A911A9 /* ccUtils.cpp in Sources */, 50ABBEBC1925AB6F00A911A9 /* ccUtils.cpp in Sources */,

View File

@ -9,6 +9,7 @@ LOCAL_SRC_FILES := \
UIWidget.cpp \ UIWidget.cpp \
UILayout.cpp \ UILayout.cpp \
UILayoutParameter.cpp \ UILayoutParameter.cpp \
UILayoutExecutant.cpp \
CocosGUI.cpp \ CocosGUI.cpp \
UIHelper.cpp \ UIHelper.cpp \
UIListView.cpp \ UIListView.cpp \

View File

@ -8,6 +8,7 @@ set(COCOS_UI_SRC
ui/UIImageView.cpp ui/UIImageView.cpp
ui/UILayout.cpp ui/UILayout.cpp
ui/UILayoutParameter.cpp ui/UILayoutParameter.cpp
ui/UILayoutExecutant.cpp
ui/UIListView.cpp ui/UIListView.cpp
ui/UILoadingBar.cpp ui/UILoadingBar.cpp
ui/UIPageView.cpp ui/UIPageView.cpp

View File

@ -32,532 +32,12 @@ THE SOFTWARE.
#include "renderer/CCRenderer.h" #include "renderer/CCRenderer.h"
#include "renderer/CCGroupCommand.h" #include "renderer/CCGroupCommand.h"
#include "renderer/CCCustomCommand.h" #include "renderer/CCCustomCommand.h"
#include "ui/UILayoutExecutant.h"
NS_CC_BEGIN NS_CC_BEGIN
namespace ui { namespace ui {
class LayoutExecutant : public Ref
{
public:
LayoutExecutant(){};
virtual ~LayoutExecutant(){};
static LayoutExecutant* create();
virtual void doLayout(const Size& layoutSize, Vector<Node*> container){};
};
class LinearVerticalLayoutExecutant : public LayoutExecutant
{
public:
LinearVerticalLayoutExecutant(){};
virtual ~LinearVerticalLayoutExecutant(){};
static LinearVerticalLayoutExecutant* create();
virtual void doLayout(const Size& layoutSize, Vector<Node*> container);
};
class LinearHorizontalLayoutExecutant : public LayoutExecutant
{
public:
LinearHorizontalLayoutExecutant(){};
virtual ~LinearHorizontalLayoutExecutant(){};
static LinearHorizontalLayoutExecutant* create();
virtual void doLayout(const Size& layoutSize, Vector<Node*> container);
};
class RelativeLayoutExecutant : public LayoutExecutant
{
public:
RelativeLayoutExecutant(){};
virtual ~RelativeLayoutExecutant(){};
static RelativeLayoutExecutant* create();
virtual void doLayout(const Size& layoutSize, Vector<Node*> container);
};
LayoutExecutant* LayoutExecutant::create()
{
LayoutExecutant* exe = new LayoutExecutant();
if (exe)
{
exe->autorelease();
return exe;
}
CC_SAFE_DELETE(exe);
return nullptr;
}
LinearVerticalLayoutExecutant* LinearVerticalLayoutExecutant::create()
{
LinearVerticalLayoutExecutant* exe = new LinearVerticalLayoutExecutant();
if (exe)
{
exe->autorelease();
return exe;
}
CC_SAFE_DELETE(exe);
return nullptr;
}
LinearHorizontalLayoutExecutant* LinearHorizontalLayoutExecutant::create()
{
LinearHorizontalLayoutExecutant* exe = new LinearHorizontalLayoutExecutant();
if (exe)
{
exe->autorelease();
return exe;
}
CC_SAFE_DELETE(exe);
return nullptr;
}
RelativeLayoutExecutant* RelativeLayoutExecutant::create()
{
RelativeLayoutExecutant* exe = new RelativeLayoutExecutant();
if (exe)
{
exe->autorelease();
return exe;
}
CC_SAFE_DELETE(exe);
return nullptr;
}
void LinearVerticalLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Vector<cocos2d::Node *> container)
{
float topBoundary = layoutSize.height;
for (auto& subWidget : container)
{
Widget* child = dynamic_cast<Widget*>(subWidget);
if (child)
{
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR));
if (layoutParameter)
{
LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity();
Vec2 ap = child->getAnchorPoint();
Size cs = child->getSize();
float finalPosX = ap.x * cs.width;
float finalPosY = topBoundary - ((1.0f-ap.y) * cs.height);
switch (childGravity)
{
case LinearLayoutParameter::LinearGravity::NONE:
case LinearLayoutParameter::LinearGravity::LEFT:
break;
case LinearLayoutParameter::LinearGravity::RIGHT:
finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);
break;
case LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL:
finalPosX = layoutSize.width / 2.0f - cs.width * (0.5f-ap.x);
break;
default:
break;
}
Margin mg = layoutParameter->getMargin();
finalPosX += mg.left;
finalPosY -= mg.top;
child->setPosition(Vec2(finalPosX, finalPosY));
topBoundary = child->getBottomInParent() - mg.bottom;
}
}
}
}
void LinearHorizontalLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Vector<cocos2d::Node *> container)
{
float leftBoundary = 0.0f;
for (auto& subWidget : container)
{
Widget* child = dynamic_cast<Widget*>(subWidget);
if (child)
{
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR));
if (layoutParameter)
{
LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity();
Vec2 ap = child->getAnchorPoint();
Size cs = child->getSize();
float finalPosX = leftBoundary + (ap.x * cs.width);
float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height;
switch (childGravity)
{
case LinearLayoutParameter::LinearGravity::NONE:
case LinearLayoutParameter::LinearGravity::TOP:
break;
case LinearLayoutParameter::LinearGravity::BOTTOM:
finalPosY = ap.y * cs.height;
break;
case LinearLayoutParameter::LinearGravity::CENTER_VERTICAL:
finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y);
break;
default:
break;
}
Margin mg = layoutParameter->getMargin();
finalPosX += mg.left;
finalPosY -= mg.top;
child->setPosition(Vec2(finalPosX, finalPosY));
leftBoundary = child->getRightInParent() + mg.right;
}
}
}
}
void RelativeLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Vector<cocos2d::Node *> container)
{
ssize_t unlayoutChildCount = 0;
Vector<Widget*> widgetChildren;
for (auto& subWidget : container)
{
Widget* child = dynamic_cast<Widget*>(subWidget);
if (child)
{
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE));
layoutParameter->_put = false;
unlayoutChildCount++;
widgetChildren.pushBack(child);
}
}
while (unlayoutChildCount > 0)
{
for (auto& subWidget : widgetChildren)
{
Widget* child = static_cast<Widget*>(subWidget);
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE));
if (layoutParameter)
{
if (layoutParameter->_put)
{
continue;
}
Vec2 ap = child->getAnchorPoint();
Size cs = child->getSize();
RelativeLayoutParameter::RelativeAlign align = layoutParameter->getAlign();
const std::string relativeName = layoutParameter->getRelativeToWidgetName();
Widget* relativeWidget = nullptr;
RelativeLayoutParameter* relativeWidgetLP = nullptr;
float finalPosX = 0.0f;
float finalPosY = 0.0f;
if (!relativeName.empty())
{
for (auto& sWidget : widgetChildren)
{
if (sWidget)
{
RelativeLayoutParameter* rlayoutParameter = dynamic_cast<RelativeLayoutParameter*>(sWidget->getLayoutParameter(LayoutParameter::Type::RELATIVE));
if (rlayoutParameter && rlayoutParameter->getRelativeName() == relativeName)
{
relativeWidget = sWidget;
relativeWidgetLP = rlayoutParameter;
break;
}
}
}
}
switch (align)
{
case RelativeLayoutParameter::RelativeAlign::NONE:
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_LEFT:
finalPosX = ap.x * cs.width;
finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height);
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL:
finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);
finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height);
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT:
finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);
finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height);
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL:
finalPosX = ap.x * cs.width;
finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);
break;
case RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT:
finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);
finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_CENTER_VERTICAL:
finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);
finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_BOTTOM:
finalPosX = ap.x * cs.width;
finalPosY = ap.y * cs.height;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL:
finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);
finalPosY = ap.y * cs.height;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_BOTTOM:
finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);
finalPosY = ap.y * cs.height;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_LEFTALIGN:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
float locationBottom = relativeWidget->getTopInParent();
float locationLeft = relativeWidget->getLeftInParent();
finalPosY = locationBottom + ap.y * cs.height;
finalPosX = locationLeft + ap.x * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_CENTER:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
Size rbs = relativeWidget->getSize();
float locationBottom = relativeWidget->getTopInParent();
finalPosY = locationBottom + ap.y * cs.height;
finalPosX = relativeWidget->getLeftInParent() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_RIGHTALIGN:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
float locationBottom = relativeWidget->getTopInParent();
float locationRight = relativeWidget->getRightInParent();
finalPosY = locationBottom + ap.y * cs.height;
finalPosX = locationRight - (1.0f - ap.x) * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_TOPALIGN:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
float locationTop = relativeWidget->getTopInParent();
float locationRight = relativeWidget->getLeftInParent();
finalPosY = locationTop - (1.0f - ap.y) * cs.height;
finalPosX = locationRight - (1.0f - ap.x) * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_CENTER:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
Size rbs = relativeWidget->getSize();
float locationRight = relativeWidget->getLeftInParent();
finalPosX = locationRight - (1.0f - ap.x) * cs.width;
finalPosY = relativeWidget->getBottomInParent() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_BOTTOMALIGN:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
float locationBottom = relativeWidget->getBottomInParent();
float locationRight = relativeWidget->getLeftInParent();
finalPosY = locationBottom + ap.y * cs.height;
finalPosX = locationRight - (1.0f - ap.x) * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_TOPALIGN:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
float locationTop = relativeWidget->getTopInParent();
float locationLeft = relativeWidget->getRightInParent();
finalPosY = locationTop - (1.0f - ap.y) * cs.height;
finalPosX = locationLeft + ap.x * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_CENTER:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
Size rbs = relativeWidget->getSize();
float locationLeft = relativeWidget->getRightInParent();
finalPosX = locationLeft + ap.x * cs.width;
finalPosY = relativeWidget->getBottomInParent() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_BOTTOMALIGN:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
float locationBottom = relativeWidget->getBottomInParent();
float locationLeft = relativeWidget->getRightInParent();
finalPosY = locationBottom + ap.y * cs.height;
finalPosX = locationLeft + ap.x * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_LEFTALIGN:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
float locationTop = relativeWidget->getBottomInParent();
float locationLeft = relativeWidget->getLeftInParent();
finalPosY = locationTop - (1.0f - ap.y) * cs.height;
finalPosX = locationLeft + ap.x * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_CENTER:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
Size rbs = relativeWidget->getSize();
float locationTop = relativeWidget->getBottomInParent();
finalPosY = locationTop - (1.0f - ap.y) * cs.height;
finalPosX = relativeWidget->getLeftInParent() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_RIGHTALIGN:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
float locationTop = relativeWidget->getBottomInParent();
float locationRight = relativeWidget->getRightInParent();
finalPosY = locationTop - (1.0f - ap.y) * cs.height;
finalPosX = locationRight - (1.0f - ap.x) * cs.width;
}
break;
default:
break;
}
Margin relativeWidgetMargin;
Margin mg = layoutParameter->getMargin();
if (relativeWidgetLP)
{
relativeWidgetMargin = relativeWidgetLP->getMargin();
}
//handle margin
switch (align)
{
case RelativeLayoutParameter::RelativeAlign::NONE:
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_LEFT:
finalPosX += mg.left;
finalPosY -= mg.top;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL:
finalPosY -= mg.top;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT:
finalPosX -= mg.right;
finalPosY -= mg.top;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL:
finalPosX += mg.left;
break;
case RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT:
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_CENTER_VERTICAL:
finalPosX -= mg.right;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_BOTTOM:
finalPosX += mg.left;
finalPosY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL:
finalPosY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_BOTTOM:
finalPosX -= mg.right;
finalPosY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_LEFTALIGN:
finalPosY += mg.bottom;
finalPosX += mg.left;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_RIGHTALIGN:
finalPosY += mg.bottom;
finalPosX -= mg.right;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_CENTER:
finalPosY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_TOPALIGN:
finalPosX -= mg.right;
finalPosY -= mg.top;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_BOTTOMALIGN:
finalPosX -= mg.right;
finalPosY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_CENTER:
finalPosX -= mg.right;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_TOPALIGN:
finalPosX += mg.left;
finalPosY -= mg.top;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_BOTTOMALIGN:
finalPosX += mg.left;
finalPosY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_CENTER:
finalPosX += mg.left;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_LEFTALIGN:
finalPosY -= mg.top;
finalPosX += mg.left;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_RIGHTALIGN:
finalPosY -= mg.top;
finalPosX -= mg.right;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_CENTER:
finalPosY -= mg.top;
break;
default:
break;
}
child->setPosition(Vec2(finalPosX, finalPosY));
layoutParameter->_put = true;
unlayoutChildCount--;
}
}
}
widgetChildren.clear();
}
static const int BACKGROUNDIMAGE_Z = (-1); static const int BACKGROUNDIMAGE_Z = (-1);
static const int BCAKGROUNDCOLORRENDERER_Z = (-2); static const int BCAKGROUNDCOLORRENDERER_Z = (-2);
@ -604,7 +84,6 @@ _currentAlphaTestFunc(GL_ALWAYS),
_currentAlphaTestRef(1), _currentAlphaTestRef(1),
_backGroundImageColor(Color3B::WHITE), _backGroundImageColor(Color3B::WHITE),
_backGroundImageOpacity(255), _backGroundImageOpacity(255),
_curLayoutExecutant(nullptr),
_passFocusToChild(true), _passFocusToChild(true),
_loopFocus(false) _loopFocus(false)
{ {
@ -615,7 +94,6 @@ _loopFocus(false)
Layout::~Layout() Layout::~Layout()
{ {
CC_SAFE_RELEASE(_clippingStencil); CC_SAFE_RELEASE(_clippingStencil);
CC_SAFE_RELEASE(_curLayoutExecutant);
} }
void Layout::onEnter() void Layout::onEnter()
@ -1180,7 +658,7 @@ void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
case Type::HORIZONTAL: case Type::HORIZONTAL:
case Type::VERTICAL: case Type::VERTICAL:
{ {
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR)); LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
if (!layoutParameter) if (!layoutParameter)
{ {
child->setLayoutParameter(LinearLayoutParameter::create()); child->setLayoutParameter(LinearLayoutParameter::create());
@ -1189,7 +667,7 @@ void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
} }
case Type::RELATIVE: case Type::RELATIVE:
{ {
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE)); RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter());
if (!layoutParameter) if (!layoutParameter)
{ {
child->setLayoutParameter(RelativeLayoutParameter::create()); child->setLayoutParameter(RelativeLayoutParameter::create());
@ -1427,9 +905,7 @@ const Size& Layout::getBackGroundImageTextureSize() const
void Layout::setLayoutType(Type type) void Layout::setLayoutType(Type type)
{ {
_layoutType = type; _layoutType = type;
CC_SAFE_RELEASE_NULL(_curLayoutExecutant);
_curLayoutExecutant = createCurrentLayoutExecutant();
CC_SAFE_RETAIN(_curLayoutExecutant);
for (auto& child : _children) for (auto& child : _children)
{ {
Widget* widgetChild = dynamic_cast<Widget*>(child); Widget* widgetChild = dynamic_cast<Widget*>(child);
@ -1441,7 +917,29 @@ void Layout::setLayoutType(Type type)
_doLayoutDirty = true; _doLayoutDirty = true;
} }
LayoutExecutant* Layout::createCurrentLayoutExecutant()
Layout::Type Layout::getLayoutType() const
{
return _layoutType;
}
void Layout::requestDoLayout()
{
_doLayoutDirty = true;
}
const Size Layout::getLayoutContentSize()
{
return this->getSize();
}
const Vector<Node*>& Layout::getLayoutElements()
{
return this->getChildren();
}
LayoutExecutant* Layout::createLayoutExecutant()
{ {
LayoutExecutant* exe = nullptr; LayoutExecutant* exe = nullptr;
switch (_layoutType) switch (_layoutType)
@ -1459,16 +957,7 @@ LayoutExecutant* Layout::createCurrentLayoutExecutant()
break; break;
} }
return exe; return exe;
}
Layout::Type Layout::getLayoutType() const
{
return _layoutType;
}
void Layout::requestDoLayout()
{
_doLayoutDirty = true;
} }
void Layout::doLayout() void Layout::doLayout()
@ -1477,10 +966,13 @@ void Layout::doLayout()
{ {
return; return;
} }
if (_curLayoutExecutant) LayoutExecutant* executant = this->createLayoutExecutant();
if (executant)
{ {
_curLayoutExecutant->doLayout(getSize(), getChildren()); executant->doLayout(this);
} }
_doLayoutDirty = false; _doLayoutDirty = false;
} }
@ -1541,7 +1033,7 @@ bool Layout::isPassFocusToChild()
return _passFocusToChild; return _passFocusToChild;
} }
Size Layout::getLayoutContentSize()const Size Layout::getLayoutAccumulatedSize()const
{ {
const auto& children = this->getChildren(); const auto& children = this->getChildren();
Size layoutSize = Size::ZERO; Size layoutSize = Size::ZERO;
@ -1551,7 +1043,7 @@ Size Layout::getLayoutContentSize()const
Layout *layout = dynamic_cast<Layout*>(widget); Layout *layout = dynamic_cast<Layout*>(widget);
if (nullptr != layout) if (nullptr != layout)
{ {
layoutSize = layoutSize + layout->getLayoutContentSize(); layoutSize = layoutSize + layout->getLayoutAccumulatedSize();
} }
else else
{ {
@ -1559,7 +1051,7 @@ Size Layout::getLayoutContentSize()const
if (w) if (w)
{ {
widgetCount++; widgetCount++;
Margin m = w->getLayoutParameter(LayoutParameter::Type::LINEAR)->getMargin(); Margin m = w->getLayoutParameter()->getMargin();
layoutSize = layoutSize + w->getSize() + Size(m.right + m.left, m.top + m.bottom) * 0.5; layoutSize = layoutSize + w->getSize() + Size(m.right + m.left, m.top + m.bottom) * 0.5;
} }
} }
@ -1582,7 +1074,7 @@ Vec2 Layout::getWorldCenterPoint(Widget* widget)
{ {
Layout *layout = dynamic_cast<Layout*>(widget); Layout *layout = dynamic_cast<Layout*>(widget);
//FIXEDME: we don't need to calculate the content size of layout anymore //FIXEDME: we don't need to calculate the content size of layout anymore
Size widgetSize = layout ? layout->getLayoutContentSize() : widget->getSize(); Size widgetSize = layout ? layout->getLayoutAccumulatedSize() : widget->getSize();
// CCLOG("contnet size : width = %f, height = %f", widgetSize.width, widgetSize.height); // CCLOG("contnet size : width = %f, height = %f", widgetSize.width, widgetSize.height);
return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2)); return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2));
} }

View File

@ -31,13 +31,26 @@ NS_CC_BEGIN
namespace ui { namespace ui {
class LayoutExecutant;
class LayoutProtocol
{
public:
LayoutProtocol(){}
virtual ~LayoutProtocol(){}
virtual LayoutExecutant* createLayoutExecutant() = 0;
virtual const Size getLayoutContentSize() = 0;
virtual const Vector<Node*>& getLayoutElements() = 0;
virtual void doLayout() = 0;
};
/** /**
* @js NA * @js NA
* @lua NA * @lua NA
*/ */
class LayoutExecutant;
class Layout : public Widget class Layout : public Widget, public LayoutProtocol
{ {
DECLARE_CLASS_GUI_INFO DECLARE_CLASS_GUI_INFO
@ -313,7 +326,11 @@ protected:
void setStencilClippingSize(const Size& size); void setStencilClippingSize(const Size& size);
const Rect& getClippingRect(); const Rect& getClippingRect();
virtual void doLayout();
virtual void doLayout()override;
virtual LayoutExecutant* createLayoutExecutant()override;
virtual const Size getLayoutContentSize()override;
virtual const Vector<Node*>& getLayoutElements() override;
//clipping //clipping
void onBeforeVisitStencil(); void onBeforeVisitStencil();
@ -325,12 +342,11 @@ protected:
void updateBackGroundImageColor(); void updateBackGroundImageColor();
void updateBackGroundImageOpacity(); void updateBackGroundImageOpacity();
void updateBackGroundImageRGBA(); void updateBackGroundImageRGBA();
LayoutExecutant* createCurrentLayoutExecutant();
/** /**
*get the content size of the layout, it will accumulate all its children's content size *get the content size of the layout, it will accumulate all its children's content size
*/ */
Size getLayoutContentSize() const; Size getLayoutAccumulatedSize() const;
/** /**
* When the layout get focused, it the layout pass the focus to its child, it will use this method to determine which child * When the layout get focused, it the layout pass the focus to its child, it will use this method to determine which child
@ -477,8 +493,6 @@ protected:
Color3B _backGroundImageColor; Color3B _backGroundImageColor;
GLubyte _backGroundImageOpacity; GLubyte _backGroundImageOpacity;
LayoutExecutant* _curLayoutExecutant;
GLint _mask_layer_le; GLint _mask_layer_le;
GroupCommand _groupCommand; GroupCommand _groupCommand;
CustomCommand _beforeVisitCmdStencil; CustomCommand _beforeVisitCmdStencil;

View File

@ -0,0 +1,559 @@
/****************************************************************************
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 "UILayoutExecutant.h"
#include "UILayout.h"
NS_CC_BEGIN
namespace ui {
LinearVerticalLayoutExecutant* LinearVerticalLayoutExecutant::create()
{
LinearVerticalLayoutExecutant* exe = new LinearVerticalLayoutExecutant();
if (exe)
{
exe->autorelease();
return exe;
}
CC_SAFE_DELETE(exe);
return nullptr;
}
LinearHorizontalLayoutExecutant* LinearHorizontalLayoutExecutant::create()
{
LinearHorizontalLayoutExecutant* exe = new LinearHorizontalLayoutExecutant();
if (exe)
{
exe->autorelease();
return exe;
}
CC_SAFE_DELETE(exe);
return nullptr;
}
RelativeLayoutExecutant* RelativeLayoutExecutant::create()
{
RelativeLayoutExecutant* exe = new RelativeLayoutExecutant();
if (exe)
{
exe->autorelease();
return exe;
}
CC_SAFE_DELETE(exe);
return nullptr;
}
void LinearVerticalLayoutExecutant::doLayout(LayoutProtocol* layout)
{
Size layoutSize = layout->getLayoutContentSize();
Vector<Node*> container = layout->getLayoutElements();
float topBoundary = layoutSize.height;
for (auto& subWidget : container)
{
LayoutParameterProtocol* child = dynamic_cast<LayoutParameterProtocol*>(subWidget);
if (child)
{
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity();
Vec2 ap = subWidget->getAnchorPoint();
Size cs = subWidget->getContentSize();
float finalPosX = ap.x * cs.width;
float finalPosY = topBoundary - ((1.0f-ap.y) * cs.height);
switch (childGravity)
{
case LinearLayoutParameter::LinearGravity::NONE:
case LinearLayoutParameter::LinearGravity::LEFT:
break;
case LinearLayoutParameter::LinearGravity::RIGHT:
finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);
break;
case LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL:
finalPosX = layoutSize.width / 2.0f - cs.width * (0.5f-ap.x);
break;
default:
break;
}
Margin mg = layoutParameter->getMargin();
finalPosX += mg.left;
finalPosY -= mg.top;
subWidget->setPosition(Vec2(finalPosX, finalPosY));
topBoundary = subWidget->getPosition().y - subWidget->getAnchorPoint().y * subWidget->getContentSize().height - mg.bottom;
}
}
}
}
void LinearHorizontalLayoutExecutant::doLayout(LayoutProtocol* layout)
{
Size layoutSize = layout->getLayoutContentSize();
Vector<Node*> container = layout->getLayoutElements();
float leftBoundary = 0.0f;
for (auto& subWidget : container)
{
Widget* child = dynamic_cast<Widget*>(subWidget);
if (child)
{
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
if (layoutParameter)
{
LinearLayoutParameter::LinearGravity childGravity = layoutParameter->getGravity();
Vec2 ap = child->getAnchorPoint();
Size cs = child->getSize();
float finalPosX = leftBoundary + (ap.x * cs.width);
float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height;
switch (childGravity)
{
case LinearLayoutParameter::LinearGravity::NONE:
case LinearLayoutParameter::LinearGravity::TOP:
break;
case LinearLayoutParameter::LinearGravity::BOTTOM:
finalPosY = ap.y * cs.height;
break;
case LinearLayoutParameter::LinearGravity::CENTER_VERTICAL:
finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y);
break;
default:
break;
}
Margin mg = layoutParameter->getMargin();
finalPosX += mg.left;
finalPosY -= mg.top;
child->setPosition(Vec2(finalPosX, finalPosY));
leftBoundary = child->getRightBoundary() + mg.right;
}
}
}
}
Vector<Widget*> RelativeLayoutExecutant::getAllWidgets(cocos2d::ui::LayoutProtocol *layout)
{
Vector<Node*> container = layout->getLayoutElements();
Vector<Widget*> widgetChildren;
for (auto& subWidget : container)
{
Widget* child = dynamic_cast<Widget*>(subWidget);
if (child)
{
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter());
layoutParameter->_put = false;
_unlayoutChildCount++;
widgetChildren.pushBack(child);
}
}
return widgetChildren;
}
Widget* RelativeLayoutExecutant::getRelativeWidget(Widget* widget)
{
Widget* relativeWidget = nullptr;
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(widget->getLayoutParameter());
const std::string relativeName = layoutParameter->getRelativeToWidgetName();
if (!relativeName.empty())
{
for (auto& sWidget : _widgetChildren)
{
if (sWidget)
{
RelativeLayoutParameter* rlayoutParameter = dynamic_cast<RelativeLayoutParameter*>(sWidget->getLayoutParameter());
if (rlayoutParameter && rlayoutParameter->getRelativeName() == relativeName)
{
relativeWidget = sWidget;
_relativeWidgetLP = rlayoutParameter;
break;
}
}
}
}
return relativeWidget;
}
bool RelativeLayoutExecutant::caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout)
{
Vec2 ap = _widget->getAnchorPoint();
Size cs = _widget->getSize();
_finalPositionX = 0.0f;
_finalPositionY = 0.0f;
Widget* relativeWidget = this->getRelativeWidget(_widget);
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(_widget->getLayoutParameter());
RelativeLayoutParameter::RelativeAlign align = layoutParameter->getAlign();
Size layoutSize = layout->getLayoutContentSize();
switch (align)
{
case RelativeLayoutParameter::RelativeAlign::NONE:
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_LEFT:
_finalPositionX = ap.x * cs.width;
_finalPositionY = layoutSize.height - ((1.0f - ap.y) * cs.height);
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL:
_finalPositionX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);
_finalPositionY = layoutSize.height - ((1.0f - ap.y) * cs.height);
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT:
_finalPositionX = layoutSize.width - ((1.0f - ap.x) * cs.width);
_finalPositionY = layoutSize.height - ((1.0f - ap.y) * cs.height);
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL:
_finalPositionX = ap.x * cs.width;
_finalPositionY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);
break;
case RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT:
_finalPositionX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);
_finalPositionY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_CENTER_VERTICAL:
_finalPositionX = layoutSize.width - ((1.0f - ap.x) * cs.width);
_finalPositionY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_BOTTOM:
_finalPositionX = ap.x * cs.width;
_finalPositionY = ap.y * cs.height;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL:
_finalPositionX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);
_finalPositionY = ap.y * cs.height;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_BOTTOM:
_finalPositionX = layoutSize.width - ((1.0f - ap.x) * cs.width);
_finalPositionY = ap.y * cs.height;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_LEFTALIGN:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
float locationTop = relativeWidget->getTopBoundary();
float locationLeft = relativeWidget->getLeftBoundary();
_finalPositionY = locationTop + ap.y * cs.height;
_finalPositionX = locationLeft + ap.x * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_CENTER:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
Size rbs = relativeWidget->getSize();
float locationTop = relativeWidget->getTopBoundary();
_finalPositionY = locationTop + ap.y * cs.height;
_finalPositionX = relativeWidget->getLeftBoundary() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_RIGHTALIGN:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
float locationTop = relativeWidget->getTopBoundary();
float locationRight = relativeWidget->getRightBoundary();
_finalPositionY = locationTop + ap.y * cs.height;
_finalPositionX = locationRight - (1.0f - ap.x) * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_TOPALIGN:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
float locationTop = relativeWidget->getTopBoundary();
float locationLeft = relativeWidget->getLeftBoundary();
_finalPositionY = locationTop - (1.0f - ap.y) * cs.height;
_finalPositionX = locationLeft - (1.0f - ap.x) * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_CENTER:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
Size rbs = relativeWidget->getSize();
float locationLeft = relativeWidget->getLeftBoundary();
_finalPositionX = locationLeft - (1.0f - ap.x) * cs.width;
_finalPositionY = relativeWidget->getBottomBoundary() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_BOTTOMALIGN:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
float locationBottom = relativeWidget->getBottomBoundary();
float locationLeft = relativeWidget->getLeftBoundary();
_finalPositionY = locationBottom + ap.y * cs.height;
_finalPositionX = locationLeft - (1.0f - ap.x) * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_TOPALIGN:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
float locationTop = relativeWidget->getTopBoundary();
float locationRight = relativeWidget->getRightBoundary();
_finalPositionY = locationTop - (1.0f - ap.y) * cs.height;
_finalPositionX = locationRight + ap.x * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_CENTER:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
Size rbs = relativeWidget->getSize();
float locationRight = relativeWidget->getRightBoundary();
_finalPositionX = locationRight + ap.x * cs.width;
_finalPositionY = relativeWidget->getBottomBoundary() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_BOTTOMALIGN:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
float locationBottom = relativeWidget->getBottomBoundary();
float locationRight = relativeWidget->getRightBoundary();
_finalPositionY = locationBottom + ap.y * cs.height;
_finalPositionX = locationRight + ap.x * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_LEFTALIGN:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
float locationBottom = relativeWidget->getBottomBoundary();
float locationLeft = relativeWidget->getLeftBoundary();
_finalPositionY = locationBottom - (1.0f - ap.y) * cs.height;
_finalPositionX = locationLeft + ap.x * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_CENTER:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
Size rbs = relativeWidget->getSize();
float locationBottom = relativeWidget->getBottomBoundary();
_finalPositionY = locationBottom - (1.0f - ap.y) * cs.height;
_finalPositionX = relativeWidget->getLeftBoundary() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_RIGHTALIGN:
if (relativeWidget)
{
if (_relativeWidgetLP && !_relativeWidgetLP->_put)
{
return false;
}
float locationBottom = relativeWidget->getBottomBoundary();
float locationRight = relativeWidget->getRightBoundary();
_finalPositionY = locationBottom - (1.0f - ap.y) * cs.height;
_finalPositionX = locationRight - (1.0f - ap.x) * cs.width;
}
break;
default:
break;
}
return true;
}
void RelativeLayoutExecutant::caculateFinalPositionWithRelativeAlign()
{
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(_widget->getLayoutParameter());
Margin mg = layoutParameter->getMargin();
RelativeLayoutParameter::RelativeAlign align = layoutParameter->getAlign();
//handle margin
switch (align)
{
case RelativeLayoutParameter::RelativeAlign::NONE:
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_LEFT:
_finalPositionX += mg.left;
_finalPositionY -= mg.top;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL:
_finalPositionY -= mg.top;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_TOP_RIGHT:
_finalPositionX -= mg.right;
_finalPositionY -= mg.top;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_CENTER_VERTICAL:
_finalPositionX += mg.left;
break;
case RelativeLayoutParameter::RelativeAlign::CENTER_IN_PARENT:
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_CENTER_VERTICAL:
_finalPositionX -= mg.right;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_LEFT_BOTTOM:
_finalPositionX += mg.left;
_finalPositionY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_BOTTOM_CENTER_HORIZONTAL:
_finalPositionY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::PARENT_RIGHT_BOTTOM:
_finalPositionX -= mg.right;
_finalPositionY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_LEFTALIGN:
_finalPositionY += mg.bottom;
_finalPositionX += mg.left;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_RIGHTALIGN:
_finalPositionY += mg.bottom;
_finalPositionX -= mg.right;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_ABOVE_CENTER:
_finalPositionY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_TOPALIGN:
_finalPositionX -= mg.right;
_finalPositionY -= mg.top;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_BOTTOMALIGN:
_finalPositionX -= mg.right;
_finalPositionY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_LEFT_OF_CENTER:
_finalPositionX -= mg.right;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_TOPALIGN:
_finalPositionX += mg.left;
_finalPositionY -= mg.top;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_BOTTOMALIGN:
_finalPositionX += mg.left;
_finalPositionY += mg.bottom;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_CENTER:
_finalPositionX += mg.left;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_LEFTALIGN:
_finalPositionY -= mg.top;
_finalPositionX += mg.left;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_RIGHTALIGN:
_finalPositionY -= mg.top;
_finalPositionX -= mg.right;
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_CENTER:
_finalPositionY -= mg.top;
break;
default:
break;
}
}
void RelativeLayoutExecutant::doLayout(LayoutProtocol *layout)
{
_widgetChildren = this->getAllWidgets(layout);
while (_unlayoutChildCount > 0)
{
for (auto& subWidget : _widgetChildren)
{
_widget = static_cast<Widget*>(subWidget);
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(_widget->getLayoutParameter());
if (layoutParameter)
{
if (layoutParameter->_put)
{
continue;
}
bool ret = this->caculateFinalPositionWithRelativeWidget(layout);
if (!ret) {
continue;
}
this->caculateFinalPositionWithRelativeAlign();
_widget->setPosition(Vec2(_finalPositionX, _finalPositionY));
layoutParameter->_put = true;
}
}
_unlayoutChildCount--;
}
_widgetChildren.clear();
}
}
NS_CC_END

View File

@ -0,0 +1,98 @@
/****************************************************************************
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_libs__CCLayoutExecutant__
#define __cocos2d_libs__CCLayoutExecutant__
#include "base/CCRef.h"
#include "base/CCVector.h"
NS_CC_BEGIN
namespace ui {
class LayoutProtocol;
class Widget;
class RelativeLayoutParameter;
class LayoutExecutant : public Ref
{
public:
LayoutExecutant(){};
virtual ~LayoutExecutant(){};
virtual void doLayout(LayoutProtocol *layout) = 0;
};
class LinearVerticalLayoutExecutant : public LayoutExecutant
{
public:
LinearVerticalLayoutExecutant(){};
virtual ~LinearVerticalLayoutExecutant(){};
static LinearVerticalLayoutExecutant* create();
virtual void doLayout(LayoutProtocol *layout) override;
};
class LinearHorizontalLayoutExecutant : public LayoutExecutant
{
public:
LinearHorizontalLayoutExecutant(){};
virtual ~LinearHorizontalLayoutExecutant(){};
static LinearHorizontalLayoutExecutant* create();
virtual void doLayout(LayoutProtocol *layout) override;
};
class RelativeLayoutExecutant : public LayoutExecutant
{
public:
RelativeLayoutExecutant()
:_unlayoutChildCount(0),
_widget(nullptr),
_finalPositionX(0.0f),
_finalPositionY(0.0f),
_relativeWidgetLP(nullptr)
{}
virtual ~RelativeLayoutExecutant(){};
static RelativeLayoutExecutant* create();
virtual void doLayout(LayoutProtocol *layout) override;
protected:
Vector<Widget*> getAllWidgets(LayoutProtocol *layout);
Widget* getRelativeWidget(Widget* widget);
bool caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout);
void caculateFinalPositionWithRelativeAlign();
ssize_t _unlayoutChildCount;
Vector<Widget*> _widgetChildren;
Widget* _widget;
float _finalPositionX;
float _finalPositionY;
RelativeLayoutParameter* _relativeWidgetLP;
};
}
NS_CC_END
#endif /* defined(__cocos2d_libs__CCLayoutExecutant__) */

View File

@ -130,6 +130,15 @@ protected:
Type _layoutParameterType; Type _layoutParameterType;
}; };
class LayoutParameterProtocol
{
public:
LayoutParameterProtocol(){}
virtual ~LayoutParameterProtocol(){}
virtual LayoutParameter* getLayoutParameter() = 0;
};
/** /**
* @js NA * @js NA

View File

@ -130,7 +130,7 @@ void ListView::remedyLayoutParameter(Widget *item)
switch (_direction) { switch (_direction) {
case Direction::VERTICAL: case Direction::VERTICAL:
{ {
LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LayoutParameter::Type::LINEAR)); LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter());
if (!llp) if (!llp)
{ {
LinearLayoutParameter* defaultLp = LinearLayoutParameter::create(); LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
@ -185,7 +185,7 @@ void ListView::remedyLayoutParameter(Widget *item)
} }
case Direction::HORIZONTAL: case Direction::HORIZONTAL:
{ {
LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LayoutParameter::Type::LINEAR)); LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter());
if (!llp) if (!llp)
{ {
LinearLayoutParameter* defaultLp = LinearLayoutParameter::create(); LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();

View File

@ -435,18 +435,18 @@ bool PageView::scrollPages(float touchOffset)
switch (_touchMoveDir) switch (_touchMoveDir)
{ {
case TouchDirection::LEFT: // left case TouchDirection::LEFT: // left
if (_rightChild->getRightInParent() + touchOffset <= _rightBoundary) if (_rightChild->getRightBoundary() + touchOffset <= _rightBoundary)
{ {
realOffset = _rightBoundary - _rightChild->getRightInParent(); realOffset = _rightBoundary - _rightChild->getRightBoundary();
movePages(realOffset); movePages(realOffset);
return false; return false;
} }
break; break;
case TouchDirection::RIGHT: // right case TouchDirection::RIGHT: // right
if (_leftChild->getLeftInParent() + touchOffset >= _leftBoundary) if (_leftChild->getLeftBoundary() + touchOffset >= _leftBoundary)
{ {
realOffset = _leftBoundary - _leftChild->getLeftInParent(); realOffset = _leftBoundary - _leftChild->getLeftBoundary();
movePages(realOffset); movePages(realOffset);
return false; return false;
} }

View File

@ -210,7 +210,7 @@ void ScrollView::setInnerContainerSize(const Size &size)
} }
case Direction::HORIZONTAL: case Direction::HORIZONTAL:
{ {
if (_innerContainer->getRightInParent() <= _size.width) if (_innerContainer->getRightBoundary() <= _size.width)
{ {
Size newInnerSize = _innerContainer->getSize(); Size newInnerSize = _innerContainer->getSize();
float offset = originalInnerSize.width - newInnerSize.width; float offset = originalInnerSize.width - newInnerSize.width;
@ -223,7 +223,7 @@ void ScrollView::setInnerContainerSize(const Size &size)
Size newInnerSize = _innerContainer->getSize(); Size newInnerSize = _innerContainer->getSize();
float offsetY = originalInnerSize.height - newInnerSize.height; float offsetY = originalInnerSize.height - newInnerSize.height;
float offsetX = 0.0f; float offsetX = 0.0f;
if (_innerContainer->getRightInParent() <= _size.width) if (_innerContainer->getRightBoundary() <= _size.width)
{ {
offsetX = originalInnerSize.width - newInnerSize.width; offsetX = originalInnerSize.width - newInnerSize.width;
} }
@ -233,11 +233,11 @@ void ScrollView::setInnerContainerSize(const Size &size)
default: default:
break; break;
} }
if (_innerContainer->getLeftInParent() > 0.0f) if (_innerContainer->getLeftBoundary() > 0.0f)
{ {
_innerContainer->setPosition(Vec2(_innerContainer->getAnchorPoint().x * _innerContainer->getSize().width, _innerContainer->getPosition().y)); _innerContainer->setPosition(Vec2(_innerContainer->getAnchorPoint().x * _innerContainer->getSize().width, _innerContainer->getPosition().y));
} }
if (_innerContainer->getRightInParent() < _size.width) if (_innerContainer->getRightBoundary() < _size.width)
{ {
_innerContainer->setPosition(Vec2(_size.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getSize().width), _innerContainer->getPosition().y)); _innerContainer->setPosition(Vec2(_size.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getSize().width), _innerContainer->getPosition().y));
} }
@ -245,7 +245,7 @@ void ScrollView::setInnerContainerSize(const Size &size)
{ {
_innerContainer->setPosition(Vec2(_innerContainer->getPosition().x, _innerContainer->getAnchorPoint().y * _innerContainer->getSize().height)); _innerContainer->setPosition(Vec2(_innerContainer->getPosition().x, _innerContainer->getAnchorPoint().y * _innerContainer->getSize().height));
} }
if (_innerContainer->getTopInParent() < _size.height) if (_innerContainer->getTopBoundary() < _size.height)
{ {
_innerContainer->setPosition(Vec2(_innerContainer->getPosition().x, _size.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getSize().height)); _innerContainer->setPosition(Vec2(_innerContainer->getPosition().x, _size.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getSize().height));
} }
@ -390,56 +390,56 @@ bool ScrollView::checkNeedBounce()
{ {
if (_topBounceNeeded && _leftBounceNeeded) if (_topBounceNeeded && _leftBounceNeeded)
{ {
Vec2 scrollVector = Vec2(0.0f, _size.height) - Vec2(_innerContainer->getLeftInParent(), _innerContainer->getTopInParent()); Vec2 scrollVector = Vec2(0.0f, _size.height) - Vec2(_innerContainer->getLeftBoundary(), _innerContainer->getTopBoundary());
float orSpeed = scrollVector.getLength()/(0.2f); float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized(); _bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed); startBounceChildren(orSpeed);
} }
else if (_topBounceNeeded && _rightBounceNeeded) else if (_topBounceNeeded && _rightBounceNeeded)
{ {
Vec2 scrollVector = Vec2(_size.width, _size.height) - Vec2(_innerContainer->getRightInParent(), _innerContainer->getTopInParent()); Vec2 scrollVector = Vec2(_size.width, _size.height) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getTopBoundary());
float orSpeed = scrollVector.getLength()/(0.2f); float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized(); _bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed); startBounceChildren(orSpeed);
} }
else if (_bottomBounceNeeded && _leftBounceNeeded) else if (_bottomBounceNeeded && _leftBounceNeeded)
{ {
Vec2 scrollVector = Vec2::ZERO - Vec2(_innerContainer->getLeftInParent(), _innerContainer->getBottomInParent()); Vec2 scrollVector = Vec2::ZERO - Vec2(_innerContainer->getLeftBoundary(), _innerContainer->getBottomBoundary());
float orSpeed = scrollVector.getLength()/(0.2f); float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized(); _bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed); startBounceChildren(orSpeed);
} }
else if (_bottomBounceNeeded && _rightBounceNeeded) else if (_bottomBounceNeeded && _rightBounceNeeded)
{ {
Vec2 scrollVector = Vec2(_size.width, 0.0f) - Vec2(_innerContainer->getRightInParent(), _innerContainer->getBottomInParent()); Vec2 scrollVector = Vec2(_size.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getBottomBoundary());
float orSpeed = scrollVector.getLength()/(0.2f); float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized(); _bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed); startBounceChildren(orSpeed);
} }
else if (_topBounceNeeded) else if (_topBounceNeeded)
{ {
Vec2 scrollVector = Vec2(0.0f, _size.height) - Vec2(0.0f, _innerContainer->getTopInParent()); Vec2 scrollVector = Vec2(0.0f, _size.height) - Vec2(0.0f, _innerContainer->getTopBoundary());
float orSpeed = scrollVector.getLength()/(0.2f); float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized(); _bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed); startBounceChildren(orSpeed);
} }
else if (_bottomBounceNeeded) else if (_bottomBounceNeeded)
{ {
Vec2 scrollVector = Vec2::ZERO - Vec2(0.0f, _innerContainer->getBottomInParent()); Vec2 scrollVector = Vec2::ZERO - Vec2(0.0f, _innerContainer->getBottomBoundary());
float orSpeed = scrollVector.getLength()/(0.2f); float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized(); _bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed); startBounceChildren(orSpeed);
} }
else if (_leftBounceNeeded) else if (_leftBounceNeeded)
{ {
Vec2 scrollVector = Vec2::ZERO - Vec2(_innerContainer->getLeftInParent(), 0.0f); Vec2 scrollVector = Vec2::ZERO - Vec2(_innerContainer->getLeftBoundary(), 0.0f);
float orSpeed = scrollVector.getLength()/(0.2f); float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized(); _bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed); startBounceChildren(orSpeed);
} }
else if (_rightBounceNeeded) else if (_rightBounceNeeded)
{ {
Vec2 scrollVector = Vec2(_size.width, 0.0f) - Vec2(_innerContainer->getRightInParent(), 0.0f); Vec2 scrollVector = Vec2(_size.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), 0.0f);
float orSpeed = scrollVector.getLength()/(0.2f); float orSpeed = scrollVector.getLength()/(0.2f);
_bounceDir = scrollVector.getNormalized(); _bounceDir = scrollVector.getNormalized();
startBounceChildren(orSpeed); startBounceChildren(orSpeed);
@ -451,7 +451,7 @@ bool ScrollView::checkNeedBounce()
void ScrollView::checkBounceBoundary() void ScrollView::checkBounceBoundary()
{ {
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos > _bottomBoundary) if (icBottomPos > _bottomBoundary)
{ {
scrollToBottomEvent(); scrollToBottomEvent();
@ -461,7 +461,7 @@ void ScrollView::checkBounceBoundary()
{ {
_bottomBounceNeeded = false; _bottomBounceNeeded = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos < _topBoundary) if (icTopPos < _topBoundary)
{ {
scrollToTopEvent(); scrollToTopEvent();
@ -471,7 +471,7 @@ void ScrollView::checkBounceBoundary()
{ {
_topBounceNeeded = false; _topBounceNeeded = false;
} }
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos < _rightBoundary) if (icRightPos < _rightBoundary)
{ {
scrollToRightEvent(); scrollToRightEvent();
@ -481,7 +481,7 @@ void ScrollView::checkBounceBoundary()
{ {
_rightBounceNeeded = false; _rightBounceNeeded = false;
} }
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos > _leftBoundary) if (icLeftPos > _leftBoundary)
{ {
scrollToLeftEvent(); scrollToLeftEvent();
@ -588,14 +588,14 @@ bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY)
{ {
float realOffsetX = touchOffsetX; float realOffsetX = touchOffsetX;
float realOffsetY = touchOffsetY; float realOffsetY = touchOffsetY;
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + realOffsetX >= _rightBoundary) if (icRightPos + realOffsetX >= _rightBoundary)
{ {
realOffsetX = _rightBoundary - icRightPos; realOffsetX = _rightBoundary - icRightPos;
bounceRightEvent(); bounceRightEvent();
scrollenabled = false; scrollenabled = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY >= _topBoundary) if (icTopPos + touchOffsetY >= _topBoundary)
{ {
realOffsetY = _topBoundary - icTopPos; realOffsetY = _topBoundary - icTopPos;
@ -608,14 +608,14 @@ bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY)
{ {
float realOffsetX = touchOffsetX; float realOffsetX = touchOffsetX;
float realOffsetY = touchOffsetY; float realOffsetY = touchOffsetY;
float icLefrPos = _innerContainer->getLeftInParent(); float icLefrPos = _innerContainer->getLeftBoundary();
if (icLefrPos + realOffsetX <= _leftBoundary) if (icLefrPos + realOffsetX <= _leftBoundary)
{ {
realOffsetX = _leftBoundary - icLefrPos; realOffsetX = _leftBoundary - icLefrPos;
bounceLeftEvent(); bounceLeftEvent();
scrollenabled = false; scrollenabled = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY >= _topBoundary) if (icTopPos + touchOffsetY >= _topBoundary)
{ {
realOffsetY = _topBoundary - icTopPos; realOffsetY = _topBoundary - icTopPos;
@ -628,14 +628,14 @@ bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY)
{ {
float realOffsetX = touchOffsetX; float realOffsetX = touchOffsetX;
float realOffsetY = touchOffsetY; float realOffsetY = touchOffsetY;
float icLefrPos = _innerContainer->getLeftInParent(); float icLefrPos = _innerContainer->getLeftBoundary();
if (icLefrPos + realOffsetX <= _leftBoundary) if (icLefrPos + realOffsetX <= _leftBoundary)
{ {
realOffsetX = _leftBoundary - icLefrPos; realOffsetX = _leftBoundary - icLefrPos;
bounceLeftEvent(); bounceLeftEvent();
scrollenabled = false; scrollenabled = false;
} }
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY <= _bottomBoundary) if (icBottomPos + touchOffsetY <= _bottomBoundary)
{ {
realOffsetY = _bottomBoundary - icBottomPos; realOffsetY = _bottomBoundary - icBottomPos;
@ -648,14 +648,14 @@ bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY)
{ {
float realOffsetX = touchOffsetX; float realOffsetX = touchOffsetX;
float realOffsetY = touchOffsetY; float realOffsetY = touchOffsetY;
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + realOffsetX >= _rightBoundary) if (icRightPos + realOffsetX >= _rightBoundary)
{ {
realOffsetX = _rightBoundary - icRightPos; realOffsetX = _rightBoundary - icRightPos;
bounceRightEvent(); bounceRightEvent();
scrollenabled = false; scrollenabled = false;
} }
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY <= _bottomBoundary) if (icBottomPos + touchOffsetY <= _bottomBoundary)
{ {
realOffsetY = _bottomBoundary - icBottomPos; realOffsetY = _bottomBoundary - icBottomPos;
@ -667,7 +667,7 @@ bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY)
else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // bounce to top else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // bounce to top
{ {
float realOffsetY = touchOffsetY; float realOffsetY = touchOffsetY;
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY >= _topBoundary) if (icTopPos + touchOffsetY >= _topBoundary)
{ {
realOffsetY = _topBoundary - icTopPos; realOffsetY = _topBoundary - icTopPos;
@ -679,7 +679,7 @@ bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY)
else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) //bounce to bottom else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) //bounce to bottom
{ {
float realOffsetY = touchOffsetY; float realOffsetY = touchOffsetY;
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY <= _bottomBoundary) if (icBottomPos + touchOffsetY <= _bottomBoundary)
{ {
realOffsetY = _bottomBoundary - icBottomPos; realOffsetY = _bottomBoundary - icBottomPos;
@ -691,7 +691,7 @@ bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY)
else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) //bounce to right else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) //bounce to right
{ {
float realOffsetX = touchOffsetX; float realOffsetX = touchOffsetX;
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + realOffsetX >= _rightBoundary) if (icRightPos + realOffsetX >= _rightBoundary)
{ {
realOffsetX = _rightBoundary - icRightPos; realOffsetX = _rightBoundary - icRightPos;
@ -703,7 +703,7 @@ bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY)
else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) //bounce to left else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) //bounce to left
{ {
float realOffsetX = touchOffsetX; float realOffsetX = touchOffsetX;
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + realOffsetX <= _leftBoundary) if (icLeftPos + realOffsetX <= _leftBoundary)
{ {
realOffsetX = _leftBoundary - icLeftPos; realOffsetX = _leftBoundary - icLeftPos;
@ -724,7 +724,7 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
{ {
if (_autoScrollDir.y > 0) if (_autoScrollDir.y > 0)
{ {
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y)
{ {
*touchOffsetY = _autoScrollDestination.y - icBottomPos; *touchOffsetY = _autoScrollDestination.y - icBottomPos;
@ -733,7 +733,7 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
} }
else else
{ {
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + *touchOffsetY <= _autoScrollDestination.y) if (icBottomPos + *touchOffsetY <= _autoScrollDestination.y)
{ {
*touchOffsetY = _autoScrollDestination.y - icBottomPos; *touchOffsetY = _autoScrollDestination.y - icBottomPos;
@ -746,7 +746,7 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
{ {
if (_autoScrollDir.x > 0) if (_autoScrollDir.x > 0)
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x)
{ {
*touchOffsetX = _autoScrollDestination.x - icLeftPos; *touchOffsetX = _autoScrollDestination.x - icLeftPos;
@ -755,7 +755,7 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
} }
else else
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + *touchOffsetX <= _autoScrollDestination.x) if (icLeftPos + *touchOffsetX <= _autoScrollDestination.x)
{ {
*touchOffsetX = _autoScrollDestination.x - icLeftPos; *touchOffsetX = _autoScrollDestination.x - icLeftPos;
@ -768,13 +768,13 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
{ {
if (*touchOffsetX > 0.0f && *touchOffsetY > 0.0f) // up right if (*touchOffsetX > 0.0f && *touchOffsetY > 0.0f) // up right
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x)
{ {
*touchOffsetX = _autoScrollDestination.x - icLeftPos; *touchOffsetX = _autoScrollDestination.x - icLeftPos;
scrollenabled = false; scrollenabled = false;
} }
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y)
{ {
*touchOffsetY = _autoScrollDestination.y - icBottomPos; *touchOffsetY = _autoScrollDestination.y - icBottomPos;
@ -783,13 +783,13 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
} }
else if (*touchOffsetX < 0.0f && *touchOffsetY > 0.0f) // up left else if (*touchOffsetX < 0.0f && *touchOffsetY > 0.0f) // up left
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + *touchOffsetX <= _autoScrollDestination.x) if (icRightPos + *touchOffsetX <= _autoScrollDestination.x)
{ {
*touchOffsetX = _autoScrollDestination.x - icRightPos; *touchOffsetX = _autoScrollDestination.x - icRightPos;
scrollenabled = false; scrollenabled = false;
} }
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y)
{ {
*touchOffsetY = _autoScrollDestination.y - icBottomPos; *touchOffsetY = _autoScrollDestination.y - icBottomPos;
@ -798,13 +798,13 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
} }
else if (*touchOffsetX < 0.0f && *touchOffsetY < 0.0f) // down left else if (*touchOffsetX < 0.0f && *touchOffsetY < 0.0f) // down left
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + *touchOffsetX <= _autoScrollDestination.x) if (icRightPos + *touchOffsetX <= _autoScrollDestination.x)
{ {
*touchOffsetX = _autoScrollDestination.x - icRightPos; *touchOffsetX = _autoScrollDestination.x - icRightPos;
scrollenabled = false; scrollenabled = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + *touchOffsetY <= _autoScrollDestination.y) if (icTopPos + *touchOffsetY <= _autoScrollDestination.y)
{ {
*touchOffsetY = _autoScrollDestination.y - icTopPos; *touchOffsetY = _autoScrollDestination.y - icTopPos;
@ -813,13 +813,13 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
} }
else if (*touchOffsetX > 0.0f && *touchOffsetY < 0.0f) // down right else if (*touchOffsetX > 0.0f && *touchOffsetY < 0.0f) // down right
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x)
{ {
*touchOffsetX = _autoScrollDestination.x - icLeftPos; *touchOffsetX = _autoScrollDestination.x - icLeftPos;
scrollenabled = false; scrollenabled = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + *touchOffsetY <= _autoScrollDestination.y) if (icTopPos + *touchOffsetY <= _autoScrollDestination.y)
{ {
*touchOffsetY = _autoScrollDestination.y - icTopPos; *touchOffsetY = _autoScrollDestination.y - icTopPos;
@ -828,7 +828,7 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
} }
else if (*touchOffsetX == 0.0f && *touchOffsetY > 0.0f) // up else if (*touchOffsetX == 0.0f && *touchOffsetY > 0.0f) // up
{ {
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y) if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y)
{ {
*touchOffsetY = _autoScrollDestination.y - icBottomPos; *touchOffsetY = _autoScrollDestination.y - icBottomPos;
@ -837,7 +837,7 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
} }
else if (*touchOffsetX < 0.0f && *touchOffsetY == 0.0f) // left else if (*touchOffsetX < 0.0f && *touchOffsetY == 0.0f) // left
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + *touchOffsetX <= _autoScrollDestination.x) if (icRightPos + *touchOffsetX <= _autoScrollDestination.x)
{ {
*touchOffsetX = _autoScrollDestination.x - icRightPos; *touchOffsetX = _autoScrollDestination.x - icRightPos;
@ -846,7 +846,7 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
} }
else if (*touchOffsetX == 0.0f && *touchOffsetY < 0.0f) // down else if (*touchOffsetX == 0.0f && *touchOffsetY < 0.0f) // down
{ {
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + *touchOffsetY <= _autoScrollDestination.y) if (icTopPos + *touchOffsetY <= _autoScrollDestination.y)
{ {
*touchOffsetY = _autoScrollDestination.y - icTopPos; *touchOffsetY = _autoScrollDestination.y - icTopPos;
@ -855,7 +855,7 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
} }
else if (*touchOffsetX > 0.0f && *touchOffsetY == 0.0f) // right else if (*touchOffsetX > 0.0f && *touchOffsetY == 0.0f) // right
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x) if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x)
{ {
*touchOffsetX = _autoScrollDestination.x - icLeftPos; *touchOffsetX = _autoScrollDestination.x - icLeftPos;
@ -870,25 +870,21 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
return scrollenabled; return scrollenabled;
} }
bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY) bool ScrollView::scrollChilderVertical(float touchOffsetX, float touchOffsetY)
{ {
bool scrollenabled = true; bool scrollenabled = true;
scrollingEvent();
switch (_direction)
{
case Direction::VERTICAL: // vertical
{
float realOffset = touchOffsetY; float realOffset = touchOffsetY;
if (_bounceEnabled) if (_bounceEnabled)
{ {
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) if (icBottomPos + touchOffsetY >= _bounceBottomBoundary)
{ {
realOffset = _bounceBottomBoundary - icBottomPos; realOffset = _bounceBottomBoundary - icBottomPos;
scrollToBottomEvent(); scrollToBottomEvent();
scrollenabled = false; scrollenabled = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY <= _bounceTopBoundary) if (icTopPos + touchOffsetY <= _bounceTopBoundary)
{ {
realOffset = _bounceTopBoundary - icTopPos; realOffset = _bounceTopBoundary - icTopPos;
@ -898,14 +894,14 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else else
{ {
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY >= _bottomBoundary) if (icBottomPos + touchOffsetY >= _bottomBoundary)
{ {
realOffset = _bottomBoundary - icBottomPos; realOffset = _bottomBoundary - icBottomPos;
scrollToBottomEvent(); scrollToBottomEvent();
scrollenabled = false; scrollenabled = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY <= _topBoundary) if (icTopPos + touchOffsetY <= _topBoundary)
{ {
realOffset = _topBoundary - icTopPos; realOffset = _topBoundary - icTopPos;
@ -914,21 +910,25 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
} }
moveChildren(0.0f, realOffset); moveChildren(0.0f, realOffset);
break;
} return scrollenabled;
case Direction::HORIZONTAL: // horizontal }
{
bool ScrollView::scrollChilderHorizontal(float touchOffsetX, float touchOffsetY)
{
bool scrollenabled = true;
float realOffset = touchOffsetX; float realOffset = touchOffsetX;
if (_bounceEnabled) if (_bounceEnabled)
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + touchOffsetX <= _bounceRightBoundary) if (icRightPos + touchOffsetX <= _bounceRightBoundary)
{ {
realOffset = _bounceRightBoundary - icRightPos; realOffset = _bounceRightBoundary - icRightPos;
scrollToRightEvent(); scrollToRightEvent();
scrollenabled = false; scrollenabled = false;
} }
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) if (icLeftPos + touchOffsetX >= _bounceLeftBoundary)
{ {
realOffset = _bounceLeftBoundary - icLeftPos; realOffset = _bounceLeftBoundary - icLeftPos;
@ -938,14 +938,14 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else else
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + touchOffsetX <= _rightBoundary) if (icRightPos + touchOffsetX <= _rightBoundary)
{ {
realOffset = _rightBoundary - icRightPos; realOffset = _rightBoundary - icRightPos;
scrollToRightEvent(); scrollToRightEvent();
scrollenabled = false; scrollenabled = false;
} }
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + touchOffsetX >= _leftBoundary) if (icLeftPos + touchOffsetX >= _leftBoundary)
{ {
realOffset = _leftBoundary - icLeftPos; realOffset = _leftBoundary - icLeftPos;
@ -954,24 +954,27 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
} }
moveChildren(realOffset, 0.0f); moveChildren(realOffset, 0.0f);
break;
} return scrollenabled;
case Direction::BOTH: }
{
bool ScrollView::scrollChilderBoth(float touchOffsetX, float touchOffsetY)
{
bool scrollenabled = true;
float realOffsetX = touchOffsetX; float realOffsetX = touchOffsetX;
float realOffsetY = touchOffsetY; float realOffsetY = touchOffsetY;
if (_bounceEnabled) if (_bounceEnabled)
{ {
if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) // up right if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) // up right
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) if (icLeftPos + touchOffsetX >= _bounceLeftBoundary)
{ {
realOffsetX = _bounceLeftBoundary - icLeftPos; realOffsetX = _bounceLeftBoundary - icLeftPos;
scrollToLeftEvent(); scrollToLeftEvent();
scrollenabled = false; scrollenabled = false;
} }
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) if (icBottomPos + touchOffsetY >= _bounceBottomBoundary)
{ {
realOffsetY = _bounceBottomBoundary - icBottomPos; realOffsetY = _bounceBottomBoundary - icBottomPos;
@ -981,14 +984,14 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX < 0.0f && touchOffsetY > 0.0f) // up left else if (touchOffsetX < 0.0f && touchOffsetY > 0.0f) // up left
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + touchOffsetX <= _bounceRightBoundary) if (icRightPos + touchOffsetX <= _bounceRightBoundary)
{ {
realOffsetX = _bounceRightBoundary - icRightPos; realOffsetX = _bounceRightBoundary - icRightPos;
scrollToRightEvent(); scrollToRightEvent();
scrollenabled = false; scrollenabled = false;
} }
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) if (icBottomPos + touchOffsetY >= _bounceBottomBoundary)
{ {
realOffsetY = _bounceBottomBoundary - icBottomPos; realOffsetY = _bounceBottomBoundary - icBottomPos;
@ -998,14 +1001,14 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) // down left else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) // down left
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + touchOffsetX <= _bounceRightBoundary) if (icRightPos + touchOffsetX <= _bounceRightBoundary)
{ {
realOffsetX = _bounceRightBoundary - icRightPos; realOffsetX = _bounceRightBoundary - icRightPos;
scrollToRightEvent(); scrollToRightEvent();
scrollenabled = false; scrollenabled = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY <= _bounceTopBoundary) if (icTopPos + touchOffsetY <= _bounceTopBoundary)
{ {
realOffsetY = _bounceTopBoundary - icTopPos; realOffsetY = _bounceTopBoundary - icTopPos;
@ -1015,14 +1018,14 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) // down right else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) // down right
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) if (icLeftPos + touchOffsetX >= _bounceLeftBoundary)
{ {
realOffsetX = _bounceLeftBoundary - icLeftPos; realOffsetX = _bounceLeftBoundary - icLeftPos;
scrollToLeftEvent(); scrollToLeftEvent();
scrollenabled = false; scrollenabled = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY <= _bounceTopBoundary) if (icTopPos + touchOffsetY <= _bounceTopBoundary)
{ {
realOffsetY = _bounceTopBoundary - icTopPos; realOffsetY = _bounceTopBoundary - icTopPos;
@ -1032,7 +1035,7 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // up else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // up
{ {
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY >= _bounceBottomBoundary) if (icBottomPos + touchOffsetY >= _bounceBottomBoundary)
{ {
realOffsetY = _bounceBottomBoundary - icBottomPos; realOffsetY = _bounceBottomBoundary - icBottomPos;
@ -1042,7 +1045,7 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) // left else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) // left
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + touchOffsetX <= _bounceRightBoundary) if (icRightPos + touchOffsetX <= _bounceRightBoundary)
{ {
realOffsetX = _bounceRightBoundary - icRightPos; realOffsetX = _bounceRightBoundary - icRightPos;
@ -1052,7 +1055,7 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) // down else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) // down
{ {
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY <= _bounceTopBoundary) if (icTopPos + touchOffsetY <= _bounceTopBoundary)
{ {
realOffsetY = _bounceTopBoundary - icTopPos; realOffsetY = _bounceTopBoundary - icTopPos;
@ -1062,7 +1065,7 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) // right else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) // right
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + touchOffsetX >= _bounceLeftBoundary) if (icLeftPos + touchOffsetX >= _bounceLeftBoundary)
{ {
realOffsetX = _bounceLeftBoundary - icLeftPos; realOffsetX = _bounceLeftBoundary - icLeftPos;
@ -1075,14 +1078,14 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
{ {
if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) // up right if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) // up right
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + touchOffsetX >= _leftBoundary) if (icLeftPos + touchOffsetX >= _leftBoundary)
{ {
realOffsetX = _leftBoundary - icLeftPos; realOffsetX = _leftBoundary - icLeftPos;
scrollToLeftEvent(); scrollToLeftEvent();
scrollenabled = false; scrollenabled = false;
} }
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY >= _bottomBoundary) if (icBottomPos + touchOffsetY >= _bottomBoundary)
{ {
realOffsetY = _bottomBoundary - icBottomPos; realOffsetY = _bottomBoundary - icBottomPos;
@ -1092,14 +1095,14 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX < 0.0f && touchOffsetY > 0.0f) // up left else if (touchOffsetX < 0.0f && touchOffsetY > 0.0f) // up left
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + touchOffsetX <= _rightBoundary) if (icRightPos + touchOffsetX <= _rightBoundary)
{ {
realOffsetX = _rightBoundary - icRightPos; realOffsetX = _rightBoundary - icRightPos;
scrollToRightEvent(); scrollToRightEvent();
scrollenabled = false; scrollenabled = false;
} }
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY >= _bottomBoundary) if (icBottomPos + touchOffsetY >= _bottomBoundary)
{ {
realOffsetY = _bottomBoundary - icBottomPos; realOffsetY = _bottomBoundary - icBottomPos;
@ -1109,14 +1112,14 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) // down left else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) // down left
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + touchOffsetX <= _rightBoundary) if (icRightPos + touchOffsetX <= _rightBoundary)
{ {
realOffsetX = _rightBoundary - icRightPos; realOffsetX = _rightBoundary - icRightPos;
scrollToRightEvent(); scrollToRightEvent();
scrollenabled = false; scrollenabled = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY <= _topBoundary) if (icTopPos + touchOffsetY <= _topBoundary)
{ {
realOffsetY = _topBoundary - icTopPos; realOffsetY = _topBoundary - icTopPos;
@ -1126,14 +1129,14 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) // down right else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) // down right
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + touchOffsetX >= _leftBoundary) if (icLeftPos + touchOffsetX >= _leftBoundary)
{ {
realOffsetX = _leftBoundary - icLeftPos; realOffsetX = _leftBoundary - icLeftPos;
scrollToLeftEvent(); scrollToLeftEvent();
scrollenabled = false; scrollenabled = false;
} }
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY <= _topBoundary) if (icTopPos + touchOffsetY <= _topBoundary)
{ {
realOffsetY = _topBoundary - icTopPos; realOffsetY = _topBoundary - icTopPos;
@ -1143,7 +1146,7 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // up else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // up
{ {
float icBottomPos = _innerContainer->getBottomInParent(); float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY >= _bottomBoundary) if (icBottomPos + touchOffsetY >= _bottomBoundary)
{ {
realOffsetY = _bottomBoundary - icBottomPos; realOffsetY = _bottomBoundary - icBottomPos;
@ -1153,7 +1156,7 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) // left else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) // left
{ {
float icRightPos = _innerContainer->getRightInParent(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + touchOffsetX <= _rightBoundary) if (icRightPos + touchOffsetX <= _rightBoundary)
{ {
realOffsetX = _rightBoundary - icRightPos; realOffsetX = _rightBoundary - icRightPos;
@ -1163,7 +1166,7 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) // down else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) // down
{ {
float icTopPos = _innerContainer->getTopInParent(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY <= _topBoundary) if (icTopPos + touchOffsetY <= _topBoundary)
{ {
realOffsetY = _topBoundary - icTopPos; realOffsetY = _topBoundary - icTopPos;
@ -1173,7 +1176,7 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) // right else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) // right
{ {
float icLeftPos = _innerContainer->getLeftInParent(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + touchOffsetX >= _leftBoundary) if (icLeftPos + touchOffsetX >= _leftBoundary)
{ {
realOffsetX = _leftBoundary - icLeftPos; realOffsetX = _leftBoundary - icLeftPos;
@ -1183,6 +1186,29 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
} }
} }
moveChildren(realOffsetX, realOffsetY); moveChildren(realOffsetX, realOffsetY);
return scrollenabled;
}
bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
{
bool scrollenabled = true;
scrollingEvent();
switch (_direction)
{
case Direction::VERTICAL: // vertical
{
scrollenabled = this->scrollChilderVertical(touchOffsetX, touchOffsetY);
break;
}
case Direction::HORIZONTAL: // horizontal
{
scrollenabled = this->scrollChilderHorizontal(touchOffsetX, touchOffsetY);
break;
}
case Direction::BOTH:
{
scrollenabled = this->scrollChilderBoth(touchOffsetX, touchOffsetY);
break; break;
} }
default: default:

View File

@ -357,7 +357,13 @@ protected:
void startBounceChildren(float v); void startBounceChildren(float v);
void stopBounceChildren(); void stopBounceChildren();
bool checkCustomScrollDestination(float* touchOffsetX, float* touchOffsetY); bool checkCustomScrollDestination(float* touchOffsetX, float* touchOffsetY);
virtual bool scrollChildren(float touchOffsetX, float touchOffsetY); virtual bool scrollChildren(float touchOffsetX, float touchOffsetY);
virtual bool scrollChilderHorizontal(float touchOffsetX, float touchOffsetY);
virtual bool scrollChilderVertical(float touchOffsetX, float touchOffsetY);
virtual bool scrollChilderBoth(float touchOffsetX, float touchOffsetY);
bool bounceScrollChildren(float touchOffsetX, float touchOffsetY); bool bounceScrollChildren(float touchOffsetX, float touchOffsetY);
void startRecordSlidAction(); void startRecordSlidAction();
virtual void endRecordSlidAction(); virtual void endRecordSlidAction();

View File

@ -62,7 +62,8 @@ _opacity(255),
_flippedX(false), _flippedX(false),
_flippedY(false), _flippedY(false),
_focused(false), _focused(false),
_focusEnabled(true) _focusEnabled(true),
_layoutParameterType(LayoutParameter::Type::NONE)
{ {
onFocusChanged = CC_CALLBACK_2(Widget::onFocusChange,this); onFocusChanged = CC_CALLBACK_2(Widget::onFocusChange,this);
onNextFocusedWidget = nullptr; onNextFocusedWidget = nullptr;
@ -815,24 +816,24 @@ bool Widget::isEnabled() const
return _enabled; return _enabled;
} }
float Widget::getLeftInParent() float Widget::getLeftBoundary() const
{ {
return getPosition().x - getAnchorPoint().x * _size.width;; return getPosition().x - getAnchorPoint().x * _size.width;
} }
float Widget::getBottomInParent() float Widget::getBottomBoundary() const
{ {
return getPosition().y - getAnchorPoint().y * _size.height;; return getPosition().y - getAnchorPoint().y * _size.height;
} }
float Widget::getRightInParent() float Widget::getRightBoundary() const
{ {
return getLeftInParent() + _size.width; return getLeftBoundary() + _size.width;
} }
float Widget::getTopInParent() float Widget::getTopBoundary() const
{ {
return getBottomInParent() + _size.height; return getBottomBoundary() + _size.height;
} }
const Vec2& Widget::getTouchStartPos() const Vec2& Widget::getTouchStartPos()
@ -868,6 +869,12 @@ void Widget::setLayoutParameter(LayoutParameter *parameter)
return; return;
} }
_layoutParameterDictionary.insert((int)parameter->getLayoutType(), parameter); _layoutParameterDictionary.insert((int)parameter->getLayoutType(), parameter);
_layoutParameterType = parameter->getLayoutType();
}
LayoutParameter* Widget::getLayoutParameter()
{
return dynamic_cast<LayoutParameter*>(_layoutParameterDictionary.at((int)_layoutParameterType));
} }
LayoutParameter* Widget::getLayoutParameter(LayoutParameter::Type type) LayoutParameter* Widget::getLayoutParameter(LayoutParameter::Type type)

View File

@ -28,6 +28,7 @@ THE SOFTWARE.
#include "ui/CCProtectedNode.h" #include "ui/CCProtectedNode.h"
#include "ui/UILayoutParameter.h" #include "ui/UILayoutParameter.h"
#include "ui/GUIDefine.h" #include "ui/GUIDefine.h"
#include "ui/UILayoutParameter.h"
NS_CC_BEGIN NS_CC_BEGIN
@ -57,7 +58,7 @@ CC_DEPRECATED_ATTRIBUTE typedef void (Ref::*SEL_TouchEvent)(Ref*,TouchEventType)
#endif #endif
class Widget : public ProtectedNode class Widget : public ProtectedNode, public LayoutParameterProtocol
{ {
public: public:
enum class FocusDirection enum class FocusDirection
@ -200,28 +201,32 @@ public:
* *
* @return The left boundary position of this widget. * @return The left boundary position of this widget.
*/ */
float getLeftInParent(); CC_DEPRECATED_ATTRIBUTE float getLeftInParent(){return this->getLeftBoundary();}
float getLeftBoundary() const;
/** /**
* Gets the bottom boundary position of this widget. * Gets the bottom boundary position of this widget.
* *
* @return The bottom boundary position of this widget. * @return The bottom boundary position of this widget.
*/ */
float getBottomInParent(); CC_DEPRECATED_ATTRIBUTE float getBottomInParent(){return this->getBottomBoundary();}
float getBottomBoundary() const;
/** /**
* Gets the right boundary position of this widget. * Gets the right boundary position of this widget.
* *
* @return The right boundary position of this widget. * @return The right boundary position of this widget.
*/ */
float getRightInParent(); CC_DEPRECATED_ATTRIBUTE float getRightInParent(){return this->getRightBoundary();}
float getRightBoundary() const;
/** /**
* Gets the top boundary position of this widget. * Gets the top boundary position of this widget.
* *
* @return The top boundary position of this widget. * @return The top boundary position of this widget.
*/ */
float getTopInParent(); CC_DEPRECATED_ATTRIBUTE float getTopInParent(){return this->getTopBoundary();}
float getTopBoundary() const;
/** /**
* Gets a child from the container with its name * Gets a child from the container with its name
@ -479,7 +484,9 @@ public:
* *
* @return LayoutParameter * @return LayoutParameter
*/ */
LayoutParameter* getLayoutParameter(LayoutParameter::Type type); LayoutParameter* getLayoutParameter() override;
CC_DEPRECATED_ATTRIBUTE LayoutParameter* getLayoutParameter(LayoutParameter::Type type);
/** /**
* Ignore the widget size * Ignore the widget size
@ -667,9 +674,12 @@ protected:
Size _size; Size _size;
Size _customSize; Size _customSize;
bool _ignoreSize; bool _ignoreSize;
bool _affectByClipping;
SizeType _sizeType; SizeType _sizeType;
Vec2 _sizePercent; Vec2 _sizePercent;
bool _affectByClipping;
PositionType _positionType; PositionType _positionType;
Vec2 _positionPercent; Vec2 _positionPercent;
bool _reorderWidgetChildDirty; bool _reorderWidgetChildDirty;
@ -679,7 +689,9 @@ protected:
GLubyte _opacity; GLubyte _opacity;
bool _flippedX; bool _flippedX;
bool _flippedY; bool _flippedY;
Map<int, LayoutParameter*> _layoutParameterDictionary; //use map to enble switch back and forth for user layout parameters
Map<int,LayoutParameter*> _layoutParameterDictionary;
LayoutParameter::Type _layoutParameterType;
bool _focused; bool _focused;
bool _focusEnabled; bool _focusEnabled;

View File

@ -19,6 +19,7 @@
<ClInclude Include="..\UIHelper.h" /> <ClInclude Include="..\UIHelper.h" />
<ClInclude Include="..\UIImageView.h" /> <ClInclude Include="..\UIImageView.h" />
<ClInclude Include="..\UILayout.h" /> <ClInclude Include="..\UILayout.h" />
<ClInclude Include="..\UILayoutExecutant.h" />
<ClInclude Include="..\UILayoutParameter.h" /> <ClInclude Include="..\UILayoutParameter.h" />
<ClInclude Include="..\UIListView.h" /> <ClInclude Include="..\UIListView.h" />
<ClInclude Include="..\UILoadingBar.h" /> <ClInclude Include="..\UILoadingBar.h" />
@ -44,6 +45,7 @@
<ClCompile Include="..\UIHelper.cpp" /> <ClCompile Include="..\UIHelper.cpp" />
<ClCompile Include="..\UIImageView.cpp" /> <ClCompile Include="..\UIImageView.cpp" />
<ClCompile Include="..\UILayout.cpp" /> <ClCompile Include="..\UILayout.cpp" />
<ClCompile Include="..\UILayoutExecutant.cpp" />
<ClCompile Include="..\UILayoutParameter.cpp" /> <ClCompile Include="..\UILayoutParameter.cpp" />
<ClCompile Include="..\UIListView.cpp" /> <ClCompile Include="..\UIListView.cpp" />
<ClCompile Include="..\UILoadingBar.cpp" /> <ClCompile Include="..\UILoadingBar.cpp" />

View File

@ -87,6 +87,9 @@
<ClInclude Include="..\UIVBox.h"> <ClInclude Include="..\UIVBox.h">
<Filter>Layouts</Filter> <Filter>Layouts</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\UILayoutExecutant.h">
<Filter>Layouts</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\UIScrollView.cpp"> <ClCompile Include="..\UIScrollView.cpp">
@ -155,5 +158,8 @@
<ClCompile Include="..\UIVBox.cpp"> <ClCompile Include="..\UIVBox.cpp">
<Filter>Layouts</Filter> <Filter>Layouts</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\UILayoutExecutant.cpp">
<Filter>Layouts</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -60,13 +60,13 @@ bool UIScrollViewTest_Vertical::init()
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button"); titleButton->setTitleText("Title Button");
titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomInParent() - button->getSize().height)); titleButton->setPosition(Vec2(innerWidth / 2.0f, button->getBottomBoundary() - button->getSize().height));
scrollView->addChild(titleButton); scrollView->addChild(titleButton);
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); button_scale9->setScale9Enabled(true);
button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomInParent() - titleButton->getSize().height)); button_scale9->setPosition(Vec2(innerWidth / 2.0f, titleButton->getBottomBoundary() - titleButton->getSize().height));
scrollView->addChild(button_scale9); scrollView->addChild(button_scale9);
imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getSize().height / 2.0f)); imageView->setPosition(Vec2(innerWidth / 2.0f, imageView->getSize().height / 2.0f));
@ -137,19 +137,19 @@ bool UIScrollViewTest_Horizontal::init()
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png"); Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
titleButton->setTitleText("Title Button"); titleButton->setTitleText("Title Button");
titleButton->setPosition(Vec2(button->getRightInParent() + button->getSize().width / 2.0f, titleButton->setPosition(Vec2(button->getRightBoundary() + button->getSize().width / 2.0f,
button->getBottomInParent() - button->getSize().height / 2.0f)); button->getBottomBoundary() - button->getSize().height / 2.0f));
scrollView->addChild(titleButton); scrollView->addChild(titleButton);
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png"); Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
button_scale9->setScale9Enabled(true); button_scale9->setScale9Enabled(true);
button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height)); button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
button_scale9->setPosition(Vec2(titleButton->getRightInParent() + titleButton->getSize().width / 2.0f, button_scale9->setPosition(Vec2(titleButton->getRightBoundary() + titleButton->getSize().width / 2.0f,
titleButton->getBottomInParent() - titleButton->getSize().height / 2.0f)); titleButton->getBottomBoundary() - titleButton->getSize().height / 2.0f));
scrollView->addChild(button_scale9); scrollView->addChild(button_scale9);
imageView->setPosition(Vec2(innerWidth - imageView->getSize().width / 2.0f, imageView->setPosition(Vec2(innerWidth - imageView->getSize().width / 2.0f,
button_scale9->getBottomInParent() - button_scale9->getSize().height / 2.0f)); button_scale9->getBottomBoundary() - button_scale9->getSize().height / 2.0f));
scrollView->addChild(imageView); scrollView->addChild(imageView);
return true; return true;