bool CGUIStaticImage_Impl::LoadFromTexture ( CGUITexture* pTexture ) { if ( m_pImageset && m_pImage ) { m_pImageset->undefineAllImages (); } if ( m_pTexture && pTexture != m_pTexture ) { delete m_pTexture; m_bCreatedTexture = false; } m_pTexture = (CGUITexture_Impl *)pTexture; // Get CEGUI texture CEGUI::Texture* pCEGUITexture = m_pTexture->GetTexture (); // Get an unique identifier for CEGUI for the imageset char szUnique [CGUI_CHAR_SIZE]; m_pGUI->GetUniqueName ( szUnique ); // Create an imageset if ( !m_pImageset ) { while ( m_pImagesetManager->isImagesetPresent( szUnique ) ) m_pGUI->GetUniqueName ( szUnique ); m_pImageset = m_pImagesetManager->createImageset ( szUnique, pCEGUITexture, true ); } // Get an unique identifier for CEGUI for the image m_pGUI->GetUniqueName ( szUnique ); // Define an image and get its pointer m_pImageset->defineImage ( szUnique, CEGUI::Point ( 0, 0 ), CEGUI::Size ( pCEGUITexture->getWidth (), pCEGUITexture->getHeight () ), CEGUI::Point ( 0, 0 ) ); m_pImage = &m_pImageset->getImage ( szUnique ); // Set the image just loaded as the image to be drawn for the widget reinterpret_cast < CEGUI::StaticImage* > ( m_pWindow )->setImage ( m_pImage ); // Success return true; }
void CSimulatorWindowHandler::init() { CEGUI::WindowManager &windowMngr = CEGUI::WindowManager::getSingleton(); m_continueButton = static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/ContinueButton")); m_startButton = static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/StartButton")); m_zoomButton = static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/ZoomButton")); m_formation433Button = static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/433Button")); m_formation442Button = static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/442Button")); m_frameWindow = static_cast<CEGUI::FrameWindow*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/FrameWindow")); m_view2DButton = static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/2DButton")); m_view3DButton = static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/3DButton")); m_frameStartButtom = static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/StartButton")); m_logHistoryList = static_cast<CEGUI::Listbox*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Log")); m_logHistoryListShort = static_cast<CEGUI::Listbox*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/Log")); m_teamPlayersList = static_cast<CEGUI::MultiColumnList*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/TeamPlayersList")); m_groundImage = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Image")); m_groundFrameImage = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/Image")); m_teamNames = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/TeamNames")); m_score = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Score")); m_frameHomeName = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/HomeName")); m_frameAwayName = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/AwayName")); m_frameHomeScore = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/HomeScore")); m_frameAwayScore = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/AwayScore")); // i18n support m_continueButton->setText((CEGUI::utf8*)gettext("Continue")); m_startButton->setText((CEGUI::utf8*)gettext("Start")); m_zoomButton->setText((CEGUI::utf8*)gettext("Zoom")); m_frameWindow->setText((CEGUI::utf8*)gettext("Simulation View")); m_view2DButton->setText((CEGUI::utf8*)gettext("2D View")); m_view3DButton->setText((CEGUI::utf8*)gettext("3D View")); m_frameStartButtom->setText((CEGUI::utf8*)gettext("Start")); static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/TeamTab"))->setText((CEGUI::utf8*)gettext("Team")); static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/FormationTab"))->setText((CEGUI::utf8*)gettext("Formation")); static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/LogTab"))->setText((CEGUI::utf8*)gettext("Log")); static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/StatisticsTab"))->setText((CEGUI::utf8*)gettext("Statistics")); // Event handle registerEventConnection(m_continueButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::continueButtonClicked, this))); registerEventConnection(m_startButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::startButtonClicked, this))); registerEventConnection(m_zoomButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::zoomButtonClicked, this))); registerEventConnection(m_formation433Button->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::formation433ButtonClicked, this))); registerEventConnection(m_formation442Button->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::formation442ButtonClicked, this))); registerEventConnection(m_frameWindow->subscribeEvent(CEGUI::FrameWindow::EventCloseClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::frameWindowCloseClicked, this))); registerEventConnection(m_view2DButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::view2DButtonClicked, this))); registerEventConnection(m_view3DButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::view3DButtonClicked, this))); registerEventConnection(m_frameStartButtom->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::startButtonClicked, this))); registerEventConnection(windowMngr.getWindow("Simulator")->subscribeEvent(CEGUI::Window::EventKeyDown, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::keyDownHandler, this))); registerEventConnection(windowMngr.getWindow("Simulator")->subscribeEvent(CEGUI::Window::EventKeyUp, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::keyUpHandler, this))); m_direction = Ogre::Vector3::ZERO; m_sceneMngr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, SIMULATION_SCENE_MANAGER_NODE_NAME); m_cam2D = m_sceneMngr->createCamera("2D_Camera"); m_cam2D->setNearClipDistance(1); int width = 120; int height = 90; double right = width/2.0, left = -width/2.0, top = height/2.0, bottom = -height/2.0, farZ = 150.0, nearZ = 10.0; Ogre::Matrix4 projectionMatrix( 2/(right-left), 0, 0, -(right+left)/(right-left), 0, 2/(top-bottom), 0, -(top+bottom)/(top-bottom), 0, 0, -2/(farZ-nearZ), -(farZ+nearZ)/(farZ-nearZ), 0, 0, 0, 1 ); m_cam2D->setProjectionType(Ogre::PT_ORTHOGRAPHIC); m_cam2D->setCustomProjectionMatrix(true, projectionMatrix); m_cam3D = m_sceneMngr->createCamera("3D_Camera"); m_cam3D->setProjectionType(Ogre::PT_PERSPECTIVE); m_cam3D->setCustomProjectionMatrix(false); m_cam3D->setNearClipDistance(5); Ogre::TexturePtr texturePtr = Ogre::TextureManager::getSingleton().createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, (int)m_groundImage->getPixelSize().d_width, (int)m_groundImage->getPixelSize().d_height, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); m_renderTexture = texturePtr->getBuffer()->getRenderTarget(); CEGUI::Texture *cTex = static_cast<CEGUI::OgreCEGUIRenderer*>(CEGUI::System::getSingleton().getRenderer())->createTexture((CEGUI::utf8*)"RttTex"); CEGUI::Imageset *imageSet = CEGUI::ImagesetManager::getSingleton().createImageset((CEGUI::utf8*)"RttImageset", cTex); imageSet->defineImage((CEGUI::utf8*)"RttImage", CEGUI::Point(0.0f, 0.0f), CEGUI::Size(cTex->getWidth(), cTex->getHeight()), CEGUI::Point(0.0f,0.0f)); m_groundImage->setProperty( "Image", CEGUI::PropertyHelper::imageToString(&imageSet->getImage((CEGUI::utf8*)"RttImage"))); m_groundFrameImage->setProperty("Image", CEGUI::PropertyHelper::imageToString(&imageSet->getImage((CEGUI::utf8*)"RttImage"))); m_groundFrameImage->disable(); m_initiated = true; }
//--------------------------------------------------------------------- void CompositorDemo_FrameListener::updateDebugRTTWindow(void) { // Clear listbox mDebugRTTListbox->resetList(); // Clear imagesets mDebugRTTStaticImage->setProperty("Image", ""); for (ImageSetList::iterator isIt = mDebugRTTImageSets.begin(); isIt != mDebugRTTImageSets.end(); ++isIt) { CEGUI::ImagesetManager::getSingleton().destroyImageset(*isIt); } mDebugRTTImageSets.clear(); Ogre::set<Ogre::String>::type uniqueTextureNames; // Add an entry for each render texture for all active compositors Ogre::Viewport* vp = mMain->getRenderWindow()->getViewport(0); Ogre::CompositorChain* chain = Ogre::CompositorManager::getSingleton().getCompositorChain(vp); Ogre::CompositorChain::InstanceIterator it = chain->getCompositors(); while (it.hasMoreElements()) { Ogre::CompositorInstance* inst = it.getNext(); if (inst->getEnabled()) { Ogre::CompositionTechnique::TextureDefinitionIterator texIt = inst->getTechnique()->getTextureDefinitionIterator(); while (texIt.hasMoreElements()) { Ogre::CompositionTechnique::TextureDefinition* texDef = texIt.getNext(); // Get instance name of texture (NB only index 0 if MRTs for now) const Ogre::String& instName = inst->getTextureInstanceName(texDef->name, 0); // Create CEGUI texture from name of OGRE texture CEGUI::Texture* tex = mMain->getGuiRenderer()->createTexture(instName.c_str()); // Create imageset // Note that if we use shared textures in compositor, the same texture name // will occur more than once, so we have to cater for this if (uniqueTextureNames.find(instName) == uniqueTextureNames.end()) { CEGUI::Imageset* imgSet = CEGUI::ImagesetManager::getSingleton().createImageset( instName.c_str(), tex); mDebugRTTImageSets.push_back(imgSet); imgSet->defineImage((CEGUI::utf8*)"RttImage", CEGUI::Point(0.0f, 0.0f), CEGUI::Size(tex->getWidth(), tex->getHeight()), CEGUI::Point(0.0f,0.0f)); CEGUI::ListboxTextItem *item = new CEGUI::ListboxTextItem(texDef->name.c_str(), 0, imgSet); item->setSelectionBrushImage("TaharezLook", "ListboxSelectionBrush"); item->setSelectionColours(CEGUI::colour(0,0,1)); mDebugRTTListbox->addItem(item); uniqueTextureNames.insert(instName); } } } } }