Project

General

Profile

Revision 291

changed menu to file

View differences:

proj_func.c
189 189
    return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p));
190 190
}
191 191

  
192
struct menu {
193
    rectangle_t *r0, *r1, *r2;
194
    text_t      *t0, *t1, *t2;
195
    rectangle_t *frame;
196
};
197

  
198
menu_t* (menu_ctor)(const font_t *fnt){
199
    if(fnt == NULL) return NULL;
200
    menu_t *ret = (menu_t*)malloc(sizeof(menu_t));
201
    if (ret == NULL) return NULL;
202
    ret->r0 = rectangle_ctor(0, 0, 400, 100);
203
    ret->r1 = rectangle_ctor(0, 0, 400, 100);
204
    ret->r2 = rectangle_ctor(0, 0, 400, 100);
205
    ret->t0 = text_ctor(fnt, "PLAY");
206
    ret->t1 = text_ctor(fnt, "TEST");
207
    ret->t2 = text_ctor(fnt, "EXIT");
208
    ret->frame = rectangle_ctor(0, 0, 800, 500);
209
    if (ret->r0 == NULL || ret->r1 == NULL || ret->r2 == NULL ||
210
        ret->t0 == NULL || ret->t1 == NULL || ret->t2 == NULL ||
211
        ret->frame == NULL) return NULL;
212
    // VISUAL
213
    rectangle_set_fill_color(ret->r0, GRAPH_BLACK);
214
    rectangle_set_outline_width(ret->r0, 2);
215
    rectangle_set_outline_color(ret->r0, GRAPH_WHITE);
216
    rectangle_set_fill_trans(ret->r0, GRAPH_TRANSPARENT);
217
    rectangle_set_fill_color(ret->r1, GRAPH_BLACK);
218
    rectangle_set_outline_width(ret->r1, 2);
219
    rectangle_set_outline_color(ret->r1, GRAPH_WHITE);
220
    rectangle_set_fill_trans(ret->r1, GRAPH_TRANSPARENT);
221
    rectangle_set_fill_color(ret->r2, GRAPH_BLACK);
222
    rectangle_set_outline_width(ret->r2, 2);
223
    rectangle_set_outline_color(ret->r2, GRAPH_WHITE);
224
    rectangle_set_fill_trans(ret->r2, GRAPH_TRANSPARENT);
225
    text_set_valign(ret->t0, text_valign_center);
226
    text_set_halign(ret->t0, text_halign_center);
227
    text_set_color(ret->t0, TEXT_COLOR);
228
    text_set_valign(ret->t1, text_valign_center);
229
    text_set_halign(ret->t1, text_halign_center);
230
    text_set_color(ret->t1, TEXT_COLOR);
231
    text_set_valign(ret->t2, text_valign_center);
232
    text_set_halign(ret->t2, text_halign_center);
233
    text_set_color(ret->t2, TEXT_COLOR);
234
    rectangle_set_fill_color(ret->frame, GRAPH_BLACK);
235
    rectangle_set_outline_width(ret->frame, 6);
236
    rectangle_set_outline_color(ret->frame, GRAPH_WHITE);
237
    rectangle_set_fill_trans(ret->frame, GRAPH_TRANSPARENT);
238
    // POSITIONS
239
    rectangle_set_pos(ret->r0,
240
                      graph_get_XRes()/2    - rectangle_get_w(ret->r0)/2,
241
                      graph_get_YRes()*0.35 - rectangle_get_h(ret->r0)/2);
242

  
243

  
244
    rectangle_set_pos(ret->r1,
245
                    graph_get_XRes()/2    - rectangle_get_w(ret->r1)/2,
246
                    graph_get_YRes()*0.5 - rectangle_get_h(ret->r1)/2);
247

  
248

  
249
    rectangle_set_pos(ret->r2,
250
                  graph_get_XRes()/2    - rectangle_get_w(ret->r2)/2,
251
                  graph_get_YRes()*0.65 - rectangle_get_h(ret->r2)/2);
252

  
253
    text_set_pos(ret->t0, rectangle_get_x(ret->r0)+rectangle_get_w(ret->r0)/2,
254
                          rectangle_get_y(ret->r0)+rectangle_get_h(ret->r0)/2);
255

  
256
    text_set_pos(ret->t1, rectangle_get_x(ret->r1)+rectangle_get_w(ret->r1)/2,
257
                          rectangle_get_y(ret->r1)+rectangle_get_h(ret->r1)/2);
258

  
259
    text_set_pos(ret->t2, rectangle_get_x(ret->r2)+rectangle_get_w(ret->r2)/2,
260
                          rectangle_get_y(ret->r2)+rectangle_get_h(ret->r2)/2);
261

  
262
    rectangle_set_pos(ret->frame,
263
                  graph_get_XRes()/2    - rectangle_get_w(ret->frame)/2,
264
                  graph_get_YRes()*0.5 - rectangle_get_h(ret->frame)/2);
265
    return ret;
266
}
267

  
268
static int highlighted = -1;
269

  
270
int (menu_update_state)(menu_t *menu, int click) {
271

  
272
    if (rectangle_collide_point(menu->r0, mouse_x, mouse_y)) {
273
        highlighted = GAME;
274
        if (click) return GAME;
275
    } else if (rectangle_collide_point(menu->r1, mouse_x, mouse_y)) {
276
        highlighted = TEST;
277
        if (click) return TEST;
278
    } else if (rectangle_collide_point(menu->r2, mouse_x, mouse_y)) {
279
        highlighted = EXIT;
280
        if (click) return EXIT;
281
    } else {
282
        highlighted = -1;
283
    }
284
    return MENU;
285
}
286

  
287
void (menu_draw)(menu_t *menu) {
288
    rectangle_draw(menu->frame);
289
    switch (highlighted) {
290
    case GAME:
291
        rectangle_set_fill_color(menu->r0, HIGHLIGHT_COLOR);
292
        rectangle_draw(menu->r0);
293
        rectangle_draw(menu->r1);
294
        rectangle_draw(menu->r2);
295
        rectangle_set_fill_color(menu->r0, GRAPH_BLACK);
296
        break;
297
    case TEST:
298
        rectangle_set_fill_color(menu->r1, HIGHLIGHT_COLOR);
299
        rectangle_draw(menu->r0);
300
        rectangle_draw(menu->r1);
301
        rectangle_draw(menu->r2);
302
        rectangle_set_fill_color(menu->r1, GRAPH_BLACK);
303
        break;
304
    case EXIT:
305
        rectangle_set_fill_color(menu->r2, HIGHLIGHT_COLOR);
306
        rectangle_draw(menu->r0);
307
        rectangle_draw(menu->r1);
308
        rectangle_draw(menu->r2);
309
        rectangle_set_fill_color(menu->r2, GRAPH_BLACK);
310
        break;
311
    default:
312
        rectangle_draw(menu->r0);
313
        rectangle_draw(menu->r1);
314
        rectangle_draw(menu->r2);
315
        break;
316
    }
317
    text_draw(menu->t0);
318
    text_draw(menu->t1);
319
    text_draw(menu->t2);
320
}
321

  
322
void (menu_dtor)(menu_t *p){
323
    rectangle_dtor(p->r0);
324
    rectangle_dtor(p->r1);
325
    rectangle_dtor(p->r2);
326
    rectangle_dtor(p->frame);
327
    text_dtor(p->t0);
328
    text_dtor(p->t1);
329
    text_dtor(p->t2);
330
    free(p);
331
}
332

  
333 192
text_timer_t* (timer_ctor)(const font_t *fnt){
334 193
    if(fnt == NULL) return NULL;
335 194
    text_timer_t *ret = malloc(sizeof(timer_t));

Also available in: Unified diff