00001
00002 #include <pi2d14/pi2d14_selectionbutton.h>
00003
00004
00005
00006
00007
00008
00009
00010
00011
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;
00019 nbSelection = nbEntry;
00020 selections = new Selection[nbEntry];
00021
00022 for(int i=0; i<nbEntry; i++)
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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 void MENU::SelectionButton::render(float x, float y, float sizex, float sizey, float r, float g, float b)
00047 {
00048
00049 if(nbSelection!=0)
00050 {
00051 glEnable(GL_ALPHA_TEST);
00052 glAlphaFunc(GL_GREATER,0.8);
00053
00054
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
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
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
00088
00089 int MENU::SelectionButton::getCurrentSelectionID()
00090 {
00091 if(nbSelection!=0)
00092 {
00093 return selections[currentSelection].idButton;
00094 }
00095 }
00096
00097
00098
00099
00100 int MENU::SelectionButton::getCurrentSelectionTexID()
00101 {
00102 if(nbSelection!=0)
00103 {
00104 return selections[currentSelection].idTexture;
00105 }
00106 }
00107
00108
00109
00110
00111
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
00127
00128
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