issue #5047, refactor LayoutParameterType

This commit is contained in:
andyque 2014-05-09 17:38:05 +08:00
parent d12a71f738
commit 0c0f18e7f3
7 changed files with 44 additions and 26 deletions

View File

@ -52,6 +52,9 @@ CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_NONE = La
CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_SOLID = Layout::BackGroundColorType::SOLID;
CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_GRADIENT
= Layout::BackGroundColorType::GRADIENT;
CC_DEPRECATED_ATTRIBUTE const LayoutParameter::Type LAYOUT_PARAMETER_NONE = LayoutParameter::Type::NONE;
CC_DEPRECATED_ATTRIBUTE const LayoutParameter::Type LAYOUT_PARAMETER_LINEAR = LayoutParameter::Type::LINEAR;
CC_DEPRECATED_ATTRIBUTE const LayoutParameter::Type LAYOUT_PARAMETER_RELATIVE = LayoutParameter::Type::RELATIVE;
@ -63,6 +66,7 @@ CC_DEPRECATED_ATTRIBUTE typedef Widget::BrightStyle BrightStyle;
CC_DEPRECATED_ATTRIBUTE typedef Layout::ClippingType LayoutClippingType;
CC_DEPRECATED_ATTRIBUTE typedef Layout::LayoutType LayoutType;
CC_DEPRECATED_ATTRIBUTE typedef Layout::BackGroundColorType LayoutBackGroundColorType;
CC_DEPRECATED_ATTRIBUTE typedef LayoutParameter::Type LayoutParameterType;
}

View File

