fix al problema con "const char *", parece que en gcc 4.2.3 andaba, en 4.5.2 no XD
[seni.git] / engine / menu.cpp
blob5b36cf215e78e99bffaf90b5af530fef908b2e83
1 /*SENI, Search for Extra Nibiru Intelligence*/
3 /*
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Copyright SSW Team 2010
22 #include <string.h>
23 #include "menu.hpp"
24 #include "engine.hpp"
26 Option::Option()
28 this->id = 0;
29 this->image[0] = 0;
30 this->Simage = 0;
31 this->event = 0;
32 this->engine = 0;
35 Option::Option(Engine *e)
37 this->id = 0;
38 this->image[0] = 0;
39 this->Simage = 0;
40 this->event = 0;
41 this->engine = e;
44 Option::Option(char *f, Engine *e)
46 this->id = 0;
47 this->engine = e;
48 this->setImage(f);
49 this->event = 0;
52 Option::Option(char *f, int i, Engine *e)
54 this->setId(i);
55 this->engine = e;
56 this->setImage(f);
57 this->event = 0;
60 int Option::getId(void)
62 return this->id;
65 void Option::setId(int i)
67 this->id = i;
70 int Option::setImage(char *f)
72 char err[255];
73 if(!this->engine)
74 return MENU_NO_ENGINE;
75 strcpy(this->image, f);
76 this->Simage = SDL_LoadBMP(f);
77 if(!this->Simage){
78 strcpy(err, "Error: SDL_LoadBMP(f): ");
79 strcat(err, SDL_GetError());
80 this->engine->setError(err);
81 return MENU_ERROR;
83 this->engine->setError((char *)"No hay errores", ERROR_NO_PRINT);
84 return MENU_NO_ERROR;
87 void Option::setEvent(option_event oe)
89 event = oe;
92 int Option::execEvent(SDL_Event *se, Engine *e, Menu *m, Option *o)
94 if(!this->event)
95 return OPTION_STAY;
96 return this->event(se, e, m, o);
99 int Option::show(void)
101 char err[255];
102 if(!this->engine)
103 return MENU_NO_ENGINE;
104 if(!this->Simage){
105 engine->setError((char *)"Error: No se asigno imagen");
106 return MENU_ERROR;
108 if(this->engine->show(this->Simage, this->x, this->y, this->Simage->w, this->Simage->h) == ENGINE_ERROR){
109 strcpy(err, "Error: Option->show()->engine->show(): ");
110 strcat(err, SDL_GetError());
111 this->engine->setError(err);
112 return MENU_ERROR;
114 // this->engine->update(this->x, this->y, this->Simage->w, this->Simage->h);
115 engine->setError((char *)"No hay errores", ERROR_NO_PRINT);
116 return MENU_NO_ERROR;
120 int Option::update(void)
122 if(!engine)
123 return MENU_NO_ENGINE;
124 this->engine->update(this->x, this->y, this->Simage->w, this->Simage->h);
125 return MENU_NO_ERROR;
128 void Option::setXY(int x, int y)
130 this->x = x;
131 this->y = y;
134 int Option::getX(void)
136 return this->x;
139 int Option::getY(void)
141 return this->y;
144 int Option::getH(void)
146 return this->Simage ? this->Simage->h : 0;
149 int Option::getW(void)
151 return this->Simage ? this->Simage->w : 0;
154 void Option::setEngine(Engine *e)
156 this->engine = e;
159 Menu::Menu(void)
161 int i;
162 this->engine = 0;
163 for(i = 0; i < MAX_OPTIONS; i++)
164 this->options[i] = WITHOUT_OPTION;
165 this->wallpaper[0] = 0;
168 Menu::Menu(Engine *e)
170 int i;
171 this->engine = e;
172 for(i = 0; i < MAX_OPTIONS; i++)
173 this->options[i] = WITHOUT_OPTION;
174 this->wallpaper[0] = 0;
177 Menu::Menu(char *w, Engine *e)
179 int i;
180 this->engine = e;
181 for(i = 0; i < MAX_OPTIONS; i++)
182 this->options[i] = WITHOUT_OPTION;
183 this->setWallpaper(w);
186 Menu::Menu(char *w, Option **o, int im, Engine *e)
188 int i;
189 this->engine = e;
190 for(i = 0; i < im && i < MAX_OPTIONS; i++){
191 this->options[i] = o[i];
193 for(;i < MAX_OPTIONS; i++)
194 this->options[i] = WITHOUT_OPTION;
195 this->setWallpaper(w);
198 int Menu::setWallpaper(char *w)
200 char err[255];
201 strcpy(this->wallpaper, w);
202 this->Swallpaper = SDL_LoadBMP(w);
203 if(!this->Swallpaper){
204 strcpy(err, "Error: SDL_LoadBMP(w): ");
205 strcat(err, SDL_GetError());
206 this->engine->setError(err);
207 return MENU_ERROR;
209 this->engine->setError((char *)"No hay errores", ERROR_NO_PRINT);
210 return MENU_NO_ERROR;
213 int Menu::addOption(Option *o)
215 int i;
216 for(i = 0; i < MAX_OPTIONS; i++){
217 if(this->options[i] == WITHOUT_OPTION){
218 this->options[i] = o;
219 return MENU_NO_ERROR;
222 return OPTIONS_FULL;
225 Option *Menu::getOptionById(int oid)
227 int i;
228 for(i = 0; i < MAX_OPTIONS; i++){
229 if(options[i] != WITHOUT_OPTION && options[i]->getId() == oid){
230 return options[i];
233 return 0;
236 Option *Menu::getOption(int i)
238 if(i >= MAX_OPTIONS)
239 return WITHOUT_OPTION;
240 return this->options[i];
243 int Menu::removeOption(int oid)
245 int i;
246 for(i = 0; i < MAX_OPTIONS; i++){
247 if(options[i] != WITHOUT_OPTION && options[i]->getId() == oid){
248 options[i] = WITHOUT_OPTION;
249 return MENU_NO_ERROR;
252 return NO_OPTION;
255 int Menu::show()
257 int i;
258 char err[255];
259 if(!this->engine)
260 return MENU_NO_ENGINE;
261 if(this->engine->show(this->Swallpaper, 0, 0, this->Swallpaper->w, this->Swallpaper->h) == ENGINE_ERROR){
262 strcpy(err, "Error: Menu->show()->engine->show(): ");
263 strcat(err, SDL_GetError());
264 this->engine->setError(err);
265 return MENU_ERROR;
267 // this->engine->update(0, 0, 0, 0);
268 for(i = 0; i < MAX_OPTIONS; ++i){
269 if(this->options[i] != WITHOUT_OPTION){
270 int r = this->options[i]->show();
271 if(r != MENU_NO_ERROR)
272 return r;
275 return MENU_NO_ERROR;
278 int Menu::update(void)
280 if(!engine)
281 return MENU_NO_ENGINE;
282 this->engine->update(0, 0, 0, 0);
283 return MENU_NO_ERROR;
286 void Menu::setEngine(Engine *e)
288 this->engine = e;