当前位置: 首页>>代码示例>>C++>>正文


C++ JObject::AddChild方法代码示例

本文整理汇总了C++中JObject::AddChild方法的典型用法代码示例。如果您正苦于以下问题:C++ JObject::AddChild方法的具体用法?C++ JObject::AddChild怎么用?C++ JObject::AddChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JObject的用法示例。


在下文中一共展示了JObject::AddChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FnSetParent

int JLuaServer::FnSetParent( lua_State* pLua )
{
    if (lua_gettop( pLua ) != 2)
    {
        rlog.err( "LUA: Incorrect command usage: <setparent>. "
            "Function takes 2 arguments, but %d is provided", lua_gettop( pLua ) );
        lua_settop( pLua, 0 );
        lua_pushnil( pLua );
        return 1;
    }
    JObject* pParent = reinterpret_cast<JObject*>( lua_touserdata( pLua, 2 ) );
    JObject* pObj    = reinterpret_cast<JObject*>( lua_touserdata( pLua, 1 ) );
    if (!pObj)
    {
        lua_pushnil( pLua );
        return 0;
    }
    //  set new parent for the object
    JObject* pOldParent = pObj->GetParent();
    if (pParent)
    {
        pParent->AddChild( pObj );
    }
    if (pOldParent)
    {
        pOldParent->RemoveChild( pObj );
    }
    pObj->SetParent( pParent );
    
    return 0;
} // JLuaServer::FnSetParent
开发者ID:skopp,项目名称:rush,代码行数:31,代码来源:luafunc.cpp

示例2: DropNode

void JObjectTree::DropNode( JObject* pNode, JObject* pDest, bool bAsChild, bool bClone )
{
    if (!pNode || !pDest) return;
    JObject* pAddedNode = pNode;
    pNode->AddRef();

    if (bClone)
    {
        const char* nodeName = pNode->GetName();
        pAddedNode = pNode->Clone( NULL, nodeName );
    }
    else
    {
        pNode->GetParent()->RemoveChild( pNode );
    }

    if (!bAsChild)
    {
        //  insert after the node we dropped onto
        JObject* pParent = pDest->GetParent();
        pParent->AddChild( pAddedNode, pParent->GetChildIndex( pDest ) + 1 );
    }
    else
    {
        //  add as child node
        pDest->AddChild( pAddedNode );
    }

    pNode->Release();
} // JObjectTree::DropNode
开发者ID:,项目名称:,代码行数:30,代码来源:

示例3: CreateEditor

void JBoundsEditor::CreateEditor( JObject* pEdited )
{
    JObject* pTemplates = g_pObjectServer->FindObject( "templates", this );
    JObject* pEditors = GetEditorsGroup();
    if (pTemplates == NULL || pEditors == NULL)
    {
        return;
    }
    int nTemplates = pTemplates->GetNChildren();
    JString editorName;
    for (int i = 0; i < nTemplates; i++)
    {
        JWidget* pTemplate = obj_cast<JWidget>( pTemplates->GetChild( i ) );
        if (pTemplate && is_a( pEdited, pTemplate->GetName() ))
        {
            //  this object can be edited with this editor template
            editorName = pEdited->GetName();
            editorName += "_";
            editorName += pTemplate->GetName();
            editorName += "_editor";
            JObject* pEditor = pTemplate->Clone( pEditors, editorName.c_str(), true );

            pEditors->AddChild( pEditor );

            JBoundsEditContext ctx;
            ctx.m_pEdited = pEdited;
            ctx.m_pEditor = pEditor;
            pEdited->GetPath( ctx.m_Path );
            m_Edited.push_back( ctx );

            //  parse property connections from text field
            JString propcfg( pTemplate->GetText() );
            char* propConfig = (char*)propcfg.c_str();
            while (propConfig && *propConfig != 0)
            {
                char* editedVal = propConfig;
                char* editorVal = propConfig + strcspn( propConfig, "<|" );
                char& ch = *editorVal;

                if (ch == '|')
                {
                    ch = 0;
                    editorVal = "value";
                }
                else if (ch == '<')
                {
                    *editorVal = 0;
                    editorVal++;
                    propConfig = editorVal + strcspn( editorVal, "|" );
                    if (*propConfig == '|')
                    {
                        *propConfig = 0;
                        propConfig++;
                    }
                }
                else if (ch == 0)
                {
                    propConfig = 0;
                    editorVal = "value";
                }

                g_pSignalServer->Connect( pEditor, editorVal, pEdited, editedVal );
                g_pSignalServer->Connect( pEdited, editedVal, pEditor, editorVal );
                pEdited->SendSignal( editedVal );

                g_pSignalServer->Connect( pEdited, "visible", pEditor, "visible" );
                pEdited->SendSignal( "visible" );
            }
        }
    }
}
开发者ID:,项目名称:,代码行数:71,代码来源:

示例4: FnCreate

int JLuaServer::FnCreate( lua_State* pLua )
{
    int nParam = lua_gettop( pLua );
    if (nParam < 1 || nParam > 3)
    {
        rlog.err( "LUA: Incorrect command usage: <create>. "
            "Must be: create( <className or fileName> | <templateObject>, [<newName>, <parentObject>] )" );
        lua_settop( pLua, 0 );
        lua_pushnil( pLua );
        return 1;
    }
    
    //  first parameter
    const char* pClassName = lua_tostring( pLua, 1 );
    JObject* pTemplateObj = NULL;
    if (!pClassName)
    {
        pTemplateObj = (JObject*)lua_touserdata( pLua, 1 );
    }

    //  second parameter
    const char* pObjName   = lua_tostring( pLua, 2 );

    //  third parameter
    JObject* pParentObj = NULL;
    if (nParam > 2)
    {
        pParentObj = (JObject*)lua_touserdata( pLua, 3 );
    }
    else
    {
        JLuaThread* pThread = reinterpret_cast<JLuaThread*>( pLua->userdata );
        assert( pThread->m_pLua == pLua );
        pParentObj = pThread->m_pRootObj;
    }

    JObject* pObj = NULL;
    if (pClassName)
    {
        pObj = g_pObjectServer->Create( pClassName );
        //  try to load from script
        if (pObj == NULL)
        {
            pObj = g_pPersistServer->LoadObject( pClassName );
        }
        if (pObj == NULL)
        {
            rlog.err( "LUA: Cannot create an object because of unknown class (or filename): %s", pClassName );
            lua_settop( pLua, 0 );
            lua_pushnil( pLua );
            return 1;
        }
        if (pObjName) 
        {
            pObj->SetName( pObjName );
        }
    }
    else if (pTemplateObj)
    {
        pObj = pTemplateObj->Clone( pParentObj, pObjName );
    }

    if (pParentObj)
    {
        pParentObj->AddChild( pObj );
    }

    lua_settop( pLua, 0 );
    lua_pushlightuserdata( pLua, pObj );
    return 1;
} // JLuaServer::FnCreate
开发者ID:skopp,项目名称:rush,代码行数:71,代码来源:luafunc.cpp


注:本文中的JObject::AddChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。