zori.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #ifndef zori_H_INCLUDED
  2. #define zori_H_INCLUDED
  3. #include "eruta.h"
  4. #include "rebox.h"
  5. #include "miao.h"
  6. /* Typedefs for possible later portability. */
  7. typedef ALLEGRO_COLOR zori_color ;
  8. typedef ALLEGRO_BITMAP zori_bitmap ;
  9. typedef ALLEGRO_FONT zori_font ;
  10. typedef ALLEGRO_EVENT zori_system_event;
  11. typedef ALLEGRO_EVENT_TYPE zori_event_type;
  12. typedef ALLEGRO_DISPLAY zori_display;
  13. typedef Point zori_point;
  14. typedef Rebox zori_rebox;
  15. typedef int zori_id;
  16. #define ZORI_ID_OK_P(ID) ((ID) > -1)
  17. #define ZORI_ID_OK ((zori_id)(0))
  18. #define ZORI_ID_ERROR ((zori_id)(-1))
  19. #define ZORI_ID_ENOMEM ((zori_id)(-2))
  20. #define ZORI_ID_EINVAL ((zori_id)(-3))
  21. struct zori_widget;
  22. struct zori_event {
  23. zori_system_event sysev;
  24. struct zori_widget * widget;
  25. void * data;
  26. };
  27. struct zori_stylepart {
  28. zori_color color;
  29. zori_bitmap * image;
  30. zori_font * font;
  31. };
  32. struct zori_style {
  33. struct zori_stylepart fore;
  34. struct zori_stylepart back;
  35. struct zori_stylepart text;
  36. };
  37. struct zori_widget;
  38. typedef int zori_handler_func(struct zori_event * event);
  39. struct zori_handler {
  40. zori_event_type type;
  41. zori_handler_func * handler;
  42. void * data;
  43. };
  44. /* System event handlers. */
  45. struct zori_handlers miao_of_type(struct zori_handler);
  46. /*
  47. struct zori_handlers {
  48. size_t size;
  49. struct zori_handler * handlers;
  50. };
  51. */
  52. /* Mouse or keyboard/joystick cursor. */
  53. struct zori_cursor {
  54. zori_point p;
  55. struct zori_widget * hover;
  56. struct zori_widget * focus;
  57. zori_bitmap * bitmap;
  58. };
  59. /* Support multiple cursors... */
  60. struct zori_cursors {
  61. struct zori_cursor mouse;
  62. struct zori_cursor keyjoy;
  63. };
  64. /*
  65. on_enter
  66. on_enter(data = {})
  67. on_event(*args)
  68. on_event(*data)
  69. on_key_down(*args)
  70. on_leave(name=nil)
  71. on_mouse_axes(t, x, y, z, w, dx, dy, dz, dw)
  72. on_mouse_button_down(t, x, y, z, w, b)
  73. on_mouse_button_up(t, x, y, z, w, b)
  74. on_mouse_in(x, y, from)
  75. on_mouse_out(x, y, to)
  76. on_resize
  77. */
  78. struct zori_widget {
  79. /* ID of the widget, used in most external API's. */
  80. zori_id id;
  81. /* Root level widget under which this widget is active. */
  82. struct zori_widget * root;
  83. /* Position and size of the widget. */
  84. zori_rebox box;
  85. /* Z ordering. */
  86. int z;
  87. /* Style. */
  88. struct zori_style style;
  89. /* Handlers. */
  90. struct zori_handlers handlers;
  91. /* Related widgets. */
  92. struct zori_widget * parent;
  93. struct zori_widget * child;
  94. struct zori_widget * sibling;
  95. };
  96. /* An array of widget pointers. */
  97. struct zori_widget_array {
  98. struct zori_widget * array;
  99. size_t size;
  100. };
  101. /* Root level widget. */
  102. struct zori_root {
  103. /* A root is a widget. */
  104. struct zori_widget widget;
  105. /* It also manages the cursors*/
  106. struct zori_cursors cursors;
  107. /* It has an array of all widgets it manages. */
  108. struct zori_widget_array * widgets;
  109. /* It is linked to a particular display. */
  110. zori_display * display;
  111. };
  112. zori_id zori_set_background_color(zori_id id, zori_color color);
  113. zori_id zori_set_foreground_color(zori_id id, zori_color color);
  114. zori_id zori_new_root_widget(const struct zori_style * style);
  115. zori_id zori_new_frame_widget(zori_id parent);
  116. zori_id zori_register(zori_id id, zori_event_type type, zori_handler_func handler, void * extra);
  117. #endif