// add a gui element to the page list DWORD CGUIPage::OnAddGUIElementToPage(DWORD size, void *params) { OBJECTLIST::iterator olIter; GUIPAGEMESSAGE *gpm; IObject *guiObject; static CHashString managerName(_T("CGUIManager")); CGUIManager *manager; // make sure message is valid VERIFY_MESSAGE_SIZE(size, sizeof(GUIPAGEMESSAGE)); // downcast parameters to struct we expect gpm = (GUIPAGEMESSAGE *)params; // ask gui manager for the object to add manager = dynamic_cast<CGUIManager*>(EngineGetToolBox()->GetComponent( &managerName )); if (!manager) { EngineGetToolBox()->SetErrorValue(ERR_NULL_POINTER); EngineGetToolBox()->Log(LOGERROR, _T("could not cast IComponent from EngineToolBox to CGUIManager\n")); return MSG_ERROR; } guiObject = manager->GetObject(gpm->name, gpm->compType); if(guiObject == NULL) { EngineGetToolBox()->SetErrorValue(ERR_NULL_POINTER); EngineGetToolBox()->Log(LOGERROR, _T("could not get the gui object from the gui manager: %s object not found\n"), gpm->name); return MSG_ERROR; } // check if object is already on list for(olIter = m_ObjectList.begin(); olIter != m_ObjectList.end(); olIter++) { if ( (*olIter)->GetName()->GetUniqueID() == guiObject->GetName()->GetUniqueID() ) { // object is already on page return MSG_NOT_HANDLED; } } // now add object to list m_ObjectList.push_back(guiObject); m_SortedMap.clear(); IGUIElement *guiElement = dynamic_cast<IGUIElement*>(guiObject); guiElement->SetWidthRatio(m_fWidthRatio); guiElement->SetHeightRatio(m_fHeightRatio); guiElement->SetZoomFactor(m_fZoomFactor); guiElement->SetPageOffset(m_iPageOffsetX, m_iPageOffsetY); return MSG_HANDLED_STOP; }
/// Sets the width ratio value for this page and all the underlying gui elements /// \param value - value to set ratio to void CGUIPage::SetWidthRatio(float value) { m_fWidthRatio = value; IGUIElement *guiElement; OBJECTLIST::iterator olIter = m_ObjectList.begin(); while(olIter != m_ObjectList.end()) { guiElement = dynamic_cast<IGUIElement*>((*olIter)); if(guiElement == NULL) { m_ToolBox->SetErrorValue(ERR_NULL_POINTER); m_ToolBox->Log(LOGERROR, _T("Could not cast to IGUIElement: %s"), (*olIter)->GetName()); } guiElement->SetWidthRatio(value); olIter++; } }