Exemplo n.º 1
0
void Menu::dessiner() {
	_fond->redimensionner(glm::vec2(Ecran::largeur() / static_cast<coordonnee_t>(_fond->dimensionsReelles().x), Ecran::hauteur() /static_cast<coordonnee_t>( _fond->dimensionsReelles().y)));
	
	_nbElementsAffiches = 0;
	size_t dim = 0;
	for(std::vector<element_t>::iterator i = _elements.begin(); i != _elements.end(); ++i) {
		dim += i->_texte.dimensions().y;
		if(dim > Menu::tailleMax())
			break;
		
		dim += ECART_ELEM * Ecran::echelleMin();
		++ _nbElementsAffiches;
		
		i->_texte.definir(POLICE_DECO, TAILLE_ELEMENTS_MENU * Ecran::echelleMin());
		i->_cadre.definirDimensions(i->_texte.dimensions());
	}
	
	_s->activer();
	_s->definirParametre(Shader::temps, horloge() - _tempsInitial);
	_s->definirParametre(Shader::tempsAbsolu, horloge());
	_fond->afficher(glm::vec2(0));
	Shader::desactiver();
	
	this->afficherElements(_selection);
}
Exemplo n.º 2
0
void Menu::gestionClavier() {	
	Ecran::definirPointeurAffiche(true);

	if(_continuer) {
		if(_echap && Session::evenement(Session::T_ESC)) {
			_retour = _elements.size() - 1;
			_continuer = false;
		}
		else if(Session::evenement(Session::T_ENTREE) || Session::evenement(Session::T_ESPACE) || (Session::evenement(Session::B_GAUCHE) && _elements[_selection]._cadre.contientPoint(Session::souris()))) {
			_retour = _selection;
			_continuer = false;
		}
		else if(Session::evenement(Session::T_HAUT) && horloge() - _ancienDefilement > INTERVALLE_DEFILEMENT) {
			if(_selection > 0) {
				--_selection;
				if(_selection < _premierElementAffiche)
					--_premierElementAffiche;
			}
			else {
				_selection = _elements.size() - 1;
				if(_elements.size() > _nbElementsAffiches)
					_premierElementAffiche = _elements.size() - _nbElementsAffiches;
			}
			
			_ancienDefilement = horloge();
		}
		else if(Session::evenement(Session::T_BAS) && horloge() - _ancienDefilement > INTERVALLE_DEFILEMENT) {
			if(_selection < _elements.size() - 1) {
				++_selection;
				if(_selection >= _premierElementAffiche + _nbElementsAffiches)
					++_premierElementAffiche;
			}
			else {
				_selection = 0;
				_premierElementAffiche = 0;
			}
			
			_ancienDefilement = horloge();
		}
		else if(Session::evenement(Session::SOURIS)) {
			for(std::vector<element_t>::iterator i = _elements.begin() + _premierElementAffiche; i != _elements.end() && i != _elements.begin() + _premierElementAffiche + _nbElementsAffiches; ++i) {
				if(i->_cadre.contientPoint(Session::souris())) {
					_selection = i - _elements.begin();
				}
			}
		}
	}
	
	if(!_continuer)
		Session::supprimerVueFenetre();
	
	/*if(!afficheurAuxiliaire.gestionEvenements()) {
		_retour = _elements.size() - 1;
		_continuer = false;
	}*/
}
Exemplo n.º 3
0
void EntiteMobile::animer() {
	if(horloge() - _tempsPrecedent >= _tempsAffichage[_action]) {
		_tempsPrecedent = horloge();
		_imageActuelle = (_imageActuelle + 1) % _nbImages[_action];
		
		if(_action == a_mourir && _imageActuelle == _nbImages[a_mourir] - 1) {
			_mortTerminee = true;
		}
		if(_imageActuelle == 0) {
			_action = nbActions;
			this->definirAction(a_immobile);
		}
	}
}
Exemplo n.º 4
0
void Niveau::afficher() {
	glm::vec2 cam = _perso->positionAffichage();
	if(_perso->inventaireAffiche())
		cam = _perso->positionAffichage() - glm::vec2(Ecran::largeur() / 4, 0);
	cam -= (glm::vec2(Ecran::dimensions()) - _perso->dimensions() * static_cast<coordonnee_t>(LARGEUR_CASE)) / 2.0f - glm::vec2(0, 80);
	cam.x = std::floor(cam.x);
	cam.y = std::floor(cam.y);
	

	this->afficherCouche(cn_sol, cam);
	this->afficherTransitionsSol(cam);
	
	this->afficherBordure(DROITE, cam);
	this->afficherBordure(HAUT, cam);
	
	// Sert à afficher la grille de case, inutile sauf en cas de test
	/*for(index_t y = 0; y <= _dimY; ++y) {
		Ecran::afficherLigne(referentielNiveauVersEcran(Coordonnees(0, y) * static_cast<coordonnee_t>(LARGEUR_CASE)) - cam, referentielNiveauVersEcran(Coordonnees(_dimX, y) * static_cast<coordonnee_t>(LARGEUR_CASE)) - cam, Couleur::rouge, 1.0);
	}
	for(index_t x = 0; x <= _dimX; ++x) {
		Ecran::afficherLigne(referentielNiveauVersEcran(Coordonnees(x, 0) * static_cast<coordonnee_t>(LARGEUR_CASE)) - cam, referentielNiveauVersEcran(Coordonnees(x, _dimY) * static_cast<coordonnee_t>(LARGEUR_CASE)) - cam, Couleur::rouge, 1.0);
	}*/
	
	for(Niveau::couche_t c = premiereCouche + 1; c != nbCouches; ++c) {
		if(c == cn_objetsInventaire)
			this->afficherObjetsInventaire(cam);
		else
			this->afficherCouche(c, cam);
	}
	
	this->afficherBordure(BAS, cam);
	this->afficherBordure(GAUCHE, cam);

	static float tonnerre = 0;
	if(horloge() - tonnerre > nombreAleatoire(5) + 1) {
		if(tonnerre > 0)
			Audio::jouerSon(_tonnerre);
		tonnerre = horloge() + 15 + nombreAleatoire(60);
	}
	
	_pluie.activer();
	_pluie.definirParametre("temps", horloge());
	_pluie.definirParametre("cam", glm::vec2(cam.x, cam.y));
	_pluie.definirParametre("tonnerre", tonnerre);
	
	_pluie.activer();
	Affichage::afficherRectangle(Ecran::ecran(), Couleur::blanc);
	Shader::desactiver();
}
Exemplo n.º 5
0
    void
