コード例 #1
0
static int lua_cocos2dx_LayoutParameter_getMargin(lua_State* L)
{
    if (nullptr == L)
        return 0;
    
    int argc = 0;
    LayoutParameter* self = nullptr;
    
#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
	if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror;
#endif
    
    self = static_cast<LayoutParameter*>(tolua_tousertype(L,1,0));
    
#if COCOS2D_DEBUG >= 1
	if (nullptr == self) {
		tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_LayoutParameter_getMargin'\n", NULL);
		return 0;
	}
#endif
    argc = lua_gettop(L) - 1;
    
    if (0 == argc)
    {
        Margin margin = self->getMargin();
        
        lua_newtable(L);
        
        lua_pushstring(L, "left");                             
        lua_pushnumber(L, (lua_Number) margin.left);
        lua_rawset(L, -3);
        
        lua_pushstring(L, "top");                             
        lua_pushnumber(L, (lua_Number) margin.top);
        lua_rawset(L, -3);
        
        lua_pushstring(L, "right");
        lua_pushnumber(L, (lua_Number) margin.right);
        lua_rawset(L, -3);
        
        lua_pushstring(L, "bottom");
        lua_pushnumber(L, (lua_Number) margin.bottom);
        lua_rawset(L, -3);
        
        return 1;
    }
    
    CCLOG("'getMargin' function of LayoutParameter has wrong number of arguments: %d, was expecting %d\n", argc, 0);
    
    return 0;
    
#if COCOS2D_DEBUG >= 1
tolua_lerror:
    tolua_error(L,"#ferror in function 'getMargin'.",&tolua_err);
    return 0;
#endif
}
コード例 #2
0
ファイル: UILayoutParameter.cpp プロジェクト: 2193q/cocos2d-x
LayoutParameter* LayoutParameter::create()
{
    LayoutParameter* parameter = new LayoutParameter();
    if (parameter)
    {
        parameter->autorelease();
        return parameter;
    }
    CC_SAFE_DELETE(parameter);
    return NULL;
}
コード例 #3
0
LayoutParameter* LayoutParameter::create()
{
    LayoutParameter* parameter = new (std::nothrow) LayoutParameter();
    if (parameter)
    {
        parameter->autorelease();
        return parameter;
    }
    CC_SAFE_DELETE(parameter);
    return nullptr;
}
コード例 #4
0
static int tolua_Cocos2dx_LayoutParameter_setMargin00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
    tolua_Error tolua_err;
    if (
        !tolua_isusertype(tolua_S,1,"LayoutParameter",0,&tolua_err) ||
        !tolua_istable(tolua_S, 2, 0, &tolua_err) ||
        !tolua_isnoobj(tolua_S,3,&tolua_err)
    )
        goto tolua_lerror;
    else
#endif
    {
        LayoutParameter* self = (LayoutParameter*)  tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
        if (!self) tolua_error(tolua_S,"invalid 'self' in function 'setMargin'", NULL);
#endif
        Margin margin;
        lua_pushstring(tolua_S, "left");
        lua_gettable(tolua_S,2);
        margin.left = lua_isnil(tolua_S,-1) ? 0 : lua_tonumber(tolua_S,-1);
        lua_pop(tolua_S,1);

        lua_pushstring(tolua_S, "top");
        lua_gettable(tolua_S,2);
        margin.top = lua_isnil(tolua_S,-1) ? 0 : lua_tonumber(tolua_S,-1);
        lua_pop(tolua_S,1);

        lua_pushstring(tolua_S, "right");
        lua_gettable(tolua_S,2);
        margin.right = lua_isnil(tolua_S,-1) ? 0 : lua_tonumber(tolua_S,-1);
        lua_pop(tolua_S,1);

        lua_pushstring(tolua_S, "bottom");
        lua_gettable(tolua_S,2);
        margin.bottom = lua_isnil(tolua_S,-1) ? 0 : lua_tonumber(tolua_S,-1);
        lua_pop(tolua_S,1);

        self->setMargin(margin);
    }
    return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'setMargin'.",&tolua_err);
    return 0;
