fixed imago 565, started on menu
[eradicate] / src / menuscr.c
1 #include <stdio.h>
2 #include "screens.h"
3 #include "imago2.h"
4 #include "gfx.h"
5 #include "gfxutil.h"
6 #include "game.h"
7
8 static const struct menuent {
9         int x, y, len, height;
10 } menuent[] = {
11         {240, 300, 170, 32},
12         {230, 360, 184, 32},
13         {260, 424, 130, 32}
14 };
15
16 static int cur;
17
18 static uint16_t *bgpix;
19 static int bgwidth, bgheight;
20
21 int menu_init(void)
22 {
23         if(!(bgpix = img_load_pixels("data/menbg640.png", &bgwidth, &bgheight, IMG_FMT_RGB565))) {
24                 fprintf(stderr, "failed to load menu bg image\n");
25                 return -1;
26         }
27         return 0;
28 }
29
30 void menu_cleanup(void)
31 {
32         img_free_pixels(bgpix);
33 }
34
35 void menu_start(void)
36 {
37         draw = menu_draw;
38         key_event = menu_keyb;
39 }
40
41 void menu_stop(void)
42 {
43 }
44
45
46
47 void menu_draw(void)
48 {
49         static uint16_t blurbuf[2][16384];
50         int y, offs;
51         int i, j;
52         const struct menuent *ent = menuent + cur;
53
54         y = ent->y - ent->height / 2;
55         offs = y * ent->len + ent->x;
56         blit(blurbuf[0], ent->len, bgpix + offs, ent->len, ent->height, bgwidth);
57
58         //blur_grey_horiz(blurbuf[1], blurbuf[0], ent->len, ent->height, 5, 0x100);
59         for(i=0; i<ent->height; i++) {
60                 for(j=0; j<ent->len; j++) {
61                         blurbuf[1][i * ent->len + j] = 0xff;//~blurbuf[0][i * ent->len + j];
62                 }
63         }
64
65         wait_vsync();
66
67         blit_frame(bgpix, 0);
68         blit(fb_pixels + offs, fb_width, blurbuf[1], ent->len, ent->height, ent->len);
69 }
70
71 void menu_keyb(int key, int pressed)
72 {
73         switch(key) {
74         case 27:
75                 game_quit();
76                 break;
77         }
78 }