]> icculus.org git repositories - taylor/freespace2.git/blob - include/ui.h
Fix net_addr vs net_addr_t
[taylor/freespace2.git] / include / ui.h
1 /*
2  * $Logfile: /Freespace2/code/Ui/UI.H $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Include file for our user interface.
8  *
9  * $Log$
10  * Revision 1.2  2002/05/27 00:38:47  relnev
11  * virtual
12  *
13  * Revision 1.1.1.1  2002/05/03 03:28:12  root
14  * Initial import.
15  *
16  * 
17  * 20    8/16/99 9:45a Jefff
18  * changes to cursor management to allow a 2nd temporary cursor
19  * 
20  * 19    8/11/99 3:21p Jefff
21  * set_bmaps clarification by daveb
22  * 
23  * 18    8/11/99 12:18p Jefff
24  * added option to slider2 class to not force slider reset on
25  * set_numberItems
26  * 
27  * 17    8/10/99 6:54p Dave
28  * Mad optimizations. Added paging to the nebula effect.
29  * 
30  * 16    8/05/99 2:44p Jefff
31  * added disabled callback to UI_BUTTON
32  * 
33  * 15    6/25/99 11:59a Dave
34  * Multi options screen.
35  * 
36  * 14    6/22/99 7:03p Dave
37  * New detail options screen.
38  * 
39  * 13    5/21/99 6:45p Dave
40  * Sped up ui loading a bit. Sped up localization disk access stuff. Multi
41  * start game screen, multi password, and multi pxo-help screen.
42  * 
43  * 12    5/04/99 5:20p Dave
44  * Fixed up multiplayer join screen and host options screen. Should both
45  * be at 100% now.
46  * 
47  * 11    5/03/99 8:33p Dave
48  * New version of multi host options screen.
49  * 
50  * 10    4/29/99 2:15p Neilk
51  * fixed slider so there is an extra callback for mouse locks
52  * 
53  * 9     4/16/99 5:22p Neilk
54  * Added UI_SLIDER2 class
55  * 
56  * 8     2/21/99 6:02p Dave
57  * Fixed standalone WSS packets. 
58  * 
59  * 7     2/11/99 3:08p Dave
60  * PXO refresh button. Very preliminary squad war support.
61  * 
62  * 6     2/01/99 5:55p Dave
63  * Removed the idea of explicit bitmaps for buttons. Fixed text
64  * highlighting for disabled gadgets.
65  * 
66  * 5     12/18/98 1:13a Dave
67  * Rough 1024x768 support for Direct3D. Proper detection and usage through
68  * the launcher.
69  * 
70  * 4     12/02/98 5:47p Dave
71  * Put in interface xstr code. Converted barracks screen to new format.
72  * 
73  * 3     11/30/98 1:07p Dave
74  * 16 bit conversion, first run.
75  * 
76  * 2     10/07/98 10:54a Dave
77  * Initial checkin.
78  * 
79  * 1     10/07/98 10:51a Dave
80  * 
81  * 71    5/12/98 11:59p Dave
82  * Put in some more functionality for Parallax Online.
83  * 
84  * 70    5/11/98 5:29p Hoffoss
85  * Added mouse button mapped to joystick button support.
86  * 
87  * 69    5/05/98 1:49a Lawrance
88  * Add member function to disable processing for all gadgets in a window
89  * 
90  * 68    5/03/98 1:55a Lawrance
91  * Add function call that forces button code to skip first callback for
92  * highlighing
93  * 
94  * 67    4/17/98 12:22a Dave
95  * Bumped up MAX_TOOLTIPS from 350 to 500 so Freespace will start.
96  * 
97  * 66    4/14/98 5:07p Dave
98  * Don't load or send invalid pilot pics. Fixed chatbox graphic errors.
99  * Made chatbox display team icons in a team vs. team game. Fixed up pause
100  * and endgame sequencing issues.
101  * 
102  * 65    4/14/98 4:27p Hoffoss
103  * Changed the way tooltips render as requested.
104  * 
105  * 64    4/13/98 4:30p Hoffoss
106  * Fixed a bunch of stupid little bugs in options screen.  Also changed
107  * forced_draw() to work like it used to.
108  * 
109  * 63    4/12/98 2:09p Dave
110  * Make main hall door text less stupid. Make sure inputbox focus in the
111  * multi host options screen is managed more intelligently.
112  * 
113  * 62    4/10/98 5:36p Dave
114  * Put in user notification of illegal values in multi host options
115  * screen. Fixed server respawn ship class problem.
116  * 
117  * 61    4/10/98 4:51p Hoffoss
118  * Made several changes related to tooltips.
119  * 
120  * 60    4/09/98 7:14p Hoffoss
121  * Did some cool changes for tooltips.
122  * 
123  * 59    4/09/98 5:57p Hoffoss
124  * Added custom tooltip handler functionality for callback.
125  * 
126  * 58    4/09/98 12:12p Mike
127  * Separate versioning for demo and full versions.
128  * Fix inputbox bugs.
129  * 
130  * 57    3/30/98 6:24p Hoffoss
131  * Added the tooltip (foreign language translation of text) system.
132  * 
133  * 56    3/23/98 5:48p Hoffoss
134  * Improved listbox handling.  Most notibly the scrollbar arrows work now.
135  * 
136  * 55    3/22/98 10:50p Lawrance
137  * Allow sliders to not have end-buttons.
138  * 
139  * 54    3/10/98 4:06p Hoffoss
140  * Removed unused variables.
141  * 
142  * 53    3/09/98 5:55p Dave
143  * Fixed stats to take asteroid hits into account. Polished up UI stuff in
144  * team select. Finished up pilot info popup. Tracked down and fixed
145  * double click bug.
146  * 
147  * 52    3/02/98 3:54p Lawrance
148  * make button draw function public
149  * 
150  * 51    2/26/98 4:21p Dave
151  * More robust multiplayer voice.
152  * 
153  * 50    2/11/98 6:24p Hoffoss
154  * Fixed bug where disabled and hidden buttons give failed sound when
155  * pressed.  Shouldn't happen when they are hidden.
156  * 
157  * 49    2/09/98 10:03a Hoffoss
158  * Made first_time variable public so I can clear the stupid thing in code
159  * that I want it to be cleared in.
160  * 
161  * 48    1/26/98 6:28p Lawrance
162  * Add ability to for a button press event externally.
163  * 
164  * 47    1/23/98 5:43p Dave
165  * Finished bringing standalone up to speed. Coded in new host options
166  * screen.
167  * 
168  * 46    1/16/98 7:57p Lawrance
169  * support animating input box cursor
170  * 
171  * 45    1/15/98 5:10p Allender
172  * ton of interface changes.  chatbox in multiplayer now behaves
173  * differently than before.  It's always active in any screen that uses
174  * it.  Only non-printatble characters will get passed back out from
175  * chatbox
176  * 
177  * 44    1/14/98 6:44p Hoffoss
178  * Massive changes to UI code.  A lot cleaner and better now.  Did all
179  * this to get the new UI_DOT_SLIDER to work properly, which the old code
180  * wasn't flexible enough to handle.
181  * 
182  * 43    1/02/98 9:11p Lawrance
183  * Add button_hot() function
184  * 
185  * 42    12/22/97 5:08p Hoffoss
186  * Changed inputbox class to be able to accept only certain keys, changed
187  * pilot screens to utilize this feature.  Added to assert with pilot file
188  * saving.
189  * 
190  * 41    12/11/97 8:15p Dave
191  * Put in network options screen. Xed out olf protocol selection screen.
192  * 
193  * 40    12/10/97 3:14p Dave
194  * Added an overloaded set_mask_bmap(int) function for the UI_WINDOW
195  * 
196  * 39    12/08/97 6:22p Lawrance
197  * blink cursor on inputbox
198  * 
199  * 38    12/06/97 4:27p Dave
200  * Another load of interface and multiplayer bug fixes.
201  * 
202  * 37    11/25/97 3:51p Hoffoss
203  * Changed edit background rect position slightly.
204  * 
205  * 36    11/19/97 8:32p Hoffoss
206  * Changed UI buttons so they go back to unpressed when they are disabled.
207  * 
208  * 35    10/29/97 7:25p Hoffoss
209  * Added crude support for UI button double click checking.
210  * 
211  * 34    10/24/97 10:58p Hoffoss
212  * Made some changes to the UI code to do some things I need it to do.
213  * 
214  * 33    10/01/97 4:40p Lawrance
215  * allow process() to have key input
216  * 
217  * 32    9/18/97 10:31p Lawrance
218  * allow listbox to change text
219  * 
220  * 31    9/09/97 4:32p Dave
221  * Added sel_changed() function to UI_LISTBOX to check is the selection
222  * has changed.
223  * 
224  * 30    9/07/97 10:05p Lawrance
225  * add icon class
226  * 
227  * 29    8/30/97 12:23p Lawrance
228  * add button function to reset the status of a button
229  * 
230  * 28    8/29/97 7:33p Lawrance
231  * move cleanup code from destructor to destroy() method
232  * 
233  * 27    8/24/97 5:25p Lawrance
234  * improve drawing of buttons 
235  * 
236  * 26    8/21/97 12:13p Dave
237  * Made it possible for input box to ignore esc to lose focus.
238  * 
239  * 25    8/19/97 1:27p Dave
240  * Modified input box to allow character limitation by pixel width.
241  * Changed list box so that you can create an empty box and add items as
242  * you need to.
243  * 
244  * 24    8/18/97 5:28p Lawrance
245  * integrating sounds for when mouse goes over an active control
246  * 
247  * 23    8/17/97 2:42p Lawrance
248  * add code to have selected bitmap for buttons linger for a certain time
249  * 
250  * 22    8/15/97 8:21p Dave
251  * Modified UI_INPUTBOX so that it is possible to draw it invisibly. That
252  * is, only the text is displayed.
253  * 
254  * 21    8/14/97 5:23p Dave
255  * Added clear_all_items() to the UI_LISTBOX
256  * 
257  * 20    6/13/97 5:51p Lawrance
258  * add in support for repeating buttons
259  * 
260  * 19    6/11/97 1:32p Allender
261  * externed sort_filelist
262  * 
263  * 18    5/26/97 10:26a Lawrance
264  * get slider control working 100%
265  * 
266  * 17    5/22/97 5:36p Lawrance
267  * allowing custom art for scrollbars
268  * 
269  * 16    5/21/97 11:07a Lawrance
270  * integrate masks and custom bitmaps
271  * 
272  * 15    4/28/97 2:19p Lawrance
273  * added clear_focus() function
274  * 
275  * 14    4/22/97 10:11a John
276  * Added checkbox lists to listboxes
277  * 
278  * 13    4/15/97 3:47p Allender
279  * moved type selection of list box items into actual UI code.  Made it
280  * behave more like windows listboxes do
281  * 
282  * 12    1/28/97 4:58p Lawrance
283  * allowing hidden UI components
284  * 
285  * 11    12/23/96 2:42p Lawrance
286  * allowing keys to select list box items in the mission load screen
287  * 
288  * 10    12/04/96 3:00p John
289  * Added code to allow adjusting of HUD colors and saved it to the player
290  * config file.
291  * 
292  * 9     12/03/96 3:46p Lawrance
293  * added ability to set contents of input box
294  * 
295  * 8     12/03/96 11:29a John
296  * Made scroll buttons on listbox scroll once, then delay, then repeat
297  * when the buttons are held down.
298  * 
299  * 7     12/02/96 2:17p John
300  * Made right button drag UI gadgets around and
301  * Ctrl+Shift+Alt+F12 dumps out where they are.
302  * 
303  * 6     12/01/96 3:48a Lawrance
304  * added function set_current to UI_LISTBOX
305  * 
306  * 5     11/29/96 6:08p Lawrance
307  * enabled check-boxes to be set to a specific value outside of the
308  * create() function
309  * 
310  * 4     11/21/96 10:58a John
311  * Started adding code to drag buttons.
312  * 
313  * 3     11/18/96 4:28p Jasen
314  * making class member process return an int
315  * 
316  * 2     11/15/96 11:42a John
317  * 
318  * 1     11/14/96 6:55p John
319  *
320  * $NoKeywords: $
321  */
322
323 #ifndef _UI_H
324 #define _UI_H
325
326 #include "2d.h"
327
328 #define UI_KIND_BUTTON                          1
329 #define UI_KIND_KEYTRAP                         2
330 #define UI_KIND_CHECKBOX                        3
331 #define UI_KIND_RADIO                           4
332 #define UI_KIND_SCROLLBAR                       5
333 #define UI_KIND_LISTBOX                         6
334 #define UI_KIND_INPUTBOX                        7
335 #define UI_KIND_SLIDER                          8
336 #define UI_KIND_ICON                                    9
337 #define UI_KIND_DOT_SLIDER                      10
338 #define UI_KIND_SLIDER2                         11
339 #define UI_KIND_DOT_SLIDER_NEW  12
340
341 #define MAX_KEY_BUFFER                          32              // for listboxes
342
343 #define MAX_BMAPS_PER_GADGET            15
344
345 #define UI_INPUTBOX_FLAG_INVIS                  (1 << 0)                // don't draw the input box boarders
346 #define UI_INPUTBOX_FLAG_KEYTHRU                        (1 << 1)                // pass all keypresses through to parent
347 #define UI_INPUTBOX_FLAG_ESC_CLR                        (1 << 2)                // allow escape key to clear input box
348 #define UI_INPUTBOX_FLAG_ESC_FOC                        (1 << 3)                // escape loses focus for the input box
349 #define UI_INPUTBOX_FLAG_PASSWD                 (1 << 4)                // display all characters as special "password" characters
350 #define UI_INPUTBOX_FLAG_EAT_USED               (1 << 5)                // don't return any characters actually used by inputbox
351 #define UI_INPUTBOX_FLAG_LETTER_FIRST   (1 << 6)                // require input string to begin with a letter.
352 #define UI_INPUTBOX_FLAG_NO_LETTERS             (1 << 7)                // don't allow [a-z,A-Z] at all, no matter what
353 #define UI_INPUTBOX_FLAG_NO_NUMERALS    (1 << 8)                // don't allow [0-9] at all, no matter what
354 #define UI_INPUTBOX_FLAG_TEXT_CEN               (1 << 9)                // always draw text centered in the inputbox
355 #define UI_INPUTBOX_FLAG_NO_BACK                        (1 << 10)       // don't draw a black background rectangle
356
357 #define UI_GF_MOUSE_CAPTURED                            (1 << 31)  // gadget has all rights to the mouse
358
359 class UI_WINDOW;
360 class UI_BUTTON;
361 class UI_KEYTRAP;
362 class UI_CHECKBOX;
363 class UI_RADIO;
364 class UI_SCROLLBAR;
365 class UI_LISTBOX;
366 class UI_INPUTBOX;
367 // class UI_SLIDER;
368 class UI_DOT_SLIDER;
369 class UI_DOT_SLIDER_NEW;
370
371 class UI_GADGET
372 {
373         friend class UI_WINDOW;
374         friend class UI_BUTTON;
375         friend class UI_KEYTRAP;
376         friend class UI_CHECKBOX;
377         friend class UI_RADIO;
378         friend class UI_SCROLLBAR;
379         friend class UI_LISTBOX;
380         friend class UI_INPUTBOX;
381         // friend UI_SLIDER;
382         friend class UI_DOT_SLIDER;     
383         friend class UI_DOT_SLIDER_NEW;
384
385         protected:
386                 char *bm_filename;
387                 int kind;
388                 int hotkey;
389                 int x, y, w, h;
390                 int m_flags;
391                 void (*user_function)(void);
392                 int disabled_flag;
393                 int base_dragging;
394                 int base_drag_x, base_drag_y;
395                 int base_start_x, base_start_y;
396                 int hidden;
397
398                 // Data for supporting linking controls to hotspots
399                 int linked_to_hotspot;
400                 int hotspot_num;
401
402                 // Data for supporting bitmaps associated with different states of the control
403                 int uses_bmaps;
404                 int m_num_frames;
405 //              ubyte           *bmap_storage[MAX_BMAPS_PER_GADGET];
406
407                 void drag_with_children( int dx, int dy );
408                 void start_drag_with_children();
409                 void stop_drag_with_children();
410
411                 UI_GADGET *parent;
412                 UI_GADGET *children;
413                 UI_GADGET *prev;
414                 UI_GADGET *next;
415
416                 int is_mouse_on_children();
417                 void remove_from_family();
418                 void set_parent(UI_GADGET *_parent);
419
420                 UI_GADGET *get_next();
421                 UI_GADGET *get_prev();
422                 UI_WINDOW *my_wnd;
423                 
424                 virtual void process(int focus = 0);
425                 virtual void destroy();
426                 int check_move();
427
428         public:
429                 int bmap_ids[MAX_BMAPS_PER_GADGET];
430
431                 UI_GADGET();    // constructor
432                 virtual ~UI_GADGET();   // destructor
433
434                 void base_create( UI_WINDOW *wnd, int kind, int x, int y, int w, int h );
435                 virtual void draw();
436                 void set_focus();
437                 void clear_focus();
438                 int has_focus();
439                 void set_hotkey(int keycode);
440                 void set_callback(void (*user_function)(void));
441                 void disable();
442                 void enable(int n = 1);
443                 void capture_mouse();
444                 int mouse_captured(UI_GADGET *gadget = NULL);
445                 int disabled();
446                 int enabled();
447                 virtual void hide(int n = 1);
448                 virtual void unhide();
449                 void update_dimensions(int x, int y, int w, int h);
450                 void get_dimensions(int *x, int *y, int *w, int *h);
451                 int is_mouse_on();
452                 void get_mouse_pos(int *x, int *y);
453
454                 void link_hotspot(int num);
455                 int get_hotspot();
456                 int bmaps_used() { return uses_bmaps; }
457
458                 // loads nframes bitmaps, starting at index start_frame.
459                 // anything < start_frame will not be loaded.
460                 // this keeps the loading code from trying to load bitmaps which don't exist
461                 // and taking an unnecessary disk hit.          
462                 int set_bmaps(char *ani_filename, int nframes = 3, int start_frame = 1);                // extracts MAX_BMAPS_PER_GADGET from .ani file         
463
464                 void reset();  // zero out m_flags
465                 int is_hidden() { return hidden; }
466 };
467
468 // xstrings for a window
469 #define UI_NUM_XSTR_COLORS                      2
470 #define UI_XSTR_COLOR_GREEN             0                       // shades of green/gray
471 #define UI_XSTR_COLOR_PINK                      1                       // pinkish hue
472 typedef struct UI_XSTR {
473         char *xstr;                                                                             // base string
474         int xstr_id;                                                                    // xstring id   
475         int x, y;                                                                               // coords of the string
476         int clr;                                                                                        // color to use
477         int font_id;                                                                    // font id              
478         UI_GADGET *assoc;                                                               // the associated gadget
479 } UI_XSTR;
480
481 #define MAX_UI_XSTRS                                    100
482
483 // Button terminology:
484 //   Up = button is in up state (also called pressed)
485 //   Down = button is in down state (also called released)
486 //   Just pressed = button has just gone from up to down state
487 //   Just released = button has just gone from down to up state
488 //   Clicked = a trigger type effect caused by 'just pressed' event or repeat while 'down'
489 //   Double clicked = 2 'just pressed' events occuring within a short amount of time
490
491 // Button flags
492 #define BF_UP                                                   (1<<0)
493 #define BF_DOWN                                         (1<<1)
494 #define BF_JUST_PRESSED                         (1<<2)
495 #define BF_JUST_RELEASED                        (1<<3)
496 #define BF_CLICKED                                      (1<<4)
497 #define BF_DOUBLE_CLICKED                       (1<<5)
498 #define BF_HIGHLIGHTED                          (1<<6)  // button is not highlighted (ie mouse is not over)
499 #define BF_JUST_HIGHLIGHTED             (1<<7)  // button has just been highlighted, true for 1 frame
500 #define BF_IGNORE_FOCUS                         (1<<8)  // button should not use focus to accept space/enter keypresses
501 #define BF_HOTKEY_JUST_PRESSED  (1<<9)  // button hotkey was just pressed
502 #define BF_REPEATS                                      (1<<10) // if held down, generates repeating presses
503 #define BF_SKIP_FIRST_HIGHLIGHT_CALLBACK (1<<11)        // skip first callback for mouse over event
504
505 class UI_BUTTON : public UI_GADGET
506 {
507         friend class UI_SCROLLBAR;
508         // friend UI_SLIDER;
509         friend class UI_DOT_SLIDER;
510         friend class UI_DOT_SLIDER_NEW;
511
512                 char *text;
513                 int position;                   // indicates position of button (0 - up, 1 - down by mouse click 2 - down by keypress
514                 int next_repeat;                // timestamp for next repeat if held down
515                 int m_press_linger;     // timestamp for hold a pressed state animation
516                 int hotkey_if_focus;    // hotkey for button that only works if it has focus
517                 int force_draw_frame;   // frame number to draw next time (override default)
518                 int first_callback;             // true until first time callback function is called for button highlight
519
520                 // Used to index into bmap_ids[] array to locate right bitmap for button
521                 enum { B_NORMAL = 0 };
522                 enum { B_HIGHLIGHT = 1 };
523                 enum { B_PRESSED = 2 };
524                 enum { B_DISABLED = 3 };
525                 enum { B_REPEAT_TIME = 100 };  // ms
526                         
527                 void (*m_just_highlighted_function)(void);      // call-back that gets called when button gets highlighted
528                 void (*m_disabled_function)(void);                              // callback that gets called when disabled button gets pressed (sound, popup, etc)
529
530                 void frame_reset();
531                 virtual void process(int focus = 0);
532                 virtual void destroy();
533
534                 int custom_cursor_bmap;                                 // bmap handle of special cursor used on mouseovers
535                 int previous_cursor_bmap;                               // store old cursor
536                 void maybe_show_custom_cursor();                // call this in process() 
537                 void restore_previous_cursor();         // called in frame_reset()
538
539         public:
540                 virtual void draw();
541                 void set_hotkey_if_focus(int key);
542                 int pressed();                          // has it been selected (ie clicked on)
543                 int double_clicked();   // button was double clicked on
544                 int just_pressed();             // button has just been selected
545                 int just_highlighted(); // button has just had mouse go over it
546                 int button_down();              // is the button depressed?
547                 int button_hilighted(); // is the mouse over this button?
548                 void set_button_hilighted();    // force button to be highlighted
549                 void press_button();            // force button to get pressed
550                 void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h, int do_repeat=0, int ignore_focus = 0);
551                 void set_highlight_action( void (*user_function)(void) );
552                 void set_disabled_action( void (*user_function)(void) );
553                 void draw_forced(int frame_num);
554                 void reset_status();
555                 void reset_timestamps();
556                 void skip_first_highlight_callback();
557                 void repeatable(int yes);
558                 void set_custom_cursor_bmap(int bmap_id) { custom_cursor_bmap = bmap_id; };
559 };
560
561 class UI_KEYTRAP : public UI_GADGET
562 {
563                 int pressed_down;
564                 virtual void draw();
565                 virtual void process(int focus = 0);
566
567         public:
568                 int pressed();
569                 void create(UI_WINDOW *wnd, int hotkey, void (*user_function)(void) );
570 };
571
572 class UI_USERBOX : public UI_GADGET
573 {
574                 int b1_held_down;
575                 int b1_clicked;
576                 int b1_double_clicked;
577                 int b1_dragging;
578                 int b1_drag_x1, b1_drag_y1;
579                 int b1_drag_x2, b1_drag_y2;
580                 int b1_done_dragging;
581                 int keypress;
582                 int mouse_onme;
583                 int mouse_x, mouse_y;
584                 int bitmap_number;
585 };
586
587 class UI_INPUTBOX : public UI_GADGET
588 {
589                 char *text;
590                 char *passwd_text;
591                 int length;
592                 int position;
593                 int oldposition;
594                 int pressed_down;
595                 int changed_flag;
596                 int flags;
597                 int pixel_limit;    // base max characters on how wide the string is (-1 to ignore) in pixels
598                 int locked;
599 //              int should_reset;
600                 int ignore_escape;
601                 color *text_color;
602                 char *valid_chars;
603                 char *invalid_chars;
604
605                 // cursor drawing
606                 int cursor_first_frame;
607                 int cursor_nframes;
608                 int cursor_fps;
609                 int cursor_current_frame;
610                 int cursor_elapsed_time;
611
612                 int     validate_input(int chr);
613                 void    init_cursor();
614
615                 virtual void draw();
616                 virtual void process(int focus = 0);
617                 virtual void destroy();
618
619         public:
620 //              int first_time;
621
622                 void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _textlen, char *text, int _flags = 0, int pixel_lim = -1, color *clr = NULL);
623                 void set_valid_chars(char *vchars);
624                 void set_invalid_chars(char *ichars);
625                 int changed();
626                 int pressed();
627                 void get_text(char *out);
628                 void set_text(char *in);
629 };
630
631 // Icon flags
632 #define ICON_NOT_HIGHLIGHTED            (1<<0)  // icon is not highlighted (ie mouse is not over)
633 #define ICON_JUST_HIGHLIGHTED   (1<<1)  // icon has just been highlighted, true for 1 frame
634
635 class UI_ICON : public UI_GADGET
636 {
637                 char *text;
638
639                 // Used to index into bmap_ids[] array to locate right bitmap for button
640                 enum { ICON_NORMAL = 0 };
641                 enum { ICON_HIGHLIGHT = 1 };
642                 enum { ICON_SELECTED = 2 };
643                 enum { ICON_DISABLED = 3 };
644                         
645                 virtual void draw();
646                 virtual void process(int focus = 0);
647                 virtual void destroy();
648
649         public:
650                 void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h);
651 };
652
653 class UI_CHECKBOX : public UI_GADGET
654 {
655                 char *text;
656                 int position;
657                 int pressed_down;
658                 int flag;
659                 virtual void draw();
660                 virtual void process(int focus = 0);
661                 virtual void destroy();
662
663                 // Used to index into bmap_ids[] array to locate right bitmap for checkbox
664                 enum { CBOX_UP_CLEAR = 0 };
665                 enum { CBOX_DOWN_CLEAR = 1 };
666                 enum { CBOX_UP_MARKED = 2 };
667                 enum { CBOX_DOWN_MARKED = 3 };
668                 enum { CBOX_DISABLED_CLEAR = 4 };
669                 enum { CBOX_DISABLED_MARKED = 5 };
670
671         public:
672                 int changed();
673                 int checked();
674                 void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _state );
675                 void set_state(int _state);
676 };
677
678 class UI_RADIO : public UI_GADGET
679 {
680                 char *text;
681                 int position;
682                 int pressed_down;
683                 int flag;
684                 int group;
685                 virtual void draw();
686                 virtual void process(int focus = 0);
687                 virtual void destroy();
688
689                 // Used to index into bmap_ids[] array to locate right bitmap for radio button
690                 enum { RADIO_UP_CLEAR = 0 };
691                 enum { RADIO_DOWN_CLEAR = 1 };
692                 enum { RADIO_UP_MARKED = 2 };
693                 enum { RADIO_DOWN_MARKED = 3 };
694                 enum { RADIO_DISABLED_CLEAR = 4 };
695                 enum { RADIO_DISABLED_MARKED = 5 };
696
697         public:
698                 int changed();
699                 int checked();
700                 void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _state, int _group );
701 };
702
703 class UI_SCROLLBAR : public UI_GADGET
704 {
705         friend class UI_LISTBOX;
706         friend class UI_BUTTON;
707                 int horz;
708                 int start;
709                 int stop;
710                 int position;
711                 int window_size;
712                 int bar_length;
713                 int bar_position;
714                 int bar_size;
715                 UI_BUTTON up_button;
716                 UI_BUTTON down_button;
717                 int last_scrolled;
718                 int drag_x, drag_y;
719                 int drag_starting;
720                 int dragging;
721                 int moved;
722
723                 virtual void draw();
724                 virtual void process(int focus = 0);
725
726                 // Used to index into bmap_ids[] array to locate right bitmap for scrollbar
727                 enum { SB_NORMAL = 0 };
728                 enum { SB_DISABLED = 1 };
729
730         public:
731                 void create(UI_WINDOW *wnd, int _x, int _y, int _h,int _start, int _stop, int _position, int _window_size  );
732                 int getpos();
733                 int changed();
734                 void hide();
735                 void unhide();
736                 int get_hidden();
737                 void link_hotspot(int up_button_num, int down_button_num);
738                 int set_bmaps(char *up_button_fname, char *down_button_fname, char *line_fname);
739 };
740
741 class UI_SLIDER2 : public UI_GADGET
742 {
743         friend class UI_BUTTON;
744         private:
745                 int numberItems;                                // total range
746                 int numberPositions;                    // total positions (height - bitmapbuttonheight)
747                 int currentItem;                                // current item we are on
748                 int currentPosition;                    // current position
749                 int last_scrolled;
750                 int mouse_locked;
751                 int slider_mode;                                //              
752                 UI_BUTTON sliderBackground;// invisible button to detect clicks
753                 int bitmapSliderControl;        // this is the bitmap of the slider button itself
754                 void (*upCallback)();
755                 void (*downCallback)();
756                 void (*captureCallback)();      // this is called when the mouse is released
757                 UI_BUTTON *upButton, *downButton;
758                 int slider_w, slider_h, slider_half_h;          // this is the width and height and half height of the bitmap used for the slider
759                 virtual void draw();
760                 virtual void process(int focus = 0);
761
762                 // Used to index into bmap_ids[] array to locate right bitmap for slider
763                 enum { S2_NORMAL = 0 };
764                 enum { S2_HIGHLIGHT = 1 };
765                 enum { S2_PRESSED = 2 };
766                 enum { S2_DISABLED = 3 };
767
768                 // Used for slider mode
769                 enum { S2M_ON_ME = 0 };
770                 enum { S2M_MOVING = 1 };
771                 enum { S2M_DEFAULT = 2 };
772
773         public:
774                 // create the slider
775                 void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, int _numberItems, char *_bitmapSliderControl,
776                                                 void (*_upCallback)(), void (*_downCallback)(), void (*_captureCallback)());
777                 
778                 // range management
779                 int get_numberItems();          // return number of itmes
780                 int get_currentPosition();      // return current position
781                 int get_currentItem();          // return current item
782                 void set_numberItems(int _numberItems, int reset = 1);          // change range. maybe reset back to position 0
783                 void set_currentItem(int _currentItem);         // force slider to new position manually
784                 void force_currentItem(int _currentItem);               // force slider to new position manually, _not_ calling any callbacks
785
786                 // force down
787                 void forceDown();
788
789                 // force up
790                 void forceUp();
791
792                 // general ui commands
793                 void hide();
794                 void unhide();
795                 int get_hidden();
796 };
797
798 // to be phased out eventually in FS2
799 class UI_DOT_SLIDER : public UI_GADGET
800 {
801         friend class UI_BUTTON;
802
803                 UI_BUTTON button;
804                 UI_BUTTON up_button;
805                 UI_BUTTON down_button;
806                 int first_frame, total_frames;
807                 int has_end_buttons;
808                 int num_pos;
809
810         public:
811                 int pos;  // 0 thru 10
812
813                 void create(UI_WINDOW *wnd, int _x, int _y, char *bm, int id, int end_buttons = 1, int num_pos = 10);           
814                 virtual void draw();
815                 virtual void process(int focus = 0);
816                 virtual void destroy();
817 };
818
819 class UI_DOT_SLIDER_NEW : public UI_GADGET
820 {
821         friend class UI_BUTTON;
822                 UI_BUTTON button;
823                 UI_BUTTON up_button;
824                 UI_BUTTON down_button;          
825                 int has_end_buttons;
826                 int num_pos;
827                 int dot_width;
828
829         public:
830                 int pos;  // 0 thru 10
831
832                 void create(UI_WINDOW *wnd, int _x, int _y, int num_pos, char *bm_slider, int slider_mask,
833                                                                                                                                                                         char *bm_left = NULL, int left_mask = -1, int left_x = -1, int left_y = -1,
834                                                                                                                                                                         char *bm_right = NULL, int right_mask = -1, int right_x = -1, int right_y = -1,
835                                                                                                                                                                         int dot_width = 19);
836                 virtual void draw();
837                 virtual void process(int focus = 0);            
838 };
839
840 class UI_LISTBOX : public UI_GADGET
841 {
842         private:
843                 char **list;
844                 char *check_list;
845                 int max_items;
846                 int num_items;
847                 int num_items_displayed;
848                 int first_item;
849                 int old_first_item;
850                 int current_item;
851                 int selected_item;
852                 int toggled_item;
853                 int old_current_item;
854                 int last_scrolled;
855                 int dragging;
856                 int textheight;
857                 int has_scrollbar;
858                 char key_buffer[MAX_KEY_BUFFER];
859                 int key_buffer_count;
860                 int last_typed;
861                 UI_SCROLLBAR scrollbar;
862
863                 virtual void draw();
864                 virtual void process(int focus = 0);
865
866                 // Used to index into bmap_ids[] array to locate right bitmap for listbox
867                 enum { LBOX_NORMAL = 0 };
868                 enum { LBOX_DISABLED = 1 };
869
870         public:
871                 void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, int _numitem, char **_list, char *_check_list = NULL, int _max_items = -1);
872                 int selected(); // selected: Returns >= 0 if an item was selected
873                 int current();  // current:  Returns which item listbox bar is currently on. This could be -1, if none selected!                
874                 int toggled();  // toggled:  Returns which item was toggled with spacebr or mouse click of check_list is not NULL               
875                 void set_current(int _index);   // sets the current item in the list box
876                 void set_first_item(int _index);
877                 char *get_string(int _index);
878                 void clear_all_items();       // deletes all the items in the list (makes them empty strings)
879                 int add_string(char *str);
880                 int sel_changed();           // returns > 0 if the selected item has changed
881                 void set_new_list(int _numitems, char **_list);
882
883                 int set_bmaps(char *lbox_fname, char *b_up_fname, char *b_down_fname, char *sb_fname);
884                 void link_hotspot(int up_button_num, int down_button_num);
885 };
886
887 #define WIN_BORDER 1
888 #define WIN_FILLED 2
889 #define WIN_SAVE_BG 4
890 #define WIN_DIALOG (4+2+1)
891
892 class UI_WINDOW
893 {
894         friend class UI_GADGET;
895         friend class UI_BUTTON;
896         friend class UI_KEYTRAP;
897         friend class UI_CHECKBOX;
898         friend class UI_RADIO;
899         friend class UI_SCROLLBAR;
900         friend class UI_LISTBOX;
901         friend class UI_INPUTBOX;
902         // friend UI_SLIDER;
903         friend class UI_SLIDER2;
904         friend class UI_DOT_SLIDER;
905         friend class UI_DOT_SLIDER_NEW;
906         friend class UI_ICON;
907
908 protected:
909         int flags;
910         int x, y;
911         int w, h;
912         int f_id;                                                               // font id
913         int last_tooltip_hotspot;
914         uint last_tooltip_time;
915         int tt_group;  // which tooltip group this window uses, or -1 if none
916         int ignore_gadgets;
917
918         UI_GADGET *first_gadget;
919         UI_GADGET *selected_gadget;
920         UI_GADGET *mouse_captured_gadget;
921
922         int mask_bmap_id;                                               // bitmap id of the mask bitmap to define hotspots
923         int foreground_bmap_id;                         // bitmap id of the foreground bitmap to display
924         bitmap *mask_bmap_ptr;                          // pointer to bitmap of the mask
925         ushort *mask_data;                                      // points to raw mask bitmap data
926         int mask_w, mask_h;                                     // width and height of the mask
927
928         UI_XSTR *xstrs[MAX_UI_XSTRS];   // strings for drawing in code instead of in artwork
929
930
931         int keypress;           // filled in each frame
932         void capture_mouse(UI_GADGET *gadget = NULL);
933         void release_bitmaps();         // called internally when window destroys gadgets
934         void check_focus_switch_keys();
935         void do_dump_check();
936         void draw_xstrs();                      // draw xstrs
937         void draw_one_xstr(UI_XSTR *xstr, int frame);
938
939 public:
940         UI_WINDOW();    // constructor
941         ~UI_WINDOW();   // destructor
942         void set_mask_bmap(char *fname);
943         void set_mask_bmap(int bmap, char *name);
944         void set_foreground_bmap(char *fname);
945         void create( int x, int y, int w, int h, int flags );
946         int process( int key_in = -1,int process_mouse = 1);
947         void draw();
948         void draw_tooltip();
949         void draw_XSTR_forced(UI_GADGET *owner, int frame);
950         int get_current_hotspot();
951         void destroy();
952         ushort *get_mask_data(int *w, int *h) { *w = mask_w; *h = mask_h; return mask_data; }
953         void render_tooltip(char *str);
954         void set_ignore_gadgets(int state);
955         void add_XSTR(char *string, int xstr_id, int x, int y, UI_GADGET *assoc, int color_type, int font_id = -1);
956         void add_XSTR(UI_XSTR *xstr);
957
958         char *(*tooltip_handler)(char *text);
959         int last_keypress;              // filled in each frame
960         int ttx, tty;
961         int use_hack_to_get_around_stupid_problem_flag;
962 };
963
964 // 2 extremely useful structs
965 typedef struct ui_button_info {
966         char *filename;
967         int x, y, xt, yt;
968         int hotspot;
969         UI_BUTTON button;  // because we have a class inside this struct, we need the constructor below..
970
971         ui_button_info(char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
972 } ui_button_info;
973
974
975 /*
976 typedef struct {
977         char *mask;
978         int start;
979         int end;
980 } tooltip_group;
981
982 typedef struct {
983         int hotspot;
984         char *text;
985 } tooltip;
986
987 #define MAX_TOOLTIP_GROUPS      50
988 #define MAX_TOOLTIPS                    500
989
990 extern int Num_tooltip_groups;
991 extern tooltip_group Tooltip_groups[MAX_TOOLTIP_GROUPS];
992 extern tooltip Tooltips[MAX_TOOLTIPS];
993 */
994
995 int ui_getfilelist( int MaxNum, char **list, char *filespec );
996 void ui_sort_filenames( int n, char **list );
997
998 /*
999 class UI_SLIDER : public UI_GADGET
1000 {
1001         friend UI_BUTTON;
1002                 int horz;
1003                 int position;
1004                 int window_size;
1005                 int fake_length;
1006                 int fake_position;
1007                 int fake_size;
1008                 UI_BUTTON left_button;
1009                 UI_BUTTON right_button;
1010                 int last_scrolled;
1011                 int drag_x, drag_y;
1012                 int drag_starting;
1013                 int dragging;
1014                 int moved;
1015
1016                 int marker_x, marker_y, marker_w, marker_h;
1017                 int n_positions, pixel_range, increment;
1018                 float start, stop, current;
1019                 int mouse_locked;
1020
1021                 virtual void draw();
1022                 virtual void process(int focus = 0);
1023
1024                 // Used to index into bmap_ids[] array to locate right bitmap for slider
1025                 enum { SLIDER_BAR_NORMAL = 0 };
1026                 enum { SLIDER_BAR_DISABLED = 1 };
1027                 enum { SLIDER_MARKER_NORMAL = 2 };
1028                 enum { SLIDER_MARKER_DISABLED = 3 };
1029
1030         public:
1031                 void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, float _start, float _stop, float _pos, int n_positions);
1032                 int getpos();
1033                 float getcurrent();
1034                 int changed();
1035                 void hide();
1036                 void unhide();
1037                 int get_hidden();
1038                 void link_hotspot(int up_button_num, int down_button_num);
1039                 int set_bmaps(char *left_button_fname, char *right_button_fname, char *bar_fname, char *marker_fname);
1040 };
1041 */
1042
1043 #endif
1044