#endif
}
コード例 #5
0
static int tolua_Cocos2dx_LayoutParameter_getMargin00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
    tolua_Error tolua_err;
    if (
        !tolua_isusertype(tolua_S,1,"LayoutParameter",0,&tolua_err) ||
        !tolua_isnoobj(tolua_S,2,&tolua_err)
    )
        goto tolua_lerror;
    else
#endif
    {
        LayoutParameter* self = (LayoutParameter*)  tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
        if (!self) tolua_error(tolua_S,"invalid 'self' in function 'getMargin'", NULL);
#endif
        Margin margin = self->getMargin();

        lua_newtable(tolua_S);

        lua_pushstring(tolua_S, "left");
        lua_pushnumber(tolua_S, (lua_Number) margin.left);
        lua_rawset(tolua_S, -3);

        lua_pushstring(tolua_S, "top");
        lua_pushnumber(tolua_S, (lua_Number) margin.top);
        lua_rawset(tolua_S, -3);

        lua_pushstring(tolua_S, "right");
        lua_pushnumber(tolua_S, (lua_Number) margin.right);
        lua_rawset(tolua_S, -3);

        lua_pushstring(tolua_S, "bottom");
        lua_pushnumber(tolua_S, (lua_Number) margin.bottom);
        lua_rawset(tolua_S, -3);

        return 1;
    }
    return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'getMargin'.",&tolua_err);
    return 0;
#endif
}
コード例 #6
0
static int lua_cocos2dx_LayoutParameter_setMargin(lua_State* L)
{
    if (nullptr == L)
        return 0;
    
    int argc = 0;
    LayoutParameter* self = nullptr;
    
#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
	if (!tolua_isusertype(L,1,"ccui.LayoutParameter",0,&tolua_err)) goto tolua_lerror;
#endif
    
    self = static_cast<LayoutParameter*>(tolua_tousertype(L,1,0));
    
#if COCOS2D_DEBUG >= 1
	if (nullptr == self) {
		tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_LayoutParameter_setMargin'\n", NULL);
		return 0;
	}
#endif
    argc = lua_gettop(L) - 1;
    
    if (1 == argc)
    {
#if COCOS2D_DEBUG >= 1
        if (!tolua_istable(L, 2, 0, &tolua_err))
        {
            goto tolua_lerror;
        }
#endif
        
        Margin margin;
        lua_pushstring(L, "left");
        lua_gettable(L,2);
        margin.left = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1);
        lua_pop(L,1);
            
        lua_pushstring(L, "top");
        lua_gettable(L,2);
        margin.top = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1);
        lua_pop(L,1);
            
        lua_pushstring(L, "right");
        lua_gettable(L,2);
        margin.right = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1);
        lua_pop(L,1);
            
        lua_pushstring(L, "bottom");
        lua_gettable(L,2);
        margin.bottom = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1);
        lua_pop(L,1);
        
        self->setMargin(margin);
        return 0;
    }
    
    CCLOG("'setMargin' function of LayoutParameter has wrong number of arguments: %d, was expecting %d\n", argc, 1);
    
    return 0;
    
#if COCOS2D_DEBUG >= 1
tolua_lerror:
    tolua_error(L,"#ferror in function 'setMargin'.",&tolua_err);
    return 0;
