5 // AK: new passive ui (like the menu stuff)
7 1. two different structs (one for the ui core code and one for the rest)
8 2. each item has a size field
11 #define UI_EVENT_QUEUE_SIZE 32
13 typedef enum ui_control_type_e { UI_BUTTON, UI_LABEL } ui_control_type;
15 typedef struct ui_message_s ui_message_t;
16 typedef struct ui_item_s *ui_item_t;
17 typedef struct ui_itemlist_s *ui_itemlist_t;
18 typedef struct ui_message_queue_s ui_message_queue_t;
26 const char *name; // used for debugging purposes and to identify an object
29 // used to build the item list
30 struct ui_item_s *prev, *next; // items are allowed to be freed everywhere
32 // called for system events (true means message processed)
33 int (*eventhandler)(ui_itemlist_t list, ui_item_t self, ui_message_t *in, ui_message_queue_t *out);
35 // z-order (the higher, the later it is drawn)
38 // called to draw the object
39 void (*draw)(ui_itemlist_t list, struct ui_item_s * self);
51 void (*eventhandler)(struct ui_itemlist_s * list, struct ui_message_s *msg);
57 // this is structure contains *all* possible messages
58 enum ui_message_type_e { UI_EVENT_FRAME, UI_EVENT_KEY, UI_EVENT_MOUSE, UI_BUTTON_PRESSED };
65 // in_mouse_x and in_mouse_y can be also used...
71 union ui_message_data_u
73 unsigned char reserved;
74 struct ui_ev_key_s key;
75 struct ui_ev_mouse_s mouse;
80 // empty for input messages, but contains a valid item for all other events
83 // used to determine which data struct was used
84 enum ui_message_type_e type;
86 union ui_message_data_u data;
89 struct ui_message_queue_s
92 ui_message_t queue[UI_EVENT_QUEUE_SIZE];
97 #define UI_MOUSEEVENT 1
100 void UI_Draw(ui_itemlist_t list);
102 void UI_Mouse(ui_itemlist_t list, float x, float y);
103 void UI_Key(ui_itemlist_t list, int key, int ascii);
106 #define UI_ITEM(item) ((ui_item_t*)item)
108 ui_item_t UI_CloneItem(ui_item_t);
110 ui_item_t UI_FindItemByName(ui_itemlist_t, const char *);
112 void UI_FreeItem(ui_itemlist_t, ui_item_t);
113 void UI_FreeItemByName(ui_itemlist_t, const char *);
116 ui_itemlist_t UI_CreateItemList();
117 ui_itemlist_t UI_CloneItemList(ui_itemlist_t);
118 void UI_FreeItemList(ui_itemlist_t);
120 void UI_AddItem(ui_itemlist_t list, ui_item_t item);
123 #define UI_TEXT_DEFAULT_LENGTH 255
125 typedef struct ui_button_s *ui_button_t;
126 typedef struct ui_label_s *ui_label_t;
127 typedef struct ui_text_s *ui_text_t;
131 struct ui_item_s item;
140 struct ui_item_s item;
145 ui_item_t UI_CreateButton(void);
146 ui_item_t UI_CreateLabel(void);
147 ui_item_t UI_CreateText(void);
149 // AK: new callback system
150 #define UI_MAX_CALLBACK_COUNT 10
152 #define UI_SLOTUSED 1
153 typedef struct ui_callback_s
156 void (*keydown) (int num, char ascii);
160 // functions which should be used
161 void UI_Callback_Init(void);
162 void UI_Callback_Reset(void);
164 void UI_Callback_SetupSlot(int slotnr, void(*keydownf)(int num, char ascii), void(*drawf)(void));
165 void UI_Callback_ResetSlot(int slotnr);
166 int UI_Callback_GetFreeSlot(void);
167 int UI_Callback_IsSlotUsed(int slotnr);
169 void UI_Callback_Draw(void);
170 void UI_Callback_KeyDown(int num, char ascii);