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