#endif
}
コード例 #7
0
ファイル: WidgetReader.cpp プロジェクト: ElvisQin/genius-x
 void WidgetReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
 {        
     bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, P_IgnoreSize);
     if (ignoreSizeExsit)
     {
         widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize));
     }
     
     widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType));
     widget->setPositionType((Widget::PositionType)DICTOOL->getIntValue_json(options, P_PositionType));
     
     widget->setSizePercent(Vec2(DICTOOL->getFloatValue_json(options, P_SizePercentX), DICTOOL->getFloatValue_json(options, P_SizePercentY)));
     widget->setPositionPercent(Vec2(DICTOOL->getFloatValue_json(options, P_PositionPercentX), DICTOOL->getFloatValue_json(options, P_PositionPercentY)));
     
     /* adapt screen */
     float w = 0, h = 0;
     bool adaptScrenn = DICTOOL->getBooleanValue_json(options, P_AdaptScreen);
     if (adaptScrenn)
     {
         Size screenSize = CCDirector::getInstance()->getWinSize();
         w = screenSize.width;
         h = screenSize.height;
     }
     else
     {
         w = DICTOOL->getFloatValue_json(options, P_Width);
         h = DICTOOL->getFloatValue_json(options, P_Height);
     }
     widget->setSize(Size(w, h));
     
     widget->setTag(DICTOOL->getIntValue_json(options, P_Tag));
     widget->setActionTag(DICTOOL->getIntValue_json(options, P_ActionTag));
     widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, P_TouchAble));
     const char* name = DICTOOL->getStringValue_json(options, P_Name);
     const char* widgetName = name?name:"default";
     widget->setName(widgetName);
     
     float x = DICTOOL->getFloatValue_json(options, P_X);
     float y = DICTOOL->getFloatValue_json(options, P_Y);
     widget->setPosition(Vec2(x,y));
     bool sx = DICTOOL->checkObjectExist_json(options, P_ScaleX);
     if (sx)
     {
         widget->setScaleX(DICTOOL->getFloatValue_json(options, P_ScaleX));
     }
     bool sy = DICTOOL->checkObjectExist_json(options, P_ScaleY);
     if (sy)
     {
         widget->setScaleY(DICTOOL->getFloatValue_json(options, P_ScaleY));
     }
     bool rt = DICTOOL->checkObjectExist_json(options, P_Rotation);
     if (rt)
     {
         widget->setRotation(DICTOOL->getFloatValue_json(options, P_Rotation));
     }
     bool vb = DICTOOL->checkObjectExist_json(options, P_Visbile);
     if (vb)
     {
         widget->setVisible(DICTOOL->getBooleanValue_json(options, P_Visbile));
     }
     int z = DICTOOL->getIntValue_json(options, P_ZOrder);
     widget->setLocalZOrder(z);
     
     bool layout = DICTOOL->checkObjectExist_json(options, P_LayoutParameter);
     if (layout)
     {
         const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, P_LayoutParameter);
         int paramType = DICTOOL->getIntValue_json(layoutParameterDic, P_Type);
         LayoutParameter* parameter = nullptr;
         switch (paramType)
         {
             case 0:
                 break;
             case 1:
             {
                 parameter = LinearLayoutParameter::create();
                 int gravity = DICTOOL->getIntValue_json(layoutParameterDic, P_Gravity);
                 ((LinearLayoutParameter*)parameter)->setGravity((cocos2d::ui::LinearLayoutParameter::LinearGravity)gravity);
                 break;
             }
             case 2:
             {
                 parameter = RelativeLayoutParameter::create();
                 RelativeLayoutParameter* rParameter = (RelativeLayoutParameter*)parameter;
                 const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, P_RelativeName);
                 rParameter->setRelativeName(relativeName);
                 const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, P_RelativeToName);
                 rParameter->setRelativeToWidgetName(relativeToName);
                 int align = DICTOOL->getIntValue_json(layoutParameterDic, P_Align);
                 rParameter->setAlign((cocos2d::ui::RelativeLayoutParameter::RelativeAlign)align);
                 break;
             }
             default:
                 break;
         }
         if (parameter)
         {
             float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginLeft);
             float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginTop);
             float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginRight);
             float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginDown);
             parameter->setMargin(Margin(mgl, mgt, mgr, mgb));
             widget->setLayoutParameter(parameter);
         }
     }
 }
コード例 #8
0
LayoutParameter* LayoutParameter::clone()
{
    LayoutParameter* clonedParameter = createCloneInstance();
    clonedParameter->copyProperties(this);
    return clonedParameter;
}