bool ElAvatar::creat(unsigned int width, unsigned int height) { using namespace ELGUI; // setup texture D3DXCreateTexture(ElDeviceManager::getDevice(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &mTexture); mTexture->GetSurfaceLevel(0, &mSurface); // setup imageset ElGUITexture* gui_texture = (ElGUITexture*)System::getSingleton().getRenderer()->createTexture(); gui_texture->setTexture(mTexture); Imageset* imageset = ImagesetManager::getSingleton().createImageset(ElAvatarImageset, gui_texture); Rect rect = Rect(Point(0.0f, 0.0f), Size(width, height)); imageset->defineImage(ElAvatarImage, rect, Point(0.0f, 0.0f)); // setup scene if (!_createScene()) return false; // setup scene camera ElCamera* sceneCamera = ElNew ElCamera; float aspect = (float)width / (float)height; //sceneCamera->setPosition(D3DXVECTOR3(0.0f, 1.0f, -5.0f)); sceneCamera->setPosition(D3DXVECTOR3(0.0f, 2.175f, -0.5f)); sceneCamera->setProjectionParameters(ElCamera::PT_PERSPECTIVE, D3DX_PI / 4, aspect, 0.1f, 500.0f); mScene->setCamera(sceneCamera); return true; }
/************************************************************************* Create an Imageset object from the specified file *************************************************************************/ Imageset* ImagesetManager::createImageset(const String& filename, const String& resourceGroup ) { Logger::getSingleton().logEvent((utf8*)"Attempting to create an Imageset from the information specified in file '" + filename + "'."); Imageset* temp = new Imageset(filename, resourceGroup ); String name = temp->getName(); if (isImagesetPresent(name)) { delete temp; throw AlreadyExistsException("ImagesetManager::createImageset - An Imageset object named '" + name + "' already exists."); } d_imagesets[name] = temp; return temp; }
//----------------------------------------------------------------------- CEGUI::Imageset* EditorDocument::generateRealImageset(const wxString& pathName) { const String imagesetName ( CEGUIHelper::ToCEGUIString( m_imagesetName ) ); const String imageFilename ( CEGUIHelper::ToCEGUIString( pathName + m_imageFilename ) ); ImagesetManager& isMgr = ImagesetManager::getSingleton(); if ( isMgr.isImagesetPresent( imagesetName ) ) // TODO: Maybe ask user whether to continue here? isMgr.destroyImageset( imagesetName ); // create the imageset Imageset* imageset = isMgr.createImagesetFromImageFile( imagesetName, imageFilename ); // auto-scale options imageset->setAutoScalingEnabled( m_autoScaled ); imageset->setNativeResolution( CEGUI::Size( m_nativeResolution.x, m_nativeResolution.y ) ); // iterate over all the elements in the class mapNamedRegion::iterator it; for( it = m_mapSetRectangles.begin(); it != m_mapSetRectangles.end(); ++it ) { const String imageName = CEGUIHelper::ToCEGUIString( wxString( it->first ) ); if ( !imageset->isImageDefined( imageName ) ) { const wxRect r( it->second ); const CEGUI::Rect newDim( ( ( r.GetLeft() > 0 ) ? r.GetLeft() : 0 ), ( ( r.GetTop() > 0 ) ? r.GetTop() : 0 ), ( ( r.GetRight() + 1 > 0 ) ? r.GetRight() + 1 : 0 ), ( ( r.GetBottom() + 1 > 0 ) ? r.GetBottom() + 1 : 0 ) ); const CEGUI::Point p ( 0.0f, 0.0f ); imageset->defineImage( imageName, newDim, p ); } } if ( imageset->isImageDefined ( "full_image" ) ) imageset->undefineImage( "full_image" ); return imageset; }
/************************************************************************* Load all resources for this scheme *************************************************************************/ void Scheme::loadResources(void) { Logger::getSingleton().logEvent((utf8*)"---- Begining resource loading for GUI scheme '" + d_name + "' ----", Informative); ImagesetManager& ismgr = ImagesetManager::getSingleton(); FontManager& fntmgr = FontManager::getSingleton(); WindowFactoryManager& wfmgr = WindowFactoryManager::getSingleton(); WidgetLookManager& wlfMgr = WidgetLookManager::getSingleton(); std::vector<LoadableUIElement>::const_iterator pos; // check imagesets for (pos = d_imagesets.begin(); pos != d_imagesets.end(); ++pos) { if (!ismgr.isImagesetPresent((*pos).name)) { Imageset* iset = ismgr.createImageset((*pos).filename, (*pos).resourceGroup); // check for wrong imageset for specified name String realname = iset->getName(); if (realname != (*pos).name) { ismgr.destroyImageset(iset); throw InvalidRequestException((utf8*)"Scheme::loadResources - The Imageset created by file '" + (*pos).filename + "' is named '" + realname + "', not '" + (*pos).name + "' as required by Scheme '" + d_name + "'."); } } } // check imagesets that are created directly from image files for (pos = d_imagesetsFromImages.begin(); pos != d_imagesetsFromImages.end(); ++pos) { if (!ismgr.isImagesetPresent((*pos).name)) ismgr.createImagesetFromImageFile((*pos).name, (*pos).filename, (*pos).resourceGroup); } // check fonts for (pos = d_fonts.begin(); pos != d_fonts.end(); ++pos) { if (!fntmgr.isFontPresent((*pos).name)) { Font* font = fntmgr.createFont((*pos).filename, (*pos).resourceGroup); // check for wrong font for specified name String realname = font->getName(); if (realname != (*pos).name) { fntmgr.destroyFont(font); throw InvalidRequestException((utf8*)"Scheme::loadResources - The Font created by file '" + (*pos).filename + "' is named '" + realname + "', not '" + (*pos).name + "' as required by Scheme '" + d_name + "'."); } } } // load look'n'feels (can't actually check these, so just re-parse data; it does no harm except maybe wase a bit of time) for (pos = d_looknfeels.begin(); pos != d_looknfeels.end(); ++pos) { wlfMgr.parseLookNFeelSpecification((*pos).filename, (*pos).resourceGroup); } // check factories std::vector<UIModule>::iterator cmod = d_widgetModules.begin(); for (; cmod != d_widgetModules.end(); ++cmod) { // create and load dynamic module as required if ((*cmod).module == NULL) { (*cmod).module = new FactoryModule((*cmod).name); } // see if we should just register all factories available in the module (i.e. No factories explicitly specified) if ((*cmod).factories.size() == 0) { Logger::getSingleton().logEvent("No window factories specified for module '" + (*cmod).name + "' - adding all available factories..."); (*cmod).module->registerAllFactories(); } // some names were explicitly given, so only register those. else { std::vector<UIElementFactory>::const_iterator elem = (*cmod).factories.begin(); for (; elem != (*cmod).factories.end(); ++elem) { if (!wfmgr.isFactoryPresent((*elem).name)) { (*cmod).module->registerFactory((*elem).name); } } } } // check aliases std::vector<AliasMapping>::iterator alias = d_aliasMappings.begin(); for (; alias != d_aliasMappings.end(); ++alias) { // get iterator WindowFactoryManager::TypeAliasIterator iter = wfmgr.getAliasIterator(); // look for this alias while (!iter.isAtEnd() && (iter.getCurrentKey() != (*alias).aliasName)) ++iter; // if the alias exists if (!iter.isAtEnd()) { // if the current target type matches if (iter.getCurrentValue().getActiveTarget() == (*alias).targetName) { // assume this mapping is ours and skip to next alias continue; } } // create a new alias entry wfmgr.addWindowTypeAlias((*alias).aliasName, (*alias).targetName); } // check falagard window mappings. std::vector<FalagardMapping>::iterator falagard = d_falagardMappings.begin(); for (; falagard != d_falagardMappings.end(); ++falagard) { // get iterator WindowFactoryManager::FalagardMappingIterator iter = wfmgr.getFalagardMappingIterator(); // look for this mapping while (!iter.isAtEnd() && (iter.getCurrentKey() != (*falagard).windowName)) ++iter; // if the alias exists if (!iter.isAtEnd()) { // if the current target and looks match if ((iter.getCurrentValue().d_baseType == (*falagard).targetName) && (iter.getCurrentValue().d_lookName == (*falagard).lookName)) { // assume this mapping is ours and skip to next continue; } } // create a new mapping entry wfmgr.addFalagardWindowMapping((*falagard).windowName, (*falagard).targetName, (*falagard).lookName); } Logger::getSingleton().logEvent((utf8*)"---- Resource loading for GUI scheme '" + d_name + "' completed ----", Informative); }