mirror of https://github.com/axmolengine/axmol.git
Add clone method to LayoutParameter
This commit is contained in:
parent
602133a071
commit
bea46fa290
|
@ -57,6 +57,23 @@ LayoutParameterType LayoutParameter::getLayoutType() const
|
|||
return _layoutParameterType;
|
||||
}
|
||||
|
||||
LayoutParameter* LayoutParameter::clone()
|
||||
{
|
||||
LayoutParameter* clonedParameter = createCloneInstance();
|
||||
clonedParameter->copyProperties(this);
|
||||
return clonedParameter;
|
||||
}
|
||||
|
||||
LayoutParameter* LayoutParameter::createCloneInstance()
|
||||
{
|
||||
return LayoutParameter::create();
|
||||
}
|
||||
|
||||
void LayoutParameter::copyProperties(LayoutParameter *model)
|
||||
{
|
||||
_margin = model->_margin;
|
||||
}
|
||||
|
||||
LinearLayoutParameter* LinearLayoutParameter::create()
|
||||
{
|
||||
LinearLayoutParameter* parameter = new LinearLayoutParameter();
|
||||
|
@ -79,6 +96,21 @@ LinearGravity LinearLayoutParameter::getGravity() const
|
|||
return _linearGravity;
|
||||
}
|
||||
|
||||
LayoutParameter* LinearLayoutParameter::createCloneInstance()
|
||||
{
|
||||
return LinearLayoutParameter::create();
|
||||
}
|
||||
|
||||
void LinearLayoutParameter::copyProperties(LayoutParameter *model)
|
||||
{
|
||||
LayoutParameter::copyProperties(model);
|
||||
LinearLayoutParameter* parameter = dynamic_cast<LinearLayoutParameter*>(model);
|
||||
if (parameter)
|
||||
{
|
||||
setGravity(parameter->_linearGravity);
|
||||
}
|
||||
}
|
||||
|
||||
RelativeLayoutParameter* RelativeLayoutParameter::create()
|
||||
{
|
||||
RelativeLayoutParameter* parameter = new RelativeLayoutParameter();
|
||||
|
@ -121,6 +153,23 @@ const char* RelativeLayoutParameter::getRelativeName() const
|
|||
return _relativeLayoutName.c_str();
|
||||
}
|
||||
|
||||
LayoutParameter* RelativeLayoutParameter::createCloneInstance()
|
||||
{
|
||||
return RelativeLayoutParameter::create();
|
||||
}
|
||||
|
||||
void RelativeLayoutParameter::copyProperties(LayoutParameter *model)
|
||||
{
|
||||
LayoutParameter::copyProperties(model);
|
||||
RelativeLayoutParameter* parameter = dynamic_cast<RelativeLayoutParameter*>(model);
|
||||
if (parameter)
|
||||
{
|
||||
setAlign(parameter->_relativeAlign);
|
||||
setRelativeName(parameter->_relativeLayoutName.c_str());
|
||||
setRelativeToWidgetName(parameter->_relativeWidgetName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -86,6 +86,10 @@ public:
|
|||
* @return LayoutParameterType
|
||||
*/
|
||||
LayoutParameterType getLayoutType() const;
|
||||
|
||||
LayoutParameter* clone();
|
||||
virtual LayoutParameter* createCloneInstance();
|
||||
virtual void copyProperties(LayoutParameter* model);
|
||||
protected:
|
||||
Margin _margin;
|
||||
LayoutParameterType _layoutParameterType;
|
||||
|
@ -130,6 +134,8 @@ public:
|
|||
* @return LinearGravity
|
||||
*/
|
||||
LinearGravity getGravity() const;
|
||||
virtual LayoutParameter* createCloneInstance();
|
||||
virtual void copyProperties(LayoutParameter* model);
|
||||
protected:
|
||||
LinearGravity _linearGravity;
|
||||
};
|
||||
|
@ -202,6 +208,9 @@ public:
|
|||
* @return name
|
||||
*/
|
||||
const char* getRelativeName() const;
|
||||
|
||||
virtual LayoutParameter* createCloneInstance();
|
||||
virtual void copyProperties(LayoutParameter* model);
|
||||
protected:
|
||||
RelativeAlign _relativeAlign;
|
||||
std::string _relativeWidgetName;
|
||||
|
|
|
@ -334,6 +334,7 @@ void LoadingBar::copySpecialProperties(Widget *widget)
|
|||
loadTexture(loadingBar->_textureFile.c_str(), loadingBar->_renderBarTexType);
|
||||
setCapInsets(loadingBar->_capInsets);
|
||||
setPercent(loadingBar->_percent);
|
||||
setDirection(loadingBar->_barType);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1065,6 +1065,11 @@ void Widget::copyProperties(Widget *widget)
|
|||
setOpacity(widget->getOpacity());
|
||||
setCascadeOpacityEnabled(widget->isCascadeOpacityEnabled());
|
||||
setCascadeColorEnabled(widget->isCascadeColorEnabled());
|
||||
Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary;
|
||||
for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter)
|
||||
{
|
||||
setLayoutParameter(iter->second->clone());
|
||||
}
|
||||
onSizeChanged();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue