zori_page.c 1.4 KB

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