Revert "Merge pull request #6752 from andyque/refactorLayout"

This reverts commit ae118a9d22, reversing
changes made to 6f2f2046c7.
This commit is contained in:
andyque 2014-05-20 14:36:29 +08:00
parent 84fa60e171
commit 1ed9b9749e
17 changed files with 955 additions and 1163 deletions

View File

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

View File

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

View File

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

View File

@ -32,12 +32,532 @@ THE SOFTWARE.
#include "renderer/CCRenderer.h"
#include "renderer/CCGroupCommand.h"
#include "renderer/CCCustomCommand.h"
#include "ui/UILayoutExecutant.h"
NS_CC_BEGIN
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 BCAKGROUNDCOLORRENDERER_Z = (-2);
@ -84,6 +604,7 @@ _currentAlphaTestFunc(GL_ALWAYS),
_currentAlphaTestRef(1),
_backGroundImageColor(Color3B::WHITE),
_backGroundImageOpacity(255),
_curLayoutExecutant(nullptr),
_passFocusToChild(true),
_loopFocus(false)
{
@ -94,6 +615,7 @@ _loopFocus(false)
Layout::~Layout()
{
CC_SAFE_RELEASE(_clippingStencil);
CC_SAFE_RELEASE(_curLayoutExecutant);
}
void Layout::onEnter()
@ -658,7 +1180,7 @@ void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
case Type::HORIZONTAL:
case Type::VERTICAL:
{
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR));
if (!layoutParameter)
{
child->setLayoutParameter(LinearLayoutParameter::create());
@ -667,7 +1189,7 @@ void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
}
case Type::RELATIVE:
{
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter());
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE));
if (!layoutParameter)
{
child->setLayoutParameter(RelativeLayoutParameter::create());
@ -905,7 +1427,9 @@ const Size& Layout::getBackGroundImageTextureSize() const
void Layout::setLayoutType(Type type)
{
_layoutType = type;
CC_SAFE_RELEASE_NULL(_curLayoutExecutant);
_curLayoutExecutant = createCurrentLayoutExecutant();
CC_SAFE_RETAIN(_curLayoutExecutant);
for (auto& child : _children)
{
Widget* widgetChild = dynamic_cast<Widget*>(child);
@ -917,29 +1441,7 @@ void Layout::setLayoutType(Type type)
_doLayoutDirty = true;
}
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* Layout::createCurrentLayoutExecutant()
{
LayoutExecutant* exe = nullptr;
switch (_layoutType)
@ -957,7 +1459,16 @@ LayoutExecutant* Layout::createLayoutExecutant()
break;
}
return exe;
}
Layout::Type Layout::getLayoutType() const
{
return _layoutType;
}
void Layout::requestDoLayout()
{
_doLayoutDirty = true;
}
void Layout::doLayout()
@ -966,13 +1477,10 @@ void Layout::doLayout()
{
return;
}
LayoutExecutant* executant = this->createLayoutExecutant();
if (executant)
if (_curLayoutExecutant)
{
executant->doLayout(this);
_curLayoutExecutant->doLayout(getSize(), getChildren());
}
_doLayoutDirty = false;
}
@ -1031,7 +1539,7 @@ bool Layout::isPassFocusToChild()
return _passFocusToChild;
}
Size Layout::getLayoutAccumulatedSize()const
Size Layout::getLayoutContentSize()const
{
const auto& children = this->getChildren();
Size layoutSize = Size::ZERO;
@ -1041,7 +1549,7 @@ Size Layout::getLayoutAccumulatedSize()const
Layout *layout = dynamic_cast<Layout*>(widget);
if (nullptr != layout)
{
layoutSize = layoutSize + layout->getLayoutAccumulatedSize();
layoutSize = layoutSize + layout->getLayoutContentSize();
}
else
{
@ -1049,7 +1557,7 @@ Size Layout::getLayoutAccumulatedSize()const
if (w)
{
widgetCount++;
Margin m = w->getLayoutParameter()->getMargin();
Margin m = w->getLayoutParameter(LayoutParameter::Type::LINEAR)->getMargin();
layoutSize = layoutSize + w->getSize() + Size(m.right + m.left, m.top + m.bottom) * 0.5;
}
}
@ -1072,7 +1580,7 @@ Vec2 Layout::getWorldCenterPoint(Widget* widget)
{
Layout *layout = dynamic_cast<Layout*>(widget);
//FIXEDME: we don't need to calculate the content size of layout anymore
Size widgetSize = layout ? layout->getLayoutAccumulatedSize() : widget->getSize();
Size widgetSize = layout ? layout->getLayoutContentSize() : widget->getSize();
// CCLOG("contnet size : width = %f, height = %f", widgetSize.width, widgetSize.height);
return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2));
}

