#include "zori.h" #include "zori_page.h" #include "zori_screen.h" struct zori_screen * zori_widget_to_screen(struct zori_widget * widget) { return ZORI_CONTAINER_OF(widget, struct zori_screen, widget); } int zori_screen_on_sysevent(union zori_event * event) { struct zori_screen * screen = zori_widget_to_screen(event->any.widget); /* Move the mouse cursor before passing on the event to the active page, if any. */ if (event->any.type == ALLEGRO_EVENT_MOUSE_AXES) { screen->cursors.mouse.p.x = event->sys.ev->mouse.x; screen->cursors.mouse.p.y = event->sys.ev->mouse.y; } if (screen->active_page) { return zori_widget_raise_sys_event(&screen->active_page->widget, &event->sys); } return ZORI_HANDLE_OK; } void zori_draw_cursor(const struct zori_cursor * cursor, const struct zori_style * style) { if (cursor->bitmap) { al_draw_bitmap(cursor->bitmap, cursor->p.x, cursor->p.y, 0); } else { float x1, x2, x3, y1, y2, y3; x1 = cursor->p.x; y1 = cursor->p.y; x2 = x1 + 5; y2 = y1 + 10; x3 = x1 + 3; y3 = y1 + 12; al_draw_filled_triangle(x1, y1, x2, y2, x3, y3, style->fore.color); } }; void zori_draw_cursors(const struct zori_cursors * cursors, const struct zori_style * style) { zori_draw_cursor(&cursors->keyjoy, style); zori_draw_cursor(&cursors->mouse, style); }; int zori_screen_on_draw(union zori_event * event) { struct zori_screen * screen = zori_widget_to_screen(event->any.widget); zori_draw_cursors(&screen->cursors, &screen->widget.style); return ZORI_HANDLE_OK; } /* struct zori_handler zori_screen_handlers[] = { { ZORI_SYSTEM_EVENT_KEY_DOWN , zori_console_handle_keydown , NULL }, { ZORI_SYSTEM_EVENT_KEY_UP , zori_console_handle_ignore , NULL }, { ZORI_SYSTEM_EVENT_KEY_CHAR , zori_console_handle_keychar , NULL }, { ZORI_EVENT_ _MOUSE_AXES, zori_console_handle_mouseaxes , NULL }, { ZORI_EVENT_DRAW , zori_console_draw , NULL }, { ZORI_EVENT_DONE , zori_console_handle_ignore , NULL }, { ZORI_EVENT_FREE , zori_console_handle_ignore , NULL }, { -1, NULL, NULL } }; */ struct zori_screen * zori_screen_init(struct zori_screen * screen, zori_display * display) { memset(&screen->cursors, 0, sizeof(screen->cursors)); screen->display = display; screen->active_page = NULL; return screen; } struct zori_screen * zori_screen_new(zori_id id, zori_display * display) { struct zori_screen * screen = NULL; zori_rebox box; box.at.x = 0; box.at.y = 0; if (!display) return NULL; screen = calloc(1, sizeof(*screen)); if (!screen) return NULL; box.size.x = al_get_display_width(display); box.size.y = al_get_display_height(display); zori_widget_initall(&screen->widget, id, &zori_get_root()->widget, &box, NULL, 0, NULL); if (!zori_screen_init(screen, display)) { free(screen); screen = NULL; } return screen; } zori_id zori_new_screen(zori_id id, zori_display * display) { struct zori_screen * screen = zori_screen_new(id, display); if (!screen) return ZORI_ID_ENOMEM; return screen->widget.id; } zori_id zori_active_page(zori_id screen_id) { struct zori_screen * screen = zori_widget_to_page(zori_get_widget(screen_id)); if (!screen) { return ZORI_ID_EINVAL; } if (!screen->active_page) { return ZORI_ID_EINVAL; } return screen->active_page->widget.id; } zori_id zori_screen_go(zori_id screen_id, zori_id page_id, void * data) { struct zori_screen * screen = zori_widget_to_screen(zori_get_widget(screen_id)); struct zori_page * page = zori_widget_to_page(zori_get_widget(page_id)); if ((screen) && (page)) { screen->active_page = page; zori_widget_raise_action_event(&page->widget); return page->widget.id; } else { return ZORI_ID_EINVAL; } }