1 /*!
2  * \file
3  * \ingroup widgets
4  * \brief Functions for the widgets used by EL
5  */
6 #ifndef	__WIDGETS_H
7 #define	__WIDGETS_H
8 
9 typedef struct select_info select_info;
10 
11 #include <SDL_types.h>
12 #include <SDL_keycode.h>
13 #include "font.h"
14 #include "text.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 typedef struct {
21 	unsigned char label[64];
22 	int content_id;
23 	Uint16 tag_width;
24 	Uint16 min_tag_width;
25 	float label_r, label_g, label_b;
26 	char closable;
27 } tab;
28 
29 typedef struct {
30 	int tag_height, button_size, tabs_right_margin;
31 	int nr_tabs, max_tabs, cur_tab, tab_offset, tab_last_visible;
32 	tab *tabs;
33 } tab_collection;
34 
35 // Forward declaration
36 struct wl;
37 
38 // The purpose of this implementation if to remove the need to edit
39 // the implementation of the widgets to add a new client widget. It
40 // also allows clients to be dynamically created and populated.
41 struct WIDGET_TYPE {
42     // Function Pointers
43 	int (*init)();
44 	int (*draw)();
45 	int (*click)();
46 	int (*drag)();
47 	int (*mouseover)();
48 	int (*resize)();
49 	int (*key)();
50 	int (*destroy)();
51 	int (*move)();
52 	int (*font_change)();
53 	int (*paste)();
54 	int (*color_change)(struct wl*, float, float, float);
55     // We can conceivably store other generic info here too
56 } ;
57 
58 typedef struct {
59 	int pos, pos_inc, bar_len;
60 }vscrollbar;
61 
62 /*!
63  * The widget list structure - each window has a widget list.
64  */
65 typedef struct wl{
66     /*!
67 	 * \name Common widget data
68      */
69     /*! @{ */
70 	Uint16 pos_x, pos_y, len_x, len_y; /*!< Widget area */
71 	Uint32 id;                         /*!< Widget unique id */
72 	int window_id; /*!< The id of the parent window */
73 	const struct WIDGET_TYPE *type;  /*!< Specifies what properties the widget inherits from it's type */
74 	void *spec;		/*!< The specific implementation info for this widget which is passed to type-nonspecific handlers*/
75 	Uint32 Flags;  /*!< Status flags... visible, enabled, etc */
76 	float size;    /*!< Size of text, image, etc */
77 	float r, g, b; /*!< Associated color */
78 	font_cat fcat; /*!< Font category for drawing text contents in */
79     /*! @} */
80 
81 	/*! \name The specific widget handlers */
82 	/*! \{ */
83 	int (*OnDraw)();
84 	int (*OnClick)();
85 	int (*OnDrag)();
86 	int (*OnInit)();
87 	int (*OnMouseover)();
88 	int (*OnResize)();
89 	int (*OnKey)();
90 	int (*OnDestroy)();
91 	int (*OnFontChange)();
92 	/*! \} */
93 
94 	void *widget_info; /*!< Pointer to specific widget data */
95 	struct wl *next;   /*!< Pointer to the next widget in the window */
96 }widget_list;
97 
98 /*!
99  * \name	Generic flags for widgets
100  */
101 /*! \{ */
102 #define WIDGET_INVISIBLE	0x40
103 #define WIDGET_DISABLED		0x80
104 #define WIDGET_CLICK_TRANSPARENT 0x100
105 /*! \} */
106 
107 /*!
108  * \name	Flags for the buttons
109  */
110 /*! \{ */
111 #define BUTTON_ACTIVE          0x0400
112 #define BUTTON_SQUARE          0x0800
113 #define BUTTON_VCENTER_CONTENT 0x1000
114 /*! \} */
115 
116 /*!
117  * \name	Flags for the text field
118  */
119 /*! \{ */
120 #define TEXT_FIELD_BORDER          0x01
121 #define TEXT_FIELD_EDITABLE        0x02
122 #define TEXT_FIELD_NO_KEYPRESS     0x04
123 #define TEXT_FIELD_CAN_GROW        0x08
124 #define TEXT_FIELD_SCROLLBAR       0x10
125 #define TEXT_FIELD_IGNORE_RETURN   0x20
126 #define TEXT_FIELD_MOUSE_EDITABLE 0x200
127 /*! \} */
128 
129 /*!
130  * \name Flags for the password field
131  */
132 /*! \{ */
133 #define PWORD_FIELD_NO_KEYPRESS TEXT_FIELD_NO_KEYPRESS
134 #define PWORD_FIELD_NO_BORDER   0x2000
135 #define PWORD_FIELD_DRAW_CURSOR 0x4000
136 #define PWORD_FIELD_NO_CURSOR   0x8000
137 /*! \} */
138 
139 #define TF_BLINK_DELAY 500
140 
141 /*!
142  * Contains auxilary information for selection.
143  */
144 typedef struct
145 {
146 	int msg, chr;
147 } text_field_line;
148 
149 /*!
150  * Contains selection information for text_field.
151  */
152 struct select_info
153 {
154 	text_field_line* lines;
155 	int sm, sc, em, ec;
156 };
157 
158 /*!
159  * Checks if selection is empty.
160  */
161 #define TEXT_FIELD_SELECTION_EMPTY(select) (((select)->em == -1) && ((select)->ec == -1))
162 
163 /*!
164  * Makes given selection empty.
165  */
166 #define TEXT_FIELD_CLEAR_SELECTION(select) {(select)->em = (select)->ec = -1;}
167 
168 /*!
169  * Text field structure
170  */
171 typedef struct
172 {
173 	int msg, offset;
174 	int cursor, cursor_line;
175 	int buf_size, buf_fill;
176 	int nr_lines, nr_visible_lines;
177 	int update_bar;
178 	int scroll_id;
179 	int scrollbar_width;
180 	int line_offset;
181 	text_message *buffer;
182 	Uint8 chan_nr;
183 	Uint16 x_space, y_space;
184 	Uint32 next_blink;
185 	select_info select;
186 } text_field;
187 
188 typedef struct {
189 	void *data;
190 	char input_buffer[255];
191 	float max;
192 	float min;
193 	Uint8 type;
194 	float interval;
195 }spinbutton;
196 
197 /* SPLIT INTO ELWIDGETS.C and ELWIDGETS.H */
198 
199 // Common widget functions
200 
201 /*!
202  * \ingroup	widgets
203  * \brief 	Creates a widget and adds it to the given window
204  *
205  * 		Creates a widget and adds it to the given window.
206  *
207  * \param  	window_id The location of the window in the windows_list.window[] array
208  * \param	wid The widget's unique ID
209  * \param   OnInit The function used for initiating the label
210  * \param   x The x location
211  * \param   y The y location
212  * \param   lx The width
213  * \param   ly The height
214  * \param   Flags The flags
215  * \param   size The text size
216  * \param   type The widget type
217  * \param   T Pointer to specific widget data
218  * \param   S Pointer to specific implementation info
219  * \retval int Returns the new widgets unique ID
220  */
221 Uint32 widget_add (int window_id, Uint32 wid, int (*OnInit)(), Uint16 x, Uint16 y,
222 	Uint16 lx, Uint16 ly, Uint32 Flags, float size, const struct WIDGET_TYPE *type, void *T, void *S);
223 
224 /*!
225  * \ingroup	widgets
226  * \brief 	Find a widget with the given widget_id
227  *
228  * 		Returns the widget with the given widget_id in window_id.
229  *
230  * \param   	window_id The location of the window in the windows_list.window[] array
231  * \param   	widget_id The widget's unique ID
232  * \retval widget_list*  	A widget_list pointer to the widget if found, otherwise NULL
233  */
234 widget_list * widget_find(int window_id, Uint32 widget_id);
235 
236 /*!
237  * \ingroup	widgets
238  * \brief 	Destroy a widget with a given ID
239  *
240  * 		Destroys a widget with ID \a widget_id, and removes it from the window's widget list.
241  *
242  * \param   	window_id The location of the window in the windows_list.window[] array
243  * \param   	widget_id The widget's unique ID
244  * \retval	int 1 on success, 0 on failure
245  */
246 int widget_destroy (int window_id, Uint32 widget_id);
247 
248 /*!
249  * \ingroup	widgets
250  * \brief 	Sets the widget's draw callback
251  *
252  * 		Finds the widget in the window and sets the widget's draw callback in the specified window.
253  *
254  * \param   	window_id The location of the window in the windows_list.window[] array
255  * \param   	widget_id The widget's unique ID
256  * \param   	handler A function pointer to the handler
257  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
258  *
259  * \sa widget_find
260  */
261 int widget_set_OnDraw(int window_id, Uint32 widget_id, int (*handler)());
262 
263 /*!
264  * \ingroup	widgets
265  * \brief 	Sets the widget's on-click handler
266  *
267  *      	Finds the widget in the window and sets the widget's on-click handler
268  *
269  * \param   	window_id The location of the window in the windows_list.window[] array
270  * \param   	widget_id The widget's unique ID
271  * \param   	handler A function pointer to the handler
272  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
273  *
274  * \sa widget_find
275  */
276 int widget_set_OnClick(int window_id, Uint32 widget_id, int (*handler)());
277 
278 /*!
279  * \ingroup	widgets
280  * \brief 	Sets the widget's on-drag handler
281  *
282  * 		Finds the widget in the window and sets the widget's on-drag handler
283  *
284  * \param   	window_id The location of the window in the windows_list.window[] array
285  * \param   	widget_id The widget's unique ID
286  * \param   	handler A function pointer to the handler
287  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
288  *
289  * \sa widget_find
290  */
291 int widget_set_OnDrag(int window_id, Uint32 widget_id, int (*handler)());
292 
293 /*!
294  * \ingroup	widgets
295  * \brief 	Sets the widget's on-mouse-over handler
296  *
297  * 		Finds the widget in the window and sets the widget's on-mouse-over handler.
298  *
299  * \param   	window_id The location of the window in the windows_list.window[] array
300  * \param   	widget_id The widget's unique ID
301  * \param   	handler A function pointer to the handler.
302  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
303  *
304  * \sa widget_find
305  */
306 int widget_set_OnMouseover(int window_id, Uint32 widget_id, int (*handler)());
307 
308 /*!
309  * \ingroup	widgets
310  * \brief 	Sets the widget's on-keypress handler
311  *
312  * 		Finds the widget in the window and sets the widget's on-keypress handler.
313  *
314  * \param   	window_id The location of the window in the windows_list.window[] array
315  * \param   	widget_id The widget's unique ID
316  * \param   	handler A function pointer to the handler.
317  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
318  *
319  * \sa widget_find
320  */
321 int widget_set_OnKey ( int window_id, Uint32 widget_id, int (*handler)() );
322 
323 /*!
324  * \ingroup	widgets
325  * \brief 	Sets the widget's specific argument (passed to specific handlers)
326  *
327  * 		Finds the widget in the window and sets the widget's specific argument.
328  *
329  * \param   	window_id The location of the window in the windows_list.window[] array
330  * \param   	widget_id The widget's unique ID
331  * \param   	spec A pointer to the memory of the argument.
332  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
333  *
334  * \sa widget_find
335  */
336 int widget_set_args (int window_id, Uint32 widget_id, void *spec);
337 
338 /*!
339  * \ingroup 	widgets
340  * \brief 	Moves the widget
341  *
342  *      	Finds the widget in the window and moves the widget to the new x,y in the given window.
343  *
344  * \param   	window_id The location of the window in the windows_list.window[] array
345  * \param   	widget_id The widget's unique ID
346  * \param   	x The new x location
347  * \param   	y The new y location
348  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
349  *
350  * \sa widget_find
351  */
352 int widget_move(int window_id, Uint32 widget_id, Uint16 x, Uint16 y);
353 
354 /*!
355  * \ingroup 	widgets
356  * \brief 	Moves the widget to a new window
357  *
358  *      	Finds the widget in the window and moves it to the window new_win_id
359  *
360  * \param   	window_id The location of the window in the windows_list.window[] array
361  * \param   	widget_id The widget's unique ID
362  * \param   	new_win_id The location of the target window in the windows_list.window[] array
363  * \retval Uint32 	 Returns the new widget id on success or 0 on failure (the new id will never be 0)
364  *
365  * \sa widget_find
366  */
367 Uint32 widget_move_win(int window_id, Uint32 widget_id, int new_win_id);
368 
369 /*!
370  * \ingroup 	widgets
371  * \brief 	Moves the widget relative to it's current position
372  *
373  *      	Finds the widget in the window and moves the widget relative to it's current position.
374  *
375  * \param   	window_id The location of the window in the windows_list.window[] array
376  * \param   	widget_id The widget's unique ID
377  * \param   	dx The shift in the x-direction
378  * \param   	dy The shift in the y-direction
379  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
380  *
381  * \sa widget_find
382  */
383 int widget_move_rel (int window_id, Uint32 widget_id, Sint16 dx, Sint16 dy);
384 
385 /*!
386  * \ingroup	widgets
387  * \brief 	Resizes the widget
388  *
389  * 		Finds the widget in the window and resizes the widget to the given x_len and y_len.
390  *
391  * \param   	window_id The location of the window in the windows_list.window[] array
392  * \param   	widget_id The widget's unique ID
393  * \param   	x The new width
394  * \param   	y The new height
395  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
396  *
397  * \sa widget_find
398  */
399 int widget_resize(int window_id, Uint32 widget_id, Uint16 x, Uint16 y);
400 
401 /*!
402  * \ingroup	widgets
403  * \brief 	Sets the widget's flags to f
404  *
405  * 		Finds the widget in the window and sets the widgets flags.
406  *
407  * \param   	window_id The location of the window in the windows_list.window[] array
408  * \param   	widget_id The widget's unique ID
409  * \param   	f The flags
410  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
411  *
412  * \sa widget_find
413  */
414 int widget_set_flags(int window_id, Uint32 widget_id, Uint32 f);
415 
416 /*!
417  * \ingroup	widgets
418  * \brief 	Unsets the specified flags
419  *
420  * 		Finds the widget in the window and unsets the specified flags.
421  *
422  * \param   	window_id The location of the window in the windows_list.window[] array
423  * \param   	widget_id The widget's unique ID
424  * \param   	f The flags
425  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
426  *
427  * \sa widget_find
428  */
429 int widget_unset_flags (int window_id, Uint32 widget_id, Uint32 f);
430 
431 /*!
432  * \ingroup	widgets
433  * \brief 	Set the widget's text size
434  *
435  * 		The function finds the widget in the window and sets it's text size.
436  *
437  * \param   	window_id The location of the window in the windows_list.window[] array
438  * \param   	widget_id The widget's unique ID
439  * \param   	size The new text size
440  * \retval int  	Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
441  *
442  * \sa widget_find
443  */
444 int widget_set_size(int window_id, Uint32 widget_id, float size);
445 
446 /*!
447  * \ingroup	widgets
448  * \brief 	Sets the widget colour
449  *
450  * 		Finds the widget in the given window and sets the r g b foreground colour.
451  *
452  * \param   	window_id The location of the window in the windows_list.window[] array
453  * \param   	widget_id The widget's unique ID
454  * \param   	r (0<=r<=1)
455  * \param   	g (0<=g<=1)
456  * \param   	b (0<=b<=1)
457  * \retval int  Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
458  *
459  * \sa widget_find
460  */
461 int widget_set_color(int window_id, Uint32 widget_id, float r, float g, float b);
462 /*!
463  * \ingroup	widgets
464  * \brief 	Unsets the widget colour
465  *
466  * Finds the widget in the given window and removes the color. The widget will be drawn in
467  * the last color used.
468  *
469  * \param   	window_id The location of the window in the windows_list.window[] array
470  * \param   	widget_id The widget's unique ID
471  * \retval int  Returns 1 on succes or 0 on failure (when the widget was not found in the given window)
472  *
473  * \sa widget_find
474  */
widget_unset_color(int window_id,Uint32 widget_id)475 static __inline__ int widget_unset_color(int window_id, Uint32 widget_id)
476 {
477 	return widget_set_color(window_id, widget_id, -1.0f, -1.0f, -1.0f);
478 }
479 
480 /*!
481  * \ingroup widgets
482  * \brief Set the font category
483  *
484  * Set the font category for the textual elements in this widget to \a fcat
485  *
486  * \param window_id The location of the window in the windows_list.window[] array
487  * \param widget_id The widget's unique ID
488  * \param fcat      The new font category for this widget
489  * \return 1 on succes or 0 on failure
490  */
491 int widget_set_font_cat(int window_id, int widget_id, font_cat fcat);
492 
493 /*!
494  * \ingroup	widgets
495  * \brief 	Return the widget width
496  *
497  * 		Finds the widget in the given window and returns its width
498  *
499  * \param   	window_id The location of the window in the windows_list.window[] array
500  * \param   	widget_id The widget's unique ID
501  * \retval int  	Returns the width on succes or -1 on failure (when the widget was not found in the given window)
502  *
503  * \sa widget_find
504  */
505 int widget_get_width (int window_id, Uint32 widget_id);
506 
507 /*!
508  * \ingroup	widgets
509  * \brief 	Return the widget height
510  *
511  * 		Finds the widget in the given window and returns its height
512  *
513  * \param   	window_id The location of the window in the windows_list.window[] array
514  * \param   	widget_id The widget's unique ID
515  * \retval int  	Returns the width on succes or -1 on failure (when the widget was not found in the given window)
516  *
517  * \sa widget_find
518  */
519 int widget_get_height (int window_id, Uint32 widget_id);
520 
521 // Label
522 
523 /*!
524  * \ingroup	labels
525  * \brief 	Creates an extended label widget
526  *
527  * 		Creates an extended label widget and adds it to the given window.
528  *
529  * \param  	window_id The location of the window in the windows_list.window[] array
530  * \param	wid The widget's unique ID
531  * \param   	OnInit The function used for initiating the label
532  * \param   	x The x location
533  * \param   	y The y location
534  * \param   	Flags The flags
535  * \param   	size The text size
536  * \param   	r (0<=r<=1)
537  * \param   	g (0<=g<=1)
538  * \param   	b (0<=b<=1)
539  * \param   	text The text
540  * \retval int  	Returns the new widgets unique ID
541  *
542  * \sa lable_add
543  */
544 int label_add_extended(int window_id, Uint32 wid, int (*OnInit)(), Uint16 x, Uint16 y, Uint32 Flags, float size, const char *text);
545 
546 /*!
547  * \ingroup	labels
548  * \brief 	Creates a label and adds it to the given window.
549  *
550  * 		Creates a label and adds it to the given window - calls label_add_extended.
551  *
552  * \param   	window_id The location of the window in the windows_list.window[] array
553  * \param   	OnInit The function called on init
554  * \param   	text The text
555  * \param   	x The x position
556  * \param   	y The y position
557  * \retval int  	Returns the new widgets unique ID
558  *
559  * \sa		label_add_extended
560  */
561 int label_add(int window_id, int (*OnInit)(), const char *text, Uint16 x, Uint16 y);
562 
563 /*!
564  * \ingroup	labels
565  * \brief	Draws a label
566  *
567  * 		Draws the label given by the widget.
568  *
569  * \param   	W The widget that is to be drawn
570  * \retval int  	Returns true
571  * \callgraph
572  */
573 int label_draw(widget_list *W);
574 
575 /*!
576  * \ingroup	labels
577  * \brief 	Sets the text of the given widget
578  *
579  * 		Finds the widget in the given window and sets the text.
580  *
581  * \param   	window_id The location of the window in the windows_list.window[] array
582  * \param   	widget_id The widget's unique ID
583  * \param   	text The new text
584  * \retval int  	Returns 1 on succes, 0 on failure (if the widget is not found in the given window)
585  *
586  * \sa widget_find
587  */
588 int label_set_text(int window_id, Uint32 widget_id, const char *text);
589 
590 
591 
592 // Image
593 
594 /*!
595  * \ingroup	images
596  * \brief 	Create an extended image widget
597  *
598  * 		Creates an extended image widget and adds it to the window_id.
599  *
600  * \param   	window_id The location of the window in the windows_list.window[] array
601  * \param   	wid The widget's unique ID
602  * \param   	OnInit Sets the function to run on init
603  * \param   	x The x position
604  * \param   	y The y position
605  * \param   	lx The width
606  * \param   	ly The height
607  * \param   	Flags The flags
608  * \param   	size The text size
609  * \param   	id The offset in the texture_cache
610  * \param   	u1 The start u texture coordinate
611  * \param   	v1 The start v texture coordinate
612  * \param   	u2 The end u texture coordinate
613  * \param   	v2 The end v texture coordinate
614  * \param   	alpha The alpha value for the image
615  * \retval int  	Returns the new widgets unique ID
616  *
617  * \sa image_add
618  */
619 int image_add_extended(int window_id, Uint32 wid,  int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, Uint32 Flags, float size, int id, float u1, float v1, float u2, float v2, float alpha);
620 
621 /*!
622  * \ingroup	images
623  * \brief 	Creates an image widget
624  *
625  *      	Creates an image widget. Calls image_add_extended.
626  *
627  * \param   	window_id The location of the window in the windows_list.window[] array
628  * \param   	OnInit Sets the init handler
629  * \param   	id The texture id in the texture_cache
630  * \param   	x The x position
631  * \param   	y The y position
632  * \param   	lx The width
633  * \param   	ly The height
634  * \param   	u1 The start u texture coordinate
635  * \param   	v1 The start v texture coordinate
636  * \param   	u2 The end u texture coordinate
637  * \param   	v2 The end v texture coordinate
638  * \retval int  	Returns the new widgets unique ID
639  *
640  * \sa image_add_extended
641  */
642 int image_add(int window_id, int (*OnInit)(), int id, Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, float u1, float v1, float u2, float v2);
643 
644 /*!
645  * \ingroup	images
646  * \brief 	Draws the image widget
647  *
648  * 		Draws an image widget as given by the widget *.
649  *
650  * \param   	W A pointer to the widget that should be drawn
651  * \retval int  	Returns true
652  * \callgraph
653  */
654 int image_draw(widget_list *W);
655 
656 /*!
657  * \ingroup	images
658  * \brief 	Sets the texture ID
659  *
660  * 		The function sets the texture ID (or rather, the location in the texture_cache) of the given widget.
661  *
662  * \param   	window_id The location of the window in the windows_list.window[] array
663  * \param   	widget_id The widgets unique ID
664  * \param   	id The location in the texture_cache array
665  * \retval int  	Returns 1 on succes, 0 on failure (if the widget is not found in the given window)
666  *
667  * \sa widget_find
668  */
669 int image_set_id(int window_id, Uint32 widget_id, int id);
670 
671 /*!
672  * \ingroup 	images
673  * \brief 	Sets the UV coordinates of the image widget
674  *
675  * 		Sets the UV coordinates of the image widget
676  *
677  * \param   	window_id The location of the window in the windows_list.window[] array
678  * \param   	widget_id The unique widget ID
679  * \param   	u1 The start u texture coordinate
680  * \param   	v1 The start v texture coordinate
681  * \param   	u2 The end u texture coordinate
682  * \param   	v2 The end v texture coordinate
683  * \retval int  	Returns 1 on succes, 0 on failure (if the widget is not found in the given window)
684  *
685  * \sa widget_find
686  */
687 int image_set_uv(int window_id, Uint32 widget_id, float u1, float v1, float u2, float v2);
688 
689 
690 
691 // Checkbox
692 
693 /*!
694  * \ingroup	checkboxes
695  * \brief 	Create an extended checkbox label
696  *
697  * 		Creates an extended checkbox label and adds it to the given image.
698  *
699  * \param   	window_id The location of the window in the windows_list.window[] array
700  * \param   	wid The unique widget ID
701  * \param   	OnInit The function used for initiating the widget
702  * \param   	x The x location
703  * \param   	y The y locatoin
704  * \param   	lx The width
705  * \param   	ly The height
706  * \param   	Flags The flags
707  * \param   	size The text size
708  * \param   	checked Specifies if the widget is checked or not
709  * \retval int  	Returns the new widgets unique ID
710  *
711  * \sa checkbox_add
712  */
713 int checkbox_add_extended(int window_id, Uint32 wid,  int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, Uint32 Flags, float size, int *checked);
714 
715 /*!
716  * \ingroup	checkboxes
717  * \brief 	Creates a checkbox
718  *
719  * 		Creates a checkbox and adds it to the given window.
720  *
721  * \param   	window_id The location of the window in the windows_list.window[] array
722  * \param   	OnInit The function used for initiating the widget
723  * \param   	x The x position
724  * \param   	y The y position
725  * \param   	lx The width
726  * \param   	ly The height
727  * \param   	checked Specifies whether the checkbox is checked or not
728  * \retval int  	Returns the new widgets unique ID
729  *
730  * \sa checkbox_add_extended
731  */
732 int checkbox_add(int window_id, int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, int *checked);
733 
734 /*!
735  * \ingroup	checkboxes
736  * \brief 	Draws a checkbox
737  *
738  * 		Draws the checkbox pointed to by *W.
739  *
740  * \param   	W The widget you wish to draw
741  * \retval int  	Returns true
742  * \callgraph
743  */
744 int checkbox_draw(widget_list *W);
745 
746 /*!
747  * \ingroup	checkboxes
748  * \brief 	Checks if the given checkbox is checked
749  *
750  * 		Is used for checking if the given checkbox widget is checked or not.
751  *
752  * \param   	window_id The location of the window in the windows_list.window[] array
753  * \param   	widget_id The unique widget ID
754  * \retval int  	Returns 0 if the checkbox is unchecked, 1 if the checkbox is checked and -1 if the checkbox is not even found.
755  *
756  * \sa widget_find
757  */
758 int checkbox_get_checked(int window_id, Uint32 widget_id);
759 
760 /*!
761  * \ingroup	checkboxes
762  * \brief 	Is used for setting the checkbox as checked or not
763  *
764  * 		Finds the given checkbox in the window and sets it as checked or not
765  *
766  * \param   	window_id The location of the window in the windows_list.window[] array
767  * \param   	widget_id The unique widget ID
768  * \param   	checked Whether it should be checked or not
769  * \retval int  	Returns 1 on succes, 0 on failure (if the widget is not found in the given window)
770  *
771  * \sa widget_find
772  */
773 int checkbox_set_checked(int window_id, Uint32 widget_id, int checked);
774 
775 
776 //Button
777 
778 /* Config option: disables double click protection. */
779 extern int disable_double_click;
780 
781 /*!
782  * \ingroup	buttons
783  * \brief 	Check for safety protected button press.
784  *
785  * 		Some buttons are protected from mis-click by requiring you to
786  * 		double-click them.  This protection can be disabled by setting
787  *		the disable_double_click config option to true.  This function
788  *		tests that option and impliments the double click test if needed.
789  *
790  * \param last_click	The SDL_GetTicks() value from the last click
791  * \retval int			Returns 1 if the button press should be actioned, else 0.
792  */
793 int safe_button_click(Uint32 *last_click);
794 
795 /*!
796  * \ingroup	buttons
797  * \brief 	Creates an extended button widget
798  *
799  * 		Creates an extended button widget and adds it to the given window.
800  *
801  * \param   	window_id The location of the window in the windows_list.window[] array
802  * \param   	wid The unique widget ID
803  * \param   	OnInit The function called on initiating the widget
804  * \param   	x The x position
805  * \param   	y The y position
806  * \param   	lx The width
807  * \param   	ly The height
808  * \param   	Flags The flags
809  * \param   	size The text size
810  * \param   	text The button label
811  * \retval int  	Returns the new widgets unique ID
812  *
813  * \sa button_add
814  */
815 int button_add_extended(int window_id, Uint32 wid,  int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, Uint32 Flags, float size, const char *text);
816 
817 /*!
818  * \ingroup	buttons
819  * \brief 	Creates a button widget
820  *
821  * 		Creates a button widget and adds it to the given window.
822  *
823  * \param   	window_id The location of the window in the windows_list.window[] array
824  * \param   	OnInit The function called on initiating the widget
825  * \param   	text The button label
826  * \param   	x The x position
827  * \param   	y The y position
828  * \retval int  	Returns the new widgets unique ID
829  *
830  * \sa button_add_extended
831  */
832 int button_add(int window_id, int (*OnInit)(), const char *text, Uint16 x, Uint16 y);
833 
834 /*!
835  * \ingroup buttons
836  * \brief Resize a button widget
837  *
838  * Resize a button widget using to the specified dimensions. If \a lx or \a ly
839  * are zero, the corresponding dimension is calculated from the button's contents.
840  *
841  * \param window_id The location of the window in the windows_list.window[] array
842  * \param wid       The unique widget ID for the button
843  * \param lx        The new width
844  * \param ly        The new height
845  * \param size      the new font and button size
846  * \retval int Returns the new widgets unique ID
847  *
848  * \sa button_add_extended
849  */
850 int button_resize(int window_id, Uint32 wid, Uint16 lx, Uint16 ly, float size);
851 
852 /*!
853  * \ingroup	buttons
854  * \brief 	Sets the button text
855  *
856  * 		Finds the given button widget and sets the button text
857  *
858  * \param   window_id The location of the window in the windows_list.window[] array
859  * \param   widget_id The unique widget ID
860  * \param   text The button label
861  * \retval int  Returns 1 on succes, 0 on failure (if the widget is not found in the given window)
862  *
863  * \sa widget_find
864  */
865 int button_set_text(int window_id, Uint32 widget_id, const char *text);
866 
867 /*!
868  * \ingroup buttons
869  * \brief Draws a button with round corners.
870  *
871  * 	Draws a button with round corners. The box can be highlighted with the chosen highlight colors (r,g,b,a).
872  *
873  * \param str The name to write within the button, optional
874  * \param cat The category for the font with which to draw \a str
875  * \param size The size of the text
876  * \param x The start x position
877  * \param y The start y position
878  * \param w The width
879  * \param lines The number of lines (determines the height)
880  * \param r The red color for border and text
881  * \param g The green color for border and text
882  * \param b The blue color for border and text
883  * \param highlight If the button is highlighted or not
884  * \param hr The red color for highlighted buttons
885  * \param hg The green color for highlighted buttons
886  * \param hb The blue color for highlighted buttons
887  * \param ha The alpha color for highlighted buttons
888  */
889 void draw_smooth_button(const unsigned char* str, font_cat cat, float size,
890 	int x, int y, int w, int lines, float r, float g, float b,
891 	int highlight, float hr, float hg, float hb, float ha);
892 /*!
893  * \ingroup buttons
894  * \brief Compute the width of a button
895  *
896  * Calculate the normal width of a button of size \a size, with label \a label drawn in the font
897  * for category \a cat.
898  *
899  * \param label The text to draw on the button
900  * \param cat   The font category for the button
901  * \param size  The size scale factor for the button
902  * \return The width of the button, in pixels
903  */
904 int calc_button_width(const unsigned char* label, font_cat cat, float size);
905 
906 // Progressbar
907 
908 /*!
909  * \ingroup	progressbars
910  * \brief 	Adds an extended progressbar widget
911  *
912  * 		Adds an extended progressbar widget to the given window.
913  *
914  * \param   	window_id The location of the window in the windows_list.window[] array
915  * \param   	wid The unique widget ID
916  * \param   	OnInit The function called on initiating the widget
917  * \param   	x The x position
918  * \param   	y The y position
919  * \param   	lx The width
920  * \param   	ly The height
921  * \param   	Flags The flags
922  * \param   	size The text size
923  * \param   	progress The current progress
924  * \param     colors The colors of the four corners of the bar. Pointer to an array of 12 floats (4 consecutive RGB colors). May be NULL.
925  * \retval int  	Returns the new widgets unique ID
926  *
927  * \sa progressbar_add
928  */
929 int progressbar_add_extended(int window_id, Uint32 wid, int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, Uint32 Flags, float size, float progress, const float * colors);
930 
931 /*!
932  * \ingroup	progressbars
933  * \brief 	Adds a progressbar widget
934  *
935  * 		Adds a progressbar widget to the given window.
936  *
937  * \param   	window_id The location of the window in the windows_list.window[] array
938  * \param   	OnInit The function called on initiating the widget
939  * \param   	x The x position
940  * \param   	y The y position
941  * \param   	lx The width
942  * \param   	ly The height
943  * \retval int  	Returns the new widgets unique ID
944  *
945  * \sa progressbar_add_extended
946  */
947 int progressbar_add(int window_id, int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly);
948 
949 /*!
950  * \ingroup	progressbars
951  * \brief 	Draws a progressbar
952  *
953  * 		The function draws the progressbar pointed to by *W
954  *
955  * \param   	W The progressbar widget that is going to be drawn
956  * \retval int  	Returns false
957  * \callgraph
958  */
959 int progressbar_draw(widget_list *W);
960 
961 /*!
962  * \ingroup	progressbars
963  * \brief 	Gets the progress from a progressbar
964  *
965  * 		Finds the progressbar widget and returns the current progress
966  *
967  * \param   	window_id The location of the window in the windows_list.window[] array
968  * \param   	widget_id The unique widget ID
969  * \retval float  	Returns -1 on failure, otherwise the current progress.
970  *
971  * \sa widget_find
972  */
973 float progressbar_get_progress(int window_id, Uint32 widget_id);
974 
975 /*!
976  * \ingroup	progressbars
977  * \brief 	Sets the current progress in the progressbar
978  *
979  * 		The function finds the progressbar and sets it's progress.
980  *
981  * \param   	window_id The location of the window in the windows_list.window[] array
982  * \param   	widget_id The unique widget ID
983  * \param   	progress The new progress
984  * \retval int  	Returns 1 on succes, 0 on failure (if the widget_id was not found in that window).
985  *
986  * \sa widget_find
987  */
988 int progressbar_set_progress(int window_id, Uint32 widget_id, float progress);
989 
990 
991 
992 // Vertical Scrollbar
993 
994 /*!
995  * \ingroup	scrollbars
996  * \brief 	Creates an extended vertical scrollbar widget
997  *
998  * 		Creates an extended vertical scrollbar widget and adds it to the given window
999  *
1000  * \param   	window_id The location of the window in the windows_list.window[] array
1001  * \param   	wid The unique widget ID
1002  * \param   	OnInit The function called when initializing the widget
1003  * \param   	x The x position
1004  * \param   	y The y position
1005  * \param   	lx The width
1006  * \param   	ly The height
1007  * \param   	Flags The flags
1008  * \param   	size The text size
1009  * \param   	pos
1010  * \param   	pos_inc
1011  * \param		bar_len
1012  * \retval int  	Returns the new widgets unique ID
1013  *
1014  * \sa vscrollbar_add
1015  */
1016 int vscrollbar_add_extended(int window_id, Uint32 wid,  int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, Uint32 Flags, float size, int pos, int pos_inc, int bar_len);
1017 
1018 /*!
1019  * \ingroup	scrollbars
1020  * \brief 	Creates a vertical scrollbar
1021  *
1022  * 		Creates a vertical scrollbar widget and adds it to the given window
1023  *
1024  * \param   	window_id The location of the window in the windows_list.window[] array
1025  * \param   	OnInit The function used when initializing the widget
1026  * \param   	x The x position
1027  * \param   	y The y position
1028  * \param   	lx The width
1029  * \param   	ly The height
1030  * \retval int  	Returns the new widgets unique ID
1031  *
1032  * \sa vscrollbar_add_extended
1033  */
1034 int vscrollbar_add(int window_id, int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly);
1035 
1036 /*!
1037  * \ingroup	scrollbars
1038  * \brief 	Draws a vertical scrollbar
1039  *
1040  * 		Draws the vertical scrollbar given by *W
1041  *
1042  * \param   	W A pointer to the vertical scrollbar widget you wish to draw
1043  * \retval int  	Returns false
1044  * \callgraph
1045  */
1046 int vscrollbar_draw(widget_list *W);
1047 
1048 /*!
1049  * \ingroup	scrollbars
1050  * \brief 	Sets the position of the vertical scrollbar
1051  *
1052  * 		Finds the vertical scrollbar widget and sets the position.
1053  *
1054  * \param   	window_id The location of the window in the windows_list.window[] array
1055  * \param   	widget_id The unique widget ID
1056  * \param   	pos_inc The position increase (or decrease)
1057  * \retval int  	Returns 1 on succes, 0 on failure (if the widget was not found in the given window)
1058  *
1059  * \sa widget_find
1060  */
1061 int vscrollbar_set_pos_inc(int window_id, Uint32 widget_id, int pos_inc);
1062 
1063 /*!
1064  * \ingroup	scrollbars
1065  * \brief 	Sets the position of the vertical scrollbar
1066  *
1067  * 		Finds the vertical scrollbar widget and sets the position.
1068  *
1069  * \param   	window_id The location of the window in the windows_list.window[] array
1070  * \param   	widget_id The unique widget ID
1071  * \param   	pos The new position
1072  * \retval int  	Returns 1 on success, 0 on failure (if the widget was not found in the given window)
1073  *
1074  * \sa widget_find
1075  */
1076 int vscrollbar_set_pos(int window_id, Uint32 widget_id, int pos);
1077 
1078 /*!
1079  * \ingroup	scrollbars
1080  * \brief 	Scrolls the scrollbar up
1081  *
1082  * 		Finds the vertical scrollbar widget and sets the position a bit up.
1083  *
1084  * \param   	window_id The location of the window in the windows_list.window[] array
1085  * \param   	widget_id The unique widget ID
1086  * \retval int  	Returns 1 on success, 0 on failure (if the widget was not found in the given window)
1087  *
1088  * \sa widget_find
1089  */
1090 int vscrollbar_scroll_up(int window_id, Uint32 widget_id);
1091 
1092 /*!
1093  * \ingroup	scrollbars
1094  * \brief 	Scrolls the scrollbar down
1095  *
1096  * 		Finds the vertical scrollbar widget and sets the position a bit down.
1097  *
1098  * \param   	window_id The location of the window in the windows_list.window[] array
1099  * \param   	widget_id The unique widget ID
1100  * \retval int  	Returns 1 on success, 0 on failure (if the widget was not found in the given window)
1101  *
1102  * \sa widget_find
1103  */
1104 int vscrollbar_scroll_down(int window_id, Uint32 widget_id);
1105 
1106 /*!
1107  * \ingroup	scrollbars
1108  * \brief 	Sets the logical length of vertical scrollbar
1109  *
1110  * 		Finds the vertical scrollbar widget and sets its logical bar length.
1111  *
1112  * \param   	window_id The location of the window in the windows_list.window[] array
1113  * \param   	widget_id The unique widget ID
1114  * \param   	bar_len The new logical bar length
1115  * \retval int  	Returns 1 on success, 0 on failure (if the widget was not found in the given window)
1116  *
1117  * \sa widget_find
1118  */
1119 int vscrollbar_set_bar_len (int window_id, Uint32 widget_id, int bar_len);
1120 
1121 /*!
1122  * \ingroup	scrollbars
1123  * \brief 	Sets the position of the vertical scrollbar
1124  *
1125  * 		Finds the vertical scrollbar widget and returns the position
1126  *
1127  * \param   	window_id The location of the window in the windows_list.window[] array
1128  * \param   	widget_id The unique widget ID
1129  * \retval int  	Returns pos on succes, -1 on failure (if the widget was not found in the given window)
1130  *
1131  * \sa widget_find
1132  */
1133 int vscrollbar_get_pos(int window_id, Uint32 widget_id);
1134 
1135 
1136 // Tabbed window
1137 
1138 /*!
1139  * \ingroup	tabs
1140  * \brief 	Returns the number of the currently selected tab
1141  *
1142  * 		Returns the number of the currently selected tab in a tabbed window collection. Numbers are in the range 0...nr_tabs-1.
1143  *
1144  * \param   	window_id The location of the window in the windows_list.window[] array
1145  * \param   	widget_id The unique widget ID of the tab collection
1146  * \retval int  	Returns the tab number on succes, -1 on failure
1147  *
1148  * \sa widget_find
1149  */
1150 int tab_collection_get_tab (int window_id, Uint32 widget_id);
1151 
1152 /*!
1153  * \ingroup	tabs
1154  * \brief 	Returns the window ID of the currently selected tab
1155  *
1156  * 		Returns the window ID of the currently selected tab in a tabbed window collection.
1157  *
1158  * \param   	window_id The location of the window in the windows_list.window[] array
1159  * \param   	widget_id The unique widget ID of the tab collection
1160  * \retval int  	Returns the tab's window ID number on succes, -1 on failure
1161  */
1162 int tab_collection_get_tab_id (int window_id, Uint32 widget_id);
1163 
1164 /*!
1165  * \ingroup	tabs
1166  * \brief 	Returns the position of a tab in the collection from its window ID
1167  *
1168  * 		Returns the position of a tab in the collection from its window ID
1169  *
1170  * \param   	window_id The location of the window in the windows_list.window[] array
1171  * \param   	col_id The unique widget ID of the tab collection
1172  * \param   	tab_id The tab's window ID
1173  * \retval int  	Returns the tab's number on succes, -1 on failure
1174  */
1175 int tab_collection_get_tab_nr (int window_id, Uint32 col_id, int tab_id);
1176 
1177 /*!
1178  * \ingroup	tabs
1179  * \brief 	Returns the number of tabs in this collection
1180  *
1181  * 		Returns the number of tabs in this collection
1182  *
1183  * \param   	window_id The location of the window in the windows_list.window[] array
1184  * \param   	widget_id The unique widget ID of the tab collection
1185  * \retval int  	Returns the number of tabs, or -1 on failure
1186  */
1187 int tab_collection_get_nr_tabs (int window_id, Uint32 widget_id);
1188 
1189 /*!
1190  * \ingroup	tabs
1191  * \brief 	Sets the label color for a tab
1192  *
1193  * 		Sets the color with which the label of the tab belonging to the window with ID \a tab_id is drawn.
1194  *
1195  * \param   	window_id The location of the window in the windows_list.window[] array
1196  * \param   	col_id The unique widget ID of the tab collection
1197  * \param	tab_id The window ID of the tab window
1198  * \param	r the red component of the color
1199  * \param	g the green component of the color
1200  * \param	b the blue component of the color
1201  * \retval int  	Returns the tab's window ID number on succes, -1 on failure
1202  */
1203 int tab_set_label_color_by_id (int window_id, Uint32 col_id, int tab_id, float r, float g, float b);
1204 
1205 /*!
1206  * \ingroup	tabs
1207  * \brief 	Selects a tab in the tab collection
1208  *
1209  * 		Select a tab from the tab collection and bring it to the front
1210  *
1211  * \param   	window_id The location of the window in the windows_list.window[] array
1212  * \param   	widget_id The unique widget ID of the tab collection
1213  * \param	tab The number of the tab to be selected
1214  * \retval int  	Returns the tab number on succes, -1 on failure (if the tab number was greater than or equal to the number of tabs in the collection)
1215  * \callgraph
1216  */
1217 int tab_collection_select_tab (int window_id, Uint32 widget_id, int tab);
1218 
1219 /*!
1220  * \ingroup	tabs
1221  * \brief 	Closes a tab in the tab collection
1222  *
1223  * 		Closes a tab from the tab collection and destroys the associated window.
1224  *
1225  * \param   	window_id The location of the window in the windows_list.window[] array
1226  * \param   	widget_id The unique widget ID of the tab collection
1227  * \param	tab The number of the tab to be closed
1228  * \retval int  	Returns the tab number on succes, -1 on failure (if the tab number was greater than or equal to the number of tabs in the collection)
1229  * \callgraph
1230  */
1231 int tab_collection_close_tab (int window_id, Uint32 widget_id, int tab);
1232 
1233 /*!
1234  * \ingroup	tabs
1235  * \brief 	Calculate the tab tag height
1236  *
1237  * Calculate the tab tag height given the specified size and font category for
1238  * the label.
1239  *
1240  * \param cat  the category for the font with which the label is drawn
1241  * \param size the scale factor
1242  * \retval int  	Returns the calculate tag tag height.
1243  * \callgraph
1244  */
1245 int tab_collection_calc_tab_height(font_cat cat, float size);
1246 
1247 /*!
1248  * \ingroup	tabs
1249  * \brief 	Creates a tabbed window collection
1250  *
1251  * 		Creates a tabbed window collection and adds it to the given window
1252  *
1253  * \param   	window_id The location of the window in the windows_list.window[] array
1254  * \param   	OnInit The function used when initializing the widget
1255  * \param   	x The x position
1256  * \param   	y The y position
1257  * \param   	lx The width
1258  * \param   	ly The height
1259  * \retval int  	Returns the new widgets unique ID
1260  *
1261  * \sa tab_collection_add_extended
1262  */
1263 int tab_collection_add (int window_id, int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly);
1264 
1265 /*!
1266  * \ingroup	tabs
1267  * \brief 	Creates an extended tabbed window collection
1268  *
1269  * 		Creates an extended tabbed window collection and adds it to the given window
1270  *
1271  * \param   	window_id The location of the window in the windows_list.window[] array
1272  * \param   	wid The unique widget ID
1273  * \param   	OnInit The function called when initializing the widget
1274  * \param   	x The x position
1275  * \param   	y The y position
1276  * \param   	lx The width
1277  * \param   	ly The height
1278  * \param   	Flags The flags
1279  * \param   	size The text size
1280  * \param   	max_tabs The largest number of tabs this collection will hold
1281  * \param   	right_margin space to leave to the right of the line of tabs (for example, for a close box)
1282  * \retval int  	Returns the new widgets unique ID
1283  *
1284  * \sa tab_collection_add
1285  */
1286 int tab_collection_add_extended (int window_id, Uint32 wid, int (*OnInit)(), Uint16 x, Uint16 y,
1287 	Uint16 lx, Uint16 ly, Uint32 Flags, float size, int max_tabs, int right_margin);
1288 
1289 /*!
1290  * \ingroup	tabs
1291  * \brief 	Draws a tabbed window collection
1292  *
1293  * 		Draws the vertical tabbed window collection given by *W
1294  *
1295  * \param   	W A pointer to the tabbed window collection you wish to draw
1296  * \retval int  	Returns 1 on success, 0 on error
1297  * \callgraph
1298  */
1299 int tab_collection_draw (widget_list *W);
1300 
1301 /*!
1302  * \ingroup	tabs
1303  * \brief 	The callback for resizing the tabbed window collection widget
1304  *
1305  * 		The callback for resizing the tabbed window collection widget
1306  *
1307  * \param   	W The widget
1308  * \param   	w the new width
1309  * \param   	h the new height
1310  * \retval int  	Returns 1 on success, 0 on failure
1311  * \callgraph
1312  */
1313 int tab_collection_resize (widget_list *W, Uint32 w, Uint32 h);
1314 
1315 /*!
1316  * \ingroup	tabs
1317  * \brief 	Move the tabbed window collection widget tabs
1318  *
1319  * 		Move the tabbed window collection widget tabs
1320  *
1321  * \param   	W The widget
1322  * \param   	pos_x the absolute x position
1323  * \param   	pos_y the absolute y position
1324  * \retval int  	Returns 1 on success, 0 on failure
1325  * \callgraph
1326  */
1327 int tab_collection_move (widget_list *W, Uint32 pos_x, Uint32 pos_y);
1328 
1329 /*!
1330  * \ingroup	tabs
1331  * \brief 	Creates a new tabbed window
1332  *
1333  * 		Creates a new tabbed window
1334  *
1335  * \param   	window_id The location of the parent window in the windows_list.window[] array
1336  * \param   	col_id The unique widget id of the tabbed window collection in which this tab is created
1337  * \param   	label The name of this tab as it appears on its tag
1338  * \param	tag_width The width of the tag
1339  * \param	closable Flag indicating if the tab can be closed
1340  * \param	flags Flags to be passed to the create_window() function
1341  * \retval int  	Returns 1 if a new tab is selected, 0 otherwise
1342  * \callgraph
1343  */
1344 int tab_add (int window_id, Uint32 col_id, const char *label, Uint16 tag_width, int closable, Uint32 flags);
1345 
1346 /*!
1347  * \ingroup	textfields
1348  * \brief 	Creates a text field
1349  *
1350  * 		Creates a text field and adds it to the given window
1351  *
1352  * \param   	window_id The location of the window in the windows_list.window[] array
1353  * \param   	OnInit The function used when initializing the widget
1354  * \param   	x The x position
1355  * \param   	y The y position
1356  * \param   	lx The width
1357  * \param   	ly The height
1358  * \param	buf the message buffer
1359  * \param 	buf_size the size of the message buffer
1360  * \param	x_space the number of pixels in the x-direction between the border and the text
1361  * \param	y_space the number of pixels in the y-direction between the border and the text
1362  * \retval int  	Returns the new widgets unique ID
1363  *
1364  * \sa text_field_add_extended
1365  */
1366 int text_field_add (int window_id, int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, text_message *buf, int buf_size, int x_space, int y_space);
1367 
1368 /*!
1369  * \ingroup	textfields
1370  * \brief 	Creates an extended text field
1371  *
1372  * 		Creates an extended text field and adds it to the given window
1373  *
1374  * \param   	window_id The location of the window in the windows_list.window[] array
1375  * \param   	wid The unique widget ID
1376  * \param   	OnInit The function used when initializing the widget
1377  * \param   	x The x position
1378  * \param   	y The y position
1379  * \param   	lx The width
1380  * \param   	ly The height
1381  * \param   	Flags The flags
1382  * \param		fcat Font category for the text
1383  * \param   	size The text size
1384  * \param	buf the text buffer
1385  * \param 	buf_size the size of the text buffer
1386  * \param	chan_filt the channel of which messages are drawn
1387  * \param	x_space the number of pixels in the x-direction between the border and the text
1388  * \param	y_space the number of pixels in the y-direction between the border and the text
1389  * \retval int  	Returns the new widgets unique ID
1390  *
1391  * \sa text_field_add
1392  */
1393 int text_field_add_extended (int window_id, Uint32 wid, int (*OnInit)(),
1394 	Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, Uint32 Flags, font_cat fcat,
1395 	float size, text_message *buf, int buf_size, Uint8 chan_filt, int x_space, int y_space);
1396 
1397 /*!
1398  * \ingroup	textfields
1399  * \brief 	Draws a text field
1400  *
1401  * 		Draws the vertical textfield given by \a *w
1402  *
1403  * \param   	w A pointer to the text field you wish to draw
1404  * \retval int  	Returns 1 on success, 0 on error
1405  * \callgraph
1406  */
1407 int text_field_draw (widget_list *w);
1408 
1409 /*!
1410  * \ingroup	textfields
1411  * \brief 	Sets the offset in the text buffer
1412  *
1413  * 		Sets the offset in the buffer at which the text_field starts drawing
1414  *
1415  * \param   	window_id The location of the window in the windows_list.window[] array
1416  * \param	widget_id The unique widget ID
1417  * \param	msg the new message nr
1418  * \param	offset the new offset within the message
1419  * \retval int  	Returns 1 on success, 0 on error
1420  * \callgraph
1421  */
1422 int text_field_set_buf_pos (int window_id, Uint32 widget_id, int msg, int offset);
1423 
1424 /*!
1425  * \ingroup	textfields
1426  * \brief       Clear an editable text field
1427  *
1428  *              Clear an editable text field, erasing its current buffer and
1429  *              moving the cursor to the start
1430  *
1431  * \param   	window_id The location of the window in the windows_list.window[] array
1432  * \param	widget_id The unique widget ID
1433  * \retval int  	Returns 1 on success, 0 on error
1434  * \callgraph
1435  */
1436 int text_field_clear (int window_id, Uint32 widget_id);
1437 
1438 /*!
1439  * \ingroup	textfields
1440  * \brief 	Sets the text color
1441  *
1442  * 		Sets the color with which the text is drawn. Not that color characters in the text override this setting.
1443  *
1444  * \param   	window_id The location of the window in the windows_list.window[] array
1445  * \param	widget_id The unique widget ID
1446  * \param	r the red component of the text color
1447  * \param	g the green component of the text color
1448  * \param	b the blue component of the text color
1449  * \retval int  	Returns 1 on success, 0 on error
1450  * \callgraph
1451  */
1452 int text_field_set_text_color (int window_id, Uint32 widget_id, float r, float g, float b);
1453 
1454 /*!
1455  * \ingroup	widgets
1456  * \brief	Is called on keypress in the given widget
1457  *
1458  * 		Is called on keypress in the given widget
1459  *
1460  * \param	w pointer to the widget structure
1461  * \param   	mx the mouse x position relative to the widgets origin
1462  * \param   	my the mouse y position relative to the widgets origin
1463  * \param	key_code the SDL key code
1464  * \param	key_unicode the unicode representation of the key pressed
1465  * \param	key_mod the status bitmask for mod keys
1466  * retval	1 if the event is handled 0 otherwise
1467  */
1468 int text_field_keypress (widget_list *w, int mx, int my, SDL_Keycode key_code, Uint32 key_unicode, Uint16 key_mod);
1469 
1470 /*!
1471  * \ingroup widgets
1472  *
1473  * \brief Force a text field to rewrap the lines.
1474  *
1475  * Force the textfield identified by window ID \a window_id and widget ID
1476  * \a widget_id, to recalculate the positions of the soft line breaks. This is
1477  * done e.g. in situations where the font or font size is changed.
1478  *
1479  * \param window_id The identifier for the window the text field resides in
1480  * \param widget_id The identifier for the text field widget
1481  */
1482 void text_field_force_rewrap(int window_id, Uint32 widget_id);
1483 
1484 //FIXME: Write documentation for these...
1485 #define P_NORMAL    0
1486 #define P_TEXT      1
1487 #define P_NONE      2
1488 
1489 int pword_field_add (int window_id, int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, Uint8 status, unsigned char *buffer, int buffer_size);
1490 int pword_field_add_extended (int window_id, Uint32 wid, int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, Uint8 status, float size, unsigned char *buffer, int buffer_size);
1491 int pword_field_set_content(int window_id, Uint32 widget_id, const unsigned char* buf, size_t len);
1492 /*!
1493  * \ingroup widgets
1494  *
1495  * \brief Set the shadow color of the text
1496  *
1497  * Set the shadow color of the text in the password field identified by window ID \a window_id
1498  * and widget ID \a widget_id, to \a r, \a g, \a b. If this function is not called, or \a r < 0,
1499  * no shadow is drawn.
1500  *
1501  * \param window_id The window identifier for the password field
1502  * \param widget_id The widget identifier for the password field
1503  * \param r         The red component of the shadow color
1504  * \param g         The green component of the shadow color
1505  * \param b         The blue component of the shadow color
1506  * \return 1 on success, 0 on failure (widget not found)
1507  */
1508 int pword_field_set_shadow_color(int window_id, Uint32 widget_id, float r, float g, float b);
1509 void pword_set_status(widget_list *w, Uint8 status);
1510 int pword_clear(int window_id, Uint32 widget_id);
1511 
1512 int multiselect_add(int window_id, int (*OnInit)(), Uint16 x, Uint16 y, int width);
1513 int multiselect_add_extended(int window_id, Uint32 widget_id, int (*OnInit)(), Uint16 x, Uint16 y, int width, Uint16 max_height, float size, float r, float g, float b, float hr, float hg, float hb, int max_buttons);
1514 int multiselect_button_add(int window_id, Uint32 multiselect_id, Uint16 x, Uint16 y, const char *text, const char selected);
1515 int multiselect_button_add_extended(int window_id, Uint32 multiselect_id, Uint16 x, Uint16 y, int width, const char *text, float size, const char selected);
1516 int multiselect_get_selected(int window_id, Uint32 widget_id);
1517 int multiselect_set_selected(int window_id, Uint32 widget_id, int button_id);
1518 int multiselect_get_scrollbar_pos(int window_id, Uint32 widget_id);
1519 int multiselect_set_scrollbar_pos(int window_id, Uint32 widget_id, int pos);
1520 int multiselect_get_height(int window_id, Uint32 widget_id);
1521 int multiselect_clear(int window_id, Uint32 widget_id);
1522 
1523 #define SPIN_FLOAT 0
1524 #define SPIN_INT 1
1525 
1526 int spinbutton_add(int window_id, int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, Uint8 data_type, void *data, float min, float max, float interval);
1527 int spinbutton_add_extended(int window_id, Uint32 widget_id, int (*OnInit)(), Uint16 x, Uint16 y, Uint16 lx, Uint16 ly, Uint8 data_type, void *data, float min, float max, float interval, float size);
1528 
1529 /*!
1530  * \ingroup	widgets
1531  * \brief 	Handles a mouseover event
1532  *
1533  * 		Handles a mousover event for a widget.
1534  *
1535  * \param   	widget pointer to the widget structure
1536  * \param   	mx the mouse x position relative to the widgets origin
1537  * \param   	my the mouse y position relative to the widgets origin
1538  * \retval 	1 if the event is handled, 0 otherwise
1539  */
1540 int widget_handle_mouseover (widget_list *widget, int mx, int my);
1541 
1542 /*!
1543  * \ingroup	widgets
1544  * \brief 	Handles a mouse click event
1545  *
1546  * 		Handles a mous click event for a widget.
1547  *
1548  * \param   	widget pointer to the widget structure
1549  * \param   	mx the mouse x position relative to the widgets origin
1550  * \param   	my the mouse y position relative to the widgets origin
1551  * \param	flags flags specifying the mouse button and modifier state
1552  * \retval 	1 if the event is handled, 0 otherwise
1553  */
1554 int widget_handle_click (widget_list *widget, int mx, int my, Uint32 flags);
1555 
1556 /*!
1557  * \ingroup	widgets
1558  * \brief 	Handles a mouse drag event
1559  *
1560  * 		Handles a mouse drag event for a widget.
1561  *
1562  * \param   	widget pointer to the widget structure
1563  * \param   	mx the mouse x position relative to the widgets origin
1564  * \param   	my the mouse y position relative to the widgets origin
1565  * \param	flags flags specifying the mouse button and modifier state
1566  * \param   	dx the change in mouse position in the x direction
1567  * \param   	dy the change in mouse position in the y direction
1568  * \retval 	1 if the event is handled, 0 otherwise
1569  */
1570 int widget_handle_drag (widget_list *widget, int mx, int my, Uint32 flags, int dx, int dy);
1571 
1572 /*!
1573  * \ingroup	widgets
1574  * \brief 	Handles a keypess event
1575  *
1576  * 		Handles a keypress event for a widget.
1577  *
1578  * \param   	widget pointer to the widget structure
1579  * \param   	mx the mouse x position relative to the widgets origin
1580  * \param   	my the mouse y position relative to the widgets origin
1581  * \param	key_code the SDL key code
1582  * \param	key_unicode the unicode representation of the key pressed
1583  * \param	key_mod the status bitmask for mod keys
1584  * \retval 	1 if the event is handled, 0 otherwise
1585  */
1586 int widget_handle_keypress (widget_list *widget, int mx, int my, SDL_Keycode key_code, Uint32 key_unicode, Uint16 key_mod);
1587 /*!
1588  * \ingroup widgets
1589  *
1590  * Handle a change in font
1591  *
1592  * Handle a change in font or font size in font category \a cat for widget \a widget.
1593  *
1594  * \param widget The widget to handle the font change for.
1595  * \param cat    The font category that was changed.
1596  *
1597  * \return 1 if the widget handled the change, 0 otherwise
1598  */
1599 int widget_handle_font_change(widget_list *widget, font_cat cat);
1600 /*!
1601  * \ingroup widgets
1602  *
1603  * Handle a paste event
1604  *
1605  * Handle a text paste event, and paste text \a text into widget \a widget.
1606  *
1607  * \param widget The widget to handle the paste event
1608  * \param text   The text to paste into the widget
1609  *
1610  * \return 1 if the widget handled the change, 0 otherwise
1611  */
1612 int widget_handle_paste(widget_list *widget, const char* text);
1613 
1614 
1615 
1616 /*!
1617  * \ingroup	widgets
1618  * \brief 	A general helper function to draw a cross.
1619  *
1620  * 		Draw a scalable cross centred the specified position and of the
1621  * 	specified size and width.
1622  *
1623  * \param	the centre x coordinate of the cross.
1624  * \param	the centre y coordinate of the cross.
1625  * \param	half the length in pixels of the cross width/height.
1626  * \param	half the width in pixels of cross lines
1627  */
1628 void draw_cross(int centre_x, int centre_y, int half_len, int half_width);
1629 
1630 
1631 // XML Windows
1632 
1633 /*!
1634  * \ingroup 	xml_windows
1635  * \brief 	Adds a window from an xml-file.
1636  *
1637  * 		Adds a window from an xml-file.
1638  *
1639  * \param   	fn The filename
1640  * \retval int  	Returns 0 on failure and the window_id on succes
1641  * \callgraph
1642  */
1643 int AddXMLWindow(char *fn);
1644 
1645 #ifdef __cplusplus
1646 } // extern "C"
1647 #endif
1648 
1649 #endif
1650