Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Composants | Déclarations

pi2d14_selectionbutton.cpp

Aller à la documentation de ce fichier.
00001 
00002 #include <pi2d14/pi2d14_selectionbutton.h>
00003 
00004 /*
00005 *       constructeur
00006 *
00007 *       @pr� nbEntry>0
00008 *       @pr� idTex>0
00009 *       @pr� idButton>0
00010 *       @param *idTex pointer sur tableau d'identifiant de texture OpenGL
00011 *       @param *idButton pointer sur tableau d'identifiant de bouton
00012 */
00013 MENU::SelectionButton::SelectionButton(unsigned int *idTex, unsigned int *idButton, unsigned int nbEntry)
00014 {
00015         if(nbEntry>0 && idTex!=NULL && idButton!=NULL)
00016         {
00017         std::cout<<"chargement menu fait\n";
00018                 currentSelection = 0;                                                   //initialisation du pointeur null
00019                 nbSelection = nbEntry;                                                  //0 selection possible au d�but
00020                 selections = new Selection[nbEntry];                    //cration du tableau
00021 
00022                 for(int i=0; i<nbEntry; i++)                                    //pour chaque entree on affecte les valeurs
00023                 {
00024                         selections[i].idButton = idButton[i];
00025                         selections[i].idTexture = idTex[i];
00026                 }
00027         }
00028 }
00029 
00030 MENU::SelectionButton::~SelectionButton()
00031 {
00032         delete [] selections;
00033 }
00034 
00035 /*
00036 *       rend le boutton a l'ecran
00037 *
00038 *       @param x , coordonnee x du coin inferieur gauche du boutton
00039 *       @param y , coordonnee y du coin inferieur gauche du boutton
00040 *       @param sizex , taille sur x du boutton
00041 *       @param sizey , taille sur y du boutton
00042 *       @param r , composante rouge de la bordure  0<=r<=1
00043 *       @param g , composante rouge de la bordure  0<=g<=1
00044 *       @param b , composante rouge de la bordure  0<=b<=1
00045 */
00046 void MENU::SelectionButton::render(float x, float y, float sizex, float sizey, float r, float g, float b)
00047 {
00048         //dessin de l'interieur si une selection existe
00049         if(nbSelection!=0)
00050         {
00051                 glEnable(GL_ALPHA_TEST);
00052                 glAlphaFunc(GL_GREATER,0.8);
00053 
00054                 //on selestionne la texture de l'imtem courant
00055                 glEnable(GL_TEXTURE_2D);
00056                 glBindTexture(GL_TEXTURE_2D,selections[currentSelection].idTexture);
00057                 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
00058 
00059                 //on affiche la selection
00060                 glBegin(GL_QUADS);
00061                 glTexCoord2f(0, 0);
00062                 glVertex2f(x, y);
00063                 glTexCoord2f(1, 0);
00064                 glVertex2f(x+sizex, y);
00065                 glTexCoord2f(1, 1);
00066                 glVertex2f(x+sizex, y+sizey);
00067                 glTexCoord2f(0, 1);
00068                 glVertex2f(x, y+sizey);
00069                 glEnd();
00070 
00071                 glDisable(GL_ALPHA_TEST);
00072         }
00073 
00074         //dessin du contour du bouton
00075         glDisable(GL_TEXTURE_2D);
00076         glBegin(GL_LINE_LOOP);
00077         glColor3f(r,g,b);
00078         glVertex2f(x, y);
00079         glVertex2f(x+sizex, y);
00080         glVertex2f(x+sizex, y+sizey);
00081         glVertex2f(x, y+sizey);
00082         glEnd();
00083         glEnable(GL_TEXTURE_2D);
00084 }
00085 
00086 /*
00087 *   @return retourne l'identifiant de la selection courante
00088 */
00089 int MENU::SelectionButton::getCurrentSelectionID()
00090 {
00091         if(nbSelection!=0)
00092         {
00093                 return selections[currentSelection].idButton;
00094         }
00095 }
00096 
00097 /*
00098 *   @return retourne l'identifiant de texture OpenGL de la s�lection courante
00099 */
00100 int MENU::SelectionButton::getCurrentSelectionTexID()
00101 {
00102         if(nbSelection!=0)
00103         {
00104                 return selections[currentSelection].idTexture;
00105         }
00106 }
00107 
00108 /*
00109 *       se positionne sur le prochaine element
00110 *
00111 *       TODO : preciser
00112 */
00113 void MENU::SelectionButton::next()
00114 {
00115         if(nbSelection!=0)
00116         {
00117                 currentSelection++;
00118                 if(currentSelection>=nbSelection)
00119                 {
00120                         currentSelection=0;
00121                 }
00122         }
00123 }
00124 
00125 /*
00126 *       se positionne sur le prochaine element
00127 *
00128 *       TODO : preciser
00129 */
00130 void MENU::SelectionButton::prev()
00131 {
00132         if(nbSelection!=0)
00133         {
00134                 if(currentSelection==0)
00135                 {
00136                         currentSelection=nbSelection-1;
00137                 }
00138                 else
00139                 {
00140                         currentSelection--;
00141                 }
00142         }
00143 }
00144 
00145 unsigned int MENU::SelectionButton::getNbSelection()
00146 {
00147         return nbSelection;
00148 }
00149 
00150 
00151 

Généré le Fri Mar 26 13:02:03 2004 pour AlgoAtomD par doxygen 1.3.5