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) {
37 linestartsize = _linestartsize;
38 lineendsize = _lineendsize;
39 if (type == MenuItem::BUTTON) {
41 w = text.length() * 10;
48 vector<MenuItem> items;
53 void Menu::clearMenu()
58 void Menu::addLabel(int id, const string& text, int x, int y, float r, float g, float b)
60 items.push_back(MenuItem());
61 items.back().init(MenuItem::LABEL, id, text, Texture(), x, y, -1, -1, r, g, b);
63 void Menu::addButton(int id, const string& text, int x, int y, float r, float g, float b)
65 items.push_back(MenuItem());
66 items.back().init(MenuItem::BUTTON, id, text, Texture(), x, y, -1, -1, r, g, b);
68 void Menu::addImage(int id, Texture texture, int x, int y, int w, int h, float r, float g, float b)
70 items.push_back(MenuItem());
71 items.back().init(MenuItem::IMAGE, id, "", texture, x, y, w, h, r, g, b);
73 void Menu::addButtonImage(int id, Texture texture, int x, int y, int w, int h, float r, float g, float b)
75 items.push_back(MenuItem());
76 items.back().init(MenuItem::IMAGEBUTTON, id, "", texture, x, y, w, h, r, g, b);
78 void Menu::addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r, float g, float b)
80 items.push_back(MenuItem());
81 items.back().init(MenuItem::MAPLINE, -1, "", Texture(), x, y, w, h, r, g, b, startsize, endsize);
83 void Menu::addMapMarker(int id, Texture texture, int x, int y, int w, int h, float r, float g, float b)
85 items.push_back(MenuItem());
86 items.back().init(MenuItem::MAPMARKER, id, "", texture, x, y, w, h, r, g, b);
88 void Menu::addMapLabel(int id, const string& text, int x, int y, float r, float g, float b)
90 items.push_back(MenuItem());
91 items.back().init(MenuItem::MAPLABEL, id, text, Texture(), x, y, -1, -1, r, g, b);
94 void Menu::setText(int id, const string& text)
96 for (vector<MenuItem>::iterator it = items.begin(); it != items.end(); it++)
99 it->w = it->text.length() * 10;
104 void Menu::setText(int id, const string& text, int x, int y, int w, int h)
106 for (vector<MenuItem>::iterator it = items.begin(); it != items.end(); it++)
112 it->w = it->text.length() * 10;
119 int Menu::getSelected(int mousex, int mousey)
121 for (vector<MenuItem>::iterator it = items.begin(); it != items.end(); it++)
122 if (it->type == MenuItem::BUTTON || it->type == MenuItem::IMAGEBUTTON || it->type == MenuItem::MAPMARKER) {
125 if (it->type == MenuItem::MAPMARKER) {
129 if (mx >= it->x && mx < it->x + it->w && my >= it->y && my < it->y + it->h)
137 for (vector<MenuItem>::iterator it = items.begin(); it != items.end(); it++) {
138 if (it->id == Game::selected) {
139 it->effectfade += multiplier * 5;
140 if (it->effectfade > 1)
143 it->effectfade -= multiplier * 5;
144 if (it->effectfade < 0)
150 void Menu::drawItems()
153 glEnable(GL_TEXTURE_2D);
154 glEnable(GL_ALPHA_TEST);
156 for (vector<MenuItem>::iterator it = items.begin(); it != items.end(); it++) {
158 case MenuItem::IMAGE:
159 case MenuItem::IMAGEBUTTON:
160 case MenuItem::MAPMARKER:
161 glColor4f(it->r, it->g, it->b, 1);
163 if (it->type == MenuItem::MAPMARKER) {
164 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
165 glTranslatef(2.5, -4.5, 0); //from old code
167 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
170 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
171 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
174 glVertex3f(it->x, it->y, 0);
176 glVertex3f(it->x + it->w, it->y, 0);
178 glVertex3f(it->x + it->w, it->y + it->h, 0);
180 glVertex3f(it->x, it->y + it->h, 0);
182 if (it->type != MenuItem::IMAGE) {
183 //mouseover highlight
184 for (int i = 0; i < 10; i++) {
185 if (1 - ((float)i) / 10 - (1 - it->effectfade) > 0) {
186 glColor4f(it->r, it->g, it->b, (1 - ((float)i) / 10 - (1 - it->effectfade))*.25);
189 glVertex3f(it->x - ((float)i) * 1 / 2, it->y - ((float)i) * 1 / 2, 0);
191 glVertex3f(it->x + it->w + ((float)i) * 1 / 2, it->y - ((float)i) * 1 / 2, 0);
193 glVertex3f(it->x + it->w + ((float)i) * 1 / 2, it->y + it->h + ((float)i) * 1 / 2, 0);
195 glVertex3f(it->x - ((float)i) * 1 / 2, it->y + it->h + ((float)i) * 1 / 2, 0);
202 case MenuItem::LABEL:
203 case MenuItem::BUTTON:
204 glColor4f(it->r, it->g, it->b, 1);
205 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
206 Game::text->glPrint(it->x, it->y, it->text.c_str(), 0, 1, 640, 480);
207 if (it->type != MenuItem::LABEL) {
208 //mouseover highlight
209 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
210 for (int i = 0; i < 15; i++) {
211 if (1 - ((float)i) / 15 - (1 - it->effectfade) > 0) {
212 glColor4f(it->r, it->g, it->b, (1 - ((float)i) / 10 - (1 - it->effectfade))*.25);
213 Game::text->glPrint(it->x - ((float)i), it->y, it->text.c_str(), 0, 1 + ((float)i) / 70, 640, 480);
218 case MenuItem::MAPLABEL:
219 Game::text->glPrintOutlined(0.9, 0, 0, it->x, it->y, it->text.c_str(), 0, 0.6, 640, 480);
221 case MenuItem::MAPLINE: {
227 lineend.x = it->x + it->w;
228 lineend.y = it->y + it->h;
230 XYZ offset = lineend - linestart;
233 offset = DoRotation(offset, 0, 0, 90);
236 linestart += fac * 4 * it->linestartsize;
237 lineend -= fac * 4 * it->lineendsize;
239 glDisable(GL_TEXTURE_2D);
240 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
241 glColor4f(it->r, it->g, it->b, 1);
243 glTranslatef(2, -5, 0); //from old code
245 glVertex3f(linestart.x - offset.x * it->linestartsize, linestart.y - offset.y * it->linestartsize, 0.0f);
246 glVertex3f(linestart.x + offset.x * it->linestartsize, linestart.y + offset.y * it->linestartsize, 0.0f);
247 glVertex3f(lineend.x + offset.x * it->lineendsize, lineend.y + offset.y * it->lineendsize, 0.0f);
248 glVertex3f(lineend.x - offset.x * it->lineendsize, lineend.y - offset.y * it->lineendsize, 0.0f);
251 glEnable(GL_TEXTURE_2D);