本文整理汇总了C++中JObject::GetParent方法的典型用法代码示例。如果您正苦于以下问题:C++ JObject::GetParent方法的具体用法?C++ JObject::GetParent怎么用?C++ JObject::GetParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JObject
的用法示例。
在下文中一共展示了JObject::GetParent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetObjectID
int PhysicsServer::GetObjectID( const char* name, JObject* context )
{
int nObj = m_Objects.size();
for (int i = 0; i < nObj; i++)
{
JObject* pObject = m_Objects[i];
if (!pObject) continue;
if (!stricmp( name, pObject->GetName() ) &&
(!context || pObject->GetParent() == context )) return i;
}
if (context == NULL)
{
context = this;
}
PhysObject* pObj = g_pObjectServer->FindObject<PhysObject>( name, context );
if (pObj)
{
m_Objects.push_back( pObj );
int id = m_Objects.size() - 1;
pObj->SetID( id );
return id;
}
return -1;
} // PhysicsServer::GetObjectID
示例2: 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
示例3: FnParent
int JLuaServer::FnParent( lua_State* pLua )
{
if (lua_gettop( pLua ) != 1)
{
rlog.err( "LUA: Incorrect command usage: <parent>. "
"Function takes 1 argument, but %d is provided", lua_gettop( pLua ) );
lua_settop( pLua, 0 );
lua_pushnil( pLua );
return 1;
}
JObject* pObj = NULL;
const char* pPath = lua_tostring( pLua, -1 );
if (pPath)
{
JLuaThread* pThread = reinterpret_cast<JLuaThread*>( pLua->userdata );
assert( pThread->m_pLua == pLua );
JObject* pRootObj = pThread->m_pRootObj;
pObj = g_pObjectServer->FindObject( pPath, NULL, pRootObj );
}
else
{
pObj = reinterpret_cast<JObject*>( lua_touserdata( pLua, -1 ) );
}
if (!pObj)
{
lua_pushnil( pLua );
return 1;
}
lua_pushlightuserdata( pLua, pObj->GetParent() );
return 1;
} // JLuaServer::FnParent
示例4: Init
void JBlotPiece::Init()
{
JObject* pParent = GetParent();
m_pBlot = NULL;
while (pParent && !m_pBlot)
{
m_pBlot = dynamic_cast<JBlotGame*>( pParent );
pParent = pParent->GetParent();
}
} // JBlotPiece:Init
示例5: Init
void JSlidePiece::Init()
{
JObject* pParent = GetParent();
m_pSlideGame = NULL;
while (pParent && !m_pSlideGame)
{
m_pSlideGame = dynamic_cast<JSlideGame*>( pParent );
pParent = pParent->GetParent();
}
} // JSlidePiece:Init
示例6: Traverse
void JObjectTree::Traverse( TraverseCallback callback, void* pContext ) const
{
if (!m_pRoot) return;
float nodeW = m_NodeWidth;
float nodeVisH = m_NodeHeight;
Frame ext( m_RootPos.x, m_RootPos.y, nodeW, nodeVisH );
// find node path for tree expansion
static std::vector<int> nodePath;
nodePath.clear();
JObject* pCurObj = m_pExpanded;
if (pCurObj) nodePath.push_back( 0 );
while (pCurObj && pCurObj != m_pRoot)
{
JObject* pParent = pCurObj->GetParent();
if (!pParent) break;
nodePath.push_back( pParent->GetChildIndex( pCurObj ) );
pCurObj = pParent;
}
// traverse root node (which is never collapsed)
if ((this->*callback)( ext, m_pRoot, (m_pExpanded != NULL), pContext ) == false) return;
// traverse along expansion path
pCurObj = m_pRoot;
for (int i = nodePath.size() - 1; i >= 0; i--)
{
int childIdx = nodePath[i];
if (!pCurObj) break;
int nCh = pCurObj->GetNChildren();
if (childIdx >= nCh) break;
float blockH = float( nCh )*nodeVisH;
ext.y = ext.y - blockH*0.5f + nodeVisH*0.5f;
ext.x += nodeW;
float cY = ext.y;
for (int j = 0; j < nCh; j++)
{
JObject* pChild = pCurObj->GetChild( j );
Frame chExt( ext );
chExt.y = cY;
bool bExpanded = (j == childIdx)&&(pCurObj != m_pExpanded);
if ((this->*callback)( chExt, pChild, bExpanded, pContext ) == false)
{
return;
}
cY += nodeVisH;
}
pCurObj = pCurObj->GetChild( childIdx );
ext.y += float( childIdx )*nodeVisH;
}
} // JObjectTree::Traverse