View File

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

View File

@ -1,513 +0,0 @@
/****************************************************************************
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;
}
}
}
}
void RelativeLayoutExecutant::doLayout(LayoutProtocol *layout)
{
Size layoutSize = layout->getLayoutContentSize();
Vector<Node*> container = layout->getLayoutElements();
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->_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());
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());
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 locationTop = relativeWidget->getTopBoundary();
float locationLeft = relativeWidget->getLeftBoundary();
finalPosY = locationTop + 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 locationTop = relativeWidget->getTopBoundary();
finalPosY = locationTop + ap.y * cs.height;
finalPosX = 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)
{
continue;
}
float locationTop = relativeWidget->getTopBoundary();
float locationRight = relativeWidget->getRightBoundary();
finalPosY = locationTop + 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->getTopBoundary();
float locationLeft = relativeWidget->getLeftBoundary();
finalPosY = locationTop - (1.0f - ap.y) * cs.height;
finalPosX = locationLeft - (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 locationLeft = relativeWidget->getLeftBoundary();
finalPosX = locationLeft - (1.0f - ap.x) * cs.width;
finalPosY = 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)
{
continue;
}
float locationBottom = relativeWidget->getBottomBoundary();
float locationLeft = relativeWidget->getLeftBoundary();
finalPosY = locationBottom + ap.y * cs.height;
finalPosX = locationLeft - (1.0f - ap.x) * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_TOPALIGN:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
float locationTop = relativeWidget->getTopBoundary();
float locationRight = relativeWidget->getRightBoundary();
finalPosY = locationTop - (1.0f - ap.y) * cs.height;
finalPosX = locationRight + ap.x * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_RIGHT_OF_CENTER:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
Size rbs = relativeWidget->getSize();
float locationRight = relativeWidget->getRightBoundary();
finalPosX = locationRight + ap.x * cs.width;
finalPosY = 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)
{
continue;
}
float locationBottom = relativeWidget->getBottomBoundary();
float locationRight = relativeWidget->getRightBoundary();
finalPosY = locationBottom + ap.y * cs.height;
finalPosX = locationRight + ap.x * cs.width;
}
break;
case RelativeLayoutParameter::RelativeAlign::LOCATION_BELOW_LEFTALIGN:
if (relativeWidget)
{
if (relativeWidgetLP && !relativeWidgetLP->_put)
{
continue;
}
float locationBottom = relativeWidget->getBottomBoundary();
float locationLeft = relativeWidget->getLeftBoundary();
finalPosY = locationBottom - (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 locationBottom = relativeWidget->getBottomBoundary();
finalPosY = locationBottom - (1.0f - ap.y) * cs.height;
finalPosX = 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)
{
continue;
}
float locationBottom = relativeWidget->getBottomBoundary();
float locationRight = relativeWidget->getRightBoundary();
finalPosY = locationBottom - (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();
}
}
NS_CC_END

View File

@ -1,75 +0,0 @@
/****************************************************************************
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"
NS_CC_BEGIN
namespace ui {
class LayoutProtocol;
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(){};
virtual ~RelativeLayoutExecutant(){};
static RelativeLayoutExecutant* create();
virtual void doLayout(LayoutProtocol *layout) override;
};
}
NS_CC_END
#endif /* defined(__cocos2d_libs__CCLayoutExecutant__) */

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -357,13 +357,7 @@ protected:
void startBounceChildren(float v);
void stopBounceChildren();
bool checkCustomScrollDestination(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);
void startRecordSlidAction();
virtual void endRecordSlidAction();

View File

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

View File

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

View File

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

View File

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

View File

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