void CPUTGUIElement::Resize(CPUTRenderNode *pRoot, int width, int height)
{
    CPUTRenderNode *pNode = pRoot;
    while(pNode->GetNodeType() != CPUT_NODE_GUI_ELEMENT)    
        pNode = pNode->GetNext(pRoot);

    if(pNode)
    {
        ((CPUTGUIElement*)pNode)->Resize(0, 0, width, height, width, height);
    }
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
void CPUTAssetSet::RenderRecursive(CPUTRenderParameters &renderParams, int materialIndex)
{
	if (!IsEnabled)
		return;
    CPUTMaterial* pCurrentMaterial = NULL;
    CPUTRenderStateBlock* pCurrentRenderState = NULL;
    CPUTRenderNode* pCurrent = mpRootNode;
    CPUTInputLayoutCache* pInputLayoutCache = CPUTInputLayoutCache::GetInputLayoutCache();
    while (pCurrent)
    {
        if (pCurrent->GetNodeType() == CPUTRenderNode::CPUT_NODE_MODEL)
        {
            CPUTModel* pModel = (CPUTModel*)pCurrent;
            pModel->UpdateShaderConstants(renderParams);
            int meshCount = pModel->GetMeshCount();
            for (int mesh = 0; mesh < meshCount; mesh++)
            {
                CPUTMaterial* pMaterial = pModel->GetMaterial(mesh, materialIndex);
                if (pMaterial != NULL)
                {
                    CPUTRenderStateBlock* pRenderStateBlock = pMaterial->GetRenderStateBlock();
                    CPUTMesh* pMesh = pModel->GetMesh(mesh);
                    SetMaterialStates(pMaterial, pCurrentMaterial);
                    SetRenderStateBlock(pRenderStateBlock, pCurrentRenderState);
                    pInputLayoutCache->Apply(pMesh, pMaterial);
                    pMesh->Draw();
                    SAFE_RELEASE(pCurrentMaterial);
                    pCurrentMaterial = pMaterial;
                    SAFE_RELEASE(pCurrentRenderState)
                    pCurrentRenderState = pRenderStateBlock;
                }
            }
        }
        CPUTRenderNode* pNext = pCurrent->GetChild();
        if (pNext == NULL)
        {
            pNext = pCurrent->GetSibling();

            if (pNext == NULL)
            {
                pNext = pCurrent->GetParent();
                if (pNext != NULL)
                {
                    pNext = pNext->GetSibling();
                }
            }
        }
        pCurrent = pNext;
    }
    SAFE_RELEASE(pCurrentMaterial);
    SAFE_RELEASE(pCurrentRenderState);
}
void CPUTGUIElement::SetEvents(CPUTRenderNode *pRoot, StringMap *pEventMap, CPUTCallbackHandler *pHandler)
{
    if(pRoot == NULL)
        return;
    CPUTRenderNode *pNode = pRoot;
    do
    {
        if(pNode->GetNodeType() == CPUTRenderNode::CPUT_NODE_TYPE::CPUT_NODE_GUI_ELEMENT)
        {
            ((CPUTGUIElement*)pNode)->SetEvents(pEventMap, pHandler);
        }
        pNode = pNode->GetNext(pRoot);
    } while(pNode  != pRoot);
}
CPUTEventHandledCode CPUTGUIElement::HandleKeyboardEvent(CPUTRenderNode *pRoot, CPUTKey key, CPUTKeyState state)
{
    if(pRoot == NULL)
        return CPUT_EVENT_UNHANDLED;;
    CPUTRenderNode* pNode = pRoot;

    do 
    {
        if(pNode->GetNodeType() == CPUTRenderNode::CPUT_NODE_TYPE::CPUT_NODE_GUI_ELEMENT)
        {
            if(CPUT_EVENT_HANDLED == ((CPUTGUIElement*)pNode)->HandleKeyboardEvent(key, state))
                return CPUT_EVENT_HANDLED;
        }
        pNode = pNode->GetNext(pRoot);
    } while(pNode  != pRoot);
    return CPUT_EVENT_UNHANDLED;
}
CPUTEventHandledCode CPUTGUIElement::HandleMouseEvent(CPUTRenderNode *pRoot, int x, int y , int wheel, CPUTMouseState state, CPUTEventID message)
{
    if(pRoot == NULL)
        return CPUT_EVENT_UNHANDLED;;
    CPUTRenderNode* pNode = pRoot;

    do 
    {
        if(pNode->GetNodeType() == CPUTRenderNode::CPUT_NODE_TYPE::CPUT_NODE_GUI_ELEMENT)
        {
            CPUTGUIElement* pElement = (CPUTGUIElement*)pNode;
            if(CPUT_EVENT_HANDLED == ((CPUTGUIElement*)pNode)->HandleMouseEvent(x, y, wheel, state, message))
                return CPUT_EVENT_HANDLED;
        }
        pNode = pNode->GetNext(pRoot);
    } while(pNode  != pRoot);
    return CPUT_EVENT_UNHANDLED;
}