9 int mouse_x, mouse_y, mouse_state[3];
11 int scr_width, scr_height;
16 struct app_screen *cur_scr;
18 unsigned char *framebuf;
20 /* available screens */
22 static struct app_screen *screens[MAX_SCREENS];
23 static int num_screens;
30 static rtk_draw_ops guigfx = {gui_fill, 0, gui_drawtext, gui_textrect};
34 /* initialize screens */
35 screens[num_screens++] = &menuscr;
37 start_scr_name = getenv("START_SCREEN");
39 for(i=0; i<num_screens; i++) {
40 if(screens[i]->init() == -1) {
45 time_msec = get_msec();
47 for(i=0; i<num_screens; i++) {
48 if(screens[i]->name && start_scr_name && strcmp(screens[i]->name, start_scr_name) == 0) {
49 app_chscr(screens[i]);
60 void app_shutdown(void)
64 for(i=0; i<num_screens; i++) {
65 if(screens[i]->destroy) {
66 screens[i]->destroy();
73 void app_display(void)
75 time_msec = get_msec();
80 void app_reshape(int x, int y)
83 int prev_numpix = scr_width * scr_height;
85 if(!framebuf || numpix > prev_numpix) {
87 if(!(tmp = realloc(framebuf, numpix * sizeof *framebuf))) {
88 errormsg("failed to resize framebuffer to %dx%d\n", x, y);
97 if(cur_scr && cur_scr->reshape) {
98 cur_scr->reshape(x, y);
101 app_invalidate(0, 0, 0, 0);
104 void app_keyboard(int key, int press)
107 static long prev_esc;
114 if(msec - prev_esc < 1000) {
123 if(modkeys & KEY_MOD_CTRL) {
131 if(modkeys & KEY_MOD_ALT) {
140 if(cur_scr && cur_scr->keyboard) {
141 cur_scr->keyboard(key, press);
145 void app_mouse(int bn, int st, int x, int y)
150 mouse_state[bn] = st;
153 if(cur_scr && cur_scr->mouse) {
154 cur_scr->mouse(bn, st, x, y);
158 void app_motion(int x, int y)
160 if(cur_scr && cur_scr->motion) {
161 cur_scr->motion(x, y);
167 void app_chscr(struct app_screen *scr)
169 struct app_screen *prev = cur_scr;
173 if(scr->start && scr->start() == -1) {
177 scr->reshape(scr_width, scr_height);
180 if(prev && prev->stop) {
186 void gui_fill(rtk_rect *rect, int color)
192 rect->width += rect->x;
196 rect->height += rect->y;
199 if(rect->x + rect->width >= scr_width) {
200 rect->width = scr_width - rect->x;
202 if(rect->y + rect->height >= scr_height) {
203 rect->height = scr_height - rect->y;
206 fb = framebuf + rect->y * scr_width + rect->x;
207 for(i=0; i<rect->height; i++) {
208 for(j=0; j<rect->width; j++) {
215 void gui_drawtext(int x, int y, const char *str)
219 void gui_textrect(const char *str, rtk_rect *rect)