]> icculus.org git repositories - divverent/darkplaces.git/blob - ui.h
make sure client ports are opened before trying to connect to anything
[divverent/darkplaces.git] / ui.h
1
2 #ifndef UI_H
3 #define UI_H
4 /*
5 // these defines and structures are for internal use only
6 // (ui_t is passed around by users of the system, but should not be altered)
7 #define MAX_UI_COUNT 16
8 #define MAX_UI_ITEMS 256
9
10 typedef struct
11 {
12         char name[32];
13         int flags;
14         char *draw_picname;
15         char *draw_string;
16         int draw_x, draw_y;
17         int click_x, click_y, click_x2, click_y2;
18         void(*leftkey)(void *nativedata1, void *nativedata2, float data1, float data2);
19         void(*rightkey)(void *nativedata1, void *nativedata2, float data1, float data2);
20         void(*enterkey)(void *nativedata1, void *nativedata2, float data1, float data2);
21         void(*mouseclick)(void *nativedata1, void *nativedata2, float data1, float data2, float xfrac, float yfrac);
22         void *nativedata1, *nativedata2;
23         float data1, data2;
24 }
25 ui_item_t;
26
27 typedef struct
28 {
29         int item_count;
30         int pad;
31         ui_item_t items[MAX_UI_ITEMS];
32 }
33 ui_t;
34
35 // engine use:
36 // initializes the ui system
37 void ui_init(void);
38 // updates the mouse position, given an absolute loation (some input systems use this)
39 void ui_mouseupdate(float x, float y);
40 // updates the mouse position, by an offset from the previous location (some input systems use this)
41 void ui_mouseupdaterelative(float x, float y);
42 // left key update
43 void ui_leftkeyupdate(int pressed);
44 // right key update
45 void ui_rightkeyupdate(int pressed);
46 // up key update
47 void ui_upkeyupdate(int pressed);
48 // down key update
49 void ui_downkeyupdate(int pressed);
50 // mouse button update (note: 0 = left, 1 = right, 2 = middle, 3+ not supported yet)
51 void ui_mousebuttonupdate(int button, int pressed);
52 // perform input updates and check for clicks on items (note: calls callbacks)
53 void ui_update(void);
54 // draw all items of all panels
55 void ui_draw(void);
56
57 // intentionally public functions:
58 // creates a panel
59 ui_t *ui_create(void);
60 // frees a panel
61 void ui_free(ui_t *ui);
62 // empties a panel, removing all the items
63 void ui_clear(ui_t *ui);
64 // sets an item in a panel (adds or replaces the item)
65 void ui_item
66 (
67         ui_t *ui, char *basename, int number,
68         float x, float y, char *picname, char *string,
69         float left, float top, float width, float height,
70         void(*leftkey)(void *nativedata1, void *nativedata2, float data1, float data2),
71         void(*rightkey)(void *nativedata1, void *nativedata2, float data1, float data2),
72         void(*enterkey)(void *nativedata1, void *nativedata2, float data1, float data2),
73         void(*mouseclick)(void *nativedata1, void *nativedata2, float data1, float data2, float xfrac, float yfrac),
74         void *nativedata1, void *nativedata2, float data1, float data2
75 );
76 // removes an item from a panel
77 void ui_item_remove(ui_t *ui, char *basename, int number);
78 // checks if a panel is enabled
79 int ui_uiactive(ui_t *ui);
80 // enables/disables a panel on the screen
81 void ui_activate(ui_t *ui, int yes);*/
82
83 // AK: new passive ui (like the menu stuff)
84 #define UI_TEXT_DEFAULT_LENGTH 255
85 typedef void * ui_item_t;
86 typedef void * ui_itemlist_t;
87
88 void UI_Init(void);
89
90 void UI_Key(ui_itemlist_t, int key, int ascii);
91 void UI_Draw(ui_itemlist_t);
92
93 void UI_SetFocus(ui_itemlist_t, ui_item_t);
94 void UI_SetNeighbors(ui_item_t left, ui_item_t right, ui_item_t up, ui_item_t down);
95
96 // item stuff
97 ui_item_t UI_CreateButton(const char *caption, float x, float y, void(*action)(ui_item_t)); 
98 ui_item_t UI_CreateLabel(const char *caption, float x, float y);
99 ui_item_t UI_CreateText(const char *caption, float x, float y, const char *allowed, int maxlen, int scrolllen);
100 void UI_FreeItem(ui_item_t);
101
102 const char* UI_GetCaption(ui_item_t);
103 void UI_SetCaption(ui_item_t, const char *);
104
105 // itemlist stuff
106 ui_itemlist_t UI_CreateItemList(float x, float y);
107 void UI_FreeItemList(ui_itemlist_t);
108
109 void UI_AddItem(ui_itemlist_t, ui_item_t);
110
111 // AK: new callback system
112 #define UI_MAX_CALLBACK_COUNT 10
113
114 #define UI_SLOTUSED     1
115 typedef struct ui_callback_s
116 {
117         unsigned int flag;
118         void (*keydown) (int num, char ascii);
119         void (*draw)    (void);
120 } ui_callback_t;
121
122 // functions which should be used
123 void UI_Callback_Init(void);
124 void UI_Callback_Reset(void);
125
126 void UI_Callback_SetupSlot(int slotnr, void(*keydownf)(int num, char ascii), void(*drawf)(void));
127 void UI_Callback_ResetSlot(int slotnr);
128 int  UI_Callback_GetFreeSlot(void);
129 int      UI_Callback_IsSlotUsed(int slotnr);
130
131 void UI_Callback_Draw(void);
132 void UI_Callback_KeyDown(int num, char ascii);
133
134 #endif
135