Exemplo n.º 1
0
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
Exemplo n.º 2
0
bool JObjectTree::DeleteNode()
{
    if (!m_pSelected) return false;
    JObject* pParent = m_pSelected->GetParent();
    if (!pParent) return false;

    int idx = pParent->GetChildIndex( m_pSelected );
    pParent->RemoveChild( m_pSelected );
    if (idx >= pParent->GetNChildren()) idx = pParent->GetNChildren() - 1;
    if (idx < 0) idx = 0;
    m_pSelected = pParent->GetChild( idx );
    if (!m_pSelected) m_pSelected = pParent;
    m_pExpanded = m_pSelected;
    return true;
} // JObjectTree::DeleteNode