mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3774 from nutty898/optimize_layout
[develop] [GUI] Optimize layout
This commit is contained in:
commit
6ded79111b
|
@ -1 +1 @@
|
||||||
2abd573d3cb41c16925cbdf14bd55be5f97d88a4
|
a87ed79f8ef68972cf8791008b9d79f2a5ed84f1
|
|
@ -63,7 +63,6 @@ CocoStudio/Components/CCInputDelegate.cpp \
|
||||||
CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
|
CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
|
||||||
CocoStudio/GUI/BaseClasses/UIWidget.cpp \
|
CocoStudio/GUI/BaseClasses/UIWidget.cpp \
|
||||||
CocoStudio/GUI/Layouts/Layout.cpp \
|
CocoStudio/GUI/Layouts/Layout.cpp \
|
||||||
CocoStudio/GUI/Layouts/LayoutExecutant.cpp \
|
|
||||||
CocoStudio/GUI/Layouts/LayoutParameter.cpp \
|
CocoStudio/GUI/Layouts/LayoutParameter.cpp \
|
||||||
CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
|
CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
|
||||||
CocoStudio/GUI/System/CocosGUI.cpp \
|
CocoStudio/GUI/System/CocosGUI.cpp \
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "Layout.h"
|
#include "Layout.h"
|
||||||
#include "../System/UILayer.h"
|
#include "../System/UILayer.h"
|
||||||
|
#include "../System/UIHelper.h"
|
||||||
#include "../../../GUI/CCControlExtension/CCScale9Sprite.h"
|
#include "../../../GUI/CCControlExtension/CCScale9Sprite.h"
|
||||||
|
|
||||||
NS_CC_EXT_BEGIN
|
NS_CC_EXT_BEGIN
|
||||||
|
@ -32,7 +33,6 @@ NS_CC_EXT_BEGIN
|
||||||
|
|
||||||
Layout::Layout():
|
Layout::Layout():
|
||||||
_clippingEnabled(false),
|
_clippingEnabled(false),
|
||||||
_layoutExecutant(NULL),
|
|
||||||
_backGroundScale9Enabled(false),
|
_backGroundScale9Enabled(false),
|
||||||
_backGroundImage(NULL),
|
_backGroundImage(NULL),
|
||||||
_backGroundImageFileName(""),
|
_backGroundImageFileName(""),
|
||||||
|
@ -46,14 +46,14 @@ _gStartColor(Color3B::WHITE),
|
||||||
_gEndColor(Color3B::WHITE),
|
_gEndColor(Color3B::WHITE),
|
||||||
_alongVector(Point(0.0f, -1.0f)),
|
_alongVector(Point(0.0f, -1.0f)),
|
||||||
_cOpacity(255),
|
_cOpacity(255),
|
||||||
_backGroundImageTextureSize(Size::ZERO)
|
_backGroundImageTextureSize(Size::ZERO),
|
||||||
|
_layoutType(LAYOUT_ABSOLUTE)
|
||||||
{
|
{
|
||||||
_widgetType = WidgetTypeContainer;
|
_widgetType = WidgetTypeContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
Layout::~Layout()
|
Layout::~Layout()
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE_NULL(_layoutExecutant);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Layout* Layout::create()
|
Layout* Layout::create()
|
||||||
|
@ -90,22 +90,6 @@ bool Layout::init()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::setLayoutExecutant(LayoutExecutant *exe)
|
|
||||||
{
|
|
||||||
if (_layoutExecutant)
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE_NULL(_layoutExecutant);
|
|
||||||
}
|
|
||||||
_layoutExecutant = exe;
|
|
||||||
_layoutExecutant->setLayout(this);
|
|
||||||
CC_SAFE_RETAIN(_layoutExecutant);
|
|
||||||
}
|
|
||||||
|
|
||||||
LayoutExecutant* Layout::getLayoutExecutant() const
|
|
||||||
{
|
|
||||||
return _layoutExecutant;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layout::initRenderer()
|
void Layout::initRenderer()
|
||||||
{
|
{
|
||||||
_renderer = RectClippingNode::create();
|
_renderer = RectClippingNode::create();
|
||||||
|
@ -136,10 +120,7 @@ void Layout::setClippingEnabled(bool able)
|
||||||
void Layout::onSizeChanged()
|
void Layout::onSizeChanged()
|
||||||
{
|
{
|
||||||
DYNAMIC_CAST_CLIPPINGLAYER->setClippingSize(_size);
|
DYNAMIC_CAST_CLIPPINGLAYER->setClippingSize(_size);
|
||||||
if (_layoutExecutant)
|
doLayout();
|
||||||
{
|
|
||||||
_layoutExecutant->doLayout();
|
|
||||||
}
|
|
||||||
if (_backGroundImage)
|
if (_backGroundImage)
|
||||||
{
|
{
|
||||||
_backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f));
|
_backGroundImage->setPosition(Point(_size.width/2.0f, _size.height/2.0f));
|
||||||
|
@ -425,6 +406,283 @@ const Size& Layout::getContentSize() const
|
||||||
return _renderer->getContentSize();
|
return _renderer->getContentSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Layout::setLayoutType(LayoutType type)
|
||||||
|
{
|
||||||
|
_layoutType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
LayoutType Layout::getLayoutType() const
|
||||||
|
{
|
||||||
|
return _layoutType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layout::doLayout()
|
||||||
|
{
|
||||||
|
switch (_layoutType)
|
||||||
|
{
|
||||||
|
case LAYOUT_ABSOLUTE:
|
||||||
|
break;
|
||||||
|
case LAYOUT_LINEAR_VERTICAL:
|
||||||
|
{
|
||||||
|
ccArray* layoutChildrenArray = getChildren()->data;
|
||||||
|
int length = layoutChildrenArray->num;
|
||||||
|
Size layoutSize = getSize();
|
||||||
|
float topBoundary = layoutSize.height;
|
||||||
|
for (int i=0; i<length; ++i)
|
||||||
|
{
|
||||||
|
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
|
||||||
|
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
|
||||||
|
|
||||||
|
if (layoutParameter)
|
||||||
|
{
|
||||||
|
WidgetType childType = child->getWidgetType();
|
||||||
|
UILinearGravity childGravity = layoutParameter->getGravity();
|
||||||
|
Point ap = child->getAnchorPoint();
|
||||||
|
Size cs = child->getSize();
|
||||||
|
float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f;
|
||||||
|
float finalPosY = childType == WidgetTypeWidget ? topBoundary - ((1.0f-ap.y) * cs.height) : topBoundary - cs.height;
|
||||||
|
switch (childGravity)
|
||||||
|
{
|
||||||
|
case LINEAR_GRAVITY_NONE:
|
||||||
|
case LINEAR_GRAVITY_LEFT:
|
||||||
|
break;
|
||||||
|
case LINEAR_GRAVITY_RIGHT:
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width;
|
||||||
|
break;
|
||||||
|
case LINEAR_GRAVITY_CENTER_HORIZONTAL:
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? layoutSize.width / 2.0f - cs.width * (0.5f-ap.x) : (layoutSize.width - cs.width) * 0.5f;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
UIMargin mg = layoutParameter->getMargin();
|
||||||
|
finalPosX += mg.left;
|
||||||
|
finalPosY -= mg.top;
|
||||||
|
child->setPosition(Point(finalPosX, finalPosY));
|
||||||
|
topBoundary = child->getBottomInParent() - mg.bottom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LAYOUT_LINEAR_HORIZONTAL:
|
||||||
|
{
|
||||||
|
ccArray* layoutChildrenArray = getChildren()->data;
|
||||||
|
int length = layoutChildrenArray->num;
|
||||||
|
Size layoutSize = getSize();
|
||||||
|
float leftBoundary = 0.0f;
|
||||||
|
for (int i=0; i<length; ++i)
|
||||||
|
{
|
||||||
|
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
|
||||||
|
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
|
||||||
|
|
||||||
|
if (layoutParameter)
|
||||||
|
{
|
||||||
|
WidgetType childType = child->getWidgetType();
|
||||||
|
UILinearGravity childGravity = layoutParameter->getGravity();
|
||||||
|
Point ap = child->getAnchorPoint();
|
||||||
|
Size cs = child->getSize();
|
||||||
|
float finalPosX = childType == WidgetTypeWidget ? leftBoundary + (ap.x * cs.width) : leftBoundary;
|
||||||
|
float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - (1.0f - ap.y) * cs.height : layoutSize.height - cs.height;
|
||||||
|
switch (childGravity)
|
||||||
|
{
|
||||||
|
case LINEAR_GRAVITY_NONE:
|
||||||
|
case LINEAR_GRAVITY_TOP:
|
||||||
|
break;
|
||||||
|
case LINEAR_GRAVITY_BOTTOM:
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f;
|
||||||
|
break;
|
||||||
|
case LINEAR_GRAVITY_CENTER_VERTICAL:
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? layoutSize.height/2.0f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
UIMargin mg = layoutParameter->getMargin();
|
||||||
|
finalPosX += mg.left;
|
||||||
|
finalPosY -= mg.top;
|
||||||
|
child->setPosition(Point(finalPosX, finalPosY));
|
||||||
|
leftBoundary = child->getRightInParent() + mg.right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LAYOUT_RELATIVE:
|
||||||
|
{
|
||||||
|
ccArray* layoutChildrenArray = getChildren()->data;
|
||||||
|
int length = layoutChildrenArray->num;
|
||||||
|
Size layoutSize = getSize();
|
||||||
|
for (int i=0; i<length; i++)
|
||||||
|
{
|
||||||
|
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
|
||||||
|
WidgetType childType = child->getWidgetType();
|
||||||
|
Point ap = child->getAnchorPoint();
|
||||||
|
Size cs = child->getSize();
|
||||||
|
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter());
|
||||||
|
if (layoutParameter)
|
||||||
|
{
|
||||||
|
float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f;
|
||||||
|
float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - ((1.0f - ap.y) * cs.height) : layoutSize.height - cs.height;
|
||||||
|
UIRelativeAlign align = layoutParameter->getAlign();
|
||||||
|
const char* relativeName = layoutParameter->getRelativeToWidgetName();
|
||||||
|
UIWidget* relativeWidget = NULL;
|
||||||
|
if (relativeName && strcmp(relativeName, ""))
|
||||||
|
{
|
||||||
|
relativeWidget = CCUIHELPER->seekWidgetByRelativeName(this, relativeName);
|
||||||
|
}
|
||||||
|
switch (align)
|
||||||
|
{
|
||||||
|
case RELATIVE_ALIGN_NONE:
|
||||||
|
break;
|
||||||
|
case RELATIVE_ALIGN_PARENT_LEFT:
|
||||||
|
break;
|
||||||
|
case RELATIVE_ALIGN_PARENT_TOP:
|
||||||
|
break;
|
||||||
|
case RELATIVE_ALIGN_PARENT_RIGHT:
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width;
|
||||||
|
break;
|
||||||
|
case RELATIVE_ALIGN_PARENT_BOTTOM:
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f;
|
||||||
|
break;
|
||||||
|
case RELATIVE_CENTER_IN_PARENT:
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f;
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
|
||||||
|
break;
|
||||||
|
case RELATIVE_CENTER_HORIZONTAL:
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f;
|
||||||
|
break;
|
||||||
|
case RELATIVE_CENTER_VERTICAL:
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
|
||||||
|
if (relativeWidget)
|
||||||
|
{
|
||||||
|
float locationTop = relativeWidget->getTopInParent();
|
||||||
|
float locationRight = relativeWidget->getLeftInParent();
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height;
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_LEFT_OF_CENTER:
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
|
||||||
|
if (relativeWidget)
|
||||||
|
{
|
||||||
|
float locationRight = relativeWidget->getLeftInParent();
|
||||||
|
float locationBottom = relativeWidget->getBottomInParent();
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
|
||||||
|
if (relativeWidget)
|
||||||
|
{
|
||||||
|
float locationTop = relativeWidget->getTopInParent();
|
||||||
|
float locationLeft = relativeWidget->getRightInParent();
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height;
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
|
||||||
|
if (relativeWidget)
|
||||||
|
{
|
||||||
|
float locationLeft = relativeWidget->getRightInParent();
|
||||||
|
float locationBottom = relativeWidget->getBottomInParent();
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
|
||||||
|
if (relativeWidget)
|
||||||
|
{
|
||||||
|
float locationBottom = relativeWidget->getTopInParent();
|
||||||
|
float locationLeft = relativeWidget->getLeftInParent();
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_ABOVE_CENTER:
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
|
||||||
|
if (relativeWidget)
|
||||||
|
{
|
||||||
|
float locationBottom = relativeWidget->getTopInParent();
|
||||||
|
float locationRight = relativeWidget->getRightInParent();
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
|
||||||
|
if (relativeWidget)
|
||||||
|
{
|
||||||
|
float locationTop = relativeWidget->getBottomInParent();
|
||||||
|
float locationLeft = relativeWidget->getLeftInParent();
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height;
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_BELOW_CENTER:
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
|
||||||
|
if (relativeWidget)
|
||||||
|
{
|
||||||
|
float locationTop = relativeWidget->getBottomInParent();
|
||||||
|
float locationRight = relativeWidget->getRightInParent();
|
||||||
|
finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height;
|
||||||
|
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
UIMargin relativeWidgetMargin;
|
||||||
|
UIMargin mg;
|
||||||
|
if (relativeWidget)
|
||||||
|
{
|
||||||
|
relativeWidgetMargin = relativeWidget->getLayoutParameter()->getMargin();
|
||||||
|
mg = child->getLayoutParameter()->getMargin();
|
||||||
|
}
|
||||||
|
//handle margin
|
||||||
|
switch (align)
|
||||||
|
{
|
||||||
|
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
|
||||||
|
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
|
||||||
|
case RELATIVE_LOCATION_ABOVE_CENTER:
|
||||||
|
finalPosY += relativeWidgetMargin.top;
|
||||||
|
finalPosY += mg.bottom;
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
|
||||||
|
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
|
||||||
|
case RELATIVE_LOCATION_BELOW_CENTER:
|
||||||
|
finalPosY -= relativeWidgetMargin.bottom;
|
||||||
|
finalPosY -= mg.top;
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
|
||||||
|
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
|
||||||
|
case RELATIVE_LOCATION_LEFT_OF_CENTER:
|
||||||
|
finalPosX -= relativeWidgetMargin.left;
|
||||||
|
finalPosX -= mg.right;
|
||||||
|
break;
|
||||||
|
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
|
||||||
|
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
|
||||||
|
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
|
||||||
|
finalPosX += relativeWidgetMargin.right;
|
||||||
|
finalPosX += mg.left;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
child->setPosition(Point(finalPosX, finalPosY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char* Layout::getDescription() const
|
const char* Layout::getDescription() const
|
||||||
{
|
{
|
||||||
return "Layout";
|
return "Layout";
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#define __LAYOUT_H__
|
#define __LAYOUT_H__
|
||||||
|
|
||||||
#include "../BaseClasses/UIWidget.h"
|
#include "../BaseClasses/UIWidget.h"
|
||||||
#include "LayoutExecutant.h"
|
|
||||||
|
|
||||||
NS_CC_EXT_BEGIN
|
NS_CC_EXT_BEGIN
|
||||||
|
|
||||||
|
@ -37,6 +36,14 @@ typedef enum
|
||||||
LAYOUT_COLOR_GRADIENT
|
LAYOUT_COLOR_GRADIENT
|
||||||
}LayoutBackGroundColorType;
|
}LayoutBackGroundColorType;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
LAYOUT_ABSOLUTE,
|
||||||
|
LAYOUT_LINEAR_VERTICAL,
|
||||||
|
LAYOUT_LINEAR_HORIZONTAL,
|
||||||
|
LAYOUT_RELATIVE
|
||||||
|
}LayoutType;
|
||||||
|
|
||||||
class Layout : public UIWidget
|
class Layout : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -55,24 +62,6 @@ public:
|
||||||
*/
|
*/
|
||||||
static Layout* create();
|
static Layout* create();
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a LayoutExecutant for doing layout.
|
|
||||||
*
|
|
||||||
* @see LayoutExecutant
|
|
||||||
*
|
|
||||||
* @param LayoutExecutant pointer.
|
|
||||||
*/
|
|
||||||
virtual void setLayoutExecutant(LayoutExecutant* exe);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the LayoutExecutant of Layout
|
|
||||||
*
|
|
||||||
* @see LayoutExecutant
|
|
||||||
*
|
|
||||||
* @return LayoutExecutant pointer.
|
|
||||||
*/
|
|
||||||
virtual LayoutExecutant* getLayoutExecutant() const;
|
|
||||||
|
|
||||||
//override "hitTest" method of widget.
|
//override "hitTest" method of widget.
|
||||||
virtual bool hitTest(const Point &pt);
|
virtual bool hitTest(const Point &pt);
|
||||||
|
|
||||||
|
@ -178,6 +167,26 @@ public:
|
||||||
* Content size is widget's texture size.
|
* Content size is widget's texture size.
|
||||||
*/
|
*/
|
||||||
virtual const Size& getContentSize() const;
|
virtual const Size& getContentSize() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets LayoutType.
|
||||||
|
*
|
||||||
|
* @see LayoutType
|
||||||
|
*
|
||||||
|
* @param LayoutType
|
||||||
|
*/
|
||||||
|
virtual void setLayoutType(LayoutType type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets LayoutType.
|
||||||
|
*
|
||||||
|
* @see LayoutType
|
||||||
|
*
|
||||||
|
* @return LayoutType
|
||||||
|
*/
|
||||||
|
virtual LayoutType getLayoutType() const;
|
||||||
|
|
||||||
|
virtual void doLayout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the "class name" of widget.
|
* Returns the "class name" of widget.
|
||||||
|
@ -197,7 +206,6 @@ protected:
|
||||||
void addBackGroundImage();
|
void addBackGroundImage();
|
||||||
protected:
|
protected:
|
||||||
bool _clippingEnabled;
|
bool _clippingEnabled;
|
||||||
LayoutExecutant* _layoutExecutant;
|
|
||||||
|
|
||||||
//background
|
//background
|
||||||
bool _backGroundScale9Enabled;
|
bool _backGroundScale9Enabled;
|
||||||
|
@ -214,6 +222,7 @@ protected:
|
||||||
Point _alongVector;
|
Point _alongVector;
|
||||||
int _cOpacity;
|
int _cOpacity;
|
||||||
Size _backGroundImageTextureSize;
|
Size _backGroundImageTextureSize;
|
||||||
|
LayoutType _layoutType;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RectClippingNode : public ClippingNode
|
class RectClippingNode : public ClippingNode
|
||||||
|
|
|
@ -1,342 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2013 cocos2d-x.org
|
|
||||||
|
|
||||||
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 "LayoutExecutant.h"
|
|
||||||
#include "Layout.h"
|
|
||||||
#include "../System/UIHelper.h"
|
|
||||||
|
|
||||||
NS_CC_EXT_BEGIN
|
|
||||||
|
|
||||||
void LayoutExecutant::setLayout(Layout *layout)
|
|
||||||
{
|
|
||||||
_layout = layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
Layout* LayoutExecutant::getLayout() const
|
|
||||||
{
|
|
||||||
return _layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
LinearVerticalLayoutExecutant* LinearVerticalLayoutExecutant::create()
|
|
||||||
{
|
|
||||||
LinearVerticalLayoutExecutant* executant = new LinearVerticalLayoutExecutant();
|
|
||||||
if (executant)
|
|
||||||
{
|
|
||||||
executant->autorelease();
|
|
||||||
return executant;
|
|
||||||
}
|
|
||||||
CC_SAFE_DELETE(executant);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
LinearHorizontalLayoutExecutant* LinearHorizontalLayoutExecutant::create()
|
|
||||||
{
|
|
||||||
LinearHorizontalLayoutExecutant* executant = new LinearHorizontalLayoutExecutant();
|
|
||||||
if (executant)
|
|
||||||
{
|
|
||||||
executant->autorelease();
|
|
||||||
return executant;
|
|
||||||
}
|
|
||||||
CC_SAFE_DELETE(executant);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
RelativeLayoutExecutant* RelativeLayoutExecutant::create()
|
|
||||||
{
|
|
||||||
RelativeLayoutExecutant* executant = new RelativeLayoutExecutant();
|
|
||||||
if (executant)
|
|
||||||
{
|
|
||||||
executant->autorelease();
|
|
||||||
return executant;
|
|
||||||
}
|
|
||||||
CC_SAFE_DELETE(executant);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LinearVerticalLayoutExecutant::doLayout()
|
|
||||||
{
|
|
||||||
if (_layout)
|
|
||||||
{
|
|
||||||
ccArray* layoutChildrenArray = _layout->getChildren()->data;
|
|
||||||
int length = layoutChildrenArray->num;
|
|
||||||
Size layoutSize = _layout->getSize();
|
|
||||||
float topBoundary = layoutSize.height;
|
|
||||||
for (int i=0; i<length; ++i)
|
|
||||||
{
|
|
||||||
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
|
|
||||||
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
|
|
||||||
|
|
||||||
if (layoutParameter)
|
|
||||||
{
|
|
||||||
WidgetType childType = child->getWidgetType();
|
|
||||||
UILinearGravity childGravity = layoutParameter->getGravity();
|
|
||||||
Point ap = child->getAnchorPoint();
|
|
||||||
Size cs = child->getSize();
|
|
||||||
float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f;
|
|
||||||
float finalPosY = childType == WidgetTypeWidget ? topBoundary - ((1.0f-ap.y) * cs.height) : topBoundary - cs.height;
|
|
||||||
switch (childGravity)
|
|
||||||
{
|
|
||||||
case LINEAR_GRAVITY_NONE:
|
|
||||||
case LINEAR_GRAVITY_LEFT:
|
|
||||||
break;
|
|
||||||
case LINEAR_GRAVITY_RIGHT:
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width;
|
|
||||||
break;
|
|
||||||
case LINEAR_GRAVITY_CENTER_HORIZONTAL:
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? layoutSize.width / 2.0f - cs.width * (0.5f-ap.x) : (layoutSize.width - cs.width) * 0.5f;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
UIMargin mg = layoutParameter->getMargin();
|
|
||||||
finalPosX += mg.left;
|
|
||||||
finalPosY -= mg.top;
|
|
||||||
child->setPosition(Point(finalPosX, finalPosY));
|
|
||||||
topBoundary = child->getBottomInParent() - mg.bottom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LinearHorizontalLayoutExecutant::doLayout()
|
|
||||||
{
|
|
||||||
if (_layout)
|
|
||||||
{
|
|
||||||
ccArray* layoutChildrenArray = _layout->getChildren()->data;
|
|
||||||
int length = layoutChildrenArray->num;
|
|
||||||
Size layoutSize = _layout->getSize();
|
|
||||||
float leftBoundary = 0.0f;
|
|
||||||
for (int i=0; i<length; ++i)
|
|
||||||
{
|
|
||||||
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
|
|
||||||
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter());
|
|
||||||
|
|
||||||
if (layoutParameter)
|
|
||||||
{
|
|
||||||
WidgetType childType = child->getWidgetType();
|
|
||||||
UILinearGravity childGravity = layoutParameter->getGravity();
|
|
||||||
Point ap = child->getAnchorPoint();
|
|
||||||
Size cs = child->getSize();
|
|
||||||
float finalPosX = childType == WidgetTypeWidget ? leftBoundary + (ap.x * cs.width) : leftBoundary;
|
|
||||||
float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - (1.0f - ap.y) * cs.height : layoutSize.height - cs.height;
|
|
||||||
switch (childGravity)
|
|
||||||
{
|
|
||||||
case LINEAR_GRAVITY_NONE:
|
|
||||||
case LINEAR_GRAVITY_TOP:
|
|
||||||
break;
|
|
||||||
case LINEAR_GRAVITY_BOTTOM:
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f;
|
|
||||||
break;
|
|
||||||
case LINEAR_GRAVITY_CENTER_VERTICAL:
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? layoutSize.height/2.0f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
UIMargin mg = layoutParameter->getMargin();
|
|
||||||
finalPosX += mg.left;
|
|
||||||
finalPosY -= mg.top;
|
|
||||||
child->setPosition(Point(finalPosX, finalPosY));
|
|
||||||
leftBoundary = child->getRightInParent() + mg.right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RelativeLayoutExecutant::doLayout()
|
|
||||||
{
|
|
||||||
if (_layout)
|
|
||||||
{
|
|
||||||
ccArray* layoutChildrenArray = _layout->getChildren()->data;
|
|
||||||
int length = layoutChildrenArray->num;
|
|
||||||
Size layoutSize = _layout->getSize();
|
|
||||||
for (int i=0; i<length; i++)
|
|
||||||
{
|
|
||||||
UIWidget* child = dynamic_cast<UIWidget*>(layoutChildrenArray->arr[i]);
|
|
||||||
WidgetType childType = child->getWidgetType();
|
|
||||||
Point ap = child->getAnchorPoint();
|
|
||||||
Size cs = child->getSize();
|
|
||||||
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter());
|
|
||||||
if (layoutParameter)
|
|
||||||
{
|
|
||||||
float finalPosX = childType == WidgetTypeWidget ? ap.x * cs.width : 0.0f;
|
|
||||||
float finalPosY = childType == WidgetTypeWidget ? layoutSize.height - ((1.0f - ap.y) * cs.height) : layoutSize.height - cs.height;
|
|
||||||
UIRelativeAlign align = layoutParameter->getAlign();
|
|
||||||
const char* relativeName = layoutParameter->getRelativeToWidgetName();
|
|
||||||
UIWidget* relativeWidget = NULL;
|
|
||||||
if (relativeName && strcmp(relativeName, ""))
|
|
||||||
{
|
|
||||||
relativeWidget = CCUIHELPER->seekWidgetByRelativeName(_layout, relativeName);
|
|
||||||
}
|
|
||||||
switch (align)
|
|
||||||
{
|
|
||||||
case RELATIVE_ALIGN_NONE:
|
|
||||||
break;
|
|
||||||
case RELATIVE_ALIGN_PARENT_LEFT:
|
|
||||||
break;
|
|
||||||
case RELATIVE_ALIGN_PARENT_TOP:
|
|
||||||
break;
|
|
||||||
case RELATIVE_ALIGN_PARENT_RIGHT:
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? layoutSize.width - ((1.0f - ap.x) * cs.width) : layoutSize.width - cs.width;
|
|
||||||
break;
|
|
||||||
case RELATIVE_ALIGN_PARENT_BOTTOM:
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? ap.y * cs.height : 0.0f;
|
|
||||||
break;
|
|
||||||
case RELATIVE_CENTER_IN_PARENT:
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f;
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
|
|
||||||
break;
|
|
||||||
case RELATIVE_CENTER_HORIZONTAL:
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? layoutSize.width * 0.5f - cs.width * (0.5f - ap.x) : (layoutSize.width - cs.width) * 0.5f;
|
|
||||||
break;
|
|
||||||
case RELATIVE_CENTER_VERTICAL:
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? layoutSize.height * 0.5f - cs.height * (0.5f - ap.y) : (layoutSize.height - cs.height) * 0.5f;
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
|
|
||||||
if (relativeWidget)
|
|
||||||
{
|
|
||||||
float locationTop = relativeWidget->getTopInParent();
|
|
||||||
float locationRight = relativeWidget->getLeftInParent();
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height;
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_LEFT_OF_CENTER:
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
|
|
||||||
if (relativeWidget)
|
|
||||||
{
|
|
||||||
float locationRight = relativeWidget->getLeftInParent();
|
|
||||||
float locationBottom = relativeWidget->getBottomInParent();
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
|
|
||||||
if (relativeWidget)
|
|
||||||
{
|
|
||||||
float locationTop = relativeWidget->getTopInParent();
|
|
||||||
float locationLeft = relativeWidget->getRightInParent();
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? locationTop - ap.y * cs.height : locationTop - cs.height;
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
|
|
||||||
if (relativeWidget)
|
|
||||||
{
|
|
||||||
float locationLeft = relativeWidget->getRightInParent();
|
|
||||||
float locationBottom = relativeWidget->getBottomInParent();
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
|
|
||||||
if (relativeWidget)
|
|
||||||
{
|
|
||||||
float locationBottom = relativeWidget->getTopInParent();
|
|
||||||
float locationLeft = relativeWidget->getLeftInParent();
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_ABOVE_CENTER:
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
|
|
||||||
if (relativeWidget)
|
|
||||||
{
|
|
||||||
float locationBottom = relativeWidget->getTopInParent();
|
|
||||||
float locationRight = relativeWidget->getRightInParent();
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? locationBottom + ap.y * cs.height : locationBottom;
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
|
|
||||||
if (relativeWidget)
|
|
||||||
{
|
|
||||||
float locationTop = relativeWidget->getBottomInParent();
|
|
||||||
float locationLeft = relativeWidget->getLeftInParent();
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height;
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? locationLeft + ap.x * cs.width : locationLeft;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_BELOW_CENTER:
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
|
|
||||||
if (relativeWidget)
|
|
||||||
{
|
|
||||||
float locationTop = relativeWidget->getBottomInParent();
|
|
||||||
float locationRight = relativeWidget->getRightInParent();
|
|
||||||
finalPosY = childType == WidgetTypeWidget ? locationTop - (1.0f - ap.y) * cs.height : locationTop - cs.height;
|
|
||||||
finalPosX = childType == WidgetTypeWidget ? locationRight - (1.0f - ap.x) * cs.width : locationRight - cs.width;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
UIMargin relativeWidgetMargin;
|
|
||||||
UIMargin mg;
|
|
||||||
if (relativeWidget)
|
|
||||||
{
|
|
||||||
relativeWidgetMargin = relativeWidget->getLayoutParameter()->getMargin();
|
|
||||||
mg = child->getLayoutParameter()->getMargin();
|
|
||||||
}
|
|
||||||
//handle margin
|
|
||||||
switch (align)
|
|
||||||
{
|
|
||||||
case RELATIVE_LOCATION_ABOVE_LEFTALIGN:
|
|
||||||
case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:
|
|
||||||
case RELATIVE_LOCATION_ABOVE_CENTER:
|
|
||||||
finalPosY += relativeWidgetMargin.top;
|
|
||||||
finalPosY += mg.bottom;
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_BELOW_LEFTALIGN:
|
|
||||||
case RELATIVE_LOCATION_BELOW_RIGHTALIGN:
|
|
||||||
case RELATIVE_LOCATION_BELOW_CENTER:
|
|
||||||
finalPosY -= relativeWidgetMargin.bottom;
|
|
||||||
finalPosY -= mg.top;
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:
|
|
||||||
case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:
|
|
||||||
case RELATIVE_LOCATION_LEFT_OF_CENTER:
|
|
||||||
finalPosX -= relativeWidgetMargin.left;
|
|
||||||
finalPosX -= mg.right;
|
|
||||||
break;
|
|
||||||
case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:
|
|
||||||
case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:
|
|
||||||
case RELATIVE_LOCATION_RIGHT_OF_CENTER:
|
|
||||||
finalPosX += relativeWidgetMargin.right;
|
|
||||||
finalPosX += mg.left;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
child->setPosition(Point(finalPosX, finalPosY));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_EXT_END
|
|
|
@ -1,158 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2013 cocos2d-x.org
|
|
||||||
|
|
||||||
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 __LAYOUTEXECUTANT_H__
|
|
||||||
#define __LAYOUTEXECUTANT_H__
|
|
||||||
|
|
||||||
#include "LayoutParameter.h"
|
|
||||||
|
|
||||||
NS_CC_EXT_BEGIN
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
LAYOUT_DEFAULT,
|
|
||||||
LAYOUT_LINEAR_VERTICAL,
|
|
||||||
LAYOUT_LINEAR_HORIZONTAL,
|
|
||||||
LAYOUT_RELATIVE
|
|
||||||
}LayoutType;
|
|
||||||
|
|
||||||
class Layout;
|
|
||||||
|
|
||||||
class LayoutExecutant : public Object
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Default constructor
|
|
||||||
*/
|
|
||||||
LayoutExecutant() : _layout(NULL){_layoutType = LAYOUT_DEFAULT;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default destructor
|
|
||||||
*/
|
|
||||||
virtual ~LayoutExecutant(){_layout = NULL;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To do layout. Need to be overrided.
|
|
||||||
*/
|
|
||||||
virtual void doLayout()=0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets LayoutType.
|
|
||||||
*
|
|
||||||
* @see LayoutType
|
|
||||||
*
|
|
||||||
* @return LayoutType
|
|
||||||
*/
|
|
||||||
LayoutType getLayoutType(){return _layoutType;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binding a Layout to LayoutExecutant.
|
|
||||||
*
|
|
||||||
* @param Layout
|
|
||||||
*/
|
|
||||||
void setLayout(Layout* layout);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Layout of LayoutExecutant.
|
|
||||||
*
|
|
||||||
* @return Layout
|
|
||||||
*/
|
|
||||||
Layout* getLayout() const;
|
|
||||||
protected:
|
|
||||||
LayoutType _layoutType;
|
|
||||||
Layout* _layout;
|
|
||||||
};
|
|
||||||
|
|
||||||
class LinearVerticalLayoutExecutant : public LayoutExecutant
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Default constructor
|
|
||||||
*/
|
|
||||||
LinearVerticalLayoutExecutant(){_layoutType = LAYOUT_LINEAR_VERTICAL;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default destructor
|
|
||||||
*/
|
|
||||||
virtual ~LinearVerticalLayoutExecutant(){};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocates and initializes.
|
|
||||||
* @return A initialized LayoutExecutant which is marked as "autorelease".
|
|
||||||
*/
|
|
||||||
static LinearVerticalLayoutExecutant* create();
|
|
||||||
|
|
||||||
//To do layout.
|
|
||||||
virtual void doLayout();
|
|
||||||
};
|
|
||||||
|
|
||||||
class LinearHorizontalLayoutExecutant : public LayoutExecutant
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Default constructor
|
|
||||||
*/
|
|
||||||
LinearHorizontalLayoutExecutant(){_layoutType = LAYOUT_LINEAR_HORIZONTAL;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default destructor
|
|
||||||
*/
|
|
||||||
virtual ~LinearHorizontalLayoutExecutant(){};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocates and initializes.
|
|
||||||
* @return A initialized LayoutExecutant which is marked as "autorelease".
|
|
||||||
*/
|
|
||||||
static LinearHorizontalLayoutExecutant* create();
|
|
||||||
|
|
||||||
//To do layout.
|
|
||||||
virtual void doLayout();
|
|
||||||
};
|
|
||||||
|
|
||||||
class RelativeLayoutExecutant : public LayoutExecutant
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Default constructor
|
|
||||||
*/
|
|
||||||
RelativeLayoutExecutant(){_layoutType = LAYOUT_RELATIVE;};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default destructor
|
|
||||||
*/
|
|
||||||
virtual ~RelativeLayoutExecutant(){};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocates and initializes.
|
|
||||||
* @return A initialized LayoutExecutant which is marked as "autorelease".
|
|
||||||
*/
|
|
||||||
static RelativeLayoutExecutant* create();
|
|
||||||
|
|
||||||
//To do layout.
|
|
||||||
virtual void doLayout();
|
|
||||||
};
|
|
||||||
|
|
||||||
NS_CC_EXT_END
|
|
||||||
|
|
||||||
#endif /* defined(__LayoutExecutant__) */
|
|
|
@ -51,11 +51,7 @@ void LayoutParameter::setMargin(const UIMargin &margin)
|
||||||
Layout* containerParent = dynamic_cast<Layout*>(parent);
|
Layout* containerParent = dynamic_cast<Layout*>(parent);
|
||||||
if (containerParent)
|
if (containerParent)
|
||||||
{
|
{
|
||||||
LayoutExecutant* exe = containerParent->getLayoutExecutant();
|
containerParent->doLayout();
|
||||||
if (exe)
|
|
||||||
{
|
|
||||||
exe->doLayout();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,10 +91,9 @@ void LinearLayoutParameter::setGravity(UILinearGravity gravity)
|
||||||
Layout* containerParent = dynamic_cast<Layout*>(parent);
|
Layout* containerParent = dynamic_cast<Layout*>(parent);
|
||||||
if (containerParent)
|
if (containerParent)
|
||||||
{
|
{
|
||||||
LayoutExecutant* exe = containerParent->getLayoutExecutant();
|
if ((containerParent->getLayoutType() == LAYOUT_LINEAR_HORIZONTAL || containerParent->getLayoutType() == LAYOUT_LINEAR_VERTICAL))
|
||||||
if (exe && (exe->getLayoutType() == LAYOUT_LINEAR_HORIZONTAL || exe->getLayoutType() == LAYOUT_LINEAR_VERTICAL))
|
|
||||||
{
|
{
|
||||||
exe->doLayout();
|
containerParent->doLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,10 +129,9 @@ void RelativeLayoutParameter::setAlign(UIRelativeAlign align)
|
||||||
Layout* containerParent = dynamic_cast<Layout*>(parent);
|
Layout* containerParent = dynamic_cast<Layout*>(parent);
|
||||||
if (containerParent)
|
if (containerParent)
|
||||||
{
|
{
|
||||||
LayoutExecutant* exe = containerParent->getLayoutExecutant();
|
if ((containerParent->getLayoutType() == LAYOUT_RELATIVE))
|
||||||
if (exe && (exe->getLayoutType() == LAYOUT_RELATIVE))
|
|
||||||
{
|
{
|
||||||
exe->doLayout();
|
containerParent->doLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,10 +155,9 @@ void RelativeLayoutParameter::setRelativeToWidgetName(const char *name)
|
||||||
Layout* containerParent = dynamic_cast<Layout*>(parent);
|
Layout* containerParent = dynamic_cast<Layout*>(parent);
|
||||||
if (containerParent)
|
if (containerParent)
|
||||||
{
|
{
|
||||||
LayoutExecutant* exe = containerParent->getLayoutExecutant();
|
if ((containerParent->getLayoutType() == LAYOUT_RELATIVE))
|
||||||
if (exe && (exe->getLayoutType() == LAYOUT_RELATIVE))
|
|
||||||
{
|
{
|
||||||
exe->doLayout();
|
containerParent->doLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,10 +181,9 @@ void RelativeLayoutParameter::setRelativeName(const char* name)
|
||||||
Layout* containerParent = dynamic_cast<Layout*>(parent);
|
Layout* containerParent = dynamic_cast<Layout*>(parent);
|
||||||
if (containerParent)
|
if (containerParent)
|
||||||
{
|
{
|
||||||
LayoutExecutant* exe = containerParent->getLayoutExecutant();
|
if ((containerParent->getLayoutType() == LAYOUT_RELATIVE))
|
||||||
if (exe && (exe->getLayoutType() == LAYOUT_RELATIVE))
|
|
||||||
{
|
{
|
||||||
exe->doLayout();
|
containerParent->doLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
#include "UIHelper.h"
|
#include "UIHelper.h"
|
||||||
#include "../../Reader/CCSGUIReader.h"
|
#include "../../Reader/CCSGUIReader.h"
|
||||||
#include "UILayer.h"
|
#include "UILayer.h"
|
||||||
#include "../Layouts/LayoutExecutant.h"
|
|
||||||
NS_CC_EXT_BEGIN
|
NS_CC_EXT_BEGIN
|
||||||
|
|
||||||
const char* CocosGUIVersion();
|
const char* CocosGUIVersion();
|
||||||
|
|
|
@ -1244,6 +1244,21 @@ Layout* UIDragPanel::getInnerContainer()
|
||||||
return _innerContainer;
|
return _innerContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIDragPanel::setLayoutType(LayoutType type)
|
||||||
|
{
|
||||||
|
_innerContainer->setLayoutType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
LayoutType UIDragPanel::getLayoutType() const
|
||||||
|
{
|
||||||
|
return _innerContainer->getLayoutType();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIDragPanel::doLayout()
|
||||||
|
{
|
||||||
|
_innerContainer->doLayout();
|
||||||
|
}
|
||||||
|
|
||||||
const char* UIDragPanel::getDescription() const
|
const char* UIDragPanel::getDescription() const
|
||||||
{
|
{
|
||||||
return "DragPanel";
|
return "DragPanel";
|
||||||
|
|
|
@ -191,6 +191,26 @@ public:
|
||||||
*/
|
*/
|
||||||
Layout* getInnerContainer();
|
Layout* getInnerContainer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets LayoutType.
|
||||||
|
*
|
||||||
|
* @see LayoutType
|
||||||
|
*
|
||||||
|
* @param LayoutType
|
||||||
|
*/
|
||||||
|
virtual void setLayoutType(LayoutType type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets LayoutType.
|
||||||
|
*
|
||||||
|
* @see LayoutType
|
||||||
|
*
|
||||||
|
* @return LayoutType
|
||||||
|
*/
|
||||||
|
virtual LayoutType getLayoutType() const;
|
||||||
|
|
||||||
|
virtual void doLayout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the "class name" of widget.
|
* Returns the "class name" of widget.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -139,6 +139,8 @@ public:
|
||||||
/**/
|
/**/
|
||||||
virtual void update(float dt);
|
virtual void update(float dt);
|
||||||
|
|
||||||
|
virtual void doLayout(){};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the "class name" of widget.
|
* Returns the "class name" of widget.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -138,6 +138,8 @@ public:
|
||||||
|
|
||||||
//override "update" method of widget.
|
//override "update" method of widget.
|
||||||
virtual void update(float dt);
|
virtual void update(float dt);
|
||||||
|
|
||||||
|
virtual void doLayout(){};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the "class name" of widget.
|
* Returns the "class name" of widget.
|
||||||
|
|
|
@ -664,14 +664,19 @@ Layout* UIScrollView::getInnerContainer()
|
||||||
return _innerContainer;
|
return _innerContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIScrollView::setLayoutExecutant(LayoutExecutant *exe)
|
void UIScrollView::setLayoutType(LayoutType type)
|
||||||
{
|
{
|
||||||
_innerContainer->setLayoutExecutant(exe);
|
_innerContainer->setLayoutType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutExecutant* UIScrollView::getLayoutExecutant() const
|
LayoutType UIScrollView::getLayoutType() const
|
||||||
{
|
{
|
||||||
return _innerContainer->getLayoutExecutant();
|
return _innerContainer->getLayoutType();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIScrollView::doLayout()
|
||||||
|
{
|
||||||
|
_innerContainer->doLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* UIScrollView::getDescription() const
|
const char* UIScrollView::getDescription() const
|
||||||
|
|
|
@ -135,13 +135,7 @@ public:
|
||||||
* Add call back function called scrollview event triggered
|
* Add call back function called scrollview event triggered
|
||||||
*/
|
*/
|
||||||
void addEventListener(Object* target, SEL_ScrollViewEvent selector);
|
void addEventListener(Object* target, SEL_ScrollViewEvent selector);
|
||||||
|
|
||||||
//override "setLayoutExecutant" method of widget.
|
|
||||||
virtual void setLayoutExecutant(LayoutExecutant* exe);
|
|
||||||
|
|
||||||
//override "getLayoutExecutant" method of widget.
|
|
||||||
virtual LayoutExecutant* getLayoutExecutant() const;
|
|
||||||
|
|
||||||
//override "addChild" method of widget.
|
//override "addChild" method of widget.
|
||||||
virtual bool addChild(UIWidget* widget);
|
virtual bool addChild(UIWidget* widget);
|
||||||
|
|
||||||
|
@ -171,6 +165,26 @@ public:
|
||||||
|
|
||||||
virtual void update(float dt);
|
virtual void update(float dt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets LayoutType.
|
||||||
|
*
|
||||||
|
* @see LayoutType
|
||||||
|
*
|
||||||
|
* @param LayoutType
|
||||||
|
*/
|
||||||
|
virtual void setLayoutType(LayoutType type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets LayoutType.
|
||||||
|
*
|
||||||
|
* @see LayoutType
|
||||||
|
*
|
||||||
|
* @return LayoutType
|
||||||
|
*/
|
||||||
|
virtual LayoutType getLayoutType() const;
|
||||||
|
|
||||||
|
virtual void doLayout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the "class name" of widget.
|
* Returns the "class name" of widget.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -86,7 +86,6 @@ SOURCES = ../CCBReader/CCBFileLoader.cpp \
|
||||||
../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
|
../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
|
||||||
../CocoStudio/GUI/BaseClasses/UIWidget.cpp \
|
../CocoStudio/GUI/BaseClasses/UIWidget.cpp \
|
||||||
../CocoStudio/GUI/Layouts/Layout.cpp \
|
../CocoStudio/GUI/Layouts/Layout.cpp \
|
||||||
../CocoStudio/GUI/Layouts/LayoutExecutant.cpp \
|
|
||||||
../CocoStudio/GUI/Layouts/LayoutParameter.cpp \
|
../CocoStudio/GUI/Layouts/LayoutParameter.cpp \
|
||||||
../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
|
../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
|
||||||
../CocoStudio/GUI/System/CocosGUI.cpp \
|
../CocoStudio/GUI/System/CocosGUI.cpp \
|
||||||
|
|
|
@ -84,7 +84,6 @@ SOURCES = ../CCBReader/CCBFileLoader.cpp \
|
||||||
../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
|
../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
|
||||||
../CocoStudio/GUI/BaseClasses/UIWidget.cpp \
|
../CocoStudio/GUI/BaseClasses/UIWidget.cpp \
|
||||||
../CocoStudio/GUI/Layouts/Layout.cpp \
|
../CocoStudio/GUI/Layouts/Layout.cpp \
|
||||||
../CocoStudio/GUI/Layouts/LayoutExecutant.cpp \
|
|
||||||
../CocoStudio/GUI/Layouts/LayoutParameter.cpp \
|
../CocoStudio/GUI/Layouts/LayoutParameter.cpp \
|
||||||
../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
|
../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
|
||||||
../CocoStudio/GUI/System/CocosGUI.cpp \
|
../CocoStudio/GUI/System/CocosGUI.cpp \
|
||||||
|
|
|
@ -71,7 +71,6 @@ EXTENSIONS_SOURCES = ../CCBReader/CCBFileLoader.cpp \
|
||||||
../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
|
../CocoStudio/GUI/BaseClasses/UIRootWidget.cpp \
|
||||||
../CocoStudio/GUI/BaseClasses/UIWidget.cpp \
|
../CocoStudio/GUI/BaseClasses/UIWidget.cpp \
|
||||||
../CocoStudio/GUI/Layouts/Layout.cpp \
|
../CocoStudio/GUI/Layouts/Layout.cpp \
|
||||||
../CocoStudio/GUI/Layouts/LayoutExecutant.cpp \
|
|
||||||
../CocoStudio/GUI/Layouts/LayoutParameter.cpp \
|
../CocoStudio/GUI/Layouts/LayoutParameter.cpp \
|
||||||
../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
|
../CocoStudio/GUI/Layouts/UILayoutDefine.cpp \
|
||||||
../CocoStudio/GUI/System/CocosGUI.cpp \
|
../CocoStudio/GUI/System/CocosGUI.cpp \
|
||||||
|
|
|
@ -149,7 +149,6 @@
|
||||||
<ClCompile Include="..\CocoStudio\GUI\BaseClasses\UIRootWidget.cpp" />
|
<ClCompile Include="..\CocoStudio\GUI\BaseClasses\UIRootWidget.cpp" />
|
||||||
<ClCompile Include="..\CocoStudio\GUI\BaseClasses\UIWidget.cpp" />
|
<ClCompile Include="..\CocoStudio\GUI\BaseClasses\UIWidget.cpp" />
|
||||||
<ClCompile Include="..\CocoStudio\GUI\Layouts\Layout.cpp" />
|
<ClCompile Include="..\CocoStudio\GUI\Layouts\Layout.cpp" />
|
||||||
<ClCompile Include="..\CocoStudio\GUI\Layouts\LayoutExecutant.cpp" />
|
|
||||||
<ClCompile Include="..\CocoStudio\GUI\Layouts\LayoutParameter.cpp" />
|
<ClCompile Include="..\CocoStudio\GUI\Layouts\LayoutParameter.cpp" />
|
||||||
<ClCompile Include="..\CocoStudio\GUI\Layouts\UILayoutDefine.cpp" />
|
<ClCompile Include="..\CocoStudio\GUI\Layouts\UILayoutDefine.cpp" />
|
||||||
<ClCompile Include="..\CocoStudio\GUI\System\CocosGUI.cpp" />
|
<ClCompile Include="..\CocoStudio\GUI\System\CocosGUI.cpp" />
|
||||||
|
@ -284,7 +283,6 @@
|
||||||
<ClInclude Include="..\CocoStudio\GUI\BaseClasses\UIRootWidget.h" />
|
<ClInclude Include="..\CocoStudio\GUI\BaseClasses\UIRootWidget.h" />
|
||||||
<ClInclude Include="..\CocoStudio\GUI\BaseClasses\UIWidget.h" />
|
<ClInclude Include="..\CocoStudio\GUI\BaseClasses\UIWidget.h" />
|
||||||
<ClInclude Include="..\CocoStudio\GUI\Layouts\Layout.h" />
|
<ClInclude Include="..\CocoStudio\GUI\Layouts\Layout.h" />
|
||||||
<ClInclude Include="..\CocoStudio\GUI\Layouts\LayoutExecutant.h" />
|
|
||||||
<ClInclude Include="..\CocoStudio\GUI\Layouts\LayoutParameter.h" />
|
<ClInclude Include="..\CocoStudio\GUI\Layouts\LayoutParameter.h" />
|
||||||
<ClInclude Include="..\CocoStudio\GUI\Layouts\UILayoutDefine.h" />
|
<ClInclude Include="..\CocoStudio\GUI\Layouts\UILayoutDefine.h" />
|
||||||
<ClInclude Include="..\CocoStudio\GUI\System\CocosGUI.h" />
|
<ClInclude Include="..\CocoStudio\GUI\System\CocosGUI.h" />
|
||||||
|
|
|
@ -436,9 +436,6 @@
|
||||||
<ClCompile Include="..\CocoStudio\GUI\Layouts\Layout.cpp">
|
<ClCompile Include="..\CocoStudio\GUI\Layouts\Layout.cpp">
|
||||||
<Filter>CocoStudio\GUI\Layouts</Filter>
|
<Filter>CocoStudio\GUI\Layouts</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\CocoStudio\GUI\Layouts\LayoutExecutant.cpp">
|
|
||||||
<Filter>CocoStudio\GUI\Layouts</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\CocoStudio\GUI\Layouts\LayoutParameter.cpp">
|
<ClCompile Include="..\CocoStudio\GUI\Layouts\LayoutParameter.cpp">
|
||||||
<Filter>CocoStudio\GUI\Layouts</Filter>
|
<Filter>CocoStudio\GUI\Layouts</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -950,9 +947,6 @@
|
||||||
<ClInclude Include="..\CocoStudio\GUI\Layouts\Layout.h">
|
<ClInclude Include="..\CocoStudio\GUI\Layouts\Layout.h">
|
||||||
<Filter>CocoStudio\GUI\Layouts</Filter>
|
<Filter>CocoStudio\GUI\Layouts</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\CocoStudio\GUI\Layouts\LayoutExecutant.h">
|
|
||||||
<Filter>CocoStudio\GUI\Layouts</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\CocoStudio\GUI\Layouts\LayoutParameter.h">
|
<ClInclude Include="..\CocoStudio\GUI\Layouts\LayoutParameter.h">
|
||||||
<Filter>CocoStudio\GUI\Layouts</Filter>
|
<Filter>CocoStudio\GUI\Layouts</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
@ -362,6 +362,7 @@ bool UIPanelTest_Layout_Linear_Vertical::init()
|
||||||
|
|
||||||
// Create the layout
|
// Create the layout
|
||||||
Layout* layout = Layout::create();
|
Layout* layout = Layout::create();
|
||||||
|
layout->setLayoutType(LAYOUT_LINEAR_VERTICAL);
|
||||||
layout->setSize(Size(280, 150));
|
layout->setSize(Size(280, 150));
|
||||||
Size backgroundSize = background->getSize();
|
Size backgroundSize = background->getSize();
|
||||||
layout->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
|
layout->setPosition(Point((widgetSize.width - backgroundSize.width) / 2 +
|
||||||
|
@ -407,9 +408,7 @@ bool UIPanelTest_Layout_Linear_Vertical::init()
|
||||||
lp3->setMargin(UIMargin(0, 10, 0, 10));
|
lp3->setMargin(UIMargin(0, 10, 0, 10));
|
||||||
|
|
||||||
|
|
||||||
LinearVerticalLayoutExecutant* exe = LinearVerticalLayoutExecutant::create();
|
layout->doLayout();
|
||||||
layout->setLayoutExecutant(exe);
|
|
||||||
exe->doLayout();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -446,6 +445,7 @@ bool UIPanelTest_Layout_Linear_Horizontal::init()
|
||||||
|
|
||||||
// Create the layout
|
// Create the layout
|
||||||
Layout* layout = Layout::create();
|
Layout* layout = Layout::create();
|
||||||
|
layout->setLayoutType(LAYOUT_LINEAR_HORIZONTAL);
|
||||||
layout->setClippingEnabled(true);
|
layout->setClippingEnabled(true);
|
||||||
layout->setSize(Size(280, 150));
|
layout->setSize(Size(280, 150));
|
||||||
Size backgroundSize = background->getSize();
|
Size backgroundSize = background->getSize();
|
||||||
|
@ -491,9 +491,7 @@ bool UIPanelTest_Layout_Linear_Horizontal::init()
|
||||||
lp3->setMargin(UIMargin(0, 10, 0, 10));
|
lp3->setMargin(UIMargin(0, 10, 0, 10));
|
||||||
|
|
||||||
|
|
||||||
LinearHorizontalLayoutExecutant* exe = LinearHorizontalLayoutExecutant::create();
|
layout->doLayout();
|
||||||
layout->setLayoutExecutant(exe);
|
|
||||||
exe->doLayout();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -530,6 +528,7 @@ bool UIPanelTest_Layout_Relative::init()
|
||||||
|
|
||||||
// Create the layout
|
// Create the layout
|
||||||
Layout* layout = Layout::create();
|
Layout* layout = Layout::create();
|
||||||
|
layout->setLayoutType(LAYOUT_RELATIVE);
|
||||||
layout->setSize(Size(280, 150));
|
layout->setSize(Size(280, 150));
|
||||||
layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
|
layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
|
||||||
layout->setBackGroundColor(Color3B::GREEN);
|
layout->setBackGroundColor(Color3B::GREEN);
|
||||||
|
@ -574,9 +573,7 @@ bool UIPanelTest_Layout_Relative::init()
|
||||||
rp3->setAlign(RELATIVE_ALIGN_PARENT_RIGHT);
|
rp3->setAlign(RELATIVE_ALIGN_PARENT_RIGHT);
|
||||||
|
|
||||||
|
|
||||||
RelativeLayoutExecutant* exe = RelativeLayoutExecutant::create();
|
layout->doLayout();
|
||||||
layout->setLayoutExecutant(exe);
|
|
||||||
exe->doLayout();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue