9 int mouse_x, mouse_y, mouse_state[3];
15 struct app_screen *cur_scr;
17 unsigned char *framebuf;
19 /* available screens */
21 static struct app_screen *screens[MAX_SCREENS];
22 static int num_screens;
29 static rtk_draw_ops guigfx = {gui_fill, 0, gui_drawtext, gui_textrect};
31 if(!(framebuf = malloc(SCR_WIDTH * SCR_HEIGHT))) {
32 errormsg("failed to allocate framebuffer (%dx%d)\n", SCR_WIDTH, SCR_HEIGHT);
38 /* initialize screens */
39 screens[num_screens++] = &menuscr;
41 start_scr_name = getenv("START_SCREEN");
43 for(i=0; i<num_screens; i++) {
44 if(screens[i]->init() == -1) {
49 time_msec = get_msec();
51 for(i=0; i<num_screens; i++) {
52 if(screens[i]->name && start_scr_name && strcmp(screens[i]->name, start_scr_name) == 0) {
53 app_chscr(screens[i]);
64 void app_shutdown(void)
68 for(i=0; i<num_screens; i++) {
69 if(screens[i]->destroy) {
70 screens[i]->destroy();
78 void app_display(void)
80 time_msec = get_msec();
85 void app_keyboard(int key, int press)
95 if(msec - prev_esc < 1000) {
104 if(modkeys & KEY_MOD_CTRL) {
112 if(cur_scr && cur_scr->keyboard) {
113 cur_scr->keyboard(key, press);
117 void app_mouse(int bn, int st, int x, int y)
122 mouse_state[bn] = st;
125 if(cur_scr && cur_scr->mouse) {
126 cur_scr->mouse(bn, st, x, y);
130 void app_motion(int x, int y)
132 if(cur_scr && cur_scr->motion) {
133 cur_scr->motion(x, y);
139 void app_chscr(struct app_screen *scr)
141 struct app_screen *prev = cur_scr;
145 if(scr->start && scr->start() == -1) {
149 if(prev && prev->stop) {
155 void gui_fill(rtk_rect *rect, uint32_t color)
161 rect->width += rect->x;
165 rect->height += rect->y;
168 if(rect->x + rect->width >= SCR_WIDTH) {
169 rect->width = SCR_WIDTH - rect->x;
171 if(rect->y + rect->height >= SCR_HEIGHT) {
172 rect->height = SCR_HEIGHT - rect->y;
175 fb = framebuf + rect->y * SCR_WIDTH + rect->x;
176 for(i=0; i<rect->height; i++) {
177 for(j=0; j<rect->width; j++) {
184 void gui_drawtext(int x, int y, const char *str)
188 void gui_textrect(const char *str, rtk_rect *rect)