fonction1() {

    cout << "fonction1() débute ici" << endl;

    static Horloge horloges(240);
    Horloge horloge(300);

    cout << "fin de fonction1()" << endl;
}
Exemplo n.º 6
0
void Affichage::changerTexture(GLuint tex) {
    if(tex != _tex || tex == -1) {
        if(_nbSommets) {
#ifdef VBO
            if(_buf == 0) {
                glGenBuffers(1, &_buf);

                glBindBuffer(GL_ARRAY_BUFFER, _buf);
                glBufferData(GL_ARRAY_BUFFER, TAMPON_SOMMETS * (7 * sizeof(GLfloat) + 4 * sizeof(GLubyte)), 0, GL_STREAM_DRAW);
                glBindBuffer(GL_ARRAY_BUFFER, 0);
                //GLuint vao;
                //glGenVertexArrays(1, &vao);
                //glBindVertexArray(vao);
            }
#endif
            glEnableVertexAttribArray(Shader::shaderActuel().vertCoord());
            glEnableVertexAttribArray(Shader::shaderActuel().texCoord());
            glEnableVertexAttribArray(Shader::shaderActuel().coul());

#ifdef VBO
            glBindBuffer(GL_ARRAY_BUFFER, _buf);
            glBufferSubData(GL_ARRAY_BUFFER, 0, _nbSommets * 3 * sizeof(GLfloat), &_vertCoords[0]);
            glBufferSubData(GL_ARRAY_BUFFER, _nbSommets * 3 * sizeof(GLfloat), _nbSommets * 4 * sizeof(GLfloat), &_texCoords[0]);
            glBufferSubData(GL_ARRAY_BUFFER, _nbSommets * 7 * sizeof(GLfloat), _nbSommets * 4 * sizeof(GLubyte), &_couleurs[0]);

            glVertexAttribPointer(Shader::shaderActuel().vertCoord(), 3, GL_FLOAT, GL_FALSE, 0, 0);
            glVertexAttribPointer(Shader::shaderActuel().texCoord(), 2, GL_FLOAT, GL_FALSE, 0, (void *)(_nbSommets * 3 * sizeof(GLfloat)));
            glVertexAttribPointer(Shader::shaderActuel().coul(), 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, (void *)(_nbSommets * 7 * sizeof(GLfloat)));

            glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(_nbSommets));
            glBindBuffer(GL_ARRAY_BUFFER, 0);
#else
            glVertexAttribPointer(Shader::shaderActuel().vertCoord(), 3, GL_FLOAT, GL_FALSE, 0, &_vertCoords[0]);
            glVertexAttribPointer(Shader::shaderActuel().texCoord(), 2, GL_FLOAT, GL_FALSE, 0, &_texCoords[0]);
            glVertexAttribPointer(Shader::shaderActuel().coul(), 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, &_couleurs[0]);

            glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(_nbSommets));
#endif
            glDisableVertexAttribArray(Shader::shaderActuel().vertCoord());
            glDisableVertexAttribArray(Shader::shaderActuel().texCoord());
            glDisableVertexAttribArray(Shader::shaderActuel().coul());

#ifdef STAT
            static int nb1 = 0;
            static float nb2 = 0;
            static horloge_t h = horloge();
            ++nb1;
            nb2 += _nbSommets;
            float H = horloge();
            if(H - h >= 1.0f) {
                std::cout << nbVert / (H - h) << " vtx/s" << std::endl;
                std::cout << nb1 / (H - h) << " ch/s (" << nb2 / nb1 << " vtx/ch, " << nb1 / Ecran::frequence() << " ch/img)" << std::endl;

                nbVert = 0;

                h = H;
                nb1 = 0;
                nb2 = 0;
            }
#endif

            _nbSommets = 0;
        }

        if(tex != -1) {
            glBindTexture(GL_TEXTURE_2D, tex);
        }
        _tex = tex;
    }
}
Exemplo n.º 7
0
bool Session::boucle(float freq, bool continuer) {
	Audio::maj();
	
	for(std::list<std::pair<VueInterface *, bool> >::iterator i = _vuesASupprimer.begin(); i != _vuesASupprimer.end(); ++i) {
		i->first->parent()->supprimerEnfant(*i->first);
		if(i->second)
			delete i->first;
	}
	_vuesASupprimer.clear();
	
	if(!continuer) {
		Session::reinitialiserEvenements();
		Session::_vueFenetre = 0;
		_horlogeSurvol = horloge();
		
		VueInterface::definirVueActuelle(0);
		
		_vues.pop();
		_vueFenetre = _vues.top();
		_vueTemp = _vueFenetre;
		_retourHierarchie = true;
		_continuer = true;
		
		return false;
	}
	if(_horlogesAjoutees) {
		for(std::list<Session::HorlogeLocale *>::iterator i = Session::_horloges.begin(); i != Session::_horloges.end(); ++i) {
			if((*i)->_v == 0) {
				(*i)->_v = _vueTemp;
			}
		}
		_horlogesAjoutees = false;
	}
	if(Session::_vueFenetre != _vueTemp || _retourHierarchie) {
		if(!_retourHierarchie || _vues.top() != _vueTemp) {
			_vues.push(_vueTemp);
		}
		
		_retourHierarchie = false;
		Session::reinitialiserEvenements();
		_horlogeSurvol = horloge();
		
		horloge_t tpsV = _derniersTemps[_vueTemp];
		horloge_t tps = horloge();
		for(std::list<Session::HorlogeLocale *>::iterator i = Session::_horloges.begin(); i != Session::_horloges.end(); ++i) {
			if((*i)->_v == _vueTemp && ***i != 0.0) {
				***i += tps - tpsV;
			}
		}
		
		_vueFenetre = _vueTemp;
		VueInterface::definirVueActuelle(_vueFenetre);
	}
	
	Ecran::effacer();
	int couche = 0, ancien;
	do {
		ancien = couche;
		_vueFenetre->preparationDessin();
		Ecran::ajouterCadreAffichage(_vueFenetre->cadre());
		Ecran::ajouterVerrouTransformations();

		_vueFenetre->afficher(glm::vec2(0), ancien, couche);
		glDisable(GL_DEPTH_TEST);

		Ecran::retourVerrouTransformations();
		Ecran::supprimerVerrouTransformations();
		Ecran::supprimerCadreAffichage();
	} while(ancien != couche);
	
	Ecran::finaliser();

	bool const aClic[2] = {_evenements[B_GAUCHE], _evenements[B_DROIT]};

	_evenements[SOURIS] = false;

	while(Session::gestionEvenements());
	
	if(_souris != _sourisClic) {
		_nbClic[0] = _nbClic[1] = 0;
	}
	if(horloge() - _horlogeClic > DELAI_REPETITION_CLIC) {
		_nbClic[0] = _nbClic[1] = 0;
	}
	
	if(_evenements[B_GAUCHE] && !aClic[0]) {
		_nbClic[1] = 0;
		_sourisClic = _souris;
		_horlogeClic = horloge();
	}
	else if(!_evenements[B_GAUCHE] && aClic[0]) {
		++_nbClic[0];
	}
	
	if(_souris != _sourisSurvol && horloge() - _horlogeSurvol < 1.0f) {
		_horlogeSurvol = horloge();
		_sourisSurvol = _souris;
	}
	
	if(_vueFenetre) {
		_derniersTemps[_vueTemp] = horloge();
		
		if(VueInterface *a = _vueFenetre->gestionClic()) {
			VueInterface::definirVueActuelle(a);
		}
		_vueFenetre->gestionGestionClavier();
		
		if(VueInterface *tmp = VueInterface::vueActuelle()) {
			tmp->gestionSouris(true, Session::souris() - tmp->positionAbsolue(), _evenements[B_GAUCHE], _evenements[B_DROIT]);
		}
		if(!_evenements[B_GAUCHE] && !_evenements[B_DROIT]) {
			if(VueInterface *tmp = _vueFenetre->gestionSurvol()) {
				tmp->gestionSouris(false, Session::souris() - tmp->positionAbsolue(), _evenements[B_GAUCHE], _evenements[B_DROIT]);
				if(tmp->description().empty())
					_horlogeSurvol = horloge();
				else if(horloge() - _horlogeSurvol >= 1.0f) {
					Ecran::definirBulleAide(tmp->description());
				}
			}
			else {
				_horlogeSurvol = horloge();
			}
		}
		else {
			_horlogeSurvol = horloge();
		}
		
		Ecran::maj();
	}
	
	_vueTemp = _vueFenetre;
	
	attendre(1.0f / freq - (horloge() - Session::_horlogeBoucle));
	Session::_horlogeBoucle = horloge();
	
	return continuer;
}
Exemplo n.º 8
0
void MenuInterface::gestionSouris(bool vueActuelle, glm::vec2 const &souris, bool gauche, bool /*droit*/) {
    if(!vueActuelle)
        return;

    if(_premierAffiche != 0 && Rectangle(0, 0, this->dimensions().x, _hF + 5).contientPoint(souris)) {
        horloge_t dif = horloge() - _horlogeDefilement;
        if(dif >= interpolationQuadratique<float>(0.0, 0.02, _hF + 5, 0.2, souris.y)) {
            _horlogeDefilement = horloge();
            int nbF = (_premierAffiche != 0) + (_dernierAffiche != _elements.size());
            --_premierAffiche;
            if(this->positionAbsolue().y + this->dimensions().y + _hF + 5 < Ecran::hauteur()) {
                Rectangle cc = this->cadre();
                cc.hauteur += _hF + 5;
                this->definirCadre(cc);
            }
            else {
                --_dernierAffiche;
                _dernierAffiche += nbF - ((_premierAffiche != 0) + (_dernierAffiche != _elements.size()));
            }
        }
        return;
    }
    else if(_dernierAffiche != _elements.size() && Rectangle(0, this->dimensions().y - _hF - 5, this->dimensions().x, _hF + 5).contientPoint(souris)) {
        horloge_t dif = horloge() - _horlogeDefilement;
        if(dif >= interpolationQuadratique<float>(0.0, 0.02, _hF + 5, 0.2, souris.y - this->dimensions().y)) {
            _horlogeDefilement = horloge();
            int nbF = (_premierAffiche != 0) + (_dernierAffiche != _elements.size());
            ++_dernierAffiche;
            if(this->positionAbsolue().y >= _hF + 5) {
                Rectangle cc = this->cadre();
                cc.haut -= _hF + 5;
                cc.hauteur += _hF + 5;
                this->definirCadre(cc);
            }
            else {
                ++_premierAffiche;
                _premierAffiche -= nbF - ((_premierAffiche != 0) + (_dernierAffiche != _elements.size()));
            }
        }
        return;
    }

    _sousMenuSurvole = -1;
    for(index_t i = _premierAffiche; i != _dernierAffiche; ++i) {
        if(Rectangle(_elements[i]._pos - glm::vec2(0, 2.5), glm::vec2(this->dimensions().x, _elements[i]._texte.dimensions().y + 5)).contientPoint(souris)) {
            _sousMenuSurvole = i;
            break;
        }
    }

    if(gauche) {
        if(_sousMenuSurvole != -1) {
            if(this->valeurIndeterminee()) {
                if(_sousMenuSurvole != 0) {
                    this->supprimerBlanc();
                    this->definirSousMenuSelectionne(_sousMenuSurvole - 1);
                }
            }
            else
                this->definirSousMenuSelectionne(_sousMenuSurvole);
        }
        this->definirMasque(true);
        static_cast<MenuDeroulant *>(this->parent())->exec();
        Session::reinitialiser(Session::B_GAUCHE);
    }
}