Esempio n. 1
0
//-------------------------------------------------------------------------------------
///Load all songs, initializes overlay and play first
	Sound::Sound(const char* path, int width, int height):volumeDiff(1),actualSongNumber(0),overlayIsShowed(false),durationOverlay(0),startVolume(5)
{
	volume = startVolume; //50%
	engine = irrklang::createIrrKlangDevice();
	
	struct dirent *entry;
	DIR *dp;

	dp = opendir(path);
	std::string stringName;

	if (dp == NULL) {
		perror("opendir: Path does not exist or could not be read.");
	}else{
		while ((entry = readdir(dp))){
			stringName = entry->d_name;
			if(!(!strcmp(".", stringName.c_str())||!strcmp("..",stringName.c_str()))){
				songNames.push_back(std::string(path)+ '/'+ entry->d_name);	
			}
		}
	}
	song = engine->play2D(songNames[0].c_str(), false, false, true);
	song->setVolume(volume);

	closedir(dp);
	
	//Event Listener
	song->setSoundStopEventReceiver(this);
	
	//overlay
	Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); 

    //Create a panel 
    Ogre::OverlayContainer* panel = static_cast<Ogre::OverlayContainer*>(overlayManager.createOverlayElement("Panel", "MusicPanel")); 
    panel->setMetricsMode(Ogre::GMM_PIXELS); 
	panel->setDimensions(width*9/10, 50);
 
	panel->setLeft((width - panel->getWidth()) / 2);   
    panel->setMaterialName("Core/StatsBlockCenter"); // Optional background material 
   
    // Create a text area 
    musicTextArea = static_cast<Ogre::TextAreaOverlayElement*>(overlayManager.createOverlayElement("TextArea", "MusicTextArea")); 
    musicTextArea->setMetricsMode(Ogre::GMM_PIXELS); 
	musicTextArea->setTop(5);
	musicTextArea->setLeft((( panel->getWidth())) / 4);
	musicTextArea->setCharHeight(14);   
    musicTextArea->setFontName("StarWars"); 

	// Add the text area to the panel 
    panel->addChild(musicTextArea); 

    // Create an overlay, and add the panel 
    overlay = overlayManager.create("MusicBox"); 
    overlay->add2D((panel)); 

	actualSong();
}
Esempio n. 2
0
void GUIHelper::reposContainer(Ogre::OverlayContainer *o)
{
	ASSERT(o);
	if(!o->getParent()){
		debugWARNING("This overlay has no parent (%s)\n", o->getName().c_str());
		return;
	}
	// if we have parent then we call the other function
	Ogre::OverlayContainer *parent = o->getParent();
	reposContainer(o, parent->getLeft(), parent->getTop(),parent->getHeight(),
			parent->getWidth());
}
Esempio n. 3
0
/**
 * Bugfix for the nested overlay containers position. This function will
 * get a overlay and will iterate over all the (child) containers and will
 * set the new "relative" position
 * @param	overlay		The overlay to fix the childs positions
 */
void GUIHelper::fixOverlayPosition(Ogre::Overlay *overlay)
{
	ASSERT(overlay);

	Ogre::Overlay::Overlay2DElementsIterator it = overlay->get2DElementsIterator();

	Ogre::OverlayContainer *parent = 0;
	while(it.hasMoreElements()){
		parent = it.peekNext();
		if(!parent){
			break;
		}

		// else we have the parent... get the top left and sizes
		Ogre::Real top = parent->getTop();
		Ogre::Real left = parent->getLeft();
		Ogre::Real height = parent->getHeight();
		Ogre::Real width = parent->getWidth();


		Ogre::OverlayContainer::ChildIterator it2 = parent->getChildIterator();
		Ogre::OverlayContainer *child = 0;
		while(it2.hasMoreElements()){
			child = static_cast<Ogre::OverlayContainer *>(it2.peekNextValue());
			if(!child){
				break;
			}
			// else.. we have to configure this child with the parent size and
			// position
			reposContainer(child, left, top, height, width);

			it2.moveNext();
		}


		it.moveNext();
	}
}