8 extern float multiplier;
11 enum MenuItemType{NONE,LABEL,BUTTON,IMAGE,IMAGEBUTTON,MAPMARKER,MAPLINE,MAPLABEL} type;
22 void init(MenuItemType _type, int _id, const string& _text, Texture _texture,
23 int _x, int _y, int _w, int _h, float _r, float _g, float _b,
24 float _linestartsize=1, float _lineendsize=1){
29 x=_x; y=_y; w=_w; h=_h;
32 linestartsize=_linestartsize;
33 lineendsize=_lineendsize;
34 if(type==MenuItem::BUTTON){
43 vector<MenuItem> items;
48 void Menu::clearMenu(){
52 void Menu::addLabel(int id,const string& text,int x,int y,float r,float g,float b){
53 items.push_back(MenuItem());
54 items.back().init(MenuItem::LABEL,id,text,Texture(),x,y,-1,-1,r,g,b);
56 void Menu::addButton(int id,const string& text,int x,int y,float r,float g,float b){
57 items.push_back(MenuItem());
58 items.back().init(MenuItem::BUTTON,id,text,Texture(),x,y,-1,-1,r,g,b);
60 void Menu::addImage(int id,Texture texture,int x,int y,int w,int h,float r,float g,float b){
61 items.push_back(MenuItem());
62 items.back().init(MenuItem::IMAGE,id,"",texture,x,y,w,h,r,g,b);
64 void Menu::addButtonImage(int id,Texture texture,int x,int y,int w,int h,float r,float g,float b){
65 items.push_back(MenuItem());
66 items.back().init(MenuItem::IMAGEBUTTON,id,"",texture,x,y,w,h,r,g,b);
68 void Menu::addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r,float g,float b){
69 items.push_back(MenuItem());
70 items.back().init(MenuItem::MAPLINE,-1,"",Texture(),x,y,w,h,r,g,b,startsize,endsize);
72 void Menu::addMapMarker(int id,Texture texture,int x,int y,int w,int h,float r,float g,float b){
73 items.push_back(MenuItem());
74 items.back().init(MenuItem::MAPMARKER,id,"",texture,x,y,w,h,r,g,b);
76 void Menu::addMapLabel(int id,const string& text,int x,int y,float r,float g,float b){
77 items.push_back(MenuItem());
78 items.back().init(MenuItem::MAPLABEL,id,text,Texture(),x,y,-1,-1,r,g,b);
81 void Menu::setText(int id,const string& text){
82 for(vector<MenuItem>::iterator it=items.begin();it!=items.end();it++)
85 it->w=it->text.length()*10;
90 void Menu::setText(int id,const string& text,int x,int y,int w,int h){
91 for(vector<MenuItem>::iterator it=items.begin();it!=items.end();it++)
97 it->w=it->text.length()*10;
104 int Menu::getSelected(int mousex, int mousey){
105 for(vector<MenuItem>::iterator it=items.begin();it!=items.end();it++)
106 if(it->type==MenuItem::BUTTON || it->type==MenuItem::IMAGEBUTTON || it->type==MenuItem::MAPMARKER){
109 if(it->type==MenuItem::MAPMARKER){
113 if(mx>=it->x && mx<it->x+it->w && my>=it->y && my<it->y+it->h)
120 for(vector<MenuItem>::iterator it=items.begin();it!=items.end();it++){
121 if(it->id==Game::selected){
122 it->effectfade+=multiplier*5;
126 it->effectfade-=multiplier*5;
133 void Menu::drawItems(){
135 glEnable(GL_TEXTURE_2D);
136 glEnable(GL_ALPHA_TEST);
138 for(vector<MenuItem>::iterator it=items.begin();it!=items.end();it++){
140 case MenuItem::IMAGE:
141 case MenuItem::IMAGEBUTTON:
142 case MenuItem::MAPMARKER:
143 glColor4f(it->r,it->g,it->b,1);
145 if(it->type==MenuItem::MAPMARKER){
146 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
147 glTranslatef(2.5,-4.5,0); //from old code
149 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
152 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
153 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
156 glVertex3f(it->x,it->y,0);
158 glVertex3f(it->x+it->w,it->y,0);
160 glVertex3f(it->x+it->w,it->y+it->h,0);
162 glVertex3f(it->x,it->y+it->h,0);
164 if(it->type!=MenuItem::IMAGE){
165 //mouseover highlight
166 for(int i=0;i<10;i++){
167 if(1-((float)i)/10-(1-it->effectfade)>0){
168 glColor4f(it->r,it->g,it->b,(1-((float)i)/10-(1-it->effectfade))*.25);
171 glVertex3f(it->x-((float)i)*1/2, it->y-((float)i)*1/2, 0);
173 glVertex3f(it->x+it->w+((float)i)*1/2, it->y-((float)i)*1/2, 0);
175 glVertex3f(it->x+it->w+((float)i)*1/2, it->y+it->h+((float)i)*1/2, 0);
177 glVertex3f(it->x-((float)i)*1/2, it->y+it->h+((float)i)*1/2, 0);
184 case MenuItem::LABEL:
185 case MenuItem::BUTTON:
186 glColor4f(it->r,it->g,it->b,1);
187 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
188 Game::text->glPrint(it->x,it->y,it->text.c_str(),0,1,640,480);
189 if(it->type!=MenuItem::LABEL){
190 //mouseover highlight
191 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
192 for(int i=0;i<15;i++){
193 if(1-((float)i)/15-(1-it->effectfade)>0){
194 glColor4f(it->r,it->g,it->b,(1-((float)i)/10-(1-it->effectfade))*.25);
195 Game::text->glPrint(it->x-((float)i),it->y,it->text.c_str(),0,1+((float)i)/70,640,480);
200 case MenuItem::MAPLABEL:
201 Game::text->glPrintOutlined(0.9,0,0,it->x,it->y,it->text.c_str(),0,0.6,640,480);
203 case MenuItem::MAPLINE: {
209 lineend.x=it->x+it->w;
210 lineend.y=it->y+it->h;
212 XYZ offset=lineend-linestart;
215 offset=DoRotation(offset,0,0,90);
218 linestart+=fac*4*it->linestartsize;
219 lineend-=fac*4*it->lineendsize;
221 glDisable(GL_TEXTURE_2D);
222 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
223 glColor4f(it->r,it->g,it->b,1);
225 glTranslatef(2,-5,0); //from old code
227 glVertex3f(linestart.x-offset.x*it->linestartsize, linestart.y-offset.y*it->linestartsize, 0.0f);
228 glVertex3f(linestart.x+offset.x*it->linestartsize, linestart.y+offset.y*it->linestartsize, 0.0f);
229 glVertex3f(lineend.x+offset.x*it->lineendsize, lineend.y+offset.y*it->lineendsize, 0.0f);
230 glVertex3f(lineend.x-offset.x*it->lineendsize, lineend.y-offset.y*it->lineendsize, 0.0f);
233 glEnable(GL_TEXTURE_2D);