@ -130,7 +130,7 @@ void LinearVerticalLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Ve
Widget* child = dynamic_cast<Widget*>(subWidget);
if (child)
{
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR));
if (layoutParameter)
{
@ -171,7 +171,7 @@ void LinearHorizontalLayoutExecutant::doLayout(const cocos2d::Size &layoutSize,
Widget* child = dynamic_cast<Widget*>(subWidget);
if (child)
{
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR));
if (layoutParameter)
{
LinearGravity childGravity = layoutParameter->getGravity();
@ -212,7 +212,7 @@ void RelativeLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Vector<c
Widget* child = dynamic_cast<Widget*>(subWidget);
if (child)
{
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE));
layoutParameter->_put = false;
unlayoutChildCount++;
widgetChildren.pushBack(child);
@ -223,7 +223,7 @@ void RelativeLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Vector<c
for (auto& subWidget : widgetChildren)
{
Widget* child = static_cast<Widget*>(subWidget);
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE));
if (layoutParameter)
{
@ -245,7 +245,7 @@ void RelativeLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Vector<c
{
if (sWidget)
{
RelativeLayoutParameter* rlayoutParameter = dynamic_cast<RelativeLayoutParameter*>(sWidget->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
RelativeLayoutParameter* rlayoutParameter = dynamic_cast<RelativeLayoutParameter*>(sWidget->getLayoutParameter(LayoutParameter::Type::RELATIVE));
if (rlayoutParameter && strcmp(rlayoutParameter->getRelativeName(), relativeName) == 0)
{
relativeWidget = sWidget;
@ -1180,7 +1180,7 @@ void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
case LayoutType::HORIZONTAL:
case LayoutType::VERTICAL:
{
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR));
if (!layoutParameter)
{
child->setLayoutParameter(LinearLayoutParameter::create());
@ -1189,7 +1189,7 @@ void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
}
case LayoutType::RELATIVE:
{
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE));
if (!layoutParameter)
{
child->setLayoutParameter(RelativeLayoutParameter::create());
@ -1557,7 +1557,7 @@ Size Layout::getLayoutContentSize()const
if (w)
{
widgetCount++;
Margin m = w->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)->getMargin();
Margin m = w->getLayoutParameter(LayoutParameter::Type::LINEAR)->getMargin();
layoutSize = layoutSize + w->getSize() + Size(m.right + m.left, m.top + m.bottom) * 0.5;
}
}

View File

@ -83,7 +83,7 @@ const Margin& LayoutParameter::getMargin() const
return _margin;
}
LayoutParameterType LayoutParameter::getLayoutType() const
LayoutParameter::Type LayoutParameter::getLayoutType() const
{
return _layoutParameterType;
}

View File

@ -56,12 +56,6 @@ public:
const Margin MarginZero = Margin();
typedef enum
{
LAYOUT_PARAMETER_NONE,
LAYOUT_PARAMETER_LINEAR,
LAYOUT_PARAMETER_RELATIVE
}LayoutParameterType;
typedef enum
{
@ -107,10 +101,19 @@ typedef enum
class LayoutParameter : public Ref
{
public:
enum class Type : int
{
NONE = 0,
LINEAR,
RELATIVE
};
/**
* Default constructor
*/
LayoutParameter() : _margin(Margin()){_layoutParameterType = LAYOUT_PARAMETER_NONE;};
LayoutParameter() : _margin(Margin())
{
_layoutParameterType = Type::NONE;
};
/**
* Default destructor
@ -148,14 +151,14 @@ public:
*
* @return LayoutParameterType
*/
LayoutParameterType getLayoutType() const;
Type getLayoutType() const;
LayoutParameter* clone();
virtual LayoutParameter* createCloneInstance();
virtual void copyProperties(LayoutParameter* model);
protected:
Margin _margin;
LayoutParameterType _layoutParameterType;
Type _layoutParameterType;
};
/**
* @js NA
@ -167,7 +170,10 @@ public:
/**
* Default constructor
*/
LinearLayoutParameter() : _linearGravity(LINEAR_GRAVITY_NONE){_layoutParameterType = LAYOUT_PARAMETER_LINEAR;};
LinearLayoutParameter() : _linearGravity(LINEAR_GRAVITY_NONE)
{
_layoutParameterType = Type::LINEAR;
};
/**
* Default destructor
@ -213,7 +219,14 @@ public:
/**
* Default constructor
*/
RelativeLayoutParameter() : _relativeAlign(RELATIVE_ALIGN_NONE),_relativeWidgetName(""),_relativeLayoutName(""),_put(false){_layoutParameterType = LAYOUT_PARAMETER_RELATIVE;};
RelativeLayoutParameter()
: _relativeAlign(RELATIVE_ALIGN_NONE),
_relativeWidgetName(""),
_relativeLayoutName(""),
_put(false)
{
_layoutParameterType = Type::RELATIVE;
};
/**
* Default destructor

View File

@ -129,7 +129,7 @@ void ListView::remedyLayoutParameter(Widget *item)
switch (_direction) {
case SCROLLVIEW_DIR_VERTICAL:
{
LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LayoutParameter::Type::LINEAR));
if (!llp)
{
LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
@ -184,7 +184,7 @@ void ListView::remedyLayoutParameter(Widget *item)
}
case SCROLLVIEW_DIR_HORIZONTAL:
{
LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LayoutParameter::Type::LINEAR));
if (!llp)
{
LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();

View File

@ -845,12 +845,12 @@ void Widget::setLayoutParameter(LayoutParameter *parameter)
{
return;
}
_layoutParameterDictionary.insert(parameter->getLayoutType(), parameter);
_layoutParameterDictionary.insert((int)parameter->getLayoutType(), parameter);
}
LayoutParameter* Widget::getLayoutParameter(LayoutParameterType type)
LayoutParameter* Widget::getLayoutParameter(LayoutParameter::Type type)
{
return dynamic_cast<LayoutParameter*>(_layoutParameterDictionary.at(type));
return dynamic_cast<LayoutParameter*>(_layoutParameterDictionary.at((int)type));
}
std::string Widget::getDescription() const
@ -920,6 +920,7 @@ void Widget::copyProperties(Widget *widget)
setFlippedY(widget->isFlippedY());
setColor(widget->getColor());
setOpacity(widget->getOpacity());
//FIXME:copy focus properties, also make sure all the subclass the copy behavior is correct
Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary;
for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter)
{

View File

@ -490,7 +490,7 @@ public:
*
* @return LayoutParameter
*/
LayoutParameter* getLayoutParameter(LayoutParameterType type);
LayoutParameter* getLayoutParameter(LayoutParameter::Type type);
/**
* Ignore the widget size