コード例 #1
0
ファイル: luafunc.cpp プロジェクト: skopp/rush
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
コード例 #2
0
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
コード例 #3
0
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" );
            }
        }
    }
}
コード例 #4
0
ファイル: luafunc.cpp プロジェクト: skopp/rush
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