Revision 251
menu work
proj_func.c | ||
---|---|---|
10 | 10 |
#include "utils.h" |
11 | 11 |
#include "ent.h" |
12 | 12 |
#include "fast_math.h" |
13 |
#include "rectangle.h" |
|
14 |
#include "font.h" |
|
13 | 15 |
|
14 | 16 |
#include "kbc_macros.h" |
15 | 17 |
|
... | ... | |
189 | 191 |
return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p)); |
190 | 192 |
} |
191 | 193 |
|
194 |
struct menu { |
|
195 |
rectangle_t *r0, *r1, *r2; |
|
196 |
text_t *t0, *t1, *t2; |
|
197 |
rectangle_t *frame; |
|
198 |
}; |
|
199 |
|
|
200 |
menu_t* (menu_ctor)(const font_t *fnt){ |
|
201 |
if(fnt == NULL) return NULL; |
|
202 |
menu_t *ret = (menu_t*)malloc(sizeof(menu_t)); |
|
203 |
if (ret == NULL) return NULL; |
|
204 |
ret->r0 = rectangle_ctor(0, 0, 400, 100); |
|
205 |
ret->r1 = rectangle_ctor(0, 0, 400, 100); |
|
206 |
ret->r2 = rectangle_ctor(0, 0, 400, 100); |
|
207 |
ret->t0 = text_ctor(fnt, "PLAY"); |
|
208 |
ret->t1 = text_ctor(fnt, "TEST"); |
|
209 |
ret->t2 = text_ctor(fnt, "EXIT"); |
|
210 |
ret->frame = rectangle_ctor(0, 0, 800, 500); |
|
211 |
if (ret->r0 == NULL || ret->r1 == NULL || ret->r2 == NULL || |
|
212 |
ret->t0 == NULL || ret->t1 == NULL || ret->t2 == NULL || |
|
213 |
ret->frame == NULL) return NULL; |
|
214 |
// VISUAL |
|
215 |
rectangle_set_fill_color(ret->r0, BLACK); |
|
216 |
rectangle_set_outline_width(ret->r0, 2); |
|
217 |
rectangle_set_outline_color(ret->r0, WHITE); |
|
218 |
rectangle_set_fill_color(ret->r1, BLACK); |
|
219 |
rectangle_set_outline_width(ret->r1, 2); |
|
220 |
rectangle_set_outline_color(ret->r1, WHITE); |
|
221 |
rectangle_set_fill_color(ret->r2, BLACK); |
|
222 |
rectangle_set_outline_width(ret->r2, 2); |
|
223 |
rectangle_set_outline_color(ret->r2, WHITE); |
|
224 |
text_set_valign(ret->t0, text_valign_center); |
|
225 |
text_set_halign(ret->t0, text_halign_center); |
|
226 |
text_set_color(ret->t0, TEXT_COLOR); |
|
227 |
text_set_valign(ret->t1, text_valign_center); |
|
228 |
text_set_halign(ret->t1, text_halign_center); |
|
229 |
text_set_color(ret->t1, TEXT_COLOR); |
|
230 |
text_set_valign(ret->t2, text_valign_center); |
|
231 |
text_set_halign(ret->t2, text_halign_center); |
|
232 |
text_set_color(ret->t2, TEXT_COLOR); |
|
233 |
rectangle_set_fill_color(ret->frame, BLACK); |
|
234 |
rectangle_set_outline_width(ret->frame, 6); |
|
235 |
rectangle_set_outline_color(ret->frame, WHITE); |
|
236 |
// POSITIONS |
|
237 |
rectangle_set_pos(ret->r0, |
|
238 |
graph_get_XRes()/2 - rectangle_get_w(ret->r0)/2, |
|
239 |
graph_get_YRes()*0.35 - rectangle_get_h(ret->r0)/2); |
|
240 |
|
|
241 |
|
|
242 |
rectangle_set_pos(ret->r1, |
|
243 |
graph_get_XRes()/2 - rectangle_get_w(ret->r1)/2, |
|
244 |
graph_get_YRes()*0.5 - rectangle_get_h(ret->r1)/2); |
|
245 |
|
|
246 |
|
|
247 |
rectangle_set_pos(ret->r2, |
|
248 |
graph_get_XRes()/2 - rectangle_get_w(ret->r2)/2, |
|
249 |
graph_get_YRes()*0.65 - rectangle_get_h(ret->r2)/2); |
|
250 |
|
|
251 |
text_set_pos(ret->t0, rectangle_get_x(ret->r0)+rectangle_get_w(ret->r0)/2, |
|
252 |
rectangle_get_y(ret->r0)+rectangle_get_h(ret->r0)/2); |
|
253 |
|
|
254 |
text_set_pos(ret->t1, rectangle_get_x(ret->r1)+rectangle_get_w(ret->r1)/2, |
|
255 |
rectangle_get_y(ret->r1)+rectangle_get_h(ret->r1)/2); |
|
256 |
|
|
257 |
text_set_pos(ret->t2, rectangle_get_x(ret->r2)+rectangle_get_w(ret->r2)/2, |
|
258 |
rectangle_get_y(ret->r2)+rectangle_get_h(ret->r2)/2); |
|
259 |
|
|
260 |
rectangle_set_pos(ret->frame, |
|
261 |
graph_get_XRes()/2 - rectangle_get_w(ret->frame)/2, |
|
262 |
graph_get_YRes()*0.5 - rectangle_get_h(ret->frame)/2); |
|
263 |
return ret; |
|
264 |
} |
|
265 |
|
|
266 |
static int highlighted = -1; |
|
267 |
|
|
268 |
int (menu_update_state)(menu_t *menu, int click) { |
|
269 |
|
|
270 |
if (rectangle_collide_point(menu->r0, mouse_x, mouse_y)) { |
|
271 |
highlighted = GAME; |
|
272 |
if (click) return GAME; |
|
273 |
} else if (rectangle_collide_point(menu->r1, mouse_x, mouse_y)) { |
|
274 |
highlighted = TEST; |
|
275 |
if (click) return TEST; |
|
276 |
} else if (rectangle_collide_point(menu->r2, mouse_x, mouse_y)) { |
|
277 |
highlighted = EXIT; |
|
278 |
if (click) return EXIT; |
|
279 |
} else { |
|
280 |
highlighted = -1; |
|
281 |
} |
|
282 |
return MENU; |
|
283 |
} |
|
284 |
|
|
285 |
void (menu_draw)(menu_t *menu) { |
|
286 |
rectangle_draw(menu->frame); |
|
287 |
switch (highlighted) { |
|
288 |
case GAME: |
|
289 |
rectangle_set_fill_color(menu->r0, HIGHLIGHT_COLOR); |
|
290 |
rectangle_draw(menu->r0); |
|
291 |
rectangle_draw(menu->r1); |
|
292 |
rectangle_draw(menu->r2); |
|
293 |
rectangle_set_fill_color(menu->r0, BLACK); |
|
294 |
break; |
|
295 |
case TEST: |
|
296 |
rectangle_set_fill_color(menu->r1, HIGHLIGHT_COLOR); |
|
297 |
rectangle_draw(menu->r0); |
|
298 |
rectangle_draw(menu->r1); |
|
299 |
rectangle_draw(menu->r2); |
|
300 |
rectangle_set_fill_color(menu->r1, BLACK); |
|
301 |
break; |
|
302 |
case EXIT: |
|
303 |
rectangle_set_fill_color(menu->r2, HIGHLIGHT_COLOR); |
|
304 |
rectangle_draw(menu->r0); |
|
305 |
rectangle_draw(menu->r1); |
|
306 |
rectangle_draw(menu->r2); |
|
307 |
rectangle_set_fill_color(menu->r2, BLACK); |
|
308 |
break; |
|
309 |
default: |
|
310 |
rectangle_draw(menu->r0); |
|
311 |
rectangle_draw(menu->r1); |
|
312 |
rectangle_draw(menu->r2); |
|
313 |
break; |
|
314 |
} |
|
315 |
text_draw(menu->t0); |
|
316 |
text_draw(menu->t1); |
|
317 |
text_draw(menu->t2); |
|
318 |
} |
|
319 |
|
|
320 |
void (menu_dtor)(menu_t *p){ |
|
321 |
rectangle_dtor(p->r0); |
|
322 |
rectangle_dtor(p->r1); |
|
323 |
rectangle_dtor(p->r2); |
|
324 |
rectangle_dtor(p->frame); |
|
325 |
text_dtor(p->t0); |
|
326 |
text_dtor(p->t1); |
|
327 |
text_dtor(p->t2); |
|
328 |
free(p); |
|
329 |
} |
|
330 |
|
|
192 | 331 |
text_timer_t* (timer_ctor)(const font_t *fnt){ |
193 | 332 |
if(fnt == NULL) return NULL; |
194 | 333 |
text_timer_t *ret = malloc(sizeof(timer_t)); |
... | ... | |
196 | 335 |
ret->time = 0; |
197 | 336 |
ret->text = text_ctor(fnt, "000s"); |
198 | 337 |
ret->array = text_get_string(ret->text); |
199 |
text_set_color(ret->text, 0x888888);
|
|
338 |
text_set_color(ret->text, TEXT_COLOR);
|
|
200 | 339 |
return ret; |
201 | 340 |
} |
202 | 341 |
|
... | ... | |
208 | 347 |
p->array[0] = (p->time/100) % 10 + '0'; |
209 | 348 |
} |
210 | 349 |
|
350 |
void (timer_reset)(text_timer_t *p){ |
|
351 |
p->time = 0; |
|
352 |
p->array[2] = '0'; |
|
353 |
p->array[1] = '0'; |
|
354 |
p->array[0] = '0'; |
|
355 |
} |
|
356 |
|
|
211 | 357 |
void (timer_dtor)(text_timer_t *p){ |
212 | 358 |
if (p == NULL) return; |
213 | 359 |
text_dtor(p->text); |
Also available in: Unified diff