mirror of https://github.com/axmolengine/axmol.git
Add clone method to LayoutParameter
This commit is contained in:
parent
602133a071
commit
bea46fa290
|
@ -1,26 +1,26 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.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:
|
||||
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 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.
|
||||
****************************************************************************/
|
||||
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 "gui/UILayoutParameter.h"
|
||||
#include "gui/UILayout.h"
|
||||
|
@ -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
|
|
@ -1,26 +1,26 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.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:
|
||||
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 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.
|
||||
****************************************************************************/
|
||||
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 __LAYOUTPARMETER_H__
|
||||
#define __LAYOUTPARMETER_H__
|
||||
|
@ -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