zori_page.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "zori.h"
  2. #include "zori_widget.h"
  3. #include "zori_caption.h"
  4. #include "zori_page.h"
  5. #include "monolog.h"
  6. /* Magic comment for runcprotoall: @generate_cproto@ */
  7. struct zori_page * zori_widget_to_page(struct zori_widget * widget) {
  8. if (!zori_widget_is_type(widget, ZORI_WIDGET_TYPE_PAGE)) return NULL;
  9. return ZORI_CONTAINER_OF(widget, struct zori_page, widget);
  10. }
  11. struct zori_page * zori_id_to_page(zori_id id) {
  12. struct zori_widget * widget = zori_get_widget(id);
  13. if (!widget) return NULL;
  14. return zori_widget_to_page(widget);
  15. }
  16. int zori_page_on_draw(union zori_event * event) {
  17. struct zori_widget * widget = event->any.widget;
  18. struct zori_page * page = zori_widget_to_page(widget);
  19. struct zori_style * style = &widget->style;
  20. if (style->back.image) {
  21. al_draw_bitmap(style->back.image, 0, 0, 0);
  22. }
  23. if (style->back.flags & ZORI_STYLE_FLAG_FILL) {
  24. al_clear_to_color(style->back.color);
  25. }
  26. return ZORI_HANDLE_IGNORE;
  27. }
  28. struct zori_handler zori_page_handlers[] = {
  29. { ZORI_EVENT_DRAW , zori_page_on_draw , NULL },
  30. { -1, NULL, NULL }
  31. };
  32. struct zori_page * zori_page_new(zori_id id, struct zori_widget * parent) {
  33. struct zori_page * page = NULL;
  34. if (!parent) return NULL;
  35. page = calloc(1, sizeof(*page));
  36. if (!page) return NULL;
  37. zori_widget_initall(&page->widget, ZORI_WIDGET_TYPE_PAGE, id, parent,
  38. NULL, NULL, ZORI_ARRAY_AND_AMOUNT(zori_page_handlers));
  39. return page;
  40. }
  41. zori_id zori_new_page(zori_id id, zori_id parent_id) {
  42. struct zori_widget * parent = zori_get_widget(parent_id);
  43. struct zori_page * page = zori_page_new(id, parent);
  44. if (!page) return ZORI_ID_ENOMEM;
  45. return page->widget.id;
  46. }